summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CloudFile/CloudFile.vcxproj.filters28
-rw-r--r--plugins/CloudFile/res/resource.rc8
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp49
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.h9
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp55
-rw-r--r--plugins/CloudFile/src/Services/google_service.h9
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp59
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h9
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp55
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.h9
-rw-r--r--plugins/CloudFile/src/cloud_file.cpp (renamed from plugins/CloudFile/src/cloud_service.cpp)102
-rw-r--r--plugins/CloudFile/src/cloud_file.h (renamed from plugins/CloudFile/src/cloud_service.h)35
-rw-r--r--plugins/CloudFile/src/events.cpp4
-rw-r--r--plugins/CloudFile/src/icons.cpp3
-rw-r--r--plugins/CloudFile/src/main.cpp9
-rw-r--r--plugins/CloudFile/src/menus.cpp5
-rw-r--r--plugins/CloudFile/src/oauth.cpp40
-rw-r--r--plugins/CloudFile/src/oauth.h6
-rw-r--r--plugins/CloudFile/src/options.cpp29
-rw-r--r--plugins/CloudFile/src/resource.h7
-rw-r--r--plugins/CloudFile/src/srmm.cpp2
-rw-r--r--plugins/CloudFile/src/stdafx.h9
-rw-r--r--plugins/CloudFile/src/transfers.cpp71
23 files changed, 372 insertions, 240 deletions
diff --git a/plugins/CloudFile/CloudFile.vcxproj.filters b/plugins/CloudFile/CloudFile.vcxproj.filters
index 8f90aeb3d5..c26cb717b8 100644
--- a/plugins/CloudFile/CloudFile.vcxproj.filters
+++ b/plugins/CloudFile/CloudFile.vcxproj.filters
@@ -1,4 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Header Files\Services">
+ <UniqueIdentifier>{64D2CE87-E04F-4768-BD94-86282BBD138B}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Source Files\Services">
+ <UniqueIdentifier>{1D61FE06-83AA-4C8A-A8FC-36EAD0EAAC97}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="src\*.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Services\*.h">
+ <Filter>Header Files\Services</Filter>
+ </ClInclude>
+ <ClCompile Include="src\*.cpp;src\*.cxx">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\Services\*.cpp">
+ <Filter>Source Files\Services</Filter>
+ </ClCompile>
+ <ResourceCompile Include="res\*.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ <None Include="res\*.ico;res\*.bmp;res\*.cur">
+ <Filter>Resource Files</Filter>
+ </None>
+ </ItemGroup>
<Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
</Project>
diff --git a/plugins/CloudFile/res/resource.rc b/plugins/CloudFile/res/resource.rc
index e08283ccb2..53021dfa69 100644
--- a/plugins/CloudFile/res/resource.rc
+++ b/plugins/CloudFile/res/resource.rc
@@ -105,12 +105,12 @@ EXSTYLE WS_EX_TOPMOST
CAPTION "Authorization"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- EDITTEXT IDC_OAUTH_CODE,7,41,179,14,ES_AUTOHSCROLL
+ EDITTEXT IDC_OAUTH_CODE,7,43,179,14,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,75,62,50,14
PUSHBUTTON "Cancel",IDCANCEL,136,62,50,14
- LTEXT "Enter authorization code:",IDC_STATIC,7,31,179,8
- LTEXT "Allow access to team",IDC_STATIC,7,7,68,8
- CONTROL "Go to this link",IDC_OAUTH_AUTHORIZE,"Hyperlink",WS_GROUP | WS_TABSTOP | 0x1,7,17,179,8
+ LTEXT "Enter authorization code:",IDC_STATIC,7,33,179,8
+ LTEXT "To allow Miranda NG access to %s account:",IDC_AUTH_TEXT,7,7,140,8
+ PUSHBUTTON "Authorize",IDC_OAUTH_AUTHORIZE,58,17,74,14
END
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index 1eb184ed5d..72b544a232 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -1,20 +1,29 @@
#include "..\stdafx.h"
#include "dropbox_api.h"
-CDropboxService::CDropboxService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CDropboxService::CDropboxService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
- CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, &CDropboxService::UploadToDropbox, this);
+ //CreateServiceFunctionObj(MS_DROPBOX_UPLOAD, &CDropboxService::UploadToDropbox, this);
}
-const char* CDropboxService::GetModule() const
+CDropboxService* CDropboxService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Dropbox";
+ CDropboxService *proto = new CDropboxService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
+}
+
+int CDropboxService::UnInit(CDropboxService *proto)
+{
+ Services.remove(proto);
+ delete proto;
+ return 0;
}
-const wchar_t* CDropboxService::GetText() const
+const char* CDropboxService::GetModuleName() const
{
- return LPGENW("Dropbox");
+ return "Dropbox";
}
int CDropboxService::GetIconId() const
@@ -24,7 +33,7 @@ int CDropboxService::GetIconId() const
bool CDropboxService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
return true;
@@ -55,14 +64,14 @@ unsigned CDropboxService::RequestAccessTokenThread(void *owner, void *param)
NLHR_PTR response(request.Send(service->hConnection));
if (response == nullptr || response->resultCode != HTTP_CODE_OK) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError());
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError());
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
@@ -70,14 +79,14 @@ unsigned CDropboxService::RequestAccessTokenThread(void *owner, void *param)
JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetModule(), "TokenSecret", node.as_string().c_str());
- ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
+ db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
+ //ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -90,7 +99,7 @@ unsigned CDropboxService::RevokeAccessTokenThread(void *param)
{
CDropboxService *service = (CDropboxService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
DropboxAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -108,7 +117,7 @@ void CDropboxService::HandleJsonError(JSONNode &node)
void CDropboxService::UploadFile(const char *data, size_t size, char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
DropboxAPI::UploadFileRequest request(token, path, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -120,7 +129,7 @@ void CDropboxService::UploadFile(const char *data, size_t size, char *path)
void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateUploadSessionRequest request(token, chunk, chunkSize);
NLHR_PTR response(request.Send(hConnection));
@@ -131,7 +140,7 @@ void CDropboxService::CreateUploadSession(const char *chunk, size_t chunkSize, c
void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::UploadFileChunkRequest request(token, sessionId, offset, chunk, chunkSize);
NLHR_PTR response(request.Send(hConnection));
@@ -140,7 +149,7 @@ void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const
void CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -152,7 +161,7 @@ void CDropboxService::CommitUploadSession(const char *data, size_t size, const c
void CDropboxService::CreateFolder(const char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -167,7 +176,7 @@ void CDropboxService::CreateFolder(const char *path)
void CDropboxService::CreateSharedLink(const char *path, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
DropboxAPI::CreateSharedLinkRequest shareRequest(token, path);
NLHR_PTR response(shareRequest.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h
index 1f123d2d5c..d65db25034 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.h
+++ b/plugins/CloudFile/src/Services/dropbox_service.h
@@ -17,10 +17,13 @@ private:
void CreateSharedLink(const char *path, char *url);
public:
- CDropboxService(HNETLIBUSER hConnection);
+ CDropboxService(const char *protoName, const wchar_t *userName);
+
+ static CDropboxService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CDropboxService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index 5c5b7703d4..a15056b884 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "google_api.h"
-CGDriveService::CGDriveService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CGDriveService::CGDriveService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* CGDriveService::GetModule() const
+CGDriveService* CGDriveService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Google";
+ CGDriveService *proto = new CGDriveService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* CGDriveService::GetText() const
+int CGDriveService::UnInit(CGDriveService *proto)
{
- return LPGENW("Google Drive");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* CGDriveService::GetModuleName() const
+{
+ return "/Google";
}
int CGDriveService::GetIconId() const
@@ -23,18 +32,18 @@ int CGDriveService::GetIconId() const
bool CGDriveService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetModule(), "ExpiresIn");
+ time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
return now < expiresIn;
}
void CGDriveService::Login()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetModule(), "RefreshToken"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
GDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,11 +51,11 @@ void CGDriveService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
return;
}
@@ -79,14 +88,14 @@ unsigned CGDriveService::RequestAccessTokenThread(void *owner, void *param)
? response->pData
: service->HttpStatusToError(response->resultCode);
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), error);
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), error);
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
@@ -94,20 +103,20 @@ unsigned CGDriveService::RequestAccessTokenThread(void *owner, void *param)
JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, service->GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, service->GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -120,7 +129,7 @@ unsigned CGDriveService::RevokeAccessTokenThread(void *param)
{
CGDriveService *service = (CGDriveService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
GDriveAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -138,7 +147,7 @@ void CGDriveService::HandleJsonError(JSONNode &node)
void CGDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::UploadFileRequest request(token, parentId, name, data, size);
NLHR_PTR response(request.Send(hConnection));
@@ -149,7 +158,7 @@ void CGDriveService::UploadFile(const char *parentId, const char *name, const ch
void CGDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::CreateUploadSessionRequest request(token, parentId, name);
NLHR_PTR response(request.Send(hConnection));
@@ -191,7 +200,7 @@ void CGDriveService::UploadFileChunk(const char *uploadUri, const char *chunk, s
void CGDriveService::CreateFolder(const char *path, char *folderId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -202,7 +211,7 @@ void CGDriveService::CreateFolder(const char *path, char *folderId)
void CGDriveService::CreateSharedLink(const char *itemId, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
GDriveAPI::GrantPermissionsRequest request(token, itemId);
NLHR_PTR response(request.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/google_service.h b/plugins/CloudFile/src/Services/google_service.h
index 878fa8f442..3fb4634c4b 100644
--- a/plugins/CloudFile/src/Services/google_service.h
+++ b/plugins/CloudFile/src/Services/google_service.h
@@ -16,10 +16,13 @@ private:
void CreateSharedLink(const char *itemId, char *url);
public:
- CGDriveService(HNETLIBUSER hConnection);
+ CGDriveService(const char *protoName, const wchar_t *userName);
+
+ static CGDriveService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CGDriveService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index 38519e6d55..3b2f52a073 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "microsoft_api.h"
-COneDriveService::COneDriveService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+COneDriveService::COneDriveService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* COneDriveService::GetModule() const
+COneDriveService* COneDriveService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Microsoft";
+ COneDriveService *proto = new COneDriveService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* COneDriveService::GetText() const
+int COneDriveService::UnInit(COneDriveService *proto)
{
- return LPGENW("OneDrive");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* COneDriveService::GetModuleName() const
+{
+ return "/OneDrive";
}
int COneDriveService::GetIconId() const
@@ -23,18 +32,18 @@ int COneDriveService::GetIconId() const
bool COneDriveService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetModule(), "ExpiresIn");
+ time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
return now < expiresIn;
}
void COneDriveService::Login()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetModule(), "RefreshToken"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
OneDriveAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,11 +51,11 @@ void COneDriveService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
return;
}
@@ -57,9 +66,9 @@ void COneDriveService::Login()
void COneDriveService::Logout()
{
- db_unset(NULL, GetModule(), "TokenSecret");
- db_unset(NULL, GetModule(), "ExpiresIn");
- db_unset(NULL, GetModule(), "RefreshToken");
+ db_unset(NULL, GetAccountName(), "TokenSecret");
+ db_unset(NULL, GetAccountName(), "ExpiresIn");
+ db_unset(NULL, GetAccountName(), "RefreshToken");
}
unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
@@ -81,14 +90,14 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
? response->pData
: service->HttpStatusToError(response->resultCode);
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), error);
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), error);
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
@@ -96,20 +105,20 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, service->GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, service->GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -129,7 +138,7 @@ void COneDriveService::HandleJsonError(JSONNode &node)
void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::UploadFileRequest *request = mir_strlen(parentId)
? new OneDriveAPI::UploadFileRequest(token, parentId, name, data, size, (OnConflict)strategy)
@@ -144,7 +153,7 @@ void COneDriveService::UploadFile(const char *parentId, const char *name, const
void COneDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::CreateUploadSessionRequest *request = mir_strlen(parentId)
? new OneDriveAPI::CreateUploadSessionRequest(token, parentId, name, (OnConflict)strategy)
@@ -179,7 +188,7 @@ void COneDriveService::UploadFileChunk(const char *uploadUri, const char *chunk,
void COneDriveService::CreateFolder(const char *path, char *folderId)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -190,7 +199,7 @@ void COneDriveService::CreateFolder(const char *path, char *folderId)
void COneDriveService::CreateSharedLink(const char *itemId, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
OneDriveAPI::CreateSharedLinkRequest request(token, itemId);
NLHR_PTR response(request.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index cdd9d53976..c58bb4e07c 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.h
+++ b/plugins/CloudFile/src/Services/microsoft_service.h
@@ -15,10 +15,13 @@ private:
void CreateSharedLink(const char *itemId, char *url);
public:
- COneDriveService(HNETLIBUSER hConnection);
+ COneDriveService(const char *protoName, const wchar_t *userName);
- const char* GetModule() const;
- const wchar_t* GetText() const;
+ static COneDriveService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(COneDriveService*);
+
+ const char* GetModuleName() const override;
+
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index 1e4d5749cb..8a246fa59f 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -1,19 +1,28 @@
#include "..\stdafx.h"
#include "yandex_api.h"
-CYandexService::CYandexService(HNETLIBUSER hConnection)
- : CCloudService(hConnection)
+CYandexService::CYandexService(const char *protoName, const wchar_t *userName)
+ : CCloudService(protoName, userName)
{
}
-const char* CYandexService::GetModule() const
+CYandexService* CYandexService::Init(const char *moduleName, const wchar_t *userName)
{
- return "Yandex";
+ CYandexService *proto = new CYandexService(moduleName, userName);
+ Services.insert(proto);
+ return proto;
}
-const wchar_t* CYandexService::GetText() const
+int CYandexService::UnInit(CYandexService *proto)
{
- return LPGENW("Yandex.Disk");
+ Services.remove(proto);
+ delete proto;
+ return 0;
+}
+
+const char* CYandexService::GetModuleName() const
+{
+ return "Yandex.Disk";
}
int CYandexService::GetIconId() const
@@ -23,18 +32,18 @@ int CYandexService::GetIconId() const
bool CYandexService::IsLoggedIn()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
if (!token || token[0] == 0)
return false;
time_t now = time(nullptr);
- time_t expiresIn = db_get_dw(NULL, GetModule(), "ExpiresIn");
+ time_t expiresIn = db_get_dw(NULL, GetAccountName(), "ExpiresIn");
return now < expiresIn;
}
void CYandexService::Login()
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- ptrA refreshToken(db_get_sa(NULL, GetModule(), "RefreshToken"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
+ ptrA refreshToken(db_get_sa(NULL, GetAccountName(), "RefreshToken"));
if (token && refreshToken && refreshToken[0]) {
YandexAPI::RefreshTokenRequest request(refreshToken);
NLHR_PTR response(request.Send(hConnection));
@@ -42,14 +51,14 @@ void CYandexService::Login()
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("access_token");
- db_set_s(NULL, GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, GetAccountName(), "RefreshToken", node.as_string().c_str());
return;
}
@@ -82,14 +91,14 @@ unsigned CYandexService::RequestAccessTokenThread(void *owner, void *param)
? response->pData
: service->HttpStatusToError(response->resultCode);
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), error);
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), error);
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
JSONNode root = JSONNode::parse(response->pData);
if (root.empty()) {
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);
return 0;
}
@@ -97,20 +106,20 @@ unsigned CYandexService::RequestAccessTokenThread(void *owner, void *param)
JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
- Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
+ Netlib_Logf(service->hConnection, "%s: %s", service->GetAccountName(), service->HttpStatusToError(response->resultCode));
//ShowNotification((wchar_t*)error_description, MB_ICONERROR);
return 0;
}
node = root.at("access_token");
- db_set_s(NULL, service->GetModule(), "TokenSecret", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "TokenSecret", node.as_string().c_str());
node = root.at("expires_in");
time_t expiresIn = time(nullptr) + node.as_int();
- db_set_dw(NULL, service->GetModule(), "ExpiresIn", expiresIn);
+ db_set_dw(NULL, service->GetAccountName(), "ExpiresIn", expiresIn);
node = root.at("refresh_token");
- db_set_s(NULL, service->GetModule(), "RefreshToken", node.as_string().c_str());
+ db_set_s(NULL, service->GetAccountName(), "RefreshToken", node.as_string().c_str());
SetDlgItemTextA(hwndDlg, IDC_OAUTH_CODE, "");
@@ -123,7 +132,7 @@ unsigned CYandexService::RevokeAccessTokenThread(void *param)
{
CYandexService *service = (CYandexService*)param;
- ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, service->GetAccountName(), "TokenSecret"));
YandexAPI::RevokeAccessTokenRequest request(token);
NLHR_PTR response(request.Send(service->hConnection));
@@ -141,7 +150,7 @@ void CYandexService::HandleJsonError(JSONNode &node)
void CYandexService::CreateUploadSession(const char *path, char *uploadUri)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
YandexAPI::GetUploadUrlRequest request(token, path, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -180,7 +189,7 @@ void CYandexService::UploadFileChunk(const char *uploadUri, const char *chunk, s
void CYandexService::CreateFolder(const char *path)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::CreateFolderRequest request(token, path);
NLHR_PTR response(request.Send(hConnection));
@@ -189,7 +198,7 @@ void CYandexService::CreateFolder(const char *path)
void CYandexService::CreateSharedLink(const char *path, char *url)
{
- ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ ptrA token(db_get_sa(NULL, GetAccountName(), "TokenSecret"));
YandexAPI::PublishRequest publishRequest(token, path);
NLHR_PTR response(publishRequest.Send(hConnection));
diff --git a/plugins/CloudFile/src/Services/yandex_service.h b/plugins/CloudFile/src/Services/yandex_service.h
index 85c0ad12de..09c06d9a24 100644
--- a/plugins/CloudFile/src/Services/yandex_service.h
+++ b/plugins/CloudFile/src/Services/yandex_service.h
@@ -16,10 +16,13 @@ private:
void CreateSharedLink(const char *path, char *url);
public:
- CYandexService(HNETLIBUSER hConnection);
+ CYandexService(const char *protoName, const wchar_t *userName);
+
+ static CYandexService* Init(const char *szModuleName, const wchar_t *szUserName);
+ static int UnInit(CYandexService*);
+
+ const char* GetModuleName() const override;
- const char* GetModule() const;
- const wchar_t* GetText() const;
int GetIconId() const;
bool IsLoggedIn();
diff --git a/plugins/CloudFile/src/cloud_service.cpp b/plugins/CloudFile/src/cloud_file.cpp
index 90b84c0590..ce1392f9d3 100644
--- a/plugins/CloudFile/src/cloud_service.cpp
+++ b/plugins/CloudFile/src/cloud_file.cpp
@@ -2,72 +2,77 @@
static int CompareServices(const CCloudService *p1, const CCloudService *p2)
{
- return mir_strcmp(p1->GetModule(), p2->GetModule());
+ return mir_strcmp(p1->GetAccountName(), p2->GetAccountName());
}
LIST<CCloudService> Services(10, CompareServices);
void InitServices()
{
- Services.insert(new CDropboxService(hNetlibConnection));
- Services.insert(new CGDriveService(hNetlibConnection));
- Services.insert(new COneDriveService(hNetlibConnection));
- Services.insert(new CYandexService(hNetlibConnection));
-
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
-
- size_t count = Services.getCount();
- for (size_t i = 0; i < count; i++) {
- CCloudService *service = Services[i];
-
- CMStringA moduleName = MODULE;
- moduleName.AppendFormat("/%s", service->GetModule());
- pd.type = PROTOTYPE_VIRTUAL;
- pd.szName = moduleName.GetBuffer();
- Proto_RegisterModule(&pd);
-
- CMStringA serviceName = moduleName + PSS_FILE;
- CreateServiceFunctionObj(serviceName, ProtoSendFile, service);
-
- moduleName += "/Interceptor";
- pd.szName = moduleName.GetBuffer();
- pd.type = PROTOTYPE_FILTER;
- Proto_RegisterModule(&pd);
-
- serviceName = moduleName + PSS_FILE;
- CreateServiceFunctionObj(serviceName, ProtoSendFileInterceptor, service);
- }
+ 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(HNETLIBUSER hConnection)
- : hConnection(hConnection)
+CCloudService::CCloudService(const char *protoName, const wchar_t *userName)
+ : PROTO<CCloudService>(protoName, userName)
{
+ NETLIBUSER nlu = {};
+ nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE;
+ nlu.szSettingsModule = (char*)protoName;
+ nlu.szDescriptiveName.w = (wchar_t*)userName;
+ hConnection = Netlib_RegisterUser(&nlu);
}
-const wchar_t* CCloudService::GetText() const
+CCloudService::~CCloudService()
{
- return _A2T(GetModule());
+ Netlib_CloseHandle(hConnection);
+ hConnection = nullptr;
}
-int CCloudService::GetIconId() const
+const char* CCloudService::GetAccountName() const
{
- return 0;
+ return m_szModuleName;
}
-void CCloudService::OpenUploadDialog(MCONTACT hContact)
+const wchar_t* CCloudService::GetUserName() const
{
- char *proto = GetContactProto(hContact);
- if (!mir_strcmpi(proto, META_PROTO))
- hContact = CallService(MS_MC_GETMOSTONLINECONTACT, hContact);
+ return m_tszUserName;
+}
- auto it = InterceptedContacts.find(hContact);
- if (it == InterceptedContacts.end())
- {
- HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0);
- InterceptedContacts[hContact] = hwnd;
+DWORD_PTR CCloudService::GetCaps(int type, MCONTACT)
+{
+ switch (type) {
+ case PFLAGNUM_1:
+ return PF1_FILESEND;
+ default:
+ return 0;
}
- else
- SetActiveWindow(it->second);
}
void CCloudService::Report(MCONTACT hContact, const wchar_t *data)
@@ -98,11 +103,6 @@ char* CCloudService::PreparePath(const char *oldPath, char *newPath)
return newPath;
}
-char* CCloudService::PreparePath(const wchar_t *oldPath, char *newPath)
-{
- return PreparePath(ptrA(mir_utf8encodeW(oldPath)), newPath);
-}
-
char* CCloudService::HttpStatusToError(int status)
{
switch (status) {
@@ -154,4 +154,4 @@ JSONNode CCloudService::GetJsonResponse(NETLIBHTTPREQUEST *response)
HandleJsonError(root);
return root;
-} \ No newline at end of file
+}
diff --git a/plugins/CloudFile/src/cloud_service.h b/plugins/CloudFile/src/cloud_file.h
index edc4cdd90d..0d4f3def32 100644
--- a/plugins/CloudFile/src/cloud_service.h
+++ b/plugins/CloudFile/src/cloud_file.h
@@ -8,7 +8,7 @@ enum OnConflict
REPLACE,
};
-class CCloudService
+class CCloudService : public PROTO<CCloudService>
{
protected:
int id;
@@ -16,7 +16,6 @@ protected:
// utils
char* PreparePath(const char *oldPath, char *newPath);
- char* PreparePath(const wchar_t *oldPath, char *newPath);
virtual char* HttpStatusToError(int status = 0);
virtual void HttpResponseToError(NETLIBHTTPREQUEST *response);
@@ -28,11 +27,20 @@ protected:
public:
std::map<MCONTACT, HWND> InterceptedContacts;
- CCloudService(HNETLIBUSER hConnection);
+ CCloudService(const char *protoName, const wchar_t *userName);
+ virtual ~CCloudService();
- virtual const char* GetModule() const = 0;
- virtual const wchar_t* GetText() const;
- virtual int GetIconId() const;
+ DWORD_PTR __cdecl GetCaps(int type, MCONTACT) override;
+ int __cdecl FileCancel(MCONTACT hContact, HANDLE hTransfer);
+ HANDLE __cdecl SendFile(MCONTACT hContact, const wchar_t *msg, wchar_t **ppszFiles) override;
+
+ static INT_PTR SendFileInterceptor(WPARAM wParam, LPARAM lParam);
+
+ virtual const char* GetModuleName() const = 0;
+ const char* GetAccountName() const;
+ const wchar_t* GetUserName() const;
+
+ virtual int GetIconId() const = 0;
virtual bool IsLoggedIn() = 0;
virtual void Login() = 0;
@@ -47,21 +55,20 @@ public:
class CCloudServiceSearch : public CCloudService
{
-private:
- const char *m_search;
-
protected:
void HandleJsonError(JSONNode&) { }
public:
CCloudServiceSearch(const char *search)
- : CCloudService(NULL), m_search(search) { }
+ : CCloudService(search, nullptr) { }
+
+ const char* GetModuleName() const override { return nullptr; }
- const char* GetModule() const { return m_search; }
+ int GetIconId() const override { return NULL; }
- bool IsLoggedIn() { return false; }
- void Login() { }
- void Logout() { }
+ bool IsLoggedIn() override { return false; }
+ void Login() override { }
+ void Logout() override { }
UINT Upload(FileTransferParam*) { return 0; }
};
diff --git a/plugins/CloudFile/src/events.cpp b/plugins/CloudFile/src/events.cpp
index 6fcfed3445..df2e06ef4f 100644
--- a/plugins/CloudFile/src/events.cpp
+++ b/plugins/CloudFile/src/events.cpp
@@ -2,8 +2,12 @@
int OnModulesLoaded(WPARAM, LPARAM)
{
+ InitializeIcons();
+ InitializeMenus();
+
// options
HookEvent(ME_OPT_INITIALISE, OnOptionsInitialized);
+
// srfile
size_t count = Services.getCount();
for (size_t i = 0; i < count; i++) {
diff --git a/plugins/CloudFile/src/icons.cpp b/plugins/CloudFile/src/icons.cpp
index 72d7c22314..ed496f2430 100644
--- a/plugins/CloudFile/src/icons.cpp
+++ b/plugins/CloudFile/src/icons.cpp
@@ -19,7 +19,6 @@ HANDLE GetIconHandle(int iconId)
for (auto &it : iconList)
if (it.defIconID == iconId)
return it.hIcolib;
-
return nullptr;
}
@@ -28,7 +27,6 @@ HANDLE GetIconHandle(const char *name)
for (auto &it : iconList)
if (mir_strcmpi(it.szName, name) == 0)
return it.hIcolib;
-
return nullptr;
}
@@ -37,6 +35,5 @@ HICON LoadIconEx(int iconId, bool big)
for (auto &it : iconList)
if (it.defIconID == iconId)
return IcoLib_GetIconByHandle(it.hIcolib, big);
-
return nullptr;
} \ No newline at end of file
diff --git a/plugins/CloudFile/src/main.cpp b/plugins/CloudFile/src/main.cpp
index ffdf7bfeb5..a1dae8c146 100644
--- a/plugins/CloudFile/src/main.cpp
+++ b/plugins/CloudFile/src/main.cpp
@@ -2,7 +2,6 @@
int hLangpack;
HINSTANCE hInstance;
-HNETLIBUSER hNetlibConnection;
PLUGININFOEX pluginInfo =
{
@@ -38,15 +37,7 @@ extern "C" int __declspec(dllexport) Load(void)
HookEvent(ME_PROTO_ACK, OnProtoAck);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
- NETLIBUSER nlu = {};
- nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS;
- nlu.szSettingsModule = MODULE;
- nlu.szDescriptiveName.a = MODULE;
- hNetlibConnection = Netlib_RegisterUser(&nlu);
-
InitServices();
- InitializeIcons();
- InitializeMenus();
return 0;
}
diff --git a/plugins/CloudFile/src/menus.cpp b/plugins/CloudFile/src/menus.cpp
index acfd469092..d405d68f8b 100644
--- a/plugins/CloudFile/src/menus.cpp
+++ b/plugins/CloudFile/src/menus.cpp
@@ -44,12 +44,11 @@ void InitializeMenus()
for (size_t i = 0; i < count; i++) {
CCloudService *service = Services[i];
- CMStringA serviceName = MODULE;
- serviceName.AppendFormat("/%s/Upload", service->GetModule());
+ CMStringA serviceName(FORMAT, "/%s/Upload", service->GetAccountName());
mi.pszService = serviceName.GetBuffer();
mi.flags = CMIF_SYSTEM | CMIF_UNICODE;
- mi.name.w = (wchar_t*)service->GetText();
+ mi.name.w = (wchar_t*)service->GetUserName();
mi.position = i;
mi.hIcolibItem = GetIconHandle(Services[i]->GetIconId());
Menu_AddContactMenuItem(&mi);
diff --git a/plugins/CloudFile/src/oauth.cpp b/plugins/CloudFile/src/oauth.cpp
index 7815c27771..1f837f021d 100644
--- a/plugins/CloudFile/src/oauth.cpp
+++ b/plugins/CloudFile/src/oauth.cpp
@@ -1,16 +1,52 @@
#include "stdafx.h"
COAuthDlg::COAuthDlg(CCloudService *service, const char *authUrl, pThreadFuncOwner requestAccessTokenThread)
- : CDlgBase(hInstance, IDD_OAUTH), m_service(service),
+ : CDlgBase(hInstance, IDD_OAUTH),
+ m_service(service), m_authUrl(authUrl),
m_requestAccessTokenThread(requestAccessTokenThread),
- m_auth(this, IDC_OAUTH_AUTHORIZE, authUrl),
+ m_authorize(this, IDC_OAUTH_AUTHORIZE),
m_code(this, IDC_OAUTH_CODE), m_ok(this, IDOK)
{
m_autoClose = CLOSE_ON_CANCEL;
+ m_authorize.OnClick = Callback(this, &COAuthDlg::Auth_OnClick);
m_code.OnChange = Callback(this, &COAuthDlg::Code_OnChange);
m_ok.OnClick = Callback(this, &COAuthDlg::Ok_OnClick);
}
+void COAuthDlg::OnInitDialog()
+{
+ /*CCtrlBase *ctrl = FindControl(IDC_AUTH_TEXT);
+ ptrW format(ctrl->GetText());
+ wchar_t text[MAX_PATH];
+ mir_snwprintf(text, (const wchar_t*)format, m_service->GetUserName());
+ ctrl->SetText(text);*/
+}
+
+void COAuthDlg::Auth_OnClick(CCtrlButton*)
+{
+ if (SUCCEEDED(OleInitialize(NULL))) {
+ CComPtr<IWebBrowser2> browser;
+ if (SUCCEEDED(CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)&browser))) {
+ VARIANT empty;
+ VariantInit(&empty);
+ BSTR url = SysAllocString(_A2T(m_authUrl));
+ if (SUCCEEDED(browser->Navigate(url, &empty, &empty, &empty, &empty))) {
+ browser->put_AddressBar(VARIANT_FALSE);
+ browser->put_MenuBar(VARIANT_FALSE);
+ browser->put_ToolBar(VARIANT_FALSE);
+ browser->put_StatusBar(VARIANT_FALSE);
+ //browser->put_Resizable(VARIANT_FALSE);
+ browser->put_Visible(VARIANT_TRUE);
+ }
+ else
+ browser->Quit();
+ SysFreeString(url);
+ browser.Release();
+ }
+ OleUninitialize();
+ }
+}
+
void COAuthDlg::Code_OnChange(CCtrlBase*)
{
ptrA requestToken(m_code.GetTextA());
diff --git a/plugins/CloudFile/src/oauth.h b/plugins/CloudFile/src/oauth.h
index 434927f791..cbc4b3855e 100644
--- a/plugins/CloudFile/src/oauth.h
+++ b/plugins/CloudFile/src/oauth.h
@@ -5,13 +5,17 @@ class COAuthDlg : public CDlgBase
{
private:
CCloudService *m_service;
+ const char *m_authUrl;
pThreadFuncOwner m_requestAccessTokenThread;
- CCtrlHyperlink m_auth;
+ CCtrlButton m_authorize;
CCtrlEdit m_code;
CCtrlButton m_ok;
protected:
+ void OnInitDialog() override;
+
+ void Auth_OnClick(CCtrlButton*);
void Code_OnChange(CCtrlBase*);
void Ok_OnClick(CCtrlButton*);
diff --git a/plugins/CloudFile/src/options.cpp b/plugins/CloudFile/src/options.cpp
index a0e7a5c561..e4c8370691 100644
--- a/plugins/CloudFile/src/options.cpp
+++ b/plugins/CloudFile/src/options.cpp
@@ -10,10 +10,7 @@ COptionsMain::COptionsMain()
m_urlPasteToMessageInputArea(this, IDC_URL_COPYTOMIA),
m_urlCopyToClipboard(this, IDC_URL_COPYTOCB)
{
- /*CreateLink(m_defaultService, "DefaultService", L"");
-
- CreateLink(m_renameOnConflict, "RenameOnConflict", DBVT_BYTE, 1);
- CreateLink(m_repalceOnConflict, "RepalceOnConflict", DBVT_BYTE, 0);*/
+ CreateLink(m_defaultService, "DefaultService", L"");
CreateLink(m_urlAutoSend, "UrlAutoSend", DBVT_BYTE, 1);
CreateLink(m_urlPasteToMessageInputArea, "UrlPasteToMessageInputArea", DBVT_BYTE, 0);
@@ -32,18 +29,30 @@ void COptionsMain::OnInitDialog()
for (size_t i = 0; i < count; i++) {
CCloudService *service = Services[i];
- iItem = m_defaultService.AddString(mir_wstrdup(service->GetText()), (LPARAM)service);
- if (!mir_strcmpi(service->GetModule(), defaultService))
+ iItem = m_defaultService.AddString(mir_wstrdup(service->GetUserName()), (LPARAM)service);
+ if (!mir_strcmpi(service->GetAccountName(), defaultService))
m_defaultService.SetCurSel(iItem);
}
BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
- if (strategy == OnConflict::RENAME)
+ switch (strategy)
+ {
+ case OnConflict::RENAME:
m_renameOnConflict.SetState(TRUE);
- else if (strategy == OnConflict::REPLACE)
+ m_repalceOnConflict.SetState(FALSE);
+ m_doNothingOnConflict.SetState(FALSE);
+ break;
+ case OnConflict::REPLACE:
+ m_renameOnConflict.SetState(FALSE);
m_repalceOnConflict.SetState(TRUE);
- else
+ m_doNothingOnConflict.SetState(FALSE);
+ break;
+ default:
+ m_renameOnConflict.SetState(FALSE);
+ m_repalceOnConflict.SetState(FALSE);
m_doNothingOnConflict.SetState(TRUE);
+ break;
+ }
}
void COptionsMain::OnApply()
@@ -51,7 +60,7 @@ void COptionsMain::OnApply()
int iItem = m_defaultService.GetCurSel();
CCloudService *service = (CCloudService*)m_defaultService.GetItemData(iItem);
if (service)
- db_set_s(NULL, MODULE, "DefaultService", service->GetModule());
+ db_set_s(NULL, MODULE, "DefaultService", service->GetAccountName());
else
db_unset(NULL, MODULE, "DefaultService");
diff --git a/plugins/CloudFile/src/resource.h b/plugins/CloudFile/src/resource.h
index 384581fb4f..5a625809ca 100644
--- a/plugins/CloudFile/src/resource.h
+++ b/plugins/CloudFile/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by c:\Users\unsane\Projects\c++\miranda-ng\plugins\CloudFile\res\resource.rc
+// Used by D:\Projects\c++\miranda-ng\plugins\CloudFile\res\resource.rc
//
#define IDOK 1
#define IDCANCEL 2
@@ -21,14 +21,15 @@
#define IDC_URL_COPYTOCB 1022
#define IDC_URL_COPYTOMIA 1023
#define IDC_URL_AUTOSEND 1024
+#define IDC_AUTH_TEXT 1031
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 130
+#define _APS_NEXT_RESOURCE_VALUE 132
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1030
+#define _APS_NEXT_CONTROL_VALUE 1032
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/CloudFile/src/srmm.cpp b/plugins/CloudFile/src/srmm.cpp
index 036ee58601..1d7742f3fc 100644
--- a/plugins/CloudFile/src/srmm.cpp
+++ b/plugins/CloudFile/src/srmm.cpp
@@ -59,7 +59,7 @@ int OnSrmmButtonPressed(WPARAM, LPARAM lParam)
for (size_t i = 0; i < count; i++) {
CCloudService *service = Services[i];
- InsertMenu(hMenu, i, MF_STRING | MF_BYPOSITION, i + 1,TranslateW(service->GetText()));
+ 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);
}
diff --git a/plugins/CloudFile/src/stdafx.h b/plugins/CloudFile/src/stdafx.h
index a002e334c2..dd5d93f088 100644
--- a/plugins/CloudFile/src/stdafx.h
+++ b/plugins/CloudFile/src/stdafx.h
@@ -5,6 +5,9 @@
#include <shlwapi.h>
#include <commctrl.h>
+#include <exdisp.h>
+#include <msapi/comptr.h>
+
#include <malloc.h>
#include <time.h>
@@ -63,7 +66,7 @@ public:
#include "file_transfer.h"
// services
-#include "cloud_service.h"
+#include "cloud_file.h"
#include "oauth.h"
#include "Services\dropbox_service.h"
#include "Services\google_service.h"
@@ -99,15 +102,11 @@ int OnOptionsInitialized(WPARAM wParam, LPARAM);
// transfers
extern LIST<FileTransferParam> Transfers;
-INT_PTR ProtoSendFile(void *obj, WPARAM, LPARAM lParam);
-INT_PTR ProtoSendFileInterceptor(void *obj, WPARAM wParam, LPARAM lParam);
-INT_PTR ProtoCancelFile(WPARAM, LPARAM lParam);
UINT UploadAndReportProgressThread(void *owner, void *arg);
// utils
void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact = NULL);
void ShowNotification(const wchar_t *message, int flags, MCONTACT hContact = NULL);
-MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob);
bool CanSendToContact(MCONTACT hContact);
void SendToContact(MCONTACT hContact, const wchar_t *data);
void PasteToInputArea(MCONTACT hContact, const wchar_t *data);
diff --git a/plugins/CloudFile/src/transfers.cpp b/plugins/CloudFile/src/transfers.cpp
index 0f79f970d9..0c76247b6b 100644
--- a/plugins/CloudFile/src/transfers.cpp
+++ b/plugins/CloudFile/src/transfers.cpp
@@ -2,18 +2,36 @@
LIST<FileTransferParam> Transfers(1, HandleKeySortT);
-INT_PTR ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
+INT_PTR CCloudService::SendFileInterceptor(WPARAM wParam, LPARAM lParam)
{
CCSDATA *pccsd = (CCSDATA*)lParam;
- CCloudService *service = (CCloudService*)obj;
+ for (size_t i = 0; i < Services.getCount(); i++) {
+ CCloudService *service = Services[i];
+ auto it = service->InterceptedContacts.find(pccsd->hContact);
+ if (it == service->InterceptedContacts.end())
+ return CALLSERVICE_NOTFOUND;
+ service->InterceptedContacts.erase(it);
+ return (INT_PTR)service->SendFile(pccsd->hContact, (wchar_t*)pccsd->wParam, (wchar_t**)pccsd->lParam);
+ }
+ return CALLSERVICE_NOTFOUND;
+}
- FileTransferParam *ftp = new FileTransferParam(pccsd->hContact);
+INT_PTR CCloudService::FileCancel(MCONTACT, HANDLE hTransfer)
+{
+ FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer);
+ if (ftp)
+ ftp->Terminate();
+
+ return 0;
+}
+
+HANDLE CCloudService::SendFile(MCONTACT hContact, const wchar_t *description, wchar_t **paths)
+{
+ FileTransferParam *ftp = new FileTransferParam(hContact);
- const wchar_t *description = (wchar_t*)pccsd->wParam;
if (description && description[0])
- ftp->AppendFormatData(L"%s\r\n", (wchar_t*)pccsd->wParam);
+ ftp->AppendFormatData(L"%s\r\n", description);
- wchar_t **paths = (wchar_t**)pccsd->lParam;
ftp->SetWorkingDirectory(paths[0]);
for (int i = 0; paths[i]; i++) {
if (PathIsDirectory(paths[i]))
@@ -23,34 +41,25 @@ INT_PTR ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
Transfers.insert(ftp);
- mir_forkthreadowner(UploadAndReportProgressThread, service, ftp);
-
- return ftp->GetId();
-}
-
-INT_PTR ProtoSendFileInterceptor(void *obj, WPARAM wParam, LPARAM lParam)
-{
- CCSDATA *pccsd = (CCSDATA*)lParam;
- CCloudService *service = (CCloudService*)obj;
-
- auto it = service->InterceptedContacts.find(pccsd->hContact);
- if (it == service->InterceptedContacts.end())
- return CALLSERVICE_NOTFOUND;
- service->InterceptedContacts.erase(it);
+ mir_forkthreadowner(UploadAndReportProgressThread, this, ftp);
- return ProtoSendFile(obj, wParam, lParam);
+ return (HANDLE)ftp->GetId();
}
-INT_PTR ProtoCancelFile(WPARAM, LPARAM lParam)
+void CCloudService::OpenUploadDialog(MCONTACT hContact)
{
- CCSDATA *pccsd = (CCSDATA*)lParam;
-
- HANDLE hTransfer = (HANDLE)pccsd->wParam;
- FileTransferParam *ftp = Transfers.find((FileTransferParam*)&hTransfer);
- if (ftp)
- ftp->Terminate();
-
- return 0;
+ char *proto = GetContactProto(hContact);
+ if (!mir_strcmpi(proto, META_PROTO))
+ hContact = CallService(MS_MC_GETMOSTONLINECONTACT, hContact);
+
+ auto it = InterceptedContacts.find(hContact);
+ if (it == InterceptedContacts.end())
+ {
+ HWND hwnd = (HWND)CallService(MS_FILE_SENDFILE, hContact, 0);
+ InterceptedContacts[hContact] = hwnd;
+ }
+ else
+ SetActiveWindow(it->second);
}
UINT UploadAndReportProgressThread(void *owner, void *arg)
@@ -66,4 +75,4 @@ UINT UploadAndReportProgressThread(void *owner, void *arg)
delete ftp;
return res;
-} \ No newline at end of file
+}