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

source: content/vI_statusmenu.js @ f29419

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

tons of changes, mostly namespace-related

  • Property mode set to 100644
File size: 10.7 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
25Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
26virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
27
28let Log = vI.setupLogging("virtualIdentity.statusmenu");
29
30Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
31
32var statusmenu = {
33    stringBundle : Components.classes["@mozilla.org/intl/stringbundle;1"]
34        .getService(Components.interfaces.nsIStringBundleService)
35        .createBundle("chrome://v_identity/locale/v_identity.properties"),
36
37    objStatusMenu : null,
38    objSaveBaseIDMenuItem : null,
39    objStorageSaveMenuItem : null,
40    objStatusMenuSeparator : null,
41    objSaveSwitch : null,
42    objSaveBaseIDSwitch : null,
43    objSaveSMTPSwitch : null,
44    objFccSwitch : null,
45    objStatusText : null,
46   
47    observe: function(self, subject, topic, data) {
48//         Log.debug("statusmenu observe " + data + "\n");
49        switch (data) {
50            case "fcc_show_switch":
51                statusmenu.objFccSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
52                // no break, continue like with doFcc           
53            case "doFcc":
54                statusmenu.objFccSwitch.setAttribute("checked", vI.vIprefs.get(data));
55                break;
56            case "storage_show_switch":
57                statusmenu.objSaveSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
58                break;
59            case "storage_show_baseID_switch":
60                statusmenu.objSaveBaseIDSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
61                break;
62            case "storage_show_SMTP_switch":
63//                 Log.debug("changed storage_show_SMTP_switch to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data) + "\n");
64                statusmenu.objSaveSMTPSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
65                break;
66            case "storage_store":
67                statusmenu.objStorageSaveMenuItem.setAttribute("checked", vI.vIprefs.get(data));
68                break;
69            case "storage_store_base_id":
70                statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", vI.vIprefs.get(data));
71                break;
72            case "storage_store_SMTP":
73//                 Log.debug("changed storage_store_SMTP to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data) + "\n");
74                statusmenu.objSaveSMTPMenuItem.setAttribute("checked", vI.vIprefs.get(data));
75//                 Log.debug("changed storage_store_SMTP done\n");
76                break;
77            case "storage_colorIndication":
78                document.getElementById("identityHbox").setAttribute("colorize", vI.vIprefs.get(data))
79                document.getElementById("baseIDHbox").setAttribute("colorize", vI.vIprefs.get(data))
80                document.getElementById("smtpServerHbox").setAttribute("colorize", vI.vIprefs.get(data))
81                break;
82            case "storage":
83                if (vI.vIprefs.get(data)) {
84                    statusmenu.objStorageSaveMenuItem.removeAttribute("hidden");
85                    statusmenu.objSaveBaseIDMenuItem.removeAttribute("hidden");
86                    statusmenu.objSaveSMTPMenuItem.removeAttribute("hidden");
87                    statusmenu.objStatusMenuSeparator.removeAttribute("hidden");
88                }
89                else {
90                    statusmenu.objStorageSaveMenuItem.setAttribute("hidden", "true");
91                    statusmenu.objSaveBaseIDMenuItem.setAttribute("hidden", "true");
92                    statusmenu.objSaveSMTPMenuItem.setAttribute("hidden", "true");
93                    statusmenu.objStatusMenuSeparator.setAttribute("hidden", "true");
94                }
95                break;
96        }
97        statusmenu.menuConstraint(statusmenu.objStorageSaveMenuItem);
98    },
99   
100    addObserver: function() {
101        vI.vIprefs.addObserver("fcc_show_switch", this.observe, this);
102        vI.vIprefs.addObserver("doFcc", this.observe, this);
103        vI.vIprefs.addObserver("storage", this.observe, this);
104        vI.vIprefs.addObserver("storage_show_switch", this.observe, this);
105        vI.vIprefs.addObserver("storage_show_baseID_switch", this.observe, this);
106        vI.vIprefs.addObserver("storage_show_SMTP_switch", this.observe, this);
107        vI.vIprefs.addObserver("storage_colorIndication", this.observe, this);
108        vI.vIprefs.addObserver("storage_store", this.observe, this);
109        vI.vIprefs.addObserver("storage_store_base_id", this.observe, this);
110        vI.vIprefs.addObserver("storage_store_SMTP", this.observe, this);
111    },
112   
113    removeObserver: function() {
114        vI.vIprefs.removeObserver("fcc_show_switch", this.observe);
115        vI.vIprefs.removeObserver("doFcc", this.observe);
116        vI.vIprefs.removeObserver("storage", this.observe);
117        vI.vIprefs.removeObserver("storage_show_switch", this.observe);
118        vI.vIprefs.removeObserver("storage_show_baseID_switch", this.observe);
119        vI.vIprefs.removeObserver("storage_show_SMTP_switch", this.observe);
120        vI.vIprefs.removeObserver("storage_colorIndication", this.observe);
121        vI.vIprefs.removeObserver("storage_store", this.observe);
122        vI.vIprefs.removeObserver("storage_store_base_id", this.observe);
123        vI.vIprefs.removeObserver("storage_store_SMTP", this.observe);
124    },
125   
126    init : function () {
127        statusmenu.objStatusMenu = document.getElementById("virtualIdentityExtension_vIStatusMenu");
128        statusmenu.objSaveBaseIDMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveBaseID");
129        statusmenu.objSaveSMTPMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveSMTP");
130        statusmenu.objStorageSaveMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_save");
131        statusmenu.objStatusMenuSeparator = document.getElementById("virtualIdentityExtension_statusMenu_separator");
132        statusmenu.objSaveSwitch = document.getElementById("saveSwitch");
133        statusmenu.objSaveBaseIDSwitch = document.getElementById("saveBaseIDSwitch");
134        statusmenu.objSaveSMTPSwitch = document.getElementById("saveSMTPSwitch");
135        statusmenu.objFccSwitch = document.getElementById("virtualIdentityExtension_fccSwitch");
136        statusmenu.objStatusText = document.getElementById("statusText");
137        statusmenu.objStatusTooltipLine1 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine1");
138        statusmenu.objStatusTooltipLine2 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine2");
139
140        statusmenu.addObserver();
141        statusmenu.observe(this, null, null, "fcc_show_switch");
142        statusmenu.observe(this, null, null, "storage_show_switch");
143        statusmenu.observe(this, null, null, "storage_show_baseID_switch");
144        statusmenu.observe(this, null, null, "storage_show_SMTP_switch");
145        statusmenu.observe(this, null, null, "storage_colorIndication");
146        statusmenu.observe(this, null, null, "storage_store_base_id");
147        statusmenu.observe(this, null, null, "storage_store_SMTP");
148        statusmenu.observe(this, null, null, "storage_store");
149        statusmenu.observe(this, null, null, "storage");
150    },
151   
152    __timeout : 5,  // timeout for status messages in seconds
153    __addStatusMessage : function(save, smtp) {
154        var sourceString = "vident.statusText.save." + save;
155        if (smtp != "off") sourceString = sourceString + ".smtp"
156        var messageLine1 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line1");
157        var messageLine2 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line2");
158        if (!messageLine2) {
159            statusmenu.objStatusText.setAttribute("label", messageLine1);
160            statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
161            statusmenu.objStatusTooltipLine2.setAttribute("hidden", "true");
162        }   
163        else {
164            statusmenu.objStatusText.setAttribute("label", messageLine1 + " " + messageLine2);
165            statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
166            statusmenu.objStatusTooltipLine2.setAttribute("value", messageLine2);
167            statusmenu.objStatusTooltipLine2.removeAttribute("hidden");
168        }
169        window.setTimeout(virtualIdentityExtension.statusmenu.__clearStatusMessage, statusmenu.__timeout * 1000);
170    },
171
172    __clearStatusMessage : function() {
173        statusmenu.objStatusText.setAttribute("label", "");
174    },
175
176    changeSMTPStatus : function (elem) {
177        statusmenu.objSaveSMTPMenuItem.setAttribute("checked", elem.getAttribute("checked"));
178        statusmenu.menuConstraint();
179    },
180
181    changeBaseIDStatus : function (elem) {
182        statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", elem.getAttribute("checked"));
183        statusmenu.menuConstraint();
184    },
185
186    changeSaveStatus : function (elem) {
187        statusmenu.objStorageSaveMenuItem.setAttribute("checked", elem.getAttribute("checked"));
188        statusmenu.menuConstraint();
189    },
190
191    menuConstraint : function () {
192        var save = "off"; var smtp = "off";
193        if (statusmenu.objStorageSaveMenuItem.getAttribute("checked") == "true") {
194            statusmenu.objSaveSMTPMenuItem.removeAttribute("disabled");
195            statusmenu.objSaveBaseIDMenuItem.removeAttribute("disabled");
196            if (vI.vIprefs.get("storage")) {
197                if (statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true") save = "base";
198                else save = "ok";
199                if (statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true") smtp = "save";
200            }
201        }
202        else {
203            statusmenu.objSaveSMTPMenuItem.setAttribute("disabled", "true");
204            statusmenu.objSaveBaseIDMenuItem.setAttribute("disabled", "true");
205        }
206        statusmenu.objStatusMenu.setAttribute("save", save);
207        statusmenu.objStatusMenu.setAttribute("smtp", smtp);
208        statusmenu.__addStatusMessage(save, smtp);
209    },
210
211    clicked : function (button) {
212        if (button != 0) return; // only react on left mouse button
213        if (!vI.vIprefs.get("storage")) return;
214
215        var curSaveStatus = vI.vIprefs.get("storage_store")
216        var curSaveSMTPStatus = vI.vIprefs.get("storage_store_SMTP")
217        var curSaveBaseIDStatus = vI.vIprefs.get("storage_store_base_id")
218        var newSaveStatus = ((!curSaveStatus) || (curSaveStatus && !curSaveSMTPStatus) || (curSaveStatus && !curSaveBaseIDStatus))
219        var newSaveSMTPStatus = ((!curSaveSMTPStatus && curSaveStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
220        var newSaveBaseIDStatus = ((curSaveSMTPStatus && curSaveStatus && !curSaveBaseIDStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
221       
222        vI.vIprefs.set("storage_store", newSaveStatus)
223        vI.vIprefs.set("storage_store_SMTP", newSaveSMTPStatus)
224        vI.vIprefs.set("storage_store_base_id", newSaveBaseIDStatus)
225       
226        statusmenu.menuConstraint();
227    }
228}
229vI.statusmenu = statusmenu;
230}});
Note: See TracBrowser for help on using the repository browser.