Back to index

lightning-sunbird  0.9+nobinonly
nsOEProfileMigrator.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 "nsDirectoryServiceDefs.h"
00040 #include "nsIObserverService.h"
00041 #include "nsIServiceManager.h"
00042 #include "nsISupportsArray.h"
00043 #include "nsISupportsPrimitives.h"
00044 #include "nsOEProfileMigrator.h"
00045 #include "nsIProfileMigrator.h"
00046 #include "nsVoidArray.h"
00047 
00048 #include "nsIImportSettings.h"
00049 #include "nsIFileSpec.h" // needed for an obsolete API
00050 
00051 
00052 NS_IMPL_ISUPPORTS2(nsOEProfileMigrator, nsIMailProfileMigrator, nsITimerCallback)
00053 
00054 
00055 nsOEProfileMigrator::nsOEProfileMigrator()
00056 {
00057   mProcessingMailFolders = PR_FALSE;
00058   // get the import service
00059   mImportModule = do_CreateInstance("@mozilla.org/import/import-oe;1");
00060 }
00061 
00062 nsOEProfileMigrator::~nsOEProfileMigrator()
00063 {           
00064 
00065 }
00066 
00067 nsresult nsOEProfileMigrator::ContinueImport()
00068 {
00069   return Notify(nsnull);
00070 }
00071 
00073 // nsITimerCallback
00074 
00075 NS_IMETHODIMP
00076 nsOEProfileMigrator::Notify(nsITimer *timer)
00077 {
00078   PRInt32 progress;
00079   mGenericImporter->GetProgress(&progress);
00080   
00081   nsAutoString index;
00082   index.AppendInt( progress ); 
00083   NOTIFY_OBSERVERS(MIGRATION_PROGRESS, index.get());
00084  
00085   if (progress == 100) // are we done yet?
00086   {
00087     if (mProcessingMailFolders)
00088       return FinishCopyingMailFolders();
00089     else
00090       return FinishCopyingAddressBookData();
00091   }
00092   else
00093   {
00094     // fire a timer to handle the next one. 
00095     mFileIOTimer = do_CreateInstance("@mozilla.org/timer;1");
00096     if (mFileIOTimer)
00097       mFileIOTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback *, this), 100, nsITimer::TYPE_ONE_SHOT);
00098   }
00099   return NS_OK;
00100 }
00101 
00103 // nsIMailProfileMigrator
00104 
00105 NS_IMETHODIMP
00106 nsOEProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup, const PRUnichar* aProfile)
00107 {
00108   nsresult rv = NS_OK;
00109 
00110   PRBool aReplace = PR_FALSE;
00111 
00112   if (aStartup) 
00113   {
00114     aReplace = PR_TRUE;
00115     rv = aStartup->DoStartup();
00116     NS_ENSURE_SUCCESS(rv, rv);
00117   }
00118 
00119   NOTIFY_OBSERVERS(MIGRATION_STARTED, nsnull);
00120   rv = ImportSettings(mImportModule);
00121 
00122   // now import address books
00123   // this routine will asynchronously import address book data and it will then kick off
00124   // the final migration step, copying the mail folders over.
00125   rv = ImportAddressBook(mImportModule);  
00126 
00127   // don't broadcast an on end migration here. We aren't done until our asynch import process says we are done.
00128   return rv;
00129 }
00130 
00131 NS_IMETHODIMP
00132 nsOEProfileMigrator::GetMigrateData(const PRUnichar* aProfile, 
00133                                            PRBool aReplace, 
00134                                            PRUint16* aResult)
00135 {
00136   // There's no harm in assuming everything is available.
00137   *aResult = nsIMailProfileMigrator::ACCOUNT_SETTINGS | nsIMailProfileMigrator::ADDRESSBOOK_DATA | 
00138              nsIMailProfileMigrator::MAILDATA;
00139   return NS_OK;
00140 }
00141 
00142 NS_IMETHODIMP
00143 nsOEProfileMigrator::GetSourceExists(PRBool* aResult)
00144 {
00145   *aResult = PR_FALSE;
00146   
00147   nsCOMPtr<nsIImportSettings> importSettings;
00148   mImportModule->GetImportInterface(NS_IMPORT_SETTINGS_STR, getter_AddRefs(importSettings));
00149 
00150   if (importSettings)
00151   {
00152     nsXPIDLString description;
00153     nsCOMPtr<nsIFileSpec> location;
00154     importSettings->AutoLocate(getter_Copies(description), getter_AddRefs(location), aResult);
00155   }
00156 
00157   return NS_OK;
00158 }
00159 
00160 NS_IMETHODIMP
00161 nsOEProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
00162 {
00163   *aResult = PR_FALSE;
00164   return NS_OK;
00165 }
00166 
00167 NS_IMETHODIMP
00168 nsOEProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
00169 {
00170   *aResult = nsnull;
00171   return NS_OK;
00172 }
00173