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 /plugins/CloudFile/src | |
parent | abf1919b649645aa20ce95903d7a42a1c81a2e45 (diff) |
Implement service that returns the list of available CloudFile services (#1144)
Diffstat (limited to 'plugins/CloudFile/src')
-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 |
8 files changed, 92 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; |