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

📄 recoversettings.cpp

📁 funambol window mobile客户端源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    BOOL mailToRecover = TRUE;

    if(checkMail.GetCheck() == BST_CHECKED && doesFunambolAccountExist()) {
        if (mailToRecover) {
            firstSourceToSyncId = SOURCE_MAIL;
            sourceToSync.push_back(MAILS_NAME);
            nCheckedSources++;
            // we need to know if this source is to be synced,
            // in the case when the sync is canceled, to display the appropriate text
            ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_MAIL, ITEM_STATE_TO_SYNC);
        }
    }

    if (checkContacts.GetCheck() == BST_CHECKED) {
        if(firstSourceToSyncId == -1) {             //not set
            firstSourceToSyncId = SOURCE_CONTACTS;
        }
        sourceToSync.push_back(CONTACTS_NAME);
        nCheckedSources ++;
        ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_CONTACTS, ITEM_STATE_TO_SYNC);
    }

    if(checkCalendar.GetCheck() == BST_CHECKED) {
        if(firstSourceToSyncId == -1) {             //not set
            firstSourceToSyncId = SOURCE_CALENDAR;
        }
        sourceToSync.push_back(APPOINTMENTS_NAME);
        nCheckedSources++;
        ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_CALENDAR, ITEM_STATE_TO_SYNC);
    }

    if(checkTasks.GetCheck() == BST_CHECKED) {
        if(firstSourceToSyncId == -1) {             //not set
            firstSourceToSyncId = SOURCE_TASKS;
        }
        sourceToSync.push_back(TASKS_NAME);
        nCheckedSources++;
        ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_TASKS, ITEM_STATE_TO_SYNC);
    }

#if defined(WIN32_PLATFORM_PSPC)
    if(checkNotes.GetCheck() == BST_CHECKED) {
        if(firstSourceToSyncId == -1) {            //not set
            firstSourceToSyncId = SOURCE_NOTES;
        }
        sourceToSync.push_back(NOTES_NAME);
        nCheckedSources++;
        ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_NOTES, ITEM_STATE_TO_SYNC);
    }
#endif

    if(checkBriefcase.GetCheck() == BST_CHECKED) {
        if(firstSourceToSyncId == -1){ //not set
            firstSourceToSyncId = SOURCE_BRIEFCASE;
        }
        sourceToSync.push_back(FILES_NAME);
        nCheckedSources++;
        ((CuiDlg*)AfxGetMainWnd())->getSourceListCtrl().setState(SOURCE_BRIEFCASE, ITEM_STATE_TO_SYNC);
    }

    if(nCheckedSources != 0){
#if 0            
        wstring sourceList = getCommandLine(sourceToSync);

        command += sourceList;

        // start recover sync
        int check  = checkStartSync();
        if(check == 0) {
            BOOL toCleanup = TRUE;
            BOOL toSync = TRUE;
            if (command.find(L"refresh-from-server") != wstring::npos) {
                toCleanup = FALSE;
                // hide recover window
                ShowWindow(SW_HIDE);
                if (checkRefreshFromServer(GetSafeHwnd(), sourceToSync, FALSE) != 0) {
                    toSync = FALSE;
                }
            } else if (command.find(L"refresh-from-client") != wstring::npos) {                
                toCleanup = FALSE;
                // hide recover window
                ShowWindow(SW_HIDE);
            } else if (command.find(L"cleanup") != wstring::npos) {
                toSync = FALSE;        
#endif

                /*
                * Create the Mutex of the sync to avoid to start the sync when the
                * clean up process is in progress. The mutex is closed when the 
                * cleanup procedure is finished.
                */

                hMutex = NULL;  //Handle to mutex...
                hMutex = CreateMutex(NULL, TRUE, TEXT("FunSyncInProgress") );
                CString sss;                              
                switch(GetLastError()) {
                    case ERROR_SUCCESS:
                        LOG.debug("Mutex created.");
                        cleanupStarted = true;
                        break;
                    case ERROR_ALREADY_EXISTS:
                        if(!cleanupStarted){
                            LOG.info("Cleanup process: a sync is in progress. No cleanup possible...");
                            sss.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CLEANUP_SYNC_IN_PROG);
                            TimedMessageBox(GetSafeHwnd(), sss, 
                                getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT),
                                MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND, ASK_REFRESH_TIMEOUT * 1000); // default ASK_TIMEOUT = 10
                        }else{
                        }
                        // close the handle of the cleanup
                        if (hMutex) {
                            CloseHandle(hMutex);
                            //cleanupStarted = false;
                        }                
                        return;
                    default:
                        LOG.error("Failed to create mutex");
                        // close the handle of the cleanup
                        if (hMutex) {
                            CloseHandle(hMutex);
                            cleanupStarted = false;
                        }                
                        return;                        
                }

                EnableRecoverButton(false);
                EnableCancelButton(false);

                if (checkRefreshFromServer(GetSafeHwnd(), sourceToSync, TRUE) == 0) {

                    CString s1;
                    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CLEANUP_IN_PROG);
                    SetDlgItemText(IDC_CLEANUP, s1);                      

                    try {                        
                        GetDlgItem(IDC_CLEANUP)->SetFont(&fontBold);                                                                
                    } catch (...) {
                        LOG.debug("RecoverSettings: font not loaded");
                    }                    
                    disableCheckbox();
                    startCleanUp(sourceToSync);
                }
                else {
                    if (hMutex) {
                        CloseHandle(hMutex);
                        cleanupStarted = false;
                    } 
                    enableCheckbox();
                    EnableRecoverButton(true);
                    EnableCancelButton(true);
                }
                GetActiveWindow()->Invalidate();
                GetActiveWindow()->UpdateWindow();            
