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

📄 clientutil.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 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
 */

#include "stdafx.h"
#include "pim/maincpp.h"
#include "pim/SettingFunctions.h"
#include "base/startcmd.h"
#include "notify/timed_msgbox.h"
#include "HwndFunctions.h"
#include "spds/constants.h"

#include "ui.h"
#include "base/util/utils.h"
#include "processUtils.h"


// items in listboxes MUST be load in this order
int SynctypeReg2UI(const char* sSyncType)
{
	int pos = 0;

	if(! strcmp(sSyncType,"two-way"))
		pos=0;
	if(! strcmp(sSyncType, "one-way-server"))
		pos=1;
	if(! strcmp(sSyncType,"one-way-client"))
		pos=2;

	return pos;
}


const char* SynctypeUI2Reg(int nPos)
{
	switch(nPos)
	{
	case 0:
           return "two-way";
	case 1:
           return "one-way-server";
	case 2:
           return "one-way-client";
	}

    // should not get here
    return "";
}


/**
 * @return -1= NO, 0:YES, 1=Not running
 */
int EndAppQuery(HWND wndUIWindow)
{
    int ret = -1;
    CString s1;
    int processID = 0;
    HWND wnd = NULL;
    wnd = ::FindWindow(TEXT("funambolstartsync"), NULL);
    if ((processID = checkStartSync()) != 0)
    {
        // sync is in progress
        HwndFunctions::closePreviousMsgBox();
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_INTERRUPT_SYNC);
        //s1 = "Do you really want to interrupt the synchronization?";
        int retMsgBox = TimedMessageBox(wndUIWindow, s1, TEXT("Funambol alert"),
            MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND, 10 * 1000);

        if(retMsgBox == IDYES)
        {
            // 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);
                    CString s; s.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CODE_SYNC_STOPPED);
                    LOG.info(_wcc(s.GetString()));
                }
            }

            // The user answered YES
            return 0;
        }
    }
    else {
        // send msg to startsync to remove the notif Icon if there is again
        startProgram(SYNCAPP, TEXT("removeNotif"));
        // The process is not running
        return 1;
    }
    // The user answered no
    return -1;
}


int getSyncModeCode(const char* syncMode){
    int code = SYNC_NONE;

    if(strcmp(syncMode, "none") == 0)
        code = SYNC_NONE;
    if(strcmp(syncMode, "two-way") == 0)
        code = SYNC_TWO_WAY;
    if(strcmp(syncMode, "slow") == 0)
        code = SYNC_SLOW;
    if(strcmp(syncMode, "one-way-from-client") == 0)
        code = SYNC_ONE_WAY_FROM_CLIENT;
    if(strcmp(syncMode, "refresh-from-client") == 0)
        code = SYNC_REFRESH_FROM_CLIENT;
    if(strcmp(syncMode, "one-way-from-server") == 0)
        code = SYNC_ONE_WAY_FROM_SERVER;
    if(strcmp(syncMode, "refresh-from-server") == 0)
        code = SYNC_REFRESH_FROM_SERVER;

    return code;
}

const char* getSyncModeName(int code) {
    switch (code) {
        case SYNC_NONE:
            return "none";
            break;
        case SYNC_TWO_WAY:
        case SYNC_TWO_WAY_BY_SERVER:
            return "two-way";
            break;
        case SYNC_SLOW:
            return "slow";
            break;
        case SYNC_ONE_WAY_FROM_CLIENT:
        case SYNC_ONE_WAY_FROM_CLIENT_BY_SERVER:
            return "one-way-from-client";
            break;
        case SYNC_REFRESH_FROM_CLIENT:
        case SYNC_REFRESH_FROM_CLIENT_BY_SERVER:
            return "refresh-from-client";
            break;
        case SYNC_ONE_WAY_FROM_SERVER:
        case SYNC_ONE_WAY_FROM_SERVER_BY_SERVER:
            return "one-way-from-server";
            break;
        case SYNC_REFRESH_FROM_SERVER:
        case SYNC_REFRESH_FROM_SERVER_BY_SERVER:
            return "refresh-from-server";
            break;
        default:
            return NULL;
            break;
    }
}

BOOL existsDirectory(wchar_t* dir) {

    WIN32_FIND_DATA FileData;
    BOOL ret = TRUE;
    HANDLE hFind;

    hFind = FindFirstFile(dir, &FileData);

    if (hFind == INVALID_HANDLE_VALUE) {
        ret = FALSE;
    } else {
        ret = TRUE;
    }
    if (hFind) {
        FindClose(hFind);
    }

    return ret;
}

⌨️ 快捷键说明

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