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

📄 uidlg.cpp

📁 funambol window mobile客户端源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if( (!(isServerConfigured())) || user.IsEmpty() || password.IsEmpty() ||
        syncConfig == "1"){

        lstSources.ShowWindow(SW_HIDE);                
        //OnMenuComm();
        isInSettings = true;
        CCommunicationSettings commSettings;
        CString msg;
        if (syncConfig != "1" || user.IsEmpty() || password.IsEmpty()) {
            msg.LoadString(getLocalizationUtils()->getLocaleResource(),IDS_ERROR_ENTER_CREDENTIALS);
            commSettings.showMessage(msg);
        }
        INT_PTR result = commSettings.DoModal();
        refreshSourcePane(SOURCE_MAIL);
        lstSources.ShowWindow(SW_NORMAL);       
        if (result == 2) {
            if ( !CreateThread(NULL, 0, firtsSyncWorker, NULL, 0, NULL) ) {
                LOG.error("firtsSyncWorker Error creating updateProcedureWorker thread.");           
            }
        }
       
        isInSettings = false;
        return TRUE;

    }

    //this is set a true the first time to prevent not refresh
    //the date in on activate function before OnInitDialog 
    openUp = true;
    
    return TRUE;
}
//////////////////////////////////////////////////////////////////////////



void CuiDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
    int resId = IDD_UI_DIALOG;

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
    switch(DRA::GetDisplayMode())
    {
    case DRA::Landscape:
        resId = IDD_UI_DIALOG_WIDE;
        break;
    case DRA::Portrait:
        resId = IDD_UI_DIALOG; break;
    case DRA::Square:
        resId = IDD_UI_DIALOG_SQUARE; break;
    default:
        resId = IDD_UI_DIALOG; break;
    };
#endif

    DRA::RelayoutDialog( AfxGetInstanceHandle(), this->m_hWnd, MAKEINTRESOURCE(resId));

    // stretch the list to cover all client area
    CRect rect;
    GetClientRect(&rect);
    lstSources.setItemWidth(rect.Width());
    int panesHeight = max(rect.Height()/8, 30);
    lstSources.setItemHeight(panesHeight);
    lstSources.SetWindowPos(GetActiveWindow(),0,0, rect.Width(), rect.Height(),
        SWP_SHOWWINDOW );

    // Recalculate the main logo position.
    //ClientSettings* cs = getRegConfig();
    //if(cs->getIsPortal()) {
    //    lstSources.calculateMainLogoPosition();
    //}
    if (!showNoteSource && !showBriefcaseSource) {
        lstSources.calculateMainLogoPosition();
    }

    lstSources.Invalidate();
}


void CuiDlg::OnMenuLoglevel()
{
    isInSettings = true;
    CLoglevelSettings wndLoglevel;
    INT_PTR result = wndLoglevel.DoModal();
    isInSettings = false;
    if(bSyncStarted){
        CreateMenuBar(IDM_STOP);
    }
}

void CuiDlg::OnSync()
{
    if (!lstSources.getIsLocked()){
        lockPanes();
    }

    // start a sync of all enabled sources
    lstSources.setStateToAll(ITEM_STATE_TO_SYNC, true);
    lstSources.SetItemState(lstSources.GetCurSelItem(), 0, LVIS_FOCUSED);
    refreshSourcePane(SOURCE_MAIL);
    setFirstSourceToSync();
    StartSync(TEXT("manual"));
}

void CuiDlg::OnClose()
{
    int processID = 0;
    HWND wnd = NULL;
    wnd = ::FindWindow(TEXT("funambolstartsync"), NULL);
    if ((processID = checkStartSync()) != 0)  {
        // sync is in progress
        HwndFunctions::closePreviousMsgBox();
        
        // send msg to startsync to stop
        if(wnd){
            ::PostMessage(wnd, WM_COMMAND, (WPARAM)10, NULL);
        }
        Sleep(500);
        DWORD code = 0;
        GetExitCodeProcess((HANDLE)processID, &code);
        if (code == STILL_ACTIVE) {
            HANDLE hProcess = OpenProcess(0, FALSE, processID);
            if (hProcess) {
                startProgram(SYNCAPP, TEXT("removeNotif"));
                TerminateProcess(hProcess, -6); //-6 code for the user stop sync.
                CloseHandle(hProcess);
            }
        }
    }
    else {        
        startProgram(SYNCAPP, TEXT("removeNotif"));        
    }
    EndDialog(0);
}

