syncmethod.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 618 行 · 第 1/2 页
CPP
618 行
if (toStartPush) {
// 1. Save to registry that we changed the push status.
// ConfigSync is a process, so we have to use the registry.
// 2. Start the config sync. Will disable the UI, with a wating cursor.
// 3. After that, push service will be started (see OnMsgConfigSyncEnded())
cs->setSms ("1");
cs->setPush("3");
cs->setConfigSyncDirty(CP_DIRTY_PUSH_STATUS);
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty();
ret = startConfigSync();
}
else if (toStartSchedule) {
//
// Scheduled sync is selected:
// set the schedule value for 'polling' and for all sources
//
string schedMinutes = minutes[schedulerPos];
cs->setPolling(schedMinutes);
cs->getWinSyncSourceConfig("mail" )->setSchedule(schedMinutes);
cs->getWinSyncSourceConfig("contact" )->setSchedule(schedMinutes);
cs->getWinSyncSourceConfig("calendar" )->setSchedule(schedMinutes);
cs->getWinSyncSourceConfig("task" )->setSchedule(schedMinutes);
cs->setDirty(CS_DIRTY_SOURCE_ALL);
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty(); // Need to save now!
startProgram(_T("startsync.exe"), _T("schedule"));
}
if (toStopPush) {
ret = startConfigSync();
}
if ((toStartPush || toStopPush) && (ret == 0)) {
// Config sync is running correctly, dialog is stuck with waiting cursor.
// Will be re-enabled when sync has finished, calling OnMsgConfigSyncEnded().
}
else {
// No config sync is running.
if (toStartPush) {
startPushService();
getRegConfig()->setDirty(CS_DIRTY_ROOT_CONFIG);
getRegConfig()->saveDirty();
}
// Re-enable the dialog
SetCursor(LoadCursor(NULL, IDC_ARROW));
CDialog::OnOK();
}
}
BEGIN_MESSAGE_MAP(CSyncMethod, CDialog)
ON_WM_CTLCOLOR()
ON_CBN_SELCHANGE(IDC_SCHEDULER_SYNCMETHOD, &CSyncMethod::OnCbnSelchangeSchedulerSyncmethod)
ON_MESSAGE(ID_MYMSG_CONFIG_SYNC_ENDED, &CSyncMethod::OnMsgConfigSyncEnded)
#if defined(_DEVICE_RESOLUTION_AWARE)
ON_WM_SIZE()
#endif
END_MESSAGE_MAP()
// CSyncMethod message handlers
HBRUSH CSyncMethod::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// set ppc header text color
#if defined(WIN32_PLATFORM_PSPC)
if(pWnd->GetDlgCtrlID() == IDC_HEADER_STATIC) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(PPC_HEADER_TEXT_COLOR);
}
#endif
if(pWnd->GetDlgCtrlID() == IDC_ALERT) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(ALERT_COLOR);
}
return hbr;
}
/**
* Actions executed wehen lstSyncMethod list changes.
*/
void CSyncMethod::OnCbnSelchangeSchedulerSyncmethod()
{
int syncMethodPos = lstSyncMethod.GetCurSel();
switch (syncMethodPos) {
case 0: // 0 = Push service
case 1: // 1 = Manual sync
// Scheduled is disabled
lstPolling.ShowWindow(SW_HIDE);
GetDlgItem(IDC_SYNC_STATIC_INTERVAL)->ShowWindow(SW_HIDE);
#if defined(WIN32_PLATFORM_WFSP)
GetDlgItem(IDC_SCHEDULER_SPIN)->ShowWindow(SW_HIDE);
#endif
break;
case 2: // 2 = Scheduled sync
// Scheduled enabled
//lstPolling.EnableWindow(TRUE);
//GetDlgItem(IDC_SYNC_STATIC_INTERVAL)->EnableWindow(TRUE);
lstPolling.ShowWindow(SW_SHOW);
GetDlgItem(IDC_SYNC_STATIC_INTERVAL)->ShowWindow(SW_SHOW);
#if defined(WIN32_PLATFORM_WFSP)
GetDlgItem(IDC_SCHEDULER_SPIN)->ShowWindow(SW_SHOW);
#endif
break;
default:
break;
}
}
/**
* Read sync method from config, returns one of:
* "Push sevice" , "Manual Synchronization", "Scheduled Synchronization"
* Strings are loaded from local resources.
* Only the 'contact' synsource is analyzed for the scheduled info.
*/
CString getActiveSyncMethod() {
CString s1;
HINSTANCE localResource = getLocalizationUtils()->getLocaleResource();
ClientSettings* cs = getRegConfig();
int pushType = 0;
if (cs->getPush().size() > 0) {
pushType = atoi(cs->getPush().c_str());
}
if (pushType > 0) {
s1.LoadString(localResource, IDS_PUSH_SERVICE);
}
else {
int schedule = 0;
if (cs->getWinSyncSourceConfig("contact")->getSchedule().size() > 0) {
schedule = atoi(cs->getWinSyncSourceConfig("contact")->getSchedule().c_str());
}
if (schedule > 0) { s1.LoadString(localResource, IDS_SCHEDULED_SYNC); }
else { s1.LoadString(localResource, IDS_MANUAL_SYNC); }
}
return s1;
}
int CSyncMethod::startConfigSync() {
// First of all, check the syncmode. If "none" don't do anything.
ClientSettings* cs = getRegConfig();
SyncSourceConfig* ssc = cs->getSyncSourceConfig("config");
if (!ssc) {
LOG.error("Config Syncsource not existing, aborting config sync.");
return 1;
}
if (!strcmp(ssc->getSync(), "none")) {
LOG.debug("Config syncmode is 'none', aborting config sync.");
return 1;
}
SetCursor(LoadCursor(NULL, IDC_WAIT));
enableUIObjects(false);
CString s1;
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CHECKING_CONFIG);
GetDlgItem(IDC_ALERT)->ShowWindow(SW_SHOW);
SetDlgItemText(IDC_ALERT, s1);
// Start the config sync, in a separate thread.
HWND thisWindow = GetSafeHwnd();
if ( !CreateThread(NULL, 0, configWorker, (LPVOID)thisWindow, 0, NULL) ) {
LOG.error("Error creating configWorker thread.");
return 1;
}
return 0; // Dialog is stuck with the waiting cursor here...
}
void CSyncMethod::enableUIObjects(bool enable) {
HWND thisWnd = this->GetSafeHwnd();
EnableButton(thisWnd, IDOK, enable);
EnableButton(thisWnd, IDCANCEL, enable);
lstSyncMethod.EnableWindow(enable);
lstPolling.EnableWindow(enable);
}
LRESULT CSyncMethod::OnMsgConfigSyncEnded(WPARAM wparam, LPARAM lparam) {
bool isOldServer = false;
int exitcode = (int)wparam;
switch (exitcode) {
case 0: // OK
break;
case ERR_CONFIG_SOURCE_NOT_FOUND: // 2100 = "config" source not found on the Server.
// Silently catched in uiDlg::OnStartSyncEnded()
isOldServer = true;
break;
case 401:
case 402:
case 403:
// Msgbox is already displayed, return to main settings but DON'T start push service!
LOG.info("Authentication failed, code %d", exitcode);
toStartPush = false;
break;
// case 404: should not happen (404 is catched and converted into code 2100)
default:
if (exitcode >= 2000) {
// Error msg already displayed -> uiDlg::OnStartSyncEnded()
LOG.error("Network error, code %d", exitcode);
}
else {
LOG.error("Generic error, code %d", exitcode);
}
break;
}
//
// We MUST not change the flag if Server didn't send a status 200 for PushStatus.
//
if (!isOldServer) {
ClientSettings* cs = getRegConfig();
if (cs->getConfigSyncDirty() & CP_DIRTY_PUSH_STATUS) {
// Means that something went wrong, and the pushStatus
// was not updated on the Server. So return to the previous selection.
if (cs->getPush() == "0") {
cs->setPush("3");
}
else {
cs->setPush("0");
toStartPush = false; // Also avoid starting the push.
}
// Save the previous value, and warn the user.
cs->clearConfigSyncDirty(CP_DIRTY_PUSH_STATUS);
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty();
TimedMessageBox(GetSafeHwnd(), TEXT("Push status could not be updated correctly. Check log for details."),
getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONHAND | MB_SETFOREGROUND, 10 * 1000);
}
}
//
// Start push service (if selected, and no auth error).
//
if (toStartPush) {
startPushService();
// Save to registry.
getRegConfig()->setDirty(CS_DIRTY_ROOT_CONFIG);
getRegConfig()->saveDirty();
}
// Re-enable UI dialog.
GetDlgItem(IDC_ALERT)->ShowWindow(SW_HIDE);
SetDlgItemText(IDC_ALERT, TEXT(""));
enableUIObjects(true);
SetCursor(LoadCursor(NULL, IDC_ARROW));
// Will go to main settings screen.
CDialog::OnOK();
return 0;
}
#if defined(_DEVICE_RESOLUTION_AWARE)
void CSyncMethod::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/){
CRect clientRect, alertRect;
GetClientRect(&clientRect);
CWnd* alertLabel = GetDlgItem(IDC_ALERT);
if (alertLabel) {
alertLabel->GetWindowRect(&alertRect);
int x = 5;
int y = clientRect.Height() - alertRect.Height();
int cx = clientRect.Width() - 5; // Max value
int cy = alertRect.Height(); // No change
alertLabel->SetWindowPos(&CWnd::wndTop, x, y, cx, cy, SWP_NOZORDER);
}
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?