6 if (typeof foldersync ==
'undefined') {
24 _showNotifications:
false,
27 _listener:
function(state,
object) {
28 if (state.event ==
"started")
29 foldersync.central._updateSPNode(
true);
30 var error = foldersync.sync.generateErrorMessage(state);
31 if ((state.event ==
"completed") ||
32 (state.event ==
"cancelled") ||
34 foldersync.central._updateSPNode(
false);
37 if (!foldersync.central._showNotifications)
39 var
msg = error ? error.error : foldersync.central.
40 getLocaleString(
"status.completed");
41 msg +=
": " +
object.sync.targetFolder;
42 var gNotify = document.getElementById(
"application-notificationbox");
44 this.logEvent(
"central",
"Application's notificationbox is not " +
45 "avaiable", 1,
"chrome://foldersync/content/central.js");
48 var level = error ? (error.fatal ? 8 : 5) : 2;
49 gNotify.appendNotification(msg,
51 "chrome://foldersync/skin/node.png",
56 foldersync.central.showDialog(
57 error.error, error.message);
59 label: foldersync.central.
61 "notification.details"),
69 foldersync.central.logEvent(
"central",
"Central controller " +
70 "initialisation started.", 5);
73 this._OS =
window.navigator.platform;
75 this._strings = document.getElementById(
"foldersync-central-strings");
78 foldersync.preferences.onLoad(e);
79 foldersync.sync.onLoad(e);
82 this._setupServicePaneNode();
85 var UIprefs = foldersync.preferences.getUIPrefs();
86 this._showNotifications = UIprefs.notifications.isEnabled;
89 foldersync.sync.addListener(this._listener);
92 foldersync.central.logEvent(
"central",
"Central controller started.", 4);
94 foldersync.central.logEvent(
"central",
95 "Startup of Central controller failed:\n\n" +
97 "chrome://foldersync/content/central.js",
103 foldersync.central.logEvent(
"central",
"Central controller " +
104 "shutdown started.", 5);
106 foldersync.sync.removeListener(this._listener);
108 foldersync.preferences.onUnload(e);
109 foldersync.sync.onUnload(e);
111 foldersync.central.logEvent(
"central",
"Central controller stopped.", 4);
126 logEvent:
function(
module,
msg, type, srcFile, srcLine){
128 if (foldersync.preferences.getEvtLogLevel() < type)
131 var msgStr =
"FolderSync: Event raised in '" +
module +
"':\n" +
msg;
133 var consoleService = Components.classes[
"@mozilla.org/consoleservice;1"].
134 getService(Components.interfaces.nsIConsoleService);
139 var
message = Components.classes[
"@mozilla.org/scripterror;1"].
144 srcLine == 0 ?
null : srcLine,
146 type != 3 ? 0x0 : 0x1 ,
148 consoleService.logMessage(message);
151 consoleService.logStringMessage(msgStr);
158 getLocaleString:
function(
string){
160 return this._strings.getString(
string);
162 this.logEvent(
"central",
"Getting locale string '"+
string+
"' failed:" +
163 "\n\n" + e, 1,
"chrome://foldersync/content/central.js",
174 getMainLibaray:
function(){
175 foldersync.central.logEvent(
"central",
"Get main library", 4);
178 [
"@songbirdnest.com/Songbird/library/Manager;1"].
181 var libraries=sbILibraryManager.getLibraries();
182 var mLibrary = sbILibraryManager.mainLibrary;
184 return {
name: mLibrary.name, guid: mLibrary.guid};
195 getPlaylists:
function(onlyMain, onlyEditable){
196 foldersync.central.logEvent(
"central",
"Get playlists:\n" +
197 "in main library only: " + onlyMain +
"\n" +
198 "editable by user only: " + onlyEditable, 4);
203 [
"@songbirdnest.com/Songbird/library/Manager;1"].
206 var libraries=sbILibraryManager.getLibraries();
207 var crtLibrary = sbILibraryManager.mainLibrary;
212 result.push({
name: crtLibrary.name, guid:crtLibrary.guid});
213 foldersync.central.logEvent(
"central",
"Found Library:\n" +
214 "Name: " + crtLibrary.name +
"\n" +
215 "GUID: " + crtLibrary.guid, 5);
217 var libView = crtLibrary.createView();
218 var libFilters = libView.cascadeFilterSet;
220 libFilters.appendSearch(
new Array(
"*"), 1);
221 libFilters.appendFilter(
"http://songbirdnest.com/data/1.0#isList");
222 libFilters.set(1,
new Array(
"1"), 1);
223 for (var
i = 0;
i < libView.length;
i++){
225 var pList=libView.getItemByIndex(
i);
228 if (pList.name && (pList.name !=
"") && (pList.name !=
" ") &&
229 (pList.type !=
"smart")){
230 result.push({
name: pList.name, guid:pList.guid});
231 foldersync.central.logEvent(
"central",
"Found Playlist:\n" +
232 "Name: " + pList.name +
"\n" +
233 "GUID: " + pList.guid, 5);
236 this.logEvent(
"central",
"Getting playlist failed:\n\n" +
237 e, 2,
"chrome://foldersync/content/central.js",
243 if (onlyMain || (!libraries.hasMoreElements()))
246 crtLibrary = libraries.getNext();
249 this.logEvent(
"central",
"Getting playlists failed:\n\n" +
250 e, 1,
"chrome://foldersync/content/central.js",
259 getPlaylistByGUID:
function(guid){
260 foldersync.central.logEvent(
"central",
"Search for playlist " + guid, 4);
265 [
"@songbirdnest.com/Songbird/library/Manager;1"].
268 var libraries=sbILibraryManager.getLibraries();
269 var crtLibrary = sbILibraryManager.mainLibrary;
274 if (crtLibrary.guid == guid)
277 var libView = crtLibrary.createView();
278 var libFilters = libView.cascadeFilterSet;
280 libFilters.appendSearch(
new Array(
"*"), 1);
281 libFilters.appendFilter(
"http://songbirdnest.com/data/1.0#isList");
282 libFilters.set(1,
new Array(
"1"), 1);
283 for (var
i = 0;
i < libView.length;
i++){
285 var pList=libView.getItemByIndex(
i);
286 if (pList.guid == guid)
289 this.logEvent(
"central",
"Searching playlist failed:\n\n" +
290 e, 2,
"chrome://foldersync/content/central.js",
296 if (!libraries.hasMoreElements())
299 crtLibrary = libraries.getNext();
302 this.logEvent(
"central",
"Searching playlists failed:\n\n" +
303 e, 1,
"chrome://foldersync/content/central.js",
306 this.logEvent(
"central",
"Playlist " + guid +
" not found.",
307 2,
"chrome://foldersync/content/central.js");
320 showDialog:
function(error,
message){
321 foldersync.central.logEvent(
"central",
"Open Error Dialog:\n" +
322 "Error: " + error +
"\n" +
325 window.openDialog(
"chrome://foldersync/content/dialogs/error.xul",
326 "foldersync-error-dialog",
327 "dialog=yes,modal=no,alwaysRaised=yes," +
328 "centerscreen=yes,resizable=yes,dependent=yes",
331 this.logEvent(
"central",
"Opening Error Dialog failed:\n\n" +
332 e, 1,
"chrome://foldersync/content/central.js",
338 _setupServicePaneNode :
function() {
339 foldersync.central.logEvent(
"central",
"Setup Service Pane Node", 4);
341 var dtSB_NS =
'http://songbirdnest.com/data/1.0#';
342 var dtSP_NS =
'http://songbirdnest.com/rdf/servicepane#';
343 var dtSC_NS_DT =
"http://songbirdnest.com/data/1.0#";
345 var SPS =
Cc[
"@songbirdnest.com/servicepane/service;1"]
346 .getService(
Ci.sbIServicePaneService);
348 if (SPS.getNode(
"SB:MainLib:FolderSync")){
349 this.logEvent(
"central",
"Wasn't able to setup Service Pane Node:\n\n" +
350 "Node exists already", 3,
351 "chrome://foldersync/content/central.js");
355 var libNode = SPS.getNode(
"urn:library:" + this.getMainLibaray().guid);
357 this.logEvent(
"central",
"Wasn't able to setup Service Pane Node:\n\n" +
358 "Main Library's node not found", 1,
359 "chrome://foldersync/content/central.js");
364 var foldersyncNode = SPS.createNode();
365 foldersyncNode.id =
"SB:MainLib:FolderSync";
366 foldersyncNode.url =
"chrome://foldersync/content/accesspane.xul";
367 var tNo = document.getElementById(
"foldersync-central-branding-tab-title");
368 foldersyncNode.name = tNo.getAttribute(
"value");
369 foldersyncNode.editable =
false;
370 foldersyncNode.setAttributeNS(dtSP_NS,
372 "foldersync@rsjtdrjgfuzkfg.com");
373 foldersyncNode.image =
'chrome://foldersync/skin/node.png';
374 libNode.appendChild(foldersyncNode);
380 _updateSPNode:
function(working){
382 var SPS =
Cc[
"@songbirdnest.com/servicepane/service;1"]
383 .getService(
Ci.sbIServicePaneService);
385 var spNode = SPS.getNode(
"SB:MainLib:FolderSync");
387 this.logEvent(
"central",
"Wasn't able to update node:\n\n" +
388 "FolderSync's node not found", 1,
389 "chrome://foldersync/content/central.js");
392 spNode.image = working ?
'chrome://foldersync/skin/node-working.png'
393 :
'chrome://foldersync/skin/node.png';
397 registerUI:
function(){
398 foldersync.central.logEvent(
"central",
"Register UI", 4);
400 var UIprefs = foldersync.preferences.getUIPrefs();
401 if (UIprefs.notifications.onlyExclusive)
402 this._showNotifications =
false;
406 unregisterUI:
function(){
407 foldersync.central.logEvent(
"central",
"Unregister UI", 4);
409 var UIprefs = foldersync.preferences.getUIPrefs();
410 if ((this._numUI == 0) && UIprefs.notifications.isEnabled)
411 this._showNotifications =
true;
416 window.addEventListener(
"load",
418 foldersync.central.onLoad(e);
421 window.addEventListener(
"unload",
423 foldersync.central.onUnload(e);
getService(Ci.sbIFaceplateManager)
Manages the lifecycle of libraries in the system.
this _contentSandbox label
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i