void CuiDlg::OnMenuExit()
{
    int ret = EndAppQuery(GetSafeHwnd());
    if((ret == 0) || (ret== 1)) {
        //CDialog::OnOK();
        getRegConfig()->saveDirty();
    }
    EndDialog(0);
}

void CuiDlg::OnMenuRecover()
{
    CRecoverSettings wndRecover;
    // TODO: workaround for isInSettings
    isInSettings = true;
    INT_PTR result = wndRecover.DoModal();
    isInSettings = false;
    if(bSyncStarted){
        CreateMenuBar(IDM_STOP);
    }
     // Just to be sure...
    if (result == RECOVER_SYNC_STARTED) {
        SetCursor(LoadCursor(NULL, IDC_ARROW));
    }

    ClientSettings* cs = getRegConfig();
    cs->read();
    refreshSourcePanes();
            
    /*
    if(result == RECOVER_SYNC_STARTED){
        // the user started a recover sync
    }
    */
    //
    // this is to prevent to loose the push that maybe are come
    // during the cleanup process
    // 
    wchar_t** queue = readQueueList();
    if (queue) {        
        wstring cmdLine(TEXT("manual"));
        for (int count = 0; queue[count] != NULL; count++) {     

            if (count == 0) { cmdLine += L" "; }
            else            { cmdLine += L","; }
            cmdLine += queue[count];                       
        
        } 
        delete [] queue;        
        startProgram(SYNCAPP, cmdLine.c_str());
    }    
    
    isInSettings = false;
        
}


LRESULT CuiDlg::OnStartsyncEnded(WPARAM wParam, LPARAM lParam)
{
    CString s1("");

    lstSources.stopAnim(currentSource);
    lstSources.stopMainLogo();

    ClientSettings* cs = getRegConfig();
    cs->read();

    if(!isInSettings){
        CreateMenuBar(IDR_MENU_MAIN);
        #if defined WIN32_PLATFORM_WFSP
            #if (_WIN32_WCE < 0x500)
                CreateMenuBar(IDR_MAINFRAME);
            #endif
        #endif
    }

    retValueLastSync = lParam;
    bSyncStarted = false;

    // stop sync icon animation
    for(int i=0;i<lstSources.GetItemCount();i++){
        lstSources.stopAnim(lstSources.indexToId(i));
    }

    if( (retValueLastSync == 0) || (retValueLastSync == 10003) ||
        (retValueLastSync == -20) ||  (retValueLastSync == -6) ){  
        // for these errorcodes we don't display error message
    }
    else if (retValueLastSync == ERR_CONFIG_SOURCE_NOT_FOUND) {
        // Code 2100 = "config" source not found on the Server.
        // It's an old Server, that doesn't support config sync. 
        // Don't display messages and disable the source "config"
        // so we won't do config sync again, when UI params are modified.
        LOG.info("configuration syncsource not found on the Server (code 404).");
        LOG.debug("Config syncmode is now set to 'none'.");
        SyncSourceConfig* ssc = cs->getSyncSourceConfig("config");
        if (ssc) {
            ssc->setSync("none");
            cs->setDirty(CS_DIRTY_SOURCE_ENABLED);
            cs->saveDirty();
        }
    }
    else {
        // For smartphones, we don't want a waiting cursor over the msgbox.
        SetCursor(LoadCursor(NULL, IDC_ARROW));

        CString message = SyncErrorMsg(retValueLastSync);
        HwndFunctions::closePreviousMsgBox();
        HWND wndFocus = GetSafeHwnd();
        TimedMessageBox(GetSafeHwnd(), message, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
            MB_OK | MB_ICONHAND | MB_SETFOREGROUND, INFINITE);

        ::SetActiveWindow(wndFocus);
    }

    /* run the update procedure to show if there is one available. The check is done only if there
     * aren't any http error or is not a user stop of the sync      
    */
    if (!isInSettings && retValueLastSync >= 0 && retValueLastSync < ERR_TRANSPORT_BASE) {
        getRegConfig()->readUpdateParams();
        if (getRegConfig()->getUpdateParams().getIsAnUpdateAvailable() == "1") {
            updateProcedure(GetSafeHwnd(), false);
        }
    }

    // reset variables
    currentSource = 0;
    resetCurrentItem = true;
    totalItems = 0;
    lastItem = 0;
    sourceEnds = 0;
    sourceBegins = 0;
    firstSourceId = -1;
    nMailsToSync = 0;

    lstSources.SetItemState(lstSources.GetCurSelItem(), 0, LVIS_FOCUSED);

    //refreshRecoveredSources();
    unlockPanes();

    // for the case of scheduled sync when the user is in a config window
    if(!isInSettings){
        refreshSourcePanes();
    }

    if(! bSyncCanceled) // TODO: is this necessary?
        lstSources.setStateToAll(ITEM_STATE_OK);

    return 0;
}

