From 6f7054d8f6c14e032a45a42555d4ab097fc82863 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 May 2015 16:39:06 +0000 Subject: - STL removed; - code optimization and restructuring; - warning fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@13549 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox.cpp | 5 --- plugins/Dropbox/src/dropbox.h | 27 ++++++------ plugins/Dropbox/src/dropbox_events.cpp | 33 +++++++------- plugins/Dropbox/src/dropbox_menus.cpp | 14 +----- plugins/Dropbox/src/dropbox_services.cpp | 71 +++++++++++++------------------ plugins/Dropbox/src/dropbox_transfers.cpp | 7 ++- plugins/Dropbox/src/file_transfer.h | 5 +-- plugins/Dropbox/src/http_request.h | 2 - plugins/Dropbox/src/stdafx.h | 4 +- plugins/Dropbox/src/version.h | 6 +-- 10 files changed, 70 insertions(+), 104 deletions(-) diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 98e37451f7..b75d5a877d 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -27,11 +27,6 @@ CDropbox::CDropbox() InitializeIcons(); InitializeMenus(); - commands["help"] = CDropbox::CommandHelp; - commands["content"] = CDropbox::CommandContent; - commands["share"] = CDropbox::CommandShare; - commands["delete"] = CDropbox::CommandDelete; - hFileProcess = hMessageProcess = 1; hDefaultContact = hTransferContact = 0; } diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index bb07d1f921..ab4d72697c 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -1,8 +1,6 @@ #ifndef _DROPBOX_PROTO_H_ #define _DROPBOX_PROTO_H_ -#include -#include #include "http_request.h" #include "file_transfer.h" @@ -25,16 +23,16 @@ enum CMI_MAX // this item shall be the last one }; -struct CommandParam -{ - CDropbox *instance; - HANDLE hProcess; - MCONTACT hContact; - void *data; -}; - class CDropbox { + struct CommandParam + { + CDropbox *instance; + HANDLE hProcess; + MCONTACT hContact; + void *data; + }; + public: CDropbox(); virtual ~CDropbox(); @@ -48,9 +46,7 @@ private: MCONTACT hDefaultContact; MCONTACT hTransferContact; - - std::map dcftp; - std::map commands; + HWND hTransferWindow; HGENMENU contactMenuItems[CMI_MAX]; @@ -97,7 +93,7 @@ private: // account info void RequestAccountInfo(); - // transrers + // transfers int SendFile(const char *fileName, const char *data, int length); int SendFileChunkedFirst(const char *data, int length, char *uploadId, size_t &offset); int SendFileChunkedNext(const char *data, int length, const char *uploadId, size_t &offset); @@ -127,6 +123,9 @@ private: // dialogs static INT_PTR CALLBACK MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + // SRMM + static void DisableSrmmButton(MCONTACT hContact); + // utils static wchar_t *HttpStatusToText(HTTP_STATUS status); static int HandleHttpResponseError(HANDLE hNetlibUser, NETLIBHTTPREQUEST *response); diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 1d2c2f53e9..a73844469b 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -118,22 +118,23 @@ int CDropbox::OnTabSrmmButtonPressed(void *obj, WPARAM, LPARAM lParam) if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact) { instance->hTransferContact = cbc->hContact; + instance->hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - - instance->dcftp[hwnd] = cbc->hContact; - - BBButton bbd = { sizeof(bbd) }; - bbd.pszModuleName = MODULE; - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.bbbFlags = BBSF_DISABLED; - - CallService(MS_BB_SETBUTTONSTATE, cbc->hContact, (LPARAM)&bbd); + DisableSrmmButton(cbc->hContact); } return 0; } +void CDropbox::DisableSrmmButton(MCONTACT hContact) +{ + BBButton bbd = { sizeof(bbd) }; + bbd.pszModuleName = MODULE; + bbd.dwButtonID = BBB_ID_FILE_SEND; + bbd.bbbFlags = BBSF_DISABLED; + CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd); +} + void __stdcall EnableTabSrmmButtonAsync(void *arg) { BBButton bbd = { sizeof(bbd) }; @@ -141,7 +142,6 @@ void __stdcall EnableTabSrmmButtonAsync(void *arg) bbd.dwButtonID = BBB_ID_FILE_SEND; bbd.bbbFlags = BBSF_RELEASED; MCONTACT hContact = (MCONTACT)arg; - CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd); } @@ -150,12 +150,10 @@ int CDropbox::OnFileDialogCancelled(void *obj, WPARAM, LPARAM lParam) CDropbox *instance = (CDropbox*)obj; HWND hwnd = (HWND)lParam; - if (instance->hTransferContact == instance->dcftp[hwnd]) + if (instance->hTransferWindow == hwnd) { CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact); - - instance->dcftp.erase((HWND)lParam); - instance->hTransferContact = 0; + instance->hTransferWindow = 0; } return 0; @@ -166,11 +164,10 @@ int CDropbox::OnFileDialogSuccessed(void *obj, WPARAM, LPARAM lParam) CDropbox *instance = (CDropbox*)obj; HWND hwnd = (HWND)lParam; - if (instance->hTransferContact == instance->dcftp[hwnd]) + if (instance->hTransferWindow == hwnd) { - instance->dcftp.erase((HWND)lParam); - CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact); + instance->hTransferWindow = 0; } return 0; diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp index 3130555d3d..7255d80ff3 100644 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ b/plugins/Dropbox/src/dropbox_menus.cpp @@ -3,23 +3,13 @@ INT_PTR CDropbox::SendFilesToDropboxCommand(void *obj, WPARAM hContact, LPARAM) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return 1; instance->hTransferContact = hContact; + instance->hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - - instance->dcftp[hwnd] = hContact; - - BBButton bbd = { sizeof(bbd) }; - bbd.pszModuleName = MODULE; - bbd.dwButtonID = BBB_ID_FILE_SEND; - bbd.bbbFlags = BBSF_DISABLED; - - CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd); - + DisableSrmmButton(hContact); return 0; } diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index c1bce181d0..4667998633 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -67,7 +67,6 @@ INT_PTR CDropbox::ProtoSetStatus(void *obj, WPARAM wp, LPARAM) INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return ACKRESULT_FAILED; @@ -147,69 +146,60 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return ACKRESULT_FAILED; CCSDATA *pccsd = (CCSDATA*)lParam; - char *message = (char*)pccsd->lParam; + char *message = NEWSTR_ALLOCA((char*)pccsd->lParam); DBEVENTINFO dbei = { sizeof(dbei) }; dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = strlen(message); + dbei.cbBlob = (int)strlen(message); dbei.pBlob = (PBYTE)message; dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF; db_event_add(pccsd->hContact, &dbei); - char help[1024]; - - if (message[0] && message[0] == '/') - { + if (message[0] && message[0] == '/') { // parse commands char *sep = strchr(message, ' '); - int len = strlen(message) - (sep ? strlen(sep) : 0) - 1; - ptrA cmd((char*)mir_alloc(len + 1)); - strncpy(cmd, message + 1, len); - cmd[len] = 0; - if (instance->commands.find((char*)cmd) != instance->commands.end()) - { - ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); - - CommandParam *param = new CommandParam(); - param->instance = instance; - param->hContact = pccsd->hContact; - param->hProcess = (HANDLE)messageId; - param->data = (sep ? sep + 1 : NULL); - - mir_forkthread(instance->commands[(char*)cmd], param); + if (sep != NULL) *sep = 0; - return messageId; + struct + { + const char *szCommand; + pThreadFunc pHandler; } - else + static commands[] = { - mir_snprintf( - help, - SIZEOF(help), - Translate("Unknown command \"%s\".\nUse \"/help\" for more info."), - message); + { "help", &CDropbox::CommandHelp }, + { "content", &CDropbox::CommandContent }, + { "share", &CDropbox::CommandShare }, + { "delete", &CDropbox::CommandDelete } + }; + + for (int i=0; i < SIZEOF(commands); i++) { + if (!strcmp(message+1, commands[i].szCommand)) { + ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); - CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); + CommandParam *param = new CommandParam(); + param->instance = instance; + param->hContact = pccsd->hContact; + param->hProcess = (HANDLE)messageId; + param->data = (sep ? sep + 1 : NULL); - return 0; + mir_forkthread(commands[i].pHandler, param); + + return messageId; + } } } - mir_snprintf( - help, - SIZEOF(help), - Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), - message); - + char help[1024]; + mir_snprintf(help, SIZEOF(help), Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), message); CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); - return 0; } @@ -223,7 +213,7 @@ INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam) dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = strlen(message); + dbei.cbBlob = (int)strlen(message); dbei.pBlob = (PBYTE)message; db_event_add(pccsd->hContact, &dbei); @@ -233,7 +223,6 @@ INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam) INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; - if (!instance->HasAccessToken()) return 0; diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 760e761ebe..4bc57c097b 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -346,12 +346,11 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg) dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = wcslen(data); + dbei.cbBlob = (int)wcslen(data); dbei.pBlob = (PBYTE)message; db_event_add(ftp->hContact, &dbei); } - else - CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)ftp->hContact, (LPARAM)data); + else CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)ftp->hContact, (LPARAM)data); } else { @@ -360,7 +359,7 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg) dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = wcslen(data); + dbei.cbBlob = (int)wcslen(data); dbei.pBlob = (PBYTE)message; db_event_add(ftp->hContact, &dbei); } diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h index f214ede484..3d887abcd5 100644 --- a/plugins/Dropbox/src/file_transfer.h +++ b/plugins/Dropbox/src/file_transfer.h @@ -1,8 +1,6 @@ #ifndef _FILE_TRANSFER_H_ #define _FILE_TRANSFER_H_ -#include "stdafx.h" - struct FileTransferParam { HANDLE hProcess; @@ -79,7 +77,8 @@ struct FileTransferParam for (; pwszUrls[count]; count++); pwszUrls = (wchar_t**)mir_realloc(pwszUrls, sizeof(wchar_t*) * (count + 2)); } - int length = wcslen(url); + + size_t length = wcslen(url); pwszUrls[count] = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1)); wcscpy(pwszUrls[count], url); pwszUrls[count][length] = '\0'; diff --git a/plugins/Dropbox/src/http_request.h b/plugins/Dropbox/src/http_request.h index 231efbae25..7332975291 100644 --- a/plugins/Dropbox/src/http_request.h +++ b/plugins/Dropbox/src/http_request.h @@ -1,8 +1,6 @@ #ifndef _HTTP_REQUEST_H_ #define _HTTP_REQUEST_H_ -#include "stdafx.h" - enum HTTP_STATUS { HTTP_STATUS_OK = 200, diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h index c34bab3d16..6e736ded62 100644 --- a/plugins/Dropbox/src/stdafx.h +++ b/plugins/Dropbox/src/stdafx.h @@ -3,6 +3,8 @@ #include #include + +#include #include #include @@ -35,8 +37,6 @@ extern HINSTANCE g_hInstance; -class CDropbox; - #include "dropbox.h" #endif //_COMMON_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index b76aff3aed..5f8154e315 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 11 +#define __MINOR_VERSION 12 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 1 #include @@ -11,4 +11,4 @@ #define __AUTHOR "unsane" #define __AUTHOREMAIL "" #define __AUTHORWEB "http://miranda-ng.org/p/Dropbox/" -#define __COPYRIGHT "© 2014 Miranda NG project" +#define __COPYRIGHT "© 2014-15 Miranda NG project" -- cgit v1.2.3