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

📄 uidlg.cpp

📁 funambol window mobile客户端源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
 * 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".
 */

#include "stdafx.h"
#include "ui.h"
#include "uiDlg.h"
#include "CommunicationSettings.h"

#include "LoglevelSettings.h"
#include "RecoverSettings.h"
#include "About.h"
#include "PushSettings.h"
#include "SyncSettings.h"
#include "pim/ClientSettings.h"
#include "pim/maincpp.h"
#include "shellapi.h"

#include "SynchronizationMessages.h"

#include "Shellapi.h"
#include "aygshell.h"
#include "pim/SettingFunctions.h"
#include "ClientUtil.h"

#include "base/util/utils.h"
#include <windows.h>

#include "comutil.h"
#include "HwndFunctions.h"
#include "notify/timed_msgbox.h"

#include "CustomButton.h"
#include "ClientUtil.h"

#include "MailSettings.h"
#include "ContactSettings.h"
#include "CalendarSettings.h"
#include "TaskSettings.h"
#include "BriefcaseSettings.h"
#include "NotesSettings.h"
#include "DeviceInfo.h"
#include "pim/account.h"
#include "processUtils.h"
#include "Popup.h"


#define ITEMS_FROM_SERVER 20

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

long retValueLastSync=0;
bool isServerConfigured();
void trim(wstring& str);
wstring reformatDate(wstring date);
wstring reformatTime(wstring time);

static bool showNoteSource = false;
static bool showBriefcaseSource = false;

CuiDlg::CuiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CuiDlg::IDD, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    openUp = false;
}


void CuiDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, lstSources);
}


BEGIN_MESSAGE_MAP(CuiDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE)
    ON_WM_SIZE()
#endif
    ON_COMMAND(IDM_COMM, OnMenuComm)
    //}}AFX_MSG_MAP
    ON_COMMAND(IDM_LOGLEVEL,                     &CuiDlg::OnMenuLoglevel)
    ON_COMMAND(ID_SYNC,                          &CuiDlg::OnSync)
    ON_COMMAND(ID_MENU_EXIT,                     &CuiDlg::OnMenuExit)
    ON_COMMAND(ID_RECOVER,                       &CuiDlg::OnMenuRecover)
    ON_COMMAND(ID_MENU_CLEANUP,                  &CuiDlg::OnMenuRecover)
    ON_MESSAGE(ID_MYMSG_CONNECTING,              &CuiDlg::OnMsgConnecting)
    ON_MESSAGE(ID_MYMSG_ENDING,                  &CuiDlg::OnMsgEndingSync)
    ON_MESSAGE(ID_MYMSG_ENDING_SOURCE,           &CuiDlg::OnMsgEndingSource)
    ON_MESSAGE(ID_MYMSG_STARTSYNC_ENDED,         &CuiDlg::OnStartsyncEnded)
    ON_MESSAGE(ID_MYMSG_STARTING_SYNC,           &CuiDlg::OnStartingSync)
    ON_MESSAGE(ID_MYMSG_STARTING_SOURCE,         &CuiDlg::OnStartingSource)
    ON_MESSAGE(ID_MYMSG_ITEM_SYNCED_FROM_SERVER, &CuiDlg::OnMsgItemSyncedFromServer)
    ON_MESSAGE(ID_MYMSG_ITEM_SYNCED_FROM_CLIENT, &CuiDlg::OnMsgItemSyncedFromClient)
    ON_MESSAGE(ID_MYMSG_POPUP,                   &CuiDlg::OnMsgPopup)
    ON_MESSAGE(ID_MYMSG_TOTAL_ITEMS,             &CuiDlg::OnMsgTotalItems)
    ON_MESSAGE(ID_MYMSG_OK, &CuiDlg::OnOKMsg)
    

    ON_MESSAGE(ID_MYMSG_TOTAL_NEW, &CuiDlg::OnMsgTotalItemsNew)
    ON_MESSAGE(ID_MYMSG_TOTAL_MOD, &CuiDlg::OnMsgTotalItemsMod)
    ON_MESSAGE(ID_MYMSG_TOTAL_DEL, &CuiDlg::OnMsgTotalItemsDel)


    ON_COMMAND(ID_MENU_UPDATE_SW, &CuiDlg::OnUpdateProcedure)
    ON_COMMAND(ID_MENU_ABOUT,                    &CuiDlg::OnMenuAbout)
    ON_COMMAND(IDABORT,                          &CuiDlg::OnMenuStop)
    ON_COMMAND(ID_SETTINGS_PUSHSETTINGS,         &CuiDlg::OnMenuPush)
    ON_COMMAND(ID_SETTINGS_SYNC,                 &CuiDlg::OnMenuSync)
    
                    
    ON_WM_CLOSE()
    //ON_WM_CONTEXTMENU() // for context menu
    ON_MESSAGE(ID_MYMSG_SOURCE_STATE,            &CuiDlg::OnMsgSourceState)
    ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1,        &CuiDlg::OnItemchangedList1)
    #if defined(WIN32_PLATFORM_PSPC)
