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

source: content/vI_storage.js @ 4e6c57

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

removed enigmail storage options, this is done by enigmail now

  • Property mode set to 100644
File size: 11.3 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
30Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
31virtualIdentityExtension.ns(function () {
32  with(virtualIdentityExtension.LIB) {
33
34    Components.utils.import("resource://gre/modules/AddonManager.jsm");
35    let Log = vI.setupLogging("virtualIdentity.storage");
36    Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
37    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
38
39    var storage = {
40      timeStampID: null, // used to trace different objects of same type
41      focusedElement: null,
42
43      lastCheckedEmail: {}, // array of last checked emails per row,
44      // to prevent ugly double dialogs and time-consuming double-checks
45
46      _rdfDatasourceAccess: null, // local storage
47
48      stringBundle: Components.classes["@mozilla.org/intl/stringbundle;1"]
49        .getService(Components.interfaces.nsIStringBundleService)
50        .createBundle("chrome://v_identity/locale/v_identity.properties"),
51
52      clean: function () {
53        Log.debug("clean");
54        storage.multipleRecipients = null;
55        storage.lastCheckedEmail = {};
56        storage.firstUsedInputElement = null;
57        if (storage.original_functions.awSetInputAndPopupValue) {
58          awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue;
59          storage.original_functions.awSetInputAndPopupValue = null;
60        }
61        if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean();
62      },
63
64      original_functions: {
65        awSetInputAndPopupValue: null
66      },
67
68      replacement_functions: {
69        awSetInputAndPopupValue: function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
70          Log.debug("[" + storage.timeStampID + "] " + "awSetInputAndPopupValue '" + inputElem.id + "'");
71          storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber);
72          storage.__updateVIdentityFromStorage(inputElem, storage.currentWindow);
73        }
74      },
75
76      awOnBlur: function (element, currentWindow) {
77        // only react on events triggered by addressCol2 - textinput Elements
78        if (!element || !element.id.match(/^addressCol2*/)) return;
79        Log.debug("awOnBlur '" + element.id);
80        if (!element.value || element.value == "" || typeof element.value == 'undefined') return;
81        storage.__updateVIdentityFromStorage(element, currentWindow);
82        storage.focusedElement = null;
83      },
84
85      awOnFocus: function (element, currentWindow) {
86        if (!element || !element.id.match(/^addressCol2*/)) return;
87        Log.debug("awOnFocus '" + element.id);
88        storage.focusedElement = element;
89      },
90
91      awPopupOnCommand: function (element, currentWindow) {
92        Log.debug("awPopupOnCommand '" + element.id + "' '" + element.value + "'");
93        storage.__updateVIdentityFromStorage(element.parentNode.nextSibling.firstChild, currentWindow);
94        if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf
95          currentWindow.document.getElementById("virtualIdentityExtension_autoReplyToSelfLabel").setAttribute("hidden", "true");
96
97      },
98
99      initialized: null,
100      currentWindow: null,
101      init: function () {
102        if (!this.timeStampID) {
103          this.timeStampID = parseInt((new Date()).getTime() / 100) % 864000; // give object unified id (per day)
104          Log = vI.setupLogging("virtualIdentity.storage[" + this.timeStampID + "]");
105        }
106        if (!storage.initialized) {
107          Log.debug("initializing storage request environment");
108          storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess(window);
109
110          // better approach would be to use te onchange event, but this one is not fired in any change case
111          // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
112          // same seems to happen with the ondragdrop event
113          if (!top.MAX_RECIPIENTS || top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1;
114          for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
115            var input = window.awGetInputElement(row);
116            if (input) {
117              var oldBlur = input.getAttribute("onblur")
118              input.setAttribute("onblur", (oldBlur ? oldBlur + "; " : "") +
119                "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this, window);")
120              var oldFocus = input.getAttribute("onfocus")
121              input.setAttribute("onfocus", (oldFocus ? oldFocus + "; " : "") +
122                "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this, window);")
123            }
124            var popup = window.awGetPopupElement(row);
125            if (popup) {
126              var oldCommand = popup.getAttribute("oncommand")
127              popup.setAttribute("oncommand",
128                "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this, window);" +
129                (oldCommand ? "; " + oldCommand : ""))
130            }
131          }
132          storage.currentWindow = window;
133          Log.debug("initializing storage request environment - done.");
134          storage.initialized = true;
135        } else {
136          Log.debug("storage request environment already initialized");
137        }
138
139        if (typeof awSetInputAndPopupValue == 'function' && storage.original_functions.awSetInputAndPopupValue == null) {
140          Log.debug("replacing awSetInputAndPopupValue");
141          storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
142          awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
143            storage.replacement_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber)
144          }
145        }
146      },
147
148      firstUsedInputElement: null, // this stores the first Element for which a Lookup in the Storage was successfull
149      __updateVIdentityFromStorage: function (inputElement, currentWindow) {
150        Log.debug("__updateVIdentityFromStorage");
151        if (!vI.vIprefs.get("storage")) {
152          Log.debug("Storage deactivated");
153          return;
154        }
155        var currentDocument = currentWindow.document;
156        try {
157          var recipientType = inputElement.parentNode.previousSibling.firstChild.selectedItem.getAttribute("value");
158        } catch (e) {
159          Log.debug("inputElement.parentNode.previousSibling.firstChild.selectedItem.getAttribute('value') raised an error")
160          return;
161        }
162
163        var row = inputElement.id.replace(/^addressCol2#/, "")
164        if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.isDoBcc(row, currentWindow)) {
165          // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields)
166          if (storage.firstUsedInputElement == inputElement)
167            storage.firstUsedInputElement = null;
168          Log.debug("field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.")
169          return;
170        }
171
172        if (inputElement.value == "") {
173          Log.debug("no recipient found, not checked.");
174          return;
175        }
176
177        var row = inputElement.id.replace(/^addressCol2#/, "")
178        if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) {
179          Log.debug("same email than before, not checked again.");
180          return;
181        }
182        storage.lastCheckedEmail[row] = inputElement.value;
183
184        // firstUsedInputElement was set before and we are not editing the same
185        var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement)
186        var currentIdentity = currentDocument.getElementById("msgIdentity").identityData
187        var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType,
188          currentIdentity, currentDocument.getElementById("msgIdentity").vid, isNotFirstInputElement);
189
190        if (storageResult.identityCollection.number == 0) return; // return if there was no match
191        Log.debug("__updateVIdentityFromStorage result: " + storageResult.result);
192        // found storageData, so store InputElement
193        if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement;
194
195        var newMenuItem = null;
196        if (storageResult.result != "equal") {
197          for (var j = 0; j < storageResult.identityCollection.number; j++) {
198            Log.debug("__updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName);
199            let menuItem = currentDocument.getElementById("msgIdentity")
200              .addIdentityToMsgIdentityMenu(storageResult.identityCollection.identityDataCollection[j])
201            if (!newMenuItem) newMenuItem = menuItem;
202          }
203        }
204        if (storageResult.result == "accept") {
205          Log.debug("__updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName);
206          currentDocument.getElementById("msgIdentity").selectedMenuItem = newMenuItem;
207          if (currentDocument.getElementById("msgIdentity").vid)
208            vI.StorageNotification.info(storage.stringBundle.GetStringFromName("vident.smartIdentity.vIStorageUsage") + ".");
209        }
210      },
211
212      isDoBcc: function (row, currentWindow) {
213        if (typeof currentWindow.awGetPopupElement(row).selectedItem == 'undefined')
214          return false;
215        var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
216        if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
217
218        var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
219        if (doBccArray && doBccArray.count) {
220          for (var index = 0; index < doBccArray.count; index++) {
221            if (doBccArray.StringAt(index) == currentWindow.awGetInputElement(row).value) {
222              Log.debug("ignoring doBcc field '" +
223                doBccArray.StringAt(index));
224              return true;
225            }
226          }
227        }
228        return false
229      }
230    }
231    vI.storage = storage;
232  }
233});
Note: See TracBrowser for help on using the repository browser.