!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 41 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/printing/content/printProgress.js"
2
3 // dialog is just an array we'll use to store various properties from the dialog document...
4 var dialog;
5
6 // the printProgress is a nsIPrintProgress object
7 var printProgress = null;
8
9 // random global variables...
10 var targetFile;
11
12 var docTitle = "";
13 var docURL = "";
14 var progressParams = null;
15 var switchUI = true;
16
elipseString
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
17 function elipseString(aStr, doFront)
18 {
19 if (aStr.length > 3 && (aStr.substr(0, 3) == "..." || aStr.substr(aStr.length-4, 3) == "...")) {
20 return aStr;
21 }
22
23 var fixedLen = 64;
24 if (aStr.length > fixedLen) {
25 if (doFront) {
26 var endStr = aStr.substr(aStr.length-fixedLen, fixedLen);
27 var str = "..." + endStr;
28 return str;
29 } else {
30 var frontStr = aStr.substr(0, fixedLen);
31 var str = frontStr + "...";
32 return str;
33 }
34 }
35 return aStr;
36 }
37
38 // all progress notifications are done through the nsIWebProgressListener implementation...
39 var progressListener = {
onStateChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
40 onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
41 {
42 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_START)
43 {
44 // Put progress meter in undetermined mode.
45 // dialog.progress.setAttribute( "value", 0 );
46 dialog.progress.setAttribute( "mode", "undetermined" );
47 }
48
49 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
50 {
51 // we are done printing
52 // Indicate completion in title area.
53 var msg = getString( "printComplete" );
54 dialog.title.setAttribute("value", msg);
55
56 // Put progress meter at 100%.
57 dialog.progress.setAttribute( "value", 100 );
58 dialog.progress.setAttribute( "mode", "normal" );
59 var percentPrint = getString( "progressText" );
60 percentPrint = replaceInsert( percentPrint, 1, 100 );
61 dialog.progressText.setAttribute("value", percentPrint);
62 window.close();
63 }
64 },
65
onProgressChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
66 onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
67 {
68 if (switchUI)
69 {
70 dialog.tempLabel.setAttribute("hidden", "true");
71 dialog.progress.setAttribute("hidden", "false");
72 dialog.cancel.setAttribute("disabled", "false");
73
74 var progressLabel = getString("progress");
75 if (progressLabel == "") {
76 progressLabel = "Progress:"; // better than nothing
77 }
78 switchUI = false;
79 }
80
81 if (progressParams)
82 {
83 var docTitleStr = elipseString(progressParams.docTitle, false);
84 if (docTitleStr != docTitle) {
85 docTitle = docTitleStr;
86 dialog.title.value = docTitle;
87 }
88 var docURLStr = progressParams.docURL;
89 if (docURLStr != docURL && dialog.title != null) {
90 docURL = docURLStr;
91 if (docTitle == "") {
92 dialog.title.value = elipseString(docURLStr, true);
93 }
94 }
95 }
96
97 // Calculate percentage.
98 var percent;
99 if ( aMaxTotalProgress > 0 )
100 {
101 percent = Math.round( (aCurTotalProgress*100)/aMaxTotalProgress );
102 if ( percent > 100 )
103 percent = 100;
104
105 dialog.progress.removeAttribute( "mode");
106
107 // Advance progress meter.
108 dialog.progress.setAttribute( "value", percent );
109
110 // Update percentage label on progress meter.
111 var percentPrint = getString( "progressText" );
112 percentPrint = replaceInsert( percentPrint, 1, percent );
113 dialog.progressText.setAttribute("value", percentPrint);
114 }
115 else
116 {
117 // Progress meter should be barber-pole in this case.
118 dialog.progress.setAttribute( "mode", "undetermined" );
119 // Update percentage label on progress meter.
120 dialog.progressText.setAttribute("value", "");
121 }
122 },
123
onLocationChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
124 onLocationChange: function(aWebProgress, aRequest, aLocation)
125 {
126 // we can ignore this notification
127 },
128
onStatusChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
129 onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
130 {
131 if (aMessage != "")
132 dialog.title.setAttribute("value", aMessage);
133 },
134
onSecurityChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
135 onSecurityChange: function(aWebProgress, aRequest, state)
136 {
137 // we can ignore this notification
138 },
139
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
140 QueryInterface : function(iid)
141 {
142 if (iid.equals(Components.interfaces.nsIWebProgressListener) || iid.equals(Components.interfaces.nsISupportsWeakReference))
143 return this;
144
145 throw Components.results.NS_NOINTERFACE;
146 }
147 };
148
getString
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
149 function getString( stringId ) {
150 // Check if we've fetched this string already.
151 if (!(stringId in dialog.strings)) {
152 // Try to get it.
153 var elem = document.getElementById( "dialog.strings."+stringId );
154 try {
155 if ( elem
156 &&
157 elem.childNodes
158 &&
159 elem.childNodes[0]
160 &&
161 elem.childNodes[0].nodeValue ) {
162 dialog.strings[ stringId ] = elem.childNodes[0].nodeValue;
163 } else {
164 // If unable to fetch string, use an empty string.
165 dialog.strings[ stringId ] = "";
166 }
167 } catch (e) { dialog.strings[ stringId ] = ""; }
168 }
169 return dialog.strings[ stringId ];
170 }
171
loadDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
172 function loadDialog()
173 {
174 }
175
replaceInsert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
176 function replaceInsert( text, index, value ) {
177 var result = text;
178 var regExp = new RegExp( "#"+index );
179 result = result.replace( regExp, value );
180 return result;
181 }
182
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
183 function onLoad() {
184
185 // Set global variables.
186 printProgress = window.arguments[0];
187 if (window.arguments[1])
188 {
189 progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
190 if (progressParams)
191 {
192 docTitle = elipseString(progressParams.docTitle, false);
193 docURL = elipseString(progressParams.docURL, true);
194 }
195 }
196
197 if ( !printProgress ) {
198 dump( "Invalid argument to printProgress.xul\n" );
199 window.close()
200 return;
201 }
202
203 dialog = new Object;
204 dialog.strings = new Array;
205 dialog.title = document.getElementById("dialog.title");
206 dialog.titleLabel = document.getElementById("dialog.titleLabel");
207 dialog.progress = document.getElementById("dialog.progress");
208 dialog.progressText = document.getElementById("dialog.progressText");
209 dialog.progressLabel = document.getElementById("dialog.progressLabel");
210 dialog.tempLabel = document.getElementById("dialog.tempLabel");
211 dialog.cancel = document.getElementById("cancel");
212
213 dialog.progress.setAttribute("hidden", "true");
214 dialog.cancel.setAttribute("disabled", "true");
215
216 var progressLabel = getString("preparing");
217 if (progressLabel == "") {
218 progressLabel = "Preparing..."; // better than nothing
219 }
220 dialog.tempLabel.value = progressLabel;
221
222 dialog.title.value = docTitle;
223
224 // Set up dialog button callbacks.
225 var object = this;
anon:226:22
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
226 doSetOKCancel("", function () { return object.onCancel();});
227
228 // Fill dialog.
229 loadDialog();
230
231 // set our web progress listener on the helper app launcher
232 printProgress.registerListener(progressListener);
233 moveToAlertPosition();
234 //We need to delay the set title else dom will overwrite it
235 window.setTimeout(doneIniting, 500);
236 }
237
onUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
238 function onUnload()
239 {
240 if (printProgress)
241 {
242 try
243 {
244 printProgress.unregisterListener(progressListener);
245 printProgress = null;
246 }
247
248 catch( exception ) {}
249 }
250 }
251
252 // If the user presses cancel, tell the app launcher and close the dialog...
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
253 function onCancel ()
254 {
255 // Cancel app launcher.
256 try
257 {
258 printProgress.processCanceledByUser = true;
259 }
260 catch( exception ) {return true;}
261
262 // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
263 return false;
264 }
265
doneIniting
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
266 function doneIniting()
267 {
268 printProgress.doneIniting();
269 }