diff options
author | aunsane <aunsane@gmail.com> | 2018-02-21 00:05:54 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-02-21 00:05:54 +0300 |
commit | b1b10b4095c4e569cfeed632c2cfa08be766a01b (patch) | |
tree | 490d3f14e2a113257035393aecda6dda01e25ecc | |
parent | abf1919b649645aa20ce95903d7a42a1c81a2e45 (diff) |
Implement service that returns the list of available CloudFile services (#1144)
-rw-r--r-- | plugins/CloudFile/src/cloud_file.cpp | 39 | ||||
-rw-r--r-- | plugins/CloudFile/src/events.cpp | 6 | ||||
-rw-r--r-- | plugins/CloudFile/src/menus.cpp | 10 | ||||
-rw-r--r-- | plugins/CloudFile/src/options.cpp | 5 | ||||
-rw-r--r-- | plugins/CloudFile/src/services.cpp | 82 | ||||
-rw-r--r-- | plugins/CloudFile/src/srmm.cpp | 12 | ||||
-rw-r--r-- | plugins/CloudFile/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/CloudFile/src/transfers.cpp | 3 | ||||
-rw-r--r-- | plugins/ExternalAPI/m_cloudfile.h | 27 | ||||
-rw-r--r-- | src/mir_app/src/proto_utils.cpp | 2 |
10 files changed, 121 insertions, 66 deletions
diff --git a/plugins/CloudFile/src/cloud_file.cpp b/plugins/CloudFile/src/cloud_file.cpp index ce1392f9d3..7e3652122d 100644 --- a/plugins/CloudFile/src/cloud_file.cpp +++ b/plugins/CloudFile/src/cloud_file.cpp @@ -1,44 +1,5 @@ #include "stdafx.h" -static int CompareServices(const CCloudService *p1, const CCloudService *p2) -{ - return mir_strcmp(p1->GetAccountName(), p2->GetAccountName()); -} - -LIST<CCloudService> Services(10, CompareServices); - -void InitServices() -{ - PROTOCOLDESCRIPTOR pd = { sizeof(pd) }; - pd.type = PROTOTYPE_PROTOCOL; - - pd.szName = MODULE "/Dropbox"; - pd.fnInit = (pfnInitProto)CDropboxService::Init; - pd.fnUninit = (pfnUninitProto)CDropboxService::UnInit; - Proto_RegisterModule(&pd); - - pd.szName = MODULE "/GDrive"; - pd.fnInit = (pfnInitProto)CGDriveService::Init; - pd.fnUninit = (pfnUninitProto)CGDriveService::UnInit; - Proto_RegisterModule(&pd); - - pd.szName = MODULE "/OneDrivre"; - pd.fnInit = (pfnInitProto)COneDriveService::Init; - pd.fnUninit = (pfnUninitProto)COneDriveService::UnInit; - Proto_RegisterModule(&pd); - - pd.szName = MODULE "/YandexDisk"; - pd.fnInit = (pfnInitProto)CYandexService::Init; - pd.fnUninit = (pfnUninitProto)CYandexService::UnInit; - Proto_RegisterModule(&pd); - - pd.szName = MODULE; - pd.type = PROTOTYPE_FILTER; - Proto_RegisterModule(&pd); - - CreateServiceFunction(MODULE PSS_FILE, &CCloudService::SendFileInterceptor); -} - CCloudService::CCloudService(const char *protoName, const wchar_t *userName) : PROTO<CCloudService>(protoName, userName) { diff --git a/plugins/CloudFile/src/events.cpp b/plugins/CloudFile/src/events.cpp index df2e06ef4f..c38f89058c 100644 --- a/plugins/CloudFile/src/events.cpp +++ b/plugins/CloudFile/src/events.cpp @@ -9,12 +9,8 @@ int OnModulesLoaded(WPARAM, LPARAM) HookEvent(ME_OPT_INITIALISE, OnOptionsInitialized); // srfile - size_t count = Services.getCount(); - for (size_t i = 0; i < count; i++) { - CCloudService *service = Services[i]; - + for (auto &service : Services) HookEventObj(ME_FILEDLG_CANCELED, OnFileDialogCanceled, service); - } HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu); diff --git a/plugins/CloudFile/src/menus.cpp b/plugins/CloudFile/src/menus.cpp index d405d68f8b..900e47e636 100644 --- a/plugins/CloudFile/src/menus.cpp +++ b/plugins/CloudFile/src/menus.cpp @@ -5,9 +5,7 @@ HGENMENU hContactMenu; INT_PTR UploadMenuCommand(void *obj, WPARAM hContact, LPARAM) { CCloudService *service = (CCloudService*)obj; - service->OpenUploadDialog(hContact); - return 0; } @@ -39,18 +37,14 @@ void InitializeMenus() mi.root = hContactMenu; - size_t count = Services.getCount(); - - for (size_t i = 0; i < count; i++) { + for (int i = 0; i < Services.getCount(); i++) { CCloudService *service = Services[i]; - CMStringA serviceName(FORMAT, "/%s/Upload", service->GetAccountName()); mi.pszService = serviceName.GetBuffer(); - mi.flags = CMIF_SYSTEM | CMIF_UNICODE; mi.name.w = (wchar_t*)service->GetUserName(); mi.position = i; - mi.hIcolibItem = GetIconHandle(Services[i]->GetIconId()); + mi.hIcolibItem = GetIconHandle(service->GetIconId()); Menu_AddContactMenuItem(&mi); CreateServiceFunctionObj(mi.pszService, UploadMenuCommand, service); } diff --git a/plugins/CloudFile/src/options.cpp b/plugins/CloudFile/src/options.cpp index e4c8370691..3c7850ee22 100644 --- a/plugins/CloudFile/src/options.cpp +++ b/plugins/CloudFile/src/options.cpp @@ -25,10 +25,7 @@ void COptionsMain::OnInitDialog() int iItem = m_defaultService.AddString(TranslateT("None")); m_defaultService.SetCurSel(iItem); - size_t count = Services.getCount(); - for (size_t i = 0; i < count; i++) { - CCloudService *service = Services[i]; - + for (auto &service : Services) { iItem = m_defaultService.AddString(mir_wstrdup(service->GetUserName()), (LPARAM)service); if (!mir_strcmpi(service->GetAccountName(), defaultService)) m_defaultService.SetCurSel(iItem); diff --git a/plugins/CloudFile/src/services.cpp b/plugins/CloudFile/src/services.cpp new file mode 100644 index 0000000000..d95b2aee94 --- /dev/null +++ b/plugins/CloudFile/src/services.cpp @@ -0,0 +1,82 @@ +#include "stdafx.h" + +static int CompareServices(const CCloudService *p1, const CCloudService *p2) +{ + return mir_strcmp(p1->GetAccountName(), p2->GetAccountName()); +} + +LIST<CCloudService> Services(10, CompareServices); + +static INT_PTR GetServiceCount(WPARAM, LPARAM) +{ + return Services.getCount(); +} + +static INT_PTR GetService(WPARAM wParam, LPARAM lParam) +{ + ptrA accountName(mir_strdup((char*)wParam)); + if (!accountName || !mir_strlen(accountName)) + accountName = db_get_sa(NULL, MODULE, "DefaultService"); + if (accountName == nullptr) + return 1; + CCloudServiceSearch search(accountName); + CCloudService *service = Services.find(&search); + if (service == nullptr) + return 2; + CFSERVICEINFO *info = (CFSERVICEINFO*)lParam; + if (info != nullptr) { + info->AccountName = service->GetAccountName(); + info->UserName = service->GetUserName(); + } + return 0; +} + +static INT_PTR EnumServices(WPARAM wParam, LPARAM lParam) +{ + CFSERVICEINFO info = {}; + enumCFServiceFunc enumFunc = (enumCFServiceFunc)wParam; + void *param = (void*)lParam; + for (auto &service : Services) { + info.AccountName = service->GetAccountName(); + info.UserName = service->GetUserName(); + int res = enumFunc(&info, param); + if (res != 0) + return res; + } + return 0; +} + +void InitServices() +{ + PROTOCOLDESCRIPTOR pd = { sizeof(pd) }; + pd.type = PROTOTYPE_PROTOCOL; + + pd.szName = MODULE "/Dropbox"; + pd.fnInit = (pfnInitProto)CDropboxService::Init; + pd.fnUninit = (pfnUninitProto)CDropboxService::UnInit; + Proto_RegisterModule(&pd); + + pd.szName = MODULE "/GDrive"; + pd.fnInit = (pfnInitProto)CGDriveService::Init; + pd.fnUninit = (pfnUninitProto)CGDriveService::UnInit; + Proto_RegisterModule(&pd); + + pd.szName = MODULE "/OneDrivre"; + pd.fnInit = (pfnInitProto)COneDriveService::Init; + pd.fnUninit = (pfnUninitProto)COneDriveService::UnInit; + Proto_RegisterModule(&pd); + + pd.szName = MODULE "/YandexDisk"; + pd.fnInit = (pfnInitProto)CYandexService::Init; + pd.fnUninit = (pfnUninitProto)CYandexService::UnInit; + Proto_RegisterModule(&pd); + + pd.szName = MODULE; + pd.type = PROTOTYPE_FILTER; + Proto_RegisterModule(&pd); + + CreateServiceFunction(MODULE PSS_FILE, &CCloudService::SendFileInterceptor); + + CreateServiceFunction(MS_CLOUDFILE_GETSERVICE, GetService); + CreateServiceFunction(MS_CLOUDFILE_ENUMSERVICES, EnumServices); +}
\ No newline at end of file diff --git a/plugins/CloudFile/src/srmm.cpp b/plugins/CloudFile/src/srmm.cpp index 1d7742f3fc..68c2cca0cb 100644 --- a/plugins/CloudFile/src/srmm.cpp +++ b/plugins/CloudFile/src/srmm.cpp @@ -54,20 +54,16 @@ int OnSrmmButtonPressed(WPARAM, LPARAM lParam) } HMENU hMenu = CreatePopupMenu(); - - size_t count = Services.getCount(); - for (size_t i = 0; i < count; i++) { + for (int i = 0; i < Services.getCount(); i++) { CCloudService *service = Services[i]; - - InsertMenu(hMenu, i, MF_STRING | MF_BYPOSITION, i + 1,TranslateW(service->GetUserName())); - //HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(service->GetIconId()), IMAGE_ICON, 16, 16, 0); - //SetMenuItemBitmaps(hMenu, i, MF_BITMAP, hBitmap, hBitmap); + AppendMenu(hMenu, MF_STRING, i + 1, TranslateW(service->GetUserName())); } int pos = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbc->pt.x, cbc->pt.y, 0, cbc->hwndFrom, nullptr); + DestroyMenu(hMenu); + if (pos > 0) { CCloudService *service = Services[pos - 1]; - service->OpenUploadDialog(cbc->hContact); } diff --git a/plugins/CloudFile/src/stdafx.h b/plugins/CloudFile/src/stdafx.h index dd5d93f088..1e36ae0c91 100644 --- a/plugins/CloudFile/src/stdafx.h +++ b/plugins/CloudFile/src/stdafx.h @@ -33,6 +33,7 @@ #include <m_protoint.h> #include <m_protosvc.h> +#include <m_cloudfile.h> #include <m_dropbox.h> #include "version.h" diff --git a/plugins/CloudFile/src/transfers.cpp b/plugins/CloudFile/src/transfers.cpp index 376c5c5f74..7ffcc4e7ef 100644 --- a/plugins/CloudFile/src/transfers.cpp +++ b/plugins/CloudFile/src/transfers.cpp @@ -5,8 +5,7 @@ LIST<FileTransferParam> Transfers(1, HandleKeySortT); INT_PTR CCloudService::SendFileInterceptor(WPARAM, LPARAM lParam) { CCSDATA *pccsd = (CCSDATA*)lParam; - for (int i = 0; i < Services.getCount(); i++) { - CCloudService *service = Services[i]; + for (auto &service : Services) { auto it = service->InterceptedContacts.find(pccsd->hContact); if (it == service->InterceptedContacts.end()) return CALLSERVICE_NOTFOUND; diff --git a/plugins/ExternalAPI/m_cloudfile.h b/plugins/ExternalAPI/m_cloudfile.h new file mode 100644 index 0000000000..8824227e3a --- /dev/null +++ b/plugins/ExternalAPI/m_cloudfile.h @@ -0,0 +1,27 @@ +#ifndef M_CLOUDFILE_H_ +#define M_CLOUDFILE_H_ + +#define MIID_DROPBOX {0x9649d8e2, 0x7326, 0x4ec1, {0xb4, 0xa3, 0xf2, 0xec, 0x1a, 0x39, 0x84, 0x94}} + +struct CFSERVICEINFO +{ + const char *AccountName; + const wchar_t *UserName; +}; + +// get cloud file service info by account name +// wParam = (WPARAM)(const char*)accountName +// lParam = (LPARAM)(CFSERVICEINFO*)serviceInfo +// returns 0 on success, nonzero on failure +#define MS_CLOUDFILE_GETSERVICE "CloudFile/GetService" + +// return nonzero to stop enum +typedef int(*enumCFServiceFunc)(const CFSERVICEINFO *serviceInfo, void *param); + +// get list of cloud file services +// wParam = (WPARAM)(void*)param +// lParam = (LPARAM)(enumCFServiceFunc)enumFunc +// returns 0 on success, nonzero on failure +#define MS_CLOUDFILE_ENUMSERVICES "CloudFile/EnumServices" + +#endif //M_CLOUDFILE_H_
\ No newline at end of file diff --git a/src/mir_app/src/proto_utils.cpp b/src/mir_app/src/proto_utils.cpp index 41c97b9a79..586b9f330d 100644 --- a/src/mir_app/src/proto_utils.cpp +++ b/src/mir_app/src/proto_utils.cpp @@ -159,6 +159,8 @@ PROTO_INTERFACE::PROTO_INTERFACE(const char *pszModuleName, const wchar_t *ptszU m_hmiReqAuth = hReqAuth;
m_hmiGrantAuth = hGrantAuth;
m_hmiRevokeAuth = hRevokeAuth;
+
+ m_hWindowList = nullptr;
}
PROTO_INTERFACE::~PROTO_INTERFACE()
|