syncmethod.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 618 行 · 第 1/2 页
CPP
618 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
// SyncSettingsAdvanced.cpp : implementation file
//
#include "stdafx.h"
#include "pim/ClientSettings.h"
#include "pim/maincpp.h"
#include "pim/ConfigParams.h"
#include "processUtils.h"
#include "SyncMethod.h"
#include "PushSettings.h"
#include "hwndfunctions.h"
#include "notify/timed_msgbox.h"
IMPLEMENT_DYNAMIC(CSyncMethod, CDialog)
char minutes[9][5] = {"15","30","60","120","240","360","480","720","1440"};
int getPollingPosition(string value) {
if (value == "15") return 0;
if (value == "30") return 1;
if (value == "60") return 2;
if (value == "120") return 3;
if (value == "240") return 4;
if (value == "360") return 5;
if (value == "480") return 6;
if (value == "720") return 7;
if (value == "1440") return 8;
return 0; //default
}
int getSyncMethodPosition(CString value)
{
CString s1;
HINSTANCE localResource = getLocalizationUtils()->getLocaleResource();
s1.LoadString(localResource, IDS_PUSH_SERVICE);
if (value == s1) { return 0; }
s1.LoadString(localResource, IDS_MANUAL_SYNC);
if (value == s1) { return 1; }
s1.LoadString(localResource, IDS_SCHEDULED_SYNC);
if (value == s1) { return 2; }
return 0; // default, should not happen...
}
CSyncMethod::CSyncMethod(CWnd* pParent /*=NULL*/)
: CDialog(CSyncMethod::IDD, pParent)
{
// Just to store the local resources handle...
localResource = getLocalizationUtils()->getLocaleResource();
}
CSyncMethod::~CSyncMethod()
{
}
void CSyncMethod::DoDataExchange(CDataExchange* pDX)
{
DDX_Control(pDX, IDC_SCHEDULER_SYNCMETHOD, lstSyncMethod);
DDX_Control(pDX, IDC_SCHEDULER_MINUTES, lstPolling);
#ifdef WIN32_PLATFORM_WFSP
DDX_Control(pDX, IDC_SCHEDULER_SPIN_SYNCMETHOD, spinSyncMethod);
DDX_Control(pDX, IDC_SCHEDULER_SPIN, spinPolling);
#endif
CDialog::DoDataExchange(pDX);
}
BOOL CSyncMethod::OnInitDialog(){
CString s1;
s1.LoadString(localResource, IDS_SYNC_METHOD);
SetWindowText(s1);
CDialog::OnInitDialog();
toStartPush = false;
toStopPush = false;
#ifdef WIN32_PLATFORM_WFSP
spinSyncMethod.SetRange(2,0); spinSyncMethod.SetBuddy(&lstSyncMethod);
spinPolling.SetRange(8,0); spinPolling.SetBuddy(&lstPolling);
#endif
// set menubar
ZeroMemory(&dlgCommandBar, sizeof(SHMENUBARINFO));
dlgCommandBar.cbSize = sizeof(SHMENUBARINFO);
dlgCommandBar.hwndParent = this->GetSafeHwnd();
dlgCommandBar.dwFlags = SHCMBF_HMENU;
dlgCommandBar.nToolBarId = IDM_OKCANCEL;
#if defined WIN32_PLATFORM_WFSP
#if (_WIN32_WCE < 0x500)
dlgCommandBar.nToolBarId = IDR_MENUBAR_OKCANCEL;
#endif
#endif
dlgCommandBar.hInstRes = getLocalizationUtils()->getLocaleResource();
dlgCommandBar.nBmpId = 0;
dlgCommandBar.cBmpImages = 0;
if(!SHCreateMenuBar(&dlgCommandBar)){
TRACE(_T("Cannot create command bar!"));
return FALSE;
}
// load string resources
s1.LoadString(localResource, IDS_SCHEDULER); SetDlgItemText(IDC_SYNC_STATIC_SCHEDULER, s1);
s1.LoadString(localResource, IDS_INTERVAL); SetDlgItemText(IDC_SYNC_STATIC_INTERVAL, s1);
// Add strings to lstSyncMethod list
lstSyncMethod.ResetContent();
s1.LoadString(localResource, IDS_PUSH_SERVICE); lstSyncMethod.AddString(s1);
s1.LoadString(localResource, IDS_MANUAL_SYNC); lstSyncMethod.AddString(s1);
s1.LoadString(localResource, IDS_SCHEDULED_SYNC); lstSyncMethod.AddString(s1);
// Add strings to lstPolling list
lstPolling.ResetContent();
s1.LoadString(localResource, IDS_POLLING15); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING30); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING1H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING2H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING4H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING6H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING8H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING12H); lstPolling.AddString(s1);
s1.LoadString(localResource, IDS_POLLING1D); lstPolling.AddString(s1);
// create font
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
HFONT hFont = (HFONT) GetStockObject(SYSTEM_FONT);
GetObject(hFont, sizeof lf, &lf);
lf.lfWeight = FW_BOLD;
lf.lfHeight +=FONT_HEIGHT_OFFSET;
VERIFY(fontBold.CreateFontIndirect(&lf));
GetDlgItem(IDC_SYNC_STATIC_SCHEDULER)->SetFont(&fontBold);
GetDlgItem(IDC_SYNC_STATIC_INTERVAL)->SetFont(&fontBold);
GetDlgItem(IDC_ALERT)->SetFont(&fontBold);
GetDlgItem(IDC_ALERT)->ShowWindow(SW_HIDE);
// set ppc header
#if defined(WIN32_PLATFORM_PSPC)
s1.LoadString(localResource, IDS_SYNC_METHOD);
SetDlgItemText(IDC_HEADER_STATIC, s1);
GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
#endif
// read settings from Registry
ClientSettings* cs = getRegConfig();
// Load default polling time from registry
initialSchedulerSelection = lstPolling.GetCurSel();
lstPolling.SetCurSel(getPollingPosition(cs->getPolling()));
lstPolling.UpdateWindow();
// Read syncMethod from registry
s1 = getActiveSyncMethod();
int syncMethodPos = getSyncMethodPosition(s1);
lstSyncMethod.SetCurSel(syncMethodPos);
switch (syncMethodPos) {
case 0: // 0 = Push service
case 1: // 1 = Manual sync
// Scheduled is disabled
//lstPolling.EnableWindow(FALSE);
//GetDlgItem(IDC_SYNC_STATIC_INTERVAL)->EnableWindow(FALSE);
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;
}
lstPolling.UpdateWindow();
lstSyncMethod.UpdateWindow();
lstSyncMethod.SetFocus();
// Store initial positions, for checks on saving
initialSchedulerSelection = lstPolling.GetCurSel();
initialSyncMethodSelection = lstSyncMethod.GetCurSel();
return FALSE;
}
/**
* Save settings to registry
*/
afx_msg void CSyncMethod::OnOK(){
SetCursor(LoadCursor(NULL, IDC_WAIT));
int ret = 0;
ClientSettings* cs = getRegConfig();
if(checkStartSync()){
CDialog::OnOK();
}
// Read current selections and initial selections
int syncMethodPos = lstSyncMethod.GetCurSel();
int schedulerPos = lstPolling.GetCurSel();
toStartPush = false;
toStopPush = false;
bool toStartSchedule = false;
bool toStopSchedule = false;
if (syncMethodPos == initialSyncMethodSelection) {
// No change: exit.
SetCursor(LoadCursor(NULL, IDC_ARROW));
CDialog::OnOK();
}
else {
// Selection changed.
if (syncMethodPos == 0) {
toStartPush = true;
}
else if (initialSyncMethodSelection == 0) {
toStopPush = true;
}
if (syncMethodPos == 2) {
toStartSchedule = true;
}
else if (initialSyncMethodSelection == 2) {
toStopSchedule = true;
}
}
if (toStopSchedule) {
//
// Stop scheduling
//
cs->setPolling("0");
cs->getWinSyncSourceConfig("mail" )->setSchedule("0");
cs->getWinSyncSourceConfig("contact" )->setSchedule("0");
cs->getWinSyncSourceConfig("calendar" )->setSchedule("0");
cs->getWinSyncSourceConfig("task" )->setSchedule("0");
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->setDirty(CS_DIRTY_SOURCE_ALL);
cs->saveDirty(); // Need to save now!
startProgram(_T("startsync.exe"), _T("schedule"));
}
else if (toStopPush) {
// 1. Stop all push services.
// We don't want overlappings with scheduler, so first stop the push.
// 2. Save to registry that we changed the push status.
// ConfigSync is a process, so we have to use the registry.
// 3. Start the config sync. Will disable the UI, with a wating cursor.
stopPushService();
cs->setConfigSyncDirty(CP_DIRTY_PUSH_STATUS);
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty(); // Need to save now!
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?