clientsettings.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,830 行 · 第 1/4 页
CPP
1,830 行
char buf[512];
sprintf(buf, "%lu", deviceConfig.getLogLevel());
node->setPropertyValue(PROPERTY_LOG_LEVEL, buf);
node->setPropertyValue(PROPERTY_DEVINF_HASH, deviceConfig.getDevInfHash());
delete node;
node = NULL;
}
// read parameter of the client only
node = dmt->readManagementNode(rootContext);
if (node) {
node->setPropertyValue(PROPERTY_PUSH_NOTIFICATION, getPush().data());
node->setPropertyValue(PROPERTY_NOTIFICATION_PORT, getPushPort().data());
node->setPropertyValue(PROPERTY_SMS_WAP_PUSH, getSms().data());
node->setPropertyValue(PROPERTY_POLLING_NOTIFICATION, getPolling().data());
node->setPropertyValue(PROPERTY_SERVER_NOTIFIED, getSvrNotified().data());
node->setPropertyValue(PROPERTY_PATH, getPath().data());
node->setPropertyValue(PROPERTY_CRADLE_NOTIFICATION, getCradleNotification().data());
node->setPropertyValue(PROPERTY_ASK_USER, getAskUser().data());
node->setPropertyValue(PROPERTY_CLIENT_PUSH_INTERVAL, getClientPushInterval().data());
node->setPropertyValue(PROPERTY_TO_SYNC_CONFIGURATION, getToSyncConfiguration().data());
node->setPropertyValue(PROPERTY_EMAIL_FILTER, getEmailFilter().data());
node->setPropertyValue(PROPERTY_LAST_EMAIL_ADDRESS, getLastEmailAdress().data());
node->setPropertyValue(PROPERTY_LAST_EMAIL_VISIBLENAME,getLastEmailVisibleName().data());
// Used by ConfigSyncSource during config sync.
StringBuffer val;
val.sprintf("%d", getConfigSyncDirty());
node->setPropertyValue(PROPERTY_CONFIGSYNC_DIRTY, val.c_str());
delete node;
node = NULL;
}
close();
return TRUE;
}
const char* ClientSettings::getConfigSourcesParameter(const char* sourceName, const char* parameter) {
for (unsigned int i=0; i<winSourceConfigsCount; ++i) {
if (strcmp(winSourceConfigs[i].getName(), sourceName) == 0) {
if (strcmp(parameter, "sync") == 0) {
return winSourceConfigs[i].getSync();
}
else if (strcmp(parameter, "encryption") == 0) {
return winSourceConfigs[i].getEncryption();
}
else {
return "to implement";
}
}
}
return "";
}
bool ClientSettings::setConfigSourcesParameter(const char* sourceName, const char* parameter, const char* value) {
for (unsigned int i=0; i<winSourceConfigsCount; ++i) {
if (strcmp(winSourceConfigs[i].getName(), sourceName) == 0) {
if (strcmp(parameter, "sync") == 0) {
winSourceConfigs[i].setSync(value);
}
else if (strcmp(parameter, "encryption") == 0) {
winSourceConfigs[i].setEncryption(value);
}
return true;
}
}
return false;
}
int ClientSettings::saveSyncSourceConfig(const char* name) {
int ret = false;
//lastErrorCode = ERR_NONE;
resetError();
for (unsigned int i=0; i<winSourceConfigsCount; ++i) {
if (strcmp(name, winSourceConfigs[i].getName()) == 0) {
saveWinSourceConfig(i);
break;
}
}
resetError();
ret = getLastErrorCode();
//ret = (lastErrorCode == ERR_NONE);
return ret;
}
// method used to get the singleton instance
ClientSettings* getRegConfig(){
return ClientSettings::getInstance();
}
int ClientSettings::getConfigSourcesLastTimestamp(const char* sourceName) {
for (unsigned int i=0; i<sourceConfigsCount; ++i) {
if (strcmp(sourceConfigs[i].getName(), sourceName) == 0) {
return sourceConfigs[i].getLast();
}
}
return 0;
}
// ------------------------- Read properties from win registry -------------------------
/**
* Read the configuration from Windows registry into this object.
* This method overrides 'DMTClientConfig::read()'.
* 'DMTClientConfig::read()' is first called to read all common properties, then
* specific SyncSource properties are retrieved.
*
* A separate 'winSourceConfigs' array is used to store all specific SS config, common
* props are linked to original 'sourceConfigs' array (no copy!).
*
* @return TRUE if no errors
*/
bool ClientSettings::read() {
bool ret = FALSE;
unsigned int i=0;
//
// Read common properties
//
//lastErrorCode = ERR_NONE;
resetError();
ret = DMTClientConfig::read();
char* passDecoded = decodePassword(accessConfig.getPassword());
accessConfig.setPassword(passDecoded);
if (passDecoded) { delete [] passDecoded; }
if (getLastErrorCode() != 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);
}
// read the branding parameters
readBrandingParams();
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!)
//
// modification of the password here
StringBuffer buffer = encodePassword(accessConfig.getPassword());
accessConfig.setPassword(buffer.c_str());
saveAccessConfig(*syncMLNode);
saveDeviceConfig(*syncMLNode);
// save root values
//saveConfig();
//lastErrorCode = ERR_NONE;
resetError();
for(unsigned int i=0; i<sourceConfigsCount; i++) {
saveWinSourceConfig(i);
}
//ret = (lastErrorCode == ERR_NONE);
resetError();
ret = (getLastErrorCode() != 0);
close();
char* passDecoded = decodePassword(accessConfig.getPassword());
accessConfig.setPassword(passDecoded);
if (passDecoded) { delete [] passDecoded; }
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;
resetError();
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;
}
}
if(strcmp(winSourceConfigs[i].getName(),"config") == 0){
if(dirty & CS_DIRTY_SOURCE_CONFIG){
saveWinSourceConfig(i);
continue;
}
}
}
//ret = (lastErrorCode == ERR_NONE);
resetError();
ret = (getLastErrorCode() != 0);
//Setting dirty to false
dirty = FALSE;
close();
}
return ret;
}
/**
* Here we are sure the management node is not NULL and the timestamp
* has a value
*/
void ClientSettings::saveTimeStamp(ManagementNode* node, unsigned long stamp) {
char buf[512];
timestampToAnchor(stamp, buf);
node->setPropertyValue(PROPERTY_SOURCE_LAST_SYNC, buf);
LOG.debug("Saved node: %s, last: %s", node->getName(), buf);
}
int ClientSettings::saveWinSourceLastTimeStamp(unsigned int i) {
LOG.debug("ClientSettings::saveWinSourceLastTimeStamp by index");
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());
LOG.debug("ClientSettings: saveWinSourceLastTimeStamp create the node for the %s: ", nodeName);
delete [] fn;
node = dmt->readManagementNode(nodeName);
}
else {
node = (ManagementNode*)sourcesNode->getChild(i)->clone();
}
//
// Save Last Time Stamp
//
LOG.debug("ClientSettings::saveWinSourceLastTimeStamp of %s: ", winSourceConfigs[i].getName());
saveTimeStamp(node, winSourceConfigs[i].getLast());
delete node;
return 0;
}
int ClientSettings::saveWinSourceLastTimeStamp(const char* name) {
LOG.debug("ClientSettings::saveWinSourceLastTimeStamp by name: %s", name);
if ((name == NULL) || (strlen(name) == 0)) {
return 0;
}
ManagementNode* node;
char nodeName[DIM_MANAGEMENT_PATH];
if (!sourcesNode) {
open();
}
for (unsigned int i = 0; i < winSourceConfigsCount; ++i) {
if (strcmp(name, winSourceConfigs[i].getName()) == 0) {
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();
}
LOG.debug("ClientSettings::saveWinSourceLastTimeStamp of %s: ", winSourceConfigs[i].getName());
saveTimeStamp(node, winSourceConfigs[i].getLast());
delete node;
break;
}
}
return 0;
}
/*
* 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) {
LOG.debug("ClientSettings: entering the saveWinSourceConfig");
ManagementNode* node;
char nodeName[DIM_MANAGEMENT_PATH];
if (!sourcesNode) {
open();
}
//
// If node not found, create node from Source name.
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?