summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-13 18:17:16 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-13 18:17:16 +0000
commitd333cb91eb0fb51faf34772258a5084e95f047d8 (patch)
treeacc62fd676325289711ab054682cb84ea0c7f29e /plugins
parentac60e6cd374568da60bf732a8018f94d48ee9dd7 (diff)
Dropbox: added wrappers for instance's services and hooks
git-svn-id: http://svn.miranda-ng.org/main/trunk@13573 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dropbox/src/dropbox.cpp23
-rw-r--r--plugins/Dropbox/src/dropbox.h46
-rw-r--r--plugins/Dropbox/src/dropbox_events.cpp96
-rw-r--r--plugins/Dropbox/src/dropbox_menus.cpp12
-rw-r--r--plugins/Dropbox/src/dropbox_services.cpp64
-rw-r--r--plugins/Dropbox/src/dropbox_transfers.cpp2
-rw-r--r--plugins/Dropbox/src/file_transfer.h2
-rw-r--r--plugins/Dropbox/src/main.cpp1
8 files changed, 127 insertions, 119 deletions
diff --git a/plugins/Dropbox/src/dropbox.cpp b/plugins/Dropbox/src/dropbox.cpp
index 18f611cdff..516a30941c 100644
--- a/plugins/Dropbox/src/dropbox.cpp
+++ b/plugins/Dropbox/src/dropbox.cpp
@@ -7,22 +7,22 @@ CDropbox::CDropbox() : transfers(1, HandleKeySortT)
pd.type = PROTOTYPE_VIRTUAL;
CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
- HookEventObj(ME_PROTO_ACK, OnProtoAck, this);
- HookEventObj(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown, this);
- HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this);
+ HookEvent(ME_PROTO_ACK, OnProtoAck);
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown);
+ HookEventObj(ME_SYSTEM_MODULESLOADED, GlobalEvent<&CDropbox::OnModulesLoaded>, this);
hFileSentEventHook = CreateHookableEvent(ME_DROPBOX_SENT);
- CreateServiceFunctionObj(MS_DROPBOX_SEND_FILE, SendFileToDropbox, this);
+ CreateServiceFunctionObj(MS_DROPBOX_SEND_FILE, GlobalService<&CDropbox::SendFileToDropbox>, this);
CreateProtoServiceFunction(MODULE, PS_GETCAPS, ProtoGetCaps);
CreateProtoServiceFunction(MODULE, PS_GETNAME, ProtoGetName);
CreateProtoServiceFunction(MODULE, PS_LOADICON, ProtoLoadIcon);
- CreateProtoServiceFunctionObj(PS_GETSTATUS, ProtoGetStatus, this);
- CreateProtoServiceFunctionObj(PSS_FILEW, ProtoSendFile, this);
- CreateProtoServiceFunctionObj(PSS_FILECANCEL, ProtoCancelFile, this);
- CreateProtoServiceFunctionObj(PSS_MESSAGE, ProtoSendMessage, this);
- CreateProtoServiceFunctionObj(PSR_MESSAGE, ProtoReceiveMessage, this);
+ CreateProtoServiceFunctionObj(PS_GETSTATUS, GlobalService<&CDropbox::ProtoGetStatus>, this);
+ CreateProtoServiceFunctionObj(PSS_FILEW, GlobalService<&CDropbox::ProtoSendFile>, this);
+ CreateProtoServiceFunctionObj(PSS_FILECANCEL, GlobalService<&CDropbox::ProtoCancelFile>, this);
+ CreateProtoServiceFunctionObj(PSS_MESSAGE, GlobalService<&CDropbox::ProtoSendMessage>, this);
+ CreateProtoServiceFunction(MODULE, PSR_MESSAGE, ProtoReceiveMessage);
InitializeMenus();
@@ -85,11 +85,11 @@ void CDropbox::RequestAccountInfo()
if (node)
{
ptrW display_name = ptrW(json_as_string(node));
- TCHAR *sep = wcsrchr(display_name, L' ');
+ TCHAR *sep = _tcsrchr(display_name, L' ');
if (sep)
{
db_set_ws(hContact, MODULE, "LastName", sep + 1);
- display_name[wcslen(display_name) - wcslen(sep)] = '\0';
+ display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0';
db_set_ws(hContact, MODULE, "FirstName", display_name);
}
else
@@ -187,6 +187,7 @@ UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
JSONNODE *node = json_get(root, "access_token");
ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
db_set_s(NULL, MODULE, "TokenSecret", access_token);
+ ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);
MCONTACT hContact = instance->GetDefaultContact();
if (hContact)
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h
index f05df5e6d1..1036ff5e04 100644
--- a/plugins/Dropbox/src/dropbox.h
+++ b/plugins/Dropbox/src/dropbox.h
@@ -53,16 +53,16 @@ private:
LIST<FileTransferParam> transfers;
// hooks
- static int OnProtoAck(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnPreShutdown(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnContactDeleted(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnOptionsInitialized(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnPrebuildContactMenu(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnSrmmWindowOpened(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnTabSrmmButtonPressed(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnFileDialogCancelled(void *obj, WPARAM wParam, LPARAM lParam);
- static int OnFileDialogSuccessed(void *obj, WPARAM wParam, LPARAM lParam);
+ static int OnProtoAck(WPARAM wParam, LPARAM lParam);
+ static int OnPreShutdown(WPARAM wParam, LPARAM lParam);
+ int OnModulesLoaded(WPARAM wParam, LPARAM lParam);
+ int OnContactDeleted(WPARAM wParam, LPARAM lParam);
+ int OnOptionsInitialized(WPARAM wParam, LPARAM lParam);
+ int OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam);
+ int OnSrmmWindowOpened(WPARAM wParam, LPARAM lParam);
+ int OnTabSrmmButtonPressed(WPARAM wParam, LPARAM lParam);
+ int OnFileDialogCancelled(WPARAM wParam, LPARAM lParam);
+ int OnFileDialogSuccessed(WPARAM wParam, LPARAM lParam);
// services
static HANDLE CreateProtoServiceFunctionObj(const char *szService, MIRANDASERVICEOBJ serviceProc, void *obj);
@@ -70,13 +70,13 @@ private:
static INT_PTR ProtoGetCaps(WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoGetName(WPARAM wParam, LPARAM lParam);
static INT_PTR ProtoLoadIcon(WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoGetStatus(void *obj, WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoSendFile(void *obj, WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoCancelFile(void *obj, WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoSendMessage(void *obj, WPARAM wParam, LPARAM lParam);
- static INT_PTR ProtoReceiveMessage(void *obj, WPARAM wParam, LPARAM lParam);
+ INT_PTR ProtoGetStatus(WPARAM wParam, LPARAM lParam);
+ INT_PTR ProtoSendFile(WPARAM wParam, LPARAM lParam);
+ INT_PTR ProtoCancelFile(WPARAM wParam, LPARAM lParam);
+ INT_PTR ProtoSendMessage(WPARAM wParam, LPARAM lParam);
+ static INT_PTR ProtoReceiveMessage(WPARAM wParam, LPARAM lParam);
- static INT_PTR SendFileToDropbox(void *obj, WPARAM wParam, LPARAM lParam);
+ INT_PTR SendFileToDropbox(WPARAM wParam, LPARAM lParam);
// commands
static void CommandHelp(void *arg);
@@ -127,6 +127,20 @@ private:
// utils
static char* HttpStatusToText(HTTP_STATUS status);
static void HandleHttpResponseError(NETLIBHTTPREQUEST *response);
+
+ template<int(CDropbox::*Event)(WPARAM, LPARAM)>
+ static int GlobalEvent(void *obj, WPARAM wParam, LPARAM lParam)
+ {
+ CDropbox *instance = (CDropbox*)obj;
+ return instance ? (instance->*Event)(wParam, lParam) : 0;
+ }
+
+ template<INT_PTR(CDropbox::*Service)(WPARAM, LPARAM)>
+ static INT_PTR GlobalService(void *obj, WPARAM wParam, LPARAM lParam)
+ {
+ CDropbox *instance = (CDropbox*)obj;
+ return instance ? (instance->*Service)(wParam, lParam) : 0;
+ }
};
#endif //_DROPBOX_PROTO_H_ \ No newline at end of file
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp
index e66706cd06..fa0e3d91a8 100644
--- a/plugins/Dropbox/src/dropbox_events.cpp
+++ b/plugins/Dropbox/src/dropbox_events.cpp
@@ -1,14 +1,14 @@
#include "stdafx.h"
-int CDropbox::OnModulesLoaded(void *obj, WPARAM, LPARAM)
+int CDropbox::OnModulesLoaded(WPARAM, LPARAM)
{
- HookEventObj(ME_DB_CONTACT_DELETED, OnContactDeleted, obj);
- HookEventObj(ME_OPT_INITIALISE, OnOptionsInitialized, obj);
- HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu, obj);
+ HookEventObj(ME_DB_CONTACT_DELETED, GlobalEvent<&CDropbox::OnContactDeleted>, this);
+ HookEventObj(ME_OPT_INITIALISE, GlobalEvent<&CDropbox::OnOptionsInitialized>, this);
+ HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, GlobalEvent<&CDropbox::OnPrebuildContactMenu>, this);
- HookEventObj(ME_MSG_WINDOWEVENT, OnSrmmWindowOpened, obj);
- HookEventObj(ME_FILEDLG_CANCELED, OnFileDialogCancelled, obj);
- HookEventObj(ME_FILEDLG_SUCCEEDED, OnFileDialogSuccessed, obj);
+ HookEventObj(ME_MSG_WINDOWEVENT, GlobalEvent<&CDropbox::OnSrmmWindowOpened>, this);
+ HookEventObj(ME_FILEDLG_CANCELED, GlobalEvent<&CDropbox::OnFileDialogCancelled>, this);
+ HookEventObj(ME_FILEDLG_SUCCEEDED, GlobalEvent<&CDropbox::OnFileDialogSuccessed>, this);
NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
@@ -16,13 +16,12 @@ int CDropbox::OnModulesLoaded(void *obj, WPARAM, LPARAM)
nlu.szSettingsModule = MODULE;
nlu.ptszDescriptiveName = L"Dropbox";
- CDropbox *instance = (CDropbox*)obj;
+ hNetlibConnection = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
- instance->hNetlibConnection = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ GetDefaultContact();
- instance->GetDefaultContact();
-
- if (ServiceExists(MS_BB_ADDBUTTON)) {
+ if (ServiceExists(MS_BB_ADDBUTTON))
+ {
BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
@@ -33,15 +32,16 @@ int CDropbox::OnModulesLoaded(void *obj, WPARAM, LPARAM)
bbd.dwDefPos = 100 + bbd.dwButtonID;
CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&bbd);
- HookEventObj(ME_MSG_BUTTONPRESSED, OnTabSrmmButtonPressed, obj);
+ HookEventObj(ME_MSG_BUTTONPRESSED, GlobalEvent<&CDropbox::OnTabSrmmButtonPressed>, this);
}
return 0;
}
-int CDropbox::OnPreShutdown(void *, WPARAM, LPARAM)
+int CDropbox::OnPreShutdown(WPARAM, LPARAM)
{
- if (ServiceExists(MS_BB_ADDBUTTON)) {
+ if (ServiceExists(MS_BB_ADDBUTTON))
+ {
BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
@@ -52,18 +52,16 @@ int CDropbox::OnPreShutdown(void *, WPARAM, LPARAM)
return 0;
}
-int CDropbox::OnContactDeleted(void *obj, WPARAM hContact, LPARAM)
+int CDropbox::OnContactDeleted(WPARAM hContact, LPARAM)
{
- CDropbox *instance = (CDropbox*)obj;
-
if (mir_strcmpi(GetContactProto(hContact), MODULE) == 0)
- if (instance->HasAccessToken())
- instance->DestroyAccessToken();
+ if (HasAccessToken())
+ DestroyAccessToken();
return 0;
}
-int CDropbox::OnOptionsInitialized(void *obj, WPARAM wParam, LPARAM)
+int CDropbox::OnOptionsInitialized(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.position = 100000000;
@@ -73,18 +71,18 @@ int CDropbox::OnOptionsInitialized(void *obj, WPARAM wParam, LPARAM)
odp.pszGroup = LPGEN("Network");
odp.pszTitle = "Dropbox";
odp.pfnDlgProc = MainOptionsProc;
- odp.dwInitParam = (LPARAM)obj;
+ odp.dwInitParam = (LPARAM)this;
Options_AddPage(wParam, &odp);
return 0;
}
-int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM, LPARAM lParam)
+int CDropbox::OnSrmmWindowOpened(WPARAM, LPARAM lParam)
{
MessageWindowEventData *ev = (MessageWindowEventData*)lParam;
- if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact) {
- CDropbox *instance = (CDropbox*)obj;
+ if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact)
+ {
char *proto = GetContactProto(ev->hContact);
bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE;
WORD status = db_get_w(ev->hContact, proto, "Status", ID_STATUS_OFFLINE);
@@ -94,7 +92,7 @@ int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM, LPARAM lParam)
bbd.pszModuleName = MODULE;
bbd.dwButtonID = BBB_ID_FILE_SEND;
bbd.bbbFlags = BBSF_RELEASED;
- if (!instance->HasAccessToken() || ev->hContact == instance->GetDefaultContact() || !instance->HasAccessToken())
+ if (!HasAccessToken() || ev->hContact == GetDefaultContact() || !HasAccessToken())
bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
else if (!isProtoOnline || (status == ID_STATUS_OFFLINE && !canSendOffline))
bbd.bbbFlags = BBSF_DISABLED;
@@ -105,14 +103,13 @@ int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM, LPARAM lParam)
return 0;
}
-int CDropbox::OnTabSrmmButtonPressed(void *obj, WPARAM, LPARAM lParam)
+int CDropbox::OnTabSrmmButtonPressed(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
-
CustomButtonClickData *cbc = (CustomButtonClickData *)lParam;
- if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact) {
- instance->hTransferContact = cbc->hContact;
- instance->hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, instance->GetDefaultContact(), 0);
+ if (!strcmp(cbc->pszModule, MODULE) && cbc->dwButtonId == BBB_ID_FILE_SEND && cbc->hContact)
+ {
+ hTransferContact = cbc->hContact;
+ hTransferWindow = (HWND)CallService(MS_FILE_SENDFILE, GetDefaultContact(), 0);
DisableSrmmButton(cbc->hContact);
}
@@ -129,7 +126,7 @@ void CDropbox::DisableSrmmButton(MCONTACT hContact)
CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
}
-void __stdcall EnableTabSrmmButtonAsync(void *arg)
+void __stdcall EnableTabSrmmButtonSync(void *arg)
{
BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
@@ -139,53 +136,54 @@ void __stdcall EnableTabSrmmButtonAsync(void *arg)
CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
}
-int CDropbox::OnFileDialogCancelled(void *obj, WPARAM, LPARAM lParam)
+int CDropbox::OnFileDialogCancelled(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
-
HWND hwnd = (HWND)lParam;
- if (instance->hTransferWindow == hwnd) {
- CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact);
- instance->hTransferWindow = 0;
+ if (hTransferWindow == hwnd)
+ {
+ CallFunctionAsync(EnableTabSrmmButtonSync, (void*)hTransferContact);
+ hTransferWindow = 0;
}
return 0;
}
-int CDropbox::OnFileDialogSuccessed(void *obj, WPARAM, LPARAM lParam)
+int CDropbox::OnFileDialogSuccessed(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
-
HWND hwnd = (HWND)lParam;
- if (instance->hTransferWindow == hwnd) {
- CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact);
- instance->hTransferWindow = 0;
+ if (hTransferWindow == hwnd)
+ {
+ CallFunctionAsync(EnableTabSrmmButtonSync, (void*)hTransferContact);
+ hTransferWindow = 0;
}
return 0;
}
-int CDropbox::OnProtoAck(void *, WPARAM, LPARAM lParam)
+int CDropbox::OnProtoAck(WPARAM, LPARAM lParam)
{
ACKDATA *ack = (ACKDATA*)lParam;
if (!strcmp(ack->szModule, MODULE))
return 0; // don't rebroadcast our own acks
- if (ack->type == ACKTYPE_STATUS/* && ((int)ack->lParam != (int)ack->hProcess)*/) {
+ if (ack->type == ACKTYPE_STATUS)
+ {
WORD status = ack->lParam;
bool canSendOffline = (CallProtoService(ack->szModule, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
MessageWindowInputData msgwi = { sizeof(msgwi) };
msgwi.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
- for (MCONTACT hContact = db_find_first(ack->szModule); hContact; hContact = db_find_next(hContact, ack->szModule)) {
+ for (MCONTACT hContact = db_find_first(ack->szModule); hContact; hContact = db_find_next(hContact, ack->szModule))
+ {
msgwi.hContact = hContact;
MessageWindowData msgw;
msgw.cbSize = sizeof(msgw);
- if (!CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&msgwi, (LPARAM)&msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS) {
+ if (!CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&msgwi, (LPARAM)&msgw) && msgw.uState & MSG_WINDOW_STATE_EXISTS)
+ {
BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
bbd.dwButtonID = BBB_ID_FILE_SEND;
diff --git a/plugins/Dropbox/src/dropbox_menus.cpp b/plugins/Dropbox/src/dropbox_menus.cpp
index 79bf9d31eb..e14948e791 100644
--- a/plugins/Dropbox/src/dropbox_menus.cpp
+++ b/plugins/Dropbox/src/dropbox_menus.cpp
@@ -25,17 +25,19 @@ void CDropbox::InitializeMenus()
CreateServiceFunctionObj(mi.pszService, SendFilesToDropboxCommand, this);
}
-int CDropbox::OnPrebuildContactMenu(void *obj, WPARAM hContact, LPARAM)
+int CDropbox::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
if (!hContact)
return 0;
BOOL bShow = FALSE;
- CDropbox *instance = (CDropbox*)obj;
- if (instance->HasAccessToken() && !instance->hTransferContact && hContact != instance->GetDefaultContact()) {
+ if (HasAccessToken() && !hTransferContact && hContact != GetDefaultContact())
+ {
char *proto = GetContactProto(hContact);
- if (proto && !db_get_b(hContact, proto, "ChatRoom", 0)) {
+ bool isContact = db_get_b(hContact, proto, "ChatRoom", 0) == 0;
+ if (proto && isContact)
+ {
bool isProtoOnline = CallProtoService(proto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE;
WORD status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE);
bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
@@ -44,6 +46,6 @@ int CDropbox::OnPrebuildContactMenu(void *obj, WPARAM hContact, LPARAM)
}
}
- Menu_ShowItem(instance->contactMenuItems[CMI_SEND_FILES], bShow);
+ Menu_ShowItem(contactMenuItems[CMI_SEND_FILES], bShow);
return 0;
}
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp
index d558fa7917..37b807eedc 100644
--- a/plugins/Dropbox/src/dropbox_services.cpp
+++ b/plugins/Dropbox/src/dropbox_services.cpp
@@ -1,7 +1,5 @@
#include "stdafx.h"
-int g_nStatus = ID_STATUS_OFFLINE;
-
HANDLE CDropbox::CreateProtoServiceFunctionObj(const char *szService, MIRANDASERVICEOBJ serviceProc, void *obj)
{
char str[MAXMODULELABELLENGTH];
@@ -41,16 +39,14 @@ INT_PTR CDropbox::ProtoLoadIcon(WPARAM wParam, LPARAM)
return (LOWORD(wParam) == PLI_PROTOCOL) ? (INT_PTR)CopyIcon(LoadIconEx(IDI_DROPBOX)) : 0;
}
-INT_PTR CDropbox::ProtoGetStatus(void *obj, WPARAM, LPARAM)
+INT_PTR CDropbox::ProtoGetStatus(WPARAM, LPARAM)
{
- CDropbox *instance = (CDropbox*)obj;
- return instance->HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
+ return HasAccessToken() ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE;
}
-INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoSendFile(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
- if (!instance->HasAccessToken())
+ if (!HasAccessToken())
return ACKRESULT_FAILED;
CCSDATA *pccsd = (CCSDATA*)lParam;
@@ -58,8 +54,8 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
FileTransferParam *ftp = new FileTransferParam();
ftp->pfts.flags |= PFTS_SENDING;
ftp->pfts.hContact = pccsd->hContact;
- ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : pccsd->hContact;
- instance->hTransferContact = 0;
+ ftp->hContact = (hTransferContact) ? hTransferContact : pccsd->hContact;
+ hTransferContact = 0;
TCHAR **paths = (TCHAR**)pccsd->lParam;
@@ -84,7 +80,7 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
if (!ftp->relativePathStart)
{
TCHAR *rootFolder = paths[j];
- TCHAR *relativePath = wcsrchr(rootFolder, '\\') + 1;
+ TCHAR *relativePath = _tcsrchr(rootFolder, '\\') + 1;
ftp->relativePathStart = relativePath - rootFolder;
}
@@ -97,7 +93,7 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
if (!ftp->pfts.tszWorkingDir)
{
TCHAR *path = paths[j];
- int length = wcsrchr(path, '\\') - path;
+ int length = _tcsrchr(path, '\\') - path;
ftp->pfts.tszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * (length + 1));
mir_tstrncpy(ftp->pfts.tszWorkingDir, paths[j], length + 1);
ftp->pfts.tszWorkingDir[length] = '\0';
@@ -117,25 +113,24 @@ INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam)
}
}
- ULONG fileId = InterlockedIncrement(&instance->hFileProcess);
+ ULONG fileId = InterlockedIncrement(&hFileProcess);
ftp->hProcess = (HANDLE)fileId;
- instance->transfers.insert(ftp);
+ transfers.insert(ftp);
- mir_forkthreadowner(CDropbox::SendFilesAndReportAsync, obj, ftp, 0);
+ mir_forkthreadowner(CDropbox::SendFilesAndReportAsync, this, ftp, 0);
return fileId;
}
-INT_PTR CDropbox::ProtoCancelFile(void *obj, WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoCancelFile(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
- if (!instance->HasAccessToken())
+ if (!HasAccessToken())
return ACKRESULT_FAILED;
CCSDATA *pccsd = (CCSDATA*)lParam;
HANDLE hTransfer = (HANDLE)pccsd->wParam;
- FileTransferParam *ftp = instance->transfers.find((FileTransferParam*)&hTransfer);
+ FileTransferParam *ftp = transfers.find((FileTransferParam*)&hTransfer);
if (ftp == NULL)
return 0;
@@ -144,10 +139,9 @@ INT_PTR CDropbox::ProtoCancelFile(void *obj, WPARAM, LPARAM lParam)
return 0;
}
-INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
- if (!instance->HasAccessToken())
+ if (!HasAccessToken())
return ACKRESULT_FAILED;
CCSDATA *pccsd = (CCSDATA*)lParam;
@@ -165,7 +159,7 @@ INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam)
dbei.szModule = MODULE;
dbei.timestamp = time(NULL);
dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)strlen(message);
+ dbei.cbBlob = (int)mir_strlen(message);
dbei.pBlob = (PBYTE)message;
dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF;
db_event_add(pccsd->hContact, &dbei);
@@ -193,10 +187,10 @@ INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam)
{
if (!strcmp(message + 1, commands[i].szCommand))
{
- ULONG messageId = InterlockedIncrement(&instance->hMessageProcess);
+ ULONG messageId = InterlockedIncrement(&hMessageProcess);
CommandParam *param = new CommandParam();
- param->instance = instance;
+ param->instance = this;
param->hContact = pccsd->hContact;
param->hProcess = (HANDLE)messageId;
param->data = (sep ? sep + 1 : NULL);
@@ -210,12 +204,12 @@ INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam)
char help[1024];
mir_snprintf(help, SIZEOF(help), Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), message);
- CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
+ CallContactService(GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
return 0;
}
-INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam)
+INT_PTR CDropbox::ProtoReceiveMessage(WPARAM, LPARAM lParam)
{
CCSDATA *pccsd = (CCSDATA*)lParam;
@@ -232,23 +226,21 @@ INT_PTR CDropbox::ProtoReceiveMessage(void *, WPARAM, LPARAM lParam)
return 0;
}
-INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam)
+INT_PTR CDropbox::SendFileToDropbox(WPARAM hContact, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
- if (!instance->HasAccessToken())
+ if (!HasAccessToken())
return 0;
if (hContact == NULL)
- hContact = instance->GetDefaultContact();
+ hContact = GetDefaultContact();
TCHAR *filePath = (TCHAR*)lParam;
FileTransferParam *ftp = new FileTransferParam();
- ftp->pfts.flags |= PFTS_SENDING;
ftp->pfts.hContact = hContact;
ftp->pfts.totalFiles = 1;
- ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : hContact;
- instance->hTransferContact = 0;
+ ftp->hContact = (hTransferContact) ? hTransferContact : hContact;
+ hTransferContact = 0;
int length = _tcsrchr(filePath, '\\') - filePath;
ftp->pfts.tszWorkingDir = (TCHAR*)mir_alloc(sizeof(TCHAR) * (length + 1));
@@ -259,10 +251,10 @@ INT_PTR CDropbox::SendFileToDropbox(void *obj, WPARAM hContact, LPARAM lParam)
ftp->pfts.ptszFiles[0] = mir_wstrdup(filePath);
ftp->pfts.ptszFiles[ftp->pfts.totalFiles] = NULL;
- ULONG fileId = InterlockedIncrement(&instance->hFileProcess);
+ ULONG fileId = InterlockedIncrement(&hFileProcess);
ftp->hProcess = (HANDLE)fileId;
- mir_forkthreadowner(CDropbox::SendFilesAndEventAsync, obj, ftp, 0);
+ mir_forkthreadowner(CDropbox::SendFilesAndEventAsync, this, ftp, 0);
return fileId;
}
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp
index 459914521c..ed4b02b6f9 100644
--- a/plugins/Dropbox/src/dropbox_transfers.cpp
+++ b/plugins/Dropbox/src/dropbox_transfers.cpp
@@ -129,7 +129,7 @@ UINT CDropbox::SendFilesAsync(void *owner, void *arg)
ftp->pfts.currentFileNumber = i;
ftp->pfts.currentFileSize = fileSize;
ftp->pfts.currentFileProgress = 0;
- ftp->pfts.tszCurrentFile = wcsrchr(ftp->pfts.ptszFiles[i], '\\') + 1;
+ ftp->pfts.tszCurrentFile = _tcsrchr(ftp->pfts.ptszFiles[i], '\\') + 1;
ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftp->hProcess, (LPARAM)&ftp->pfts);
diff --git a/plugins/Dropbox/src/file_transfer.h b/plugins/Dropbox/src/file_transfer.h
index 8afb1b4ec3..f27ab76695 100644
--- a/plugins/Dropbox/src/file_transfer.h
+++ b/plugins/Dropbox/src/file_transfer.h
@@ -40,7 +40,7 @@ struct FileTransferParam
isTerminated = false;
pfts.cbSize = sizeof(this->pfts);
- pfts.flags = PFTS_TCHAR;
+ pfts.flags = PFTS_TCHAR | PFTS_SENDING;
pfts.currentFileNumber = 0;
pfts.currentFileProgress = 0;
pfts.currentFileSize = 0;
diff --git a/plugins/Dropbox/src/main.cpp b/plugins/Dropbox/src/main.cpp
index 632464ce33..ebd39e61bb 100644
--- a/plugins/Dropbox/src/main.cpp
+++ b/plugins/Dropbox/src/main.cpp
@@ -41,6 +41,7 @@ extern "C" int __declspec(dllexport) Load(void)
InitializeIcons();
dropbox = new CDropbox();
+
return 0;
}