⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syncsettingsadvanced.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * 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 General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

// SyncSettingsAdvanced.cpp : implementation file
//

#include "stdafx.h"
#include "SyncSettingsAdvanced.h"
#include "pim/ClientSettings.h"
#include "pim/maincpp.h"
#include "processUtils.h"

// CSyncSettingsAdvanced dialog

IMPLEMENT_DYNAMIC(CSyncSettingsAdvanced, CDialog)

char minutes[9][5] = {"0","5","10","15","30","60","120","240","1440"};

/*int getPollingPosition(CString value) {
    if (value.CompareNoCase(CString("0")) == 0)    return 0;
    if (value.CompareNoCase(CString("5")) == 0)    return 1;
    if (value.CompareNoCase(CString("10"))== 0)   return 2;
    if (value.CompareNoCase(CString("15"))== 0)   return 3;
    if (value.CompareNoCase(CString("30"))== 0)   return 4;
    if (value.CompareNoCase(CString("60"))== 0)   return 5;
    if (value.CompareNoCase(CString("120"))== 0)  return 6;
    if (value.CompareNoCase(CString("240"))== 0)  return 7;
    if (value.CompareNoCase(CString("1440"))== 0) return 8;
    return 3; //default
}
*/

int getPollingPosition(string value) {
    if (value == "0")    return 0;
    if (value == "5")    return 1;
    if (value == "10")   return 2;
    if (value == "15")   return 3;
    if (value == "30")   return 4;
    if (value == "60")   return 5;
    if (value == "120")  return 6;
    if (value == "240")  return 7;
    if (value == "1440") return 8;
    return 3; //default
}


CSyncSettingsAdvanced::CSyncSettingsAdvanced(CWnd* pParent /*=NULL*/)
	: CDialog(CSyncSettingsAdvanced::IDD, pParent)
{

}

CSyncSettingsAdvanced::~CSyncSettingsAdvanced()
{
}

void CSyncSettingsAdvanced::DoDataExchange(CDataExchange* pDX)
{
    DDX_Control(pDX, IDC_ENCRYPTION, checkEncryption);
    // for compression checkbox. NOT USED at the moment
    //DDX_Control(pDX, IDC_COMPRESSION, checkEnableCompression);

#if _WIN32_WCE > 0x500
    DDX_Control(pDX, IDC_SYNC_CHECK_CRADLE, checkCradle);
#endif
    DDX_Control(pDX, IDC_SCHEDULER_MINUTES, lstPolling);
    #ifdef WIN32_PLATFORM_WFSP
        DDX_Control(pDX, IDC_SCHEDULER_SPIN, spinPolling);
    #endif
	CDialog::DoDataExchange(pDX);
}

BOOL CSyncSettingsAdvanced::OnInitDialog(){
    CString s1;
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ADVANCED_SYNC);
    SetWindowText(s1);
    CDialog::OnInitDialog();

    #ifdef WIN32_PLATFORM_WFSP
        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(getLocalizationUtils()->getLocaleResource(), IDS_SCHEDULER);           SetDlgItemText(IDC_SYNC_STATIC_SCHEDULER, s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SECURITY);            SetDlgItemText(IDC_SYNC_STATIC_SECURITY, s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ENABLE_ENCRYPTION);   SetDlgItemText(IDC_ENCRYPTION, s1);
    
    // for compression checkbox. NOT USED at the moment
    //s1.LoadString(IDS_COMPRESSION);         SetDlgItemText(IDC_ENABLE_COMPRESSION, s1);//Text
    //s1.LoadString(IDS_ENABLE_COMPRESSION);  SetDlgItemText(IDC_COMPRESSION, s1);//CheckBox Text
    // HIDE this controls
    GetDlgItem(IDC_ENABLE_COMPRESSION)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_COMPRESSION)->ShowWindow(SW_HIDE);