#if 0
            }

            if (toSync) {
                // set first source to sync
                ((CuiDlg*)AfxGetMainWnd())->setFirstSourceToSync(firstSourceToSyncId);
                // start sync
                ((CuiDlg*)AfxGetMainWnd())->refreshSourcePane(SOURCE_MAIL);
                ((CuiDlg*)AfxGetMainWnd())->StartSync(command.c_str());

            }
#endif           
        }
    }
    

int CRecoverSettings::startCleanUp(vector<const wchar_t*> &sources) {
    CleanUpParams *par = new CleanUpParams(*this, sources, ((CuiDlg*)AfxGetMainWnd()));
    
    if ( !CreateThread(NULL, 0, cleanUpTask, (LPVOID)par, 0, NULL) ) {
        LOG.error("startCleanUp: error running thread.");
        return -1;
    }
    else {
        return 0;
}
}

/**
 * Clean up thread.
 */
static DWORD WINAPI cleanUpTask(LPVOID lpv) {

    CleanUpParams *par = (CleanUpParams *)lpv;

    if( !par ) {
        LOG.error("cleanUpTask: invalid parameters.");
        return 0;
    }

    SetCursor(LoadCursor(NULL, IDC_WAIT));        
    
    //
    // Call the startsync process: "startsync.exe cleanup <source1>,<source2>..."
    //
    wstring cmdLine(TEXT("cleanup"));
    vector<const wchar_t*> sourceToSync;
    sourceToSync = par->srcRef;
    vector<const wchar_t*>::iterator it;
    int count = 0;
    for (it = sourceToSync.begin(); it != sourceToSync.end(); it++) {
        if (count == 0) { cmdLine += L" "; }
        else            { cmdLine += L","; }
        cmdLine += (*it);                       
        count++;
    }
    int pid = startProgram(SYNCAPP, cmdLine.c_str());

    // Wait till the end of the cleanup...
    int ret = waitProcess(pid, INFINITE);

    
    SetCursor(LoadCursor(NULL, IDC_ARROW));
    par->wndRef.SetDlgItemText(IDC_CLEANUP, TEXT(""));

    // read the queue list and remove the sources that are already clenedup.
    // set in the registry only the ones that are not cleaned up.
    wchar_t** queue = readQueueList();
    if (queue) {
        vector<const wchar_t*> sourceToSync;
        sourceToSync = par->srcRef;
        vector<const wchar_t*>::iterator it;
        bool found = false;
        wchar_t** newQueue = new wchar_t*[10];
        int i = 0;
        for (int count = 0; queue[count] != NULL; count++) {    
            for (it = sourceToSync.begin(); it != sourceToSync.end(); it++) {
                if (wcscmp(queue[count], (*it)) == 0) {
                    found = true;
                    break;
                }
            }   
            if (found) {
                if (sourceToSync.size() > 0) {
                    sourceToSync.erase(it);
                } 
                found = false;
            } else {
                newQueue[i] = wstrdup(queue[count]);
                i++;                    
            }            
        } 
        newQueue[i] = NULL;
        delete [] queue;     
        updateQueueList((const wchar_t**)newQueue);
        delete [] newQueue;
    }

    endCleanUpProcess(par->wndRef.GetSafeHwnd(), par->srcRef);
    
    // Release the mutex if the cleanup started
    if (hMutex) {
        CloseHandle(hMutex);
        cleanupStarted = false;
    } 

    //par->mainDlg->refreshSourcePanes();
    par->wndRef.EndDialog(RECOVER_SYNC_STARTED);

    delete par;

    return 0;
}


#if defined(WIN32_PLATFORM_PSPC)
void CRecoverSettings::OnBnClickedRecoverNotes()
{
    EnableRecoverButton(isCheckboxChecked());
}
#endif


void CRecoverSettings::EnableRecoverButton(bool bEnable){
    HWND hwndMB = SHFindMenuBar (this->GetSafeHwnd());
    TBBUTTONINFO tbi;
    if (!hwndMB)
        return;

    memset (&tbi, 0, sizeof (tbi));
    tbi.cbSize = sizeof (tbi);
    tbi.dwMask = TBIF_STATE;
    ::SendMessage (hwndMB, TB_GETBUTTONINFO, IDOK, (LPARAM)&tbi);

    if(bEnable)
        tbi.fsState = TBSTATE_ENABLED;
    else
        tbi.fsState &= ~TBSTATE_ENABLED;

    ::SendMessage (hwndMB, TB_SETBUTTONINFO, IDOK, (LPARAM)&tbi);
}

void CRecoverSettings::EnableCancelButton(bool bEnable){
    HWND hwndMB = SHFindMenuBar (this->GetSafeHwnd());
    TBBUTTONINFO tbi;
    if (!hwndMB)
        return;

    memset (&tbi, 0, sizeof (tbi));
    tbi.cbSize = sizeof (tbi);
    tbi.dwMask = TBIF_STATE;
    ::SendMessage (hwndMB, TB_GETBUTTONINFO, IDCANCEL, (LPARAM)&tbi);

    if(bEnable)
        tbi.fsState = TBSTATE_ENABLED;
    else
        tbi.fsState &= ~TBSTATE_ENABLED;

    ::SendMessage (hwndMB, TB_SETBUTTONINFO, IDCANCEL, (LPARAM)&tbi);
}

void CRecoverSettings::OnBnClickedRecoverMail()
{
    EnableRecoverButton(isCheckboxChecked());

⌨️ 快捷键说明

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