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

📄 clientsettings.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 3 页
字号:
*/

BOOL ClientSettings::read() {

    BOOL ret = FALSE;
    unsigned int i=0;

    //
    // Read common properties
    //
    lastErrorCode = ERR_NONE;
    ret = DMTClientConfig::read();
    if (lastErrorCode != ERR_NONE) {
        return FALSE;
    }

    if (sourceConfigsCount < 1) {
        return FALSE;
    }
    winSourceConfigsCount = sourceConfigsCount;

    //
    // Read additional properties for SyncSources (use winSyncSourceConfig)
    //
    if (winSourceConfigs) {
        delete [] winSourceConfigs;
    }

    if (!open()) {
        return FALSE;
    }

    readConfig(); // this 1st
    //readConfigSources("mail");

    winSourceConfigs = new WindowsSyncSourceConfig[sourceConfigsCount];
    for (i=0; i<sourceConfigsCount; i++) {

        // Link internal pointer to sourceConfigs array
        winSourceConfigs[i].setCommonConfig(DMTClientConfig::getSyncSourceConfig(i));

        int t=0;

        // Read specific properties
        readWinSourceConfig(i);

    }

    close();
    return ret;
}


// ---------------------------- Save properties to win registry ----------------------------
/**
* Save the configuration from this object into Windows registry.
* If SyncReport pointer is passed not NULL, each SyncSource configuration
* will be saved ONLY if that source was successfully synced.
* This method overrides 'DMTClientConfig::save()'.
*
* A separate 'winSourceConfigs' array is used to store all SS config, so a
* specific method 'saveWinSourceConfig()' is used to save sources config
* into the windows registry.
*
* @return TRUE if no errors
*/

/**
 * save everything
 */
BOOL ClientSettings::save() {

    BOOL ret = FALSE;
    //LOG.debug(DBG_WRITING_CONFIG_TO_DM);

    if (!sourcesNode) {
        open();
    }

    //
    // SyncML management node (TBD: manage dirty flags!)
    //
    saveAccessConfig(*syncMLNode);
    saveDeviceConfig(*syncMLNode);

    // save root values
    //saveConfig();


    lastErrorCode = ERR_NONE;
    for(unsigned int i=0; i<sourceConfigsCount; i++) {
           saveWinSourceConfig(i);
    }

    ret = (lastErrorCode == ERR_NONE);

    close();
    return ret;
}

/**
 * using the flags set in the 'dirty' property, we save sections accordingly
 * used in UI
 */
BOOL ClientSettings::saveDirty() {

    BOOL ret = FALSE;
    if(dirty){

        if (!sourcesNode) {
            open();
        }

        if (dirty & CS_DIRTY_ACCESS_CONFIG){
            //saveAccessConfig(*syncMLNode);
            saveConfig();
        }

        if(dirty & CS_DIRTY_DEVICE_CONFIG){
            //saveDeviceConfig(*syncMLNode);
            saveConfig();
        }

        // save root values
        if(dirty & CS_DIRTY_ROOT_CONFIG){
            saveConfig();
        }

        if(dirty & CS_DIRTY_SOURCE_ENABLED){
                saveSyncModes();
        }

        lastErrorCode = ERR_NONE;
        for(unsigned int i=0; i<sourceConfigsCount; i++) {
            if(dirty & CS_DIRTY_SOURCE_ALL){
                saveWinSourceConfig(i);
                //if(strcmp(winSourceConfigs[i].getName(),"mail") == 0){
                    //saveConfigSources("mail");
                //}
                continue;
            }

            if(strcmp(winSourceConfigs[i].getName(),"mail") == 0){
                if(dirty & CS_DIRTY_SOURCE_MAIL){
                    // copy all the properties on the default
                    saveWinSourceConfig(i);
                    //saveConfigSources("mail");
                    continue;
                }
            }

            if(strcmp(winSourceConfigs[i].getName(),"contact") == 0){
                if(dirty & CS_DIRTY_SOURCE_CONTACTS){
                    saveWinSourceConfig(i);
                    continue;
                }
            }

            if(strcmp(winSourceConfigs[i].getName(),"calendar") == 0){
                if(dirty & CS_DIRTY_SOURCE_CALENDAR){
                    saveWinSourceConfig(i);
                    continue;
                }
            }

            if(strcmp(winSourceConfigs[i].getName(),"task") == 0){
                if(dirty & CS_DIRTY_SOURCE_TASKS){
                    saveWinSourceConfig(i);
                    continue;
                }
            }

            if(strcmp(winSourceConfigs[i].getName(),"note") == 0){
                if(dirty & CS_DIRTY_SOURCE_NOTES){
                    saveWinSourceConfig(i);
                    continue;
                }
            }

            if(strcmp(winSourceConfigs[i].getName(),"briefcase") == 0){
                if(dirty & CS_DIRTY_SOURCE_BRIEFCASE){
                    saveWinSourceConfig(i);
                    continue;
                }
            }

        }
        ret = (lastErrorCode == ERR_NONE);

        //Setting dirty to false
        dirty = FALSE;
        close();
    }
    return ret;
}

