provide palmsync conduit capability for handheld to overwrite desktop or vice versa, 222016, r/sr=mscott
git-svn-id: svn://10.0.0.236/trunk@151237 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
dae458dd06
commit
0e14f9d795
@ -348,6 +348,14 @@ long CALLBACK CondCfgDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPar
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_SYNC_FILES, szBuffer,
|
||||
sizeof(szBuffer));
|
||||
break;
|
||||
case ePCtoHH:
|
||||
CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, IDC_RADIO_PCTOHH);
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_PCTOHH, szBuffer, sizeof(szBuffer));
|
||||
break;
|
||||
case eHHtoPC:
|
||||
CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, IDC_RADIO_HHTOPC);
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_HHTOPC, szBuffer, sizeof(szBuffer));
|
||||
break;
|
||||
case eDoNothing:
|
||||
default:
|
||||
CheckRadioButton(hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING,
|
||||
@ -368,6 +376,15 @@ long CALLBACK CondCfgDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPar
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_SYNC_FILES, szBuffer,
|
||||
sizeof(szBuffer));
|
||||
break;
|
||||
case ePCtoHH:
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_PCTOHH, szBuffer,
|
||||
sizeof(szBuffer));
|
||||
break;
|
||||
|
||||
case eHHtoPC:
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_HHTOPC, szBuffer,
|
||||
sizeof(szBuffer));
|
||||
break;
|
||||
case eDoNothing:
|
||||
default:
|
||||
LoadString((HINSTANCE)hLangInstance, IDS_DO_NOTHING, szBuffer,
|
||||
@ -388,14 +405,22 @@ long CALLBACK CondCfgDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPar
|
||||
{
|
||||
case IDC_RADIO_SYNC:
|
||||
case IDC_RADIO_DONOTHING:
|
||||
case IDC_RADIO_HHTOPC:
|
||||
case IDC_RADIO_PCTOHH:
|
||||
CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, wParam);
|
||||
break;
|
||||
case IDCANCEL:
|
||||
EndDialog(hWnd, 1);
|
||||
return TRUE;
|
||||
case IDOK:
|
||||
pCfgInfo->syncNew = (IsDlgButtonChecked(hWnd, IDC_RADIO_SYNC))
|
||||
? eFast : eDoNothing;
|
||||
if (IsDlgButtonChecked(hWnd, IDC_RADIO_SYNC))
|
||||
pCfgInfo->syncNew = eFast;
|
||||
else if (IsDlgButtonChecked(hWnd, IDC_RADIO_PCTOHH))
|
||||
pCfgInfo->syncNew = ePCtoHH;
|
||||
else if (IsDlgButtonChecked(hWnd, IDC_RADIO_HHTOPC))
|
||||
pCfgInfo->syncNew = eHHtoPC;
|
||||
else
|
||||
pCfgInfo->syncNew = eDoNothing;
|
||||
pCfgInfo->syncPref = (IsDlgButtonChecked(hWnd, IDC_MAKEDEFAULT))
|
||||
? ePermanentPreference : eTemporaryPreference;
|
||||
EndDialog(hWnd, 0);
|
||||
@ -448,4 +473,22 @@ void LdCfgDlgBmps(HWND hDlg)
|
||||
if (hOldBmp != NULL)
|
||||
DeleteObject((HGDIOBJ)hOldBmp);
|
||||
}
|
||||
hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_PCTOHH, 0, &cMap, 1);
|
||||
// associate the bitmap with the button.
|
||||
if ((hwndButton = GetDlgItem(hDlg, IDC_PCTOHH)) != NULL)
|
||||
{
|
||||
hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
|
||||
(WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
|
||||
if (hOldBmp != NULL)
|
||||
DeleteObject((HGDIOBJ)hOldBmp);
|
||||
}
|
||||
hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_HHTOPC, 0, &cMap, 1);
|
||||
// associate the bitmap with the button.
|
||||
if ((hwndButton = GetDlgItem(hDlg, IDC_HHTOPC)) != NULL)
|
||||
{
|
||||
hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
|
||||
(WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
|
||||
if (hOldBmp != NULL)
|
||||
DeleteObject((HGDIOBJ)hOldBmp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,26 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -13,8 +32,19 @@ BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -22,24 +52,32 @@ END
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_CONDUIT_ACTION DIALOG DISCARDABLE 0, 0, 260, 80
|
||||
IDD_CONDUIT_ACTION DIALOG DISCARDABLE 0, 0, 294, 114
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Change HotSync Action"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
RADIOBUTTON "&Synchronize the files",IDC_RADIO_SYNC,72,28,79,10,
|
||||
RADIOBUTTON "&Synchronize the files",IDC_RADIO_SYNC,71,28,81,10,
|
||||
WS_GROUP | WS_TABSTOP
|
||||
RADIOBUTTON "Do ¬hing",IDC_RADIO_DONOTHING,72,49,48,10
|
||||
RADIOBUTTON "&Desktop overwrites handheld",IDC_RADIO_PCTOHH,71,40,
|
||||
108,10,WS_GROUP
|
||||
RADIOBUTTON "&Handheld overwrites Desktop",IDC_RADIO_HHTOPC,71,52,
|
||||
109,10,WS_GROUP
|
||||
RADIOBUTTON "Do ¬hing",IDC_RADIO_DONOTHING,71,64,51,10,WS_GROUP
|
||||
CONTROL "Set &as default",IDC_MAKEDEFAULT,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,196,64,58,10
|
||||
DEFPUSHBUTTON "OK",IDOK,196,11,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,196,27,50,14
|
||||
GROUPBOX "<PlaceHolder>",IDC_ACTIONGROUPBOXTEXT,8,8,177,64,
|
||||
GROUPBOX "<PlaceHolder>",IDC_ACTIONGROUPBOXTEXT,5,6,186,105,
|
||||
WS_GROUP
|
||||
CONTROL 103,IDC_SYNC,"Static",SS_BITMAP,14,26,32,15
|
||||
CONTROL 106,IDC_DONOTHING,"Static",SS_BITMAP,14,47,32,15
|
||||
CONTROL 103,IDC_SYNC,"Static",SS_BITMAP | WS_GROUP,18,26,32,15
|
||||
CONTROL 106,IDC_DONOTHING,"Static",SS_BITMAP | WS_GROUP,18,62,15,
|
||||
13
|
||||
CONTROL 105,IDC_PCTOHH,"Static",SS_BITMAP | WS_GROUP,18,39,32,15
|
||||
CONTROL 102,IDC_HHTOPC,"Static",SS_BITMAP | WS_GROUP,18,49,32,15
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Bitmap
|
||||
@ -47,6 +85,8 @@ END
|
||||
|
||||
IDB_DONOTHING BITMAP DISCARDABLE "res\\DoNothing.bmp"
|
||||
IDB_SYNC BITMAP DISCARDABLE "res\\Synchronize.bmp"
|
||||
IDB_HHTOPC BITMAP DISCARDABLE "res\\HhToPc.bmp"
|
||||
IDB_PCTOHH BITMAP DISCARDABLE "res\\PcToHh.bmp"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -67,9 +107,24 @@ STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
IDS_CURRENT_SETTINGS_GROUP "%s's Current Settings:"
|
||||
IDS_SYNC_FILES "Synchronize the files."
|
||||
IDS_PCTOHH "Desktop overwrites Palm organizer."
|
||||
IDS_HHTOPC "Palm organizer overwrites Desktop."
|
||||
IDS_DO_NOTHING "Do Nothing."
|
||||
IDS_SYNC_ACTION_TEXT "HotSync Action for Mozilla Address Book"
|
||||
END
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
|
||||
@ -590,11 +590,346 @@ long CMozABConduitSync::PerformSlowSync()
|
||||
|
||||
long CMozABConduitSync::CopyHHtoPC()
|
||||
{
|
||||
return 0;
|
||||
long retval=0;
|
||||
BOOL success = FALSE;
|
||||
|
||||
// Log the start time.
|
||||
time_t ltime;
|
||||
time( <ime );
|
||||
CONDUIT_LOG1(gFD, "------------ START OF PALM SYNC Palm -> Destkop ------------ at %s", ctime(<ime));
|
||||
|
||||
if(!m_dbHH)
|
||||
return retval;
|
||||
|
||||
DWORD mozABCount=0;
|
||||
LONG * mozCatIndexList = NULL; // freed by MSCOM/Mozilla
|
||||
CPString ** mozABNameList = NULL; // freed by MSCOM/Mozilla
|
||||
CPString ** mozABUrlList = NULL; // freed by MSCOM/Mozilla
|
||||
BOOL * mozIsFirstSyncList = NULL; // freed by MSCOM/Mozilla
|
||||
BOOL neverDidPalmSyncBefore = TRUE; // 1st time palm sync?
|
||||
DWORD mozABIndex;
|
||||
|
||||
retval = m_dbHH->OpenDB(FALSE);
|
||||
if (!retval)
|
||||
retval = m_dbHH->LoadCategories();
|
||||
|
||||
CONDUIT_LOG0(gFD, "Getting moz AB List ... ");
|
||||
if(!retval)
|
||||
retval = m_dbPC->GetPCABList(&mozABCount, &mozCatIndexList, &mozABNameList, &mozABUrlList, &mozIsFirstSyncList);
|
||||
|
||||
if (retval)
|
||||
return retval;
|
||||
CONDUIT_LOG0(gFD, "Done getting moz AB List. \n");
|
||||
|
||||
// Create an array to help us identify addrbooks that have been deleted on Palm.
|
||||
DWORD *mozABSeen = (DWORD *) CoTaskMemAlloc(sizeof(DWORD) * mozABCount);
|
||||
if (!mozABSeen)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
else
|
||||
memset(mozABSeen, FALSE, sizeof(DWORD) * mozABCount);
|
||||
|
||||
// See if palm sync was performed before.
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
if (! mozIsFirstSyncList[mozABIndex])
|
||||
{
|
||||
neverDidPalmSyncBefore = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
// Log moz addrbooks.
|
||||
for (mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
{
|
||||
CONDUIT_LOG5(gFD, "Moz AB[%d] category index/synced=%d/%d, name= '%s', url= '%s'\n",
|
||||
mozABIndex, mozCatIndexList[mozABIndex], !mozIsFirstSyncList[mozABIndex],
|
||||
mozABNameList[mozABIndex]->GetBuffer(0), mozABUrlList[mozABIndex]->GetBuffer(0));
|
||||
}
|
||||
|
||||
// For each category, try to find the corresponding AB in the moz AB list
|
||||
// and overwrite it with the HH category.
|
||||
CPCategory * pCategory = m_dbHH->GetFirstCategory();
|
||||
while (pCategory)
|
||||
{
|
||||
CPalmRecord ** recordListHH = NULL;
|
||||
DWORD recordCountHH=0;
|
||||
|
||||
DWORD catID = pCategory->GetID();
|
||||
DWORD catIndex = pCategory->GetIndex();
|
||||
DWORD catFlags = pCategory->GetFlags();
|
||||
CPString catName(pCategory->GetName());
|
||||
|
||||
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++)
|
||||
{
|
||||
// Palm only allows 15 chars for category names.
|
||||
CPString cutOffName;
|
||||
if (mozABNameList[mozABIndex]->Length() > 15)
|
||||
cutOffName = mozABNameList[mozABIndex]->Left(15);
|
||||
else
|
||||
cutOffName = *mozABNameList[mozABIndex];
|
||||
|
||||
// if this category has been synchronized before, check if it has been renamed
|
||||
if(catIndex == mozCatIndexList[mozABIndex])
|
||||
{
|
||||
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)))
|
||||
{
|
||||
abRenamed = TRUE;
|
||||
CONDUIT_LOG3(gFD, "Category index = %d, name = '%s' was renamed (from '%s') on Palm so do the same on moz\n",
|
||||
catID, catName.GetBuffer(0), mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
}
|
||||
break;
|
||||
}
|
||||
// if corresponding category exists
|
||||
if(!catName.CompareNoCase(cutOffName.GetBuffer(0))){
|
||||
retval = m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' matches moz ab\n", catID, catName.GetBuffer(0));
|
||||
foundInABList = TRUE;
|
||||
mozABSeen[mozABIndex] = TRUE; // mark it seen
|
||||
break;
|
||||
}
|
||||
} // 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
|
||||
// in the HH category.
|
||||
if(!retval && foundInABList)
|
||||
{
|
||||
CPalmRecord ** recordListPC=NULL;
|
||||
DWORD * newRecIDList=NULL;
|
||||
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);
|
||||
if(!retval)
|
||||
retval = m_dbPC->AddRecords(catIndex, catName, recordCountHH, recordListHH);
|
||||
CONDUIT_LOG1(gFD, "Done creating new moz AB. retval=%d.\n", retval);
|
||||
// the MozAB is now synchronized
|
||||
if(!retval)
|
||||
mozIsFirstSyncList[mozABIndex] = FALSE;
|
||||
// delete the PC recordList now that palm is updated
|
||||
if(recordListPC)
|
||||
free(recordListPC);
|
||||
// notify Mozilla that sync is done so that memory can be freed
|
||||
success = retval ? FALSE : TRUE;
|
||||
|
||||
retval = m_dbPC->NotifySyncDone(success);
|
||||
|
||||
if(newRecIDList)
|
||||
free(newRecIDList);
|
||||
|
||||
// See if it was renamed on palm.
|
||||
if (abRenamed)
|
||||
{
|
||||
// We should not rename personal and collected address books here.
|
||||
if (mozABUrlList[mozABIndex]->CompareNoCase(PERSONAL_ADDRBOOK_URL) &&
|
||||
mozABUrlList[mozABIndex]->CompareNoCase(COLLECTED_ADDRBOOK_URL))
|
||||
{
|
||||
CONDUIT_LOG0(gFD, " Renaming AB ... ");
|
||||
retval = m_dbPC->RenamePCAB(catIndex, catName, *mozABUrlList[mozABIndex]);
|
||||
CONDUIT_LOG1(gFD, "Done renaming AB. retval=%d.\n", retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If this category can't be found in the moz AB list, then
|
||||
// create a new AB in moz with all records in this category
|
||||
// (even if it's an empty AB).
|
||||
if(!retval && !foundInABList)
|
||||
{
|
||||
CONDUIT_LOG2(gFD, "Category index = %d, name = '%s' is new on palm and needs to be added to moz\n", catID, catName.GetBuffer(0));
|
||||
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);
|
||||
CONDUIT_LOG1(gFD, "Done creating new moz AB. retval=%d.\n", retval);
|
||||
}
|
||||
|
||||
// delete and free HH records and recordList once synced
|
||||
if(recordListHH) {
|
||||
CPalmRecord ** tempRecordListHH = recordListHH;
|
||||
for(DWORD i=0; i < recordCountHH; i++)
|
||||
{
|
||||
delete *tempRecordListHH;
|
||||
tempRecordListHH++;
|
||||
}
|
||||
free(recordListHH);
|
||||
}
|
||||
|
||||
// Process next category
|
||||
pCategory = m_dbHH->GetNextCategory();
|
||||
} // end of while
|
||||
|
||||
// Free stuff we allocated.
|
||||
CoTaskMemFree(mozABSeen);
|
||||
|
||||
// update category info in HH
|
||||
m_dbHH->CompactCategoriesToHH();
|
||||
|
||||
// close the HH DB once synced
|
||||
retval = m_dbHH->CloseDB(FALSE);
|
||||
|
||||
// Log the end time.
|
||||
time( <ime );
|
||||
CONDUIT_LOG1(gFD, "------------ END OF PALM SYNC ------------ at %s\n", ctime(<ime));
|
||||
return retval;
|
||||
}
|
||||
|
||||
long CMozABConduitSync::CopyPCtoHH()
|
||||
{
|
||||
return 0;
|
||||
long retval=0;
|
||||
BOOL success = FALSE;
|
||||
|
||||
// Log the start time.
|
||||
time_t ltime;
|
||||
time( <ime );
|
||||
CONDUIT_LOG1(gFD, "------------ START OF PALM SYNC Destkop-> Palm ------------ at %s", ctime(<ime));
|
||||
|
||||
if(!m_dbHH)
|
||||
return retval;
|
||||
|
||||
DWORD mozABCount=0;
|
||||
LONG * mozCatIndexList = NULL; // freed by MSCOM/Mozilla
|
||||
CPString ** mozABNameList = NULL; // freed by MSCOM/Mozilla
|
||||
CPString ** mozABUrlList = NULL; // freed by MSCOM/Mozilla
|
||||
BOOL * mozIsFirstSyncList = NULL; // freed by MSCOM/Mozilla
|
||||
BOOL neverDidPalmSyncBefore = TRUE; // 1st time palm sync?
|
||||
DWORD mozABIndex;
|
||||
|
||||
retval = m_dbHH->OpenDB(FALSE);
|
||||
if (!retval)
|
||||
retval = m_dbHH->LoadCategories();
|
||||
|
||||
CONDUIT_LOG0(gFD, "Getting moz AB List ... ");
|
||||
if(!retval)
|
||||
retval = m_dbPC->GetPCABList(&mozABCount, &mozCatIndexList, &mozABNameList, &mozABUrlList, &mozIsFirstSyncList);
|
||||
|
||||
if (retval)
|
||||
return retval;
|
||||
CONDUIT_LOG0(gFD, "Done getting moz AB List. \n");
|
||||
|
||||
// Create an array to help us identify addrbooks that have been deleted on Palm.
|
||||
DWORD *mozABSeen = (DWORD *) CoTaskMemAlloc(sizeof(DWORD) * mozABCount);
|
||||
if (!mozABSeen)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
else
|
||||
memset(mozABSeen, FALSE, sizeof(DWORD) * mozABCount);
|
||||
|
||||
// See if palm sync was performed before.
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
if (! mozIsFirstSyncList[mozABIndex])
|
||||
{
|
||||
neverDidPalmSyncBefore = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
// Log moz addrbooks.
|
||||
for (mozABIndex=0; mozABIndex<mozABCount; mozABIndex++)
|
||||
{
|
||||
CONDUIT_LOG5(gFD, "Moz AB[%d] category index/synced=%d/%d, name= '%s', url= '%s'\n",
|
||||
mozABIndex, mozCatIndexList[mozABIndex], !mozIsFirstSyncList[mozABIndex],
|
||||
mozABNameList[mozABIndex]->GetBuffer(0), mozABUrlList[mozABIndex]->GetBuffer(0));
|
||||
}
|
||||
|
||||
// For each category, try to find the corresponding AB in the moz AB list
|
||||
// and see if it has been synchronized before and take action accordingly.
|
||||
CPCategory * pCategory = m_dbHH->GetFirstCategory();
|
||||
while (pCategory)
|
||||
{
|
||||
CPalmRecord ** recordListHH = NULL;
|
||||
DWORD recordCountHH=0;
|
||||
|
||||
DWORD catID = pCategory->GetID();
|
||||
DWORD catIndex = pCategory->GetIndex();
|
||||
DWORD catFlags = pCategory->GetFlags();
|
||||
CPString catName(pCategory->GetName());
|
||||
|
||||
CONDUIT_LOG3(gFD, "\nProcessing Palm AB '%s' (catIndex/catId) = (%d/%d)... \n", catName.GetBuffer(0), catIndex, catID);
|
||||
BOOL abRenamed = FALSE;
|
||||
BOOL foundInABList=FALSE;
|
||||
|
||||
retval = m_dbHH->DeleteCategory(catIndex, FALSE); // delete the category - we'll recreate from moz ab.
|
||||
|
||||
// Process next category
|
||||
pCategory = m_dbHH->GetNextCategory();
|
||||
} // end of while
|
||||
|
||||
// Deal with any Moz AB not existing in Palm, ones not sync'ed above,
|
||||
// and the case where Palm ABs have been deleted.
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; 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));
|
||||
CPalmRecord ** recordListPC=NULL;
|
||||
DWORD recordCountPC=0;
|
||||
DWORD * newRecIDList=NULL;
|
||||
CPCategory cat;
|
||||
retval = m_dbPC->LoadAllRecords(*mozABNameList[mozABIndex],
|
||||
&recordCountPC, &recordListPC);
|
||||
if(!retval) {
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
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);
|
||||
if(!retval) {
|
||||
CONDUIT_LOG1(gFD, " Adding %d record(s) to new Palm AB ... ", recordCountPC);
|
||||
newRecIDList = (DWORD *) calloc(recordCountPC, sizeof(DWORD));
|
||||
for (unsigned long i=0; i < recordCountPC; i++)
|
||||
{
|
||||
if(!recordListPC[i])
|
||||
continue;
|
||||
CPalmRecord palmRec = *recordListPC[i];
|
||||
palmRec.SetCategory(cat.GetIndex());
|
||||
retval = m_dbHH->AddARecord(palmRec); // should we check existing recs?
|
||||
newRecIDList[i] = palmRec.GetID();
|
||||
delete recordListPC[i]; // delete the record now that it is used
|
||||
}
|
||||
CONDUIT_LOG0(gFD, "Done adding new records to new Palm AB.\n");
|
||||
}
|
||||
else
|
||||
CONDUIT_LOG1(gFD, "Creating new Palm AB failed. retval=%d.\n", retval);
|
||||
}
|
||||
else
|
||||
CONDUIT_LOG1(gFD, " Loading moz AB records failed so can't create new Palm AB. retval=%d.\n", retval);
|
||||
|
||||
|
||||
// delete the recordList now that palm is updated
|
||||
if(recordListPC)
|
||||
free(recordListPC);
|
||||
// notify Mozilla that sync is done so that memory can be freed
|
||||
if(!retval)
|
||||
success = TRUE;
|
||||
else
|
||||
{
|
||||
success = FALSE;
|
||||
recordCountPC=0;
|
||||
}
|
||||
retval = m_dbPC->NotifySyncDone(success, cat.GetIndex(), recordCountPC, newRecIDList);
|
||||
if(newRecIDList)
|
||||
free(newRecIDList);
|
||||
|
||||
// Lastly, update the AB with new category index and mod time.
|
||||
retval = m_dbPC->UpdatePCABSyncInfo(success ? cat.GetIndex() : -1, *mozABNameList[mozABIndex]);
|
||||
} // end of mozAB not existing in Palm for loop
|
||||
|
||||
// Purge deleted Palm record permanently (in case they were logically deleted).
|
||||
m_dbHH->PurgeDeletedRecs();
|
||||
|
||||
// Free stuff we allocated.
|
||||
CoTaskMemFree(mozABSeen);
|
||||
|
||||
// update category info in HH
|
||||
m_dbHH->CompactCategoriesToHH();
|
||||
|
||||
// close the HH DB once synced
|
||||
retval = m_dbHH->CloseDB(FALSE);
|
||||
|
||||
// Log the end time.
|
||||
time( <ime );
|
||||
CONDUIT_LOG1(gFD, "------------ END OF PALM SYNC ------------ at %s\n", ctime(<ime));
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -163,9 +163,12 @@ long MozABPCManager::SynchronizePCAB(LONG categoryIndex, LONG categoryId, CPStri
|
||||
|
||||
CMozABConduitRecord ** tempMozABConduitRecList = new CMozABConduitRecord*[updatedPalmRecCount];
|
||||
nsABCOMCardStruct * palmCardList = new nsABCOMCardStruct[updatedPalmRecCount];
|
||||
if(palmCardList) {
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++) {
|
||||
if(*updatedPalmRecList) {
|
||||
if(palmCardList)
|
||||
{
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++)
|
||||
{
|
||||
if(*updatedPalmRecList)
|
||||
{
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(**updatedPalmRecList);
|
||||
memcpy(&palmCardList[i], &pConduitRecord->m_nsCard, sizeof(nsABCOMCardStruct));
|
||||
tempMozABConduitRecList[i]=pConduitRecord;
|
||||
@ -176,14 +179,17 @@ long MozABPCManager::SynchronizePCAB(LONG categoryIndex, LONG categoryId, CPStri
|
||||
HRESULT hres = pNsPalmSync->nsSynchronizeAB(FALSE, categoryIndex, categoryId, categoryName.GetBuffer(0),
|
||||
updatedPalmRecCount, palmCardList,
|
||||
&dwMozCardCount, &mozCardList);
|
||||
if(hres == S_OK && mozCardList) {
|
||||
if(hres == S_OK && mozCardList)
|
||||
{
|
||||
*pUpdatedPCRecListCount = dwMozCardCount;
|
||||
CPalmRecord ** mozRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
*updatedPCRecList = mozRecordList;
|
||||
if (mozRecordList) {
|
||||
if (mozRecordList)
|
||||
{
|
||||
memset(mozRecordList, 0, sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
int i=0;
|
||||
for (i=0; i < dwMozCardCount; i++) {
|
||||
for (i=0; i < dwMozCardCount; i++)
|
||||
{
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(mozCardList[i]);
|
||||
CPalmRecord * pMozRecord = new CPalmRecord;
|
||||
pConduitRecord->ConvertToGeneric(*pMozRecord);
|
||||
@ -204,9 +210,9 @@ long MozABPCManager::SynchronizePCAB(LONG categoryIndex, LONG categoryId, CPStri
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
|
||||
|
||||
if(palmCardList)
|
||||
delete palmCardList;
|
||||
if(tempMozABConduitRecList) {
|
||||
if(tempMozABConduitRecList)
|
||||
{
|
||||
for(DWORD j=0; j<updatedPalmRecCount; j++)
|
||||
delete tempMozABConduitRecList[j];
|
||||
delete tempMozABConduitRecList;
|
||||
@ -228,9 +234,12 @@ long MozABPCManager::AddRecords(LONG categoryIndex, CPString & categoryName,
|
||||
|
||||
CMozABConduitRecord ** tempMozABConduitRecList = new CMozABConduitRecord*[updatedPalmRecCount];
|
||||
nsABCOMCardStruct * palmCardList = new nsABCOMCardStruct[updatedPalmRecCount];
|
||||
if(palmCardList) {
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++) {
|
||||
if(*updatedPalmRecList) {
|
||||
if(palmCardList)
|
||||
{
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++)
|
||||
{
|
||||
if(*updatedPalmRecList)
|
||||
{
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(**updatedPalmRecList);
|
||||
memcpy(&palmCardList[i], &pConduitRecord->m_nsCard, sizeof(nsABCOMCardStruct));
|
||||
tempMozABConduitRecList[i]=pConduitRecord;
|
||||
@ -246,9 +255,10 @@ long MozABPCManager::AddRecords(LONG categoryIndex, CPString & categoryName,
|
||||
else
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
|
||||
if(palmCardList)
|
||||
delete palmCardList;
|
||||
if(tempMozABConduitRecList) {
|
||||
if(tempMozABConduitRecList)
|
||||
{
|
||||
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++)
|
||||
delete tempMozABConduitRecList[i];
|
||||
delete tempMozABConduitRecList;
|
||||
|
||||
@ -1,21 +1,41 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by MozABConduitGenCond.rc
|
||||
//
|
||||
#define IDS_CONDUIT_NAME 1
|
||||
#define IDB_HHTOPC 102
|
||||
#define IDB_SYNC 103
|
||||
#define IDB_DONOTHING 104
|
||||
#define IDB_PCTOHH 105
|
||||
#define IDD_CONDUIT_ACTION 399
|
||||
#define IDC_ACTIONGROUPBOXTEXT 403
|
||||
#define IDC_RADIO_SYNC 404
|
||||
#define IDC_RADIO_DONOTHING 405
|
||||
#define IDC_RADIO_PCTOHH 405
|
||||
#define IDC_RADIO_HHTOPC 406
|
||||
#define IDC_RADIO_DONOTHING 407
|
||||
#define IDC_MAKEDEFAULT 411
|
||||
#define IDC_SYNC 1000
|
||||
#define IDC_DONOTHING 1001
|
||||
#define IDC_STATIC_PERMANENT 1002
|
||||
#define IDC_STATIC_TEMPORARY 1003
|
||||
#define IDC_CURRENT_SETTINGS_GROUP 1004
|
||||
#define IDC_PCTOHH 1005
|
||||
#define IDC_HHTOPC 1006
|
||||
#define IDS_CONNECTION 3311
|
||||
#define IDS_CURRENT_SETTINGS_GROUP 8004
|
||||
#define IDS_SYNC_FILES 8005
|
||||
#define IDS_DO_NOTHING 8006
|
||||
#define IDS_SYNC_ACTION_TEXT 8007
|
||||
#define IDS_PCTOHH 8007
|
||||
#define IDS_HHTOPC 8008
|
||||
#define IDS_SYNC_ACTION_TEXT 8009
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 106
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -274,7 +274,7 @@ STDMETHODIMP CPalmSyncImp::nsSynchronizeAB(BOOL aIsUnicode, long aCategoryIndex,
|
||||
STDMETHODIMP CPalmSyncImp::nsAddAllABRecords(BOOL aIsUnicode, long aCategoryIndex, LPTSTR aABName,
|
||||
int aRemoteRecCount, lpnsABCOMCardStruct aRemoteRecList)
|
||||
{
|
||||
// since we are not returning any data we donot need to keep the nsAbPalmHotSync reference
|
||||
// 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);
|
||||
|
||||
|
||||
@ -407,8 +407,9 @@ nsresult nsAbPalmHotSync::DoSyncAndGetUpdatedCards(PRInt32 aPalmCount, lpnsABCOM
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// we are just storing the pointer array here not record arrays
|
||||
for (PRInt32 i=0; i < aPalmCount; i++) {
|
||||
// we are just storing the pointer array here, not record arrays
|
||||
for (PRInt32 i=0; i < aPalmCount; i++)
|
||||
{
|
||||
mPalmRecords.AppendElement(&aPalmRecords[i]);
|
||||
#ifdef RAJIV_DEBUG
|
||||
DisplayTestData(&aPalmRecords[i],PR_FALSE);
|
||||
@ -420,9 +421,11 @@ nsresult nsAbPalmHotSync::DoSyncAndGetUpdatedCards(PRInt32 aPalmCount, lpnsABCOM
|
||||
PRUint32 deletedCardCount=0;
|
||||
mABDB->GetDeletedCardCount(&deletedCardCount);
|
||||
mTotalCardCount += deletedCardCount;
|
||||
if(mTotalCardCount) {
|
||||
if(mTotalCardCount)
|
||||
{
|
||||
mCardListForPalm = (lpnsABCOMCardStruct) CoTaskMemAlloc(sizeof(nsABCOMCardStruct) * mTotalCardCount);
|
||||
if(!mCardListForPalm) {
|
||||
if(!mCardListForPalm)
|
||||
{
|
||||
mABDB->Close(PR_FALSE);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -445,26 +448,32 @@ nsresult nsAbPalmHotSync::DoSyncAndGetUpdatedCards(PRInt32 aPalmCount, lpnsABCOM
|
||||
|
||||
// if there are no new cards to be added in Palm close DB
|
||||
// else wait for Done to be called.
|
||||
if(!mIsNewCardForPalm) {
|
||||
if(!mIsNewCardForPalm)
|
||||
{
|
||||
rv = mABDB->Close(NS_SUCCEEDED(rv) && mPalmRecords.Count());
|
||||
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mDBOpen = PR_FALSE;
|
||||
PRUint32 modTimeInSec;
|
||||
nsAddrDatabase::PRTime2Seconds(PR_Now(), &modTimeInSec);
|
||||
rv = UpdateABInfo(modTimeInSec, mPalmCategoryIndex);
|
||||
}
|
||||
else { // get back the previous file
|
||||
else
|
||||
{ // get back the previous file
|
||||
rv = mABDB->ForceClosed();
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCAutoString leafName;
|
||||
mABFile->GetNativeLeafName(leafName);
|
||||
PRBool bExists=PR_FALSE;
|
||||
mPreviousABFile->Exists(&bExists);
|
||||
if(bExists) {
|
||||
if(bExists)
|
||||
{
|
||||
nsCOMPtr<nsIFile> parent;
|
||||
rv = mABFile->GetParent(getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
mABFile->Remove(PR_FALSE);
|
||||
mPreviousABFile->CopyToNative(parent, leafName);
|
||||
}
|
||||
@ -509,10 +518,12 @@ nsresult nsAbPalmHotSync::LoadDeletedCardsSinceLastSync()
|
||||
if (NS_FAILED(rv) || !lastModifiedDate)
|
||||
continue;
|
||||
|
||||
if(lastModifiedDate > mPalmSyncTimeStamp) {
|
||||
if(lastModifiedDate > mPalmSyncTimeStamp)
|
||||
{
|
||||
nsAbIPCCard ipcCard(card);
|
||||
// check in the list of Palm records
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--) {
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--)
|
||||
{
|
||||
nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *) mPalmRecords.ElementAt(i);
|
||||
// if same record exists in palm list, donot delete it from Palm
|
||||
if(ipcCard.Same(palmRec, mIsPalmDataUnicode))
|
||||
@ -542,7 +553,8 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync()
|
||||
// create the list of cards to be sent to Palm
|
||||
nsCOMPtr<nsISupports> item;
|
||||
nsCOMPtr<nsIAbCard> card;
|
||||
for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) {
|
||||
for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next())
|
||||
{
|
||||
rv = cardsEnumerator->CurrentItem(getter_AddRefs(item));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
@ -562,7 +574,8 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync()
|
||||
continue;
|
||||
|
||||
if(lastModifiedDate > mPalmSyncTimeStamp // take care of modified
|
||||
|| !lastModifiedDate || !mPalmSyncTimeStamp) { // take care of new or never before sync
|
||||
|| !lastModifiedDate || !mPalmSyncTimeStamp)
|
||||
{ // take care of new or never before sync
|
||||
|
||||
//create nsAbIPCCard and assign its status based on lastModifiedDate
|
||||
nsAbIPCCard ipcCard(card);
|
||||
@ -576,7 +589,8 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync()
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if(ipcCard.GetStatus() == ATTR_NEW) {
|
||||
if(ipcCard.GetStatus() == ATTR_NEW)
|
||||
{
|
||||
mNewCardsArray->AppendElement(card);
|
||||
mNewCardCount++;
|
||||
mIsNewCardForPalm = PR_TRUE;
|
||||
@ -588,7 +602,7 @@ nsresult nsAbPalmHotSync::LoadNewModifiedCardsSinceLastSync()
|
||||
}
|
||||
|
||||
|
||||
// this take care of the all cases when the state is either mod or new
|
||||
// this take care of the all cases when the state is either modified or new
|
||||
PRBool nsAbPalmHotSync::CheckWithPalmRecord(nsAbIPCCard * aIPCCard)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aIPCCard);
|
||||
@ -598,39 +612,43 @@ PRBool nsAbPalmHotSync::CheckWithPalmRecord(nsAbIPCCard * aIPCCard)
|
||||
|
||||
PRBool keep = PR_TRUE;
|
||||
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--) {
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--)
|
||||
{
|
||||
nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *) mPalmRecords.ElementAt(i);
|
||||
|
||||
// if same records exists in palm list also
|
||||
if(aIPCCard->Same(palmRec, mIsPalmDataUnicode)) {
|
||||
// if same record is in palm list also
|
||||
if(aIPCCard->Same(palmRec, mIsPalmDataUnicode))
|
||||
{
|
||||
// if the state deleted on both sides no need to do anything
|
||||
if ((palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED) &&
|
||||
(aIPCCard->GetStatus() == ATTR_DELETED)) {
|
||||
(aIPCCard->GetStatus() == ATTR_DELETED))
|
||||
{
|
||||
mPalmRecords.RemoveElementAt(i);
|
||||
return PR_FALSE;
|
||||
}
|
||||
// if deleted on Palm and added or modified on Moz, donot delete on Moz
|
||||
// if deleted on Palm and added or modified on Moz, don't delete on Moz
|
||||
if ( (palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED) &&
|
||||
((aIPCCard->GetStatus() == ATTR_NEW) || (aIPCCard->GetStatus() == ATTR_MODIFIED)) ) {
|
||||
((aIPCCard->GetStatus() == ATTR_NEW) || (aIPCCard->GetStatus() == ATTR_MODIFIED)) )
|
||||
{
|
||||
mPalmRecords.RemoveElementAt(i);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// set the palm record ID in the card if not already set
|
||||
if(!aIPCCard->GetRecordId()) {
|
||||
if(!aIPCCard->GetRecordId())
|
||||
{
|
||||
ConvertAssignPalmIDAttrib(palmRec->dwRecordId, aIPCCard);
|
||||
mABDB->EditCard(aIPCCard, PR_FALSE);
|
||||
aIPCCard->SetRecordId(palmRec->dwRecordId);
|
||||
}
|
||||
|
||||
// if deleted in Moz and added or modified on Palm, donot delete on Palm
|
||||
// if deleted in Moz and added or modified on Palm, don't delete on Palm
|
||||
if ( (aIPCCard->GetStatus() == ATTR_DELETED) &&
|
||||
((palmRec->dwStatus == ATTR_NEW)
|
||||
||(palmRec->dwStatus == ATTR_MODIFIED)) ) {
|
||||
||(palmRec->dwStatus == ATTR_MODIFIED)) )
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// for rest of the cases with state as either mod or new::
|
||||
// for rest of the cases with state as either mod or new:
|
||||
nsStringArray diffAttrs;
|
||||
PRBool isFieldsMatch=PR_FALSE;
|
||||
if(mIsPalmDataUnicode)
|
||||
@ -638,13 +656,15 @@ PRBool nsAbPalmHotSync::CheckWithPalmRecord(nsAbIPCCard * aIPCCard)
|
||||
else
|
||||
isFieldsMatch = aIPCCard->EqualsAfterUnicodeConversion(palmRec, diffAttrs);
|
||||
|
||||
// if fields are ditto no need to keep it for sync
|
||||
if(isFieldsMatch) {
|
||||
// if fields match, no need to keep it for sync
|
||||
if(isFieldsMatch)
|
||||
{
|
||||
keep = PR_FALSE;
|
||||
// since the fields are ditto no need to update Moz AB with palm record
|
||||
// since the fields match, no need to update Moz AB with palm record
|
||||
mPalmRecords.RemoveElementAt(i);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// we add an additional record on both sides alike Palm Desktop sync
|
||||
palmRec->dwStatus = ATTR_NONE;
|
||||
aIPCCard->SetStatus(ATTR_NEW);
|
||||
@ -667,7 +687,8 @@ nsresult nsAbPalmHotSync::AddToListForPalm(nsAbIPCCard & ipcCard)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsresult rv = ipcCard.GetABCOMCardStruct(mIsPalmDataUnicode, &mCardListForPalm[mCardForPalmCount]);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mCardListForPalm[mCardForPalmCount].dwCategoryId = mPalmCategoryId;
|
||||
mCardForPalmCount++;
|
||||
}
|
||||
@ -701,23 +722,23 @@ nsresult nsAbPalmHotSync::OpenABDBForHotSync(PRBool aCreate)
|
||||
|
||||
// get nsIFile for nsFileSpec from abSession, why use a obsolete class if not required!
|
||||
rv = NS_FileSpecToIFile(dbPath, getter_AddRefs(mABFile));
|
||||
if(NS_FAILED(rv)) {
|
||||
if(NS_FAILED(rv))
|
||||
{
|
||||
delete dbPath;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv)) {
|
||||
if(NS_FAILED(rv))
|
||||
{
|
||||
delete dbPath;
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = addrDBFactory->Open(dbPath, aCreate, getter_AddRefs(mABDB), PR_TRUE);
|
||||
delete dbPath;
|
||||
if(NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mDBOpen = PR_TRUE; // Moz AB DB is now Open
|
||||
|
||||
return rv;
|
||||
@ -733,13 +754,15 @@ nsresult nsAbPalmHotSync::KeepCurrentStateAsPrevious()
|
||||
nsCAutoString previousLeafName(mFileName);
|
||||
previousLeafName += PREVIOUS_EXTENSION;
|
||||
|
||||
if(!mPreviousABFile) {
|
||||
if(!mPreviousABFile)
|
||||
{
|
||||
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath); // this still uses nsFileSpec!!!
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
(*dbPath) += previousLeafName.get();
|
||||
// get nsIFile for nsFileSpec from abSession, why use a obsolete class if not required!
|
||||
rv = NS_FileSpecToIFile(dbPath, getter_AddRefs(mPreviousABFile));
|
||||
@ -751,7 +774,8 @@ nsresult nsAbPalmHotSync::KeepCurrentStateAsPrevious()
|
||||
|
||||
PRBool bExists=PR_FALSE;
|
||||
mABFile->Exists(&bExists);
|
||||
if(bExists) {
|
||||
if(bExists)
|
||||
{
|
||||
mPreviousABFile->Exists(&bExists);
|
||||
if(bExists)
|
||||
rv = mPreviousABFile->Remove(PR_FALSE);
|
||||
@ -771,7 +795,8 @@ nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords()
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--) {
|
||||
for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--)
|
||||
{
|
||||
nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *)mPalmRecords.ElementAt(i);
|
||||
nsAbIPCCard ipcCard(palmRec, PR_FALSE);
|
||||
|
||||
@ -786,20 +811,24 @@ nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords()
|
||||
nsCOMPtr<nsIAbCard> existingCard;
|
||||
rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_PALMID, recordIDBuf,
|
||||
PR_FALSE, getter_AddRefs(existingCard));
|
||||
if(NS_SUCCEEDED(rv) && existingCard) {
|
||||
if(NS_SUCCEEDED(rv) && existingCard)
|
||||
{
|
||||
// Archived is the same as deleted in palm.
|
||||
if(palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED) {
|
||||
if(palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED)
|
||||
{
|
||||
mABDB->DeleteCard(existingCard, PR_FALSE);
|
||||
continue;
|
||||
}
|
||||
if(palmRec->dwStatus & ATTR_NEW)
|
||||
continue;
|
||||
if(palmRec->dwStatus & ATTR_MODIFIED) {
|
||||
if(palmRec->dwStatus & ATTR_MODIFIED)
|
||||
{
|
||||
PRBool isEqual=PR_FALSE;
|
||||
ipcCard.Equals(existingCard, &isEqual);
|
||||
if(isEqual)
|
||||
continue;
|
||||
else {
|
||||
else
|
||||
{
|
||||
existingCard->Copy(&ipcCard);
|
||||
rv = mABDB->EditCard(existingCard, PR_FALSE);
|
||||
continue;
|
||||
@ -824,12 +853,14 @@ nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords()
|
||||
// if the card does not exist
|
||||
if((ipcCard.GetStatus() == ATTR_NEW)
|
||||
||(ipcCard.GetStatus() == ATTR_MODIFIED)
|
||||
|| (ipcCard.GetStatus() == ATTR_NONE)) {
|
||||
|| (ipcCard.GetStatus() == ATTR_NONE))
|
||||
{
|
||||
PRUint32 modTimeInSec;
|
||||
nsAddrDatabase::PRTime2Seconds(PR_Now(), &modTimeInSec);
|
||||
ipcCard.SetLastModifiedDate(modTimeInSec);
|
||||
rv = mABDB->CreateNewCardAndAddToDB(newCard, PR_FALSE);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
// now set the attribute for the PalmRecID in the card in the DB
|
||||
dbCard->SetAbDatabase(mABDB);
|
||||
dbCard->SetStringAttribute(CARD_ATTRIB_PALMID, NS_ConvertASCIItoUCS2(recordIDBuf).get());
|
||||
@ -851,11 +882,14 @@ nsresult nsAbPalmHotSync::Done(PRBool aSuccess, PRInt32 aPalmCatIndex, PRUint32
|
||||
|
||||
nsresult rv=NS_ERROR_UNEXPECTED;
|
||||
|
||||
if(aPalmRecIDListCount == mNewCardCount) {
|
||||
for(PRUint32 i=0; i<aPalmRecIDListCount; i++) {
|
||||
if(aPalmRecIDListCount == mNewCardCount)
|
||||
{
|
||||
for(PRUint32 i=0; i<aPalmRecIDListCount; i++)
|
||||
{
|
||||
nsCOMPtr<nsIAbMDBCard> dbCard;
|
||||
rv = mNewCardsArray->QueryElementAt(i, NS_GET_IID(nsIAbMDBCard), getter_AddRefs(dbCard));
|
||||
if(NS_SUCCEEDED(rv) && dbCard) {
|
||||
if(NS_SUCCEEDED(rv) && dbCard)
|
||||
{
|
||||
ConvertAssignPalmIDAttrib(aPalmRecordIDList[i], dbCard);
|
||||
nsCOMPtr<nsIAbCard> newCard;
|
||||
newCard = do_QueryInterface(dbCard, &rv);
|
||||
@ -865,27 +899,34 @@ nsresult nsAbPalmHotSync::Done(PRBool aSuccess, PRInt32 aPalmCatIndex, PRUint32
|
||||
}
|
||||
}
|
||||
|
||||
if(mABDB && mDBOpen) {
|
||||
if(aSuccess) {
|
||||
if(mABDB && mDBOpen)
|
||||
{
|
||||
if(aSuccess)
|
||||
{
|
||||
rv = mABDB->Close(PR_TRUE);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
mDBOpen = PR_FALSE;
|
||||
PRUint32 modTimeInSec;
|
||||
nsAddrDatabase::PRTime2Seconds(PR_Now(), &modTimeInSec);
|
||||
rv = UpdateABInfo(modTimeInSec, aPalmCatIndex);
|
||||
}
|
||||
}
|
||||
if(NS_FAILED(rv) || !aSuccess) { // get back the previous file
|
||||
if(NS_FAILED(rv) || !aSuccess)
|
||||
{ // get back the previous file
|
||||
rv = mABDB->ForceClosed();
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCAutoString leafName;
|
||||
mABFile->GetNativeLeafName(leafName);
|
||||
PRBool bExists=PR_FALSE;
|
||||
mPreviousABFile->Exists(&bExists);
|
||||
if(bExists) {
|
||||
if(bExists)
|
||||
{
|
||||
nsCOMPtr<nsIFile> parent;
|
||||
rv = mABFile->GetParent(getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
mABFile->Remove(PR_FALSE);
|
||||
mPreviousABFile->CopyToNative(parent, leafName);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user