more changes for 4.x addressbook migration. r=bienvenu.
some hackery required since we hard code the pab to be abook.mab. also, the api's need to be able to create a new directory that already has exists and has prefs. git-svn-id: svn://10.0.0.236/trunk@63826 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
e15bf8d5b3
commit
49b85bad39
@ -49,7 +49,7 @@ interface nsIAbDirectory : nsISupports {
|
||||
boolean hasCard(in nsIAbCard cards);
|
||||
boolean hasDirectory(in nsIAbDirectory dir);
|
||||
readonly attribute nsIEnumerator mailingList;
|
||||
void createNewDirectory(in wstring dirName, in string fileName);
|
||||
void createNewDirectory(in wstring dirName, in string fileName, in boolean migrating);
|
||||
string getDirUri();
|
||||
|
||||
};
|
||||
|
||||
@ -44,6 +44,6 @@ interface nsIAddressBook : nsISupports {
|
||||
void printAddressbook();
|
||||
void setWebShellWindow(in nsIDOMWindow win);
|
||||
void importAddressBook();
|
||||
void convertLDIFtoMAB(in nsIFileSpec fileSpec);
|
||||
void convertLDIFtoMAB(in nsIFileSpec fileSpec, in boolean migrating);
|
||||
};
|
||||
|
||||
|
||||
@ -48,8 +48,10 @@ function OnLoadNewCard()
|
||||
{
|
||||
if ( editCard.selectedAB )
|
||||
abPopup.value = editCard.selectedAB;
|
||||
else
|
||||
else {
|
||||
// this should not be hardcoded.
|
||||
abPopup.value = "abdirectory://abook.mab";
|
||||
}
|
||||
}
|
||||
|
||||
GetCardValues(editCard.card, document);
|
||||
|
||||
@ -123,6 +123,7 @@ nsresult nsAbAutoCompleteSession::InitializeTable()
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr <nsIRDFResource> resource;
|
||||
// this should not be hardcoded to abook.mab
|
||||
rv = rdfService->GetResource("abdirectory://abook.mab", getter_AddRefs(resource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
@ -586,6 +586,7 @@ NS_IMETHODIMP nsAbCardProperty::AddAnonymousAttributesToDB()
|
||||
nsresult rv = NS_OK;
|
||||
if (mCardDatabase)
|
||||
mCardDatabase = null_nsCOMPtr();
|
||||
// this should not be hardcoded to abook.mab
|
||||
rv = GetCardDatabase("abdirectory://abook.mab");
|
||||
if (NS_SUCCEEDED(rv) && mCardDatabase)
|
||||
rv = mCardDatabase->AddAnonymousAttributesFromCard(this);
|
||||
@ -597,6 +598,7 @@ NS_IMETHODIMP nsAbCardProperty::EditAnonymousAttributesInDB()
|
||||
nsresult rv = NS_OK;
|
||||
if (mCardDatabase)
|
||||
mCardDatabase = null_nsCOMPtr();
|
||||
// this should not be hardcoded to abook.mab
|
||||
rv = GetCardDatabase("abdirectory://abook.mab");
|
||||
if (NS_SUCCEEDED(rv) && mCardDatabase)
|
||||
rv = mCardDatabase->EditAnonymousAttributesFromCard(this);
|
||||
|
||||
@ -194,7 +194,7 @@ nsAbDirProperty::GetMailingList(nsIEnumerator **mailingList)
|
||||
{ return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAbDirProperty::CreateNewDirectory(const PRUnichar *dirName, const char *fileName)
|
||||
nsAbDirProperty::CreateNewDirectory(const PRUnichar *dirName, const char *fileName, PRBool migrating)
|
||||
{ return NS_OK; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@ -228,13 +228,13 @@ NS_IMETHODIMP nsAbDirectory::GetMailingList(nsIEnumerator **mailingList)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectory::CreateNewDirectory(const PRUnichar *dirName, const char *fileName)
|
||||
NS_IMETHODIMP nsAbDirectory::CreateNewDirectory(const PRUnichar *dirName, const char *fileName, PRBool migrating)
|
||||
{
|
||||
if (!dirName)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
DIR_Server * server = nsnull;
|
||||
nsresult rv = DIR_AddNewAddressBook(dirName, fileName, &server);
|
||||
nsresult rv = DIR_AddNewAddressBook(dirName, fileName, migrating, &server);
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> newDir;
|
||||
char *uri = PR_smprintf("%s%s", kDirectoryDataSourceRoot, server->fileName);
|
||||
|
||||
@ -58,7 +58,7 @@ public:
|
||||
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
|
||||
NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
|
||||
NS_IMETHOD GetMailingList(nsIEnumerator **mailingList);
|
||||
NS_IMETHOD CreateNewDirectory(const PRUnichar *dirName, const char *fileName);
|
||||
NS_IMETHOD CreateNewDirectory(const PRUnichar *dirName, const char *fileName, PRBool migrating);
|
||||
NS_IMETHOD GetDirUri(char **uri);
|
||||
|
||||
// nsIAddrDBListener methods:
|
||||
|
||||
@ -352,6 +352,7 @@ protected:
|
||||
char* mDbUri;
|
||||
nsCOMPtr<nsIAddrDatabase> mDatabase;
|
||||
PRInt32 mFileType;
|
||||
PRBool mMigrating;
|
||||
|
||||
nsresult ParseTabFile();
|
||||
nsresult ParseLdifFile();
|
||||
@ -364,17 +365,18 @@ protected:
|
||||
char * str_getline( char **next );
|
||||
|
||||
public:
|
||||
AddressBookParser(nsIFileSpec *fileSpec);
|
||||
AddressBookParser(nsIFileSpec *fileSpec, PRBool migrating);
|
||||
~AddressBookParser();
|
||||
|
||||
nsresult ParseFile();
|
||||
};
|
||||
|
||||
AddressBookParser::AddressBookParser(nsIFileSpec * fileSpec)
|
||||
AddressBookParser::AddressBookParser(nsIFileSpec * fileSpec, PRBool migrating)
|
||||
{
|
||||
mFileSpec = fileSpec;
|
||||
mDbUri = nsnull;
|
||||
mFileType = UnknownFile;
|
||||
mMigrating = migrating;
|
||||
}
|
||||
|
||||
AddressBookParser::~AddressBookParser(void)
|
||||
@ -465,7 +467,7 @@ nsresult AddressBookParser::ParseFile()
|
||||
if (parentUri)
|
||||
PR_smprintf_free(parentUri);
|
||||
|
||||
parentDir->CreateNewDirectory(fileString.GetUnicode(), fileName);
|
||||
parentDir->CreateNewDirectory(fileString.GetUnicode(), fileName, mMigrating);
|
||||
|
||||
if (leafName)
|
||||
nsCRT::free(leafName);
|
||||
@ -1248,7 +1250,7 @@ void AddressBookParser::AddLdifColToDatabase(nsIMdbRow* newRow, char* typeSlot,
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddressBook::ConvertLDIFtoMAB(nsIFileSpec *fileSpec)
|
||||
NS_IMETHODIMP nsAddressBook::ConvertLDIFtoMAB(nsIFileSpec *fileSpec, PRBool migrating)
|
||||
{
|
||||
nsresult rv;
|
||||
if (!fileSpec) return NS_ERROR_FAILURE;
|
||||
@ -1256,7 +1258,7 @@ NS_IMETHODIMP nsAddressBook::ConvertLDIFtoMAB(nsIFileSpec *fileSpec)
|
||||
rv = fileSpec->OpenStreamForReading();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
AddressBookParser abParser(fileSpec);
|
||||
AddressBookParser abParser(fileSpec, migrating);
|
||||
|
||||
rv = abParser.ParseFile();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@ -1278,7 +1280,7 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook()
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = ConvertLDIFtoMAB(fileSpec);
|
||||
rv = ConvertLDIFtoMAB(fileSpec, PR_FALSE /* migrating */);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -504,7 +504,7 @@ nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, DIR_Server** pServer)
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DIR_Server** pServer)
|
||||
{
|
||||
DIR_Server * server = (DIR_Server *) PR_Malloc(sizeof(DIR_Server));
|
||||
DIR_InitServerWithType (server, PABDirectory);
|
||||
@ -525,7 +525,14 @@ nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, D
|
||||
DIR_SetFileName(&server->fileName, kMainPersonalAddressBook);
|
||||
|
||||
dir_ServerList->AppendElement(server);
|
||||
DIR_SavePrefsForOneServer(server);
|
||||
if (!migrating) {
|
||||
DIR_SavePrefsForOneServer(server);
|
||||
}
|
||||
#ifdef DEBUG_sspitzer
|
||||
else {
|
||||
printf("don't set the prefs, they are already set since this ab was migrated\n");
|
||||
}
|
||||
#endif
|
||||
*pServer = server;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ nsVoidArray* DIR_GetDirectories();
|
||||
nsresult DIR_GetDirServers();
|
||||
nsresult DIR_ShutDown(void); /* FEs should call this when the app is shutting down. It frees all DIR_Servers regardless of ref count values! */
|
||||
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, DIR_Server** pServer);
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DIR_Server** pServer);
|
||||
nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir);
|
||||
|
||||
nsresult DIR_DecrementServerRefCount (DIR_Server *);
|
||||
|
||||
@ -630,7 +630,7 @@ nsresult nsAbDirectoryDataSource::DoNewDirectory(nsIAbDirectory *directory, nsIS
|
||||
PRUnichar *name;
|
||||
literal->GetValue(&name);
|
||||
|
||||
rv = directory->CreateNewDirectory(name, nsnull);
|
||||
rv = directory->CreateNewDirectory(name, nsnull, PR_FALSE /* migrating */);
|
||||
nsAllocator::Free(name);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@ -1775,6 +1775,11 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && tmpLDIFFile,"ab migration failed: failed to get tmp dir");
|
||||
if (NS_FAILED(rv) || !tmpLDIFFile) return;
|
||||
|
||||
// HACK: I need to rename pab.ldif -> abook.ldif, because a bunch of places are hacked to point to abook.mab, and when I import abook.ldif it will create abook.mab. this is a temporary hack and will go away soon.
|
||||
if (!PL_strcmp((const char *)abName,"pab")) {
|
||||
abName = "abook";
|
||||
}
|
||||
|
||||
nsCAutoString ldifFileName;
|
||||
ldifFileName = (const char *)abName;
|
||||
ldifFileName += TEMP_LDIF_FILE_SUFFIX;
|
||||
@ -1785,6 +1790,7 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
|
||||
rv = Convert4xAddressBookToLDIF(ab4xFile, tmpLDIFFile);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration failed: failed to convert to ldif");
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
|
||||
#ifdef DEBUG_AB_MIGRATION
|
||||
printf("convert %s%s into %s%s\n",(const char *)abName,TEMP_LDIF_FILE_SUFFIX,(const char *)abName,ADDRESSBOOK_PREF_VALUE_5x_SUFFIX);
|
||||
@ -1794,10 +1800,12 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && ab, "failed to get address book");
|
||||
if (NS_FAILED(rv) || !ab) return;
|
||||
|
||||
rv = ab->ConvertLDIFtoMAB(tmpLDIFFile);
|
||||
rv = ab->ConvertLDIFtoMAB(tmpLDIFFile, PR_TRUE /* migrating */);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration filed: ldif to mab conversion failed\n");
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
|
||||
// this sucks.
|
||||
// ConvertLDIFtoMAB should set this pref value for us.
|
||||
#ifdef DEBUG_AB_MIGRATION
|
||||
printf("set %s the pref to %s%s\n",aPref,(const char *)abName,ADDRESSBOOK_PREF_VALUE_5x_SUFFIX);
|
||||
#endif /* DEBUG_AB_MIGRATION */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user