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

source: modules/identityDataExtras/characterEncoding.js @ 509348

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

code formatting (no code changes)

  • Property mode set to 100644
File size: 6.4 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() {
53    return this.valueNice;
54  },
55  get valueNice() {
56    return this.value ? this.currentWindow.gCharsetConvertManager
57      .getCharsetTitle(this.currentWindow.gCharsetConvertManager.getCharsetAlias(this.value)) : "";
58  },
59
60  // pre TB-32-version, might be removed in the future --------------------------------
61  _setMenuMark: function () {
62    var maileditCharsetMenu = this.currentWindow.document.getElementById("maileditCharsetMenu")
63    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
64    if (value) {
65      var menuitem = this.currentWindow.document.getElementById(value);
66      if (menuitem)
67        menuitem.setAttribute('checked', 'true');
68      maileditCharsetMenu.removeAttribute("unmarkedValue")
69    }
70  },
71  // ----------------------------------------------------------------------------------
72
73  setValueToEnvironment_msgCompose: function () {
74    if (!this.value)
75      return;
76    // pre TB-32-version, might be removed in the future --------------------------------
77    if (legacy) {
78      // old style
79      var menuitem = this.currentWindow.document.getElementById(this.value);
80      if (menuitem)
81        menuitem.setAttribute('checked', 'true');
82      else { // set menumark later if menu is not ready yet
83        var maileditCharsetMenu = this.currentWindow.document.getElementById("maileditCharsetMenu")
84        maileditCharsetMenu.setAttribute("unmarkedValue", this.value)
85        var onpopupshowing = maileditCharsetMenu.getAttribute("onpopupshowing")
86        this.currentWindow.document.getElementById("maileditCharsetMenu").setAttribute("onpopupshowing",
87          onpopupshowing + ";this._setMenuMark();")
88      }
89    }
90    // ----------------------------------------------------------------------------------
91    this.currentWindow.gMsgCompose.compFields.characterSet = this.value;
92    this.currentWindow.SetDocumentCharacterSet(this.value);
93  },
94
95  setValueToEnvironment_dataEditor: function () {
96    // pre TB-32-version, might be removed in the future --------------------------------
97    if (legacy) {
98      this.currentWindow.CreateMenu('mailedit'); // this is part of the magic included by the xul-binding
99      if (this.value != null) {
100        this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem = this.currentWindow.document.getElementById(this.value);
101        this.currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
102      }
103    }
104    // ----------------------------------------------------------------------------------
105    else {
106      CharsetMenu.build(this.currentWindow.document.getElementById("charsetPopup"), false, false)
107      if (this.value != null) {
108        CharsetMenu.update(this.currentWindow.document.getElementById("maileditCharsetMenu"), this.value);
109        this.currentWindow.document.getElementById("maileditCharsetMenu").setAttribute("label", CharsetMenu._getCharsetLabel(this.value));
110        this.currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
111      }
112    }
113    this.currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand();
114  },
115
116  getValueFromEnvironment_msgCompose: function () {
117    // read the value from the internal vI object, global object might not be available any more
118    // happens especially while storing after sending the message
119    this.value = this.currentWindow.gMsgCompose.compFields.characterSet;
120    if (this.currentWindow.gCharsetConvertManager) {
121      var charsetAlias = this.currentWindow.gCharsetConvertManager.getCharsetAlias(this.value);
122      if (charsetAlias == "us-ascii")
123        this.value = "ISO-8859-1"; // no menu item for "us-ascii"
124    }
125  },
126
127  getValueFromEnvironment_dataEditor: function () {
128    if (this.currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
129    // check if element is selected (list might not contain relevant entry)
130      if (this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem)
131      // pre TB-32-version, might be removed in the future --------------------------------
132        if (legacy) {
133          this.value = this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.id
134        }
135        // ----------------------------------------------------------------------------------
136        else {
137          this.value = this.currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.getAttribute('charset');
138        } else
139      this.value = null;
140  }
141}
142registerIdExtrasObject(identityDataExtrasObject_characterEncoding);
Note: See TracBrowser for help on using the repository browser.