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): Thunderbird Developers |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { |
---|
26 | var notificationBar = { |
---|
27 | quiet : null, |
---|
28 | timer : null, |
---|
29 | timeout : 5000, |
---|
30 | upgrade : true, |
---|
31 | |
---|
32 | preferences : Components.classes["@mozilla.org/preferences-service;1"] |
---|
33 | .getService(Components.interfaces.nsIPrefService) |
---|
34 | .getBranch("extensions.virtualIdentity."), |
---|
35 | |
---|
36 | prefroot : Components.classes["@mozilla.org/preferences-service;1"] |
---|
37 | .getService(Components.interfaces.nsIPrefService) |
---|
38 | .getBranch(null).QueryInterface(Components.interfaces.nsIPrefBranch2), |
---|
39 | |
---|
40 | Obj_vINotification : null, |
---|
41 | Obj_DebugBox : null, |
---|
42 | Obj_DebugBoxSplitter : null, |
---|
43 | Obj_DebugBaseID : null, |
---|
44 | |
---|
45 | observe: function() { |
---|
46 | var showDebugArea = notificationBar.preferences.getBoolPref("debug_notification") |
---|
47 | notificationBar.Obj_DebugBox.setAttribute("hidden", !showDebugArea) |
---|
48 | notificationBar.Obj_DebugBoxSplitter.setAttribute("hidden", !showDebugArea) |
---|
49 | if (notificationBar.Obj_DebugBaseID) notificationBar.Obj_DebugBaseID.setAttribute("base_id_key_hidden", !showDebugArea) |
---|
50 | }, |
---|
51 | |
---|
52 | addObserver: function() { |
---|
53 | notificationBar.prefroot.addObserver("extensions.virtualIdentity.debug_notification", notificationBar, false); |
---|
54 | }, |
---|
55 | |
---|
56 | removeObserver: function() { |
---|
57 | notificationBar.prefroot.removeObserver("extensions.virtualIdentity.debug_notification", notificationBar); |
---|
58 | }, |
---|
59 | |
---|
60 | init : function() { |
---|
61 | notificationBar.Obj_DebugBox = document.getElementById("vIDebugBox"); |
---|
62 | if (!notificationBar.Obj_DebugBox) return false; |
---|
63 | notificationBar.upgrade = notificationBar.Obj_DebugBox.getAttribute("upgrade") |
---|
64 | |
---|
65 | // nothing else to do for the upgrade dialog |
---|
66 | if (notificationBar.upgrade) return true; |
---|
67 | |
---|
68 | notificationBar.Obj_vINotification = document.getElementById("vINotification"); |
---|
69 | notificationBar.Obj_DebugBoxSplitter = document.getElementById("vIDebugBoxSplitter"); |
---|
70 | notificationBar.Obj_DebugBaseID = document.getElementById("msgIdentity_clone"); |
---|
71 | |
---|
72 | notificationBar.addObserver(); |
---|
73 | notificationBar.observe(); |
---|
74 | notificationBar.dump_app_version(); |
---|
75 | |
---|
76 | return true; |
---|
77 | }, |
---|
78 | |
---|
79 | clear : function() { |
---|
80 | if (!notificationBar.Obj_vINotification) return; |
---|
81 | if (notificationBar.timer) window.clearTimeout(notificationBar.timer); |
---|
82 | notificationBar.timer = null; |
---|
83 | notificationBar.Obj_vINotification.removeAllNotifications(true); |
---|
84 | }, |
---|
85 | |
---|
86 | clear_dump : function() { |
---|
87 | if (!notificationBar.Obj_DebugBox) return; |
---|
88 | var new_DebugBox = notificationBar.Obj_DebugBox.cloneNode(false); |
---|
89 | notificationBar.Obj_DebugBox.parentNode.replaceChild( |
---|
90 | new_DebugBox, notificationBar.Obj_DebugBox); |
---|
91 | notificationBar.Obj_DebugBox = new_DebugBox; |
---|
92 | notificationBar.dump_app_version(); |
---|
93 | }, |
---|
94 | |
---|
95 | // copied and adapted from nightly tester tools from Dave Townsend (http://www.oxymoronical.com/web/firefox/nightly) |
---|
96 | __getExtensionList: function(callback) { |
---|
97 | Components.utils.import("resource://gre/modules/AddonManager.jsm"); |
---|
98 | |
---|
99 | AddonManager.getAllAddons(function(addons) { |
---|
100 | |
---|
101 | var strings = addons.map(function(addon) { |
---|
102 | return "addon: " + addon.name + " " + addon.version |
---|
103 | + (addon.userDisabled || addon.appDisabled ? " [DISABLED]" : ""); |
---|
104 | }); |
---|
105 | |
---|
106 | try { callback(strings.join("\n")) } catch(e) {}; |
---|
107 | }); |
---|
108 | }, |
---|
109 | |
---|
110 | dump_app_version : function(note) { |
---|
111 | // add some information about the mail-client and the extensions installed |
---|
112 | if ("@mozilla.org/xre/app-info;1" in Components.classes) { |
---|
113 | var appInfo = Components.classes["@mozilla.org/xre/app-info;1"] |
---|
114 | .getService(Components.interfaces.nsIXULAppInfo); |
---|
115 | var protohandler = Components.classes["@mozilla.org/network/protocol;1?name=http"] |
---|
116 | .getService(Components.interfaces.nsIHttpProtocolHandler); |
---|
117 | notificationBar.__dumpDebugBox(appInfo.name + " " + appInfo.version + " (" + appInfo.appBuildID + "; " + protohandler.oscpu + ")\n") |
---|
118 | } |
---|
119 | else notificationBar.__dumpDebugBox("mail-client seems not supported by Virtual Identity Extension") |
---|
120 | |
---|
121 | notificationBar.__getExtensionList(notificationBar.__dumpDebugBox) |
---|
122 | |
---|
123 | // notificationBar.__dumpDebugBox(output + "\n") |
---|
124 | |
---|
125 | notificationBar.__dumpDebugBox("--------------------------------------------------------------------------------\n") |
---|
126 | }, |
---|
127 | |
---|
128 | dump : function(note) { |
---|
129 | if (!notificationBar.Obj_DebugBox) notificationBar.init() |
---|
130 | if (!notificationBar.preferences.getBoolPref("debug_notification") && |
---|
131 | !notificationBar.upgrade) return; |
---|
132 | dump(note); notificationBar.__dumpDebugBox(note); |
---|
133 | }, |
---|
134 | |
---|
135 | __dumpDebugBox : function(note) { |
---|
136 | if ((!notificationBar.preferences.getBoolPref("debug_notification") && |
---|
137 | !notificationBar.upgrade) || |
---|
138 | notificationBar.quiet) return; |
---|
139 | if (!notificationBar.Obj_DebugBox && |
---|
140 | !notificationBar.init()) return; |
---|
141 | |
---|
142 | var new_text = document.createTextNode(note); |
---|
143 | var new_br = document.createElementNS("http://www.w3.org/1999/xhtml", 'br'); |
---|
144 | notificationBar.Obj_DebugBox.inputField.appendChild(new_text); |
---|
145 | notificationBar.Obj_DebugBox.inputField.appendChild(new_br); |
---|
146 | notificationBar.Obj_DebugBox.inputField.scrollTop = |
---|
147 | notificationBar.Obj_DebugBox.inputField.scrollHeight - |
---|
148 | notificationBar.Obj_DebugBox.inputField.clientHeight |
---|
149 | }, |
---|
150 | |
---|
151 | setNote: function(note, prefstring, title) { |
---|
152 | notificationBar.clear(); |
---|
153 | notificationBar.addNote(note, prefstring, title); |
---|
154 | }, |
---|
155 | |
---|
156 | overflow : function(elem) { |
---|
157 | // height will be cut off from messagepane (in 3pane window) |
---|
158 | var objMessagepane = document.getElementById("messagepane"); |
---|
159 | var maxHeight = (objMessagepane)?parseInt(objMessagepane.boxObject.height / 2)+1:null; |
---|
160 | if (maxHeight < 60) maxHeight = 60; // set a minimum size, if to small scrollbars are hidden |
---|
161 | var tooBig = (maxHeight)?(elem.inputField.scrollHeight > maxHeight):false; |
---|
162 | var newHeight = (tooBig)?maxHeight:elem.inputField.scrollHeight; |
---|
163 | elem.height = newHeight; |
---|
164 | // give the box a frame if it is to big |
---|
165 | if (tooBig) document.getElementById("vINotificationTextbox").setAttribute("class", "plain border") |
---|
166 | }, |
---|
167 | |
---|
168 | __setTitle: function(title) { |
---|
169 | if (!title) return; |
---|
170 | // notificationBar.dump("** setTitle: " + title + "\n"); |
---|
171 | var Obj_vINotificationTitle = document.getElementById("vINotificationTitle"); |
---|
172 | Obj_vINotificationTitle.setAttribute("value", title); |
---|
173 | Obj_vINotificationTitle.removeAttribute("hidden"); |
---|
174 | }, |
---|
175 | |
---|
176 | addNote: function(note, prefstring, title) { |
---|
177 | // notificationBar.dump("** " + note + "\n\n"); |
---|
178 | if (!notificationBar.preferences.getBoolPref(prefstring)) return; |
---|
179 | if (!notificationBar.Obj_vINotification) notificationBar.init(); |
---|
180 | if (!notificationBar.Obj_vINotification) return; |
---|
181 | var oldNotification = notificationBar.Obj_vINotification.currentNotification |
---|
182 | var newLabel = (oldNotification)?oldNotification.label + note:note; |
---|
183 | notificationBar.clear(); |
---|
184 | notificationBar.Obj_vINotification |
---|
185 | .appendNotification(newLabel, "", "chrome://messenger/skin/icons/flag.png"); |
---|
186 | notificationBar.__setTitle(title); |
---|
187 | |
---|
188 | if (notificationBar.preferences.getIntPref("notification_timeout") != 0) |
---|
189 | notificationBar.timer = window.setTimeout(virtualIdentityExtension.notificationBar.clear, |
---|
190 | notificationBar.preferences.getIntPref("notification_timeout") * 1000); |
---|
191 | } |
---|
192 | } |
---|
193 | window.addEventListener("unload", function(e) { try {notificationBar.removeObserver();} catch (ex) { } }, false); |
---|
194 | vI.notificationBar = notificationBar; |
---|
195 | }}); |
---|