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

📄 poomclient2server.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#include <stdio.h>

#include "base/Log.h"
#include "spds/spdsutils.h"
#include "spds/Constants.h"
#include "base/util/utils.h"
#include "vocl/WinContact.h"


#include "pim/Utils.h"
#include "pim/ContactBuilder.h"
#include "pim/AppointmentBuilder.h"
#include "pim/TaskBuilder.h"
#include "pim/POOMFileManagement.h"
#include "pim/POOMClient2Server.h"



void setAllItemsPOOM(Container* c, int dataType, wchar_t* path) {
    LOG.debug("Enter setAllItemsPOOM... ");

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL) {
        LOG.error("setAllItemsPOOM: can't open PocketOutlook session");
        return;
    }

    if (dataType == olFolderCalendar && !isWindowsMobile5()) {
        normalizeAppointment(polApp, dataType, path);
    }

    wchar_t localTemp [DIM_LOCAL_TEMP];

    IPOutlookItemCollection *pItems;
    IFolder *pFolder;

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

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

    pFolder->get_Items (&pItems);

    int countItems = 0;

    pItems->get_Count(&countItems);    

    SyncItem* syncItem = NULL;
    for (int j=0; j<countItems; j++) {
        long oid = 0;

        // Item values start from element number 1 not 0!!!!!
        // from dataType choose if a Contact or a Appointment
        // leave 2 populateString to simplify
        if (dataType == olFolderContacts) {
            pItems->Item (j + 1, (IDispatch**)&pContact);
            pContact->get_Oid(&oid);
            // set these objlist to write to file...
            pContact->Release ();
        }
        else if (dataType == olFolderCalendar){
            pItems->Item (j + 1, (IDispatch**)&pAppointment);
            pAppointment->get_Oid(&oid);
            pAppointment->Release();
        }
        else if (dataType == olFolderTasks){
            pItems->Item (j + 1, (IDispatch**)&pTask);
            pTask->get_Oid(&oid);
            pTask->Release();
        }
        wsprintf(localTemp, TEXT("%i"), oid);

        syncItem = new SyncItem(localTemp);

        c->addItemToAllItems(syncItem);

        if (syncItem) {
            delete syncItem;
            syncItem = NULL;
        }

    }

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

    releaseOutlookApp(polApp);

    wsprintf(localTemp, SET_ALL_ITEMS, countItems);
    LOG.debug("Exiting setAllItemsPOOM... ");
 }

 /*
Set modified Items for FAST_SYNC from PPC to server
*/

void setModifiedItemsPOOM(Container* c, int dataType, wchar_t* path, bool isSIF, map<long,long> &currentOidHash) {

    LOG.debug("Enter setModifiedItemsPOOM... ");
    wchar_t localTemp [DIM_LOCAL_TEMP];

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

    int countItems = 0;

    vector<long> newOid;
    vector<long> updatedOid;
    vector<long> deletedOid;

    //bool isSIF = checkSIF(dataType);

    // only if dataType is appointment
    if (dataType == olFolderCalendar && !isWindowsMobile5())
            normalizeAppointment(polApp, dataType, path);

    fillModifiedOidArray (newOid, updatedOid, deletedOid, polApp, dataType, path, currentOidHash) ;

    SyncItem* syncItem = NULL;

    // for every oid array...
    unsigned int i = 0; //-- unsigned for avoiding "signed/unsigned mismatch"  warning
    long oid = 0;
    for (i = 0; i < newOid.size(); i++) {
        wstring stringItem;

        oid = newOid[i];
        wsprintf(localTemp, TEXT("%i"), oid);
        
        // use the IItem interface of IPoutlookApp2 wm5
        if (dataType == olFolderContacts) { // it's a contact
                        
            IItem* ppItem = NULL;
            polApp->GetItemFromOidEx(oid, 0, &ppItem); 
            WinContact* winC = contactToWinContact(ppItem, isSIF);
            if(winC) {
                stringItem = winC->toString();
                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 ();
        }
        // Set the SyncItem

        // newItems[i] = new SyncItem(localTemp);
        syncItem = new SyncItem(localTemp);


        //
        // 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;

        syncItem->setState(SYNC_STATE_NEW);

        c->addItemToNewItems(syncItem);

        if (syncItem) {
            delete syncItem; syncItem = NULL;
        }
        stringItem.clear();
    }

    i=0;
    oid = 0;
    for (i = 0; i < updatedOid.size(); i++) {
        wstring stringItem;
        oid = updatedOid[i];
        wsprintf(localTemp, TEXT("%i"), oid);

        // use the IItem interface of IPoutlookApp2 wm5
        if (dataType == olFolderContacts) { // it's a contact
            
            IItem* ppItem = NULL;
            polApp->GetItemFromOidEx(oid, 0, &ppItem); 
            WinContact* winC = contactToWinContact(ppItem, isSIF);
            if(winC) {
                stringItem = winC->toString();
                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 a 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 ();
        }

        syncItem = new SyncItem(localTemp);

        //
        // 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;

        syncItem->setState(SYNC_STATE_UPDATED);
        c->addItemToUpdatedItems(syncItem);

        if (syncItem) {
            delete syncItem; syncItem = NULL;
        }
        stringItem.clear();
    }

    i=0;
    oid = 0;
    for (i = 0; i < deletedOid.size(); i++) {
        oid = deletedOid[i];
        wsprintf(localTemp, TEXT("%i"), oid);

        syncItem = new SyncItem(localTemp);

        c->addItemToDeletedItems(syncItem);

        if (syncItem) {
            delete syncItem; syncItem = NULL;
        }

    }

    releaseOutlookApp(polApp);

    LOG.debug("Exiting setModifiedItemsPOOM... ");

}

/*
fill array new, update, delete with OID of element to modify. This function can be used by every source.
This function call funcion that use the alghorytm to retrieve OID modified
*/
void fillModifiedOidArray (vector<long>& newOid, vector<long>& updateOid,
                           vector<long>& deleteOid,
                           IP_OUTLOOK_APP *polApp, int dataType, wchar_t* path,

⌨️ 快捷键说明

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