/*
* Save WindowsSyncSourceConfig properties in DMTree for the desired Source.
* Source properties are placed in specific node under sources node.
* Notes:
* if the node for the current source is not found, it is created!
* if we are under a restore sync (slow/refresh), 'sync' property will
* be skipped (keep previous value from registry)
*
* @param i : the index of SyncSource node
*/
void ClientSettings::saveWinSourceConfig(unsigned int i) {

    ManagementNode* node;
    char nodeName[DIM_MANAGEMENT_PATH];

    if (!sourcesNode) {
        open();
    }

    //
    // If node not found, create node from Source name.
    //
    if (sourcesNode->getChild(i) == NULL) {
        char* fn = sourcesNode->createFullName();
        sprintf(nodeName, "%s/%s", fn, winSourceConfigs[i].getName());
        delete [] fn;
        node = dmt->readManagementNode(nodeName);
    }
    else {
        node = (ManagementNode*)sourcesNode->getChild(i)->clone();
    }

    //
    // Save source properties
    //
    if (node) {
        char buf[512];

        // Common props:
        node->setPropertyValue(PROPERTY_SOURCE_NAME,        winSourceConfigs[i].getName          ());
        node->setPropertyValue(PROPERTY_SOURCE_URI,         winSourceConfigs[i].getURI           ());
        node->setPropertyValue(PROPERTY_SOURCE_TYPE,        winSourceConfigs[i].getType          ());
        node->setPropertyValue(PROPERTY_SOURCE_VERSION,     winSourceConfigs[i].getVersion       ());
        node->setPropertyValue(PROPERTY_SOURCE_SYNC_MODES,  winSourceConfigs[i].getSyncModes     ());
        node->setPropertyValue(PROPERTY_SOURCE_ENCODING,    winSourceConfigs[i].getEncoding      ());
        node->setPropertyValue(PROPERTY_SOURCE_SUPP_TYPES,  winSourceConfigs[i].getSupportedTypes());
        node->setPropertyValue(PROPERTY_SOURCE_ENCRYPTION,  winSourceConfigs[i].getEncryption    ());

        node->setPropertyValue(PROPERTY_SOURCE_SCHEDULE,  winSourceConfigs[i].getSchedule().c_str());

        timestampToAnchor(winSourceConfigs[i].getLast(), buf);
        node->setPropertyValue(PROPERTY_SOURCE_LAST_SYNC, buf);

        node->setPropertyValue(PROPERTY_SOURCE_SYNC,    winSourceConfigs[i].getSync          ());
        node->setPropertyValue(PROPERTY_SOURCE_USE_SIF, winSourceConfigs[i].getUseSif().c_str());

        if (strcmp(winSourceConfigs[i].getName(), "contact")  == 0 ||
            strcmp(winSourceConfigs[i].getName(), "calendar") == 0 ||
            strcmp(winSourceConfigs[i].getName(), "task")  == 0) {

            if(winSourceConfigs[i].getUseSif() == "1"){
                node->setPropertyValue(PROPERTY_SOURCE_ENCODING, ("b64"));
                if (strcmp(winSourceConfigs[i].getName(), "contact")  == 0) {
                    node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sifc");
                }
                else if (strcmp(winSourceConfigs[i].getName(), "calendar") == 0) {
                    node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sife");
                }
                else if (strcmp(winSourceConfigs[i].getName(), "task") == 0)  {
                    node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sift");
                }

            } else {
                if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
                    node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
                } else {
                    node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
                }

                if (strcmp(winSourceConfigs[i].getName(), "contact")  == 0) {  // 2.1
                    node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vcard");
                } else if (strcmp(winSourceConfigs[i].getName(), "calendar") == 0 ||
                    strcmp(winSourceConfigs[i].getName(), "task")  == 0) {
                    node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vcalendar");
                }
            }
        } else if( (strcmp(winSourceConfigs[i].getName(), "briefcase") == 0) ||
                (strcmp(winSourceConfigs[i].getName(), "note") == 0) ) {

                if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0 ||
                   strcmp(winSourceConfigs[i].getName(), "note") == 0) {
                        node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
                } else {
                    node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
                }

                node->setPropertyValue(PROPERTY_SOURCE_TYPE, winSourceConfigs[i].getType()); // required?
                node->setPropertyValue(PROPERTY_SOURCE_DIR, winSourceConfigs[i].getSyncDir().data());

        } else if( (strcmp(winSourceConfigs[i].getName(), "mail") == 0)) {

            char t[128];

            sprintf(t, "%d", mailssconfig->getDownloadAge());
            node->setPropertyValue(PROPERTY_SOURCE_DOWNLOAD_AGE, t);
            sprintf(t, "%d", mailssconfig->getBodySize());
            node->setPropertyValue(PROPERTY_SOURCE_BODY_SIZE, t);
            sprintf(t, "%d", mailssconfig->getAttachSize());
            node->setPropertyValue(PROPERTY_SOURCE_ATTACH_SIZE, t);

            sprintf(t, "%d", mailssconfig->getInbox());
            node->setPropertyValue(PROPERTY_SOURCE_INBOX, t);
            sprintf(t, "%d", mailssconfig->getOutbox());
            node->setPropertyValue(PROPERTY_SOURCE_OUTBOX, t);
            sprintf(t, "%d", mailssconfig->getTrash());
            node->setPropertyValue(PROPERTY_SOURCE_TRASH, t);
            sprintf(t, "%d", mailssconfig->getSent());
            node->setPropertyValue(PROPERTY_SOURCE_SENT, t);
            sprintf(t, "%d", mailssconfig->getDraft());
            node->setPropertyValue(PROPERTY_SOURCE_DRAFT, t);
            sprintf(t, "%d", mailssconfig->getSchedule());
            node->setPropertyValue(PROPERTY_SOURCE_SCHEDULE, t);


            if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
                mailssconfig->setEncoding("b64");
            } else {
                mailssconfig->setEncoding("bin");
            }
            node->setPropertyValue(PROPERTY_SOURCE_ENCODING, mailssconfig->getEncoding());

        }

        delete node;
    }
}

