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

source: modules/identityDataExtras/characterEncoding.js @ ab83a7

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

removed old legacy solution

  • Property mode set to 100644
File size: 4.6 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");
34
35let Log = setupLogging("virtualIdentity.identityDataExtras.characterEncoding");
36
37function identityDataExtrasObject_characterEncoding(currentWindow) {
38  this._currentWindow = currentWindow;
39  this.field = "charEnc"; // description of the option
40  this.option = "storageExtras_characterEncoding"; // option string to get preference settings
41}
42identityDataExtrasObject_characterEncoding.prototype = {
43  __proto__: identityDataExtrasObject.prototype,
44
45  get valueHtml() {
46    return this.valueNice;
47  },
48  get valueNice() {
49    return this.value ? this._currentWindow.gCharsetConvertManager
50      .getCharsetTitle(this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value)) : "";
51  },
52
53  // pre TB-32-version, might be removed in the future --------------------------------
54  _setMenuMark: function () {
55    var maileditCharsetMenu = this._currentWindow.document.getElementById("maileditCharsetMenu")
56    var value = maileditCharsetMenu.getAttribute("unmarkedValue")
57    if (value) {
58      var menuitem = this._currentWindow.document.getElementById(value);
59      if (menuitem)
60        menuitem.setAttribute('checked', 'true');
61      maileditCharsetMenu.removeAttribute("unmarkedValue")
62    }
63  },
64  // ----------------------------------------------------------------------------------
65
66  setValueToEnvironment_msgCompose: function () {
67    if (!this.value)
68      return;
69    this._currentWindow.gMsgCompose.compFields.characterSet = this.value;
70    this._currentWindow.SetDocumentCharacterSet(this.value);
71  },
72
73  setValueToEnvironment_dataEditor: function () {
74    CharsetMenu.build(this._currentWindow.document.getElementById("charsetPopup"), true, false)
75    if (this.value != null) {
76      let menu = this._currentWindow.document.getElementById("maileditCharsetMenu");
77      let menuitem = menu.getElementsByAttribute("charset", this.value).item(0);
78      if (menuitem) {
79          menu.selectedItem = menuitem;
80          menuitem.setAttribute("checked", "true");
81      }
82      menu.setAttribute("label", CharsetMenu._getCharsetLabel(this.value));
83      this._currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
84    }
85    this._currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand();
86  },
87
88  getValueFromEnvironment_msgCompose: function () {
89    // read the value from the internal vI object, global object might not be available any more
90    // happens especially while storing after sending the message
91    this.value = this._currentWindow.gMsgCompose.compFields.characterSet;
92    if (this._currentWindow.gCharsetConvertManager) {
93      var charsetAlias = this._currentWindow.gCharsetConvertManager.getCharsetAlias(this.value);
94      if (charsetAlias == "us-ascii")
95        this.value = "ISO-8859-1"; // no menu item for "us-ascii"
96    }
97  },
98
99  getValueFromEnvironment_dataEditor: function () {
100    if (this._currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true")
101    // check if element is selected (list might not contain relevant entry)
102      if (this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem)
103        this.value = this._currentWindow.document.getElementById("maileditCharsetMenu").selectedItem.getAttribute('charset');
104      else
105        this.value = null;
106  }
107}
108registerIdExtrasObject(identityDataExtrasObject_characterEncoding);
Note: See TracBrowser for help on using the repository browser.