зеркало из https://github.com/mozilla/gecko-dev.git
fix palm sync category <-> moz ab mapping 232438 sr=mscott
This commit is contained in:
Родитель
2f7f3b474c
Коммит
fb203ae269
|
@ -135,8 +135,8 @@ interface IPalmSync : IUnknown
|
|||
[in] int aModRemoteRecCount, [in, size_is(aModRemoteRecCount)] lpnsABCOMCardStruct aModRemoteRecList,
|
||||
[out] int * aModMozRecCount, [out, size_is(, *aModMozRecCount)] lpnsABCOMCardStruct * aModMozRecList);
|
||||
|
||||
// All records from a AB represented by aCategoryIndex and aABName into a new Mozilla AB
|
||||
HRESULT nsAddAllABRecords([in] BOOL aIsUnicode, [in] long aCategoryIndex, [in] LPTSTR aABName,
|
||||
// All records from a AB represented by aCategoryIndex and aABName into a new or existing Mozilla AB
|
||||
HRESULT nsAddAllABRecords([in] BOOL aIsUnicode, [in] BOOL aReplaceExisting, [in] long aCategoryIndex, [in] LPTSTR aABName,
|
||||
[in] int aRemoteRecCount, [in, size_is(aRemoteRecCount)] lpnsABCOMCardStruct aRemoteRecList);
|
||||
|
||||
// Get All records from a Mozilla AB
|
||||
|
@ -152,6 +152,9 @@ interface IPalmSync : IUnknown
|
|||
// Delete an addressbook
|
||||
HRESULT nsDeleteAB([in] BOOL aIsUnicode, [in] long aCategoryIndex, [in] LPTSTR aABName, [in] LPTSTR aABUrl);
|
||||
|
||||
// was this address book deleted in Mozilla?
|
||||
HRESULT nsGetABDeleted([in] LPTSTR aABName, [out] BOOL *abDeleted);
|
||||
|
||||
// Rename an addressbook
|
||||
HRESULT nsRenameAB([in] BOOL aIsUnicode, [in] long aCategoryIndex, [in] LPTSTR aABName, [in] LPTSTR aABUrl);
|
||||
|
||||
|
|
|
@ -230,7 +230,15 @@ long CMozABConduitSync::GetRemoteDBInfo(int iIndex)
|
|||
return retval;
|
||||
}
|
||||
|
||||
BOOL CMozABConduitSync::CategoryExists(CPString &mozABName)
|
||||
BOOL CMozABConduitSync::CategoryNameMatches(CPString &catName, CPString &cutOffMozABName, CPString &mozABURL)
|
||||
{
|
||||
if (!catName.CompareNoCase(cutOffMozABName.GetBuffer(0)))
|
||||
return TRUE;
|
||||
else
|
||||
return (!mozABURL.CompareNoCase(PERSONAL_ADDRBOOK_URL) && !catName.CompareNoCase("Personal"));
|
||||
}
|
||||
|
||||
BOOL CMozABConduitSync::CategoryExists(CPString &mozABName, CPString &mozABURL)
|
||||
{
|
||||
CPCategory * pCategory = m_dbHH->GetFirstCategory();
|
||||
// Palm only allows 15 chars for category names.
|
||||
|
@ -242,7 +250,7 @@ BOOL CMozABConduitSync::CategoryExists(CPString &mozABName)
|
|||
while (pCategory)
|
||||
{
|
||||
CPString catName(pCategory->GetName());
|
||||
if (!catName.CompareNoCase(cutOffName.GetBuffer(0)))
|
||||
if (CategoryNameMatches(catName, cutOffName, mozABURL))
|
||||
return TRUE;
|
||||
// Process next category
|
||||
pCategory = m_dbHH->GetNextCategory();
|
||||
|
@ -335,7 +343,8 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
cutOffName = *mozABNameList[mozABIndex];
|
||||
|
||||
// if this category has been synchronized before
|
||||
if(catIndex == mozCatIndexList[mozABIndex]) {
|
||||
if(catIndex == mozCatIndexList[mozABIndex])
|
||||
{
|
||||
retval = sync->m_dbHH->LoadUpdatedRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' has been synced before\n", catID, catName.GetBuffer(0));
|
||||
foundInABList = TRUE;
|
||||
|
@ -343,7 +352,7 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
// See if the name has been changed on Palm side. Note that if both
|
||||
// Palm category and the corresponding moz addrbook are renamed then
|
||||
// Palm category name takes precedence.
|
||||
if (catName.CompareNoCase(cutOffName.GetBuffer(0)))
|
||||
if (!sync->CategoryNameMatches(catName, cutOffName, *mozABUrlList[mozABIndex]))
|
||||
{
|
||||
abRenamed = TRUE;
|
||||
CONDUIT_LOG3(gFD, "Category index = %d, name = '%s' was renamed (from '%s') on Palm so do the same on moz\n",
|
||||
|
@ -353,7 +362,8 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
}
|
||||
|
||||
// if corresponding category exists but not synchronized before
|
||||
if(!catName.CompareNoCase(cutOffName.GetBuffer(0))){
|
||||
if(sync->CategoryNameMatches(catName, cutOffName, *mozABUrlList[mozABIndex]))
|
||||
{
|
||||
retval = sync->m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' has not been synced before\n", catID, catName.GetBuffer(0));
|
||||
foundInABList = TRUE;
|
||||
|
@ -448,13 +458,18 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
// 2. else, if we never did palm sync on moz before then it's a new one
|
||||
// on palm. So create a new AB in moz with all records in this category
|
||||
// (even if it's an empty AB).
|
||||
if(!retval && !foundInABList) {
|
||||
if(!retval && !foundInABList)
|
||||
{
|
||||
if (catFlags != CAT_DIRTY && !neverDidPalmSyncBefore)
|
||||
{
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' is removed from moz and needs to be removed from palm\n", catID, catName.GetBuffer(0));
|
||||
CONDUIT_LOG0(gFD, " Deleting AB from Palm ... ");
|
||||
retval = sync->m_dbHH->DeleteCategory(catIndex, FALSE);
|
||||
CONDUIT_LOG1(gFD, "Done deleting AB from Palm. retval=%d.\n", retval);
|
||||
BOOL abDeleted = sync->m_dbPC->PCABDeleted(catName);
|
||||
if (abDeleted)
|
||||
{
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' is removed from moz and needs to be removed from palm\n", catID, catName.GetBuffer(0));
|
||||
CONDUIT_LOG0(gFD, " Deleting AB from Palm ... ");
|
||||
retval = sync->m_dbHH->DeleteCategory(catIndex, FALSE);
|
||||
CONDUIT_LOG1(gFD, "Done deleting AB from Palm. retval=%d.\n", retval);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -462,7 +477,7 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
retval = sync->m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG1(gFD, " Creating new moz AB with %d Palm record(s) ... ", recordCountHH);
|
||||
if(!retval)
|
||||
retval = sync->m_dbPC->AddRecords(catIndex, catName, recordCountHH, recordListHH);
|
||||
retval = sync->m_dbPC->AddRecords(FALSE, catIndex, catName, recordCountHH, recordListHH);
|
||||
CONDUIT_LOG1(gFD, "Done creating new moz AB. retval=%d.\n", retval);
|
||||
}
|
||||
}
|
||||
|
@ -470,7 +485,8 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
// delete and free HH records and recordList once synced
|
||||
if(recordListHH) {
|
||||
CPalmRecord ** tempRecordListHH = recordListHH;
|
||||
for(DWORD i=0; i < recordCountHH; i++) {
|
||||
for(DWORD i=0; i < recordCountHH; i++)
|
||||
{
|
||||
if(*tempRecordListHH)
|
||||
delete *tempRecordListHH;
|
||||
tempRecordListHH++;
|
||||
|
@ -486,7 +502,7 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
// and the case where Palm ABs have been deleted.
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
{
|
||||
if(mozIsFirstSyncList[mozABIndex] && !sync->CategoryExists(*mozABNameList[mozABIndex]))
|
||||
if(mozIsFirstSyncList[mozABIndex] && !sync->CategoryExists(*mozABNameList[mozABIndex], *mozABUrlList[mozABIndex]))
|
||||
{
|
||||
CONDUIT_LOG3(gFD, "\nMoz AB[%d] category index = %d, name = '%s' doesn't exist on Palm so needs to be added to palm\n",
|
||||
mozABIndex, mozCatIndexList[mozABIndex], mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
|
@ -496,8 +512,13 @@ DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
|||
CPCategory cat;
|
||||
retval = sync->m_dbPC->LoadAllRecords(*mozABNameList[mozABIndex],
|
||||
&recordCountPC, &recordListPC);
|
||||
if(!retval) {
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
if(!retval)
|
||||
{
|
||||
if (mozABUrlList[mozABIndex]->CompareNoCase(PERSONAL_ADDRBOOK_URL))
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
else
|
||||
cat.SetName("Personal");
|
||||
|
||||
CONDUIT_LOG1(gFD, " Creating new Palm AB with %d record(s) ... ", recordCountPC);
|
||||
retval = sync->m_dbHH->AddCategory(cat);
|
||||
CONDUIT_LOG2(gFD, "Done creating new Palm AB, new category index=%d. retval=%d.\n", cat.GetIndex(), retval);
|
||||
|
@ -612,7 +633,6 @@ long CMozABConduitSync::CopyHHtoPC()
|
|||
{
|
||||
long retval=0;
|
||||
BOOL success = FALSE;
|
||||
printf("copying hh to pc\n");
|
||||
// Log the start time.
|
||||
time_t ltime;
|
||||
time( <ime );
|
||||
|
@ -680,7 +700,7 @@ printf("copying hh to pc\n");
|
|||
CONDUIT_LOG3(gFD, "\nProcessing Palm AB '%s' (catIndex/catId) = (%d/%d)... \n", catName.GetBuffer(0), catIndex, catID);
|
||||
BOOL abRenamed = FALSE;
|
||||
BOOL foundInABList=FALSE;
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
for(mozABIndex = 0; mozABIndex < mozABCount; mozABIndex++)
|
||||
{
|
||||
// Palm only allows 15 chars for category names.
|
||||
CPString cutOffName;
|
||||
|
@ -692,12 +712,14 @@ printf("copying hh to pc\n");
|
|||
// if this category has been synchronized before, check if it has been renamed
|
||||
if(catIndex == mozCatIndexList[mozABIndex])
|
||||
{
|
||||
CONDUIT_LOG4(gFD, "Category index = %d, name = '%s' moz ab name = %s has been synced before uri = %s\n",
|
||||
catID, catName.GetBuffer(0), mozABNameList[mozABIndex]->GetBuffer(0), mozABUrlList[mozABIndex]->GetBuffer(0));
|
||||
foundInABList = TRUE;
|
||||
mozABSeen[mozABIndex] = TRUE; // mark it seen
|
||||
// See if the name has been changed on Palm side. Note that if both
|
||||
// Palm category and the corresponding moz addrbook are renamed then
|
||||
// Palm category name takes precedence.
|
||||
if (catName.CompareNoCase(cutOffName.GetBuffer(0)))
|
||||
if (!CategoryNameMatches(catName, cutOffName, *mozABUrlList[mozABIndex]))
|
||||
{
|
||||
abRenamed = TRUE;
|
||||
CONDUIT_LOG3(gFD, "Category index = %d, name = '%s' was renamed (from '%s') on Palm so do the same on moz\n",
|
||||
|
@ -706,13 +728,17 @@ printf("copying hh to pc\n");
|
|||
break;
|
||||
}
|
||||
// if corresponding category exists
|
||||
if(!catName.CompareNoCase(cutOffName.GetBuffer(0))){
|
||||
if (CategoryNameMatches(catName, cutOffName, *mozABUrlList[mozABIndex]))
|
||||
{
|
||||
retval = m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' matches moz ab\n", catID, catName.GetBuffer(0));
|
||||
CONDUIT_LOG3(gFD, "Category index = %d, name = '%s' matches moz ab %s\n", catID, catName.GetBuffer(0), mozABUrlList[mozABIndex]->GetBuffer(0));
|
||||
foundInABList = TRUE;
|
||||
mozABSeen[mozABIndex] = TRUE; // mark it seen
|
||||
break;
|
||||
}
|
||||
else
|
||||
CONDUIT_LOG3(gFD, "Category index = %d, name = '%s' doesn't match moz ab %s\n", catID, catName.GetBuffer(0), mozABUrlList[mozABIndex]->GetBuffer(0));
|
||||
|
||||
} // end of for
|
||||
|
||||
// we've got a matching moz AB. So, just delete all the cards in the Moz AB and copy over all the cards
|
||||
|
@ -721,11 +747,12 @@ printf("copying hh to pc\n");
|
|||
{
|
||||
CPalmRecord ** recordListPC=NULL;
|
||||
DWORD * newRecIDList=NULL;
|
||||
retval = m_dbPC->DeletePCAB(mozCatIndexList[mozABIndex], *mozABNameList[mozABIndex], *mozABUrlList[mozABIndex]);
|
||||
// retval = m_dbPC->DeletePCAB(mozCatIndexList[mozABIndex], *mozABNameList[mozABIndex], *mozABUrlList[mozABIndex]);
|
||||
retval = m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG1(gFD, " Creating new moz AB with %d Palm record(s) ... ", recordCountHH);
|
||||
CONDUIT_LOG2(gFD, " Creating new moz AB %s with %d Palm record(s) ... ", mozABNameList[mozABIndex]->GetBuffer(0), recordCountHH);
|
||||
if(!retval)
|
||||
retval = m_dbPC->AddRecords(catIndex, catName, recordCountHH, recordListHH);
|
||||
retval = m_dbPC->AddRecords(TRUE, catIndex, *mozABNameList[mozABIndex], recordCountHH, recordListHH);
|
||||
|
||||
CONDUIT_LOG1(gFD, "Done creating new moz AB. retval=%d.\n", retval);
|
||||
// the MozAB is now synchronized
|
||||
if(!retval)
|
||||
|
@ -764,12 +791,17 @@ printf("copying hh to pc\n");
|
|||
retval = m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG1(gFD, " Creating new moz AB with %d Palm record(s) ... ", recordCountHH);
|
||||
if(!retval)
|
||||
retval = m_dbPC->AddRecords(catIndex, catName, recordCountHH, recordListHH);
|
||||
{
|
||||
CPString mozABName;
|
||||
|
||||
retval = m_dbPC->AddRecords(FALSE, catIndex, mozABName, recordCountHH, recordListHH);
|
||||
}
|
||||
CONDUIT_LOG1(gFD, "Done creating new moz AB. retval=%d.\n", retval);
|
||||
}
|
||||
|
||||
// delete and free HH records and recordList once synced
|
||||
if(recordListHH) {
|
||||
if(recordListHH)
|
||||
{
|
||||
CPalmRecord ** tempRecordListHH = recordListHH;
|
||||
for(DWORD i=0; i < recordCountHH; i++)
|
||||
{
|
||||
|
@ -889,8 +921,12 @@ long CMozABConduitSync::CopyPCtoHH()
|
|||
CPCategory cat;
|
||||
retval = m_dbPC->LoadAllRecords(*mozABNameList[mozABIndex],
|
||||
&recordCountPC, &recordListPC);
|
||||
if(!retval) {
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
if(!retval)
|
||||
{
|
||||
if (mozABUrlList[mozABIndex]->CompareNoCase(PERSONAL_ADDRBOOK_URL))
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
else
|
||||
cat.SetName("Personal");
|
||||
CONDUIT_LOG1(gFD, " Creating new Palm AB with %d record(s) ... ", recordCountPC);
|
||||
retval = m_dbHH->AddCategory(cat);
|
||||
CONDUIT_LOG2(gFD, "Done creating new Palm AB, new category index=%d. retval=%d.\n", cat.GetIndex(), retval);
|
||||
|
|
|
@ -96,8 +96,9 @@ protected:
|
|||
long PerformSlowSync();
|
||||
long CopyHHtoPC();
|
||||
long CopyPCtoHH();
|
||||
// utility method
|
||||
BOOL CategoryExists(CPString &mozABName);
|
||||
// utility methods
|
||||
BOOL CategoryExists(CPString &mozABName, CPString &mozABURL);
|
||||
BOOL CategoryNameMatches(CPString &catName, CPString &cutOffMozABName, CPString &mozABURL);
|
||||
|
||||
private:
|
||||
CSyncProperties m_rSyncProperties;
|
||||
|
|
|
@ -229,8 +229,8 @@ long MozABPCManager::SynchronizePCAB(LONG categoryIndex, LONG categoryId, CPStri
|
|||
return retval;
|
||||
}
|
||||
|
||||
// this will add all records in a Palm category into a new Mozilla AB
|
||||
long MozABPCManager::AddRecords(LONG categoryIndex, CPString & categoryName,
|
||||
// this will add all records in a Palm category into a new or existing Mozilla AB
|
||||
long MozABPCManager::AddRecords(BOOL replaceExisting, LONG categoryIndex, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList)
|
||||
{
|
||||
long retval = 0;
|
||||
|
@ -255,7 +255,7 @@ long MozABPCManager::AddRecords(LONG categoryIndex, CPString & categoryName,
|
|||
updatedPalmRecList++;
|
||||
}
|
||||
// get the ABList
|
||||
HRESULT hres = pNsPalmSync->nsAddAllABRecords(FALSE, categoryIndex, categoryName.GetBuffer(0),
|
||||
HRESULT hres = pNsPalmSync->nsAddAllABRecords(FALSE, replaceExisting, categoryIndex, categoryName.GetBuffer(0),
|
||||
updatedPalmRecCount, palmCardList);
|
||||
if (hres != S_OK)
|
||||
retval = (long) hres;
|
||||
|
@ -274,6 +274,17 @@ long MozABPCManager::AddRecords(LONG categoryIndex, CPString & categoryName,
|
|||
return retval;
|
||||
}
|
||||
|
||||
bool MozABPCManager::PCABDeleted(CPString &ABName)
|
||||
{
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return false;
|
||||
BOOL abDeleted;
|
||||
HRESULT hres = pNsPalmSync->nsGetABDeleted(ABName.GetBuffer(0), &abDeleted);
|
||||
return (hres == S_OK) ? abDeleted : false; // assume false;
|
||||
|
||||
}
|
||||
// this load all records in an Moz AB
|
||||
// this function allocates the mozlist as well as the mozRecs, caller should free list and delete recs
|
||||
long MozABPCManager::LoadAllRecords(CPString & ABName, DWORD * pPCRecListCount, CPalmRecord *** pPCRecList)
|
||||
|
|
|
@ -61,8 +61,8 @@ public:
|
|||
long SynchronizePCAB(LONG categoryIndex, LONG categoryId, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList,
|
||||
DWORD * pUpdatedPCRecList, CPalmRecord *** updatedPCRecList);
|
||||
// this will add all records in a Palm category into a new Mozilla AB
|
||||
long AddRecords(LONG categoryIndex, CPString & categoryName,
|
||||
// this will add all records in a Palm category into a new or existing Mozilla AB
|
||||
long AddRecords(BOOL replaceExisting, LONG categoryIndex, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList);
|
||||
// this load all records in an Moz AB
|
||||
long LoadAllRecords(CPString & ABName, DWORD * pPCRecListCount, CPalmRecord *** pPCRecList);
|
||||
|
@ -76,6 +76,7 @@ public:
|
|||
// Rename an Moz AB
|
||||
long RenamePCAB(LONG categoryIndex, CPString & categoryName, CPString & categoryUrl);
|
||||
|
||||
bool PCABDeleted(CPString &abName);
|
||||
static BOOL gUseHomeAddress;
|
||||
static BOOL gPreferHomePhone;
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@
|
|||
#include "nspr.h"
|
||||
PRLogModuleInfo *PALMSYNC;
|
||||
|
||||
#define kPABDirectory 2 // defined in nsDirPrefs.h
|
||||
#define kPABDirectory 2 // defined in nsDirPrefs.h
|
||||
#define kMAPIDirectory 3
|
||||
|
||||
CPalmSyncImp::CPalmSyncImp()
|
||||
: m_cRef(1),
|
||||
|
@ -149,11 +150,40 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount,
|
|||
{
|
||||
// Get the total number of addrbook.
|
||||
PRInt16 count=0;
|
||||
nsCOMPtr<nsISupports> item;
|
||||
if (NS_SUCCEEDED(subDirectories->First()))
|
||||
do
|
||||
{
|
||||
count++;
|
||||
} while (NS_SUCCEEDED(subDirectories->Next()));
|
||||
do
|
||||
{
|
||||
if (NS_SUCCEEDED(subDirectories->CurrentItem(getter_AddRefs(item))))
|
||||
{
|
||||
directory = do_QueryInterface(item, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr <nsIAbDirectoryProperties> properties;
|
||||
nsXPIDLCString fileName;
|
||||
rv = directory->GetDirectoryProperties(getter_AddRefs(properties));
|
||||
if(NS_FAILED(rv))
|
||||
continue;
|
||||
rv = properties->GetFileName(getter_Copies(fileName));
|
||||
if(NS_FAILED(rv))
|
||||
continue;
|
||||
PRUint32 dirType;
|
||||
rv = properties->GetDirType(&dirType);
|
||||
nsCAutoString prefName;
|
||||
directory->GetDirPrefId(prefName);
|
||||
prefName.Append(".disablePalmSync");
|
||||
PRBool disableThisAB = GetBoolPref(prefName.get(), PR_FALSE);
|
||||
// Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
|
||||
if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) &&
|
||||
strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
|
||||
(dirType != kPABDirectory && dirType != kMAPIDirectory))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
} while (NS_SUCCEEDED(subDirectories->Next()));
|
||||
}
|
||||
|
||||
if (!count)
|
||||
return E_FAIL; // should not happen but just in case.
|
||||
|
@ -168,7 +198,6 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount,
|
|||
*aABCatIndexList = catIndexList;
|
||||
|
||||
// For each valid addrbook collect info.
|
||||
nsCOMPtr<nsISupports> item;
|
||||
if (NS_SUCCEEDED(subDirectories->First()))
|
||||
{
|
||||
do
|
||||
|
@ -204,13 +233,16 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount,
|
|||
directory->GetDirPrefId(prefName);
|
||||
prefName.Append(".disablePalmSync");
|
||||
PRBool disableThisAB = GetBoolPref(prefName.get(), PR_FALSE);
|
||||
// Skip/Ignore 4.X addrbooks (ie, with ".na2" extension).
|
||||
// Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
|
||||
if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) &&
|
||||
strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) &&
|
||||
(dirType == kPABDirectory))
|
||||
strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
|
||||
(dirType != kPABDirectory && dirType != kMAPIDirectory))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(aIsUnicode) {
|
||||
if(aIsUnicode)
|
||||
{
|
||||
// convert uri to Unicode
|
||||
nsAutoString abUrl;
|
||||
rv = ConvertToUnicode("UTF-8", uri.get(), abUrl);
|
||||
|
@ -253,7 +285,7 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount,
|
|||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Synchronize the Address Book represented by the aCategoryIndex and/or corresponding aABName in Mozilla
|
||||
|
@ -281,14 +313,14 @@ STDMETHODIMP CPalmSyncImp::nsSynchronizeAB(BOOL aIsUnicode, long aCategoryIndex,
|
|||
}
|
||||
|
||||
// All records from a AB represented by aCategoryIndex and aABName into a new Mozilla AB
|
||||
STDMETHODIMP CPalmSyncImp::nsAddAllABRecords(BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName,
|
||||
STDMETHODIMP CPalmSyncImp::nsAddAllABRecords(BOOL aIsUnicode, BOOL replaceExisting, long aCategoryIndex, LPTSTR aABName,
|
||||
int aRemoteRecCount, lpnsABCOMCardStruct aRemoteRecList)
|
||||
{
|
||||
// since we are not returning any data we don't need to keep the nsAbPalmHotSync reference
|
||||
// in order to free the returned data in its destructor. Just create a local nsAbPalmHotSync var.
|
||||
nsAbPalmHotSync palmHotSync(aIsUnicode, aABName, (const char*)aABName, aCategoryIndex, -1);
|
||||
|
||||
nsresult rv = palmHotSync.AddAllRecordsInNewAB(aRemoteRecCount, aRemoteRecList);
|
||||
nsresult rv = palmHotSync.AddAllRecordsToAB(replaceExisting, aRemoteRecCount, aRemoteRecList);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return E_FAIL;
|
||||
|
@ -296,6 +328,17 @@ STDMETHODIMP CPalmSyncImp::nsAddAllABRecords(BOOL aIsUnicode, long aCategoryInde
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CPalmSyncImp::nsGetABDeleted(LPTSTR aABName, BOOL *abDeleted)
|
||||
{
|
||||
nsCAutoString prefName("ldap_2.servers.");
|
||||
prefName.Append((const char *)aABName);
|
||||
prefName.Append(".position");
|
||||
PRInt32 position = GetIntPref(prefName.get(), -1);
|
||||
*abDeleted = (position == 0);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
// Get All records from a Mozilla AB
|
||||
STDMETHODIMP CPalmSyncImp::nsGetAllABCards(BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName,
|
||||
int * aMozRecCount, lpnsABCOMCardStruct * aMozRecList)
|
||||
|
@ -408,27 +451,27 @@ void CPalmSyncImp::CopyCString(LPTSTR *destStr, nsCString srcStr)
|
|||
}
|
||||
|
||||
|
||||
PRBool CPalmSyncImp::GetBoolPref(const char *prefName, PRBool defaultVal)
|
||||
/* static */PRBool CPalmSyncImp::GetBoolPref(const char *prefName, PRBool defaultVal)
|
||||
{
|
||||
PRBool boolVal = defaultVal;
|
||||
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
|
||||
(void) prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
if (prefBranch)
|
||||
{
|
||||
|
||||
PRBool bVal = PR_FALSE;
|
||||
prefBranch->GetBoolPref(prefName, &boolVal);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefBranch)
|
||||
prefBranch->GetBoolPref(prefName, &boolVal);
|
||||
return boolVal;
|
||||
}
|
||||
|
||||
/* static */PRInt32 CPalmSyncImp::GetIntPref(const char *prefName, PRInt32 defaultVal)
|
||||
{
|
||||
PRInt32 intVal = defaultVal;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefBranch)
|
||||
prefBranch->GetIntPref(prefName, &intVal);
|
||||
return intVal;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CPalmSyncImp::nsUseABHomeAddressForPalmAddress(BOOL *aUseHomeAddress)
|
||||
{
|
||||
*aUseHomeAddress = nsUseABHomeAddressForPalmAddress();
|
||||
|
|
|
@ -74,7 +74,7 @@ public :
|
|||
int aModRemoteRecCount, lpnsABCOMCardStruct aModRemoteRecList,
|
||||
int * aModMozRecCount, lpnsABCOMCardStruct * aModMozRecList);
|
||||
|
||||
STDMETHODIMP nsAddAllABRecords(BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName,
|
||||
STDMETHODIMP nsAddAllABRecords(BOOL aIsUnicode, BOOL replaceExisting, long aCategoryIndex, LPTSTR aABName,
|
||||
int aRemoteRecCount, lpnsABCOMCardStruct aRemoteRecList);
|
||||
|
||||
|
||||
|
@ -93,7 +93,10 @@ public :
|
|||
|
||||
STDMETHODIMP nsPreferABHomePhoneForPalmPhone(BOOL *aPreferHomePhone);
|
||||
|
||||
STDMETHODIMP nsGetABDeleted(LPTSTR aABName, BOOL *abDeleted);
|
||||
|
||||
static PRBool GetBoolPref(const char *prefName, PRBool defaultVal);
|
||||
static PRInt32 GetIntPref(const char *prefName, PRInt32 defaultVal);
|
||||
static PRBool nsUseABHomeAddressForPalmAddress();
|
||||
static PRBool nsPreferABHomePhoneForPalmPhone();
|
||||
private :
|
||||
|
|
|
@ -184,14 +184,6 @@ nsresult nsAbPalmHotSync::GetABInterface()
|
|||
if (NS_FAILED(directory->GetChildNodes(getter_AddRefs(subDirectories))) || !subDirectories)
|
||||
return E_FAIL;
|
||||
|
||||
// Get the total number of addrbook.
|
||||
PRInt16 count=0;
|
||||
if (NS_SUCCEEDED(subDirectories->First()))
|
||||
do
|
||||
{
|
||||
count++;
|
||||
} while (NS_SUCCEEDED(subDirectories->Next()));
|
||||
|
||||
// Check each valid addrbook.
|
||||
nsCOMPtr<nsISupports> item;
|
||||
if (NS_SUCCEEDED(subDirectories->First()))
|
||||
|
@ -223,8 +215,8 @@ nsresult nsAbPalmHotSync::GetABInterface()
|
|||
|
||||
// Skip/Ignore 4.X addrbooks (ie, with ".na2" extension).
|
||||
if (((fileName.Length() > kABFileName_PreviousSuffixLen) &&
|
||||
strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) &&
|
||||
(dirType == kPABDirectory))
|
||||
strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
|
||||
(dirType != kPABDirectory && dirType != kMAPIDirectory))
|
||||
continue;
|
||||
|
||||
// If Palm category is already assigned to AB then just check that (ie, was synced before).
|
||||
|
@ -270,21 +262,39 @@ nsresult nsAbPalmHotSync::Initialize()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsAbPalmHotSync::AddAllRecordsInNewAB(PRInt32 aCount, lpnsABCOMCardStruct aPalmRecords)
|
||||
nsresult nsAbPalmHotSync::AddAllRecordsToAB(PRBool existingAB, PRInt32 aCount, lpnsABCOMCardStruct aPalmRecords)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPalmRecords);
|
||||
|
||||
nsresult rv;
|
||||
// Create the new AB dir before adding cards/records.
|
||||
nsresult rv = NewAB(mAbName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (existingAB)
|
||||
{
|
||||
rv = Initialize();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = OpenABDBForHotSync(PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// lets try deleting the db out from under ourselves.
|
||||
nsFileSpec *abFileSpec;
|
||||
rv = mABDB->GetDbPath(&abFileSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mABDB->ForceClosed();
|
||||
mDBOpen = PR_FALSE;
|
||||
mABDB = nsnull;
|
||||
abFileSpec->Delete(PR_FALSE);
|
||||
delete abFileSpec;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsresult rv = NewAB(mAbName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = Initialize(); // Find the new AB and and init some vars (set mDirectory etc).
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = Initialize(); // Find the new AB and and init some vars (set mDirectory etc).
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// open the Moz AB database
|
||||
rv = OpenABDBForHotSync(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// we are just storing the pointer array here not record arrays
|
||||
for (PRInt32 i=0; i < aCount; i++)
|
||||
mPalmRecords.AppendElement(&aPalmRecords[i]);
|
||||
|
@ -807,10 +817,19 @@ nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords()
|
|||
LL_L2F(f, l);
|
||||
PR_cnvtf(recordIDBuf, 128, 0, f);
|
||||
|
||||
// if the card already exist
|
||||
// if the card already exists
|
||||
nsCOMPtr<nsIAbCard> existingCard;
|
||||
rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_PALMID, recordIDBuf,
|
||||
PR_FALSE, getter_AddRefs(existingCard));
|
||||
if (!existingCard)
|
||||
{
|
||||
rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_DISPLAY, NS_ConvertUCS2toUTF8(palmRec->displayName).get(),
|
||||
PR_FALSE, getter_AddRefs(existingCard));
|
||||
// if card with this display name exists, just continue;
|
||||
if (NS_SUCCEEDED(rv) && existingCard)
|
||||
continue;
|
||||
|
||||
}
|
||||
if(NS_SUCCEEDED(rv) && existingCard)
|
||||
{
|
||||
// Archived is the same as deleted in palm.
|
||||
|
@ -1004,7 +1023,7 @@ nsresult nsAbPalmHotSync::RenameAB(long aCategoryIndex, const char * aABUrl)
|
|||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
rv = properties->SetURI(aABUrl);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
rv = properties->SetDirType(kMAPIDirectory); // MAPI dir type for PalmSync
|
||||
rv = properties->SetDirType(kPABDirectory); // pab dir type for PalmSync
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
rv = properties->SetCategoryId(aCategoryIndex);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
@ -1024,7 +1043,7 @@ nsresult nsAbPalmHotSync::NewAB(const nsString& aAbName)
|
|||
|
||||
nsCOMPtr <nsIAbDirectoryProperties> properties = do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
properties->SetDirType(kMAPIDirectory); // MAPI addrbook type
|
||||
properties->SetDirType(kPABDirectory);
|
||||
properties->SetDescription(aAbName);
|
||||
|
||||
return(ab->NewAddressBook(properties));
|
||||
|
@ -1032,7 +1051,7 @@ nsresult nsAbPalmHotSync::NewAB(const nsString& aAbName)
|
|||
|
||||
nsresult nsAbPalmHotSync::UpdateABInfo(PRUint32 aModTime, PRInt32 aCategoryIndex)
|
||||
{
|
||||
// Fill in perperty info and call ModifyAB().
|
||||
// Fill in property info and call ModifyAB().
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIAbDirectoryProperties> properties(do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
nsresult GetCardsToBeSentToPalm(PRInt32 * aCount, lpnsABCOMCardStruct * aCardList);
|
||||
|
||||
// this will create a new AB and all data into it
|
||||
nsresult AddAllRecordsInNewAB(PRInt32 aCount, lpnsABCOMCardStruct aPalmRecords);
|
||||
nsresult AddAllRecordsToAB(PRBool replaceExisting, PRInt32 aCount, lpnsABCOMCardStruct aPalmRecords);
|
||||
|
||||
// this will be called when an AckSyncDone is recieved from the Conduit
|
||||
nsresult Done(PRBool aSuccess, PRInt32 aPalmCatIndex, PRUint32 aPalmRecIDListCount = 0, unsigned long * aPalmRecordIDList = nsnull);
|
||||
|
|
Загрузка…
Ссылка в новой задаче