!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is mozilla.org code.
15 *
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1998
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Scott MacGregor <mscott@mozilla.org>
23 * Jens Bannmann <jens.b@web.de>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 const HORIZONTAL = 1;
40 const LEFT = 2;
41 const TOP = 4;
42 const MSG_FOLDER_FLAG_VIRTUAL = 0x0020;
43
44 var gSlideTime = 50;
45 var gNumNewMsgsToShowInAlert = 4; // the more messages we show in the alert, the larger it will be
46 var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
47 var gAlertListener = null;
48 var gPendingPreviewFetchRequests = 0;
49 var gUserInitiated = false;
50 var gFadeIncrement = .05;
51 var gOrigin = 0;
52
prefillAlertInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
53 function prefillAlertInfo()
54 {
55 // unwrap all the args....
56 // arguments[0] --> array of folders with new mail
57 // arguments[1] --> the observer to call back with notifications about the alert
58 // arguments[2] --> user initiated boolean. true if the user initiated opening the alert
59 // (which means skip the fade effect and don't auto close the alert)
60 // arguments[3] --> the alert origin returned by the look and feel
61 var foldersWithNewMail = window.arguments[0];
62 gAlertListener = window.arguments[1];
63 gUserInitiated = window.arguments[2];
64 gOrigin = window.arguments[3];
65
66 // for now just grab the first folder which should be a root folder
67 // for the account that has new mail.
68 var rootFolder = foldersWithNewMail.GetElementAt(0).QueryInterface(Components.interfaces.nsIWeakReference).QueryReferent(Components.interfaces.nsIMsgFolder);
69
70 // generate an account label string based on the root folder
71 var label = document.getElementById('alertTitle');
72 var totalNumNewMessages = rootFolder.getNumNewMessages(true);
73 label.value = document.getElementById('bundle_messenger').getFormattedString(totalNumNewMessages == 1 ? "newBiffNotification_message" : "newBiffNotification_messages",
74 [rootFolder.prettiestName, totalNumNewMessages]);
75
76 // this is really the root folder and we have to walk through the list to find the real folder that has new mail in it...:(
77 var allFolders = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
78 rootFolder.ListDescendents(allFolders);
79 var numFolders = allFolders.Count();
80 var folderSummaryInfoEl = document.getElementById('folderSummaryInfo');
81 folderSummaryInfoEl.mMaxMsgHdrsInPopup = gNumNewMsgsToShowInAlert;
82 for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
83 {
84 var folder = allFolders.GetElementAt(folderIndex).QueryInterface(Components.interfaces.nsIMsgFolder);
85 if (folder.hasNewMessages && !(folder.flags & MSG_FOLDER_FLAG_VIRTUAL))
86 {
87 var asyncFetch = {};
88 folderSummaryInfoEl.parseFolder(folder, new urlListener(folder), asyncFetch);
89 if (asyncFetch.value)
90 gPendingPreviewFetchRequests++;
91 }
92 }
93 }
94
urlListener
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
95 function urlListener(aFolder)
96 {
97 this.mFolder = aFolder;
98 }
99
100 urlListener.prototype = {
OnStartRunningUrl
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
101 OnStartRunningUrl: function(aUrl)
102 {
103 },
104
OnStopRunningUrl
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
105 OnStopRunningUrl: function(aUrl, aExitCode)
106 {
107 var folderSummaryInfoEl = document.getElementById('folderSummaryInfo');
108 var asyncFetch = {};
109 folderSummaryInfoEl.parseFolder(this.mFolder, null, asyncFetch);
110 gPendingPreviewFetchRequests--;
111
112 // when we are done running all of our urls for fetching the preview text,
113 // start the alert.
114 if (!gPendingPreviewFetchRequests)
115 showAlert();
116 }
117 }
118
onAlertLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
119 function onAlertLoad()
120 {
121 // read out our initial settings from prefs.
122 try
123 {
124 var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null);
125 gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
126 gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
127 } catch (ex) {}
128
129 // bogus call to make sure the window is moved offscreen until we are ready for it.
130 resizeAlert(true);
131
132 // if we aren't waiting to fetch preview text, then go ahead and
133 // start showing the alert.
134 if (!gPendingPreviewFetchRequests)
135 setTimeout(showAlert, 0); // let the JS thread unwind, to give layout
136 // a chance to recompute the styles and widths for our alert text.
137 }
138
139 // If the user initiated the alert, show it right away, otherwise start opening the alert with
140 // the fade effect.
showAlert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
141 function showAlert()
142 {
143 if (!gUserInitiated) // set the initial opacity before we resize the window
144 document.getElementById('alertContainer').style.opacity = 0;
145
146 // resize the alert based on our current content
147 resizeAlert(false);
148
149 if (document.getElementById('folderSummaryInfo').hasMessages)
150 {
151 if (!gUserInitiated) // don't fade in if the user opened the alert
152 setTimeout(fadeOpen, gSlideTime);
153 }
154 else
155 closeAlert(); // no mail, so don't bother showing the alert...
156 }
157
resizeAlert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
158 function resizeAlert(aMoveOffScreen)
159 {
160 // sizeToContent is not working. It isn't honoring the max widths we are attaching to our inner
161 // objects like the folder summary element. While the folder summary element is cropping,
162 // sizeToContent ends up thinking the window needs to be much wider than it should be.
163 // use resizeTo and make up our measurements...
164 //sizeToContent();
165
166 // Use the wider of the alert groove and the folderSummaryInfo box, then
167 // add on the width of alertImageBox + some small amount of fudge. For the height,
168 // just use the size of the alertBox, that appears to be pretty accurate.
169 var windowWidth = Math.max (document.getBoxObjectFor(document.getElementById('alertGroove')).width,
170 document.getBoxObjectFor(document.getElementById('folderSummaryInfo')).width);
171 resizeTo(windowWidth + document.getBoxObjectFor(document.getElementById('alertImageBox')).width + 30,
172 document.getBoxObjectFor(document.getElementById('alertBox')).height + 10);
173
174 // leftover hack to get the window properly hidden when we first open it
175 if (aMoveOffScreen)
176 window.outerHeight = 1;
177
178 // Determine position and move window
179 var x = gOrigin & LEFT ? screen.availLeft :
180 (screen.availLeft + screen.availWidth - window.outerWidth);
181 var y = gOrigin & TOP ? screen.availTop :
182 (screen.availTop + screen.availHeight - window.outerHeight);
183 window.moveTo(x, y);
184 }
185
fadeOpen
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
186 function fadeOpen()
187 {
188 var alertContainer = document.getElementById('alertContainer');
189 var newOpacity = parseFloat(window.getComputedStyle(alertContainer, "").opacity) + gFadeIncrement;
190 alertContainer.style.opacity = newOpacity;
191
192 if (newOpacity < 1.0)
193 setTimeout(fadeOpen, gSlideTime);
194 else // switch gears and start closing the alert
195 setTimeout(fadeClose, gOpenTime);
196 }
197
fadeClose
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
198 function fadeClose()
199 {
200 var alertContainer = document.getElementById('alertContainer');
201 var newOpacity = parseFloat(window.getComputedStyle(alertContainer, "").opacity) - gFadeIncrement;
202 alertContainer.style.opacity = newOpacity;
203
204 if (newOpacity <= 0)
205 closeAlert();
206 else
207 setTimeout(fadeClose, gSlideTime);
208 }
209
closeAlert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
210 function closeAlert()
211 {
212 if (gAlertListener)
213 gAlertListener.observe(null, "alertfinished", "");
214 window.close();
215 }