Back to index

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