From 999fdaa2662a1fe8937ec110232a78e87d79bfe7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 3 Mar 2016 14:47:53 +0000 Subject: Dropbox: - remove menu item and srmm button for intercepted accounts - removed limitation on single transfer window from menu item and srmm git-svn-id: http://svn.miranda-ng.org/main/trunk@16405 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox.h | 8 ++++---- plugins/Dropbox/src/dropbox_events.cpp | 32 ++----------------------------- plugins/Dropbox/src/dropbox_menus.cpp | 21 ++++++++------------ plugins/Dropbox/src/dropbox_options.cpp | 22 ++++++++++++++++++++- plugins/Dropbox/src/dropbox_services.cpp | 6 +----- plugins/Dropbox/src/dropbox_transfers.cpp | 22 +++++++++++++++++++++ plugins/Dropbox/src/dropbox_utils.cpp | 8 ++++++++ plugins/Dropbox/src/file_transfer.h | 25 +++++++++++------------- 8 files changed, 77 insertions(+), 67 deletions(-) (limited to 'plugins/Dropbox') diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 4ea16c4b67..aa83b795ea 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -33,8 +33,6 @@ private: HANDLE hUploadedEventHook; MCONTACT hDefaultContact; - MCONTACT hTransferContact; - HWND hTransferWindow; HGENMENU contactMenuItems[CMI_MAX]; @@ -49,8 +47,6 @@ private: int OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam); int OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam); int OnTabSrmmButtonPressed(WPARAM wParam, LPARAM lParam); - int OnFileDialogCancelled(WPARAM wParam, LPARAM lParam); - int OnFileDialogSuccessed(WPARAM wParam, LPARAM lParam); // services static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam); @@ -93,6 +89,8 @@ private: void AppendToUploadSession(const char *data, size_t size, const char *sessionId, size_t offset); char* FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path); + void CreateFolder(const char *path); + void CreateDownloadUrl(const char *path, char *url); static UINT UploadToDropbox(void *owner, void *arg); @@ -119,6 +117,8 @@ private: static char* PreparePath(const char *oldPath, char *newPath); static char* PreparePath(const TCHAR *oldPath, char *newPath); + static bool IsAccountIntercepted(const char *module); + static char* HttpStatusToText(HTTP_STATUS status); static void HandleJsonResponseError(NETLIBHTTPREQUEST *response); diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index f8679362c6..02c1d7184f 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -7,8 +7,6 @@ int CDropbox::OnModulesLoaded(WPARAM, LPARAM) HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, GlobalEvent<&CDropbox::OnPrebuildContactMenu>, this); HookEventObj(ME_MSG_WINDOWEVENT, GlobalEvent<&CDropbox::OnSrmmWindowOpened>, this); - HookEventObj(ME_FILEDLG_CANCELED, GlobalEvent<&CDropbox::OnFileDialogCancelled>, this); - HookEventObj(ME_FILEDLG_SUCCEEDED, GlobalEvent<&CDropbox::OnFileDialogSuccessed>, this); NETLIBUSER nlu = { sizeof(nlu) }; nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; @@ -75,7 +73,7 @@ int CDropbox::OnSrmmWindowOpened(WPARAM, LPARAM lParam) bbd.pszModuleName = MODULE; bbd.dwButtonID = BBB_ID_FILE_SEND; bbd.bbbFlags = BBSF_RELEASED; - if (!HasAccessToken() || ev->hContact == GetDefaultContact()) + if (!HasAccessToken() || ev->hContact == GetDefaultContact() || IsAccountIntercepted(proto)) bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; else if (!isProtoOnline || (status == ID_STATUS_OFFLINE && !canSendOffline)) bbd.bbbFlags = BBSF_DISABLED; @@ -90,10 +88,7 @@ int CDropbox::OnTabSrmmButtonPressed(WPARAM, LPARAM lParam) { CustomButtonClickData *cbc = (CustomButtonClickData *)lParam; if (!mir_strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact) { - hTransferContact = cbc->hContact; - hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, GetDefaultContact(), 0); - - DisableSrmmButton(cbc->hContact); + CallService(MS_FILE_SENDFILE, GetDefaultContact(), 0); } return 0; @@ -117,29 +112,6 @@ void __stdcall EnableTabSrmmButtonSync(void *arg) CallService(MS_BB_SETBUTTONSTATE, (UINT_PTR)arg, (LPARAM)&bbd); } -int CDropbox::OnFileDialogCancelled(WPARAM, LPARAM lParam) -{ - HWND hwnd = (HWND)lParam; - if (hTransferWindow == hwnd) { - CallFunctionAsync(EnableTabSrmmButtonSync, (void*)hTransferContact); - hTransferContact = 0; - hTransferWindow = 0; - } - - return 0; -} - -int CDropbox::OnFileDialogSuccessed(WPARAM, LPARAM lParam) -{ - HWND hwnd = (HWND)lParam; - if (hTransferWindow == hwnd) { - CallFunctionAsync(EnableTabSrmmButtonSync, (void*)hTransferContact); - hTransferWindow = 0; - } - - return 0; -} - int CDropbox::OnProtoAck(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA*)lParam; diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp index 7fd0c9a3cb..e99b92abf4 100644 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ b/plugins/Dropbox/src/dropbox_menus.cpp @@ -1,15 +1,13 @@ #include "stdafx.h" -INT_PTR CDropbox::SendFilesToDropboxCommand(void *obj, WPARAM hContact, LPARAM) +INT_PTR CDropbox::SendFilesToDropboxCommand(void *obj, WPARAM, LPARAM) { CDropbox *instance = (CDropbox*)obj; if (!instance->HasAccessToken()) return 1; - instance->hTransferContact = hContact; - instance->hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); + CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0); - DisableSrmmButton(hContact); return 0; } @@ -32,15 +30,12 @@ int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM) char *proto = GetContactProto(hContact); if (proto != NULL) { bool bHasIM = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) != 0; - if (bHasIM && HasAccessToken() && !hTransferContact && hContact != GetDefaultContact()) { - bool isContact = db_get_b(hContact, proto, "ChatRoom", 0) == 0; - if (isContact) { - bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE; - WORD status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); - bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0; - if (isProtoOnline && (status != ID_STATUS_OFFLINE || canSendOffline)) - bShow = true; - } + if (bHasIM && HasAccessToken() && hContact != GetDefaultContact() && !IsAccountIntercepted(proto)) { + bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE; + WORD status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); + bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0; + if (isProtoOnline && (status != ID_STATUS_OFFLINE || canSendOffline)) + bShow = true; } } diff --git a/plugins/Dropbox/src/dropbox_options.cpp b/plugins/Dropbox/src/dropbox_options.cpp index 417f5cf21b..32b4daf949 100644 --- a/plugins/Dropbox/src/dropbox_options.cpp +++ b/plugins/Dropbox/src/dropbox_options.cpp @@ -120,8 +120,28 @@ void CDropboxOptionsInterception::OnApply() PROTOACCOUNT *acc = (PROTOACCOUNT*)m_accounts.GetItemData(iItem); if (m_accounts.GetCheckState(iItem)) interceptedProtos.AppendFormat("%s\t", acc->szModuleName); - interceptedProtos.TrimRight(); + + // hide tabsrmm button for intercepted accounts + MessageWindowInputData msgwi = { sizeof(msgwi) }; + msgwi.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH; + + for (MCONTACT hContact = db_find_first(acc->szModuleName); hContact; hContact = db_find_next(hContact, acc->szModuleName)) { + msgwi.hContact = hContact; + + MessageWindowData msgw; + msgw.cbSize = sizeof(msgw); + + if (!CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&msgwi, (LPARAM)&msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) { + BBButton bbd = { sizeof(bbd) }; + bbd.pszModuleName = MODULE; + bbd.dwButtonID = BBB_ID_FILE_SEND; + bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED; + + CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd); + } + } } + interceptedProtos.TrimRight(); db_set_s(NULL, MODULE, "InterceptedAccounts", interceptedProtos); db_unset(NULL, MODULE, "InterceptedProtos"); } diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index 44a0cd5113..853db24e00 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -44,7 +44,6 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam) } FileTransferParam *ftp = new FileTransferParam(pccsd->hContact); - hTransferContact = 0; const TCHAR *description = (TCHAR*)pccsd->wParam; if (description && description[0]) @@ -70,10 +69,7 @@ INT_PTR CDropbox::ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam) CCSDATA *pccsd = (CCSDATA*)lParam; const char *proto = GetContactProto(pccsd->hContact); - const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts"); - if (interceptedAccounts == NULL) - interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos"); - if (interceptedAccounts == NULL || strstr(interceptedAccounts, proto) == NULL) + if (!IsAccountIntercepted(proto)) return CALLSERVICE_NOTFOUND; return ProtoSendFile(wParam, lParam); diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 6473a0bcc6..801f2e344e 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -60,6 +60,19 @@ char* CDropbox::FinishUploadSession(const char *data, size_t size, const char *s return path; } +void CDropbox::CreateFolder(const char *path) +{ + ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); + CreateFolderRequest request(token, path); + NLHR_PTR response(request.Send(hNetlibConnection)); + + // forder exists on server + if (response->resultCode == HTTP_STATUS_FORBIDDEN) + return; + + HandleJsonResponseError(response); +} + void CDropbox::CreateDownloadUrl(const char *path, char *url) { ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); @@ -83,6 +96,15 @@ UINT CDropbox::UploadToDropbox(void *owner, void *arg) FileTransferParam *ftp = (FileTransferParam*)arg; try { + const TCHAR *folderName = ftp->GetFolderName(); + if (folderName) { + char path[MAX_PATH], url[MAX_PATH]; + PreparePath(folderName, path); + instance->CreateFolder(path); + instance->CreateDownloadUrl(path, url); + ftp->AppendFormatData(_T("%s\r\n"), ptrT(mir_utf8decodeT(url))); + } + ftp->FirstFile(); do { diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp index ee6fc73a60..b007d88245 100644 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ b/plugins/Dropbox/src/dropbox_utils.cpp @@ -21,6 +21,14 @@ char* CDropbox::PreparePath(const TCHAR *oldPath, char *newPath) return PreparePath(ptrA(mir_utf8encodeW(oldPath)), newPath); } +bool CDropbox::IsAccountIntercepted(const char *module) +{ + const char *interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedAccounts"); + if (interceptedAccounts == NULL) + interceptedAccounts = db_get_sa(NULL, MODULE, "InterceptedProtos"); + return interceptedAccounts && strstr(interceptedAccounts, module); +} + char* CDropbox::HttpStatusToText(HTTP_STATUS status) { switch (status) { diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h index 8e8a8af8c2..fed277289c 100644 --- a/plugins/Dropbox/src/file_transfer.h +++ b/plugins/Dropbox/src/file_transfer.h @@ -12,7 +12,7 @@ private: bool isTerminated; - const TCHAR* directoryName; + const TCHAR* folderName; int relativePathStart; CMString serverPath; @@ -27,7 +27,7 @@ public: isTerminated = false; - directoryName = NULL; + folderName = NULL; relativePathStart = 0; pfts.cbSize = sizeof(this->pfts); @@ -90,18 +90,10 @@ public: void SetWorkingDirectory(const TCHAR *path) { relativePathStart = _tcsrchr(path, '\\') - path + 1; - /*if (PathIsDirectory(path)) - { - size_t length = mir_tstrlen(path) + 1; - pfts.tszWorkingDir = (TCHAR*)mir_calloc(sizeof(TCHAR) * length); - mir_tstrncpy(pfts.tszWorkingDir, path, length); - directoryName = _tcsrchr(pfts.tszWorkingDir, '\\') + 1; - } - else - {*/ - pfts.tszWorkingDir = (TCHAR*)mir_calloc(sizeof(TCHAR) * relativePathStart); - mir_tstrncpy(pfts.tszWorkingDir, path, relativePathStart); - //} + pfts.tszWorkingDir = (TCHAR*)mir_calloc(sizeof(TCHAR) * relativePathStart); + mir_tstrncpy(pfts.tszWorkingDir, path, relativePathStart); + if (PathIsDirectory(path)) + folderName = _tcsrchr(path, '\\') + 1; } void SetServerPath(const TCHAR *path) @@ -117,6 +109,11 @@ public: return serverPath; } + const TCHAR* GetFolderName() const + { + return folderName; + } + void AddFile(const TCHAR *path) { pfts.ptszFiles = (TCHAR**)mir_realloc(pfts.ptszFiles, sizeof(TCHAR*) * (pfts.totalFiles + 2)); -- cgit v1.2.3