//        ON_COMMAND(ID_MENU_CONTEXT_SYNC, &CuiDlg::OnContextMenuSync)
//        ON_COMMAND(ID_MENU_CONTEXT_SETTINGS, &CuiDlg::OnContextMenuSettings)
    #endif
    ON_WM_ACTIVATE()
    ON_WM_INITMENUPOPUP()   
    ON_COMMAND(ID_TOOLS_DEVICEINFO, &CuiDlg::OnToolsDeviceinfo)
END_MESSAGE_MAP()


/**
* It deletes a special file created during the installation process to signal
* there is an update in progress. If the user chooses to stop the upgrade of the 
* product, this files remain there and there is no way to remove. So at the start
* of the plug-in we remove the file in any way. See setup.cpp for other detail.
*/
void deleteFileForUpdate() {
    DeleteFile(TEXT("\\__uninstall_Fun_plugin__"));
}


class ParamsForUpdate {
public:
    CuiDlg& dialogWnd;
    bool manual;

    ParamsForUpdate(CuiDlg& wnd, bool val) : 
            dialogWnd(wnd), manual(val) {};
    ~ParamsForUpdate() {};
} ;
 
static bool isThereAnUpdate() {
    
    bool ret = false;
    ClientSettings* cs = getRegConfig();
    cs->readUpdateParams();
    if ((getRegConfig()->getUpdateParams().getLater() != "0"   &&
        getRegConfig()->getUpdateParams().getLater() != "")    ||
        (getRegConfig()->getUpdateParams().getSkipped() != ""  &&
        getRegConfig()->getUpdateParams().getSkipped() != "0") ||
        (getRegConfig()->getUpdateParams().getNow() != ""  &&
        getRegConfig()->getUpdateParams().getNow() != "0")   ) {
            ret = true;
    }
    return ret;
}
/**
* Thread that starts after the sync of the credential if there is 
* an update available
*/
static DWORD WINAPI updateSettingsProcedureWorker(LPVOID lpv) {
    Sleep(1000);
    ParamsForUpdate* p = (ParamsForUpdate*)lpv;         
    int ret = updateProcedure(p->dialogWnd.GetSafeHwnd(), false);       
    return 0;
}

static DWORD WINAPI updateProcedureWorker(LPVOID lpv) {
    ParamsForUpdate* p = (ParamsForUpdate*)lpv;     
    SetCursor(LoadCursor(NULL, IDC_WAIT)); // LoadIconModal();   // 
    checkAvailableUpdate();
    SetCursor(LoadCursor(NULL, IDC_ARROW)); // RemoveIconModal(); // 
    if (p->manual == true) {
        p->dialogWnd.OnOK();        
    } 
    int ret = updateProcedure(p->dialogWnd.GetSafeHwnd(), p->manual);       
    return 0;
}

void CuiDlg::OnUpdateProcedure() {      
    int ret = OnMsgPopup(IDS_BUT_NOW_LATER, IDS_UP_MESSAGE);        
    LOG.debug("Asked if the user want update (mandatory): response (0Ye, 1La) %i", ret);
    if (ret == 0) {        
        ParamsForUpdate* p = new ParamsForUpdate(*this, true);
        if ( !CreateThread(NULL, 0, updateProcedureWorker, (LPVOID)p, 0, NULL) ) {
            LOG.error("OnUpdateProcedure Error creating updateProcedureWorker thread.");           
        }        
    } else {        
        // the user chooses Later. We only update the timer
        updateLastCheckUpdate();
        
    }    
}

void CuiDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex, BOOL bSysMenu) { 
       
    if (isThereAnUpdate()) {
        CString item;
        pPopupMenu->GetMenuString(3, item, MF_BYPOSITION);
        CString s1; s1.LoadString(getLocalizationUtils()->getLocaleResource(),IDS_UPDATE_SOFTWARE);
        
        if (item != s1) {
            pPopupMenu->InsertMenu(3, MF_BYCOMMAND | MF_BYPOSITION, ID_MENU_UPDATE_SW, s1);
        }
    }
}

// start the sync only for email
static DWORD WINAPI firtsSyncWorker(LPVOID lpv) {
    Sleep(2000);   
    startProgram(SYNCAPP, TEXT("manual mail"));
    return 0;
}

