clientsettings.cpp

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

CPP
1,830
字号
void ClientSettings::setConfigSyncDirty(int flag) {
    configSyncDirty |= flag;
}

void ClientSettings::clearConfigSyncDirty(int flag) {
    configSyncDirty = configSyncDirty & (~flag);
}


/**
* Load data from the update tree all the configuration parameters.
* It populates also the currentVersion of the UpdateConfig class.
* At the moment "refresh" is not used
*/
BOOL ClientSettings::readUpdateParams(bool refresh){
    
    ManagementNode* node;
    char nodeName[DIM_MANAGEMENT_PATH];

    if (!sourcesNode) {
        if (!open()) {
            return FALSE;
        }
    }
    
    char syncMLContext[DIM_MANAGEMENT_PATH];
    char* fn = syncMLNode->createFullName();
    sprintf(syncMLContext, "%s", fn);
    delete [] fn;

    sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_UPDATE);
    node = dmt->readManagementNode(nodeName);
    
    char* tmp = NULL;
    string t;

    if (node) {

        //updateParams = new UpdateParams();              
        string val;

        tmp = node->readPropertyValue(UPDATE_VERSION);
        t = tmp; 
        val = updateParams.getVersion();
        updateParams.setVersion((t.length()) > 0 ? t : val);
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_MANDATORY);
        t = tmp; 
        updateParams.setMandatory((t.length()) > 0 ? t : "0");
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_RELEASE_DATE);
        t = tmp; 
        updateParams.setReleaseDate((t.length()) > 0 ? t : "0");
        delete [] tmp;
        
        // default is ""
        tmp = node->readPropertyValue(UPDATE_URL_UPDATE);
        t = tmp; 
        updateParams.setUrlUpdate(t);
        delete [] tmp;
               
        tmp = node->readPropertyValue(UPDATE_URL_COMMENT);
        t = tmp; 
        updateParams.setUrlComment(t);
        delete [] tmp;      
       
        tmp = node->readPropertyValue(UPDATE_SIZE);
        t = tmp; 
        updateParams.setSize((t.length()) > 0 ? t : "0");
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_LAST_CHECK_UPDATE);
        t = tmp; 
        updateParams.setLastCheckUpdate((t.length()) > 0 ? t : "0");
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_INT_CHECK_UP_HTTP);
        t = tmp; 
        val = updateParams.getIntervalCheckUpdateHttp();
        updateParams.setIntervalCheckUpdateHttp((t.length()) > 0 ? t : val);
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_INT_REMIND);
        t = tmp; 
        val = updateParams.getIntervalRemind();
        updateParams.setIntervalRemind((t.length()) > 0 ? t : val);
        delete [] tmp;

        tmp = node->readPropertyValue(UPDATE_SKIPPED);
        t = tmp; 
        updateParams.setSkipped((t.length()) > 0 ? t : "0");
        delete [] tmp;
        
        tmp = node->readPropertyValue(UPDATE_LAST_UPDATE);
        t = tmp; 
        val = updateParams.getVersion();
        updateParams.setLastUpdated((t.length()) > 0 ? t : val);
        delete [] tmp;                
        
        tmp = node->readPropertyValue(UPDATE_LATER);
        t = tmp; 
        updateParams.setLater((t.length()) > 0 ? t : "0");
        delete [] tmp; 

        tmp = node->readPropertyValue(UPDATE_NOW);
        t = tmp; 
        updateParams.setNow((t.length()) > 0 ? t : "0");
        delete [] tmp; 

        tmp = node->readPropertyValue(UPDATE_IS_AN_UPDATE_AVAILABLE);
        t = tmp; 
        updateParams.setIsAnUpdateAvailable((t.length()) > 0 ? t : "0");
        delete [] tmp; 
        
        updateParams.setCurrentVersion(deviceConfig.getOem());
        
        delete node;
        node = NULL;
    }
    return TRUE;
}

