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

source: content/vI_statusmenu.js @ 21bab3

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

added switch to show/hide status informations

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