LRESULT CuiDlg::OnStartingSync(WPARAM wParam, LPARAM lParam)
{
    CString s2;

    if(!isInSettings){
        HwndFunctions::closePreviousMsgBox();

        CreateMenuBar(IDM_STOP);
        #if defined WIN32_PLATFORM_WFSP
        #if (_WIN32_WCE < 0x500)
            CreateMenuBar(IDR_MENUBAR_STOP);
        #endif
        #endif
    }
    lockPanes();

    bSyncStarted = true;

    // Starts the timer for the main logo animation
    lstSources.startMainLogo();

    //getRegConfig()->saveDirty();
    // received start sync message, we check if startsync.exe has given the first source to be synced
    // if wParam !=0, then in lParam we have the id of the 1st source
    if(wParam != 0){
        firstSourceId = (int)lParam;
    }

    return 0;
}

void CuiDlg::OnMenuAbout()
{
    CAbout wndAbout;
    isInSettings = true;
    INT_PTR result = wndAbout.DoModal();
    isInSettings = false;
    if(bSyncStarted){
        CreateMenuBar(IDM_STOP);
    }
    refreshSourcePanes();
}

void CuiDlg::OnMenuStop()
{
    // because the sync is possibly being canceled in EndAppQuery, we set bSyncCanceled to true before calling it
    bSyncCanceled = true;
    int ret = EndAppQuery(GetSafeHwnd());
    // If startsync was not running simulate the message.
    // 1 - sync not running
    // 0 - user choosed to stop the sync, we need to call OnStartsyncEnded
    //       to reset the controls
    if(ret== 0) {
        bSyncCanceled = true;
        refreshCanceledState();
        OnStartsyncEnded(NULL, (LPARAM) -20 ); // nothing to show...
    }
    else if (ret== 1){
        bSyncCanceled = true;
        refreshCanceledState();
        OnStartsyncEnded(NULL, (LPARAM) -6 );
    }
    else{
        bSyncCanceled = false;
    }
}

void CuiDlg::OnMenuPush()
{
    CPushSettings wndPushSettings;

    isInSettings = true;
    INT_PTR result;

    result = wndPushSettings.DoModal();

    isInSettings = false;
    if(bSyncStarted){
        CreateMenuBar(IDM_STOP);
    }
}

void CuiDlg::OnMenuSync()
{
    CSyncSettings wndSyncSettings;
    isInSettings = true;
    INT_PTR result = wndSyncSettings.DoModal();
    isInSettings = false;

    refreshSourcePanes();
}

LRESULT CuiDlg::OnStartingSource(WPARAM wParam, LPARAM lParam)
{
    CString s1,s2;

    if (!lstSources.getIsLocked()){
        lockPanes();
    }

    //LOG.debug("OnStartingSource: lparam=%d, currentSource=%d", lParam, currentSource);
    if (currentSource != lParam) {
        lstSources.stopAnim(currentSource);
        currentSource = lParam;
    }

    if(! (sourceBegins & (int)pow(2.0, currentSource)) ){

⌨️ 快捷键说明

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