/**
* Save data into the registry
*/
BOOL ClientSettings::storeUpdateParams(){
    
    if (updateParams.getCurrentVersion() == "0") {
        LOG.debug("The udpateParams object doesn't exists: don't save");
        return false;
    }

    ManagementNode* node;
    char nodeName[DIM_MANAGEMENT_PATH];

    if (!sourcesNode) {
        if (!open()) {
            return FALSE;
        }
    }
    
    char syncMLContext[DIM_MANAGEMENT_PATH];
    char* fn = syncMLNode->createFullName();
    sprintf(syncMLContext, "%s", fn);
    delete [] fn;

    sprintf(nodeName, "%s%s", syncMLContext, CONTEXT_UPDATE);
    node = dmt->readManagementNode(nodeName);
    
    char* tmp = NULL;
    string t;

    if (node) {
        
        node->setPropertyValue(UPDATE_VERSION, updateParams.getVersion().c_str());                                   
        node->setPropertyValue(UPDATE_MANDATORY, updateParams.getMandatory().c_str());                                   
        node->setPropertyValue(UPDATE_RELEASE_DATE, updateParams.getReleaseDate().c_str());                                   
        node->setPropertyValue(UPDATE_URL_UPDATE, updateParams.getUrlUpdate().c_str());                                   
        node->setPropertyValue(UPDATE_URL_COMMENT, updateParams.getUrlComment().c_str());   
        node->setPropertyValue(UPDATE_SIZE, updateParams.getSize().c_str());                                   
        node->setPropertyValue(UPDATE_LAST_CHECK_UPDATE, updateParams.getLastCheckUpdate().c_str());                                   
        node->setPropertyValue(UPDATE_INT_CHECK_UP_HTTP, updateParams.getIntervalCheckUpdateHttp().c_str());                                   
        node->setPropertyValue(UPDATE_INT_REMIND, updateParams.getIntervalRemind().c_str());                                   
        node->setPropertyValue(UPDATE_SKIPPED, updateParams.getSkipped().c_str());                                   
        node->setPropertyValue(UPDATE_LAST_UPDATE, updateParams.getLastUpdated().c_str());  
        node->setPropertyValue(UPDATE_LATER, updateParams.getLater().c_str()); 
        node->setPropertyValue(UPDATE_NOW, updateParams.getNow().c_str()); 
        node->setPropertyValue(UPDATE_IS_AN_UPDATE_AVAILABLE, updateParams.getIsAnUpdateAvailable().c_str()); 
               
    }
    return TRUE;
}


UpdateParams& ClientSettings::getUpdateParams() {
    return updateParams;
}


/**
* Load data from the Brand tree all the configuration parameters.
* It is used to load in the config the needed stuff about the branding of the 
* plugin.
*
*/
BOOL ClientSettings::readBrandingParams(){
    
    ManagementNode* node;
    char nodeName[DIM_MANAGEMENT_PATH];
    
    sprintf(nodeName, "%s%s", rootContext, CONTEXT_BRAND);
    if (dmt == NULL) {
        dmt = DMTreeFactory::getDMTree(rootContext);
    }
    node = dmt->readManagementNode(nodeName);
          
    char* tmp = NULL;
    string t;

    if (node) {
        string t;
        tmp = node->readPropertyValue(BRAND_URL_FIELD);        
        brandingParams.setShowUrlField(strlen(tmp) > 0 ? tmp : "0");
        delete [] tmp;

        tmp = node->readPropertyValue(BRAND_ADV_SETTING_MENU);
        brandingParams.setShowAdvSettingMenu(strlen(tmp) > 0 ? tmp : "0");
        delete [] tmp;

        tmp = node->readPropertyValue(BRAND_BRIEFCASE_SOURCE);
        brandingParams.setShowBriefcaseSource(strlen(tmp) > 0 ? tmp : "0");
        delete [] tmp;
        
        tmp = node->readPropertyValue(BRAND_NOTE_SOURCE);
        brandingParams.setShowNoteSource(strlen(tmp) > 0 ? tmp : "0");
        delete [] tmp;

        delete node;
        node = NULL;
    }
    return TRUE;
}


