maincpp.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,441 行 · 第 1/4 页

CPP
1,441
字号
        else if (!wcscmp(sources[i], APPOINTMENTS_NAME)) {
            mask = mask | 4;
        }
        else if (!wcscmp(sources[i], TASKS_NAME)) {
            mask = mask | 8;
        }
        else if (!wcscmp(sources[i], NOTES_NAME)) {
            mask = mask | 16;
        }
        else if (!wcscmp(sources[i], FILES_NAME)) {
            mask = mask | 32;
        }
    }

    // Write 'queueList' value to registry
    sprintf(buf, "%d", mask);
    node->setPropertyValue(CTP_QUEUE_LIST, buf);
    node->setPropertyValue(CTP_QUEUE_PUSH, "1");

finally:
    if (dmt)   delete dmt;
    if (node)  delete node;
    if (value) delete [] value;
}

wchar_t** readPIMModifications() {

    wchar_t** sources    = NULL;
    DMTree* dmt          = NULL;
    ManagementNode* node = NULL;
    char* value          = NULL;
    int mask = 0;
    list<wstring> sourceList;
    list<wstring>::iterator it;

    dmt = DMTreeFactory::getDMTree(APPLICATION_URI);
    if (!dmt)   goto finally;
    node = dmt->readManagementNode(APPLICATION_URI);
    if (!node)  goto finally;

    value = node->readPropertyValue(CP_PUSH_LIST);
    if (!value) {
        goto finally;
    }
    mask = atoi(value);
    if (mask <= 0) {
        goto finally;
    }

    // Create the NULL terminated array of source names
    // (first need the number of sources, to allocate the WCHAR**)
    sourceList.clear();
    if (mask &  2)  sourceList.push_back(CONTACTS_NAME    );
    if (mask &  4)  sourceList.push_back(APPOINTMENTS_NAME);
    if (mask &  8)  sourceList.push_back(TASKS_NAME       );

    int i=0;
    sources = new wchar_t*[sourceList.size()+1];
    it = sourceList.begin();
    while (it != sourceList.end()) {
        sources[i++] = wstrdup((*it).c_str());
        it++;
    }
    sources[i] = NULL;

    // NO: to reset the property, call 'resetPIMModifications'.
    //node->setPropertyValue(CP_PUSH_LIST, "0");

finally:

    if (dmt)   delete dmt;
    if (node)  delete node;
    if (value) delete [] value;

    return sources;
}


void resetPIMModifications(const wchar_t** sources) {

    DMTree* dmt          = NULL;
    ManagementNode* node = NULL;
    char* value          = NULL;
    int mask = 0;
    char buf[4];

    dmt = DMTreeFactory::getDMTree(APPLICATION_URI);
    if (!dmt)   goto finally;
    node = dmt->readManagementNode(APPLICATION_URI);
    if (!node)  goto finally;

    if (sources == NULL) {
        node->setPropertyValue(CP_PUSH_LIST, "0");
        goto finally;
    }

    value = node->readPropertyValue(CP_PUSH_LIST);
    if (!value) {
        goto finally;
    }

    mask = atoi(value);

    //
    // Update the bit-mask with current sources
    //
    for (int i=0; sources[i]; i++) {

        if (!wcscmp(sources[i], CONTACTS_NAME)) {
            mask = mask & (~2);
        }
        else if (!wcscmp(sources[i], APPOINTMENTS_NAME)) {
            mask = mask & (~4);
        }
        else if (!wcscmp(sources[i], TASKS_NAME)) {
            mask = mask & (~8);
        }
    }

    sprintf(buf, "%d", mask);
    node->setPropertyValue(CP_PUSH_LIST, buf);

finally:

    if (dmt)   delete dmt;
    if (node)  delete node;
    if (value) delete [] value;

}

