📄 communicationsettings.cpp
字号:
/*
* 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".
*/
// CommunicationSettings.cpp : implementation file
//
#include "stdafx.h"
#include "ui.h"
#include "CommunicationSettings.h"
#include "pim/ClientSettings.h"
#include "uiDlg.h"
#include "PushSettings.h"
#include "ClientUtil.h"
#include "examples/config.h"
#include "base/fscapi.h"
#include "spds/constants.h"
#include "spdm/DMTree.h"
#include "spdm/DMTreeFactory.h"
#include "spdm/ManagementNode.h"
#include "pim/ConfigParams.h"
#include "hwndfunctions.h"
#include "pim/Maincpp.h"
#include "tpcshell.h" // for SHSendBackToFocusWindow
#include "pim/SettingFunctions.h"
#include "base/startcmd.h"
#include "processUtils.h"
#include "pim/account.h"
#include "pim/utils.h"
#include "notify/timed_msgbox.h"
#include "notify/addresschange.h"
// Store the initial value of push, to be sure we set it again at the end.
static bool isPushActive = false;
static bool toSyncMail = false;
static bool isUsernameChanged = false;
/**
* Used to show the url
*/
static bool showUrlField = false;
IMPLEMENT_DYNAMIC(CCommunicationSettings, CDialog)
CCommunicationSettings::CCommunicationSettings(CWnd* pParent /*=NULL*/)
: CDialog(CCommunicationSettings::IDD, pParent)
{
isFromMainMenu = false;
}
CCommunicationSettings::~CCommunicationSettings()
{
#if defined(WIN32_PLATFORM_PSPC)
if (showUrlField) {
//if (FUNOPT_SHOW_URL) {
editUrl.Detach();
}
editUser.Detach();
editPassword.Detach();
#endif
}
void CCommunicationSettings::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//if (FUNOPT_SHOW_URL) {
ClientSettings* cs = getRegConfig();
showUrlField = cs->getBrandingParams().getShowUrlField();
if (showUrlField) {
DDX_Control(pDX, IDC_COMM_EDIT_URL, editUrl);
}
DDX_Control(pDX, IDC_COMM_EDIT_USER, editUser);
DDX_Control(pDX, IDC_COMM_EDIT_PASS, editPassword);
}
void CCommunicationSettings::showMessage(CString message){
alertMessage = message;
}
BOOL CCommunicationSettings::OnInitDialog()
{
toSyncMail = false; // initialize if the mail has to be synced
CString s1;
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_COMMUNICATION_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;
dlgCommandBar.hInstRes = getLocalizationUtils()->getLocaleResource();
dlgCommandBar.nBmpId = 0;
dlgCommandBar.cBmpImages = 0;
if(!SHCreateMenuBar(&dlgCommandBar)){
TRACE(_T("Cannot create command bar!"));
return FALSE;
}
//if (FUNOPT_SHOW_URL) {
ClientSettings* cs = getRegConfig();
showUrlField = cs->getBrandingParams().getShowUrlField();
if (showUrlField) {
editUrl.SetLimitText(EDIT_MAXLENGTH);
}
else {
// If the URL is not requested, hide it and re-position
// the other elements.
GetDlgItem(IDC_COMM_EDIT_URL)->ShowWindow(SW_HIDE);
CWnd *user = GetDlgItem(IDC_COMM_EDIT_USER);
CWnd *pass = GetDlgItem(IDC_COMM_EDIT_PASS);
modifyWindow(GetDlgItem(IDC_COMM_USER), 0, -62);
modifyWindow(user, 0, -62);
modifyWindow(GetDlgItem(IDC_COMM_PASS), 0, -52);
modifyWindow(pass, 0, -52);
modifyWindow(GetDlgItem(IDC_ALERT), 0, -5);
//adjustToParent(user, ADJUST_WIDTH, 10, 20);
//adjustToParent(pass, ADJUST_WIDTH, 10, 20);
}
editUser.SetLimitText(EDIT_MAXLENGTH);
editPassword.SetLimitText(EDIT_MAXLENGTH);
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));
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
GetDlgItem(IDC_COMM_SERVURL)->SetFont(&fontBold);
}
else {
GetDlgItem(IDC_COMM_SERVURL)->ShowWindow(SW_HIDE);
}
GetDlgItem(IDC_COMM_USER)->SetFont(&fontBold);
GetDlgItem(IDC_COMM_PASS)->SetFont(&fontBold);
GetDlgItem(IDC_ALERT)->SetFont(&fontBold);
//if (FUNOPT_SHOW_URL){
if (showUrlField) {
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_SERVURL);
SetDlgItemText(IDC_COMM_SERVURL, s1);
}
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_USER);
SetDlgItemText(IDC_COMM_USER, s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_PASS);
SetDlgItemText(IDC_COMM_PASS, s1);
SetDlgItemText(IDC_ALERT, escapeAmpString(alertMessage));
if(alertMessage.IsEmpty()){
GetDlgItem(IDC_ALERT)->ShowWindow(SW_HIDE);
}
#if defined(WIN32_PLATFORM_PSPC)
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_COMMUNICATION_SETTINGS);
s1 = escapeAmpString(s1);
SetDlgItemText(IDC_HEADER_STATIC, s1);
GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
#endif
//
// Read Registry settings
//
//ClientSettings* cs = getRegConfig();
CString s3;
// Save the initial value: we need to know it before exiting.
isPushActive = (cs->getPush() == "0")? false : true;
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
s3 = cs->getAccessConfig().getSyncURL();
SetDlgItemText(IDC_COMM_EDIT_URL, s3);
}
wchar_t* tmp = toWideChar(cs->getAccessConfig().getUsername());
s3 = tmp;
currentUsername = s3; // hold the current username to be checked if network error
delete [] tmp;
SetDlgItemText(IDC_COMM_EDIT_USER, s3);
tmp = toWideChar( cs->getAccessConfig().getPassword() );
s3 = tmp;
currentPassword = s3; // hold the current username to be checked if network error
delete [] tmp;
SetDlgItemText(IDC_COMM_EDIT_PASS, s3);
if(checkStartSync() != 0)
{
// another sync is in progress, disable controls
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
editUrl.EnableWindow(FALSE);
}
editUser.EnableWindow(FALSE);
editPassword.EnableWindow(FALSE);
}
else
{
#ifdef WIN32_PLATFORM_WFSP
// override back key
LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
::SendMessage(dlgCommandBar.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);
#endif
}
// set a large int as current selection, so the cursor will be at end
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
editUrl.SetSel(LARGE_INT ,LARGE_INT);
}
editUser.SetSel(LARGE_INT ,LARGE_INT);
editPassword.SetSel(LARGE_INT ,LARGE_INT);
// fix for wrong title problem, we get & set the title for the main window
CString title;
AfxGetMainWnd()->GetWindowText(title);
AfxGetMainWnd()->SetWindowText(title);
if (cs->getToSyncConfiguration() == "1") {
// Starts the config sync automatically (in a thread).
// Note: the dialog is blocked with the WAIT icon!
// Will be restored in OnMsgConfigSyncEnded()
if (startConfigSync()) {
goto error;
}
}
else {
//if (FUNOPT_SHOW_URL) { editUrl.SetFocus(); }
if (showUrlField) { editUrl.SetFocus(); }
else { editUser.SetFocus(); }
}
return FALSE;
error:
// Re-enable dialog.
SetCursor(LoadCursor(NULL, IDC_ARROW));
enableUIObjects(true);
return FALSE;
}
int CCommunicationSettings::startConfigSync() {
// Note: don't check the config syncmode != "none".
// We want to be sure that config sync is always done in Account Settings.
// If syncmode is "none", it's changed to two-way" in startSync.
SetCursor(LoadCursor(NULL, IDC_WAIT));
enableUIObjects(false);
CString s1;
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CHECKING_CRED);
GetDlgItem(IDC_ALERT)->ShowWindow(SW_SHOW);
SetDlgItemText(IDC_ALERT, s1);
// Reset 'toSyncConfiguration' value.
ClientSettings* cs = getRegConfig();
cs->setToSyncConfiguration("0");
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty();
// 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...
}
BEGIN_MESSAGE_MAP(CCommunicationSettings, CDialog)
#ifdef WIN32_PLATFORM_WFSP
ON_MESSAGE(WM_HOTKEY,&CCommunicationSettings::OnHotkey)
#endif
#if defined(_DEVICE_RESOLUTION_AWARE)
ON_WM_SIZE()
#endif
ON_WM_CTLCOLOR()
ON_MESSAGE(ID_MYMSG_CONFIG_SYNC_ENDED, &CCommunicationSettings::OnMsgConfigSyncEnded)
ON_MESSAGE(ID_MYMSG_CLEAR_LABEL, &CCommunicationSettings::OnMsgClearAuthenticationLabel)
END_MESSAGE_MAP()
void CCommunicationSettings::OnOK()
{
CCommunicationSettings::ShowWindow(SW_NORMAL);
enableUIObjects(false);
toSyncMail = false; // initialize to not sync the email the first time
//
// Save values in registry
//
ClientSettings* cs = getRegConfig();
CString s1, url, username, password;
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
GetDlgItemText(IDC_COMM_EDIT_URL, url);
}
else {
url = cs->getAccessConfig().getSyncURL();
}
GetDlgItemText(IDC_COMM_EDIT_USER, username);
GetDlgItemText(IDC_COMM_EDIT_PASS, password);
int inpValPar = 0;
if((inpValPar = checkInputParameters(url, username, password)) != 0) {
showNotValidInputMessage(inpValPar);
enableUIObjects(true);
return; // Stay in this dialog.
}
SetCursor(LoadCursor(NULL, IDC_WAIT));
char* tmp = NULL;
// if (FUNOPT_SHOW_URL) {
if (showUrlField) {
tmp = toMultibyte(url.GetBuffer());
if(strcmp(tmp, cs->getAccessConfig().getSyncURL()) != 0){
cs->getAccessConfig().setSyncURL(tmp);
cs->setDirty(CS_DIRTY_ACCESS_CONFIG);
}
if (tmp) {
delete [] tmp; tmp = NULL;
}
}
tmp = toMultibyte(username.GetBuffer());
if(strcmp(tmp,cs->getAccessConfig().getUsername()) != 0){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -