From 987ceba57a977c691977a0f5aa8005678fcbc7e7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 26 Feb 2016 11:29:17 +0000 Subject: Dropbox: - added ability to intercept transfers from other protocols - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@16344 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox.cpp | 18 ++++--- plugins/Dropbox/src/dropbox.h | 2 + plugins/Dropbox/src/dropbox_options.cpp | 85 ++++++++++++++++++++++++++++++-- plugins/Dropbox/src/dropbox_options.h | 21 +++++++- plugins/Dropbox/src/dropbox_services.cpp | 12 +++++ plugins/Dropbox/src/resource.h | 7 ++- plugins/Dropbox/src/version.h | 2 +- 7 files changed, 133 insertions(+), 14 deletions(-) (limited to 'plugins/Dropbox/src') diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp index 46d8d5fa8c..d9a47c1e04 100644 --- a/plugins/Dropbox/src/dropbox.cpp +++ b/plugins/Dropbox/src/dropbox.cpp @@ -2,12 +2,6 @@ CDropbox::CDropbox() : transfers(1, HandleKeySortT) { - PROTOCOLDESCRIPTOR pd = { 0 }; - pd.cbSize = sizeof(pd); - pd.szName = MODULE; - pd.type = PROTOTYPE_VIRTUAL; - Proto_RegisterModule(&pd); - HookEvent(ME_PROTO_ACK, OnProtoAck); HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); HookEventObj(ME_SYSTEM_MODULESLOADED, GlobalEvent<&CDropbox::OnModulesLoaded>, this); @@ -16,6 +10,12 @@ CDropbox::CDropbox() : transfers(1, HandleKeySortT) CreateServiceFunctionObj(MS_DROPBOX_SEND_FILE, GlobalService<&CDropbox::SendFileToDropbox>, this); + PROTOCOLDESCRIPTOR pd = { 0 }; + pd.cbSize = sizeof(pd); + pd.szName = MODULE; + pd.type = PROTOTYPE_VIRTUAL; + Proto_RegisterModule(&pd); + CreateProtoServiceFunction(MODULE, PS_GETCAPS, ProtoGetCaps); CreateProtoServiceFunction(MODULE, PS_GETNAME, ProtoGetName); CreateProtoServiceFunction(MODULE, PS_LOADICON, ProtoLoadIcon); @@ -25,6 +25,12 @@ CDropbox::CDropbox() : transfers(1, HandleKeySortT) CreateProtoServiceFunctionObj(PSS_MESSAGE, GlobalService<&CDropbox::ProtoSendMessage>, this); CreateProtoServiceFunction(MODULE, PSR_MESSAGE, ProtoReceiveMessage); + pd.szName = MODULE"Inteceptor"; + pd.type = PROTOTYPE_FILTER; + Proto_RegisterModule(&pd); + + CreateServiceFunctionObj(MODULE"Inteceptor"PSS_FILE, GlobalService<&CDropbox::ProtoSendFileInterceptor>, this); + InitializeMenus(); hFileProcess = hMessageProcess = 1; diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 5ad332b168..dba4681042 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -64,6 +64,8 @@ private: INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam); static INT_PTR ProtoReceiveMessage(WPARAM wParam, LPARAM lParam); + INT_PTR ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam); + INT_PTR SendFileToDropbox(WPARAM wParam, LPARAM lParam); // commands diff --git a/plugins/Dropbox/src/dropbox_options.cpp b/plugins/Dropbox/src/dropbox_options.cpp index 2ae67aecb6..047e59b006 100644 --- a/plugins/Dropbox/src/dropbox_options.cpp +++ b/plugins/Dropbox/src/dropbox_options.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -CDropboxOptionsMain::CDropboxOptionsMain(CDropbox *instance, int idDialog) - : CDropboxDlgBase(instance, idDialog), +CDropboxOptionsMain::CDropboxOptionsMain(CDropbox *instance) + : CDropboxDlgBase(instance, IDD_OPTIONS_MAIN), m_auth(this, IDC_GETAUTH, DROPBOX_WWW_URL "/oauth2/authorize?response_type=code&client_id=" DROPBOX_APP_KEY), m_requestCode(this, IDC_REQUEST_CODE), m_authorize(this, IDC_AUTHORIZE), m_authStatus(this, IDC_AUTH_STATUS), m_useShortUrl(this, IDC_USE_SHORT_LINKS), m_urlAutoSend(this, IDC_URL_AUTOSEND), @@ -51,6 +51,81 @@ void CDropboxOptionsMain::Authorize_OnClick(CCtrlBase*) ///////////////////////////////////////////////////////////////////////////////// +CDropboxOptionsInterception::CDropboxOptionsInterception(CDropbox *instance) + : CDropboxDlgBase(instance, IDD_OPTIONS_INTERCEPTION), + m_accounts(this, IDC_ACCOUNTS), isAccountListInit(false) +{ +} + +void CDropboxOptionsInterception::OnInitDialog() +{ + CDropboxDlgBase::OnInitDialog(); + + m_accounts.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_INFOTIP); + + m_accounts.AddColumn(0, _T("Account name"), 50); + m_accounts.AddColumn(1, _T("Protocol"), 50); + + int count; + PROTOACCOUNT** accounts; + Proto_EnumAccounts(&count, &accounts); + const char* interceptedProtos = db_get_sa(NULL, MODULE, "InterceptedProtos"); + for (int i = 0; i < count; i++) { + PROTOACCOUNT *acc = accounts[i]; + if (strstr(acc->szProtoName, MODULE) || strstr(acc->szProtoName, "Meta")) + continue; + int iItem = m_accounts.AddItem(mir_tstrdup(acc->tszAccountName), -1, (LPARAM)acc); + m_accounts.SetItem(iItem, 1, mir_a2t(acc->szProtoName)); + if (interceptedProtos && strstr(interceptedProtos, acc->szModuleName)) + m_accounts.SetCheckState(iItem, TRUE); + } + + m_accounts.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); + m_accounts.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER); + + isAccountListInit = true; +} + +INT_PTR CDropboxOptionsInterception::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_NOTIFY: + { + LPNMHDR lpnmHdr = (LPNMHDR)lParam; + if (lpnmHdr->idFrom == (UINT_PTR)m_accounts.GetCtrlId() && lpnmHdr->code == LVN_ITEMCHANGED) + { + LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam; + if (pnmv->uChanged & LVIF_STATE && pnmv->uNewState & LVIS_STATEIMAGEMASK) + { + if (isAccountListInit) + NotifyChange(); + } + } + } + break; + } + + return CDlgBase::DlgProc(msg, wParam, lParam); +} + +void CDropboxOptionsInterception::OnApply() +{ + CMStringA interceptedProtos; + int count = m_accounts.GetItemCount(); + for (int iItem = 0; iItem < count; iItem++) + { + TCHAR proto[MAX_PATH]; + PROTOACCOUNT *acc = (PROTOACCOUNT*)m_accounts.GetItemData(iItem); + if (m_accounts.GetCheckState(iItem)) + interceptedProtos.AppendFormat("%s\t", acc->szModuleName); + interceptedProtos.TrimRight(); + } + db_set_s(NULL, MODULE, "InterceptedProtos", interceptedProtos); +} + +///////////////////////////////////////////////////////////////////////////////// + int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; @@ -58,9 +133,13 @@ int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM) odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; odp.ptszGroup = LPGENT("Network"); - odp.ptszTab = _T("Dropbox"); + odp.ptszTab = _T("General"); odp.pDialog = CDropboxOptionsMain::CreateOptionsPage(this); Options_AddPage(wParam, &odp); + odp.ptszTab = _T("Interception"); + odp.pDialog = CDropboxOptionsInterception::CreateOptionsPage(this); + Options_AddPage(wParam, &odp); + return 0; } diff --git a/plugins/Dropbox/src/dropbox_options.h b/plugins/Dropbox/src/dropbox_options.h index d216a5b546..7c68ece9d5 100644 --- a/plugins/Dropbox/src/dropbox_options.h +++ b/plugins/Dropbox/src/dropbox_options.h @@ -22,9 +22,26 @@ protected: void Authorize_OnClick(CCtrlBase*); public: - CDropboxOptionsMain(CDropbox *instance, int idDialog); + CDropboxOptionsMain(CDropbox *instance); - static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsMain((CDropbox*)param, IDD_OPTIONS_MAIN); } + static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsMain((CDropbox*)param); } +}; + +class CDropboxOptionsInterception : public CDropboxDlgBase +{ +private: + bool isAccountListInit; + CCtrlListView m_accounts; + +protected: + void OnInitDialog(); + INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam); + void OnApply(); + +public: + CDropboxOptionsInterception(CDropbox *instance); + + static CDlgBase *CreateOptionsPage(void *param) { return new CDropboxOptionsInterception((CDropbox*)param); } }; #endif //_DROPBOX_OPTIONS_H_ \ No newline at end of file diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index d679059c43..92f7a5abae 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -74,6 +74,18 @@ INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam) return fileId; } +INT_PTR CDropbox::ProtoSendFileInterceptor(WPARAM wParam, LPARAM lParam) +{ + CCSDATA *pccsd = (CCSDATA*)lParam; + + const char *proto = GetContactProto(pccsd->hContact); + const char *interceptedProtos = db_get_sa(NULL, MODULE, "InterceptedProtos"); + if (interceptedProtos == NULL || strstr(interceptedProtos, proto) == NULL) + return CALLSERVICE_NOTFOUND; + + return ProtoSendFile(wParam, lParam); +} + INT_PTR CDropbox::ProtoCancelFile(WPARAM, LPARAM lParam) { CCSDATA *pccsd = (CCSDATA*)lParam; diff --git a/plugins/Dropbox/src/resource.h b/plugins/Dropbox/src/resource.h index 314d82c2b3..a01728b502 100644 --- a/plugins/Dropbox/src/resource.h +++ b/plugins/Dropbox/src/resource.h @@ -1,10 +1,11 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by e:\Projects\C++\MirandaNG\plugins\Dropbox\res\resource.rc +// Used by d:\Projects\MirandaNG\plugins\Dropbox\res\resource.rc // #define IDI_DROPBOX 102 #define IDI_UPLOAD 103 #define IDD_OPTIONS_MAIN 109 +#define IDD_OPTIONS_INTERCEPTION 110 #define IDC_REQUEST_CODE 1001 #define IDC_AUTHORIZE 1002 #define IDC_CHECK2 1004 @@ -14,6 +15,8 @@ #define IDC_GET_AUTH_LINK 1006 #define IDC_URL_COPYTOCB 1009 #define IDC_CHECK1 1010 +#define IDC_PROTOCOLS 1011 +#define IDC_ACCOUNTS 1011 #define IDC_URL_COPYTOML 1029 #define IDC_URL_COPYTOMIA 1029 #define IDC_URL_AUTOSEND 1030 @@ -25,7 +28,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1011 +#define _APS_NEXT_CONTROL_VALUE 1013 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index d629b60900..a54c801dad 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 12 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3