/**
* handles the errors that comes from the smtp server. If the errors are
* the ones in the list we can show the appropriate one.

SMTP 421 - Service not available, closing transmission channel.
SMTP 450 - Requested mail action not taken: mailbox unavailable.
           Mailbox is locked and busy.
SMTP 451 - Requested action aborted: local error in processing.
           Error processing request.
SMTP 452 - Requested action not taken: insufficient system storage.
SMTP 500 - Syntax error, command unrecognized.
SMTP 501 - Syntax error in parameters or arguments.
SMTP 502 - Command not implemented.
SMTP 503 - Bad sequence of commands.
SMTP 504 - Command parameter not implemented.
SMTP 550 - Requested action not taken: mailbox unavailable.
           Mailbox not found.
SMTP 551 - User not local; please try <forward-path>.
           User mailbox is known, but mailbox not on this server
SMTP 552 - Requested mail action aborted: exceeded storage allocation.
           Storage limit exceeded.
SMTP 553 - Requested action not taken: mailbox name not allowed.
           Invalid mailbox name syntax.
SMTP 554 - Transaction failed.
*/
wstring getEmailErrorMessage(wstring error) {

    wstring ret; 
    if (error.find(L"Error Code: [421]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_421);
    } else if (error.find(L"Error Code: [450]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_450);
    } else if (error.find(L"Error Code: [451]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_451);
    } else if (error.find(L"Error Code: [501]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_501);
    } else if (error.find(L"Error Code: [550]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_550);
    } else if (error.find(L"Error Code: [552]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_552);
    } else if (error.find(L"Error Code: [553]") != string::npos) {
        ret = getLocalizationUtils()->getLocalizationString(IDS_MAIL_OUT_ERROR_553);
    } else {
        // default
        ret = getLocalizationUtils()->getLocalizationString(IDS_ONE_OUT_MESSAGE_NOT_SENT);
    }
    return ret;
}

int OpenMessageBox(HWND hwnd, UINT buttons, UINT msg){

    if (hwnd == NULL) {
        hwnd = HwndFunctions::getWindowHandle();
    }
    if(!hwnd){
        wstring progName = TEXT(PROVIDER);
        progName += L".exe";
        startProgram(progName.c_str(), L"");
        hwnd = HwndFunctions::getWindowHandle();
    }

    int ret = SendMessage(hwnd, ID_MYMSG_POPUP, buttons, msg);

    return ret;
}


wchar_t** getCompleteList(wchar_t** sLists, wchar_t** cpLists) {
    
    if (sLists == NULL && cpLists == NULL) { return NULL;    }
    if (sLists == NULL)                    { return cpLists; }
    if (cpLists == NULL)                   { return sLists;  }
    
    list<wstring> sourceList;
    list<wstring>::iterator it;
    int queue = 0, cp = 0, mask = 0, i = 0;
    for (i = 0; sLists[i]; i++) {                      
        if (wcscmp(sLists[i], MAILS_NAME) == 0)             { queue = queue | 1; } 
        else if (wcscmp(sLists[i], CONTACTS_NAME) == 0)     { queue = queue | 2; } 
        else if (wcscmp(sLists[i], APPOINTMENTS_NAME) == 0) { queue = queue | 4; } 
        else if (wcscmp(sLists[i], TASKS_NAME) == 0)        { queue = queue | 8; }
    }
    for (i = 0; cpLists[i]; i++) {                      
        if (wcscmp(cpLists[i], CONTACTS_NAME) == 0)          { cp = cp | 2; } 
        else if (wcscmp(cpLists[i], APPOINTMENTS_NAME) == 0) { cp = cp | 4; } 
        else if (wcscmp(cpLists[i], TASKS_NAME) == 0)        { cp = cp | 8; }
    }

    mask = queue | cp;
    sourceList.clear();
    if (mask &  1)  sourceList.push_back(MAILS_NAME       );
    if (mask &  2)  sourceList.push_back(CONTACTS_NAME    );
    if (mask &  4)  sourceList.push_back(APPOINTMENTS_NAME);
    if (mask &  8)  sourceList.push_back(TASKS_NAME       );

    i = 0;
    wchar_t** sources = new wchar_t*[sourceList.size()+1];
    it = sourceList.begin();
    while (it != sourceList.end()) {
        sources[i++] = wstrdup((*it).c_str());
        it++;
    }
    sources[i] = NULL;

    return sources;
} 



bool findSourceInVector(vector<const wchar_t*> sourceVector, const wchar_t* source) {

    if (!source) { return false; }

    vector<const wchar_t*>::iterator it;

    it = sourceVector.begin();
    while(it != sourceVector.end()) {
        if (!wcscmp((*it), source)) {
            return true;
        }
        it++;
    }
    // Not found
    return false;
}

#include "Updater.h"
#ifdef WIN32_PLATFORM_WFSP
#define CLIENT_PLATFORM "wmsph"    
#endif
#ifdef WIN32_PLATFORM_PSPC
#define CLIENT_PLATFORM "wmppc"
#endif

/**
* called by the UI after a check manual or by the startsync (using both the 
* checkAvailableUpdate or the checkUpdate.
*
* It is called also by the startsync if there is a push and the UI is not available.
* in this case it instantiate the new UI.
* 
*/
int updateProcedure(HWND hwnd, bool manual) {    
    ClientSettings* cs = getRegConfig();
    const char* plugVersion = cs->getDeviceConfig().getOem();
    Updater* up = getUpdater(CLIENT_PLATFORM, hwnd, cs);
    int ret;
    if (hwnd == NULL) {
        ret = up->startWithoutUI();            
    } else {
        if (manual) {
            ret = up->startManually();
        } else {
            ret = up->start();
        }
    }
    return ret;

}

/**
* Called by the UI when there is a manual update
*/
int checkAvailableUpdate() {
    ClientSettings* cs = getRegConfig();
    const char* plugVersion = cs->getDeviceConfig().getOem();
    Updater* up = getUpdater(CLIENT_PLATFORM, NULL, cs);
    up->checkUpdateFromServer();    
    return 0;
}

/**
* It is called by startsync to check if there is a new version available. If there is one,
* it sets a parameter into the reigistry
*/
int checkUpdate() {
    ClientSettings* cs = getRegConfig();
    const char* plugVersion = cs->getDeviceConfig().getOem();
    Updater* up = getUpdater(CLIENT_PLATFORM, NULL, cs);
    int ret = up->checkIsToUpdate();    
    return ret;

}

/**
* It is used to update only the last update check parameter.
*/
void updateLastCheckUpdate() {
    ClientSettings* cs = getRegConfig();
    const char* plugVersion = cs->getDeviceConfig().getOem();
    Updater* up = getUpdater(CLIENT_PLATFORM, NULL, cs);
    up->updateTime();
  
}

/*
* return a the time to write into log file. If complete is true, it return
* the date too, else only hours, minutes, seconds and milliseconds
*/
static char* createCurrentTime(BOOL complete) {

    SYSTEMTIME sys_time;
    TIME_ZONE_INFORMATION timezone;
    GetLocalTime(&sys_time);
    GetTimeZoneInformation(&timezone);

    char fmtComplete[] = "%04d-%02d-%02d %02d:%02d:%02d GMT %c%d:%02d";
    char fmt[]         = "%02d:%02d:%02d GMT %c%d:%02d";

    char* ret = new char [64];

    // calculate offset from UTC/GMT in hours:min, positive value
    // means east of Greenwich (e.g. CET = GMT +1)

    char direction = timezone.Bias <= 0 ? '+' : '-';
    int hours = abs(timezone.Bias / 60) ;
    int minutes = abs(timezone.Bias % 60);

    if (complete) {
        sprintf(ret, fmtComplete, sys_time.wYear, sys_time.wMonth, sys_time.wDay,
                 sys_time.wHour, sys_time.wMinute, sys_time.wSecond,
                direction, hours, minutes);
    } else {
        sprintf(ret, fmt, sys_time.wHour, sys_time.wMinute, sys_time.wSecond,
                direction, hours, minutes);
    }
    return ret;
}

⌨️ 快捷键说明

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