⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poomclient2server.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                           map<long,long> &currentOidHash) {

    IPOutlookItemCollection *pItems;
    IFolder *pFolder;

    //IContact     *pContact;
    IAppointment *pAppointment;
    ITask        *pTask;


    if( FAILED(polApp->GetDefaultFolder (dataType, &pFolder)) ) {
        LOG.error("fillModifiedOidArray: can't open folder: %d", dataType);
        return;
    }

    pFolder->get_Items (&pItems);

    int currentCountItems = 0;
    vector<long> currentOid;
    vector<long> currentHash;

    pItems->Sort(TEXT ("[Oid]"), FALSE);
    pItems->get_Count(&currentCountItems);

    long previousCountItems = 0;
    vector<long> previousOid;
    vector<long> previousHash;

    // TODO:
    readFromFile(&previousCountItems, previousOid, previousHash, dataType, path);

    int i = 0;
    int j = 0;
    int lastFound = -1;

    long currentLongOid = 0;
    long currentLongHash = 0;

    for (i = 0; i < currentCountItems; i++) {

        if (dataType == olFolderContacts) {
            
            currentLongOid = 0;

            IDispatch* pDisp  = NULL;
            IItem*     ppItem = NULL;

            pItems->Item (i + 1, (IDispatch**)&pDisp);
            
            // FIXME: check this!!!!
            if (pDisp == NULL) {
                LOG.error("fillModifiedOidArray: invalid item %d", i+1);
                continue;
            }
            HRESULT hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);
            ppItem->get_Oid(&currentLongOid);
            WinContact* winC = contactToWinContact(ppItem, false);
            if (winC) { 
                currentLongHash = winC->getCRC();
                // set these objlist to write to file...
                currentOid.push_back(currentLongOid);
                currentHash.push_back(currentLongHash);
                currentOidHash[currentLongOid] = currentLongHash;
                delete winC;    
                ppItem->Release();
                pDisp->Release();   
            }
            else {
                LOG.error("fillModifiedOidArray: error converting to WinContact.");
            }
            /*
            currentLongOid = 0;
            pItems->Item (i + 1, (IDispatch**)&pContact);

            pContact->get_Oid(&currentLongOid);
            currentLongHash = calculateContactHash(pContact);
            // set these objlist to write to file...
            currentOid.push_back(currentLongOid);
            currentHash.push_back(currentLongHash);
            pContact->Release ();
            */
        }
        else if (dataType == olFolderCalendar){ // for appointment
            long internalOid = 0;

            pItems->Item (i + 1, (IDispatch**)&pAppointment);

            pAppointment->get_Oid(&internalOid);
            currentLongHash = calculateAppointmentHash(pAppointment);
            currentLongOid = internalOid;
            // set these objlist to write to file...
            currentOid.push_back(currentLongOid);
            currentHash.push_back(currentLongHash);
            pAppointment->Release ();
        }
        else if (dataType == olFolderTasks){ // for appointment
            long internalOid = 0;
            pItems->Item (i + 1, (IDispatch**)&pTask);
            pTask->get_Oid(&internalOid);
            currentLongHash = calculateTaskHash(pTask);
            currentLongOid = internalOid;
            // set these objlist to write to file...
            currentOid.push_back(currentLongOid);
            currentHash.push_back(currentLongHash);
            pTask->Release ();
        }
        int itemFound = 0;
        j = lastFound + 1;

        while ((j < previousCountItems && itemFound == 0)) {
            long previousLongOid = previousOid[j];

            if (currentLongOid == previousLongOid) {
                itemFound = 1;
                lastFound = j;

                long previousLongHash = previousHash[j];

                if (currentLongHash != previousLongHash) {
                    // if different hash then into updateOid to pass to setModifiedItems
                    updateOid.push_back(currentLongOid);

                } else {
                    // nothing to do...
                }
            }
            j++;
        }
        if (itemFound == 0) {
            newOid.push_back(currentLongOid);
        }


    } // fine for

    i = 0;
    lastFound = -1;

    for (j = 0; j < previousCountItems; j++) {

        int itemFound = 0;
        i = lastFound + 1;

        long previousLongOid = previousOid[j];

        int count = currentOid.size();
        while ((i < count && itemFound == 0)) {
            long currentLongOid = currentOid[i];

            if (currentLongOid == previousLongOid) {
                itemFound = 1;
                lastFound = i;
            }
            i++;
        }

        if (itemFound == 0) {
            deleteOid.push_back(previousLongOid);
        }

    } // fine for

    pItems->Release ();
    pFolder->Release ();


}

