Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes
nsSeamonkeyProfileMigrator Class Reference

#include <nsSeamonkeyProfileMigrator.h>

Inheritance diagram for nsSeamonkeyProfileMigrator:
Inheritance graph
[legend]
Collaboration diagram for nsSeamonkeyProfileMigrator:
Collaboration graph
[legend]

List of all members.

Public Types

typedef nsresult(* prefConverter )(void *, nsIPrefBranch *)

Public Member Functions

NS_DECL_NSIMAILPROFILEMIGRATOR
NS_DECL_ISUPPORTS
NS_DECL_NSITIMERCALLBACK 
nsSeamonkeyProfileMigrator ()
virtual ~nsSeamonkeyProfileMigrator ()
nsresult RecursiveCopy (nsIFile *srcDir, nsIFile *destDir)
void migrate (in unsigned short aItems, in nsIProfileStartup aStartup, in wstring aProfile)
 Copy user profile information to the current active profile.
unsigned short getMigrateData (in wstring aProfile, in boolean aDoingStartup)
 A bit field containing profile items that this migrator offers for import.
void notify (in nsITimer timer)

Static Public Member Functions

static nsresult GetString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetWString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetWString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetWStringFromASCII (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetBool (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetBool (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetInt (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetInt (void *aTransform, nsIPrefBranch *aBranch)

Public Attributes

const unsigned short ALL = 0x0000
 profile items to migrate.
const unsigned short SETTINGS = 0x0001
const unsigned short ACCOUNT_SETTINGS = 0x0002
const unsigned short ADDRESSBOOK_DATA = 0x0004
const unsigned short JUNKTRAINING = 0x0008
const unsigned short PASSWORDS = 0x0010
const unsigned short OTHERDATA = 0x0020
const unsigned short NEWSDATA = 0x0040
const unsigned short MAILDATA = 0x0080
readonly attribute boolean sourceExists
 Whether or not there is any data that can be imported from this browser (i.e.
readonly attribute boolean sourceHasMultipleProfiles
 Whether or not the import source implementing this interface has multiple user profiles configured.
readonly attribute nsISupportsArray sourceProfiles
 An enumeration of available profiles.

Protected Member Functions

nsresult FillProfileDataFromSeamonkeyRegistry ()
nsresult GetSourceProfile (const PRUnichar *aProfile)
nsresult CopyPreferences (PRBool aReplace)
nsresult TransformPreferences (const nsAString &aSourcePrefFileName, const nsAString &aTargetPrefFileName)
nsresult DummyCopyRoutine (PRBool aReplace)
nsresult CopyJunkTraining (PRBool aReplace)
nsresult CopyPasswords (PRBool aReplace)
nsresult CopyMailFolders (nsVoidArray *aMailServers, nsIPrefService *aPrefBranch)
nsresult CopyAddressBookDirectories (nsVoidArray *aLdapServers, nsIPrefService *aPrefService)
nsresult CopySignatureFiles (nsVoidArray *aIdentities, nsIPrefService *aPrefBranch)
void ReadBranch (const char *branchName, nsIPrefService *aPrefService, nsVoidArray *aPrefs)
void WriteBranch (const char *branchName, nsIPrefService *aPrefService, nsVoidArray *aPrefs)
void CopyNextFolder ()
void EndCopyFolders ()
nsresult GetProfileDataFromRegistry (nsILocalFile *aRegistryFile, nsISupportsArray *aProfileNames, nsISupportsArray *aProfileLocations)
nsresult CopyFile (const nsAString &aSourceFileName, const nsAString &aTargetFileName)
nsresult GetSignonFileName (PRBool aReplace, char **aFileName)
nsresult LocateSignonsFile (char **aResult)

Protected Attributes

nsCOMPtr< nsILocalFilemSourceProfile
nsCOMPtr< nsIFilemTargetProfile
nsCOMPtr< nsIStringBundlemBundle
nsVoidArraymFileCopyTransactions
PRUint32 mFileCopyTransactionIndex

Private Attributes

nsCOMPtr< nsISupportsArraymProfileNames
nsCOMPtr< nsISupportsArraymProfileLocations
nsCOMPtr< nsIObserverServicemObserverService
nsCOMPtr< nsITimermFileIOTimer
PRInt64 mMaxProgress
PRInt64 mCurrentProgress

Detailed Description

Definition at line 53 of file nsSeamonkeyProfileMigrator.h.


Member Typedef Documentation

Definition at line 64 of file nsNetscapeProfileMigratorBase.h.


Constructor & Destructor Documentation

Definition at line 93 of file nsSeamonkeyProfileMigrator.cpp.

{
  mObserverService = do_GetService("@mozilla.org/observer-service;1");
  mMaxProgress = LL_ZERO;
  mCurrentProgress = LL_ZERO;
}

Here is the call graph for this function:

Definition at line 100 of file nsSeamonkeyProfileMigrator.cpp.

{           
}

Member Function Documentation

nsresult nsSeamonkeyProfileMigrator::CopyAddressBookDirectories ( nsVoidArray aLdapServers,
nsIPrefService aPrefService 
) [protected]

Definition at line 531 of file nsSeamonkeyProfileMigrator.cpp.

{
  // each server has a pref ending with .filename. The value of that pref points to a profile which we
  // need to migrate.
  nsAutoString index;
  index.AppendInt(nsIMailProfileMigrator::ADDRESSBOOK_DATA); 
  NOTIFY_OBSERVERS(MIGRATION_ITEMBEFOREMIGRATE, index.get());

  PRUint32 count = aLdapServers->Count();
  for (PRUint32 i = 0; i < count; ++i) 
  {
    PrefBranchStruct* pref = (PrefBranchStruct*) aLdapServers->ElementAt(i);
    nsDependentCString prefName (pref->prefName);

    if (StringEndsWith(prefName, nsDependentCString(".filename")))
    {
      // should we be assuming utf-8 or ascii here?
      CopyFile(NS_ConvertUTF8toUCS2(pref->stringValue), NS_ConvertUTF8toUCS2(pref->stringValue)); 
    }

    // we don't need to do anything to the fileName pref itself
  }

  NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, index.get());

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::CopyFile ( const nsAString &  aSourceFileName,
const nsAString &  aTargetFileName 
) [protected, inherited]

Definition at line 253 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsCOMPtr<nsIFile> sourceFile;
  mSourceProfile->Clone(getter_AddRefs(sourceFile));

  sourceFile->Append(aSourceFileName);
  PRBool exists = PR_FALSE;
  sourceFile->Exists(&exists);
  if (!exists)
    return NS_OK;

  nsCOMPtr<nsIFile> targetFile;
  mTargetProfile->Clone(getter_AddRefs(targetFile));
  
  targetFile->Append(aTargetFileName);
  targetFile->Exists(&exists);
  if (exists)
    targetFile->Remove(PR_FALSE);

  return sourceFile->CopyTo(mTargetProfile, aTargetFileName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 852 of file nsSeamonkeyProfileMigrator.cpp.

Here is the call graph for this function:

nsresult nsSeamonkeyProfileMigrator::CopyMailFolders ( nsVoidArray aMailServers,
nsIPrefService aPrefBranch 
) [protected]

Definition at line 608 of file nsSeamonkeyProfileMigrator.cpp.

{
  // Each server has a .directory pref which points to the location of the mail data
  // for that server. We need to do two things for that case...
  // (1) Fix up the directory path for the new profile
  // (2) copy the mail folder data from the source directory pref to the destination directory pref

  nsresult rv = NS_OK;

  PRUint32 count = aMailServers->Count();
  for (PRUint32 i = 0; i < count; ++i) 
  {
    PrefBranchStruct* pref = (PrefBranchStruct*)aMailServers->ElementAt(i);
    nsDependentCString prefName (pref->prefName);

    if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory-rel"))) {
      // When the directories are modified below, we may change the .directory
      // pref. As we don't have a pref branch to modify at this stage and set
      // up the relative folders properly, we'll just remove all the
      // *.directory-rel prefs. Mailnews will cope with this, creating them
      // when it first needs them.
      if (pref->type == nsIPrefBranch::PREF_STRING)
        NS_Free(pref->stringValue);

      aMailServers->RemoveElementAt(i);
      // Now decrease i and count to match the removed element
      --i;
      --count;
    }
    else if (StringEndsWith(prefName, nsDependentCString(".directory")))
    {
      // let's try to get a branch for this particular server to simplify things
      prefName.Cut( prefName.Length() - strlen("directory"), strlen("directory"));
      prefName.Insert("mail.server.", 0);

      nsCOMPtr<nsIPrefBranch> serverBranch;
      aPrefService->GetBranch(prefName.get(), getter_AddRefs(serverBranch));

      if (!serverBranch)
        break; // should we clear out this server pref from aMailServers?

      nsXPIDLCString serverType; 
      serverBranch->GetCharPref("type", getter_Copies(serverType));

      nsCOMPtr<nsILocalFile> sourceMailFolder;
      serverBranch->GetComplexValue("directory", NS_GET_IID(nsILocalFile), getter_AddRefs(sourceMailFolder));

      // now based on type, we need to build a new destination path for the mail folders for this server
      nsCOMPtr<nsIFile> targetMailFolder;
      if (serverType.Equals("imap"))
      {
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(IMAP_MAIL_DIR_50_NAME);       
      }
      else if (serverType.Equals("none") || serverType.Equals("pop3")) 
      {
        // local folders and POP3 servers go under <profile>\Mail
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(MAIL_DIR_50_NAME);
      }
      else if (serverType.Equals("nntp"))
      {
        mTargetProfile->Clone(getter_AddRefs(targetMailFolder));
        targetMailFolder->Append(NEWS_DIR_50_NAME); 
      }

      if (targetMailFolder)
      {
        // for all of our server types, append the host name to the directory as part of the new location
        nsXPIDLCString hostName;
        serverBranch->GetCharPref("hostname", getter_Copies(hostName));
        targetMailFolder->Append(NS_ConvertASCIItoUTF16(hostName));

        // we should make sure the host name based directory we are going to migrate 
        // the accounts into is unique. This protects against the case where the user
        // has multiple servers with the same host name.
        targetMailFolder->CreateUnique(nsIFile::DIRECTORY_TYPE, 0777);

        rv = RecursiveCopy(sourceMailFolder, targetMailFolder);
        // now we want to make sure the actual directory pref that gets
        // transformed into the new profile's pref.js has the right file
        // location.
        nsCAutoString descriptorString;
        nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(targetMailFolder);
        localFile->GetPersistentDescriptor(descriptorString);
        nsCRT::free(pref->stringValue);
        pref->stringValue = ToNewCString(descriptorString);
      }
    }
    else if (StringEndsWith(prefName, nsDependentCString(".newsrc.file")))
    {
      // copy the news RC file into \News. this won't work if the user has different newsrc files for each account
      // I don't know what to do in that situation.
      
      nsCOMPtr<nsIFile> targetNewsRCFile;
      mTargetProfile->Clone(getter_AddRefs(targetNewsRCFile));
      targetNewsRCFile->Append(NEWS_DIR_50_NAME); 

      // turn the pref into a nsILocalFile
      nsCOMPtr<nsILocalFile> srcNewsRCFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
      srcNewsRCFile->SetPersistentDescriptor(nsDependentCString(pref->stringValue));

      // now make the copy
      PRBool exists; 
      srcNewsRCFile->Exists(&exists);
      if (exists)
      {
        nsAutoString leafName;
        srcNewsRCFile->GetLeafName(leafName);
        srcNewsRCFile->CopyTo(targetNewsRCFile,leafName); // will fail if we've already copied a newsrc file here
        targetNewsRCFile->Append(leafName);

        // now write out the new descriptor
        nsCAutoString descriptorString;
        nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(targetNewsRCFile);
        localFile->GetPersistentDescriptor(descriptorString);
        nsCRT::free(pref->stringValue);
        pref->stringValue = ToNewCString(descriptorString);
      }      
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 114 of file nsSeamonkeyProfileMigrator.cpp.

{
  if (mFileCopyTransactionIndex < mFileCopyTransactions->Count())
  {
    PRUint32 percentage = 0;
    fileTransactionEntry* fileTransaction = (fileTransactionEntry*) mFileCopyTransactions->SafeElementAt(mFileCopyTransactionIndex++);
    if (fileTransaction) // copy the file
    {
      fileTransaction->srcFile->CopyTo(fileTransaction->destFile, EmptyString());

      // add to our current progress
      PRInt64 fileSize;
      fileTransaction->srcFile->GetFileSize(&fileSize);
      LL_ADD(mCurrentProgress, mCurrentProgress, fileSize);

      PRInt64 percentDone;
      LL_MUL(percentDone, mCurrentProgress, 100);

      LL_DIV(percentDone, percentDone, mMaxProgress);
      
      LL_L2UI(percentage, percentDone);

      nsAutoString index;
      index.AppendInt( percentage ); 

      NOTIFY_OBSERVERS(MIGRATION_PROGRESS, index.get());
    }
    // fire a timer to handle the next one. 
    mFileIOTimer = do_CreateInstance("@mozilla.org/timer;1");
    if (mFileIOTimer)
      mFileIOTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback *, this), percentage == 100 ? 500 : 0, nsITimer::TYPE_ONE_SHOT);
  } else
    EndCopyFolders();
  
  return;
}

Here is the call graph for this function:

Definition at line 858 of file nsSeamonkeyProfileMigrator.cpp.

{
  nsresult rv;

  nsXPIDLCString signonsFileName;
  GetSignonFileName(aReplace, getter_Copies(signonsFileName));

  if (signonsFileName.IsEmpty())
    return NS_ERROR_FILE_NOT_FOUND;

  nsAutoString fileName; fileName.AssignWithConversion(signonsFileName);
  if (aReplace)
    rv = CopyFile(fileName, fileName);
  else {
    // don't do anything right now
  }
  return rv;
}

Here is the call graph for this function:

nsresult nsSeamonkeyProfileMigrator::CopySignatureFiles ( nsVoidArray aIdentities,
nsIPrefService aPrefBranch 
) [protected]

Definition at line 560 of file nsSeamonkeyProfileMigrator.cpp.

{
  nsresult rv = NS_OK;

  PRUint32 count = aIdentities->Count();
  for (PRUint32 i = 0; i < count; ++i) 
  {
    PrefBranchStruct* pref = (PrefBranchStruct*)aIdentities->ElementAt(i);
    nsDependentCString prefName (pref->prefName);

    // a partial fix for bug #255043
    // if the user's signature file from seamonkey lives in the 
    // seamonkey profile root, we'll copy it over to the new 
    // thunderbird profile root and thenn set the pref to the new value
    // note, this doesn't work for multiple signatures that live
    // below the seamonkey profile root
    if (StringEndsWith(prefName, nsDependentCString(".sig_file")))
    {
      // turn the pref into a nsILocalFile
      nsCOMPtr<nsILocalFile> srcSigFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
      srcSigFile->SetPersistentDescriptor(nsDependentCString(pref->stringValue));

      nsCOMPtr<nsIFile> targetSigFile;
      rv = mTargetProfile->Clone(getter_AddRefs(targetSigFile));
      NS_ENSURE_SUCCESS(rv, rv); 

      // now make the copy
      PRBool exists; 
      srcSigFile->Exists(&exists);
      if (exists)
      {
        nsAutoString leafName;
        srcSigFile->GetLeafName(leafName);
        srcSigFile->CopyTo(targetSigFile,leafName); // will fail if we've already copied a sig file here
        targetSigFile->Append(leafName);

        // now write out the new descriptor
        nsCAutoString descriptorString;
        nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(targetSigFile);
        localFile->GetPersistentDescriptor(descriptorString);
        nsCRT::free(pref->stringValue);
        pref->stringValue = ToNewCString(descriptorString);
      }   
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 845 of file nsSeamonkeyProfileMigrator.cpp.

{
  // place holder function only to fake the UI out into showing some migration process.
  return NS_OK;
}

Definition at line 151 of file nsSeamonkeyProfileMigrator.cpp.

{
  // clear out the file transaction array
  if (mFileCopyTransactions)
  {
    PRUint32 count = mFileCopyTransactions->Count();
    for (PRUint32 i = 0; i < count; ++i) 
    {
      fileTransactionEntry* fileTransaction = (fileTransactionEntry*) mFileCopyTransactions->ElementAt(i);
      if (fileTransaction)
      {
        fileTransaction->srcFile = nsnull;
        fileTransaction->destFile = nsnull;
        delete fileTransaction;
      }
    }
  
    mFileCopyTransactions->Clear();
    delete mFileCopyTransactions;
  }

  // notify the UI that we are done with the migration process
  nsAutoString index;
  index.AppendInt(nsIMailProfileMigrator::MAILDATA); 
  NOTIFY_OBSERVERS(MIGRATION_ITEMAFTERMIGRATE, index.get());

  NOTIFY_OBSERVERS(MIGRATION_ENDED, nsnull);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 358 of file nsSeamonkeyProfileMigrator.cpp.

{
  // Find the Seamonkey Registry
  nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
  nsCOMPtr<nsILocalFile> seamonkeyRegistry;
#ifdef XP_WIN
  fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
  NS_ENSURE_TRUE(seamonkeyRegistry, NS_ERROR_FAILURE);

  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
  seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
#elif defined(XP_MACOSX)
  fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
  NS_ENSURE_TRUE(seamonkeyRegistry, NS_ERROR_FAILURE);
  
  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
  seamonkeyRegistry->Append(NS_LITERAL_STRING("Application Registry"));
#elif defined(XP_UNIX)
  fileLocator->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
  NS_ENSURE_TRUE(seamonkeyRegistry, NS_ERROR_FAILURE);
  
  seamonkeyRegistry->Append(NS_LITERAL_STRING(".mozilla"));
  seamonkeyRegistry->Append(NS_LITERAL_STRING("appreg"));
#elif defined(XP_OS2)
  fileLocator->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
  NS_ENSURE_TRUE(seamonkeyRegistry, NS_ERROR_FAILURE);
  
  seamonkeyRegistry->Append(NS_LITERAL_STRING("Mozilla"));
  seamonkeyRegistry->Append(NS_LITERAL_STRING("registry.dat"));
#endif

  return GetProfileDataFromRegistry(seamonkeyRegistry, mProfileNames, mProfileLocations);
}

Here is the call graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetBool ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 225 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetBoolPref, &xform->boolValue);
}
nsresult nsNetscapeProfileMigratorBase::GetInt ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 239 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetIntPref, &xform->intValue);
}
unsigned short nsIMailProfileMigrator::getMigrateData ( in wstring  aProfile,
in boolean  aDoingStartup 
) [inherited]

A bit field containing profile items that this migrator offers for import.

Parameters:
aProfilethe profile that we are looking for available data to import
aStarting"true" if the profile is not currently being used.
Returns:
bit field containing profile items (see above)
nsresult nsNetscapeProfileMigratorBase::GetProfileDataFromRegistry ( nsILocalFile aRegistryFile,
nsISupportsArray aProfileNames,
nsISupportsArray aProfileLocations 
) [protected, inherited]

Definition at line 81 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv = NS_OK;

  // Open It
  nsCOMPtr<nsIRegistry> reg(do_CreateInstance("@mozilla.org/registry;1"));
  reg->Open(aRegistryFile);

  nsRegistryKey profilesTree;
  rv = reg->GetKey(nsIRegistry::Common, NS_LITERAL_STRING("Profiles").get(), &profilesTree);
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsIEnumerator> keys;
  reg->EnumerateSubtrees(profilesTree, getter_AddRefs(keys));

  keys->First();
  while (keys->IsDone() != NS_OK) {
    nsCOMPtr<nsISupports> key;
    keys->CurrentItem(getter_AddRefs(key));

    nsCOMPtr<nsIRegistryNode> node(do_QueryInterface(key));

    nsRegistryKey profile;
    node->GetKey(&profile);

    // "migrated" is "yes" for all valid Seamonkey profiles. It is only "no"
    // for 4.x profiles. 
    nsXPIDLString isMigrated;
    reg->GetString(profile, NS_LITERAL_STRING("migrated").get(), getter_Copies(isMigrated));

    if (isMigrated.Equals(NS_LITERAL_STRING("no"))) {
      keys->Next();
      continue;
    }

    // Get the profile name and add it to the names array
    nsXPIDLString profileName;
    node->GetName(getter_Copies(profileName));

    // Get the profile location and add it to the locations array
    nsXPIDLString directory;
    reg->GetString(profile, NS_LITERAL_STRING("directory").get(), getter_Copies(directory));

    nsCOMPtr<nsILocalFile> dir;
#ifdef XP_MACOSX
    rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(dir));
    if (NS_FAILED(rv)) return rv;
    dir->SetPersistentDescriptor(NS_LossyConvertUCS2toASCII(directory));
#else
    rv = NS_NewLocalFile(directory, PR_TRUE, getter_AddRefs(dir));
    if (NS_FAILED(rv)) return rv;
#endif

    PRBool exists;
    dir->Exists(&exists);

    if (exists) {
      nsCOMPtr<nsISupportsString> profileNameString(do_CreateInstance("@mozilla.org/supports-string;1"));
      profileNameString->SetData(profileName);
      aProfileNames->AppendElement(profileNameString);

      aProfileLocations->AppendElement(dir);
    }

    keys->Next();
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetSignonFileName ( PRBool  aReplace,
char **  aFileName 
) [protected, inherited]

Definition at line 276 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv;
  if (aReplace) {
    // Find out what the signons file was called, this is stored in a pref
    // in Seamonkey.
    nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
    psvc->ResetPrefs();

    nsCOMPtr<nsIFile> sourcePrefsName;
    mSourceProfile->Clone(getter_AddRefs(sourcePrefsName));
    sourcePrefsName->Append(FILE_NAME_PREFS_5X);
    psvc->ReadUserPrefs(sourcePrefsName);

    nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
    rv = branch->GetCharPref("signon.SignonFileName", aFileName);
  }
  else 
    rv = LocateSignonsFile(aFileName);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 340 of file nsSeamonkeyProfileMigrator.cpp.

{
  PRUint32 count;
  mProfileNames->Count(&count);
  for (PRUint32 i = 0; i < count; ++i) {
    nsCOMPtr<nsISupportsString> str(do_QueryElementAt(mProfileNames, i));
    nsXPIDLString profileName;
    str->GetData(profileName);
    if (profileName.Equals(aProfile)) {
      mSourceProfile = do_QueryElementAt(mProfileLocations, i);
      break;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetString ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 165 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetCharPref, &xform->stringValue);
}
nsresult nsNetscapeProfileMigratorBase::GetWString ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 179 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  nsCOMPtr<nsIPrefLocalizedString> prefValue;
  nsresult rv = aBranch->GetComplexValue(xform->sourcePrefName, 
                                         NS_GET_IID(nsIPrefLocalizedString),
                                         getter_AddRefs(prefValue));

  if (NS_SUCCEEDED(rv) && prefValue) {
    nsXPIDLString data;
    prefValue->ToString(getter_Copies(data));

    xform->stringValue = ToNewCString(NS_ConvertUCS2toUTF8(data));
    xform->prefHasValue = PR_TRUE;
  }
  return rv;
}

Here is the call graph for this function:

nsresult nsNetscapeProfileMigratorBase::LocateSignonsFile ( char **  aResult) [protected, inherited]

Definition at line 299 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsCOMPtr<nsISimpleEnumerator> entries;
  nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
  if (NS_FAILED(rv)) return rv;

  nsCAutoString fileName;
  do {
    PRBool hasMore = PR_FALSE;
    rv = entries->HasMoreElements(&hasMore);
    if (NS_FAILED(rv) || !hasMore) break;

    nsCOMPtr<nsISupports> supp;
    rv = entries->GetNext(getter_AddRefs(supp));
    if (NS_FAILED(rv)) break;

    nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));

    nsCOMPtr<nsIURI> uri;
    rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
    if (NS_FAILED(rv)) break;
    nsCOMPtr<nsIURL> url(do_QueryInterface(uri));

    nsCAutoString extn;
    url->GetFileExtension(extn);

    if (extn.EqualsIgnoreCase("s")) {
      url->GetFileName(fileName);
      break;
    }
  }
  while (1);

  *aResult = ToNewCString(fileName);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMailProfileMigrator::migrate ( in unsigned short  aItems,
in nsIProfileStartup  aStartup,
in wstring  aProfile 
) [inherited]

Copy user profile information to the current active profile.

Parameters:
aItemslist of data items to migrate. see above for values.
aReplacereplace or append current data where applicable.
aProfileprofile to migrate from, if there is more than one.
void nsITimerCallback::notify ( in nsITimer  timer) [inherited]
Parameters:
aTimerthe timer which has expired
void nsSeamonkeyProfileMigrator::ReadBranch ( const char *  branchName,
nsIPrefService aPrefService,
nsVoidArray aPrefs 
) [protected]

Definition at line 755 of file nsSeamonkeyProfileMigrator.cpp.

{
  // Enumerate the branch
  nsCOMPtr<nsIPrefBranch> branch;
  aPrefService->GetBranch(branchName, getter_AddRefs(branch));

  PRUint32 count;
  char** prefs = nsnull;
  nsresult rv = branch->GetChildList("", &count, &prefs);
  if (NS_FAILED(rv)) return;

  for (PRUint32 i = 0; i < count; ++i) {
    // Save each pref's value into an array
    char* currPref = prefs[i];
    PRInt32 type;
    branch->GetPrefType(currPref, &type);
    PrefBranchStruct* pref = new PrefBranchStruct;
    pref->prefName = currPref;
    pref->type = type;
    switch (type) {
    case nsIPrefBranch::PREF_STRING:
      rv = branch->GetCharPref(currPref, &pref->stringValue);
      break;
    case nsIPrefBranch::PREF_BOOL:
      rv = branch->GetBoolPref(currPref, &pref->boolValue);
      break;
    case nsIPrefBranch::PREF_INT:
      rv = branch->GetIntPref(currPref, &pref->intValue);
      break;
    case nsIPrefBranch::PREF_INVALID:
      {
        nsCOMPtr<nsIPrefLocalizedString> str;
        rv = branch->GetComplexValue(currPref, 
                                    NS_GET_IID(nsIPrefLocalizedString), 
                                    getter_AddRefs(str));
        if (NS_SUCCEEDED(rv) && str)
          str->ToString(&pref->wstringValue);
      }
      break;
    }

    if (NS_SUCCEEDED(rv))
      aPrefs->AppendElement((void*)pref);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::RecursiveCopy ( nsIFile srcDir,
nsIFile destDir 
) [inherited]

Definition at line 340 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv;
  PRBool isDir;
  
  rv = srcDir->IsDirectory(&isDir);
  if (NS_FAILED(rv)) return rv;
  if (!isDir) return NS_ERROR_INVALID_ARG;
  
  PRBool exists;
  rv = destDir->Exists(&exists);
  if (NS_SUCCEEDED(rv) && !exists)
    rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
  if (NS_FAILED(rv)) return rv;
  
  PRBool hasMore = PR_FALSE;
  nsCOMPtr<nsISimpleEnumerator> dirIterator;
  rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
  if (NS_FAILED(rv)) return rv;
  
  rv = dirIterator->HasMoreElements(&hasMore);
  if (NS_FAILED(rv)) return rv;
  
  nsCOMPtr<nsIFile> dirEntry;
  
  while (hasMore)
  {
    rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
    if (NS_SUCCEEDED(rv))
    {
      rv = dirEntry->IsDirectory(&isDir);
      if (NS_SUCCEEDED(rv))
      {
        if (isDir)
        {
          nsCOMPtr<nsIFile> destClone;
          rv = destDir->Clone(getter_AddRefs(destClone));
          if (NS_SUCCEEDED(rv))
          {
            nsCOMPtr<nsILocalFile> newChild(do_QueryInterface(destClone));
            nsAutoString leafName;
            dirEntry->GetLeafName(leafName);
            newChild->AppendRelativePath(leafName);
            rv = newChild->Exists(&exists);
            if (NS_SUCCEEDED(rv) && !exists)
              rv = newChild->Create(nsIFile::DIRECTORY_TYPE, 0775);
            rv = RecursiveCopy(dirEntry, newChild);
          }
        }
        else
        {
          // we aren't going to do any actual file copying here. Instead, add this to our
          // file transaction list so we can copy files asynchronously...
          fileTransactionEntry* fileEntry = new fileTransactionEntry;
          fileEntry->srcFile = dirEntry;
          fileEntry->destFile = destDir;

          mFileCopyTransactions->AppendElement((void*) fileEntry);
        }
      }      
    }
    rv = dirIterator->HasMoreElements(&hasMore);
    if (NS_FAILED(rv)) return rv;
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::SetBool ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 232 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetBoolPref, xform->boolValue);
}
nsresult nsNetscapeProfileMigratorBase::SetInt ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 246 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetIntPref, xform->intValue);
}
nsresult nsNetscapeProfileMigratorBase::SetString ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 172 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetCharPref, xform->stringValue);
}
nsresult nsNetscapeProfileMigratorBase::SetWString ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 211 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  if (xform->prefHasValue) {
    nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
    nsAutoString data = NS_ConvertUTF8toUCS2(xform->stringValue);
    pls->SetData(data.get());
    return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsNetscapeProfileMigratorBase::SetWStringFromASCII ( void aTransform,
nsIPrefBranch aBranch 
) [static, inherited]

Definition at line 198 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  if (xform->prefHasValue) {
    nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
    nsAutoString data; data.AssignWithConversion(xform->stringValue);
    pls->SetData(data.get());
    return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsSeamonkeyProfileMigrator::TransformPreferences ( const nsAString &  aSourcePrefFileName,
const nsAString &  aTargetPrefFileName 
) [protected]

Definition at line 455 of file nsSeamonkeyProfileMigrator.cpp.

{
  PrefTransform* transform;
  PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform);

  // Load the source pref file
  nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
  psvc->ResetPrefs();

  nsCOMPtr<nsIFile> sourcePrefsFile;
  mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile));
  sourcePrefsFile->Append(aSourcePrefFileName);
  psvc->ReadUserPrefs(sourcePrefsFile);

  nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
  for (transform = gTransforms; transform < end; ++transform)
    transform->prefGetterFunc(transform, branch);

  // read in the various pref branch trees for accounts, identities, servers, etc. 

  nsVoidArray* accounts = new nsVoidArray();
  nsVoidArray* identities = new nsVoidArray();
  nsVoidArray* servers = new nsVoidArray();
  nsVoidArray* smtpservers = new nsVoidArray();
  nsVoidArray* ldapservers = new nsVoidArray();
  nsVoidArray* labelPrefs = new nsVoidArray();

  if (!accounts || !identities || !servers || !smtpservers || !ldapservers)
    return NS_ERROR_OUT_OF_MEMORY;
  
  ReadBranch("mail.account.", psvc, accounts);
  ReadBranch("mail.identity.", psvc, identities);
  ReadBranch("mail.server.", psvc, servers);
  ReadBranch("mail.smtpserver.", psvc, smtpservers);
  ReadBranch("ldap_2.servers.", psvc, ldapservers);
  ReadBranch("mailnews.labels.", psvc, labelPrefs);

  // the signature file prefs may be paths to files in the seamonkey profile path
  // so we need to copy them over and fix these paths up before we write them out to the new prefs.js
  CopySignatureFiles(identities, psvc);

  // certain mail prefs may actually be absolute paths instead of profile relative paths
  // we need to fix these paths up before we write them out to the new prefs.js
  CopyMailFolders(servers, psvc);

  CopyAddressBookDirectories(ldapservers, psvc);

  // Now that we have all the pref data in memory, load the target pref file,
  // and write it back out
  psvc->ResetPrefs();
  for (transform = gTransforms; transform < end; ++transform)
    transform->prefSetterFunc(transform, branch);

  WriteBranch("mail.account.", psvc, accounts);
  WriteBranch("mail.identity.", psvc, identities);
  WriteBranch("mail.server.", psvc, servers);
  WriteBranch("mail.smtpserver.", psvc, smtpservers);
  WriteBranch("ldap_2.servers.", psvc, ldapservers);
  WriteBranch("mailnews.labels.", psvc, labelPrefs);

  delete accounts;
  delete identities;
  delete servers;
  delete smtpservers;
  delete ldapservers;
  delete labelPrefs;

  nsCOMPtr<nsIFile> targetPrefsFile;
  mTargetProfile->Clone(getter_AddRefs(targetPrefsFile));
  targetPrefsFile->Append(aTargetPrefFileName);
  psvc->SavePrefFile(targetPrefsFile);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSeamonkeyProfileMigrator::WriteBranch ( const char *  branchName,
nsIPrefService aPrefService,
nsVoidArray aPrefs 
) [protected]

Definition at line 803 of file nsSeamonkeyProfileMigrator.cpp.

{
  nsresult rv;

  // Enumerate the branch
  nsCOMPtr<nsIPrefBranch> branch;
  aPrefService->GetBranch(branchName, getter_AddRefs(branch));

  PRUint32 count = aPrefs->Count();
  for (PRUint32 i = 0; i < count; ++i) {
    PrefBranchStruct* pref = (PrefBranchStruct*)aPrefs->ElementAt(i);
    switch (pref->type) {
    case nsIPrefBranch::PREF_STRING:
      rv = branch->SetCharPref(pref->prefName, pref->stringValue);
      nsCRT::free(pref->stringValue);
      pref->stringValue = nsnull;
      break;
    case nsIPrefBranch::PREF_BOOL:
      rv = branch->SetBoolPref(pref->prefName, pref->boolValue);
      break;
    case nsIPrefBranch::PREF_INT:
      rv = branch->SetIntPref(pref->prefName, pref->intValue);
      break;
    case nsIPrefBranch::PREF_INVALID:
      nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
      pls->SetData(pref->wstringValue);
      rv = branch->SetComplexValue(pref->prefName, 
                                   NS_GET_IID(nsIPrefLocalizedString),
                                   pls);
      nsCRT::free(pref->wstringValue);
      pref->wstringValue = nsnull;
      break;
    }
    nsCRT::free(pref->prefName);
    pref->prefName = nsnull;
    delete pref;
    pref = nsnull;
  }
  aPrefs->Clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const unsigned short nsIMailProfileMigrator::ACCOUNT_SETTINGS = 0x0002 [inherited]

Definition at line 50 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::ADDRESSBOOK_DATA = 0x0004 [inherited]

Definition at line 51 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::ALL = 0x0000 [inherited]

profile items to migrate.

use with migrate().

Definition at line 48 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::JUNKTRAINING = 0x0008 [inherited]

Definition at line 52 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::MAILDATA = 0x0080 [inherited]

Definition at line 56 of file nsIMailProfileMigrator.idl.

Definition at line 104 of file nsNetscapeProfileMigratorBase.h.

Definition at line 93 of file nsSeamonkeyProfileMigrator.h.

Definition at line 107 of file nsNetscapeProfileMigratorBase.h.

Definition at line 106 of file nsNetscapeProfileMigratorBase.h.

Definition at line 90 of file nsSeamonkeyProfileMigrator.h.

Definition at line 92 of file nsSeamonkeyProfileMigrator.h.

Definition at line 89 of file nsSeamonkeyProfileMigrator.h.

Definition at line 88 of file nsSeamonkeyProfileMigrator.h.

Definition at line 87 of file nsSeamonkeyProfileMigrator.h.

Definition at line 102 of file nsNetscapeProfileMigratorBase.h.

Definition at line 103 of file nsNetscapeProfileMigratorBase.h.

const unsigned short nsIMailProfileMigrator::NEWSDATA = 0x0040 [inherited]

Definition at line 55 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::OTHERDATA = 0x0020 [inherited]

Definition at line 54 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::PASSWORDS = 0x0010 [inherited]

Definition at line 53 of file nsIMailProfileMigrator.idl.

const unsigned short nsIMailProfileMigrator::SETTINGS = 0x0001 [inherited]

Definition at line 49 of file nsIMailProfileMigrator.idl.

Whether or not there is any data that can be imported from this browser (i.e.

whether or not it is installed, and there exists a user profile)

Definition at line 81 of file nsIMailProfileMigrator.idl.

Whether or not the import source implementing this interface has multiple user profiles configured.

Definition at line 87 of file nsIMailProfileMigrator.idl.

An enumeration of available profiles.

If the import source does not support profiles, this attribute is null.

Definition at line 93 of file nsIMailProfileMigrator.idl.


The documentation for this class was generated from the following files: