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

source: modules/identityDataExtras/characterEncoding.js @ 998c9e

ng_0.9
Last change on this file since 998c9e was 998c9e, checked in by rene <rene@…>, 8 years ago

added compatibility changes for new charEncoding Menu

  • Property mode set to 100644
File size: 6.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    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var EXPORTED_SYMBOLS = [];
26
27const Ci = Components.interfaces;
28const Cc = Components.classes;
29const Cu = Components.utils;
30
31
32Cu.import("resource://v_identity/vI_identityDataExtras.js");
33Cu.import("resource://v_identity/vI_log.js");
34let legacy = false; // use pre TB-32 legacy code
35try {
36    Cu.import("resource://gre/modules/CharsetMenu.jsm");
37} catch (e) {
38    legacy = true; // pre TB-32-version, might be removed in the future
39}
40   
41
42let Log = setupLogging("virtualIdentity.identityDataExtras.characterEncoding");
43
44function identityDataExtrasObject_characterEncoding(currentWindow) {
45  this.currentWindow = currentWindow;
46  this.field  = "charEnc";                        // description of the option
47  this.option = "storageExtras_characterEncoding";    // option string to get preference settings
48}
49identityDataExtrasObject_characterEncoding.prototype = {
50  __proto__: identityDataExtrasObject.prototype,
51 
52  get valueHtml() { return this.valueNice; },
53  get valueNice() {
54      return this.value?this.currentWindow.gCharsetConvertManager
55                  .getCharsetTitle(this.currentWindow.gCharsetConvertManager.getCharsetAlias(this.value)):"";
56  },
57
58  // pre TB-32-version, might be removed in the future --------------------------------
59  _setMenuMark: function() {
60    var maileditCharsetMenu = this.currentWindow.document.getElementById("maileditCharsetMenu")
61    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
62    if (value) {
63        var menuitem = this.currentWindow.document.getElementById(value);
64        if (menuitem)
65          menuitem.setAttribute('checked', 'true');
66        maileditCharsetMenu.removeAttribute("unmarkedValue")
67    }
68  },
69  // ----------------------------------------------------------------------------------
70 
71  setValueToEnvironment_msgCompose: function() {
72    if (!this.value)
73      return;
74    // pre TB-32-version, might be removed in the future --------------------------------
75    if (legacy) {
76        // old style
77        var menuitem = this.currentWindow.document.getElementById(this.value);
78        if (menuitem)
79        menuitem.setAttribute('checked', 'true');
80        else {  // set menumark later if menu is not ready yet
81        var maileditCharsetMenu = this.currentWindow.document.getElementById("maileditCharsetMenu")
82        maileditCharsetMenu.setAttribute("unmarkedValue", this.value)
83        var onpopupshowing = maileditCharsetMenu.getAttribute("onpopupshowing")
84        this.currentWindow.document.getElementById("maileditCharsetMenu").setAttribute("onpopupshowing",
85            onpopupshowing + ";this._setMenuMark();")
86        }
87    }
88    // ----------------------------------------------------------------------------------
89    this.currentWindow.gMsgCompose.compFields.characterSet = this.value;
90    this.currentWindow.SetDocumentCharacterSet(this.value);
91  },
92 
93  setValueToEnvironment_dataEditor: function() {
94    // pre TB-32-version, might be removed in the future --------------------------------
95    if (legacy) {
96      this.currentWindow.CreateMenu('mailedit'); // this is part of the magic included by the xul-binding
97        if (this.value != null) {
98            this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem = this.currentWindow.document.getElementById(this.value);
99            this.currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
100        }
101    }
102    // ----------------------------------------------------------------------------------
103    else {
104        CharsetMenu.build(this.currentWindow.document.getElementById("charsetPopup"), false, false)
105        if (this.value != null) {
106            CharsetMenu.update(this.currentWindow.document.getElementById("maileditCharsetMenu"), this.value);
107            this.currentWindow.document.getElementById("maileditCharsetMenu").setAttribute("label",CharsetMenu._getCharsetLabel(this.value));
108            this.currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
109        }
110    }
111    this.currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand();
112  },
113 
114  getValueFromEnvironment_msgCompose: function() {
115    // read the value from the internal vI object, global object might not be available any more
116    // happens especially while storing after sending the message
117    this.value = this.currentWindow.gMsgCompose.compFields.characterSet;
118    if (this.currentWindow.gCharsetConvertManager) {
119      var charsetAlias = this.currentWindow.gCharsetConvertManager.getCharsetAlias(this.value);
120      if (charsetAlias == "us-ascii")
121        this.value = "ISO-8859-1";   // no menu item for "us-ascii"
122    }
123  },
124 
125  getValueFromEnvironment_dataEditor: function() {
126    if (this.currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
127      // check if element is selected (list might not contain relevant entry)
128      if (this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem)
129        // pre TB-32-version, might be removed in the future --------------------------------
130        if (legacy) {
131            this.value = this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.id
132        }
133        // ----------------------------------------------------------------------------------
134        else {
135            this.value = this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.getAttribute('charset');
136        }
137    else
138      this.value = null;
139  }
140}
141registerIdExtrasObject(identityDataExtrasObject_characterEncoding);
Note: See TracBrowser for help on using the repository browser.