clientsettings.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,830 行 · 第 1/4 页
CPP
1,830 行
if (sourcesNode->getChild(i) == NULL) {
char* fn = sourcesNode->createFullName();
sprintf(nodeName, "%s/%s", fn, winSourceConfigs[i].getName());
LOG.debug("ClientSettings: create the node for the %s: ", nodeName);
delete [] fn;
node = dmt->readManagementNode(nodeName);
}
else {
node = (ManagementNode*)sourcesNode->getChild(i)->clone();
}
LOG.debug("ClientSettings: saving the configuration...");
//
// Save source properties
//
if (node) {
LOG.debug("ClientSettings: valid node...");
// 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);
//LOG.debug("ClientSettings: setting the last %s: ", 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());
char* sifVersion = toMultibyte(SIF_VERSION);
if (strcmp(winSourceConfigs[i].getName(), "contact") == 0) {
if(winSourceConfigs[i].getUseSif() == "1"){
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sifc");
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
node->setPropertyValue(PROPERTY_SOURCE_VERSION, sifVersion);
}
else {
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vcard");
if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
} else {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
}
char* vCardVersion = toMultibyte(VCARD_VERSION);
node->setPropertyValue(PROPERTY_SOURCE_VERSION, vCardVersion);
delete [] vCardVersion;
}
}
else if (strcmp(winSourceConfigs[i].getName(), "calendar") == 0) {
if(winSourceConfigs[i].getUseSif() == "1"){
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sife");
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
node->setPropertyValue(PROPERTY_SOURCE_VERSION, sifVersion);
}
else {
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vcalendar");
if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
} else {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
}
char* vCalendarVersion = toMultibyte(VCALENDAR_VERSION);
node->setPropertyValue(PROPERTY_SOURCE_VERSION, vCalendarVersion);
delete [] vCalendarVersion;
}
}
else if (strcmp(winSourceConfigs[i].getName(), "task") == 0) {
if(winSourceConfigs[i].getUseSif() == "1"){
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sift");
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
node->setPropertyValue(PROPERTY_SOURCE_VERSION, sifVersion);
}
else {
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vcalendar");
if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
} else {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
}
char* vCalendarVersion = toMultibyte(VCALENDAR_VERSION);
node->setPropertyValue(PROPERTY_SOURCE_VERSION, vCalendarVersion);
delete [] vCalendarVersion;
}
}
else if (strcmp(winSourceConfigs[i].getName(), "note") == 0) {
if(winSourceConfigs[i].getUseSif() == "1"){
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-s4j-sifn");
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
node->setPropertyValue(PROPERTY_SOURCE_VERSION, sifVersion);
}
else {
node->setPropertyValue(PROPERTY_SOURCE_TYPE, "text/x-vnote");
if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 0) {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "b64");
} else {
node->setPropertyValue(PROPERTY_SOURCE_ENCODING, "bin");
}
char* vNoteVersion = toMultibyte(VNOTE_VERSION);
node->setPropertyValue(PROPERTY_SOURCE_VERSION, vNoteVersion);
delete [] vNoteVersion;
}
node->setPropertyValue(PROPERTY_SOURCE_DIR, winSourceConfigs[i].getSyncDir().data());
}
else if(strcmp(winSourceConfigs[i].getName(), "briefcase") == 0) {
if(strcmp(winSourceConfigs[i].getEncryption(), "0") != 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());
}
if (sifVersion) {
delete [] sifVersion;
}
delete node;
}
LOG.debug("ClientSettings: exiting the saveWinSourceConfig");
}
/**
* 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;
// Copy array in a tmp buffer
if (winSourceConfigsCount>0) {
s = new WindowsSyncSourceConfig[winSourceConfigsCount];
for (i=0; i<winSourceConfigsCount; i++) {
s[i] = winSourceConfigs[i];
}
}
// Delete old one, create new (+1 element)
if (winSourceConfigs) {
delete [] winSourceConfigs;
}
winSourceConfigs = new WindowsSyncSourceConfig[winSourceConfigsCount+1];
// Copy back.
for (i=0; i<winSourceConfigsCount; i++)
winSourceConfigs[i] = s[i];
// Copy the new one.
winSourceConfigs[winSourceConfigsCount] = wsc;
if (s) {
delete [] s;
s = NULL;
}
winSourceConfigsCount ++;
return TRUE;
}
// ------------------------------ Other methods ----------------------------------
/*
* Returns the value of the given property, from rootKey tree (read only).
* The value is returned as a new char array and must be freed by the user.
*
* @param context : full context of key, under rootKey
* @param propertyName : name of property to retrieve
* @param rootKey : one of HKEY_LOCAL_MACHINE
* HKEY_CLASSES_ROOT
* HKEY_CURRENT_USER
* HKEY_USERS
* ...
* @return : the property value (new allocated buffer)
* if key not found, returns an empty string.
*/
char* ClientSettings::readPropertyValue(const char* context, const char* propertyName, HKEY rootKey) {
DWORD res = 0;
long err = 0;
ULONG dim = 0;
HKEY key = NULL;
char* ret = NULL;
char* fullContext = new char[strlen(context) + 10];
sprintf(fullContext, "%s/%s", "Software", context);
//RegCreateKeyExA(
WCHAR* wideFullContext = toWideChar(fullContext);
RegCreateKeyEx(
rootKey,
wideFullContext,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ, // Read only: could be from a limited rights user.
NULL,
&key,
&res
);
if (key == 0) {
//lastErrorCode = ERR_INVALID_CONTEXT;
//sprintf(lastErrorMsg, ERR_INVALID_REG_PATH, fullContext);
setErrorF(ERR_INVALID_CONTEXT, "Invalid context path: %s", fullContext);
goto finally;
}
// Get value length
//err = RegQueryValueExA(
WCHAR* widePropertyName = toWideChar(propertyName);
err = RegQueryValueEx(
key,
widePropertyName,
NULL,
NULL, // we currently support only strings
NULL,
&dim
);
if (err == ERROR_SUCCESS) {
if (dim > 0) {
char* buf = new char[dim + 1];
//err = RegQueryValueExA(
err = RegQueryValueEx(
key,
widePropertyName,
NULL,
NULL, // we currently support only strings
(UCHAR*)buf,
&dim
);
if (err == ERROR_SUCCESS) {
ret = stringdup(buf);
}
delete [] buf;
}
}
finally:
if(widePropertyName){
delete [] widePropertyName;
widePropertyName = NULL;
}
if(wideFullContext){
delete [] wideFullContext;
wideFullContext = NULL;
}
if (!ret) {
// Always return an empty string if key not found!
ret = stringdup(EMPTY_STRING);
}
if (fullContext) {
delete [] fullContext;
}
if (key != 0) {
RegCloseKey(key);
}
return ret;
}
void ClientSettings::readWinSourceConfig(unsigned int i) {
char* tmp;
if (!sourcesNode) {
open();
}
ManagementNode* node = NULL;
node = sourcesNode->getChild(i);
if (node) {
if (strcmp(node->getName(), "mails") == 0) {
const char* context = NULL;
char t[255];
char* fn = node->createFullName();
strcpy(t, fn);
delete [] fn;
context = strstr(t, node->getName());
t[context - t - 1] = 0;
MailSourceManagementNode* mmn = new MailSourceManagementNode(t, node->getName());
if (mmn) {
if (mailssconfig) {
delete mailssconfig;
}
mailssconfig = new MailSyncSourceConfig(mmn->getMailSourceConfig(true));
delete mmn;
}
}
tmp = node->readPropertyValue(PROPERTY_SOURCE_USE_SIF);
winSourceConfigs[i].setUseSif(tmp);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SOURCE_DIR);
winSourceConfigs[i].setSyncDir(tmp);
delete [] tmp;
tmp = node->readPropertyValue(PROPERTY_SCHEDULE);
winSourceConfigs[i].setSchedule(tmp);
delete [] tmp;
}
}
void ClientSettings::refreshIP(){
// get IP
checkNetwork();
setIp(getLocalAddress());
}
void ClientSettings::setDirty(int flag){
dirty |= flag;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?