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 | Contributor(s): |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | var EXPORTED_SYMBOLS = []; |
---|
26 | |
---|
27 | const Ci = Components.interfaces; |
---|
28 | const Cc = Components.classes; |
---|
29 | const Cu = Components.utils; |
---|
30 | |
---|
31 | |
---|
32 | Cu.import("resource://v_identity/vI_identityDataExtras.js"); |
---|
33 | Cu.import("resource://v_identity/vI_log.js"); |
---|
34 | |
---|
35 | ChromeUtils.import("resource://gre/modules/CharsetMenu.jsm"); |
---|
36 | |
---|
37 | let Log = setupLogging("virtualIdentity.identityDataExtras.characterEncoding"); |
---|
38 | |
---|
39 | function identityDataExtrasObject_characterEncoding(currentWindow) { |
---|
40 | this._currentWindow = currentWindow; |
---|
41 | this.field = "charEnc"; // description of the option |
---|
42 | this.option = "storageExtras_characterEncoding"; // option string to get preference settings |
---|
43 | } |
---|
44 | identityDataExtrasObject_characterEncoding.prototype = { |
---|
45 | __proto__: identityDataExtrasObject.prototype, |
---|
46 | |
---|
47 | get valueHtml() { |
---|
48 | return this.valueNice; |
---|
49 | }, |
---|
50 | get valueNice() { |
---|
51 | return this.value ? this._currentWindow.gCharsetConvertManager |
---|
52 | .getCharsetTitle(this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value)) : ""; |
---|
53 | }, |
---|
54 | |
---|
55 | // pre TB-32-version, might be removed in the future -------------------------------- |
---|
56 | _setMenuMark: function () { |
---|
57 | var maileditCharsetMenu = this._currentWindow.document.getElementById("maileditCharsetMenu") |
---|
58 | var value = maileditCharsetMenu.getAttribute("unmarkedValue") |
---|
59 | if (value) { |
---|
60 | var menuitem = this._currentWindow.document.getElementById(value); |
---|
61 | if (menuitem) |
---|
62 | menuitem.setAttribute('checked', 'true'); |
---|
63 | maileditCharsetMenu.removeAttribute("unmarkedValue") |
---|
64 | } |
---|
65 | }, |
---|
66 | // ---------------------------------------------------------------------------------- |
---|
67 | |
---|
68 | setValueToEnvironment_msgCompose: function () { |
---|
69 | if (!this.value) |
---|
70 | return; |
---|
71 | this._currentWindow.gMsgCompose.compFields.characterSet = this.value; |
---|
72 | this._currentWindow.SetDocumentCharacterSet(this.value); |
---|
73 | }, |
---|
74 | |
---|
75 | setValueToEnvironment_dataEditor: function () { |
---|
76 | CharsetMenu.build(this._currentWindow.document.getElementById("charsetPopup"), true, false) |
---|
77 | if (this.value != null) { |
---|
78 | let menu = this._currentWindow.document.getElementById("maileditCharsetMenu"); |
---|
79 | let menuitem = menu.getElementsByAttribute("charset", this.value).item(0); |
---|
80 | if (menuitem) { |
---|
81 | menu.selectedItem = menuitem; |
---|
82 | menuitem.setAttribute("checked", "true"); |
---|
83 | } |
---|
84 | menu.setAttribute("label", CharsetMenu._getCharsetLabel(this.value)); |
---|
85 | this._currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true"); |
---|
86 | } |
---|
87 | this._currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand(); |
---|
88 | }, |
---|
89 | |
---|
90 | getValueFromEnvironment_msgCompose: function () { |
---|
91 | // read the value from the internal vI object, global object might not be available any more |
---|
92 | // happens especially while storing after sending the message |
---|
93 | this.value = this._currentWindow.gMsgCompose.compFields.characterSet; |
---|
94 | if (this._currentWindow.gCharsetConvertManager) { |
---|
95 | var charsetAlias = this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value); |
---|
96 | if (charsetAlias == "us-ascii") |
---|
97 | this.value = "ISO-8859-1"; // no menu item for "us-ascii" |
---|
98 | } |
---|
99 | }, |
---|
100 | |
---|
101 | getValueFromEnvironment_dataEditor: function () { |
---|
102 | if (this._currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") |
---|
103 | // check if element is selected (list might not contain relevant entry) |
---|
104 | if (this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem) |
---|
105 | this.value = this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.getAttribute('charset'); |
---|
106 | else |
---|
107 | this.value = null; |
---|
108 | } |
---|
109 | } |
---|
110 | registerIdExtrasObject(identityDataExtrasObject_characterEncoding); |
---|