From 61e1d6d2882b1582498e412dc94ed4b35de2ed77 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 27 Feb 2014 16:56:39 +0000 Subject: Dropbox: - added "Revoke authorization" in contact menu item - added authorization request on first start git-svn-id: http://svn.miranda-ng.org/main/trunk@8302 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox.cpp | 13 +++++++++++++ plugins/Dropbox/src/dropbox.h | 5 ++++- plugins/Dropbox/src/dropbox_events.cpp | 6 ++++++ plugins/Dropbox/src/dropbox_menus.cpp | 23 +++++++++++++++++------ plugins/Dropbox/src/dropbox_services.cpp | 26 ++++++++++---------------- 5 files changed, 50 insertions(+), 23 deletions(-) (limited to 'plugins/Dropbox') diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 2cd459759f..53c8cb0356 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -1,5 +1,8 @@ #include "common.h" +std::map CDropbox::dcftp; +HGENMENU CDropbox::ContactMenuItems[CMI_MAX]; + void CDropbox::Init() { PROTOCOLDESCRIPTOR pd = { PROTOCOLDESCRIPTOR_V3_SIZE }; @@ -132,4 +135,14 @@ void CDropbox::RequestApiAuthorizationAsync(void *arg) } else INSTANCE->RequestAcceessToken(); +} + +void CDropbox::RevokeApiAuthorizationAsync(void *arg) +{ + if (HasAccessToken() && MessageBox( + NULL, + TranslateT("Are you sure you want to revoke athorization?"), + TranslateT("Revoke authorization"), + MB_YESNO | MB_ICONQUESTION) == IDYES) + INSTANCE->DestroyAcceessToken(); } \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 89afb8635d..8ffd4082f8 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -23,7 +23,8 @@ enum { - CMI_API_REQUEST_AUTH, + CMI_AUTH_REQUEST, + CMI_AUTH_REVOKE, CMI_SEND_FILES, CMI_MAX // this item shall be the last one }; @@ -60,6 +61,7 @@ private: static INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam); static INT_PTR RequestApiAuthorization(WPARAM wParam, LPARAM lParam); + static INT_PTR RevokeApiAuthorization(WPARAM wParam, LPARAM lParam); static INT_PTR SendFilesToDropbox(WPARAM wParam, LPARAM lParam); @@ -70,6 +72,7 @@ private: void DestroyAcceessToken(); static void RequestApiAuthorizationAsync(void *arg); + static void RevokeApiAuthorizationAsync(void *arg); // transrers int HandleFileTransferError(NETLIBHTTPREQUEST *response, MCONTACT hContact); diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 4fc7e3613c..1e5157faa1 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -27,6 +27,12 @@ int CDropbox::OnModulesLoaded(WPARAM wParam, LPARAM lParam) { db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE); } + + if (!db_get_b(NULL, "FirstRun", MODULE, 0)) + { + mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0); + db_set_b(NULL, "FirstRun", MODULE, 1); + } } } diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp index d7a1c235ee..0dcac861a8 100644 --- a/plugins/Dropbox/src/dropbox_menus.cpp +++ b/plugins/Dropbox/src/dropbox_menus.cpp @@ -1,7 +1,5 @@ #include "common.h" -HGENMENU CDropbox::ContactMenuItems[CMI_MAX]; - void CDropbox::InitMenus() { CLISTMENUITEM mi = { 0 }; @@ -17,10 +15,17 @@ void CDropbox::InitMenus() mi.pszService = MODULE"/RequestAuthorization"; mi.ptszName = LPGENT("Request authorization"); - mi.position = -2000001000 + CMI_API_REQUEST_AUTH; + mi.position = 1000030000 + CMI_AUTH_REQUEST; mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST); - ContactMenuItems[CMI_API_REQUEST_AUTH] = Menu_AddContactMenuItem(&mi); + ContactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi); CreateServiceFunction(mi.pszService, RequestApiAuthorization); + + mi.pszService = MODULE"/RevokeAuthorization"; + mi.ptszName = LPGENT("Revoke authorization"); + mi.position = 1000030000 + CMI_AUTH_REVOKE; + mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REVOKE); + ContactMenuItems[CMI_AUTH_REVOKE] = Menu_AddContactMenuItem(&mi); + CreateServiceFunction(mi.pszService, RevokeApiAuthorization); } void CDropbox::Menu_DisableItem(HGENMENU hMenuItem, BOOL bDisable) @@ -41,13 +46,19 @@ int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM lParam) Menu_DisableItem(ContactMenuItems[CMI_SEND_FILES], FALSE); + Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], FALSE); + Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], FALSE); Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], FALSE); - Menu_ShowItem(ContactMenuItems[CMI_API_REQUEST_AUTH], FALSE); WORD status = db_get_w(hContact, GetContactProto(hContact), "Status", ID_STATUS_OFFLINE); if (hContact == GetDefaultContact()) - Menu_ShowItem(ContactMenuItems[CMI_API_REQUEST_AUTH], TRUE); + { + if (!HasAccessToken()) + Menu_ShowItem(ContactMenuItems[CMI_AUTH_REQUEST], TRUE); + else + Menu_ShowItem(ContactMenuItems[CMI_AUTH_REVOKE], TRUE); + } else if (status != ID_STATUS_OFFLINE && HasAccessToken()) Menu_ShowItem(ContactMenuItems[CMI_SEND_FILES], TRUE); diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index e18a6e9953..c298974166 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -1,15 +1,13 @@ #include "common.h" -INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM lParam) +INT_PTR CDropbox::ProtoGetCaps(WPARAM wParam, LPARAM) { switch(wParam) { case PFLAGNUM_1: - return PF1_IM | PF1_FILESEND | PF1_AUTHREQ; + return PF1_IM | PF1_FILESEND; case PFLAGNUM_2: return PF2_ONLINE; - case PFLAGNUM_4: - return PF4_FORCEAUTH; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)MODULE " ID"; case PFLAG_UNIQUEIDSETTING: @@ -93,15 +91,6 @@ INT_PTR CDropbox::ProtoSendMessage(WPARAM wParam, LPARAM 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); - //if (message[0] && message[0] == '/') //{ // // parse commands @@ -110,16 +99,21 @@ INT_PTR CDropbox::ProtoSendMessage(WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR CDropbox::RequestApiAuthorization(WPARAM wParam, LPARAM lParam) +INT_PTR CDropbox::RequestApiAuthorization(WPARAM, LPARAM) { mir_forkthread(CDropbox::RequestApiAuthorizationAsync, 0); return 0; } -std::map CDropbox::dcftp; +INT_PTR CDropbox::RevokeApiAuthorization(WPARAM, LPARAM) +{ + mir_forkthread(CDropbox::RevokeApiAuthorizationAsync, 0); + + return 0; +} -INT_PTR CDropbox::SendFilesToDropbox(WPARAM hContact, LPARAM lParam) +INT_PTR CDropbox::SendFilesToDropbox(WPARAM hContact, LPARAM) { INSTANCE->hContactTransfer = hContact; -- cgit v1.2.3