6 if (typeof playlistfolders ==
'undefined') {
7 var playlistfolders = {};
13 playlistfolders.preferences={
27 playlistfolders.central.logEvent(
"preferences",
"Perference controller " +
28 "initialisation started.", 5);
31 var
prefs = Components.classes[
"@mozilla.org/preferences-service;1"].
32 getService(Components.interfaces.nsIPrefService);
33 this.
_prefs = prefs.getBranch(
"extensions.playlistfolders.");
36 this._root =
JSON.parse(this.
_prefs.getCharPref(
"JSON"));
39 playlistfolders.central.logEvent(
"preferences",
40 "extensions.playlistfolders.JSON " +
41 "is invalid. Fallback to default " +
43 "chrome://playlistfolders/content/" +
48 this._migrateIfNeeded();
50 playlistfolders.central.logEvent(
"preferences",
51 "Preference controller started.", 4);
53 playlistfolders.central.logEvent(
"preferences",
54 "Startup of Preference controller " +
55 "failed:\n\n" + e, 1,
"chrome://" +
56 "playlistfolders/content/" +
57 "preferences.js", e.lineNumber);
62 playlistfolders.central.logEvent(
"preferences",
"Preference controller " +
63 "shutdown started.", 5);
67 playlistfolders.central.logEvent(
"preferences",
68 "Preference controller stopped.", 4);
72 _migrateIfNeeded:
function(){
87 if (!this._root.version){
88 playlistfolders.central.logEvent(
"preferences",
"Migration from fresh " +
90 this._root.version =
"1.0.0.0";
91 this._root.folders = [];
92 var root = this.createFolder(
"");
96 if (this._root.version ==
"0.0.0.0a")
97 this._root.version =
"1.0.0.0";
100 if (this._root.version !=
"1.0.0.0"){
101 playlistfolders.central.logEvent(
"preferences",
"There is no rule to " +
102 "migrate from JSON version " +
103 this._root.version +
". Fallback to " +
104 "empty JSON root.", 2,
"chrome://" +
105 "playlistfolders/content/" +
108 this._migrateIfNeeded();
113 _saveCurrent:
function(){
115 playlistfolders.central.logEvent(
"preferences",
116 "Save JSON preferences", 5);
117 this.
_prefs.setCharPref(
"JSON",
JSON.stringify(
this._root));
119 playlistfolders.central.logEvent(
"preferences",
120 "Saving of JSON preferences failed:" +
121 "\n\n" + e, 1,
"chrome://" +
122 "playlistfolders/content/" +
123 "preferences.js", e.lineNumber);
130 createFolder:
function(
name){
134 GUID: Components.classes[
"@mozilla.org/uuid-generator;1"].
135 getService(Components.interfaces.nsIUUIDGenerator).generateUUID().
142 playlistfolders.central.logEvent(
"preferences",
143 "Create Folder "+result.GUID, 5);
145 this._root.folders.push(result);
147 this.getFolderByGUID(
"{root}").content.push(result.GUID);
151 playlistfolders.central.logEvent(
"preferences",
152 "Adding of folder failed:\n\n" + e, 1,
153 "chrome://playlistfolders/content/" +
154 "preferences.js", e.lineNumber);
163 renameFolder:
function(folder,
name){
164 playlistfolders.central.logEvent(
"preferences",
"Rename folder " +
169 playlistfolders.central.logEvent(
"preferences",
170 "Renaming folder failed:\n\n" + e, 1,
171 "chrome://playlistfolders/content/" +
172 "preferences.js", e.lineNumber);
182 moveFolder:
function(folder, targetF, before){
183 playlistfolders.central.logEvent(
"preferences",
"Move folder " +
188 target = this.getFolderByGUID(
"{root}");
190 for each (var f
in this._root.folders)
191 for (var
i = 0;
i < f.content.length;
i++)
192 if (f.content[
i] == folder.GUID)
193 f.content.splice(
i,1);
197 for each (var guid
in target.content)
202 for each (var f
in target.content){
204 tmp.push(folder.GUID);
209 target.content.push(folder.GUID);
212 playlistfolders.central.logEvent(
"preferences",
213 "Moving folder failed:\n\n" + e, 1,
214 "chrome://playlistfolders/content/" +
215 "preferences.js", e.lineNumber);
225 movePlaylist:
function(pguid, targetF, before){
226 playlistfolders.central.logEvent(
"preferences",
"Move playlist " +
231 target = this.getFolderByGUID(
"{root}");
233 for each (var f
in this._root.folders)
234 for (var
i = 0;
i < f.content.length;
i++)
235 if (f.content[
i] == pguid)
236 f.content.splice(
i,1);
240 for each (var guid
in target.content)
245 for each (var
p in target.content){
252 target.content.push(pguid);
255 playlistfolders.central.logEvent(
"preferences",
256 "Moving playlist failed:\n\n" + e, 1,
257 "chrome://playlistfolders/content/" +
258 "preferences.js", e.lineNumber);
268 removeFolder:
function(folder, recursive){
270 playlistfolders.central.logEvent(
"preferences",
271 "Remove Folder " + folder.GUID, 5);
273 if (folder.content.length){
275 playlistfolders.central.logEvent(
"preferences",
276 "Removing of folder failed:\n\n" +
277 folder.GUID +
" is not empty" +
278 " folder", 1,
"chrome://" +
279 "playlistfolders/content/" +
284 for each (var GUID
in folder.content){
285 if (this.isFolder(GUID)){
286 if (!this.removeFolder(this.getFolderByGUID(GUID),
true))
288 }
else if (this.isPlaylist(GUID)){
289 if (!playlistfolders.central.removePlaylist(GUID))
294 playlistfolders.central.logEvent(
"preferences",
295 "Removing of folder failed:\n\n" +
296 folder.GUID +
" has content " +
297 "that can't get deleted", 1,
298 "chrome://playlistfolders/" +
299 "content/preferences.js");
305 for (var
i = 0;
i < this._root.folders.length;
i++){
306 if (this._root.folders[
i] == folder){
307 this._root.folders.splice(
i,1);
312 for each (var f
in this._root.folders)
313 for (var
i = 0;
i < f.content.length;
i++)
314 if (f.content[
i] == folder.GUID)
315 f.content.splice(
i,1);
318 playlistfolders.central.logEvent(
"preferences",
319 "Removing of folder failed:\n\n" +
320 folder.GUID +
" is no registered" +
321 " folder", 3,
"chrome://" +
322 "playlistfolders/content/" +
327 playlistfolders.central.logEvent(
"preferences",
328 "Removing of folder failed:\n\n" + e, 1,
329 "chrome://playlistfolders/content/" +
330 "preferences.js", e.lineNumber);
339 removePlaylist:
function(playlist, folder){
341 var plists = playlistfolders.preferences.getFolderByGUID(folder).content;
343 for (var
i in plists)
344 if (plists[
i] == playlist){
349 playlistfolders.central.logEvent(
"preferences",
"Playlist to remove " +
350 "not found in parent folder.", 2,
351 "chrome://playlistfolders/content/" +
354 playlistfolders.central.logEvent(
"preferences",
"Playlist " +
355 playlist +
" removed in folder " +
358 playlistfolders.central.logEvent(
"preferences",
359 "Removing of playlist failed:\n\n" + e,
360 1,
"chrome://playlistfolders/content/" +
361 "preferences.js", e.lineNumber);
367 getFolders:
function(){
369 return this._root.folders;
371 playlistfolders.central.logEvent(
"preferences",
372 "Getting Folder list failed:\n\n" + e,
373 1,
"chrome://playlistfolders/content/" +
383 getFolderByGUID:
function(guid){
385 for each (var f
in this._root.folders){
389 playlistfolders.central.logEvent(
"preferences",
390 "Getting folder " + guid +
" failed:" +
391 "\n\n" + guid +
" is no registered " +
392 "folder", 1,
"chrome://" +
393 "playlistfolders/content/" +
396 playlistfolders.central.logEvent(
"preferences",
397 "Getting folder " + guid +
" failed:" +
398 "\n\n" + e, 1,
"chrome://" +
399 "playlistfolders/content/" +
400 "preferences.js", e.lineNumber);
408 isFolder:
function(guid){
410 return guid[0] ==
"{";
416 isPlaylist:
function(guid){
418 return guid[0] !=
"{";
422 isDeleteBypass:
function(){
423 return this.
_prefs.getBoolPref(
"bypassdeletewarning");
427 doDeleteBypass:
function(){
428 this.
_prefs.setBoolPref(
"bypassdeletewarning",
true);
439 getEvtLogLevel:
function(){
443 return Components.classes[
"@mozilla.org/preferences-service;1"].
444 getService(Components.interfaces.nsIPrefService).
445 getBranch(
"extensions.playlistfolders.").getIntPref(
"debugLevel");
getService(Ci.sbIFaceplateManager)
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i