[Pkg-mozext-commits] [gcontactsync] 52/88: Issue #8: Create a button to reset all gContactSync settings

David Prévot taffit at moszumanska.debian.org
Thu Sep 18 20:52:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository gcontactsync.

commit 536f538fc332da418ec650337b45351a926ce78b
Author: Josh Geenen <joshgeenen at gmail.com>
Date:   Sat May 31 16:08:06 2014 -0500

    Issue #8: Create a button to reset all gContactSync settings
---
 src/content/Preferences.js               | 22 +++++---
 src/content/options.js                   | 86 +++++++++++++++++++++++---------
 src/content/options.xul                  | 10 +++-
 src/defaults/preferences/gContactSync.js |  2 -
 src/locale/en-US/gcontactsync.properties |  4 +-
 5 files changed, 90 insertions(+), 34 deletions(-)

diff --git a/src/content/Preferences.js b/src/content/Preferences.js
index 93ff230..a38491e 100644
--- a/src/content/Preferences.js
+++ b/src/content/Preferences.js
@@ -166,12 +166,12 @@ com.gContactSync.Preferences = {
    * verboseLog is first since it is used when logging preferences
    */
   mSyncPrefs: {
-    verboseLog:               new com.gContactSync.Pref("verboseLog",               "bool", true),
+    verboseLog:               new com.gContactSync.Pref("verboseLog",               "bool", false),
     initialDelayMinutes:      new com.gContactSync.Pref("initialDelayMinutes",      "int",  5),
     refreshInterval:          new com.gContactSync.Pref("refreshInterval",          "int",  120),
     accountDelay:             new com.gContactSync.Pref("accountDelay",             "int",  5000),
-    maxContacts:              new com.gContactSync.Pref("maxContacts",              "int",  5000),
-    backupInterval:           new com.gContactSync.Pref("backupInterval",           "int",  60),
+    maxContacts:              new com.gContactSync.Pref("maxContacts",              "int",  10000),
+    backupInterval:           new com.gContactSync.Pref("backupInterval",           "int",  14),
     confirmDeleteThreshold:   new com.gContactSync.Pref("confirmDeleteThreshold",   "int",  5),
     syncExtended:             new com.gContactSync.Pref("syncExtended",             "bool", true),
     overrideCopy:             new com.gContactSync.Pref("overrideCopy",             "bool", true),
@@ -186,14 +186,14 @@ com.gContactSync.Preferences = {
     phoneTypes:               new com.gContactSync.Pref("phoneTypes",               "bool", true),
     swapMobilePager:          new com.gContactSync.Pref("swapMobilePager",          "bool", true),
     newColLabels:             new com.gContactSync.Pref("newColLabels",             "bool", true),
-    dummyEmail:               new com.gContactSync.Pref("dummyEmail",               "bool", true),
+    dummyEmail:               new com.gContactSync.Pref("dummyEmail",               "bool", false),
     fixDupContactManagerCSS:  new com.gContactSync.Pref("fixDupContactManagerCSS",  "bool", false),
     getPhotos:                new com.gContactSync.Pref("getPhotos",                "bool", true),
     sendPhotos:               new com.gContactSync.Pref("sendPhotos",               "bool", true),
     addReset:                 new com.gContactSync.Pref("addReset",                 "bool", true),
     alertSummary:             new com.gContactSync.Pref("alertSummary",             "bool", true),
     statusBarText:            new com.gContactSync.Pref("statusBarText",            "char", ""),
-    myContactsName:           new com.gContactSync.Pref("myContactsName",           "char", "My Contacts"),
+    myContactsName:           new com.gContactSync.Pref("myContactsName",           "char", "Contacts"),
     lastVersionMajor:         new com.gContactSync.Pref("lastVersionMajor",         "int",  0),
     lastVersionMinor:         new com.gContactSync.Pref("lastVersionMinor",         "int",  0),
     lastVersionRelease:       new com.gContactSync.Pref("lastVersionRelease",       "int",  0),
@@ -205,7 +205,7 @@ com.gContactSync.Preferences = {
     synchronizing:            new com.gContactSync.Pref("synchronizing",            "bool", false),
     overrideGetCardForEmail:  new com.gContactSync.Pref("overrideGetCardForEmail",  "bool", true),
     syncPhoneticNames:        new com.gContactSync.Pref("syncPhoneticNames",        "bool", true),
-    newContactPhotoDelay:     new com.gContactSync.Pref("newContactPhotoDelay",      "int", 0),
+    newContactPhotoDelay:     new com.gContactSync.Pref("newContactPhotoDelay",      "int", 2000),
     v04UpgradeNeeded:         new com.gContactSync.Pref("v04UpgradeNeeded",         "bool", false),
     v04RCUpgradeNeeded:       new com.gContactSync.Pref("v04RCUpgradeNeeded",       "bool", false),
     httpRequestTimeout:       new com.gContactSync.Pref("httpRequestTimeout",        "int", 0),
@@ -307,5 +307,15 @@ com.gContactSync.Preferences = {
           document.getElementById("gContactSyncMenu")) {
       document.getElementById("gContactSyncMenu").collapsed = true;
     }
+  },
+  /**
+   * Resets all gContactSync prefs to their default values.
+   */
+  defaultAllSyncPrefs: function Preferences_defaultAllSyncPrefs() {
+    com.gContactSync.LOGGER.LOG("\n***Defaulting Sync Preferences***");
+    for (var i in this.mSyncPrefs) {
+      // TODO - use the default branch value instead?
+      this.setSyncPref(this.mSyncPrefs[i].label, this.mSyncPrefs[i].defaultValue);
+    }
   }
 };
diff --git a/src/content/options.js b/src/content/options.js
index f92a435..c7e2504 100644
--- a/src/content/options.js
+++ b/src/content/options.js
@@ -15,7 +15,7 @@
  *
  * The Initial Developer of the Original Code is
  * Josh Geenen <gcontactsync at pirules.org>.
- * Portions created by the Initial Developer are Copyright (C) 2008-2010
+ * Portions created by the Initial Developer are Copyright (C) 2008-2014
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
@@ -95,9 +95,45 @@ com.gContactSync.Options = {
     return true;
   },
   /**
-   * Deletes old preferences that are no longer required.
+   * Resets all gContactSync settings.  AB prefs, add-on prefs, cleans up old photos, and removes all auth tokens.
    */
-  cleanOldPrefs: function Options_cleanOldPrefs() {
+  resetAllSettings: function Options_resetAllSettings() {
+
+    if (!com.gContactSync.confirm(com.gContactSync.StringBundle.getStr("resetAllSettings"))) {
+      return;
+    }
+
+    // Force a restart
+    com.gContactSync.Preferences.setSyncPref("needRestart", true);
+
+    // Remove all AB prefs
+    this.removeABPrefs(false, false);
+
+    // Remove all auth tokens
+    var tokens = com.gContactSync.LoginManager.getAuthTokens();
+    for (var username in tokens) {
+      com.gContactSync.LOGGER.LOG("* Removing token for " + username);
+      com.gContactSync.LoginManager.removeAuthToken(username);
+    }
+
+    // Cleanup old photos
+    this.deleteOldPhotos(false);
+
+    // Reset sync prefs
+    com.gContactSync.Preferences.defaultAllSyncPrefs();
+
+    // Ask the user to restart
+    var restartStr = com.gContactSync.StringBundle.getStr("pleaseRestart");
+    com.gContactSync.Preferences.setSyncPref("statusBarText", restartStr);
+    com.gContactSync.alert(restartStr);
+  },
+  /**
+   * Deletes gContactSync preferences for address books.
+   * @param alertWhenFinished {bool} Whether this function should alert the user when finished.
+   * @param removeFromDeletedABsOnly {bool} Whether to only remove preferences for deleted ABs.
+   */
+  removeABPrefs: function Options_removeABPrefs(alertWhenFinished, removeFromDeletedABsOnly) {
+
     var abBranch    = Components.classes["@mozilla.org/preferences-service;1"]
                                 .getService(Components.interfaces.nsIPrefService)
                                 .getBranch("ldap_2.servers."),
@@ -115,42 +151,44 @@ com.gContactSync.Options = {
         // Step 1: Backup prefs.js
         prefsFile   = com.gContactSync.FileIO.getProfileDirectory(),
         backupFile  = com.gContactSync.FileIO.getProfileDirectory();
+
+    com.gContactSync.LOGGER.LOG("***Removing gContactSync address book preferences***");
     prefsFile.append(com.gContactSync.FileIO.fileNames.PREFS_JS);
     backupFile.append(com.gContactSync.FileIO.fileNames.FOLDER_NAME);
     backupFile.append(com.gContactSync.FileIO.fileNames.PREFS_BACKUP_DIR);
     backupFile.append(new Date().getTime() + "_" +
                       com.gContactSync.FileIO.fileNames.PREFS_JS + ".bak");
-    com.gContactSync.LOGGER.LOG("***Backing up prefs.js***");
-    com.gContactSync.LOGGER.LOG(" - Destination: " + backupFile.path);
+    com.gContactSync.LOGGER.LOG(" * Backing up prefs.js");
+    com.gContactSync.LOGGER.LOG("   - Destination: " + backupFile.path);
     com.gContactSync.FileIO.copyFile(prefsFile, backupFile);
     // Step 2: Clean all gContactSync prefs on ldap_2.servers
     //         if and only if the extensions.gContactSync.ldap_2.servers. branch
     //         exists (means that old prefs were already updated)
-    com.gContactSync.LOGGER.LOG("***Finding existing AB preference IDs***");
+    com.gContactSync.LOGGER.LOG(" * Finding existing AB preference IDs");
     for (i in abs) {
       var id = abs[i].mDirectory.dirPrefId;
-      com.gContactSync.LOGGER.VERBOSE_LOG(" - " + id);
+      com.gContactSync.LOGGER.VERBOSE_LOG("  - " + id);
       abPrefIDs[id] = abs[i];
     }
-    com.gContactSync.LOGGER.LOG("***Searching for obsolete prefs on ldap_2.servers.***");
+    com.gContactSync.LOGGER.LOG(" * Searching for obsolete prefs on ldap_2.servers.");
     children = abBranch.getChildList("", count);
     for (i = 0; i < count.value; i++) {
       // extract the preference ID from the whole preference
       // (ie MyAB_1.filename -> MyAB_1)
       var index  = children[i].indexOf("."),
           prefID = index > 0 ? children[i].substring(0, index) : children[i];
-      com.gContactSync.LOGGER.VERBOSE_LOG(" - " + children[i] + " - " + prefID);
-      if (!abPrefIDs["ldap_2.servers." + prefID]) {
+      com.gContactSync.LOGGER.VERBOSE_LOG("   - " + children[i] + " - " + prefID);
+      if (!removeFromDeletedABsOnly || !abPrefIDs["ldap_2.servers." + prefID]) {
         if (prefNames.test(children[i])) {
           abBranch.clearUserPref(children[i]);
-          com.gContactSync.LOGGER.LOG("  * Deleted old gContactSync pref");
+          com.gContactSync.LOGGER.LOG("  - Deleted old gContactSync pref");
           numObsolete++;
         }
       }
     }
-    com.gContactSync.LOGGER.LOG("***Found " + numObsolete + " obsolete prefs on ldap_2.servers.***");
+    com.gContactSync.LOGGER.LOG(" * Found " + numObsolete + " prefs on ldap_2.servers.*");
     // Step 3: clean prefs for deleted ABs on extensions.gContactSync.ldap_2.servers.
-    com.gContactSync.LOGGER.LOG("***Searching for gContactSync prefs for deleted ABs***");
+    com.gContactSync.LOGGER.LOG(" * Searching for gContactSync prefs for deleted ABs");
     children = gAbBranch.getChildList("", count);
     for (i = 0; i < count.value; i++) {
       // extract the preference ID from the whole preference
@@ -158,26 +196,28 @@ com.gContactSync.Options = {
       var index  = children[i].indexOf("."),
           prefID = index > 0 ? children[i].substring(0, index) : children[i];
       com.gContactSync.LOGGER.VERBOSE_LOG(" - " + children[i] + " - " + prefID);
-      if (!abPrefIDs["ldap_2.servers." + prefID]) {
+      if (!removeFromDeletedABsOnly || !abPrefIDs["ldap_2.servers." + prefID]) {
         if (prefNames.test(children[i])) {
           gAbBranch.clearUserPref(children[i]);
-          com.gContactSync.LOGGER.LOG("  * Deleted gContactSync pref for deleted AB");
           numDeleted++;
         }
       }
     }
-    com.gContactSync.LOGGER.LOG("***Found " + numDeleted + " gContactSync prefs for deleted ABs***");
-    com.gContactSync.alert(com.gContactSync.StringBundle.getStr("finishedPrefClean").replace("%d", numDeleted + numObsolete));
+    com.gContactSync.LOGGER.LOG(" * Found " + numDeleted + " gContactSync prefs for deleted ABs");
+    if (alertWhenFinished) {com.gContactSync.alert(com.gContactSync.StringBundle.getStr("finishedPrefClean").replace("%d", numDeleted + numObsolete));}
   },
   /**
    * Deletes unused contact photos from Thunderbird and gContactSync's photos
    * directories.  When address books and contacts are deleted TB doesn't delete
    * the corresponding photo which can leave quite a few photos behind.
+   * @param alertWhenFinished {bool} Whether this function should alert the user when finished.
    */
-  deleteOldPhotos: function Options_deleteOldPhotos() {
+  deleteOldPhotos: function Options_deleteOldPhotos(alertWhenFinished) {
     var abs = com.gContactSync.GAbManager.getAllAddressBooks();
     var photoURIs = {};
     var photoNames = {};
+
+    com.gContactSync.LOGGER.LOG("***Removing old contact photos***");
     
     // Get the URI for the gContactSync photos directory
     var file = Components.classes["@mozilla.org/file/directory_service;1"]
@@ -212,14 +252,14 @@ com.gContactSync.Options = {
     if (file.exists() && file.isDirectory()) {
       // Step 2: Iterate through all photos in gContactSync's photos directory and
       // delete the unused ones
-      com.gContactSync.LOGGER.VERBOSE_LOG("\n\n**Searching gContactSync Photos directory***");
+      com.gContactSync.LOGGER.VERBOSE_LOG(" * Searching gContactSync Photos directory");
       var iter = file.directoryEntries;
       while (iter.hasMoreElements()) {
         file = iter.getNext().QueryInterface(Components.interfaces.nsIFile);
         if (file.isFile()) {
           var filename = file.leafName;
           if (!photoURIs[filename]) {
-            com.gContactSync.LOGGER.VERBOSE_LOG(" * Deleting " + filename);
+            com.gContactSync.LOGGER.VERBOSE_LOG("  - Deleting " + filename);
             try {
               file.remove(false);
               ++numRemoved;
@@ -239,14 +279,14 @@ com.gContactSync.Options = {
     if (file.exists() && file.isDirectory()) {
       // Step 2: Iterate through all photos in gContactSync's photos directory and
       // delete the unused ones
-      com.gContactSync.LOGGER.VERBOSE_LOG("\n\n**Searching TB Photos directory***");
+      com.gContactSync.LOGGER.VERBOSE_LOG(" * Searching TB Photos directory");
       var iter = file.directoryEntries;
       while (iter.hasMoreElements()) {
         file = iter.getNext().QueryInterface(Components.interfaces.nsIFile);
         if (file.isFile()) {
           var filename = file.leafName;
           if (!photoNames[filename]) {
-            com.gContactSync.LOGGER.VERBOSE_LOG(" * Deleting " + filename);
+            com.gContactSync.LOGGER.VERBOSE_LOG("  - Deleting " + filename);
             try {
               file.remove(false);
               ++numRemoved;
@@ -257,6 +297,6 @@ com.gContactSync.Options = {
         }
       }
     }
-    com.gContactSync.alert(com.gContactSync.StringBundle.getStr("finishedPhotoClean").replace("%d", numRemoved));
+    if (alertWhenFinished) {com.gContactSync.alert(com.gContactSync.StringBundle.getStr("finishedPhotoClean").replace("%d", numRemoved));}
   }
 };
diff --git a/src/content/options.xul b/src/content/options.xul
index 3c869dc..846b40a 100644
--- a/src/content/options.xul
+++ b/src/content/options.xul
@@ -316,14 +316,20 @@
                 label="&resetAll.label;"
                 accesskey="&resetAll.accesskey;"
                 oncommand="com.gContactSync.GAbManager.resetAllSyncedABs(true);"/>
+        <button id="resetAllSettings"
+                label="&resetAllSettings.label;"
+                accesskey="&resetAllSettings.accesskey;"
+                oncommand="com.gContactSync.Options.resetAllSettings();"/>
+      </hbox>
+      <hbox>
         <button id="cleanOldPhotos"
                 label="&cleanOldPhotos.label;"
                 accesskey="&cleanOldPhotos.accesskey;"
-                oncommand="com.gContactSync.Options.deleteOldPhotos();"/>
+                oncommand="com.gContactSync.Options.deleteOldPhotos(true);"/>
         <button id="cleanOldPrefs"
                 label="&cleanOldPrefs.label;"
                 accesskey="&cleanOldPrefs.accesskey;"
-                oncommand="com.gContactSync.Options.cleanOldPrefs(true);"/>
+                oncommand="com.gContactSync.Options.removeABPrefs(true, true);"/>
       </hbox>
     </vbox>
   </prefpane>
diff --git a/src/defaults/preferences/gContactSync.js b/src/defaults/preferences/gContactSync.js
index dd6958e..9d8491b 100644
--- a/src/defaults/preferences/gContactSync.js
+++ b/src/defaults/preferences/gContactSync.js
@@ -45,8 +45,6 @@ pref("extensions.gContactSync.newColLabels", true);
 // if disabled this can cause problems w/ mailing lists...
 // in cases where problems will almost certainly happen this pref is ignored
 pref("extensions.gContactSync.dummyEmail", false);
-// enable different IM URLs as defined in Overlay.js
-pref("extensions.gContactSync.enableImUrls", true);
 // the last version of gContactSync loaded
 pref("extensions.gContactSync.lastVersionMajor", 0);
 pref("extensions.gContactSync.lastVersionMinor", 0);
diff --git a/src/locale/en-US/gcontactsync.properties b/src/locale/en-US/gcontactsync.properties
index 9ad37af..a5c71df 100644
--- a/src/locale/en-US/gcontactsync.properties
+++ b/src/locale/en-US/gcontactsync.properties
@@ -199,7 +199,7 @@ gcMenuKey=C
 # Preferences
 confirmMyContacts=In order to change this preference, all of your contacts and mailing lists in synchronized address books must be removed from Thunderbird only before you can change this preference.  If you do have not backed up your contacts yet or no longer wish to do this, click Cancel.\n\nWhen this is finished, please restart Thunderbird.
 confirmReset=This will reset all synchronized address books.  All of their contacts and mailing lists will be removed and you must restart Thunderbird when this is finished.  Your account details will be saved, so your contacts and groups will be added to Thunderbird during the next synchronization.  Click OK to continue, or Cancel to stop.
-pleaseRestart=Please close all Thunderbird windows and restart Thunderbird before synchronizing.
+pleaseRestart=Please close all Thunderbird windows and restart Thunderbird.
 
 # Confirm dialog when a mailing list has broken (due to bugs in Thunderbird)
 resetConfirm=One or more of your mailing lists has broken.  This can happen if you drag and drop several contacts into mailing lists, or sometimes if you have contacts without e-mail addresses.\nCertain groups in Gmail (My Contacts, Coworkers, Family, and Friends) cannot be deleted or renamed, either.\nClick OK to reset the addresss book or Cancel to do it later.\nVisit the forum if you have any questions.
@@ -209,6 +209,8 @@ resetConfirm2=Resetting an address book will permanently remove all contacts and
 alreadyReset=This address book has already been reset.
 # This error is thrown (visible in the Error Console) when a mailing list has broken
 mailListBroken=A mailing list has broken.
+# Confirmation dialog for resetting all settings
+resetAllSettings=Are you sure you want to reset all gContactSync-related settings?  This will remove all saved authentication tokens and synchronization settings.  No contacts will be deleted.\nClick OK to continue.
 
 # Toolbar buttons
 syncButton=Sync

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/gcontactsync.git



More information about the Pkg-mozext-commits mailing list