diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-03-11 14:19:01 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-03-11 14:19:01 +0000 |
commit | a0a667fd07e912b1dc425748e58a72fa9a50512f (patch) | |
tree | 027b0ed27a5c3d697dd1aa51a13ca0d3e1375582 /plugins/Dropbox/src/dropbox_events.cpp | |
parent | f8f38839dba925d30c09d9b1527258973c24e591 (diff) |
Dropbox:
- fixed TabSrmm button behavior
- added ME_DROPBOX_SEND_SUCCEEDED and ME_DROPBOX_SEND_FAILED events
- remained only unicode version of MS_DROPBOX_SEND_FILE
- minor fixes
- version bumped
git-svn-id: http://svn.miranda-ng.org/main/trunk@8557 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox_events.cpp')
-rw-r--r-- | plugins/Dropbox/src/dropbox_events.cpp | 147 |
1 files changed, 128 insertions, 19 deletions
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index 14d982f928..69397d8608 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -2,11 +2,13 @@ int CDropbox::OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam)
{
- CDropbox *instance = (CDropbox*)obj;
+ HookEventObj(ME_DB_CONTACT_DELETED, OnContactDeleted, obj);
+ HookEventObj(ME_OPT_INITIALISE, OnOptionsInitialized, obj);
+ HookEventObj(ME_CLIST_PREBUILDCONTACTMENU, OnPrebuildContactMenu, obj);
- HookEventObj(ME_FILEDLG_CANCELED, OnFileDoalogCancelled, obj);
- HookEventObj(ME_FILEDLG_SUCCEEDED, OnFileDoalogSuccessed, obj);
HookEventObj(ME_MSG_WINDOWEVENT, OnSrmmWindowOpened, obj);
+ HookEventObj(ME_FILEDLG_CANCELED, OnFileDialogCancelled, obj);
+ HookEventObj(ME_FILEDLG_SUCCEEDED, OnFileDialogSuccessed, obj);
NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
@@ -14,6 +16,8 @@ int CDropbox::OnModulesLoaded(void *obj, WPARAM wParam, LPARAM lParam) nlu.szSettingsModule = MODULE;
nlu.ptszDescriptiveName = L"Dropbox";
+ CDropbox *instance = (CDropbox*)obj;
+
instance->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
instance->GetDefaultContact();
@@ -87,7 +91,9 @@ int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM wParam, LPARAM lParam) MessageWindowEventData *ev = (MessageWindowEventData*)lParam;
if (ev->uType == MSG_WINDOW_EVT_OPENING && ev->hContact)
{
- WORD status = db_get_w(ev->hContact, GetContactProto(ev->hContact), "Status", ID_STATUS_OFFLINE);
+ char *proto = GetContactProto(ev->hContact);
+ WORD status = db_get_w(ev->hContact, proto, "Status", ID_STATUS_OFFLINE);
+ bool canSendOffline = (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDOFFLINE) > 0;
BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
@@ -95,7 +101,7 @@ int CDropbox::OnSrmmWindowOpened(void *obj, WPARAM wParam, LPARAM lParam) bbd.bbbFlags = BBSF_RELEASED;
if (ev->hContact == instance->GetDefaultContact() || !instance->HasAccessToken())
bbd.bbbFlags = BBSF_HIDDEN | BBSF_DISABLED;
- else if (/*instance->hTransferContact*/ status == ID_STATUS_OFFLINE)
+ else if (status == ID_STATUS_OFFLINE && !canSendOffline)
bbd.bbbFlags = BBSF_DISABLED;
CallService(MS_BB_SETBUTTONSTATE, ev->hContact, (LPARAM)&bbd);
@@ -128,28 +134,34 @@ int CDropbox::OnTabSrmmButtonPressed(void *obj, WPARAM wParam, LPARAM lParam) return 0;
}
-int CDropbox::OnFileDoalogCancelled(void *obj, WPARAM hContact, LPARAM lParam)
+void __stdcall EnableTabSrmmButtonAsync(void *arg)
+{
+ BBButton bbd = { sizeof(bbd) };
+ bbd.pszModuleName = MODULE;
+ bbd.dwButtonID = BBB_ID_FILE_SEND;
+ bbd.bbbFlags = BBSF_RELEASED;
+ MCONTACT hContact = (MCONTACT)arg;
+
+ CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
+}
+
+int CDropbox::OnFileDialogCancelled(void *obj, WPARAM hContact, LPARAM lParam)
{
CDropbox *instance = (CDropbox*)obj;
HWND hwnd = (HWND)lParam;
if (instance->hTransferContact == instance->dcftp[hwnd])
{
+ CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact);
+
instance->dcftp.erase((HWND)lParam);
instance->hTransferContact = 0;
-
- BBButton bbd = { sizeof(bbd) };
- bbd.pszModuleName = MODULE;
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.bbbFlags = BBSF_RELEASED;
-
- CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
}
return 0;
}
-int CDropbox::OnFileDoalogSuccessed(void *obj, WPARAM hContact, LPARAM lParam)
+int CDropbox::OnFileDialogSuccessed(void *obj, WPARAM hContact, LPARAM lParam)
{
CDropbox *instance = (CDropbox*)obj;
@@ -158,12 +170,109 @@ int CDropbox::OnFileDoalogSuccessed(void *obj, WPARAM hContact, LPARAM lParam) {
instance->dcftp.erase((HWND)lParam);
- BBButton bbd = { sizeof(bbd) };
- bbd.pszModuleName = MODULE;
- bbd.dwButtonID = BBB_ID_FILE_SEND;
- bbd.bbbFlags = BBSF_RELEASED;
+ CallFunctionAsync(EnableTabSrmmButtonAsync, (void*)instance->hTransferContact);
+ }
+
+ return 0;
+}
- CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
+int CDropbox::OnSendSuccessed(void *obj, WPARAM hContact, LPARAM lParam)
+{
+ wchar_t *data = (wchar_t*)lParam;
+ CDropbox *instance = (CDropbox*)obj;
+
+ if (instance->hTransferContact)
+ instance->hTransferContact = 0;
+
+ if (db_get_b(NULL, MODULE, "UrlAutoSend", 1))
+ {
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.flags = DBEF_UTF;
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = wcslen(data);
+ dbei.pBlob = (PBYTE)mir_utf8encodeW(data);
+
+ if (hContact != instance->GetDefaultContact())
+ {
+ if (CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)data) != ACKRESULT_FAILED)
+ {
+ dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF;
+ db_event_add(hContact, &dbei);
+ }
+ else
+ CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)hContact, (LPARAM)data);
+ }
+ else
+ db_event_add(hContact, &dbei);
+ }
+
+ CMString urls = data; urls += L"\r\n";
+
+ if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0))
+ CallServiceSync(MS_MSG_SENDMESSAGEW, (WPARAM)hContact, (LPARAM)urls.GetBuffer());
+
+ if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0))
+ {
+ if (OpenClipboard(NULL))
+ {
+ EmptyClipboard();
+ size_t size = sizeof(wchar_t) * (urls.GetLength() + 1);
+ HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
+ if (hClipboardData)
+ {
+ wchar_t* pchData = (wchar_t*)GlobalLock(hClipboardData);
+ if (pchData)
+ {
+ memcpy(pchData, (wchar_t*)urls.GetString(), size);
+ GlobalUnlock(hClipboardData);
+ SetClipboardData(CF_UNICODETEXT, hClipboardData);
+ }
+ }
+ CloseClipboard();
+ }
+ }
+
+ return 0;
+}
+
+int CDropbox::OnProtoAck(void *obj, WPARAM 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)*/)
+ {
+ 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))
+ {
+ msgwi.hContact = hContact;
+
+ MessageWindowData msgw;
+ msgw.cbSize = sizeof(msgw);
+
+ 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;
+ bbd.bbbFlags = BBSF_RELEASED;
+
+ if (status == ID_STATUS_OFFLINE && !canSendOffline)
+ bbd.bbbFlags = BBSF_DISABLED;
+
+ CallService(MS_BB_SETBUTTONSTATE, hContact, (LPARAM)&bbd);
+ }
+ }
}
return 0;
|