From 3997c1912c9ef57697452f357b02b10b8f5bc6a7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 7 Mar 2014 19:41:15 +0000 Subject: Dropbox: - code cleaning and reorganization - added "/help" command - more informative authorization request - version bumped git-svn-id: http://svn.miranda-ng.org/main/trunk@8456 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox_services.cpp | 108 ++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 39 deletions(-) (limited to 'plugins/Dropbox/src/dropbox_services.cpp') diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index ec556056ff..4a28527423 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -17,18 +17,20 @@ INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM) return 0; } -INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam) +INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM wParam, LPARAM lParam) { - if (!HasAccessToken()) + CDropbox *instance = (CDropbox*)obj; + + if (!instance->HasAccessToken()) return ACKRESULT_FAILED; CCSDATA *pccsd = (CCSDATA*)lParam; - FileTransfer *ftp = new FileTransfer(); + FileTransferParam *ftp = new FileTransferParam(instance); ftp->pfts.flags = PFTS_SENDING | PFTS_UTF; ftp->pfts.hContact = pccsd->hContact; - ftp->hContact = (INSTANCE->hContactTransfer) ? INSTANCE->hContactTransfer : pccsd->hContact; - INSTANCE->hContactTransfer = 0; + ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : pccsd->hContact; + instance->hTransferContact = 0; char **files = (char**)pccsd->lParam; @@ -77,7 +79,7 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam) } } - ULONG fileId = InterlockedIncrement(&INSTANCE->hFileProcess); + ULONG fileId = InterlockedIncrement(&instance->hFileProcess); ftp->hProcess = (HANDLE)fileId; mir_forkthread(CDropbox::SendFileAsync, ftp); @@ -85,50 +87,76 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM wParam, LPARAM lParam) return fileId; } -INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam) +INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam) { + CDropbox *instance = (CDropbox*)obj; + CCSDATA *pccsd = (CCSDATA*)lParam; char *message = (char*)pccsd->lParam; + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.szModule = MODULE; + dbei.timestamp = time(NULL); + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.cbBlob = strlen(message); + dbei.pBlob = (PBYTE)message; + dbei.flags = DBEF_SENT | DBEF_UTF; + db_event_add(pccsd->hContact, &dbei); + + char help[1024]; + if (message[0] && message[0] == '/') { // parse commands char *sep = strchr(message, ' '); int len = strlen(message) - (sep ? strlen(sep) : 0) - 1; - char *cmd = (char*)mir_alloc(len + 1); + ptrA cmd((char*)mir_alloc(len + 1)); strncpy(cmd, message + 1, len); cmd[len] = 0; - if (INSTANCE->commands.find(cmd) != INSTANCE->commands.end()) + if (instance->commands.find((char*)cmd) != instance->commands.end()) { - ULONG messageId = InterlockedIncrement(&INSTANCE->hMessageProcess); + ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); - MessageParam *param = new MessageParam(); + 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[cmd], param); + mir_forkthread(instance->commands[(char*)cmd], param); return messageId; } - //mir_free(cmd); + else + { + mir_snprintf( + help, + SIZEOF(help), + Translate("Unknown command \"%s\".\nUse \"/help\" for more info."), + message); + + CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); + + return 0; + } } - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = MODULE; - dbei.timestamp = time(NULL); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.cbBlob = strlen(message); - dbei.pBlob = (PBYTE)message; - dbei.flags = DBEF_SENT | DBEF_UTF; - db_event_add(pccsd->hContact, &dbei); + 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; } -INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam) +INT_PTR CDropbox::ProtoReceiveMessage(void *obj, WPARAM, LPARAM lParam) { + CDropbox *instance = (CDropbox*)obj; + CCSDATA *pccsd = (CCSDATA*)lParam; char *message = (char*)pccsd->lParam; @@ -144,27 +172,29 @@ INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam) return 0; } -INT_PTR CDropbox::RequestApiAuthorization(WPARAM, LPARAM) +//INT_PTR CDropbox::RequestApiAuthorization(WPARAM, LPARAM) +//{ +// mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0); +// +// return 0; +//} +// +//INT_PTR CDropbox::RevokeApiAuthorization(WPARAM, LPARAM) +//{ +// mir_forkthread(CDropbox::RevokeApiAuthorizationAsync, 0); +// +// return 0; +//} + +INT_PTR CDropbox::SendFilesToDropbox(void *obj, WPARAM hContact, LPARAM) { - mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0); + CDropbox *instance = (CDropbox*)obj; - return 0; -} - -INT_PTR CDropbox::RevokeApiAuthorization(WPARAM, LPARAM) -{ - mir_forkthread(CDropbox::RevokeApiAuthorizationAsync, 0); - - return 0; -} - -INT_PTR CDropbox::SendFilesToDropbox(WPARAM hContact, LPARAM) -{ - INSTANCE->hContactTransfer = hContact; + instance->hTransferContact = hContact; - HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, INSTANCE->GetDefaultContact(), 0); + HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - dcftp[hwnd] = hContact; + instance->dcftp[hwnd] = hContact; return 0; } \ No newline at end of file -- cgit v1.2.3