void CuiDlg::OnMenuComm()
{
    isInSettings = true;
    CCommunicationSettings wndCommSett;
    wndCommSett.setIsFromMainMenu(true);
    INT_PTR result = wndCommSett.DoModal();   
    // it returns 1 if the sync process has aborted
    if (result == 1) {
        OnStartsyncEnded(NULL, (LPARAM) -20 );
        bSyncStarted = false;
    }   
    else if (result == 2) {
        if ( !CreateThread(NULL, 0, firtsSyncWorker, NULL, 0, NULL) ) {
            LOG.error("firtsSyncWorker Error creating updateProcedureWorker thread.");           
        }
    }
    
    isInSettings = false;
    if(bSyncStarted){
        CreateMenuBar(IDM_STOP);
    }
    this->Invalidate();
}


// CuiDlg message handlers

BOOL CuiDlg::OnInitDialog()
{
    
    // it is used to decide if reset the counter of the total item.
    resetTheItem = false;
    // it is used to populate the message without the default message
    messageToWrite = "";

    CString s1;
    s1.LoadString(getLocalizationUtils()->getLocaleResource(),IDS_FUNAMBOL); SetWindowText(s1);
    CDialog::OnInitDialog();
    LOG.setLevel(getLOGLevel());
    AfxGetMainWnd()->EnableWindow();
    // init settings
    ClientSettings* cs = getRegConfig();
    
    //
    // it defines if we have to show the briefcase source and note source
    //
    showBriefcaseSource = cs->getBrandingParams().getShowBriefcaseSource();
    showNoteSource = cs->getBrandingParams().getShowNoteSource();

    deleteFileForUpdate();
    
    try {
        // Set the icon for this dialog.  The framework does this automatically
        //  when the application's main window is not a dialog
        SetIcon(m_hIcon, TRUE);			// Set big icon
        SetIcon(m_hIcon, FALSE);		// Set small icon
    }
    catch(...) {
        LOG.error("uiDlg: can't set application icon.");
    }

     // try to set the font used in main window
    try {
        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(lstSources.fontBold.CreateFontIndirect(&lf));
    }
    catch(...) {
        LOG.error("uiDlg: can't set main screen font.");
    }

    // check if another sync is in progress
    if(checkStartSync() != 0)
    {
        CreateMenuBar(IDM_STOP);
        #if defined WIN32_PLATFORM_WFSP
        #if (_WIN32_WCE < 0x500)
            CreateMenuBar(IDR_MENUBAR_STOP);
        #endif
        #endif
        bSyncStarted = true;
    }
    else
    {
        CreateMenuBar(IDR_MENU_MAIN);
       
        #if defined WIN32_PLATFORM_WFSP
        #if (_WIN32_WCE < 0x500)
            CreateMenuBar(IDR_MAINFRAME);
        #endif
        #endif
        bSyncStarted = false;
    }

     // init variables. To put in the constructor
    //**************************
    currentSource = 0;
    resetCurrentItem = true;
    lastItem = 0;
    currentItem = 0;
    totalItems = 0;
    sourceEnds = 0;
    sourceBegins = 0;
    nMailsToSync = 0;

    isInSettings = false;
    firstSourceId = -1;

    // set states
    syncSourceContactState = SYNCSOURCE_STATE_OK;
    syncSourceCalendarState = SYNCSOURCE_STATE_OK;
    syncSourceTaskState = SYNCSOURCE_STATE_OK;
    syncSourceNoteState = SYNCSOURCE_STATE_OK;
    syncSourceBriefcaseState = SYNCSOURCE_STATE_OK;
    syncSourceMailState = SYNCSOURCE_STATE_OK;
    bSyncCanceled = false;
    //**************************

    initSyncControls();
    lstSources.SetItemState(0, LVIS_SELECTED, LVIF_STATE);

    // stretch the list to cover all client area.
    // this is used only for smartphone because it has only one dialog.
    // For pocket pc it is overwritten by the OnSize function
    CRect rect;
    GetClientRect(&rect);
    lstSources.setItemWidth(rect.Width());
    int panesHeight = max(rect.Height()/8, 30);     // min height is 30px
    lstSources.setItemHeight(panesHeight);
    lstSources.SetWindowPos(GetActiveWindow(),0,0, rect.Width(), rect.Height(), SWP_SHOWWINDOW);
    lstSources.Invalidate();          

    CString user;
    CString password;
    user = getRegConfig()->getAccessConfig().getUsername();
    password = getRegConfig()->getAccessConfig().getPassword();
    string syncConfig = getRegConfig()->getToSyncConfiguration();

⌨️ 快捷键说明

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