📄 communicationsettings.cpp
字号:
cs->getAccessConfig().setUsername(tmp);
cs->setDirty(CS_DIRTY_ACCESS_CONFIG);
// If username changed, config will be forced to "slow" by the Server.
// Nothing to change here.
isUsernameChanged = true; // it set the email must be synced automatically
}
if (tmp) {
delete [] tmp; tmp = NULL;
}
tmp = toMultibyte(password.GetBuffer());
if(strcmp(tmp,cs->getAccessConfig().getPassword()) != 0){
cs->getAccessConfig().setPassword(tmp);
cs->setDirty(CS_DIRTY_ACCESS_CONFIG);
}
if (tmp) {
delete [] tmp; tmp = NULL;
}
const char* devId = cs->getDeviceConfig().getDevID();
if(strcmp(devId, "") == 0){
wstring s1;
#if defined(WIN32_PLATFORM_WFSP)
s1 = getIMEI();
#endif
#if defined(WIN32_PLATFORM_PSPC)
s1 = GetSerialNumberFromKernelIoControl();
#endif
tmp = toMultibyte(s1.c_str());
if(strcmp(tmp,cs->getDeviceConfig().getDevID()) != 0){
cs->getDeviceConfig().setDevID(tmp);
cs->setDirty(CS_DIRTY_DEVICE_CONFIG);
}
if (tmp) {
delete [] tmp; tmp = NULL;
}
}
// Save effectively to registry.
cs->saveDirty();
// If something changed and push was active, stop push, sync the config and restart push.
// (if ctp is running, we need to restart it with updated credentials / url)
if (isPushActive) {
stopPushService();
Sleep(1000);
}
// Starts the config sync (in a thread). Will restart the push at the end, if it was running.
// Note: the dialog is blocked with the WAIT icon!
// Will be restored in OnMsgConfigSyncEnded()
if (startConfigSync()) {
goto error;
}
return;
error:
// Re-enable dialog.
SetCursor(LoadCursor(NULL, IDC_ARROW));
enableUIObjects(true);
CDialog::OnOK();
}
#ifdef WIN32_PLATFORM_WFSP
LRESULT CCommunicationSettings::OnHotkey(WPARAM wParam, LPARAM lParam)
{
if (HIWORD(lParam) == VK_TBACK)
SHSendBackToFocusWindow(WM_HOTKEY, wParam, lParam);
return 0;
}
#endif
void CCommunicationSettings::showNotValidInputMessage(int code) {
CString s1;
switch (code) {
case 1:
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_EMPTY_USERNAME);
TimedMessageBox(NULL, s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONERROR | MB_SETFOREGROUND, INFINITE);
break;
case 2:
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_EMPTY_PASSWORD);
TimedMessageBox(NULL, s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONERROR | MB_SETFOREGROUND, INFINITE);
break;
case 3:
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_USERNAME_CONTAINS_BLANKS);
TimedMessageBox(NULL, s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONERROR | MB_SETFOREGROUND, INFINITE);
break;
case 4:
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_EMPTY_URL);
TimedMessageBox(NULL, s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONERROR | MB_SETFOREGROUND, INFINITE);
break;
case 5:
s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_INVALID_URL);
TimedMessageBox(NULL, s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONERROR | MB_SETFOREGROUND, INFINITE);
break;
default:
break;
}
}
/*
* return 0 if ok, a code otherwise
*/
int CCommunicationSettings::checkInputParameters(CString url, CString username, CString password){
CString s1;
CString lowerUrl(url);
lowerUrl.MakeLower();
if(username.IsEmpty()){
return 1;
};
if(password.IsEmpty()){
return 2;
};
if(username.Find(' ') != -1){
return 3;
}
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
CString lowerUrl(url);
lowerUrl.MakeLower();
if(url.IsEmpty()){
return 4;
};
// check if url is valid
if( ((lowerUrl.Left(7).Compare(_T("http://")) != 0) &&
(lowerUrl.Left(8).Compare(_T("https://")) != 0) ) ||
(lowerUrl.Compare(_T("http://")) == 0) ||
(lowerUrl.Compare(_T("https://")) == 0) ||
(lowerUrl.Left(8).Compare(_T("http:///")) == 0) ||
(lowerUrl.Left(9).Compare(_T("https:///"))== 0) ||
(lowerUrl.Mid(7).Find(_T("http:/")) != -1) ||
(lowerUrl.Mid(7).Find(_T("https:/")) != -1) ||
(lowerUrl.Find(' ') != -1) ||
(lowerUrl.Find('<') != -1) ||
(lowerUrl.Find('>') != -1)
) {
return 5;
}
}
return 0;
}
HBRUSH CCommunicationSettings::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
if(pWnd->GetDlgCtrlID() == IDC_ALERT) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(ALERT_COLOR);
}
return hbr;
}
void CCommunicationSettings::changeMailSettingsInfo(CString username) {
HRESULT ret = -1;
ret = modifyAccount(TEXT(""), DEFAULT_USER_W);
}
LRESULT CCommunicationSettings::OnMsgConfigSyncEnded( WPARAM wparam, LPARAM lparam){
bool isOldServer = false;
bool startPush = isPushActive; // Will restart the push, if necessary, at the end.
bool gotoMainScreen = true; // In some circumstances, we don't return to the main screen.
int exitcode = (int)wparam;
int value = 0;
ClientSettings* cs = getRegConfig();
switch (exitcode) {
case 0:
if (isUsernameChanged) {
toSyncMail = true;
isUsernameChanged = false; // no used next time
} else if (!toSyncMail) {
if (cs->getWinSyncSourceConfig("mail")->getLast() == 0) {
toSyncMail = true;
}
} // OK
break;
case ERR_CONFIG_SOURCE_NOT_FOUND: // 2100 = "config" source not found on the Server.
// Silently catched in uiDlg::OnStartSyncEnded()
isOldServer = true;
if (isUsernameChanged) {
toSyncMail = true;
isUsernameChanged = false; // no used next time
} else if (!toSyncMail) {
if (cs->getWinSyncSourceConfig("mail")->getLast() == 0) {
toSyncMail = true;
}
}
break;
case 401:
case 402:
case 403:
// Msgbox is already displayed, stay in this dialog and DON'T start push service!
LOG.info("Authentication failed, code %d", exitcode);
gotoMainScreen = false;
startPush = false;
toSyncMail = false;
setPushServiceOnlyInRegistry();
break;
// case 404: should not happen (404 is catched and converted into code 2100)
default:
if (exitcode >= 2000) {
// Error msg already displayed -> uiDlg::OnStartSyncEnded()
LOG.error("Network error, code %d", exitcode);
}
else {
LOG.error("Generic error, code %d", exitcode);
}
// the exit code is checked also to decide if go back to the main screen
toSyncMail = false;
gotoMainScreen = false;
break;
}
//
// We warn the user if Server didn't send a status 200 for PushStatus.
//
if (!isOldServer) {
if (cs->getConfigSyncDirty() & CP_DIRTY_PUSH_STATUS) {
if (startPush) {
// Avoid starting the push if we should restart it.
startPush = false;
cs->setPush("0");
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty();
}
TimedMessageBox(GetSafeHwnd(), TEXT("Push options could not be updated correctly. Check log for details."),
getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
MB_OK | MB_ICONHAND | MB_SETFOREGROUND, 10 * 1000);
}
}
//
// Restart push if it was initially active AND we stopped it.
//
if (isPushActive && startPush && (cs->getPush() == "0")) {
startPushService();
cs->setDirty(CS_DIRTY_ROOT_CONFIG);
cs->saveDirty();
}
// Re-enable UI dialog.
GetDlgItem(IDC_ALERT)->ShowWindow(SW_HIDE);
SetDlgItemText(IDC_ALERT, TEXT(""));
enableUIObjects(true);
SetCursor(LoadCursor(NULL, IDC_ARROW));
if (toSyncMail) { // start the first sync of the mail automatically
value = 2;
}
if (gotoMainScreen) {
((CuiDlg*)AfxGetMainWnd())->refreshSourcePanes();
EndDialog(value);
} else { // if there are any error, it doesn't go to main screen
const char* p = cs->getAccessConfig().getPassword();
const char* u = cs->getAccessConfig().getUsername();
char* ep = toMultibyte(currentPassword);
char* eu = toMultibyte(currentUsername);
if (exitcode >= 500 && exitcode != 2100 &&
strcmp(p, ep) == 0 &&
strcmp(u, eu) == 0 &&
isFromMainMenu) {
}
else {
cs->getAccessConfig().setPassword("");
cs->setDirty(CS_DIRTY_ACCESS_CONFIG);
cs->saveDirty();
SetDlgItemText(IDC_COMM_EDIT_PASS, L"");
editPassword.SetFocus();
}
delete [] eu; delete [] ep;
}
return 0;
}
LRESULT CCommunicationSettings::OnMsgClearAuthenticationLabel(WPARAM wparam, LPARAM ){
GetDlgItem(IDC_ALERT)->ShowWindow(SW_HIDE);
SetDlgItemText(IDC_ALERT, TEXT(""));
return 0;
}
void CCommunicationSettings::enableUIObjects(bool enable) {
HWND thisWnd = this->GetSafeHwnd();
EnableButton(thisWnd, IDOK, enable);
EnableButton(thisWnd, IDCANCEL, enable);
editUser.EnableWindow(enable);
editPassword.EnableWindow(enable);
//if (FUNOPT_SHOW_URL) {
if (showUrlField) {
editUrl.EnableWindow(enable);
}
}
#if defined(_DEVICE_RESOLUTION_AWARE)
void CCommunicationSettings::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/){
CRect clientRect, alertRect;
GetClientRect(&clientRect);
CWnd* alertLabel = GetDlgItem(IDC_ALERT);
if (alertLabel) {
alertLabel->GetWindowRect(&alertRect);
int x = 5;
int y = clientRect.Height() - alertRect.Height();
int cx = clientRect.Width() - 5; // Max value
int cy = alertRect.Height(); // No change
alertLabel->SetWindowPos(&CWnd::wndTop, x, y, cx, cy, SWP_NOZORDER);
}
}
#endif
void CCommunicationSettings::OnCancel(){
((CuiDlg*)AfxGetMainWnd())->refreshSourcePanes();
StringBuffer empty("");
ClientSettings* cs = getRegConfig();
CString user(cs->getAccessConfig().getUsername());
CString pass(cs->getAccessConfig().getPassword());
CString url(cs->getAccessConfig().getSyncURL());
if (checkInputParameters (url, user, pass) != 0 ) {
((CuiDlg*)AfxGetMainWnd())->OnClose();
}
EndDialog(0);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -