This is just some static backup of the original site, don't expect every link to work!

source: chrome/content/v_identity/vI_storageExtras.js @ 92fd25

ng_0.8ng_0.9
Last change on this file since 92fd25 was 3f9026, checked in by rene <rene@…>, 11 years ago

changed preferences dialog

  • Property mode set to 100644
File size: 20.5 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22 * ***** END LICENSE BLOCK ***** */
23
24function vI_storageExtras_adapt(sourceId, targetId) {
25    var checked = document.getElementById(sourceId).getAttribute("checked");
26    if (targetId) var target = document.getElementById(targetId)
27    else var target = document.getElementById(sourceId.replace(/_store/,""))
28    if (checked == "true") target.removeAttribute("disabled")
29    else target.setAttribute("disabled", "true");
30}   
31
32var vI_storageExtrasHelper = {
33    seamonkey_old : null,
34
35    preferences : Components.classes["@mozilla.org/preferences-service;1"]
36            .getService(Components.interfaces.nsIPrefService)
37            .getBranch("extensions.virtualIdentity."),
38   
39    hideUnusedEditorFields : function() {
40        var storageExtras = new vI_storageExtras();
41        var allHidden = true;
42        var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
43        for( var i = 0; i < storageExtras.extras.length; i++ ) {
44            var hidden = hide && !vI_storageExtrasHelper.preferences.getBoolPref(storageExtras.extras[i].option)
45            if (!hidden) allHidden = false
46            document.getElementById("vI_" + storageExtras.extras[i].option).setAttribute("hidden", hidden)
47            document.getElementById("vI_" + storageExtras.extras[i].option + "_store").setAttribute("hidden", hidden)
48        }
49        document.getElementById("storeValue").setAttribute("hidden", allHidden)
50        // resize the window to the content
51        window.sizeToContent();
52    }
53}
54
55function vI_storageExtras(rdfDatasource, resource) {
56// function vI_storageExtras_checkbox(field, option, composeDialogElementID, updateFunction, identityValue) {
57    this.extras = [
58        new vI_storageExtras_checkbox(
59            "reciept", "storageExtras_returnReciept", "returnReceiptMenu", null, function(identity) { return identity.requestReturnReceipt; }),
60        new vI_storageExtras_checkbox(
61            "fcc", "storageExtras_fcc", "fcc_switch", null, function(identity) { return identity.doFcc; }),
62        new vI_storageExtras_characterEncoding(),
63        new vI_storageExtras_msgFormat(),
64        new vI_storageExtras_checkbox(
65            "sMimeEnc", "storageExtras_sMime_messageEncryption", "menu_securityEncryptRequire1",
66                function() { return ((typeof(setSecuritySettings)=='function')?setSecuritySettings(1):null) },
67                function(identity) { return (identity.getIntAttribute('encryptionpolicy') == 2) }),
68        new vI_storageExtras_checkbox(
69            "sMimeSig", "storageExtras_sMime_messageSignature", "menu_securitySign1",
70                function() { return ((typeof(setSecuritySettings)=='function')?setSecuritySettings(1):null) },
71                function(identity) { return (identity.getBoolAttribute('sign_mail')) }),
72        new vI_storageExtras_checkbox(
73            "PGPEnc", "storageExtras_openPGP_messageEncryption", "enigmail_encrypted_send",
74                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
75                function(identity) { return (identity.getIntAttribute('defaultEncryptionPolicy') > 0) }),
76        new vI_storageExtras_checkbox(
77            "PGPSig", "storageExtras_openPGP_messageSignature", "enigmail_signed_send",
78                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
79                function(identity) { return ((identity.getIntAttribute('defaultEncryptionPolicy') > 0)?identity.getBoolAttribute('pgpSignEncrypted'):identity.getBoolAttribute('pgpSignPlain')) }),
80        new vI_storageExtras_checkbox(
81            "PGPMIME", "storageExtras_openPGP_PGPMIME", "enigmail_sendPGPMime",
82                function() { return ((typeof(enigSetMenuSettings)=='function')?enigSetMenuSettings(''):null) },
83                function(identity) { return (identity.getBoolAttribute('pgpMimeMode')) })
84        ]
85    if (rdfDatasource) this.loopForRDF(rdfDatasource, resource, "get")
86}
87
88vI_storageExtras.prototype = {
89    loopForRDF : function(rdfDatasource, resource, type) {
90        for( var i = 0; i < this.extras.length; i++ ) {
91//          if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: loopForRDF " + rdfDatasource + "\n");
92            // only if pref set and feature(element available) or for dataEditor
93            if (typeof(gMsgCompose) == "undefined" || !gMsgCompose || this.extras[i].active) {
94                switch (type) {
95                    case "get": this.extras[i].value = rdfDatasource._getRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
96                    case "set": this.extras[i].value = rdfDatasource._setRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
97                    case "unset": this.extras[i].value = rdfDatasource._unsetRDFValue(resource, this.extras[i].field, this.extras[i].value); break;
98                }
99            }
100        }
101    },
102   
103    // just give a duplicate of the current storageExtras, else we will work with pointers
104    getDuplicate : function() {
105        var newExtras = new vI_storageExtras();
106        for( var i = 0; i < this.extras.length; i++ ) {
107            newExtras.extras[i].value = this.extras[i].value;
108        }
109        return newExtras;
110    },
111   
112    // copys all values of an identity. This way we can create a new object with a different document-context
113    copy : function(extras) {
114        for( var i = 0; i < this.extras.length; i++ ) {
115            this.extras[i].value = extras.extras[i].value;
116        }
117    },
118
119    equal : function(storageExtras) {
120        var equal = true;
121        for( var i = 0; i < this.extras.length; i++ ) {
122            if (this.extras[i].active) {
123                equal = (this.extras[i].equal(storageExtras.extras[i]) && equal) // in this order to compare all fields (required for Matrix)
124            }
125        }
126        return equal;
127    },
128    getMatrix : function() {
129        var prefStrings = document.getElementById("vIStorageExtrasBundle");
130        var string = "";
131        for( var i = 0; i < this.extras.length; i++ ) {
132            if (this.extras[i].active) {
133                if (this.extras[i].valueHtml)
134                    string += "<tr>" +
135                    "<td class='col1 extras '>" + prefStrings.getString("vident.identityData.extras." + this.extras[i].field) + "</td>" +
136                    "<td class='col2 extras '>" + this.extras[i].valueHtml + "</td>" +
137                    "</tr>"
138            }
139        }
140        return string;
141    },
142    getCompareMatrix : function() {
143        var prefStrings = document.getElementById("vIStorageExtrasBundle");
144        var string = "";
145        for( var i = 0; i < this.extras.length; i++ ) {
146            if (this.extras[i].active) {
147                var classEqual = (this.extras[i].comp.equal)?"equal":"unequal";
148                string += "<tr>" +
149                    "<td class='col1 extras " + classEqual + "'>" + prefStrings.getString("vident.identityData.extras." + this.extras[i].field) + "</td>" +
150                    "<td class='col2 extras " + classEqual + "'>" + this.extras[i].comp.compareValue + "</td>" +
151                    "<td class='col3 extras " + classEqual + "'>" + this.extras[i].valueHtml + "</td>" +
152                    "</tr>"
153            }
154        }
155        return string;
156    },
157    status : function() {
158        var returnVal = "";
159        for( var i = 0; i < this.extras.length; i++ )
160            if (this.extras[i].active && this.extras[i].value)
161                returnVal += " " + this.extras[i].field + "='" + this.extras[i].value + "'";
162        return returnVal
163    },
164
165    readIdentityValues : function(identity) {
166        for( var i = 0; i < this.extras.length; i++ ) {
167            if (this.extras[i].active) this.extras[i].readIdentityValue(identity)
168//          vI_notificationBar.dump("## vI_storageExtras readIdentityValues "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
169        }
170    },
171
172    setValues : function() {
173        for( var i = 0; i < this.extras.length; i++ ) {
174            if (this.extras[i].active) this.extras[i].setValue()
175//          vI_notificationBar.dump("## vI_storageExtras setValue "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
176        }
177    },
178    readValues : function() {
179        for( var i = 0; i < this.extras.length; i++ ) {
180//          vI_notificationBar.dump("## vI_storageExtras preparing readValue "+ this.extras[i].field +"\n");
181            if (this.extras[i].active) this.extras[i].readValue()
182//              vI_notificationBar.dump("## vI_storageExtras readValue "+ this.extras[i].field + "=" + this.extras[i].value + "\n");
183        }
184    },
185    setEditorValues : function() {
186        for( var i = 0; i < this.extras.length; i++ ) this.extras[i].setEditorValue();
187    },
188    readEditorValues : function() {
189        for( var i = 0; i < this.extras.length; i++ ) {
190            this.extras[i].readEditorValue();
191//          vI_notificationBar.dump("## vI_storageExtras readValue " + this.extras[i].field + "=" + this.extras[i].value + "\n");
192        }
193    },
194
195    // add value's to the pref object, required for rdfDataTree
196    addPrefs : function(pref) {
197        for( var i = 0; i < this.extras.length; i++ )
198            pref[this.extras[i].field + "Col"] = this.extras[i].valueNice;
199    }
200}
201
202function vI_storageExtras_characterEncoding_setMenuMark() {
203    var maileditCharsetMenu = document.getElementById("maileditCharsetMenu")
204    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
205    if (value) {
206        var menuitem = document.getElementById(value);
207        if (menuitem) menuitem.setAttribute('checked', 'true');
208        maileditCharsetMenu.removeAttribute("unmarkedValue")
209    }
210}
211function vI_storageExtras_characterEncoding() {
212    this.active = vI_storageExtrasHelper.preferences.getBoolPref("storage") &&
213                vI_storageExtrasHelper.preferences.getBoolPref(this.option)
214    this.comp = { compareValue : null, equal : null }
215}
216vI_storageExtras_characterEncoding.prototype = {
217    active : null,
218    value : null,
219    field : "charEnc",
220    option : "storageExtras_characterEncoding",
221    comp : null,
222
223    // functions to get nicely formatted output
224    get valueHtml() { return this.valueNice; },
225    get valueNice() {
226        return this.value?gCharsetConvertManager
227                    .getCharsetTitle(gCharsetConvertManager.getCharsetAlias(this.value)):"";
228    },
229
230    // function to read the value from a given identity
231    readIdentityValue : function(identity) { }, // no charset per identity
232
233    equal : function(compareStorageExtra) {
234        this.comp.compareValue = compareStorageExtra.valueHtml;
235        this.comp.equal = (!this.value || !compareStorageExtra.value || this.value == compareStorageExtra.value);
236        return this.comp.equal;
237    },
238    // function to set or read the value from/to the MessageCompose Dialog
239    setValue : function() {
240        if (!this.value) return;
241        var menuitem = document.getElementById(this.value);
242        if (menuitem) menuitem.setAttribute('checked', 'true');
243        else {  // set menumark later if menu is not ready yet
244            var maileditCharsetMenu = document.getElementById("maileditCharsetMenu")
245            maileditCharsetMenu.setAttribute("unmarkedValue", this.value)
246            var onpopupshowing = maileditCharsetMenu.getAttribute("onpopupshowing")
247            document.getElementById("maileditCharsetMenu").setAttribute("onpopupshowing",
248                onpopupshowing + ";vI_storageExtras_characterEncoding_setMenuMark();")
249        }
250        gMsgCompose.compFields.characterSet = this.value;
251        SetDocumentCharacterSet(this.value);
252    },
253    readValue : function() {
254        // read the value from the internal vI object, global object might not be available any more
255        // happens especially while storing after sending the message
256        this.value = vI_main.gMsgCompose.compFields.characterSet;
257        if (gCharsetConvertManager) {
258            var charsetAlias = gCharsetConvertManager.getCharsetAlias(this.value);
259            if (charsetAlias == "us-ascii") this.value = "ISO-8859-1";   // no menu item for "us-ascii"
260        }
261    },
262    // function to set or read the value from the rdfDataEditor
263    // XXX still Problem if selected Encoding is not (yet) Element of the Menu, repair this
264
265    setEditorValue : function() {
266        CreateMenu('mailedit');
267        if (this.value != null) {
268            document.getElementById("maileditCharsetMenu").selectedItem = document.getElementById(this.value);
269            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
270           
271        }
272        document.getElementById("vI_" + this.option + "_store").doCommand();
273    },
274    readEditorValue : function() {
275        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
276            // check if element is selected (list might not contain relevant entry)
277            if (document.getElementById("maileditCharsetMenu").selectedItem)
278                this.value = document.getElementById("maileditCharsetMenu").selectedItem.id
279        else    this.value = null;
280    }
281}
282
283function vI_storageExtras_msgFormat() {
284    this.active = vI_storageExtrasHelper.preferences.getBoolPref("storage") &&
285                vI_storageExtrasHelper.preferences.getBoolPref(this.option)
286    this.comp = { value : null, compareValue : null, equal : null }
287}
288vI_storageExtras_msgFormat.prototype = {
289    active : null,
290    value : null,
291    field : "msgFormat",
292    option : "storageExtras_messageFormat",
293    comp : null,
294
295    // functions to get nicely formatted output
296    get valueHtml() { return this.valueNice; },
297    get valueNice() {
298        return this.value?document.getElementById(this.value).label:"";
299    },
300
301    // function to read the value from a given identity
302    readIdentityValue : function(identity) { }, // no msgFormat per identity
303
304    equal : function(compareStorageExtra) {
305        this.comp.compareValue = compareStorageExtra.valueHtml;
306        this.comp.equal = (!this.value || !compareStorageExtra.value || this.value == compareStorageExtra.value);
307        return this.comp.equal;
308    },
309    // function to set or read the value from/to the MessageCompose Dialog
310    setValue : function() {
311        if (!this.value) return;
312        document.getElementById(this.value).setAttribute("checked","true");
313        OutputFormatMenuSelect(document.getElementById(this.value))
314    },
315    readValue : function() {
316        switch (gSendFormat) {
317            case nsIMsgCompSendFormat.AskUser: this.value = "format_auto"; break;
318            case nsIMsgCompSendFormat.PlainText: this.value = "format_plain"; break;
319            case nsIMsgCompSendFormat.HTML: this.value = "format_html"; break;
320            case nsIMsgCompSendFormat.Both: this.value = "format_both"; break;
321        }
322    },
323    // function to set or read the value from the rdfDataEditor
324    setEditorValue : function() {
325        //~ document.getElementById(this.value).setAttribute("checked","true");
326        if (this.value != null) {
327            document.getElementById("outputFormatMenu").selectedItem = document.getElementById(this.value);
328            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
329        }
330        document.getElementById("vI_" + this.option + "_store").doCommand();
331       
332    },
333    readEditorValue : function() {
334        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
335            this.value = document.getElementById("outputFormatMenu").selectedItem.id
336        else    this.value = null;
337    }
338}
339
340function vI_storageExtras_sMime_messageEncryption() { 
341    this.active = vI_storageExtrasHelper.preferences.getBoolPref("storage") &&
342                vI_storageExtrasHelper.preferences.getBoolPref(this.option)
343    this.comp = { value : null, compareValue : null, equal : null }
344}
345vI_storageExtras_sMime_messageEncryption.prototype = {
346    active : null,
347    value : null,
348    field : "sMimeEnc",
349    option : "storageExtras_sMime_messageEncryption",
350    comp : null,
351
352    // functions to get nicely formatted output
353    get valueHtml() {
354        if (!this.value) return "";
355        return  "<div class='bool" + ((this.value=="true")?" checked":"") + "'>" +
356                "<label class='screen'>&nbsp;</label>" +
357                "<label class='braille'>" + this.valueNice + "</label>" +
358            "</div>"
359    },
360    get valueNice() {
361        if (!this.value) return "";
362        return (this.value=="true")?"yes":"no";
363    },
364
365    equal : function(compareStorageExtra) {
366        this.comp.compareValue = compareStorageExtra.valueHtml;
367        this.comp.equal = (this.value == null || this.value == compareStorageExtra.value);
368        return this.comp.equal;
369    },
370
371    // function to read the value from a given identity
372    readIdentityValue : function(identity) {
373        this.value = (identity.getIntAttribute("encryptionpolicy") == 2)?"true":"false"
374    },
375    // function to set or read the value from/to the MessageCompose Dialog
376    setValue : function() {
377        vI_notificationBar.dump("## storageExtras_sMime_messageEncryption \n");
378        var doEncryptElem = document.getElementById("menu_securityEncryptRequire1");
379        if (this.value == null) return;
380        if (this.value == "true") var element = document.getElementById("menu_securityEncryptRequire1")
381        else var element = document.getElementById("menu_securityNoEncryption1")
382        element.setAttribute("checked", "true");
383        element.doCommand();
384    },
385    readValue : function() {
386        setSecuritySettings(1)
387        this.value = (document.getElementById("menu_securityEncryptRequire1").getAttribute("checked") == "true")?"true":"false"
388    },
389    // function to set or read the value from the rdfDataEditor
390    setEditorValue : function() { 
391        if (this.value != null) {
392            document.getElementById("vI_" + this.option).setAttribute("checked", this.value);
393            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
394        }
395        document.getElementById("vI_" + this.option + "_store").doCommand();
396    },
397    readEditorValue : function() {
398        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") {
399            var elementValue = document.getElementById("vI_" + this.option).getAttribute("checked");
400            this.value = (elementValue == "true")?"true":"false"
401        }
402        else    this.value = null;
403    }
404}
405
406// a general checkbox for extra options. Has to provide some additional information
407function vI_storageExtras_checkbox(field, option, composeDialogElementID, updateFunction, identityValue) {
408    this.field = field;     // description of the option
409    this.option = option;       // option string to get preference settings
410    this.composeDialogElementID = composeDialogElementID;
411    this.updateFunction = updateFunction;
412    this.valueFromIdentityFunction = identityValue;
413    this.active = vI_storageExtrasHelper.preferences.getBoolPref("storage") &&
414                vI_storageExtrasHelper.preferences.getBoolPref(this.option) 
415//      elements are never available in DataTree, so leave this out.
416//      && document.getElementById(this.composeDialogElementID);
417    this.comp = { compareValue : null, equal : null }
418}
419vI_storageExtras_checkbox.prototype = {
420    active : null,
421    value : null,
422    field : null,
423    option : null,
424    comp : null,
425    composeDialogElementID : null,
426    updateFunction : null, // some elements have to be updated before the can be read
427    valueFromIdentityFunction : null,
428   
429    // functions to get nicely formatted output
430    get valueHtml() {
431        if (!this.value) return "";
432        return  "<div class='bool" + ((this.value=="true")?" checked":"") + "'>" +
433                "<label class='screen'>&nbsp;</label>" +
434                "<label class='braille'>" + this.valueNice + "</label>" +
435            "</div>"
436    },
437    get valueNice() {
438        if (!this.value) return "";
439        return (this.value=="true")?"yes":"no";
440    },
441
442    equal : function(compareStorageExtra) {
443        this.comp.compareValue = compareStorageExtra.valueHtml;
444        this.comp.equal = (this.value == null || this.value == compareStorageExtra.value);
445        return this.comp.equal;
446    },
447
448    // function to read the value from a given identity
449    readIdentityValue : function(identity) {
450        this.value = (this.valueFromIdentityFunction(identity))?"true":"false";
451    },
452    // function to set or read the value from/to the MessageCompose Dialog
453    setValue : function() {
454        var element = document.getElementById(this.composeDialogElementID);
455        if (!this.value || !element) return;
456        if (typeof(this.updateFunction)=="function") this.updateFunction();
457
458        if ((element.getAttribute("checked") == "true") != (this.value == "true")) {
459            vI_notificationBar.dump("## vI_storageExtras change "+ this.field + " to " + this.value + " with doCommand\n");
460            element.doCommand();
461        }
462    },
463    readValue : function() {
464        var element = document.getElementById(this.composeDialogElementID)
465        if (!element) return;
466        if (typeof(this.updateFunction)=="function") this.updateFunction();
467        this.value = ((element.getAttribute("checked") == "true")?"true":"false")
468    },
469    // function to set or read the value from the rdfDataEditor
470    setEditorValue : function() {
471        if (this.value != null) {
472            document.getElementById("vI_" + this.option).setAttribute("checked", this.value);
473            document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
474        }
475        document.getElementById("vI_" + this.option + "_store").doCommand();
476    },
477    readEditorValue : function() {
478        if (document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") {
479            var elementValue = document.getElementById("vI_" + this.option).getAttribute("checked");
480            this.value = (elementValue == "true")?"true":"false"
481        }
482        else    this.value = null;
483    }
484}
Note: See TracBrowser for help on using the repository browser.