Back to index

lightning-sunbird  0.9+nobinonly
nsMapiRegistry.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Srilatha Moturi <srilatha@netscape.com>
00023  *   Rajiv Dayal <rdayal@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038  
00039 /***************************************************************************
00040 *
00041 * This File is no longer used by Thunderbird. Seamonkey is the only consumer.
00042 * See mozilla/mail/components/shell for the Thunderbird registry code
00043 *
00044 *****************************************************************************/
00045 
00046 #include "nsIServiceManager.h"
00047 #include "nsXPIDLString.h"
00048 #include "nsIPromptService.h"
00049 #include "nsIProxyObjectManager.h"
00050 #include "nsProxiedService.h"
00051 
00052 #include "nsMapiRegistryUtils.h" 
00053 #include "nsMapiRegistry.h"
00054 
00055 #include "nsIPrefService.h"
00056 #include "nsIPrefBranch.h"
00057 
00058 #include "nsEmbedCID.h"
00059 
00063 NS_IMPL_ISUPPORTS1(nsMapiRegistry, nsIMapiRegistry)
00064 
00065 nsMapiRegistry::nsMapiRegistry() {
00066     m_DefaultMailClient = m_registryUtils.IsDefaultMailClient();
00067     m_DefaultNewsClient = m_registryUtils.IsDefaultNewsClient(); 
00068     // m_ShowDialog should be initialized to false 
00069     // if we are the default mail client.
00070     m_ShowDialog = !m_registryUtils.HasRestrictedRegistryAccess() && !m_DefaultMailClient;
00071 }
00072 
00073 nsMapiRegistry::~nsMapiRegistry() {
00074 }
00075 
00076 NS_IMETHODIMP
00077 nsMapiRegistry::GetIsDefaultMailClient(PRBool * retval) {
00078     // we need to get the value from registry everytime
00079     // because the registry settings can be changed from
00080     // other mail applications.
00081     *retval = m_registryUtils.IsDefaultMailClient();
00082     return NS_OK;
00083 }
00084 
00085 NS_IMETHODIMP
00086 nsMapiRegistry::GetIsDefaultNewsClient(PRBool * retval) {
00087     // we need to get the value from registry everytime
00088     // because the registry settings can be changed from
00089     // other mail applications.
00090     *retval = m_registryUtils.IsDefaultNewsClient();
00091     return NS_OK;
00092 }
00093 
00094 NS_IMETHODIMP
00095 nsMapiRegistry::GetIsDefaultFeedClient(PRBool * retval) {
00096     // we need to get the value from registry everytime
00097     // because the registry settings can be changed from
00098     // other applications.
00099     *retval = m_registryUtils.IsDefaultFeedClient();
00100     return NS_OK;
00101 }
00102 
00103 NS_IMETHODIMP
00104 nsMapiRegistry::GetShowDialog(PRBool * retval) {
00105     *retval = m_ShowDialog;
00106     return NS_OK;
00107 }
00108 
00109 
00110 NS_IMETHODIMP
00111 nsMapiRegistry::SetIsDefaultMailClient(PRBool aIsDefaultMailClient) 
00112 {
00113     nsresult rv = NS_OK ;
00114 
00115     if (aIsDefaultMailClient)
00116     {
00117         rv = m_registryUtils.setDefaultMailClient();
00118         if (NS_SUCCEEDED(rv))
00119             m_DefaultMailClient = PR_TRUE;
00120         else
00121             m_registryUtils.ShowMapiErrorDialog(PR_TRUE);
00122     }
00123     else
00124     {
00125         rv = m_registryUtils.unsetDefaultMailClient();
00126         if (NS_SUCCEEDED(rv))
00127             m_DefaultMailClient = PR_FALSE;
00128         else
00129             m_registryUtils.ShowMapiErrorDialog(PR_TRUE);
00130     }
00131 
00132     return rv ;
00133 }
00134 
00135 NS_IMETHODIMP
00136 nsMapiRegistry::SetIsDefaultNewsClient(PRBool aIsDefaultNewsClient) 
00137 {
00138     nsresult rv = NS_OK ;
00139 
00140     if (aIsDefaultNewsClient)
00141     {
00142         rv = m_registryUtils.setDefaultNewsClient();
00143         if (NS_SUCCEEDED(rv))
00144             m_DefaultNewsClient = PR_TRUE;
00145         else
00146             m_registryUtils.ShowMapiErrorDialog(PR_FALSE);
00147     }
00148     else
00149     {
00150         rv = m_registryUtils.unsetDefaultNewsClient();
00151         if (NS_SUCCEEDED(rv))
00152             m_DefaultNewsClient = PR_FALSE;
00153         else
00154             m_registryUtils.ShowMapiErrorDialog(PR_FALSE);
00155     }
00156 
00157     return rv ;
00158 }
00159 
00160 NS_IMETHODIMP
00161 nsMapiRegistry::SetIsDefaultFeedClient(PRBool aIsDefaultFeedClient) 
00162 {
00163     nsresult rv = NS_OK;
00164     return aIsDefaultFeedClient ? m_registryUtils.setDefaultFeedClient() : m_registryUtils.unsetDefaultFeedClient();
00165 }
00166 
00167 NS_IMETHODIMP nsMapiRegistry::RegisterMailAndNewsClient()
00168 {
00169   m_registryUtils.registerNewsApp(PR_FALSE);
00170   m_registryUtils.registerMailApp(PR_FALSE);
00171   return NS_OK;
00172 }
00173 
00179 NS_IMETHODIMP
00180 nsMapiRegistry::ShowMailIntegrationDialog(nsIDOMWindow *aParentWindow) {
00181     if (!m_ShowDialog || !m_registryUtils.getShowDialog() ||
00182         m_registryUtils.IsDefaultMailClient()) {
00183       return NS_OK;
00184     }
00185 
00186     nsresult rv;
00187     nsCOMPtr<nsIPromptService> promptService(do_GetService(
00188                   NS_PROMPTSERVICE_CONTRACTID, &rv));
00189     if (NS_SUCCEEDED(rv) && promptService)
00190     {
00191         nsCOMPtr<nsIStringBundle> bundle;
00192         rv = m_registryUtils.MakeMapiStringBundle (getter_AddRefs (bundle)) ;
00193         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00194 
00195         nsXPIDLString dialogTitle;
00196         const PRUnichar *brandStrings[] = { m_registryUtils.brandName() };
00197         NS_NAMED_LITERAL_STRING(dialogTitlePropertyTag, "dialogTitle");
00198         rv = bundle->FormatStringFromName(dialogTitlePropertyTag.get(),
00199                                           brandStrings, 1,
00200                                           getter_Copies(dialogTitle));
00201         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00202         
00203         nsXPIDLString dialogText;
00204         NS_NAMED_LITERAL_STRING(dialogTextPropertyTag, "dialogText");
00205         rv = bundle->FormatStringFromName(dialogTextPropertyTag.get(),
00206                                           brandStrings, 1,
00207                                           getter_Copies(dialogText));
00208         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00209 
00210         nsXPIDLString checkboxText;
00211         rv = bundle->GetStringFromName(
00212                            NS_LITERAL_STRING("checkboxText").get(),
00213                            getter_Copies(checkboxText));
00214         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00215 
00216         PRBool checkValue = PR_FALSE;
00217         PRInt32 buttonPressed = 0;
00218         rv = promptService->ConfirmEx(aParentWindow,
00219                                       dialogTitle,
00220                                       dialogText.get(),
00221                                       (nsIPromptService::BUTTON_TITLE_YES * 
00222                                       nsIPromptService::BUTTON_POS_0) +
00223                                       (nsIPromptService::BUTTON_TITLE_NO * 
00224                                       nsIPromptService::BUTTON_POS_1),
00225                                       nsnull,
00226                                       nsnull,
00227                                       nsnull,
00228                                       checkboxText,
00229                                       &checkValue,
00230                                       &buttonPressed);
00231         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00232         rv = m_registryUtils.SetRegistryKey(HKEY_LOCAL_MACHINE, kAppDesktopKey, 
00233                                 "showMapiDialog", (checkValue) ? "0" : "1");
00234         if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
00235 
00236         m_ShowDialog = PR_FALSE;
00237         if (!buttonPressed)
00238             rv = SetIsDefaultMailClient(PR_TRUE);
00239     }
00240     return rv;
00241 }
00242