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

📄 pushsettings.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
 */

// PushSettings.cpp : implementation file
//

#include "stdafx.h"
#include "ui.h"
#include "PushSettings.h"
#include "pim/ClientSettings.h"
#include "comutil.h"

#include "tpcshell.h"  // for SHSendBackToFocusWindow

#include "pim/Maincpp.h"
#include "base/startcmd.h"
#include "ClientUtil.h"

#include "notify/checknet.h"
#include <string>
#include "processUtils.h"
using namespace std;

#define SYNCAPP             TEXT("startsync.exe")
#define APP_RUN_AT_TIME     TEXT("AppRunAtTime")

// CPushSettings dialog

IMPLEMENT_DYNAMIC(CPushSettings, CDialog)

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

}

CPushSettings::~CPushSettings()
{
}

void CPushSettings::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_PUSH_CHECK_PUSH, checkServerPush);
    DDX_Control(pDX, IDC_PUSH_LIST_CONFIRM, lstConfirm);
    #ifdef WIN32_PLATFORM_WFSP
        DDX_Control(pDX, IDC_PUSH_SPIN, spinConfirm);
    #endif
}


BEGIN_MESSAGE_MAP(CPushSettings, CDialog)
    ON_BN_CLICKED(IDC_PUSH_CHECK_PUSH, &CPushSettings::OnCheckPushClicked)
    ON_WM_CTLCOLOR()
	/*#ifdef WIN32_PLATFORM_WFSP
		ON_MESSAGE(WM_HOTKEY,&CPushSettings::OnHotkey)
	#endif*/
END_MESSAGE_MAP()


// CPushSettings message handlers

BOOL CPushSettings::OnInitDialog()
{
    // TODO: source
	CString s1;
	// set window text title
	s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_SETTINGS); SetWindowText(s1);

	CDialog::OnInitDialog();

    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;
    }

    #ifdef WIN32_PLATFORM_WFSP
        spinConfirm.SetRange(2,0);	spinConfirm.SetBuddy(&lstConfirm);
    #endif

    ClientSettings* cs = getRegConfig();

   // read string resources
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_SERVER); SetDlgItemText(IDC_PUSH_CHECK_PUSH, s1);
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_ASK); SetDlgItemText(IDC_PUSH_STATIC_ASK, s1);
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_CONFIRM_NO); lstConfirm.AddString(s1);
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_CONFIRM_YES); lstConfirm.AddString(s1);

   lstConfirm.SetCurSel(0);

   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_PUSH_STATIC_ASK)->SetFont(&fontBold);

   #if defined(WIN32_PLATFORM_PSPC)
     s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_SETTINGS); SetDlgItemText(IDC_HEADER_STATIC, s1);
     GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
   #endif


  //
  // read Registry Settings
  //
  /*
    if( (cs->getSms() == "1")  ||
         (cs->getSms() == "2")  ||
         (cs->getPush() == "1")  ||
         (cs->getPush() == "2")  ){
  */
    if( (cs->getSms() != "0")  || cs->getPush() != "0") {
	     checkServerPush.SetCheck(BST_UNCHECKED);
	}
	else{
		checkServerPush.SetCheck(BST_CHECKED);
		lstConfirm.EnableWindow(FALSE);
	};

    int i=0;  int pos=-1;

   // askConfirmation
    /*
    if( (cs->getSms()  == "2") ||
     (cs->getPush() == "2") ){
    */
    if (cs->getAskUser() == "1") {
        lstConfirm.SetCurSel(1);
    }
    else {
        lstConfirm.SetCurSel(0);
    };

    // fix for wrong title problem, we get & set the title for the main window
    wchar_t title[256];
    AfxGetMainWnd()->GetWindowText(title,256);
    AfxGetMainWnd()->SetWindowText(title);

    checkServerPush.SetFocus();
    return FALSE;
}


void CPushSettings::OnCheckPushClicked()
{
    CString s1;

    if(checkServerPush.GetCheck() == BST_CHECKED){
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_MSG_DISABLE);
        int ret = AfxMessageBox(s1, MB_YESNO | MB_ICONQUESTION);
        if(ret == IDYES){
            lstConfirm.EnableWindow(FALSE);
        }
        else{
            checkServerPush.SetCheck(BST_UNCHECKED);
            lstConfirm.EnableWindow(TRUE);
        }
    }
    else{
        // 'Supress notifications' is unchecked
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_PUSH_MSG_ENABLE);
        int ret = AfxMessageBox(s1, MB_OK | MB_ICONINFORMATION);
        lstConfirm.EnableWindow(TRUE);
    }

}

void CPushSettings::OnOK()
{
    ClientSettings* cs = getRegConfig();

    CString s1(""); _bstr_t bst;
    bool deRegisterSms  =false;
    bool registerSms    =false;
    bool deRegisterTcp  =false;
    bool registerTcp    =false;

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

    if(checkServerPush.GetCheck() == BST_CHECKED){
        // supress notifications
        if( (cs->getSms() != "0")){
            deRegisterSms = true;
        }
        if( (cs->getPush() != "0")){
            deRegisterTcp = true;
        }
        cs->setSms("0");
        cs->setPush("0");
        cs->setAskUser("0");
    }
    else {
        // enable notifications
        if(cs->getSms() == "0"){
            registerSms = true;
        }

        if(lstConfirm.GetCurSel() == 1){
            cs->setSms("1");
            cs->setAskUser("1");
        }
        else{
            cs->setSms("1");
            cs->setAskUser("0");
        };

        if(cs->getPush() == "0") {
            registerTcp = true;
        }
        
        cs->setPush("3");
        if(lstConfirm.GetCurSel() == 1){
            cs->setAskUser("1");
        }
        else{
           cs->setAskUser("0");
        }
    }

    if (deRegisterSms && deRegisterTcp &&
        !registerSms && !registerTcp ) {
        cs->setSvrNotified("0");
    }



   // check if tcp and sms settings have changed, and register/deregister  sms and tcp/ip push
   // TODO: check for errors
   if (deRegisterSms){
       startProgram(_T("startsync.exe"),_T("deregister"));
   };

   if (registerSms){
    startProgram(_T("startsync.exe"),_T("register"));
   };


   if(deRegisterTcp && registerTcp){
       // re-register (the port has changed)
       startProgram(_T("handleservice.exe"),_T("deregister")); //wait
       startProgram(_T("handleservice.exe"),_T("register"));
   }
   else{
       if (deRegisterTcp){
           startProgram(_T("handleservice.exe"),_T("deregister"));
       };

       if (registerTcp){
           startProgram(_T("handleservice.exe"),_T("register"));
       };
  }

   getRegConfig()->setDirty(CS_DIRTY_ROOT_CONFIG);
   getRegConfig()->saveDirty();

   CDialog::OnOK();
}

HBRUSH CPushSettings::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 + -