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

source: content/vI_storage.js @ bf505e

ng_0.9
Last change on this file since bf505e was bf505e, checked in by rene <rene@…>, 11 years ago

cleanup debug messages

  • Property mode set to 100644
File size: 8.9 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): Mike Krieger, Sebastian Apel
23 * ***** END LICENSE BLOCK ***** */
24 
25/**
26* some code copied and adapted from 'addressContext' and from 'Birthday Reminder'
27* thanks to Mike Krieger and Sebastian Apel
28*/
29
30virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
31
32Components.utils.import("resource://gre/modules/AddonManager.jsm");
33Components.utils.import("resource://v_identity/vI_log.js");
34let Log = setupLogging("virtualIdentity.storage");
35
36var storage = {
37    focusedElement : null,
38    _pref : Components.classes["@mozilla.org/preferences-service;1"]
39        .getService(Components.interfaces.nsIPrefService)
40        .getBranch("extensions.virtualIdentity."),
41   
42    lastCheckedEmail : {},  // array of last checked emails per row,
43                // to prevent ugly double dialogs and time-consuming double-checks
44   
45    _rdfDatasourceAccess : null,    // local storage
46
47    clean: function() {
48        Log.debug("clean.\n");
49        storage.multipleRecipients = null;
50        storage.lastCheckedEmail = {};
51        storage.firstUsedInputElement = null;
52        awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue;
53        if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean();
54    },
55   
56    original_functions : {
57        awSetInputAndPopupValue : null
58    },
59
60    replacement_functions : {
61        awSetInputAndPopupValue : function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
62            Log.debug("awSetInputAndPopupValue '" + inputElem.id +"'\n");
63            storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber);
64            storage.updateVIdentityFromStorage(inputElem);
65        }
66    },
67       
68    awOnBlur : function (element) {
69        // only react on events triggered by addressCol2 - textinput Elements
70        if (!element || ! element.id.match(/^addressCol2*/)) return;
71        Log.debug("\nawOnBlur '" + element.id +"'\n");
72        storage.updateVIdentityFromStorage(element);
73        storage.focusedElement = null;
74    },
75
76    awOnFocus : function (element) {
77        if (!element || ! element.id.match(/^addressCol2*/)) return;
78        storage.focusedElement = element;
79    },
80
81    awPopupOnCommand : function (element) {
82        Log.debug("\nawPopupOnCommand'" + element.id +"'\n");
83        storage.updateVIdentityFromStorage(document.getElementById(element.id.replace(/^addressCol1/,"addressCol2")));
84        if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf
85            document.getElementById("autoReplyToSelfLabel").setAttribute("hidden", "true");
86
87    },
88   
89    initialized : null,
90    init: function() {
91        if (!storage.initialized) {
92            storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess();
93
94            // better approach would be to use te onchange event, but this one is not fired in any change case
95            // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
96            // same seems to happen with the ondragdrop event
97            if (top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1;
98            for (var row = 1; row <= top.MAX_RECIPIENTS ; row ++) {
99                var input = awGetInputElement(row);
100                if (input) {
101                    var oldBlur = input.getAttribute("onblur")
102                    input.setAttribute("onblur", (oldBlur?oldBlur+"; ":"") +
103                        "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this.parentNode.parentNode.parentNode);")
104                    var oldFocus = input.getAttribute("onfocus")
105                    input.setAttribute("onfocus", (oldFocus?oldFocus+"; ":"") +
106                        "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this.parentNode.parentNode.parentNode);")
107                }
108                var popup = awGetPopupElement(row);
109                if (popup) {
110                    var oldCommand = popup.getAttribute("oncommand")
111                    popup.setAttribute("oncommand", (oldCommand?oldCommand+"; ":"") +
112                        "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this);")
113                }
114            }
115            storage.initialized = true;
116        }
117        storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
118        awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
119            storage.replacement_functions.awSetInputAndPopupValue (inputElem, inputValue, popupElem, popupValue, rowNumber) }
120
121        // reset unavailable storageExtras preferences
122        AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function(addon) {
123          if (addon && !addon.userDisabled && !addon.appDisable) {
124            vI.main.preferences.setBoolPref("storageExtras_openPGP_messageEncryption", false)
125            vI.main.preferences.setBoolPref("storageExtras_openPGP_messageSignature", false)
126            vI.main.preferences.setBoolPref("storageExtras_openPGP_PGPMIME", false)
127          }
128        }); 
129    },
130   
131    firstUsedInputElement : null,   // this stores the first Element for which a Lookup in the Storage was successfull
132    updateVIdentityFromStorage: function(inputElement) {
133        if (!storage._pref.getBoolPref("storage"))
134            { Log.debug("Storage deactivated\n"); return; }
135        Log.debug("updateVIdentityFromStorage()\n");
136
137        var recipientType = document.getElementById(inputElement.id.replace(/^addressCol2/,"addressCol1"))
138            .selectedItem.getAttribute("value");
139        var row = inputElement.id.replace(/^addressCol2#/,"")
140        if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.__isDoBcc(row)) {
141            // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields)
142            if (storage.firstUsedInputElement == inputElement)
143                storage.firstUsedInputElement = null;
144            Log.debug("field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.\n")
145            return;
146        }
147       
148        if (inputElement.value == "") {
149            Log.debug("no recipient found, not checked.\n"); return;
150        }
151       
152        var row = inputElement.id.replace(/^addressCol2#/,"")
153        if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) {
154            Log.debug("same email than before, not checked again.\n"); return;
155        }
156        storage.lastCheckedEmail[row] = inputElement.value;
157       
158        // firstUsedInputElement was set before and we are not editing the same
159        var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement)
160        var currentIdentity = document.getElementById("msgIdentity_clone").identityData
161        var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType,
162            currentIdentity, document.getElementById("msgIdentity_clone").vid, isNotFirstInputElement);
163       
164        if (storageResult.identityCollection.number == 0) return; // return if there was no match
165        Log.debug("updateVIdentityFromStorage result: " + storageResult.result + "\n");
166        // found storageData, so store InputElement
167        if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement;
168       
169        var selectedMenuItem;
170        if (storageResult.result != "equal") {
171            for (var j = 0; j < storageResult.identityCollection.number; j++) {
172                Log.debug("updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName + "\n");
173                selectedMenuItem = document.getElementById("msgIdentity_clone").addIdentityToCloneMenu(storageResult.identityCollection.identityDataCollection[j])
174            }
175        }
176        if (storageResult.result == "accept") {
177            Log.debug("updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName + "\n");
178            document.getElementById("msgIdentity_clone").selectedMenuItem = selectedMenuItem;
179            if (document.getElementById("msgIdentity_clone").vid)
180                StorageNotification.info(vI.main.elements.strings.getString("vident.smartIdentity.vIStorageUsage") + ".");
181        }
182    },
183   
184    __isDoBcc : function(row) {
185        var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
186        if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
187
188        var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
189
190        for (var index = 0; index < doBccArray.count; index++ ) {
191            if (doBccArray.StringAt(index) == awGetInputElement(row).value) {
192                Log.debug("ignoring doBcc field '" +
193                    doBccArray.StringAt(index) + "'.\n");
194                return true;
195            }
196        }       
197        return false
198    }
199}
200vI.storage = storage;
201}});
Note: See TracBrowser for help on using the repository browser.