This is just some static backup of the original site, don't expect every link to work!

source: chrome/content/v_identity/vI_upgrade.js @ c4e569

ng_0.6ng_0.8ng_0.9
Last change on this file since c4e569 was c4e569, checked in by rene <just@…>, 12 years ago

changed vI_rdfDatasource into class to allow multiple instances

  • Property mode set to 100644
File size: 10.5 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var vI_upgrade = {
26    preferences : Components.classes["@mozilla.org/preferences-service;1"]
27            .getService(Components.interfaces.nsIPrefService)
28            .getBranch("extensions.virtualIdentity."),
29           
30    versionChecker : Components.classes["@mozilla.org/xpcom/version-comparator;1"]
31            .getService(Components.interfaces.nsIVersionComparator),
32   
33    vI_rdfDatasource : null,
34
35    init : function() {
36        vI_upgrade.__initRequirements();
37        document.documentElement.getButton("cancel").setAttribute("hidden", "true")
38    },
39
40    clean : function() {
41        if (vI_upgrade.vI_rdfDatasource) vI_upgrade.vI_rdfDatasource.clean();
42    },
43
44    __initRequirements : function() {
45        vI_notificationBar.dump("") // this initialises the debug-area
46        vI_upgrade.vI_rdfDatasource = new vI_rdfDatasource("virtualIdentity.rdf", true);
47    },
48   
49    // this function checks for the chance to ugrade without shoing the complete wizard
50    // if so, perform the upgrade and return true
51    // by default the wizard is not shown if it is a one-version-forward upgrade
52    quick_upgrade : function(currentVersion) {
53        // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label
54        if (!currentVersion) return false;
55        currentVersion = currentVersion.split(/\./);
56        var nextVersion = currentVersion[0] + "." + currentVersion[1] + "."
57        if (currentVersion[2].match(/pre/))
58            nextVersion += parseInt(currentVersion[2])
59        else nextVersion += parseInt(currentVersion[2]) + 1
60        var extVersion = document.getElementById("extVersion").getAttribute("value");
61               
62        // don't show the dialog if we do a one-step upgrade
63        if (vI_upgrade.versionChecker.compare(extVersion, nextVersion) <= 0) {
64            vI_notificationBar.dump("starting quick_upgrade.\n")
65            vI_upgrade.__initRequirements();
66            vI_upgrade.__upgrade();
67            return true;
68        }
69        return false;
70    },
71
72    prepare : function(elem) {
73        document.documentElement.getButton('back').setAttribute('hidden','true');
74        document.documentElement.getButton('next').focus();
75        var pageid = elem.getAttribute("pageid");
76        var browser = document.getElementById('vITextBox.' + pageid)
77        if (browser) 
78            browser.outputString =
79                    document.getElementById('vITextBoxBundle').getString('vident.' + pageid);
80    },
81   
82    __upgrade : function() {
83        if (vI_upgrade.vI_rdfDatasource.extUpgradeRequired()) vI_upgrade.extUpgrade();
84       
85        vI_account.cleanupSystem();
86    },         
87
88    upgrade : function() {
89        vI_notificationBar.dump("starting upgrade.\n\n")
90        document.getElementById("upgradeWizard").setAttribute("canAdvance", "false")
91        document.documentElement.getButton('next').setAttribute('disabled','true');
92       
93        vI_upgrade.__upgrade();
94   
95        vI_notificationBar.dump("\n\nupgrade finished.\n");
96       
97        document.documentElement.getButton('next').setAttribute('disabled','false');
98        document.getElementById("upgradeWizard").setAttribute("canAdvance", "true")
99    },
100   
101    extUpgrade : function() {
102        var currentVersion = vI_upgrade.vI_rdfDatasource.getCurrentExtFileVersion();
103        vI_notificationBar.dump("checking for previous version, found " + 
104            currentVersion + "\nextension-upgrade required.\n")
105        switch (currentVersion) {
106            case null:
107                vI_upgrade.__transferAllVIdentityABookToRDF(); // no break
108            default:
109                vI_upgrade.__transferMovedUserPrefs(currentVersion);
110                vI_upgrade.__removeObsoleteUserPrefs(currentVersion);
111                vI_upgrade.__removeExtraAddedHeaders(currentVersion);
112        }
113        vI_upgrade.vI_rdfDatasource.storeExtVersion();
114        vI_notificationBar.dump("extension-upgrade to " + vI_upgrade.vI_rdfDatasource.getCurrentExtFileVersion() + " done.\n\n");
115    },
116   
117    __removeExtraAddedHeaders : function(currentVersion) {
118        if (vI_upgrade.versionChecker.compare(currentVersion, "0.6.9") < 0 && 
119                vI_prepareHeader.prefroot.getCharPref("mailnews.headers.extraExpandedHeaders") != "") {
120            // clean extraExpandedHeaders once, because the whole header-saving and restoring was broken too long
121            vI_prepareHeader.prefroot.setCharPref("mailnews.headers.extraExpandedHeaders", "")
122            vI_notificationBar.dump("cleaned extraExpandedHeaders\n");
123        }
124    },
125   
126    __transferMovedUserPrefs : function(currentVersion) {
127        // transfer renamed preferences
128        var transferPrefs = [   { version : "0.5.3",
129                    prefs : Array({ sourcePref : "smart_reply_ask", targetPref : "idSelection_ask" },
130                        { sourcePref : "smart_reply_ask_always", targetPref : "idSelection_ask_always" },
131                        { sourcePref : "smart_reply_autocreate", targetPref : "idSelection_autocreate" },
132                        { sourcePref : "smart_timestamp", targetPref : "autoTimestamp" },
133                        { sourcePref : "storage_prefer_smart_reply", targetPref : "idSelection_storage_prefer_smart_reply" },
134                        { sourcePref : "storage_ignore_smart_reply", targetPref : "idSelection_storage_ignore_smart_reply" }) }];
135        // remove obsolete preference-tree virtualIdentity
136        for (var i = 0; i < transferPrefs.length; i++) {
137            // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
138            if (!currentVersion || (vI_upgrade.versionChecker.compare(currentVersion, transferPrefs[i].version) < 0)) {
139                // remove any obsolete preferences under extensions.virtualIdentity
140                vI_notificationBar.dump("transfer changed preferences of pre-" + transferPrefs[i].version + " release:\n")
141                for each (transferPref in transferPrefs[i].prefs) {
142                    try {   vI_upgrade.preferences.setBoolPref(transferPref.targetPref, 
143                            vI_upgrade.preferences.getBoolPref(transferPref.sourcePref));
144                        vI_upgrade.preferences.clearUserPref(transferPref.sourcePref);
145                        vI_notificationBar.dump(".") 
146                    }
147                    catch (e) { };
148                }
149                vI_notificationBar.dump("done.\n")
150            }
151        }
152    },
153   
154    __removeObsoleteUserPrefs : function(currentVersion) {
155        var obsoletePrefs = [   { version : "0.5.0",
156                    prefs : Array("aBook_use", "aBook_storedefault", "aBook_dont_update_multiple",
157                    "aBook_show_switch", "aBook_warn_update", "aBook_use_for_smart_reply",
158                    "aBook_prefer_smart_reply", "aBook_ignore_smart_reply", "aBook_warn_vI_replace",
159                    "aBook_use_non_vI", "aBook_notification", "storeVIdentity", "experimental",
160                    "storage_use_for_smart_reply") },
161                    { version : "0.5.3", prefs : Array("storage_use_for_smart_reply") },
162                    { version : "0.5.6", prefs : Array("copyEnigmailSettings") } ];
163        // remove obsolete preference-tree virtualIdentity
164        for (var i = 0; i < obsoletePrefs.length; i++) {
165            // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
166            if (!currentVersion || (vI_upgrade.versionChecker.compare(currentVersion, obsoletePrefs[i].version) < 0)) {
167                // remove any obsolete preferences under extensions.virtualIdentity
168                vI_notificationBar.dump("removing obsolete preferences of pre-" + obsoletePrefs[i].version + " release:\n")
169                for each (pref in obsoletePrefs[i].prefs) {
170                    try { vI_upgrade.preferences.clearUserPref(pref); vI_notificationBar.dump(".") }
171                    catch (e) { };
172                }
173                vI_notificationBar.dump("done.\n")
174            }
175        }
176    },
177
178    CardFields : Array("Custom1", "Custom2", "Custom3", "Custom4", "Notes"),
179    // --------------------------------------------------------------------
180    // remove all VirtualIdentity-related Information from the AddressBook
181    // and transfer it to the RDF File.
182    __transferAllVIdentityABookToRDF : function() {
183        var returnVar = { prop : null, counter : 0, warning : true }
184        for each (returnVar.prop in vI_upgrade.CardFields) {
185            var queryString = "?(or(" +returnVar.prop + ",c,vIdentity:))";
186            returnVar.prop = returnVar.prop.toLowerCase();
187            returnVar = vI_storage._walkTroughCards(queryString,vI_upgrade.__transferVIdentityABookToRDF, returnVar )
188        }
189        vI_notificationBar.dump("\ntransferred " + returnVar.counter + " VirtualIdentity information items from AddressBook to RDF.\n")
190    },
191   
192    __transferVIdentityABookToRDF: function(addrbook, Card, returnVar) {
193        if (!Card[returnVar.prop].match(/^vIdentity:/)) return returnVar;
194        if (returnVar.warning) {
195            vI_notificationBar.dump("transferring VirtualIdentity information from AddressBook to RDF file,\nthis might take a while:\n");
196            returnVar.warning = false
197        }
198       
199        var newFullEmail=Card[returnVar.prop].replace(/vIdentity: /,"");
200        var infoIndex = newFullEmail.indexOf(" (id")
201        if (!infoIndex) infoIndex = newFullEmail.indexOf(" (smtp")
202        var info = null; var id= null; var smtp = null;
203        if ( infoIndex != -1) {
204            info = newFullEmail.substr(infoIndex+2).replace(/\)/,"").split(/,/)
205            newFullEmail = newFullEmail.substr(0, infoIndex);
206        }
207        if ( info && info[0] ) id = info[0];
208        if ( info && info[1] ) smtp = info[1];
209       
210        var localIdentityData = new vI_identityData(newFullEmail, null, id, smtp, null)
211       
212        vI_upgrade.vI_rdfDatasource.updateRDF(localIdentityData.combinedName,
213                        "email", localIdentityData, true, true, null, null)
214        if (Card.secondEmail.replace(/^\s+|\s+$/g,""))
215            vI_upgrade.vI_rdfDatasource.updateRDF(localIdentityData.combinedName,
216                    "email", localIdentityData, true, true, null, null)
217       
218        Card[returnVar.prop] = "";
219        Card.editCardToDatabase("");
220        vI_notificationBar.dump(".");
221        return { prop: returnVar.prop, counter : ++returnVar.counter, warning : returnVar.warning };
222    },
223   
224    openURL : function(aURL) {
225            var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
226            var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"].getService(Components.interfaces.nsIExternalProtocolService);
227
228            uri.spec = aURL;
229            protocolSvc.loadUrl(uri);
230        }
231}
232// start init only if wizard is shown, so it is done in vI_upgrade.xul
233// window.addEventListener('load', vI_upgrade.init, true);
Note: See TracBrowser for help on using the repository browser.