/**
* Save only "sync" properties of each source, to win registry.
*/
void ClientSettings::saveSyncModes() {

    if (!sourcesNode) {
        open();
    }

    ManagementNode* node = NULL;
    for(unsigned int i=0; i<sourceConfigsCount; ++i) {
        node = sourcesNode->getChild(i);
        if (node) {
            node->setPropertyValue(PROPERTY_SOURCE_SYNC, winSourceConfigs[i].getSync());
        }
        node = NULL;
    }

    close();
}


//////////////////////////////////////////////////////////////////////////

// ------------------------------ Get/Set objects ----------------------------------

/**
* Return a pointer to the internal WindowsSyncSourceConfig object from
* its name (must NOT be freed by caller).
* This method replaces 'getSyncSourceConfig()' of DMTClientConfig.
*
* @param name : the source name
* @return     : the correspondent WindowsSyncSourceConfig pointer
*/

WindowsSyncSourceConfig* ClientSettings::getWinSyncSourceConfig(const char* name) {
    if ((name == NULL) || (strlen(name) == 0)) {
        return 0;
    }

    for (unsigned int i=0; i<sourceConfigsCount; i++) {
        if (strcmp(winSourceConfigs[i].getName(), name) == 0) {
            return &winSourceConfigs[i];
        }
    }

    return 0;
}
/**
* Set the passed WindowsSyncSourceConfig object into the correspondent object
* inside 'winSourceConfigs' array. The values are copied into the object that
* matches the same name of the passed one.
* This method replaces the 'SyncManagerConfig::setSyncSourceConfig()'.
* Note:
* If a WindowsSyncSourceConfig with the same name is not found, the passed
* object is added at the end of the 'winSourceConfig' array.
*
* @param wsc : the WindowsSyncSourceConfig passed by reference
* @return    : TRUE if no errors
*/
BOOL ClientSettings::setSyncSourceConfig(WindowsSyncSourceConfig& wsc) {

    unsigned int i=0;
    for (i=0; i<winSourceConfigsCount; ++i) {
        if (strcmp(wsc.getName(), winSourceConfigs[i].getName()) == 0) {
            break;
        }
    }
    if (i >= winSourceConfigsCount) {
        // Not found! -> add the WindowsSyncSourceConfig.
        return addSyncSourceConfig(wsc);
    }

    // copy all values
    winSourceConfigs[i] = wsc;

    return TRUE;
}


/*
* Adds the passed WindowsSyncSourceConfig.
* It is added at the end of the 'winSourceConfig' array.
* This method replaces the 'SyncManagerConfig::addSyncSourceConfig()'.
*
* @param wsc : the WindowsSyncSourceConfig passed by reference
* @return    : TRUE if no errors
*/
BOOL ClientSettings::addSyncSourceConfig(WindowsSyncSourceConfig& wsc) {

    unsigned int i = 0;
    WindowsSyncSourceConfig* s = NULL;

⌨️ 快捷键说明

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