void fillSyncItem(SyncItem* syncItem, int dataType, bool isSIF, map<long,long> &currentOidHash) {

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return;
    
    IAppointment *pAppointment;
    ITask        *pTask;    

    //bool isSIF = checkSIF(dataType);
    wstring stringItem;
    long oid = wcstol(syncItem->getKey(), NULL, 10);

    //
    // we start to use the IPOutlookApp2 to use the IItem object
    // 
    if (dataType == olFolderContacts) { // it's a contact
       
        IItem* ppItem = NULL;
        polApp->GetItemFromOidEx(oid, 0, &ppItem); 
                
        WinContact* winC = contactToWinContact(ppItem, isSIF);
        
        long crc = winC->getCRC();
        currentOidHash[oid] = crc;
        
        stringItem = winC->toString();
        if (winC) { 
            delete winC; 
        } 
        if (ppItem) {
            ppItem->Release();
        }
    }
    else if (dataType == olFolderCalendar){ // it's an appointments

        polApp->GetItemFromOid (oid, (IDispatch**)&pAppointment);

        if(isSIF)
            populateAppointmentStringItem(stringItem, pAppointment);
        else {
            VObject* vo = AppointmentToVObject(pAppointment);
            if(vo) {
                stringItem = vo->toString();
                delete vo;
            }
        }
        pAppointment->Release ();
    }
    else if (dataType == olFolderTasks){ // it's an task

        polApp->GetItemFromOid (oid, (IDispatch**)&pTask);
        if(isSIF)
            populateTaskStringItem(stringItem, pTask);
        else {
            VObject* vo = TaskToVObject(pTask);
            if(vo) {
                stringItem = vo->toString();
                delete vo;
            }
        }
        pTask->Release ();
    }
    //
    // Now Sources works in clear mode. The encoding in b64 is demanded to api side
    //

    char* data = toMultibyte((wchar_t*)stringItem.data());
    syncItem->setData(data, strlen(data)*sizeof(char));
    delete [] data; data = NULL;

    releaseOutlookApp(polApp);

}

int deleteAllItems(int dataType) {

    IContact     *pContact;
    IAppointment *pAppointment;
    ITask        *pTask;

    IFolder *pFolder;
    IPOutlookItemCollection *pItems;

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return -1;

    if( FAILED(polApp->GetDefaultFolder (dataType, &pFolder)) ) {
        LOG.error("deleteAllItems: can't open folder: %d", dataType);
        return -1;
    }

    pFolder->get_Items (&pItems);
    int numItems = 0;

    pItems->get_Count(&numItems);

    LOG.info("Items to delete: %i", numItems);

    for (int i = 1; i <=numItems; i++) {
        try {
            if (dataType == olFolderContacts) { // it's a contact
                pItems->Item(1,(IDispatch **)&pContact);

                pContact->Delete();              

            }
            else if (dataType == olFolderCalendar){ // it's an appointments
                pItems->Item(1,(IDispatch **)&pAppointment);
                //pAppointment->Cancel();   it sends the cancellation to the recipients
                pAppointment->Delete();
                pAppointment->Release();

            }
            else if (dataType == olFolderTasks){ // it's an task
                pItems->Item(1,(IDispatch **)&pTask);
                pTask->Delete();
                pTask->Release();

            }
        } catch(...) {
            LOG.debug("Exception in deleting all items. Continue until num items: %i", numItems);
        }

    }

    pItems->Release ();
    pFolder->Release ();

    releaseOutlookApp(polApp);
    return numItems;

}

/*
* Call function to remove all the appointment exceptions and transform them into
* normal appointment with only delete exceptions
*/
void normalizeAllExceptions() {

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return;

    normalizeAppointmentExceptions(polApp);

    releaseOutlookApp(polApp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -