6 if (typeof foldersync ==
'undefined') {
14 foldersync.preferences={
41 foldersync.central.logEvent(
"preferences",
"Perference controller " +
42 "initialisation started.", 5);
45 var
prefs = Components.classes[
"@mozilla.org/preferences-service;1"].
46 getService(Components.interfaces.nsIPrefService);
47 this.
_prefs = prefs.getBranch(
"extensions.FolderSync.");
50 this._root =
JSON.parse(this.
_prefs.getCharPref(
"JSON"));
53 foldersync.central.logEvent(
"preferences",
54 "extensions.FolderSync.JSON is invalid. " +
55 "Fallback to default value.", 2,
56 "chrome://foldersync/content/" +
61 this._migrateIfNeeded();
63 foldersync.central.logEvent(
"preferences",
64 "Preference controller started.", 4);
66 foldersync.central.logEvent(
"preferences",
67 "Startup of Preference controller " +
69 "chrome://foldersync/content/preferences.js",
75 foldersync.central.logEvent(
"preferences",
"Preference controller " +
76 "shutdown started.", 5);
78 for each (var profile
in this._root.profiles)
79 if (profile.temporary)
80 this.removeProfile(profile);
84 foldersync.central.logEvent(
"preferences",
85 "Preference controller stopped.", 4);
89 _migrateIfNeeded:
function(){
104 if (!this._root.version){
105 foldersync.central.logEvent(
"preferences",
"Migration from FolderSync " +
106 "< 3.0.0.0 / fresh install", 4);
107 this._root.version =
"3.0.0.0";
110 this._root.profiles = [];
111 this._root.favorites = [];
112 this._root.defaulttags = {
116 albumartist:
"unknown",
136 this.createProfile(foldersync.central.
137 getLocaleString(
"profile.defaultname"));
140 var migrateFromOld =
false;
142 migrateFromOld = !this.
_prefs.getBoolPref(
"firstrun");
145 foldersync.central.logEvent(
"preferences",
"FolderSync < 3.0.0.0 " +
149 this._root.defaulttags.artist = this.
_prefs.
150 getCharPref(
"defaultTag.artist");
153 this._root.defaulttags.title = this.
_prefs.
154 getCharPref(
"defaultTag.title");
157 this._root.defaulttags.album = this.
_prefs.
158 getCharPref(
"defaultTag.album");
161 this._root.defaulttags.albumartist = this.
_prefs.
162 getCharPref(
"defaultTag.albumartist");
165 this._root.defaulttags.discnumber = this.
_prefs.
166 getCharPref(
"defaultTag.discnumber");
169 this._root.defaulttags.tracknumber = this.
_prefs.
170 getCharPref(
"defaultTag.tracknumber");
173 this._root.defaulttags.genre = this.
_prefs.
174 getCharPref(
"defaultTag.genre");
177 this._root.defaulttags.rating = this.
_prefs.
178 getCharPref(
"defaultTag.rating");
181 this._root.defaulttags.year = this.
_prefs.
182 getCharPref(
"defaultTag.year");
185 this._root.defaulttags.disccount = this.
_prefs.
186 getCharPref(
"defaultTag.disccount");
189 this._root.defaulttags.composer = this.
_prefs.
190 getCharPref(
"defaultTag.composer");
193 this._root.defaulttags.producer = this.
_prefs.
194 getCharPref(
"defaultTag.producer");
198 var dProfile = this.getProfiles()[0];
200 dProfile.structure.isEnabled = this.
_prefs.getBoolPref(
"naming");
203 dProfile.structure.schema = this.
_prefs.getCharPref(
"namingString");
206 dProfile.playlists.isEnabled = this.
_prefs.getBoolPref(
"writeM3U");
209 dProfile.flags.doDelete =
true;
210 dProfile.flags.doDelete = this.
_prefs.getBoolPref(
"enabledelete");
213 dProfile.structure.tnDigits = this.
_prefs.getIntPref(
"trackdigits");
216 dProfile.playlists.splitChar = this.
_prefs.getCharPref(
"SplitChar");
219 dProfile.playlists.doRelativePoint = this.
_prefs.
223 dProfile.playlists.format = this.
_prefs.getBoolPref(
"doExtendedM3U") ?
227 var blChars = this.
_prefs.getCharPref(
"badcharacters").split(
"#");
228 dProfile.advanced.blockedChars =
"";
229 for each (var c
in blChars)
230 dProfile.advanced.blockedChars += c;
233 dProfile.advanced.cutReplaced = this.
_prefs.getBoolPref(
"cutoff");
236 dProfile.flags.doUpdate = this.
_prefs.getBoolPref(
"ChangeCheck");
239 dProfile.structure.doCovers = this.
_prefs.getBoolPref(
"writecover");
242 dProfile.structure.coverSchema = this.
_prefs.
243 getCharPref(
"coverfolder");
246 dProfile.structure.coverFile = this.
_prefs.
247 getCharPref(
"coverfilename");
250 dProfile.playlists.toFolder = this.
_prefs.getCharPref(
"m3ufolder");
253 dProfile.flags.doRockbox = this.
_prefs.getBoolPref(
"RockboxSyncBack");
258 var oldProfiles = this.
_prefs.getCharPref(
"Profiles").split(
";?&?;");
259 if (oldProfiles[0] ==
"")
260 throw "No profile in there";
261 for each (var oProfile
in oldProfiles){
262 var pParts = oProfile.split(
";!&!;");
264 var profile = this.createProfile(unescape(pParts[0]));
267 profile.playlists.splitChar = dProfile.playlists.splitChar;
268 profile.playlists.doRelativePoint = dProfile.playlists.
270 profile.playlists.format = dProfile.playlists.format;
273 profile.advanced.cutReplaced = dProfile.advanced.cutReplaced;
274 profile.advanced.blockedChars = dProfile.advanced.blockedChars;
277 profile.structure.schema = unescape(pParts[1]);
278 profile.structure.isEnabled = unescape(pParts[2]) ==
"true";
279 profile.playlists.isEnabled = unescape(pParts[3]) ==
"true";
280 profile.flags.doDelete = unescape(pParts[4]) ==
"true";
281 profile.structure.tnDigits = unescape(pParts[5])*1;
282 profile.flags.doUpdate = unescape(pParts[6]) ==
"true";
283 if (pParts.length == 7)
285 profile.structure.doCovers = unescape(pParts[7]) ==
"true";
286 profile.structure.coverSchema = unescape(pParts[8]);
287 profile.structure.coverFile = unescape(pParts[9]);
288 profile.playlists.toFolder = unescape(pParts[10]);
289 if (pParts.length == 11)
291 profile.flags.doRockbox = unescape(pParts[11]) ==
"true";
297 var sString = this.
_prefs.getCharPref(
"selections");
298 var sParts = sString.split(
";!&");
299 for each (var part
in sParts){
301 var parts = part.split(
"!;&");
302 var pParts = parts[1].split(
"&!;");
304 for each (var plist
in pParts)
307 var pName = parts.length > 2 ? parts[2] :
null;
308 var profiles = this.getProfiles();
309 var pGUID = dProfile.GUID;
310 for each (var profile
in profiles)
311 if (profile.name == pName)
312 pGUID = profile.GUID;
314 var
sync = foldersync.sync.generateSync(parts[0], pGUID, plists);
315 this.createFavorite(parts[0], sync);
320 var
ui = this.getUIPrefs();
322 var sHelp = ui.show.help;
324 sHelp = this.
_prefs.getBoolPref(
"showHelpLink");
327 sHelp = sHelp || this.
_prefs.getBoolPref(
"showPrefBtn");
329 ui.show.help = sHelp;
337 ui.lastUI.target = this.
_prefs.getCharPref(
"lastfolder");
340 var parts = this.
_prefs.getCharPref(
"lastselection").split(
"&!;");
341 for each (var part
in parts)
343 ui.lastUI.playlists.push(part);
346 var pName = this.
_prefs.getCharPref(
"lastProfileName");
347 var profiles = this.getProfiles();
348 for each (var profile
in profiles)
349 if (profile.name == pName)
350 ui.lastUI.profile = profile;
356 if (this._root.version ==
"3.0.0.0"){
357 foldersync.central.logEvent(
"preferences",
"Migration from 3.0.0.0 " +
359 this._root.version =
"3.0.2.0";
361 if (this._root.ui.lastUI){
362 var profile = this.getProfileByGUID(this._root.ui.lastUI.profile.GUID);
365 profile.temporary =
false;
366 this._root.profiles.push(profile);
368 this._root.ui.lastUI.profile = profile.GUID;
371 for each (var profile
in this.getProfiles()){
372 profile.playlists.isSorted =
false;
373 profile.playlists.sortingScheme =
"%albumartist:a%,%album%,%tracknumber%,%title%";
377 if (this._root.version ==
"3.0.2.0"){
378 foldersync.central.logEvent(
"preferences",
"Migration from 3.0.2.0 " +
380 this._root.version =
"3.0.3.0";
382 this._root.fallbacks = {
388 if (this._root.version !=
"3.0.3.0"){
389 foldersync.central.logEvent(
"preferences",
"There is no rule to " +
390 "migrate from JSON version " +
391 this._root.version +
". Fallback to empty " +
392 "JSON root.", 2,
"chrome://" +
393 "foldersync/content/preferences.js");
395 this._migrateIfNeeded();
400 _saveCurrent:
function(){
402 foldersync.central.logEvent(
"preferences",
403 "Save JSON preferences", 5);
404 this.
_prefs.setCharPref(
"JSON",
JSON.stringify(
this._root));
406 foldersync.central.logEvent(
"preferences",
407 "Saving of JSON preferences failed:\n\n" + e,
409 "chrome://foldersync/content/preferences.js",
415 getProfiles:
function(){
417 return this._root.profiles;
419 foldersync.central.logEvent(
"preferences",
420 "Getting Profile list failed:\n\n" + e, 1,
421 "chrome://foldersync/content/preferences.js",
430 getProfileByGUID:
function(guid){
432 for each (var profile
in this._root.profiles){
433 if (profile.GUID == guid)
436 foldersync.central.logEvent(
"preferences",
437 "Getting Profile " + guid +
" failed:\n\n" +
438 guid +
" is no registered profile", 1,
439 "chrome://foldersync/content/" +
442 foldersync.central.logEvent(
"preferences",
443 "Getting Profile " + guid +
" failed:\n\n" +
445 "chrome://foldersync/content/preferences.js",
454 createProfile:
function(
name){
458 GUID: Components.classes[
"@mozilla.org/uuid-generator;1"].
459 getService(Components.interfaces.nsIUUIDGenerator).generateUUID().
472 schema:
"%artist%/%album%/%title%",
476 coverSchema:
"%album%",
485 doRelativePoint:
true,
491 sortingScheme:
"%albumartist:a%,%album%,%tracknumber%,%title%",
495 blockedChars:
'/\\:*?><|".',
506 foldersync.central.logEvent(
"preferences",
507 "Create Profile "+result.GUID, 5);
509 this._root.profiles.push(result);
512 foldersync.central.logEvent(
"preferences",
513 "Adding of profile failed:\n\n" + e, 1,
514 "chrome://foldersync/content/preferences.js",
523 removeProfile:
function(profile){
525 foldersync.central.logEvent(
"preferences",
526 "Remove Profile "+profile.GUID, 5);
528 for (var
i = 0;
i < this._root.profiles.length;
i++){
529 if (this._root.profiles[
i] == profile){
530 this._root.profiles.splice(
i,1);
535 foldersync.central.logEvent(
"preferences",
536 "Removing of profile failed:\n\n" +
537 profile.GUID +
" is no registered" +
538 " profile", 3,
"chrome://" +
539 "foldersync/content/preferences.js");
541 foldersync.central.logEvent(
"preferences",
542 "Removing of profile failed:\n\n" + e, 1,
543 "chrome://foldersync/content/preferences.js",
549 getFavorites:
function(){
551 return this._root.favorites;
553 foldersync.central.logEvent(
"preferences",
554 "Getting Favorite list failed:\n\n" + e, 1,
555 "chrome://foldersync/content/preferences.js",
564 getFavoriteByGUID:
function(guid){
566 for each (var fav
in this._root.favorites){
567 if (fav.GUID == guid)
570 foldersync.central.logEvent(
"preferences",
571 "Getting Favorite " + guid +
" failed:\n\n" +
572 guid +
" is no registered Favorite", 1,
573 "chrome://foldersync/content/" +
576 foldersync.central.logEvent(
"preferences",
577 "Getting Favorite " + guid +
" failed:\n\n" +
579 "chrome://foldersync/content/preferences.js",
589 createFavorite:
function(
name,
sync){
592 GUID: Components.classes[
"@mozilla.org/uuid-generator;1"].
593 getService(Components.interfaces.nsIUUIDGenerator).generateUUID().
599 foldersync.central.logEvent(
"preferences",
600 "Create Favorite '" + result.name +
"'", 5);
602 this._root.favorites.push(result);
605 foldersync.central.logEvent(
"preferences",
606 "Adding of favorite failed:\n\n" + e, 1,
607 "chrome://foldersync/content/preferences.js",
616 removeFavorite:
function(favorite){
618 foldersync.central.logEvent(
"preferences",
619 "Remove Favorite "+favorite.name, 5);
621 for (var
i = 0;
i < this._root.favorites.length;
i++){
622 if (this._root.favorites[
i] == favorite){
623 this._root.favorites.splice(
i,1);
628 foldersync.central.logEvent(
"preferences",
629 "Removing of favorite failed:\n\n" +
630 "'" + favorite.name +
"' is no " +
631 "registered favorite", 3,
"chrome://" +
632 "foldersync/content/preferences.js");
634 foldersync.central.logEvent(
"preferences",
635 "Removing of favorite failed:\n\n" + e, 1,
636 "chrome://foldersync/content/preferences.js",
649 getEvtLogLevel:
function(){
653 return Components.classes[
"@mozilla.org/preferences-service;1"].
654 getService(Components.interfaces.nsIPrefService).
655 getBranch(
"extensions.FolderSync.").getIntPref(
"debugLevel");
659 getDefaultTags:
function(){
660 return this._root.defaulttags;
664 getUIPrefs:
function(){
665 return this._root.ui;
669 getFallbacks:
function(){
670 return this._root.fallbacks;
dataSBHighestRatedArtists SBProperties rating
sbDeviceFirmwareAutoCheckForUpdate prototype flags
function getBoolPref(prefname, def)
getService(Ci.sbIFaceplateManager)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i