#if _WIN32_WCE > 0x500
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SYNC_CRADLE); SetDlgItemText(IDC_SYNC_STATIC_CRADLE, s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SYNC_CRADLE_STARTSYNC); SetDlgItemText(IDC_SYNC_CHECK_CRADLE, s1);
#else
    GetDlgItem(IDC_SYNC_STATIC_CRADLE)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_SYNC_CHECK_CRADLE)->ShowWindow(SW_HIDE);
#endif
    lstPolling.ResetContent();
    // add strings to polling list
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING0); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING5); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING10); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING15); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING30); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING1H); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING2H); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_POLLING4H); lstPolling.AddString(s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), 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));

    // set font
#if _WIN32_WCE > 0x500
    GetDlgItem(IDC_SYNC_STATIC_CRADLE)->SetFont(&fontBold);
#endif
    GetDlgItem(IDC_SYNC_STATIC_SCHEDULER)->SetFont(&fontBold);
    GetDlgItem(IDC_SYNC_STATIC_SECURITY)->SetFont(&fontBold);
    
    // for compression checkbox. NOT USED at the moment
    //GetDlgItem(IDC_ENABLE_COMPRESSION)->SetFont(&fontBold);

    // set ppc header
    #if defined(WIN32_PLATFORM_PSPC)
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ADVANCED_SYNC); SetDlgItemText(IDC_HEADER_STATIC, s1);
        GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
    #endif

    // read settings from Registry
    ClientSettings* cs = getRegConfig();

    //
    // Encryption is a property of every source. At the moment every source is
    // is encrypted or not at the same time. So the check for the encryption is made
    // only on a source that is contact
    //

    const char* encr = getRegConfig()->getWinSyncSourceConfig("contact")->getEncryption();
    bool enc = false;
    if (strcmp(encr, "des") == 0)
        enc = true;

    if(enc){
        checkEncryption.SetCheck(BST_CHECKED);
    }
    else{
        checkEncryption.SetCheck(BST_UNCHECKED);
    }

// for compression checkbox. NOT USED at the moment
/*
    if (cs->getAccessConfig().getCompression()){
        checkEnableCompression.SetCheck(BST_CHECKED);
    }else{
        checkEnableCompression.SetCheck(BST_UNCHECKED);
    }
*/
// for compression checkbox. NOT USED at the moment
//#ifndef USE_ZLIB
//    checkEnableCompression.ShowWindow(SW_HIDE);
//    GetDlgItem(IDC_ENABLE_COMPRESSION)->ShowWindow(SW_HIDE);
//#endif
    // but we hide for portal version
    if(cs->getIsPortal()){
        checkEncryption.ShowWindow(SW_HIDE);
        GetDlgItem(IDC_SYNC_STATIC_SECURITY)->ShowWindow(SW_HIDE);
    }
#if _WIN32_WCE > 0x500
    if(cs->getCradleNotification() == "1"){
        checkCradle.SetCheck(BST_CHECKED);
        cradleInitiallyEnabled = true;
    }
    else{
        checkCradle.SetCheck(BST_UNCHECKED);
        cradleInitiallyEnabled = false;
    };
#endif
    initialSchedulerSelection = lstPolling.GetCurSel();

    // TODO: check polling CurSel
    lstPolling.SetCurSel(getPollingPosition(cs->getPolling())); // 30 minutes set by default
    lstPolling.UpdateWindow();

    initialSchedulerSelection = lstPolling.GetCurSel();
    lstPolling.SetFocus();

    return FALSE;
}

