diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-09-01 18:28:13 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-09-01 18:28:13 +0000 |
commit | 140039aa214f240421dc3b629d15d5ed506c72af (patch) | |
tree | ffc2687e88b3854fbbc14fc815510e016e2279ef /plugins/Dropbox/src | |
parent | 981c8fa2b7348484507ff13488ace6db2c79b611 (diff) |
Dropbox: chat support
git-svn-id: http://svn.miranda-ng.org/main/trunk@15138 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src')
-rw-r--r-- | plugins/Dropbox/src/dropbox.h | 7 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_events.cpp | 2 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_services.cpp | 10 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 60 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_utils.cpp | 91 | ||||
-rw-r--r-- | plugins/Dropbox/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/Dropbox/src/version.h | 2 |
7 files changed, 102 insertions, 71 deletions
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 8cad46c4ea..31167ff7aa 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -113,6 +113,13 @@ private: static char* HttpStatusToText(HTTP_STATUS status);
static void HandleHttpResponseError(NETLIBHTTPREQUEST *response);
+ static MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob);
+
+ void SendToContact(MCONTACT hContact, const char* data);
+ void PasteToInputArea(MCONTACT hContact, const char* data);
+ void PasteToClipboard(MCONTACT hContact, const char* data);
+ void Report(MCONTACT hContact, const char* data);
+
template<int(CDropbox::*Event)(WPARAM, LPARAM)>
static int GlobalEvent(void *obj, WPARAM wParam, LPARAM lParam)
{
diff --git a/plugins/Dropbox/src/dropbox_events.cpp b/plugins/Dropbox/src/dropbox_events.cpp index d2d4aa027b..1ee5fe72d9 100644 --- a/plugins/Dropbox/src/dropbox_events.cpp +++ b/plugins/Dropbox/src/dropbox_events.cpp @@ -27,7 +27,7 @@ int CDropbox::OnModulesLoaded(WPARAM, LPARAM) BBButton bbd = { sizeof(bbd) };
bbd.pszModuleName = MODULE;
- bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISRSIDEBUTTON;
+ bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISCHATBUTTON | BBBF_ISRSIDEBUTTON;
bbd.ptszTooltip = TranslateT("Upload files to Dropbox");
bbd.hIcon = GetIconHandleByName("upload");
bbd.dwButtonID = BBB_ID_FILE_SEND;
diff --git a/plugins/Dropbox/src/dropbox_services.cpp b/plugins/Dropbox/src/dropbox_services.cpp index 1a35c464f1..ce27720305 100644 --- a/plugins/Dropbox/src/dropbox_services.cpp +++ b/plugins/Dropbox/src/dropbox_services.cpp @@ -150,16 +150,6 @@ INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam) }
char *szMessage = (char*)pccsd->lParam;
-
- /*DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = MODULE;
- dbei.timestamp = time(NULL);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)mir_strlen(szMessage);
- dbei.pBlob = (PBYTE)szMessage;
- dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF;
- db_event_add(pccsd->hContact, &dbei);*/
-
if (*szMessage == '/')
{
// parse commands
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 226d109ce3..66333980a0 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -222,66 +222,8 @@ UINT CDropbox::SendFilesAndReportAsync(void *owner, void *arg) CMStringA urls;
for (int i = 0; i < ftp->urlList.getCount(); i++)
urls.AppendFormat("%s\r\n", ftp->urlList[i]);
- char *data = urls.GetBuffer();
- if (db_get_b(NULL, MODULE, "UrlAutoSend", 1))
- {
- char *message = mir_utf8encode(data);
- if (ftp->hContact != instance->GetDefaultContact())
- {
- if (CallContactService(ftp->hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
- {
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.flags = DBEF_UTF | DBEF_SENT;
- dbei.szModule = MODULE;
- dbei.timestamp = time(NULL);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)mir_strlen(data);
- dbei.pBlob = (PBYTE)message;
- db_event_add(ftp->hContact, &dbei);
- }
- else
- {
- CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)ftp->hContact, (LPARAM)data);
- mir_free(message);
- }
- }
- else
- {
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.flags = DBEF_UTF;
- dbei.szModule = MODULE;
- dbei.timestamp = time(NULL);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)mir_strlen(data);
- dbei.pBlob = (PBYTE)message;
- db_event_add(ftp->hContact, &dbei);
- }
- }
-
- if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0))
- CallServiceSync(MS_MSG_SENDMESSAGE, (WPARAM)ftp->hContact, (LPARAM)data);
-
- if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0))
- {
- if (OpenClipboard(NULL))
- {
- EmptyClipboard();
- size_t size = sizeof(TCHAR) * (urls.GetLength() + 1);
- HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
- if (hClipboardData)
- {
- TCHAR *pchData = (TCHAR*)GlobalLock(hClipboardData);
- if (pchData)
- {
- memcpy(pchData, (TCHAR*)data, size);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_TEXT, hClipboardData);
- }
- }
- CloseClipboard();
- }
- }
+ instance->Report(ftp->hContact, urls.GetBuffer());
instance->transfers.remove(ftp);
delete ftp;
diff --git a/plugins/Dropbox/src/dropbox_utils.cpp b/plugins/Dropbox/src/dropbox_utils.cpp index 17fe9eb919..b5e837878d 100644 --- a/plugins/Dropbox/src/dropbox_utils.cpp +++ b/plugins/Dropbox/src/dropbox_utils.cpp @@ -37,3 +37,94 @@ void CDropbox::HandleHttpResponseError(NETLIBHTTPREQUEST *response) if (response->resultCode != HTTP_STATUS_OK)
throw TransferException(HttpStatusToText((HTTP_STATUS)response->resultCode));
}
+
+MEVENT CDropbox::AddEventToDb(MCONTACT hContact, WORD type, DWORD flags, DWORD cbBlob, PBYTE pBlob)
+{
+ DBEVENTINFO dbei;
+ dbei.cbSize = sizeof(dbei);
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = type;
+ dbei.cbBlob = cbBlob;
+ dbei.pBlob = pBlob;
+ dbei.flags = flags;
+ return db_event_add(hContact, &dbei);
+}
+
+void CDropbox::SendToContact(MCONTACT hContact, const char* data)
+{
+ if (hContact == GetDefaultContact())
+ {
+ char *message = mir_utf8encode(data);
+ AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, mir_strlen(message), (PBYTE)message);
+ return;
+ }
+
+ const char *szProto = GetContactProto(hContact);
+ bool isChatRoom = db_get_b(hContact, szProto, "ChatRoom", 0);
+ if (isChatRoom)
+ {
+ ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
+ GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE };
+ GCEVENT gce = { sizeof(gce), &gcd };
+ gce.bIsMe = TRUE;
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.ptszText = mir_utf8decodeT(data);
+ gce.time = time(NULL);
+ CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
+ mir_free((void*)gce.ptszText);
+ return;
+ }
+
+ CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)data);
+}
+
+void CDropbox::PasteToInputArea(MCONTACT hContact, const char* data)
+{
+ MessageWindowInputData mwid = { sizeof(MessageWindowInputData) };
+ mwid.hContact = hContact;
+ mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
+
+ MessageWindowData mwd = { sizeof(MessageWindowData) };
+ if (!CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd))
+ {
+ HWND hEdit = GetDlgItem(mwd.hwndWindow, 1002 /*IDC_MESSAGE*/);
+ if (!hEdit) hEdit = GetDlgItem(mwd.hwndWindow, 1009 /*IDC_CHATMESSAGE*/);
+
+ ptrT text(mir_utf8decodeT(data));
+ SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)text);
+ }
+}
+
+void CDropbox::PasteToClipboard(MCONTACT hContact, const char* data)
+{
+ if (OpenClipboard(NULL))
+ {
+ EmptyClipboard();
+ size_t size = sizeof(TCHAR) * (mir_strlen(data) + 1);
+ HGLOBAL hClipboardData = GlobalAlloc(NULL, size);
+ if (hClipboardData)
+ {
+ TCHAR *pchData = (TCHAR*)GlobalLock(hClipboardData);
+ if (pchData)
+ {
+ memcpy(pchData, (TCHAR*)data, size);
+ GlobalUnlock(hClipboardData);
+ SetClipboardData(CF_TEXT, hClipboardData);
+ }
+ }
+ CloseClipboard();
+ }
+}
+
+void CDropbox::Report(MCONTACT hContact, const char* data)
+{
+ if (db_get_b(NULL, MODULE, "UrlAutoSend", 1))
+ SendToContact(hContact, data);
+
+ if (db_get_b(NULL, MODULE, "UrlPasteToMessageInputArea", 0))
+ PasteToInputArea(hContact, data);
+
+ if (db_get_b(NULL, MODULE, "UrlCopyToClipboard", 0))
+ PasteToClipboard(hContact, data);
+}
diff --git a/plugins/Dropbox/src/stdafx.h b/plugins/Dropbox/src/stdafx.h index cf14580de3..ae52bb9fb4 100644 --- a/plugins/Dropbox/src/stdafx.h +++ b/plugins/Dropbox/src/stdafx.h @@ -24,6 +24,7 @@ #include <m_string.h>
#include <m_msg_buttonsbar.h>
#include <m_gui.h>
+#include <m_chat.h>
#include <m_protoint.h>
#include <m_protosvc.h>
diff --git a/plugins/Dropbox/src/version.h b/plugins/Dropbox/src/version.h index 69b84b0724..caacfd20a7 100644 --- a/plugins/Dropbox/src/version.h +++ b/plugins/Dropbox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 12
#define __RELEASE_NUM 0
-#define __BUILD_NUM 6
+#define __BUILD_NUM 7
#include <stdver.h>
|