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