afx_msg void CSyncSettingsAdvanced::OnOK(){

    // save encryption to registry
    ClientSettings* cs = getRegConfig();
    BOOL dirtyFlag = FALSE;

    if(checkStartSync()){
        CDialog::OnOK();
    }

    if(checkEncryption.GetCheck() == BST_CHECKED) {
        if(strcmp(cs->getConfigSourcesParameter("mail","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("mail","encryption","des");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("calendar","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("calendar","encryption","des");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("contact","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("contact","encryption","des");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("task","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("task","encryption","des");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("briefcase","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("briefcase","encryption","des");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("note","encryption"),"des") != 0){
            cs->setConfigSourcesParameter("note","encryption","des");
            dirtyFlag = TRUE;
        }
    } else {
        if(strcmp(cs->getConfigSourcesParameter("mail","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("mail","encryption","0");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("calendar","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("calendar","encryption","0");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("contact","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("contact","encryption","0");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("task","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("task","encryption","0");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("briefcase","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("briefcase","encryption","0");
            dirtyFlag = TRUE;
        }
        if(strcmp(cs->getConfigSourcesParameter("note","encryption"),"0") != 0){
            cs->setConfigSourcesParameter("note","encryption","0");
            dirtyFlag = TRUE;
        }
    }

    if(atoi(cs->getPolling().c_str())!=lstPolling.GetCurSel()){
        cs->setPolling(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    
    // for compression checkbox. NOT USED at the moment
    /*
    if(checkEnableCompression.GetCheck() == BST_CHECKED){
        if(!cs->getAccessConfig().getCompression()){
            cs->getAccessConfig().setCompression(TRUE);
            dirtyFlag = TRUE;
        }
    }else{
        if(cs->getAccessConfig().getCompression()){
            cs->getAccessConfig().setCompression(FALSE);
            dirtyFlag = TRUE;
        }
    }
    */


#if _WIN32_WCE > 0x500
    if(checkCradle.GetCheck() == BST_CHECKED){
        if(strcmp(cs->getCradleNotification().c_str(),"1") != 0){
            cs->setCradleNotification("1");
            dirtyFlag = TRUE;
        }
    }
    else{
        if(strcmp(cs->getCradleNotification().c_str(),"0") != 0){
            cs->setCradleNotification("0");
            dirtyFlag = TRUE;
        }
    }
#endif
    // set the schedule value
    if(atoi(cs->getWinSyncSourceConfig("mail")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("mail")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    if(atoi(cs->getWinSyncSourceConfig("contact")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("contact")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    if(atoi(cs->getWinSyncSourceConfig("calendar")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("calendar")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    if(atoi(cs->getWinSyncSourceConfig("task")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("task")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    if(atoi(cs->getWinSyncSourceConfig("note")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("note")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }
    if(atoi(cs->getWinSyncSourceConfig("briefcase")->getSchedule().c_str()) != lstPolling.GetCurSel()){
        cs->getWinSyncSourceConfig("briefcase")->setSchedule(minutes[lstPolling.GetCurSel()]);
        dirtyFlag = TRUE;
    }

    
#if _WIN32_WCE > 0x500
        if ((checkCradle.GetCheck() == BST_CHECKED) && (!cradleInitiallyEnabled)){
            startProgram(_T("handleservice.exe"), _T("registerCradle"));
        }

        if ((checkCradle.GetCheck() == BST_UNCHECKED) && ( cradleInitiallyEnabled)){
            startProgram(_T("handleservice.exe"), _T("deregisterCradle"));
        }
#endif
    if(dirtyFlag){
        getRegConfig()->setDirty(CS_DIRTY_SOURCE_ALL);
        getRegConfig()->setDirty(CS_DIRTY_ROOT_CONFIG);
        getRegConfig()->saveDirty();
    }
    
    // only if the scheduler setting has changed
    if(initialSchedulerSelection != lstPolling.GetCurSel()){
        startProgram(_T("startsync.exe"), _T("schedule"));
    }
    
    CDialog::OnOK();
}

BEGIN_MESSAGE_MAP(CSyncSettingsAdvanced, CDialog)
    ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// CSyncSettingsAdvanced message handlers
HBRUSH CSyncSettingsAdvanced::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

    return hbr;
}

⌨️ 快捷键说明

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