diff --git a/mailnews/mapi/mapihook/src/msgMapiSupport.cpp b/mailnews/mapi/mapihook/src/msgMapiSupport.cpp index 8fecb473c9d3..f61de730b382 100644 --- a/mailnews/mapi/mapihook/src/msgMapiSupport.cpp +++ b/mailnews/mapi/mapihook/src/msgMapiSupport.cpp @@ -19,6 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com) + * Rajiv Dayal * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -86,23 +87,6 @@ nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnicha if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) return ShutdownMAPISupport(); - if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) - { - nsCOMPtr prefs = do_QueryInterface(aSubject, &rv); - if (NS_FAILED(rv)) return rv; - // which preference changed? - if (!nsCRT::strcmp(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, NS_ConvertUCS2toUTF8(aData).get())) - { - PRBool bIsDefault = PR_FALSE ; - rv = prefs->GetBoolPref(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, &bIsDefault); - if (NS_FAILED(rv)) return rv; - nsCOMPtr mapiRegistry = do_CreateInstance(NS_IMAPIREGISTRY_CONTRACTID, &rv) ; - if (NS_FAILED(rv)) return rv; - return mapiRegistry->SetIsDefaultMailClient(bIsDefault) ; - } - return rv ; - } - nsCOMPtr observerService(do_GetService("@mozilla.org/observer-service;1", &rv)); if (NS_FAILED(rv)) return rv; @@ -112,15 +96,6 @@ nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnicha rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); if (NS_FAILED(rv)) return rv; - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr prefInternal = do_QueryInterface(prefs, &rv); - if (NS_FAILED(rv)) return rv; - - rv = prefInternal->AddObserver(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, this, PR_FALSE); - if (NS_FAILED(rv)) return rv; - return rv; } diff --git a/mailnews/mapi/mapihook/src/nsMapiRegistry.cpp b/mailnews/mapi/mapihook/src/nsMapiRegistry.cpp index f80bfed1d425..0b178e640f78 100644 --- a/mailnews/mapi/mapihook/src/nsMapiRegistry.cpp +++ b/mailnews/mapi/mapihook/src/nsMapiRegistry.cpp @@ -20,6 +20,7 @@ * * Contributor(s): * Srilatha Moturi + * Rajiv Dayal * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -167,16 +168,7 @@ nsMapiRegistry::ShowMailIntegrationDialog(nsIDOMWindow *aParentWindow) { m_ShowDialog = PR_FALSE; if (!buttonPressed) - { - // set the pref when OK is clicked on Mail Integration dialog, - // setDefaultMailClient is called from the Observer. - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr prefBranch; - rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - NS_ENSURE_SUCCESS(rv,rv); - prefBranch->SetBoolPref(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, PR_TRUE) ; - } + rv = SetIsDefaultMailClient(PR_TRUE); } return rv; } diff --git a/mailnews/mapi/mapihook/src/nsMapiRegistry.h b/mailnews/mapi/mapihook/src/nsMapiRegistry.h index 294acf26a46b..c5d5e0cdbeb3 100644 --- a/mailnews/mapi/mapihook/src/nsMapiRegistry.h +++ b/mailnews/mapi/mapihook/src/nsMapiRegistry.h @@ -50,8 +50,6 @@ #define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1" #define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry" -#define MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT "mailnews.default_mail_client" - class nsMapiRegistry : public nsIMapiRegistry { public: // ctor/dtor diff --git a/mailnews/mapi/resources/content/jar.mn b/mailnews/mapi/resources/content/jar.mn index 80dfa71d563a..ebffe9bc495f 100644 --- a/mailnews/mapi/resources/content/jar.mn +++ b/mailnews/mapi/resources/content/jar.mn @@ -1,3 +1,4 @@ messenger.jar: content/messenger-mapi/pref-mailnewsOverlay.xul + content/messenger-mapi/pref-mailnewsOverlay.js content/messenger-mapi/contents.rdf diff --git a/mailnews/mapi/resources/content/pref-mailnewsOverlay.js b/mailnews/mapi/resources/content/pref-mailnewsOverlay.js index 07a9815e39b1..e3e3c2ecb1cd 100644 --- a/mailnews/mapi/resources/content/pref-mailnewsOverlay.js +++ b/mailnews/mapi/resources/content/pref-mailnewsOverlay.js @@ -18,9 +18,27 @@ * * Contributor(s): * Srilatha Moturi + * Rajiv Dayal */ +function mailnewsOverlayStartup() { + mailnewsOverlayInit(); parent.hPrefWindow.registerOKCallbackFunc( onOK ); + if (!("mapiPref" in parent)) { + parent.mapiPref = new Object; + parent.mapiPref.isDefaultMailClient = + document.getElementById("mailnewsEnableMapi").checked; + } + else { + // when we switch between different panes + // set the checkbox based on the saved state + var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi"); + if (parent.mapiPref.isDefaultMailClient) + mailnewsEnableMapi.setAttribute("checked", "true"); + else + mailnewsEnableMapi.setAttribute("checked", "false"); + } +} function mailnewsOverlayInit() { try { @@ -42,11 +60,8 @@ function mailnewsOverlayInit() { .getService() .QueryInterface(Components.interfaces.nsIPrefService); var prefBranch = prefService.getBranch(prefbase); - if (prefBranch && prefBranch.prefIsLocked("default_mail_client")) { - if (prefBranch.getBoolPref("default_mail_client")) - mapiRegistry.setDefaultMailClient(); - else - mapiRegistry.unsetDefaultMailClient(); + if (prefBranch && prefBranch.prefIsLocked("defaultMailClient")) { + mapiRegistry.isDefaultMailClient = prefBranch.getBoolPref("defaultMailClient") ; mailnewsEnableMapi.setAttribute("disabled", "true"); } } @@ -54,12 +69,19 @@ function mailnewsOverlayInit() { if (mapiRegistry.isDefaultMailClient) mailnewsEnableMapi.setAttribute("checked", "true"); else - mailnewsEnableMapi.removeAttribute("checked"); + mailnewsEnableMapi.setAttribute("checked", "false"); } else mailnewsEnableMapi.setAttribute("disabled", "true"); } +function onEnableMapi() { + // save the state of the checkbox + if ("mapiPref" in parent) + parent.mapiPref.isDefaultMailClient = + document.getElementById("mailnewsEnableMapi").checked; +} + function onOK() { try { @@ -69,10 +91,12 @@ function onOK() catch(ex){ mapiRegistry = null; } - if (mapiRegistry) { - if (document.getElementById("mailnewsEnableMapi").checked) - mapiRegistry.setDefaultMailClient(); - else - mapiRegistry.unsetDefaultMailClient(); - } + if (mapiRegistry && + ("mapiPref" in parent) && + (mapiRegistry.isDefaultMailClient != parent.mapiPref.isDefaultMailClient)) { + mapiRegistry.isDefaultMailClient = parent.mapiPref.isDefaultMailClient ; + } } + +// Install the onload handler +addEventListener("load", mailnewsOverlayStartup, false); diff --git a/mailnews/mapi/resources/content/pref-mailnewsOverlay.xul b/mailnews/mapi/resources/content/pref-mailnewsOverlay.xul index b11ebc31a2d6..6b762b852f26 100644 --- a/mailnews/mapi/resources/content/pref-mailnewsOverlay.xul +++ b/mailnews/mapi/resources/content/pref-mailnewsOverlay.xul @@ -34,9 +34,10 @@ Contributor(s): _elementIDs.push("mailnewsEnableMapi"); ]]> - +