Back to index

lightning-sunbird  0.9+nobinonly
nsEudoraProfileMigrator.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is The Mail Profile Migrator.
00016  *
00017  * The Initial Developer of the Original Code is Scott MacGregor.
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *  Scott MacGregor <mscott@mozilla.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsMailProfileMigratorUtils.h"
00039 #include "nsCRT.h"
00040 #include "nsDirectoryServiceDefs.h"
00041 #include "nsIObserverService.h"
00042 #include "nsIPrefLocalizedString.h"
00043 #include "nsIPrefService.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsISupportsArray.h"
00046 #include "nsISupportsPrimitives.h"
00047 #include "nsNetCID.h"
00048 #include "nsNetUtil.h"
00049 #include "nsEudoraProfileMigrator.h"
00050 #include "nsIProfileMigrator.h"
00051 #include "nsVoidArray.h"
00052 
00053 #include "nsIImportSettings.h"
00054 #include "nsIFileSpec.h" // needed for an obsolete API
00055 
00056 
00057 NS_IMPL_ISUPPORTS2(nsEudoraProfileMigrator, nsIMailProfileMigrator, nsITimerCallback)
00058 
00059 
00060 nsEudoraProfileMigrator::nsEudoraProfileMigrator()
00061 {
00062   mProcessingMailFolders = PR_FALSE;
00063   // get the import service
00064   mImportModule = do_CreateInstance("@mozilla.org/import/import-eudora;1");
00065 }
00066 
00067 nsEudoraProfileMigrator::~nsEudoraProfileMigrator()
00068 {           
00069 }
00070 
00071 nsresult nsEudoraProfileMigrator::ContinueImport()
00072 {
00073   return Notify(nsnull);
00074 }
00075 
00077 // nsITimerCallback
00078 
00079 NS_IMETHODIMP
00080 nsEudoraProfileMigrator::Notify(nsITimer *timer)
00081 {
00082   PRInt32 progress;
00083   mGenericImporter->GetProgress(&progress);
00084   
00085   nsAutoString index;
00086   index.AppendInt( progress ); 
00087   NOTIFY_OBSERVERS(MIGRATION_PROGRESS, index.get());
00088  
00089   if (progress == 100) // are we done yet?
00090   {
00091     if (mProcessingMailFolders)
00092       return FinishCopyingMailFolders();
00093     else
00094       return FinishCopyingAddressBookData();
00095   }
00096   else
00097   {
00098     // fire a timer to handle the next one. 
00099     mFileIOTimer = do_CreateInstance("@mozilla.org/timer;1");
00100     if (mFileIOTimer)
00101       mFileIOTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback *, this), 100, nsITimer::TYPE_ONE_SHOT);
00102   }
00103   return NS_OK;
00104 }
00105 
00107 // nsIMailProfileMigrator
00108 
00109 NS_IMETHODIMP
00110 nsEudoraProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup, const PRUnichar* aProfile)
00111 {
00112   nsresult rv = NS_OK;
00113 
00114   PRBool aReplace = PR_FALSE;
00115 
00116   if (aStartup) 
00117   {
00118     aReplace = PR_TRUE;
00119     rv = aStartup->DoStartup();
00120     NS_ENSURE_SUCCESS(rv, rv);
00121   }
00122 
00123   NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
00124   rv = ImportSettings(mImportModule);
00125 
00126   // now import address books
00127   // this routine will asynchronously import address book data and it will then kick off
00128   // the final migration step, copying the mail folders over.
00129   rv = ImportAddressBook(mImportModule);  
00130 
00131   // don't broadcast an on end migration here. We aren't done until our asynch import process says we are done.
00132   return rv;
00133 }
00134 
00135 NS_IMETHODIMP
00136 nsEudoraProfileMigrator::GetMigrateData(const PRUnichar* aProfile, 
00137                                            PRBool aReplace, 
00138                                            PRUint16* aResult)
00139 {
00140   // There's no harm in assuming everything is available.
00141   *aResult = nsIMailProfileMigrator::ACCOUNT_SETTINGS | nsIMailProfileMigrator::ADDRESSBOOK_DATA | 
00142              nsIMailProfileMigrator::MAILDATA;
00143   return NS_OK;
00144 }
00145 
00146 NS_IMETHODIMP
00147 nsEudoraProfileMigrator::GetSourceExists(PRBool* aResult)
00148 {
00149   *aResult = PR_FALSE;
00150   
00151   nsCOMPtr<nsIImportSettings> importSettings;
00152   mImportModule->GetImportInterface(NS_IMPORT_SETTINGS_STR, getter_AddRefs(importSettings));
00153 
00154   if (importSettings)
00155   {
00156     nsXPIDLString description;
00157     nsCOMPtr<nsIFileSpec> location;
00158     importSettings->AutoLocate(getter_Copies(description), getter_AddRefs(location), aResult);
00159   }
00160 
00161   return NS_OK;
00162 }
00163 
00164 NS_IMETHODIMP
00165 nsEudoraProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
00166 {
00167   *aResult = PR_FALSE;
00168   return NS_OK;
00169 }
00170 
00171 NS_IMETHODIMP
00172 nsEudoraProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
00173 {
00174   *aResult = nsnull;
00175   return NS_OK;
00176 }
00177