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

source: modules/plugins/signatureSwitch.js @ 509348

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

code formatting (no code changes)

  • Property mode set to 100644
File size: 4.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) 2011
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var EXPORTED_SYMBOLS = ["signatureSwitch"]
26
27const {
28  classes: Cc,
29  interfaces: Ci,
30  utils: Cu,
31  results: Cr
32} = Components;
33Cu.import("resource://gre/modules/AddonManager.jsm");
34Cu.import("resource://v_identity/vI_prefs.js");
35Cu.import("resource://v_identity/vI_log.js");
36let Log = setupLogging("virtualIdentity.signatureSwitch");
37
38function signatureSwitch(existingIdentity) {
39  // always try to initialize Security/Enigmail-Options
40  try {
41    setSecuritySettings(1);
42    enigSetMenuSettings('');
43  } catch (vErr) {};
44
45  let signatureWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
46    .getService(Ci.nsIWindowMediator)
47    .getMostRecentWindow(null);
48
49  if (!existingIdentity) {
50    Log.debug("signatureSwitch hide/remove signatures");
51
52    // code to hide the text signature
53    if (signatureSwitchInstalled && vIprefs.get("hide_signature") && signatureWindow.ss_signature && signatureWindow.ss_signature.length == 0) {
54      Log.debug("hide text/html signature");
55      signatureWindow.ss_main.signatureSwitch()
56    }
57
58    // code to hide the sMime signature
59    if (vIprefs.get("hide_sMime_messageSignature")) {
60      var element = signatureWindow.document.getElementById("menu_securitySign1");
61      if (element && element.getAttribute("checked") == "true") {
62        Log.debug("signatureSwitch hide_sMime_messageSignature with doCommand");
63        element.doCommand();
64      }
65    }
66
67    // code to hide the openGPG signature
68    if (vIprefs.get("hide_openPGP_messageSignature")) {
69      var element = signatureWindow.document.getElementById("enigmail_signed_send");
70      if (element && element.getAttribute("checked") == "true") {
71        var skipChangeGPGsign = false;
72        // sometimes GPG delays changing with dialog, so don't act if EnigmailAlertWindow is open to prevent double changes
73        var windows = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
74          .getService(Components.interfaces.nsIWindowWatcher).getWindowEnumerator();
75        while (windows.hasMoreElements()) {
76          var window = windows.getNext();
77          skipChangeGPGsign = skipChangeGPGsign || (window.document.title == EnigGetString("enigAlert"));
78        }
79        if (skipChangeGPGsign)
80          Log.debug("signatureSwitch skip hide_openPGP_messageSignature - EnigMail AlertWindow open");
81        else {
82          Log.debug("signatureSwitch hide_openPGP_messageSignature with doCommand");
83          element.doCommand();
84        }
85      }
86    }
87  } else if (signatureSwitchInstalled) {
88    Log.debug("signatureSwitch restore signature");
89    // code to show the text signature
90    if (signatureWindow.ss_signature && signatureWindow.ss_signature.length > 0) {
91      Log.debug("show text/html signature");
92      signatureWindow.ss_main.signatureSwitch()
93    }
94    // sMime and openGPG signature will not be re-added automatically
95  }
96}
97
98let signatureSwitchInstalled = false;
99// check for signature_switch extension
100AddonManager.getAddonByID("{2ab1b709-ba03-4361-abf9-c50b964ff75d}", function (addon) {
101  signatureSwitchInstalled = (addon && !addon.userDisabled && !addon.appDisable);
102  if (signatureSwitchInstalled)
103    Log.debug("Virtual Identity plugin for signatureSwitch Extension loaded!");
104  else
105    Log.debug("virtualIdentity is ready for signatureSwitch, but you don't use it");
106});
Note: See TracBrowser for help on using the repository browser.