📄 mailsettings.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
*/
// MailSettings.cpp : implementation file
//
#include "stdafx.h"
#include "ui.h"
#include "MailSettings.h"
#include "MailSettingsAdvanced.h"
#include "pim/ClientSettings.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 "comutil.h"
#include "pim/Maincpp.h"
#include "pim/account.h" // to be removed
// CMailSettings dialog
int getMsgSizePosition(int value) {
switch(value){
case 2: return 0;
case 5: return 1;
case 10: return 2;
case 25: return 3;
case 50: return 4;
case 100: return 5;
case 250: return 6;
case -1: return 7;
}
return 3; //default
}
IMPLEMENT_DYNAMIC(CMailSettings, CDialog)
CMailSettings::CMailSettings(CWnd* pParent /*=NULL*/)
: CDialog(CMailSettings::IDD, pParent)
{
}
CMailSettings::~CMailSettings()
{
}
void CMailSettings::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
#if defined(WIN32_PLATFORM_WFSP)
DDX_Control(pDX, IDC_SETTMAIL_SPIN1, spinSyncType );
DDX_Control(pDX, IDC_SETTMAIL_SPIN2, spinMailSince );
DDX_Control(pDX, IDC_SETTMAIL_SPIN3, spinMsgSize );
#endif
DDX_Control(pDX, IDC_MAIL_SYNCTYPE, lstSyncType );
DDX_Control(pDX, IDC_FILTERS_MAILSINCE, lstMailSince );
DDX_Control(pDX, IDC_FILTERS_MSGSIZE, lstMsgSize );
DDX_Control(pDX, IDC_MAIL_LINK_ADVANCED, linkAdvanced);
DDX_Control(pDX, IDC_MAIL_CHECK_ATTACHMENTS, checkAttachments);
}
BEGIN_MESSAGE_MAP(CMailSettings, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
ON_BN_CLICKED(IDC_MAIL_LINK_ADVANCED, &CMailSettings::OnBnClickedMailLinkAdvanced)
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
BOOL CMailSettings::OnInitDialog(){
CString s1;
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_MAIL_SETTINGS); SetWindowText(s1);
CDialog::OnInitDialog();
#if defined(WIN32_PLATFORM_WFSP)
spinSyncType.SetRange(2,0); spinSyncType.SetBuddy(&lstSyncType);
spinMailSince.SetRange(5,0); spinMailSince.SetBuddy(&lstMailSince);
spinMsgSize.SetRange(7,0); spinMsgSize.SetBuddy(&lstMsgSize);
#endif
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;
}
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_MAIL_SYNCTYPE1); lstSyncType.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_ALL); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_0DAY); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_3DAY); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_5DAY); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_7DAY); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_DOWNMAIL_10DAY); lstMailSince.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_2K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_5K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_10K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_25K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_50K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_100K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_250K); lstMsgSize.AddString(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FILTERS_GETMSGSIZE_500K); lstMsgSize.AddString(s1);
LoadStringResources();
// create and set the bold 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_SETTMAIL_STATIC_SYNCTYPE)->SetFont(&fontBold);
GetDlgItem(IDC_MAIL_STATIC_DOWNLOAD)->SetFont(&fontBold);
// set ppc header
#if defined(WIN32_PLATFORM_PSPC)
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_MAIL_SETTINGS); SetDlgItemText(IDC_HEADER_STATIC, s1);
GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
#endif
// read from the registry
ClientSettings* cs = getRegConfig();
int pos=0;
/*
if(!strcmp(cs->mailssconfig->getSync(),"two-way")){
pos = 0;
}
if(!strcmp(cs->mailssconfig->getSync(),"one-way-server")){
pos =1;
}
if(!strcmp(cs->mailssconfig->getSync(),"one-way-client")){
pos =2;
}
lstSyncType.SetCurSel(pos);
*/
// Download mail since
pos=0;
switch(cs->mailssconfig->getDownloadAge())
{
case -1: pos=0; break;
case 0: pos=1; break;
case 3: pos=2; break;
case 5: pos=3; break;
case 7: pos=4; break;
case 10: pos=5; break;
};
lstMailSince.SetCurSel(pos);
// mail size
pos=0;
lstMsgSize.SetCurSel(getMsgSizePosition(cs->mailssconfig->getAttachSize()));
// attachments
if(cs->mailssconfig->getBodySize() == -1){
checkAttachments.SetCheck(BST_CHECKED);
}
// 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);
// lstSyncType.SetFocus();
return FALSE;
}
// CMailSettings message handlers
void CMailSettings::OnOK()
{
// save values in registry
ClientSettings* cs = getRegConfig();
CString s1, s2; int pos=0;
BOOL dirtyFlag=FALSE;
if(checkStartSync()){
CDialog::OnOK();
}
// pos = lstSyncType.GetCurSel();
//
// set type of sync
//
/* if(pos == 0){
cs->mailssconfig->setSync("two-way");
} else if(pos == 1){
cs->mailssconfig->setSync("one-way-server");
} else if(pos == 2) {
cs->mailssconfig->setSync("one-way-client");
}
*/
// mail since
int value=-1;
pos = lstMailSince.GetCurSel();
switch(pos)
{
case 0: value=-1;break;
case 1: value=0;break;
case 2: value=3;break;
case 3: value=5;break;
case 4: value=7;break;
case 5: value=10;break;
}
if(cs->mailssconfig->getDownloadAge() != value){
cs->mailssconfig->setDownloadAge(value);
dirtyFlag = TRUE;
}
// mail size
pos=0; value=-1;
pos = lstMsgSize.GetCurSel();
switch(pos)
{
case 0: value=2;break;
case 1: value=5;break;
case 2: value=10;break;
case 3: value=25;break;
case 4: value=50;break;
case 5: value=100;break;
case 6: value=250;break;
case 7: value=-1;break;
}
if(cs->mailssconfig->getAttachSize() != value){
cs->mailssconfig->setAttachSize(value);
dirtyFlag = TRUE;
}
// attachments
if(checkAttachments.GetCheck() == BST_CHECKED){
if(cs->mailssconfig->getBodySize() != -1){
cs->mailssconfig->setBodySize(-1);
dirtyFlag = TRUE;
}
}
else {
if(cs->mailssconfig->getBodySize() != 1){
cs->mailssconfig->setBodySize(1);
dirtyFlag = TRUE;
}
}
if(dirtyFlag){
getRegConfig()->setDirty(CS_DIRTY_SOURCE_MAIL);
getRegConfig()->saveDirty();
}
CDialog::OnOK();
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CMailSettings::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
//int displayMode = DRA::GetDisplayMode();
int resId;
switch(DRA::GetDisplayMode())
{
case DRA::Landscape:
resId = IDD_UI_MAIL_WIDE; break;
case DRA::Portrait:
resId = IDD_UI_MAIL; break;
case DRA::Square:
resId = IDD_UI_MAIL_SQUARE; break;
default:
resId = IDD_UI_MAIL; break;
};
DRA::RelayoutDialog( AfxGetInstanceHandle(), this->m_hWnd, MAKEINTRESOURCE(resId));
/*if( (resId == IDD_UI_MAIL_WIDE) || ( resId == IDD_UI_MAIL_SQUARE) )
staticAdvanced.ShowWindow(FALSE);
else
staticAdvanced.ShowWindow(TRUE);
*/
LoadStringResources();
}
#endif
void CMailSettings::LoadStringResources(){
CString s1;
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ADVANCED_SETTINGS); linkAdvanced.setText(s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SYNCTYPE); SetDlgItemText(IDC_SETTMAIL_STATIC_SYNCTYPE,s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ATTACHMENTS); SetDlgItemText(IDC_MAIL_CHECK_ATTACHMENTS, s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_DOWNLOAD); SetDlgItemText(IDC_MAIL_STATIC_DOWNLOAD, s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTMAIL_BUTFOLDERS); SetDlgItemText(IDC_SETTMAIL_BUTFOLDERS,s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTMAIL_BUTFILTER); SetDlgItemText(IDC_SETTMAIL_BUTFILTER,s1);
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTMAIL_BUTACCOUNT); SetDlgItemText(IDC_SETTMAIL_BUTACCOUNT,s1);
#if defined(WIN32_PLATFORM_PSPC)
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_MAIL_SETTINGS); SetDlgItemText(IDC_HEADER_STATIC, s1);
#endif
}
void CMailSettings::OnBnClickedMailLinkAdvanced()
{
CMailSettingsAdvanced wndMailAdvanced;
INT_PTR result = wndMailAdvanced.DoModal();
}
// capture pressing of 'Advanced' link
BOOL CMailSettings::PreTranslateMessage(MSG* pMsg){
bool bProcessed =false;
if(pMsg->message == WM_KEYDOWN){
if(pMsg->wParam == VK_RETURN){
if(GetFocus()->GetSafeHwnd() == linkAdvanced.GetSafeHwnd()){
bProcessed = true;
OnBnClickedMailLinkAdvanced();
}
}
};
if(bProcessed)
return TRUE;
else
return CDialog::PreTranslateMessage(pMsg);
}
HBRUSH CMailSettings::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 + -