!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * William A. ("PowerGUI") Law <law@netscape.com>
25 * Scott MacGregor <mscott@netscape.com>
26 * jean-Francois Ducarroz <ducarroz@netscape.com>
27 * Žiga Sancin <bisi@pikslar.com>
28 *
29 * Alternatively, the contents of this file may be used under the terms of
30 * either of the GNU General Public License Version 2 or later (the "GPL"),
31 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
40 *
41 * ***** END LICENSE BLOCK ***** */
42
43 var msgCompDeliverMode = Components.interfaces.nsIMsgCompDeliverMode;
44
45 // dialog is just an array we'll use to store various properties from the dialog document...
46 var dialog;
47
48 // the msgProgress is a nsIMsgProgress object
49 var msgProgress = null;
50
51 // random global variables...
52 var itsASaveOperation = false;
53 var gSendProgressStringBundle;
54
55 // all progress notifications are done through the nsIWebProgressListener implementation...
56 var progressListener = {
onStateChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
58 {
59 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_START)
60 {
61 // Put progress meter in undetermined mode.
62 dialog.progress.setAttribute("mode", "undetermined");
63 }
64
65 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
66 {
67 // we are done sending/saving the message...
68 // Indicate completion in status area.
69 var msg;
70 if (itsASaveOperation)
71 msg = gSendProgressStringBundle.getString("messageSaved");
72 else
73 msg = gSendProgressStringBundle.getString("messageSent");
74 dialog.status.setAttribute("value", msg);
75
76 // Put progress meter at 100%.
77 dialog.progress.setAttribute("value", 100);
78 dialog.progress.setAttribute("mode", "normal");
79 var percentMsg = gSendProgressStringBundle.getFormattedString("percentMsg", [100]);
80 dialog.progressText.setAttribute("value", percentMsg);
81
82 window.close();
83 }
84 },
85
onProgressChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
86 onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
87 {
88 // Calculate percentage.
89 var percent;
90 if (aMaxTotalProgress > 0)
91 {
92 percent = Math.round(aCurTotalProgress / aMaxTotalProgress * 100);
93 if (percent > 100)
94 percent = 100;
95
96 dialog.progress.removeAttribute("mode");
97
98 // Advance progress meter.
99 dialog.progress.setAttribute("value", percent);
100
101 // Update percentage label on progress meter.
102 var percentMsg = gSendProgressStringBundle.getFormattedString("percentMsg", [percent]);
103 dialog.progressText.setAttribute("value", percentMsg);
104 }
105 else
106 {
107 // Progress meter should be barber-pole in this case.
108 dialog.progress.setAttribute("mode", "undetermined");
109 // Update percentage label on progress meter.
110 dialog.progressText.setAttribute("value", "");
111 }
112 },
113
onLocationChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
114 onLocationChange: function(aWebProgress, aRequest, aLocation)
115 {
116 // we can ignore this notification
117 },
118
onStatusChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
119 onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
120 {
121 if (aMessage != "")
122 dialog.status.setAttribute("value", aMessage);
123 },
124
onSecurityChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
125 onSecurityChange: function(aWebProgress, aRequest, state)
126 {
127 // we can ignore this notification
128 },
129
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
130 QueryInterface : function(iid)
131 {
132 if (iid.equals(Components.interfaces.nsIWebProgressListener) ||
133 iid.equals(Components.interfaces.nsISupportsWeakReference) ||
134 iid.equals(Components.interfaces.nsISupports))
135 return this;
136
137 throw Components.results.NS_NOINTERFACE;
138 }
139 };
140
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
141 function onLoad()
142 {
143 // Set global variables.
144 var subject = "";
145 gSendProgressStringBundle = document.getElementById("sendProgressStringBundle");
146 msgProgress = window.arguments[0];
147 if (window.arguments[1])
148 {
149 var progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIMsgComposeProgressParams)
150 if (progressParams)
151 {
152 itsASaveOperation = (progressParams.deliveryMode != msgCompDeliverMode.Now);
153 subject = progressParams.subject;
154 }
155 }
156
157 if (!msgProgress)
158 {
159 dump("Invalid argument to sendProgress.xul\n");
160 window.close()
161 return;
162 }
163
164 dialog = {};
165 dialog.status = document.getElementById("dialog.status");
166 dialog.progress = document.getElementById("dialog.progress");
167 dialog.progressText = document.getElementById("dialog.progressText");
168
169 // set our web progress listener on the helper app launcher
170 msgProgress.registerListener(progressListener);
171 moveToAlertPosition();
172
173 var prefix = itsASaveOperation ? "titlePrefixSave" : "titlePrefixSend";
174 document.title = gSendProgressStringBundle.getString(prefix) + " " + subject;
175 }
176
onUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
177 function onUnload()
178 {
179 if (msgProgress)
180 {
181 try
182 {
183 msgProgress.unregisterListener(progressListener);
184 msgProgress = null;
185 } catch (e) {}
186 }
187 }
188
189 // If the user presses cancel, tell the app launcher and close the dialog...
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
190 function onCancel ()
191 {
192 // Cancel app launcher.
193 try
194 {
195 msgProgress.processCanceledByUser = true;
196 } catch (e)
197 {
198 return true;
199 }
200
201 // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
202 return false;
203 }