poomclient2server.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 502 行 · 第 1/2 页

CPP
502
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc.
 * 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 Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 *
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#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;
    }

    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!!!!!
        if (dataType == olFolderContacts) {
            pItems->Item (j + 1, (IDispatch**)&pContact);
            pContact->get_Oid(&oid);
            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];
    int countItems = 0;

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

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

    fillModifiedOidArray (newOid, updatedOid, deletedOid, polApp, dataType, path, currentOidHash);
    SyncItem* syncItem = NULL;


    // NEW
    unsigned int i = 0; //-- unsigned for avoiding "signed/unsigned mismatch"  warning
    for (i=0; i < newOid.size(); i++) {
        wsprintf(localTemp, TEXT("%i"), newOid[i]);

        syncItem = new SyncItem(localTemp);
        c->addItemToNewItems(syncItem);
        if (syncItem) { delete syncItem; }
    }

    // UPDATED
    for (i = 0; i < updatedOid.size(); i++) {
        wsprintf(localTemp, TEXT("%i"), updatedOid[i]);
        
        syncItem = new SyncItem(localTemp);
        c->addItemToUpdatedItems(syncItem);
        if (syncItem) { delete syncItem; }
    }

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

        syncItem = new SyncItem(localTemp);
        c->addItemToDeletedItems(syncItem);
        if (syncItem) { delete syncItem; }
    }

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

    readFromFile(&previousCountItems, previousOid, previousHash, dataType, path);

    int i = 0;
    int j = 0;
    int lastFound = -1;
    long currentLongOid = 0;
    long currentLongHash = 0;

    bool isSIF = checkSIF(dataType);


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

        /*
        * Check to aim the right contact update from the version before 6.5.x in which
        * the crc and the contact sif where calculated using the IpOutlookApp interface
        * and using the IContact object. Since 6.5.x the crc and the IpOutlookApp2 interface
        * permits to get other fields like picture...
        */
        if (getUpdateFlag(dataType) == true) {
            if (dataType == olFolderContacts) {
                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) {
                currentLongOid = 0;
                pItems->Item(i + 1, (IDispatch**)&pAppointment);
                pAppointment->get_Oid(&currentLongOid);

⌨️ 快捷键说明

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