From 5fb7d6a8304db2236f46a6c7b33b0540fee11fd6 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 6 Mar 2014 19:03:12 +0000 Subject: Dropbox: - added first approach of options page - fixed tabsrmm button destruction git-svn-id: http://svn.miranda-ng.org/main/trunk@8430 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/res/resource.rc | Bin 7492 -> 9848 bytes plugins/Dropbox/src/dropbox.cpp | 1 + plugins/Dropbox/src/dropbox.h | 7 +- plugins/Dropbox/src/dropbox_dialogs.cpp | 124 ++++++++++++++++++++++++++---- plugins/Dropbox/src/dropbox_events.cpp | 16 +++- plugins/Dropbox/src/dropbox_transfers.cpp | 10 +++ plugins/Dropbox/src/resource.h | Bin 1370 -> 1818 bytes 7 files changed, 137 insertions(+), 21 deletions(-) (limited to 'plugins') diff --git a/plugins/Dropbox/res/resource.rc b/plugins/Dropbox/res/resource.rc index 52a1d26839..876a41341a 100644 Binary files a/plugins/Dropbox/res/resource.rc and b/plugins/Dropbox/res/resource.rc differ diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 3e5cd0f5d1..b52e80c166 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -12,6 +12,7 @@ void CDropbox::Init() CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd); HookEvent(ME_OPT_INITIALISE, OnOptionsInit); + HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); HookEvent(ME_SYSTEM_MODULESLOADED, CDropbox::OnModulesLoaded); HookEvent(ME_DB_CONTACT_DELETED, CDropbox::OnContactDeleted); HookEvent(ME_CLIST_PREBUILDCONTACTMENU, CDropbox::OnPrebuildContactMenu); diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 1b84aa786b..b10d78edb0 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -57,6 +57,7 @@ private: // hooks static int OnModulesLoaded(WPARAM wParam, LPARAM lParam); + static int OnPreShutdown(WPARAM wParam, LPARAM lParam); static int OnOptionsInit(WPARAM wParam, LPARAM lParam); static int OnContactDeleted(WPARAM wParam, LPARAM lParam); static int OnPrebuildContactMenu(WPARAM wParam, LPARAM); @@ -91,7 +92,7 @@ private: static void RevokeApiAuthorizationAsync(void *arg); // transrers - int HandleFileTransferError(NETLIBHTTPREQUEST *response, MCONTACT hContact); + static int HandleFileTransferError(NETLIBHTTPREQUEST *response, MCONTACT hContact); int SendFileChunkedFirst(const char *data, int length, char *uploadId, int &offset, MCONTACT hContact); int SendFileChunkedNext(const char *data, int length, const char *uploadId, int &offset, MCONTACT hContact); @@ -118,8 +119,8 @@ private: // utils static wchar_t *HttpStatusToText(HTTP_STATUS status); - void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); - void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + static void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + static void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); }; #endif //_DROPBOX_PROTO_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_dialogs.cpp b/plugins/Dropbox/src/dropbox_dialogs.cpp index 6c07e4f0bf..445da14a3f 100644 --- a/plugins/Dropbox/src/dropbox_dialogs.cpp +++ b/plugins/Dropbox/src/dropbox_dialogs.cpp @@ -17,9 +17,9 @@ INT_PTR CALLBACK CDropbox::TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wPara /*wchar_t title[MAX_PATH]; ::mir_sntprintf( - title, - MAX_PATH, - ::TranslateT("Enter a password for %s:"), + title, + MAX_PATH, + ::TranslateT("Enter a password for %s:"), param->login);*/ //::SetDlgItemText(hwndDlg, IDC_INSTRUCTION, title); @@ -32,24 +32,24 @@ INT_PTR CALLBACK CDropbox::TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wPara break; case WM_COMMAND: + { + switch (LOWORD(wParam)) { - switch (LOWORD(wParam)) - { - case IDOK: - { - char data[128]; - GetDlgItemTextA(hwndDlg, IDC_TOKEN, data, SIZEOF(data)); - strcpy(token, data); + case IDOK: + { + char data[128]; + GetDlgItemTextA(hwndDlg, IDC_TOKEN, data, SIZEOF(data)); + strcpy(token, data); - EndDialog(hwndDlg, IDOK); - } - break; + EndDialog(hwndDlg, IDOK); + } + break; - case IDCANCEL: - EndDialog(hwndDlg, IDCANCEL); - break; - } + case IDCANCEL: + EndDialog(hwndDlg, IDCANCEL); + break; } + } break; } @@ -58,5 +58,95 @@ INT_PTR CALLBACK CDropbox::TokenRequestProc(HWND hwndDlg, UINT msg, WPARAM wPara INT_PTR CALLBACK CDropbox::MainOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + switch (msg) + { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + CheckDlgButton(hwndDlg, IDC_USE_SHORT_LINKS, db_get_b(NULL, MODULE, "UseSortLinks", 1)); + } + return TRUE; + + case WM_COMMAND: + if (HIWORD(wParam) == STN_CLICKED) + { + switch (LOWORD(wParam)) + { + case IDC_GETAUTH: + CallService(MS_UTILS_OPENURL, 0, (LPARAM)DROPBOX_WWW_URL DROPBOX_API_VER "/oauth2/authorize?response_type=code&client_id=" DROPBOX_API_KEY); + break; + + case IDC_USE_SHORT_LINKS: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case IDC_AUTHORIZE: + { + char request_token[128]; + GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, request_token, SIZEOF(request_token)); + + char data[1024]; + mir_snprintf( + data, + SIZEOF(data), + "grant_type=authorization_code&code=%s", + request_token); + + HttpRequest *request = new HttpRequest(INSTANCE->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token"); + request->pData = mir_strdup(data); + request->dataLength = (int)strlen(data); + request->AddHeader("Content-Type", "application/x-www-form-urlencoded"); + request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET); + + mir_ptr response(request->Send()); + + delete request; + + MCONTACT hContact = CDropbox::GetDefaultContact(); + + if (response) + { + JSONNODE *root = json_parse(response->pData); + if (root) + { + if (response->resultCode == HTTP_STATUS::OK) + { + JSONNODE *node = json_get(root, "access_token"); + ptrA access_token = ptrA(mir_u2a(json_as_string(node))); + db_set_s(NULL, MODULE, "TokenSecret", access_token); + + if (hContact) + { + if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) + db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); + } + + ShowNotification(TranslateT("You have been authorized"), MB_ICONINFORMATION); + } + else + { + JSONNODE *node = json_get(root, "error_description"); + ptrW error_description(json_as_string(node)); + + ShowNotification((wchar_t*)error_description, MB_ICONERROR); + } + } + } + else + HandleFileTransferError(response, hContact); + + } + } + break; + } + break; + + case WM_NOTIFY: + if (reinterpret_cast(lParam)->code == PSN_APPLY) + { + db_set_b(NULL, MODULE, "UseSortLinks", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USE_SHORT_LINKS)); + } + break; + } return FALSE; } \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 1e5157faa1..0e5472ef0b 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -55,6 +55,20 @@ int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam) return 0; } +int CDropbox::OnPreShutdown(WPARAM wParam, LPARAM lParam) +{ + if (ServiceExists(MS_BB_ADDBUTTON)) + { + BBButton bbd = { sizeof(bbd) }; + bbd.pszModuleName = MODULE; + + bbd.dwButtonID = BBB_ID_FILE_SEND; + CallService(MS_BB_REMOVEBUTTON, 0, (LPARAM)&bbd); + } + + return 0; +} + int CDropbox::OnOptionsInit(WPARAM wParam, LPARAM lParam) { OPTIONSDIALOGPAGE odp = { sizeof(odp) }; @@ -66,7 +80,7 @@ int CDropbox::OnOptionsInit(WPARAM wParam, LPARAM lParam) odp.pszTitle = LPGEN("Dropbox"); odp.pfnDlgProc = MainOptionsProc; - //Options_AddPage(wParam, &odp); + Options_AddPage(wParam, &odp); return 0; } diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 6eb03d8c86..2abdaa588c 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -118,6 +118,11 @@ int CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, MC request = new HttpRequest(hNetlibUser, REQUEST_POST, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); + if (!db_get_b(NULL, MODULE, "UseSortLinks", 1)) + { + request->pData = mir_strdup("short_url=false"); + request->dataLength = strlen(request->pData); + } response = request->Send(); @@ -212,6 +217,11 @@ int CDropbox::CreateFolder(const char *folderName, MCONTACT hContact) request = new HttpRequest(hNetlibUser, REQUEST_POST, url); request->AddBearerAuthHeader(db_get_sa(NULL, MODULE, "TokenSecret")); + if (!db_get_b(NULL, MODULE, "UseSortLinks", 1)) + { + request->pData = mir_strdup("short_url=false"); + request->dataLength = strlen(request->pData); + } mir_free(response); diff --git a/plugins/Dropbox/src/resource.h b/plugins/Dropbox/src/resource.h index 50deccd319..51c6dfb265 100644 Binary files a/plugins/Dropbox/src/resource.h and b/plugins/Dropbox/src/resource.h differ -- cgit v1.2.3