!import
1 //@line 39 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/printing/content/printPreviewProgress.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
elipseString
16 function elipseString(aStr, doFront)
17 {
18 if (aStr.length > 3 && (aStr.substr(0, 3) == "..." || aStr.substr(aStr.length-4, 3) == "..."))
19 return aStr;
20
21 var fixedLen = 64;
22 if (aStr.length <= fixedLen)
23 return aStr;
24
25 if (doFront)
26 return "..." + aStr.substr(aStr.length-fixedLen, fixedLen);
27
28 return aStr.substr(0, fixedLen) + "...";
29 }
30
31 // all progress notifications are done through the nsIWebProgressListener implementation...
32 var progressListener = {
33
onStateChange
34 onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus)
35 {
36 if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
37 window.close();
38 },
39
onProgressChange
40 onProgressChange: function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
41 {
42 if (!progressParams)
43 return;
44 var docTitleStr = elipseString(progressParams.docTitle, false);
45 if (docTitleStr != docTitle) {
46 docTitle = docTitleStr;
47 dialog.title.value = docTitle;
48 }
49 var docURLStr = elipseString(progressParams.docURL, true);
50 if (docURLStr != docURL && dialog.title != null) {
51 docURL = docURLStr;
52 if (docTitle == "")
53 dialog.title.value = docURLStr;
54 }
55 },
56
onLocationChange
57 onLocationChange: function (aWebProgress, aRequest, aLocation) {},
onSecurityChange
58 onSecurityChange: function (aWebProgress, aRequest, state) {},
59
onStatusChange
60 onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage)
61 {
62 if (aMessage)
63 dialog.title.setAttribute("value", aMessage);
64 },
65
QueryInterface
66 QueryInterface: function (iid)
67 {
68 if (iid.equals(Components.interfaces.nsIWebProgressListener) || iid.equals(Components.interfaces.nsISupportsWeakReference))
69 return this;
70 throw Components.results.NS_NOINTERFACE;
71 }
72 }
73
onLoad
74 function onLoad() {
75 // Set global variables.
76 printProgress = window.arguments[0];
77 if (window.arguments[1]) {
78 progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
79 if (progressParams) {
80 docTitle = elipseString(progressParams.docTitle, false);
81 docURL = elipseString(progressParams.docURL, true);
82 }
83 }
84
85 if (!printProgress) {
86 dump( "Invalid argument to printPreviewProgress.xul\n" );
87 window.close()
88 return;
89 }
90
91 dialog = new Object;
92 dialog.strings = new Array;
93 dialog.title = document.getElementById("dialog.title");
94 dialog.titleLabel = document.getElementById("dialog.titleLabel");
95
96 dialog.title.value = docTitle;
97
98 // set our web progress listener on the helper app launcher
99 printProgress.registerListener(progressListener);
100 moveToAlertPosition();
101
102 //We need to delay the set title else dom will overwrite it
103 window.setTimeout(doneIniting, 100);
104 }
105
onUnload
106 function onUnload()
107 {
108 if (!printProgress)
109 return;
110 try {
111 printProgress.unregisterListener(progressListener);
112 printProgress = null;
113 }
114 catch(e) {}
115 }
116
getString
117 function getString (stringId) {
118 // Check if we've fetched this string already.
119 if (!(stringId in dialog.strings)) {
120 // Try to get it.
121 var elem = document.getElementById( "dialog.strings."+stringId);
122 try {
123 if (elem && elem.childNodes && elem.childNodes[0] &&
124 elem.childNodes[0].nodeValue)
125 dialog.strings[stringId] = elem.childNodes[0].nodeValue;
126 // If unable to fetch string, use an empty string.
127 else
128 dialog.strings[stringId] = "";
129 } catch (e) { dialog.strings[stringId] = ""; }
130 }
131 return dialog.strings[stringId];
132 }
133
134 // If the user presses cancel, tell the app launcher and close the dialog...
onCancel
135 function onCancel ()
136 {
137 // Cancel app launcher.
138 try {
139 printProgress.processCanceledByUser = true;
140 }
141 catch(e) {return true;}
142
143 // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
144 return false;
145 }
146
doneIniting
147 function doneIniting()
148 {
149 // called by function timeout in onLoad
150 printProgress.doneIniting();
151 }