/*
bool ClientSettings::readConfigSources(const char* sourceType, BOOL toClose) {

    int n = 0, i = 0; // number of sync sources

    bool ret = FALSE;
    ManagementNode* nn = NULL;

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

    n = sourcesNode->getChildrenMaxCount();

    //
    // Let's remove previously created config objects and reinitialize
    // sourceConfigs
    //
    if (sourceConfigs) {
        delete [] sourceConfigs;
    }
    sourceConfigs = new SyncSourceConfig[n];
    sourceConfigsCount = n;

    for (i=0; i<n; ++i) {
        // node owns children, we must not delete them
        readSourceConfig(i, *(sourcesNode) );
    }

    if (sourceType && strcmp(sourceType, "all") == 0) {
         if (toClose)
            close();
        return true;
    }

    for (unsigned int i=0; i<sourceConfigsCount; ++i) {
        if (strcmp(sourceConfigs[i].getName(), sourceType) == 0) {
            ssconfig.assign(sourceConfigs[i]);
            nn = sourcesNode->getChild(i);
            break;
        }
    }

    char* tmp;

    // TODO: this method is used in ClientSettings for "mail" to init mailssconfig, but seems not used anywhere else,
    // so the code for the other sources below should be removed
    if (strcmp(sourceType, "contact") == 0) {

        tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
        //~setUseSif(string(tmp));
        delete [] tmp;
        tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
        //~setSchedule(string(tmp));
        delete [] tmp;
    } else if (strcmp(sourceType, "calendar") == 0) {

        tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
        //~setUseSif(string(tmp));
        delete [] tmp;
        tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
        //~setSchedule(string(tmp));
        delete [] tmp;
    } else if (strcmp(sourceType, "task") == 0) {

        tmp = nn->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
        //~setUseSif(string(tmp));
        delete [] tmp;
        tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
        //~setSchedule(string(tmp));
        delete [] tmp;
    } else if (strcmp(sourceType, "briefcase") == 0) {

        tmp = nn->readPropertyValue(PROPERTY_SOURCE_DIR);
        setDir(string(tmp));
        delete [] tmp;
         tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
        //~setSchedule(string(tmp));
        delete [] tmp;
    } else if (strcmp(sourceType, "note") == 0) {

        tmp = nn->readPropertyValue(PROPERTY_SOURCE_DIR);
        setDir(string(tmp));
        delete [] tmp;
        tmp = nn->readPropertyValue(PROPERTY_SCHEDULE);
        //~setSchedule(string(tmp));
        delete [] tmp;
    } else if (strcmp(sourceType, "mail") == 0) {
        const char* context = NULL;
        char t[255];
        char* fn = nn->createFullName();
        strcpy(t, fn);
        delete [] fn;

        context = strstr(t, nn->getName());
        t[context - t - 1] = 0;

        MailSourceManagementNode* mmn = new MailSourceManagementNode(t, nn->getName());

        mailssconfig = mmn->getMailSourceConfig(true);

        if (mmn) {
            delete mmn;
        }

    }
    ret = TRUE;

    if (toClose)
        close();

    return ret;

}
*/
/*
// TODO: called only for "mail", the other sources could be removed if not needed anymore
bool ClientSettings::saveConfigSources(const char* saveAll) {

    ManagementNode* nn;

    // to save all the sources config. It is used by the form
    // in which there are all the sources whith the list of the sync property
    // and to reset the last timestamp in the recover form. it is set to 1
    //

    if (saveAll && strcmp(saveAll, "all") == 0) {

        for (unsigned int i=0; i<sourceConfigsCount; ++i) {

            nn = sourcesNode->getChild(i);
            saveSourceConfig(i, *sourcesNode, *nn);

        }
        close();
        return true;
    }


    for (unsigned int i=0; i<sourceConfigsCount; ++i) {

        if (strcmp(sourceConfigs[i].getName(), ssconfig.getName()) == 0) {
            nn = sourcesNode->getChild(i);
            break;
        }
    }

    if (strcmp(ssconfig.getName(), "contact")  == 0 ||
        strcmp(ssconfig.getName(), "calendar") == 0 ||
        strcmp(ssconfig.getName(), "task")  == 0) {

        if(strcmp(ssconfig.getEncryption(), "0") != 0 || strcmp(ssconfig.getName(), "note") == 0) {
            nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
        } else {
            nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
        }
        //nn->setPropertyValue(PROPERTY_SOURCE_ENCODING, ssconfig.getEncoding());

    } else if (strcmp(ssconfig.getName(), "mail") == 0) {

        //setMailSourceConfig(mailssconfig, nn);

        const char* context = NULL;
        char* tt = nn->createFullName();
        char t[255];
        strcpy(t, tt);
        context = strstr(t, nn->getName());
        t[context - t - 1] = 0;

        MailSourceManagementNode* mmn = new MailSourceManagementNode(t, nn->getName());

        if(strcmp(mailssconfig.getEncryption(), "0") != 0) {
            mailssconfig.setEncoding("b64");
        } else {
            mailssconfig.setEncoding("bin");
        }

        //mmn->setMailSourceConfig(mailssconfig);
        if (tt) { delete [] tt; }
        if (mmn){ delete [] mmn;}

    }

    close();
    return TRUE;

}
*/

/**
* Reads all sources timestamps from win registry and set
* all values into configuration.

void ClientSettings::readSourcesTimestamps() {

    if (!open()) {
        return;
    }

    for (unsigned int i=0; i<sourceConfigsCount; i++) {
        ManagementNode* node = sourcesNode->getChild(i);
        if (node) {
            // This sets only variables that the library uses internally, like anchors
            readSourceVars(i, *sourcesNode, *node);
        }
    }

    close();
}
*/

/**
* Reads only "sync" properties of each source, to win registry.

void ClientSettings::readSyncModes() {

    if (!open()) {
        return;
    }

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

    close();
}
*/

⌨️ 快捷键说明

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