Back to index

lightning-sunbird  0.9+nobinonly
nsEudoraSettings.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /*
00041   Eudora settings
00042 */
00043 
00044 #include "nsCOMPtr.h"
00045 #include "nscore.h"
00046 #include "nsEudoraSettings.h"
00047 #include "nsEudoraStringBundle.h"
00048 
00049 #include "EudoraDebugLog.h"
00050 
00051 #if defined(XP_WIN) || defined(XP_OS2)
00052 #include "nsEudoraWin32.h"
00053 #endif
00054 #if defined(XP_MAC) || defined(XP_MACOSX)
00055 #include "nsEudoraMac.h"
00056 #endif
00057 
00058 
00060 nsresult nsEudoraSettings::Create(nsIImportSettings** aImport)
00061 {
00062     NS_PRECONDITION(aImport != nsnull, "null ptr");
00063     if (! aImport)
00064         return NS_ERROR_NULL_POINTER;
00065 
00066     *aImport = new nsEudoraSettings();
00067     if (! *aImport)
00068         return NS_ERROR_OUT_OF_MEMORY;
00069 
00070     NS_ADDREF(*aImport);
00071     return NS_OK;
00072 }
00073 
00074 nsEudoraSettings::nsEudoraSettings()
00075 {
00076 }
00077 
00078 nsEudoraSettings::~nsEudoraSettings()
00079 {
00080 }
00081 
00082 NS_IMPL_ISUPPORTS1(nsEudoraSettings, nsIImportSettings)
00083 
00084 NS_IMETHODIMP nsEudoraSettings::AutoLocate(PRUnichar **description, nsIFileSpec **location, PRBool *_retval)
00085 {
00086     NS_PRECONDITION(description != nsnull, "null ptr");
00087     NS_PRECONDITION(_retval != nsnull, "null ptr");
00088     NS_PRECONDITION(location != nsnull, "null ptr");
00089        if (!description || !_retval || !location)
00090               return( NS_ERROR_NULL_POINTER);
00091        
00092        *description = nsnull;      
00093        *_retval = PR_FALSE; 
00094 
00095        nsresult      rv;
00096 
00097        if (NS_FAILED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation))))
00098               return rv;
00099        *description = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_NAME);
00100 
00101 #if defined(XP_WIN) || defined(XP_OS2)
00102        *_retval = nsEudoraWin32::FindSettingsFile( m_pLocation );
00103 #endif
00104        
00105   NS_IF_ADDREF(*location = m_pLocation);
00106        return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP nsEudoraSettings::SetLocation(nsIFileSpec *location)
00110 {
00111        m_pLocation = location;
00112        return( NS_OK);
00113 }
00114 
00115 NS_IMETHODIMP nsEudoraSettings::Import(nsIMsgAccount **localMailAccount, PRBool *_retval)
00116 {
00117        NS_PRECONDITION( _retval != nsnull, "null ptr");
00118        nsresult      rv;
00119 
00120        *_retval = PR_FALSE;
00121 
00122        // Get the settings file if it doesn't exist
00123        if (!m_pLocation) {
00124 #if defined(XP_WIN) || defined(XP_OS2)
00125               if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation)))) {
00126                      if (!nsEudoraWin32::FindSettingsFile( m_pLocation)) {
00127                             m_pLocation = nsnull;
00128                      }
00129               }
00130 #endif
00131 #if defined(XP_MAC) || defined(XP_MACOSX)
00132               if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation)))) {
00133                      if (!nsEudoraMac::FindSettingsFile( m_pLocation)) {
00134                             m_pLocation = nsnull;
00135                      }
00136               }
00137 #endif
00138        }
00139 
00140        if (!m_pLocation) {
00141               IMPORT_LOG0( "*** Error, unable to locate settings file for import.\n");
00142               return( NS_ERROR_FAILURE);
00143        }
00144 
00145        // do the settings import
00146 #if defined(XP_WIN) || defined(XP_OS2)
00147        *_retval = nsEudoraWin32::ImportSettings( m_pLocation, localMailAccount);
00148 #endif
00149 #if defined(XP_MAC) || defined(XP_MACOSX)
00150        *_retval = nsEudoraMac::ImportSettings( m_pLocation, localMailAccount);
00151 #endif
00152 
00153        if (*_retval) {
00154               IMPORT_LOG0( "Successful import of eudora settings\n");
00155        }
00156        else {
00157               IMPORT_LOG0( "*** Error, Unsuccessful import of eudora settings\n");
00158        }
00159 
00160        return( NS_OK);
00161 }