jobProgress.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
34 var JobProgressDialog = {
35 
36  // The sbIJobProgress interface to track
37  _job: null,
38 
39  // UI elements
40  _label: null,
41  _progressMeter: null,
42  _errorContainer: null,
43  _errorList: null,
44  _cancelButton: null,
45 
46 
50  onLoad: function JobProgressDialog_onLoad() {
51  // The first window argument can either be a |nsIDialogParamBlock| or a
52  // |nsIArray| object (i.e. from |WindowUtils.openDialog()|).
53  var argArray = null;
54  if (window.arguments[0] instanceof Ci.nsIDialogParamBlock) {
55  argArray = window.arguments[0].objects;
56  }
57  else if (window.arguments[0] instanceof Ci.nsIArray) {
58  argArray = window.arguments[0];
59  }
60  else {
61  throw Cr.NS_ERROR_INVALID_ARG;
62  }
63 
64  this._job = argArray.queryElementAt(0, Ci.sbIJobProgress);
65 
66  if (this._job.status == Ci.sbIJobProgress.STATUS_SUCCEEDED) {
67  window.close();
68  return;
69  }
70 
71  this._job.addJobProgressListener(this);
72 
73  this._description = document.getElementById("jobprogress_status_desc");
74  this._progressMeter = document.getElementById("jobprogress_progressmeter");
75  this._errorContainer = document.getElementById("jobprogress_error_box");
76  this._errorList = document.getElementById("jobprogress_error_list");
77 
78  // Show cancel if allowed
79  if (this._job instanceof Ci.sbIJobCancelable) {
80  document.documentElement.buttons = "cancel";
81  this._cancelButton = document.documentElement.getButton("cancel");
82  }
83 
84  // Initialize the UI
85  this.onJobProgress();
86  },
87 
91  onUnLoad: function JobProgressDialog_onUnLoad() {
92  try {
93  this._job.removeJobProgressListener(this);
94  } catch (e) {
95  // Failing to remove is fine, as the job may have cleared listeners
96  }
97  this._job = null;
98  },
99 
103  onCancel: function JobProgressDialog_onUnLoad() {
104  this._job.cancel();
105  window.close();
106  },
107 
111  onJobProgress: function JobProgressDialog_onJobProgress(aJob) {
112  this._updateProgressUI();
113 
114  if (this._job.status == Ci.sbIJobProgress.STATUS_SUCCEEDED) {
115  window.close();
116  } else if (this._job.status == Ci.sbIJobProgress.STATUS_FAILED) {
117 
118  // If there is a main error summary, show the error messages
119  if (this._job.statusText) {
120  document.documentElement.buttons = "accept";
121  this._showErrors();
122  } else {
123  // Otherwise just close
124  window.close();
125  }
126  } else if (this._job.blocked) {
127  // Close window to prevent blocking the UI.
128  //XXXeps should only do this if dialog is modal.
129  window.close();
130  }
131  },
132 
136  _updateProgressUI: function JobProgressDialog__updateUI() {
137  this._formatDescription(this._description, this._job);
138  this._setTitle(this._job.titleText);
139 
140  if (this._cancelButton) {
141  var cancelable = this._job.canCancel;
142  if (this._cancelButton.disabled == cancelable) {
143  this._cancelButton.disabled = !cancelable;
144  }
145  }
146 
147  if (this._job.total <= 0) {
148  this._progressMeter.mode = "undetermined";
149  } else {
150  this._progressMeter.mode = "determined";
151 
152  // Songbird has a special modified progress meter.
153  // We allow max > 100, but there are some crazy bugs
154  // if max goes too high.
155  if (this._job.total < 10000) {
156  this._progressMeter.max = this._job.total;
157  this._progressMeter.value = this._job.progress;
158  } else {
159  this._progressMeter.max = 10000;
160  this._progressMeter.value = Math.round((this._job.progress / this._job.total) * 10000);
161  }
162  }
163 
164  // If the content is too big for the window (or the window has just loaded)
165  // then resize the window.
166  // This madness is needed because calling sizeToContent twice with no
167  // change in dimensions results 1px of bonus width.
168  // See https://bugzilla.mozilla.org/show_bug.cgi?id=230959
169  if (window.innerHeight < 10 ||
170  window.innerHeight != document.documentElement.boxObject.height) {
171  setTimeout(function() { window.sizeToContent(); }, 50);
172  }
173  },
174 
178  _showErrors: function () {
179  this._progressMeter.hidden = true;
180  this._errorContainer.hidden = false;
181 
182  var messages = this._job.getErrorMessages();
183  var message;
184  while (messages.hasMore()) {
185  message = unescape(messages.getNext());
186  var item = this._errorList.appendItem(message);
187  item.setAttribute("crop", "center");
188  item.setAttribute("tooltiptext", message);
189  }
190 
191  if (this._errorList.hasAttribute("maxrows")) {
192  rows = parseInt(this._errorList.getAttribute("maxrows"));
193  }
194  else {
195  rows = 4;
196  }
197  this._errorList.setAttribute("rows", Math.min(rows, this._job.errorCount));
198  },
199 
203  _setTitle: function JobProgressDialog__setTitle(aTitle) {
204  if (document.title == aTitle) {
205  return;
206  }
207 
208  document.title = aTitle;
209 
210  // If this dialog is going to be shown on Mac (i.e. sheets) and the current
211  // skin is running showChrome=true, use the inline progress title.
212  var sysInfo = Components.classes["@mozilla.org/system-info;1"]
213  .getService(Components.interfaces.nsIPropertyBag2);
214  var platform = sysInfo.getProperty("name");
215  var isPlucked = Application.prefs.getValue("songbird.accessibility.enabled", false);
216  var titleBox = document.getElementById("jobprogress_title_box");
217  if (platform == "Darwin" && isPlucked && window.opener) {
218  var macSheetTitle = document.getElementById("jobprogress_title_desc");
219  if (macSheetTitle) {
220  macSheetTitle.value = aTitle;
221  }
222  }
223  else {
224  titleBox.hidden = true;
225  var windowTitle = document.getElementById('dialog-titlebar');
226  if (windowTitle) {
227  windowTitle.title = aTitle;
228  }
229  }
230  },
231 
236  _formatDescription: function(aDescription, aJob) {
237  var crop = false;
238  if (aJob instanceof Components.interfaces.sbIJobProgressUI) {
239  if (aJob.crop) {
240  aDescription.setAttribute("crop", aJob.crop);
241  crop = true;
242  } else {
243  aDescription.removeAttribute("crop");
244  }
245  }
246  var lines = aJob.statusText.split("\n");
247  if (lines.length > 1) {
248  aDescription.textContent = "";
249  for (var i = 0; i < lines.length; i++) {
250  aDescription.appendChild(document.createTextNode(lines[i]));
251  aDescription.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml","html:br"));
252  }
253  } else {
254  if (crop) {
255  aDescription.value = lines[0];
256  } else {
257  aDescription.textContent = lines[0];
258  }
259  }
260  }
261 }
262 
var Application
Definition: sbAboutDRM.js:37
let window
Lastfm onLoad
Definition: mini.js:36
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function onCancel()
Definition: safeMode.js:129
GstMessage * message
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
_getSelectedPageStyle s i