From ae739a66709d15079be7514c8cbc9eabb5c8b8b4 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 24 Apr 2015 19:53:21 +0000 Subject: Tox: - removed unneded "audio" events - fixed call dialog git-svn-id: http://svn.miranda-ng.org/main/trunk@13104 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/common.h | 5 +- protocols/Tox/src/resource.h | 2 +- protocols/Tox/src/tox_events.cpp | 19 +--- protocols/Tox/src/tox_multimedia.cpp | 177 +++++++++++++---------------------- protocols/Tox/src/tox_multimedia.h | 6 ++ protocols/Tox/src/tox_proto.h | 4 +- protocols/Tox/src/tox_utils.cpp | 12 +++ 7 files changed, 89 insertions(+), 136 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 3e20832f55..be70a8bf6b 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -89,10 +89,7 @@ extern HINSTANCE g_hInstance; enum TOX_DB_EVENT { DB_EVENT_ACTION = 10001, - DB_EVENT_AUDIO_CALL = 20001, - DB_EVENT_AUDIO_RING = 20002, - DB_EVENT_AUDIO_START = 20003, - DB_EVENT_AUDIO_END = 20004 + DB_EVENT_CALL = 20001 }; #define PSR_AUDIO "/RecvAudio" diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index 6bb9ffc284..593c8dec7a 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by D:\Projects\MirandaNG\protocols\Tox\res\resource.rc +// Used by e:\Projects\C++\MirandaNG\protocols\Tox\res\resource.rc // #define IDI_TOX 100 #define IDD_USER_INFO 101 diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 29a3a6eda6..e22ebb1c3c 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -21,23 +21,8 @@ void CToxProto::InitCustomDbEvents() dbEventType.descr = Translate("Action"); CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); - dbEventType.eventType = DB_EVENT_AUDIO_CALL; - dbEventType.descr = Translate("Outgoing call"); - dbEventType.eventIcon = GetIconHandle("audio_call"); - CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); - - dbEventType.eventType = DB_EVENT_AUDIO_RING; - dbEventType.descr = Translate("Incoming call"); - dbEventType.eventIcon = GetIconHandle("audio_ring"); - CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); - - dbEventType.eventType = DB_EVENT_AUDIO_START; - dbEventType.descr = Translate("Call started"); + dbEventType.eventType = DB_EVENT_CALL; + dbEventType.descr = Translate("Call"); dbEventType.eventIcon = GetIconHandle("audio_start"); CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); - - dbEventType.eventType = DB_EVENT_AUDIO_END; - dbEventType.descr = Translate("Call ended"); - dbEventType.eventIcon = GetIconHandle("audio_end"); - CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType); } \ No newline at end of file diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp index fa08e66ea5..0abf9634b7 100644 --- a/protocols/Tox/src/tox_multimedia.cpp +++ b/protocols/Tox/src/tox_multimedia.cpp @@ -7,13 +7,15 @@ CToxCallDlgBase::CToxCallDlgBase(CToxProto *proto, int idDialog, MCONTACT hConta void CToxCallDlgBase::OnInitDialog() { - Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, typeid(this).name()); + const char *className = typeid(this).name(); + Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, className); } void CToxCallDlgBase::OnClose() { //WindowList_Remove(m_proto->hAudioDialogs, m_hwnd); - Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, typeid(this).name()); + const char *className = typeid(this).name(); + Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, className); } INT_PTR CToxCallDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) @@ -68,16 +70,10 @@ void CToxIncomingCall::OnAnswer(CCtrlBase*) { ToxAvCSettings *cSettings = m_proto->GetAudioCSettings(); if (cSettings == NULL) - { - Close(); return; - } if (toxav_answer(m_proto->toxAv, m_proto->calls[hContact], cSettings) == TOX_ERROR) - { m_proto->debugLogA(__FUNCTION__": failed to start call"); - Close(); - } } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -126,16 +122,13 @@ void CToxOutgoingCall::OnCall(CCtrlBase*) } m_proto->calls[hContact] = callId; - char *message = mir_utf8encodeT(TranslateT("Outgoing call")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = m_proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_CALL; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + char *message = NULL; + TCHAR title[MAX_PATH]; + if(GetWindowText(m_hwnd, title, SIZEOF(title))) + message = mir_utf8encodeT(title); + else + message = mir_utf8encode("Outgoing call"); + m_proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); call.Enable(FALSE); SetIcon("audio_call"); @@ -278,11 +271,14 @@ void CToxProto::OnAvInvite(void*, int32_t callId, void *arg) return; } + TCHAR message[MAX_PATH]; + mir_sntprintf(message, SIZEOF(message), TranslateT("Incoming call from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); + PROTORECVEVENT recv = { 0 }; recv.timestamp = time(NULL); recv.lParam = callId; recv.flags = PREF_UTF; - recv.szMessage = mir_utf8encodeT(TranslateT("Incoming call")); + recv.szMessage = mir_utf8encodeT(message); ProtoChainRecv(hContact, PSR_AUDIO, hContact, (LPARAM)&recv); } @@ -293,28 +289,20 @@ INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam) calls[hContact] = pre->lParam; - char *message = mir_utf8encodeT(TranslateT("Incoming call")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = m_szModuleName; - dbei.timestamp = pre->timestamp; - dbei.eventType = DB_EVENT_AUDIO_RING; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - MEVENT hEvent = db_event_add(hContact, &dbei); + MEVENT hEvent = AddEventToDb(hContact, DB_EVENT_CALL, pre->timestamp, DBEF_UTF, (PBYTE)pre->szMessage, mir_strlen(pre->szMessage)); CLISTEVENT cle = { sizeof(cle) }; cle.flags |= CLEF_TCHAR; cle.hContact = hContact; cle.hDbEvent = hEvent; + cle.lParam = DB_EVENT_CALL; cle.hIcon = Skin_GetIconByHandle(GetIconHandle("audio_ring")); - TCHAR szTooltip[256]; + TCHAR szTooltip[MAX_PATH]; mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("Incoming call from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); cle.ptszTooltip = szTooltip; - char szService[256]; + char szService[MAX_PATH]; mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Ring", GetContactProto(hContact)); cle.pszService = szService; @@ -323,7 +311,7 @@ INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam) return hEvent; } -// +// react on clist event click INT_PTR CToxProto::OnAudioRing(WPARAM wParam, LPARAM lParam) { CLISTEVENT *cle = (CLISTEVENT*)lParam; @@ -354,20 +342,19 @@ void CToxProto::OnAvCancel(void*, int32_t callId, void *arg) return; } - CLISTEVENT *cle = (CLISTEVENT*)CallService(MS_CLIST_GETEVENT, hContact, 0); - if (cle) - CallService(MS_CLIST_REMOVEEVENT, hContact, cle->hDbEvent); - - char *message = mir_utf8encodeT(TranslateT("Call ended")); + int iEvent = 0; + CLISTEVENT *cle = NULL; + while ((cle = (CLISTEVENT*)CallService(MS_CLIST_GETEVENT, hContact, 0))) + { + if (cle->lParam == DB_EVENT_CALL) + { + CallService(MS_CLIST_REMOVEEVENT, hContact, cle->hDbEvent); + break; + } + } - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_END; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + char *message = mir_utf8encodeT(TranslateT("Call cancelled")); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); } @@ -404,16 +391,8 @@ void CToxProto::OnAvReject(void*, int32_t callId, void *arg) return; } - char *message = mir_utf8encodeT(TranslateT("Call ended")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_END; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + char *message = mir_utf8encodeT(TranslateT("Call cancelled")); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); } @@ -438,22 +417,36 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg) return; } - char *message = mir_utf8encodeT(TranslateT("Call ended")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_END; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + char *message = mir_utf8encodeT(TranslateT("Call cancelled")); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); } /* --- */ +static void CALLBACK WaveOutCallback(HWAVEOUT hOutDevice, UINT uMsg, DWORD/* dwInstance*/, DWORD dwParam1, DWORD/* dwParam2*/) +{ + switch (uMsg) + { + case WOM_DONE: + { + WAVEHDR *header = (WAVEHDR*)dwParam1; + if (header->dwFlags & WHDR_PREPARED) + waveOutUnprepareHeader(hOutDevice, header, sizeof(WAVEHDR)); + mir_free(header->lpData); + mir_free(header); + } + break; + } +} + +static void CALLBACK ToxShowDialogApcProc(void *arg) +{ + CDlgBase *callDlg = (CDlgBase*)arg; + callDlg->Show(); +} + void CToxProto::OnAvStart(void*, int32_t callId, void *arg) { CToxProto *proto = (CToxProto*)arg; @@ -483,7 +476,7 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg) wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; DWORD deviceId = proto->getDword("AudioOutputDeviceID", WAVE_MAPPER); - MMRESULT error = waveOutOpen(&proto->hOutDevice, deviceId, &wfx, (DWORD_PTR)&CToxProto::WaveOutCallback, (DWORD_PTR)proto, CALLBACK_FUNCTION); + MMRESULT error = waveOutOpen(&proto->hOutDevice, deviceId, &wfx, (DWORD_PTR)WaveOutCallback, (DWORD_PTR)proto, CALLBACK_FUNCTION); if (error != MMSYSERR_NOERROR) { proto->debugLogA(__FUNCTION__": failed to open audio device (%d)", error); @@ -522,19 +515,12 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg) } char *message = mir_utf8encodeT(TranslateT("Call started")); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_START; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); CDlgBase *callDlg = new CToxCallDialog(proto, hContact); - callDlg->Show(); - WindowList_Add(proto->hAudioDialogs, callDlg->GetHwnd(), hContact); + CallFunctionAsync(ToxShowDialogApcProc, callDlg); } void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) @@ -559,15 +545,7 @@ void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) } char *message = mir_utf8encodeT(TranslateT("Call ended")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_END; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); } @@ -596,16 +574,8 @@ void CToxProto::OnAvPeerTimeout(void*, int32_t callId, void *arg) if (cle) CallService(MS_CLIST_REMOVEEVENT, hContact, cle->hDbEvent); - char *message = mir_utf8encodeT(TranslateT("Call ended")); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = proto->m_szModuleName; - dbei.timestamp = time(NULL); - dbei.eventType = DB_EVENT_AUDIO_END; - dbei.flags = DBEF_UTF; - dbei.pBlob = (PBYTE)message; - dbei.cbSize = mir_strlen(message); - db_event_add(hContact, &dbei); + char *message = mir_utf8encodeT(TranslateT("Call cancelled")); + proto->AddEventToDb(hContact, DB_EVENT_CALL, time(NULL), DBEF_UTF, (PBYTE)message, mir_strlen(message)); WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0); @@ -614,23 +584,6 @@ void CToxProto::OnAvPeerTimeout(void*, int32_t callId, void *arg) ////// -void CToxProto::WaveOutCallback(HWAVEOUT m_hWO, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) -{ - CToxProto *proto = (CToxProto*)dwInstance; - switch (uMsg) - { - case WOM_DONE: - { - WAVEHDR *header = (WAVEHDR*)dwParam1; - if (header->dwFlags & WHDR_PREPARED) - waveOutUnprepareHeader(proto->hOutDevice, header, sizeof(WAVEHDR)); - mir_free(header->lpData); - mir_free(header); - } - break; - } -} - void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_t size, void *arg) { CToxProto *proto = (CToxProto*)arg; diff --git a/protocols/Tox/src/tox_multimedia.h b/protocols/Tox/src/tox_multimedia.h index 68f35bef56..6db47459ff 100644 --- a/protocols/Tox/src/tox_multimedia.h +++ b/protocols/Tox/src/tox_multimedia.h @@ -63,6 +63,12 @@ public: /////////////////////////////////////////////// +struct ToxCallDialogParam +{ + CToxProto *proto; + MCONTACT hContact; +}; + class CToxCallDialog : public CToxCallDlgBase { protected: diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 946dcb9039..075c4b4b26 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -248,8 +248,6 @@ private: HWAVEOUT hOutDevice; std::map calls; - static void CALLBACK WaveOutCallback(HWAVEOUT m_hWO, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); - ToxAvCSettings* GetAudioCSettings(); static void OnFriendAudio(void *agent, int32_t callId, const int16_t *PCM, uint16_t size, void *arg); @@ -275,6 +273,8 @@ private: static bool IsFileExists(std::tstring path); + MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, PBYTE pBlob, DWORD cbBlob); + template static INT_PTR __cdecl GlobalService(WPARAM wParam, LPARAM lParam) { diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 29e43d425b..68736bfd08 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -63,4 +63,16 @@ void CToxProto::ShowNotification(const TCHAR *message, int flags, MCONTACT hCont bool CToxProto::IsFileExists(std::tstring path) { return _taccess(path.c_str(), 0) == 0; +} + +MEVENT CToxProto::AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, PBYTE pBlob, DWORD cbBlob) +{ + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.szModule = this->m_szModuleName; + dbei.timestamp = timestamp; + dbei.eventType = type; + dbei.cbBlob = cbBlob; + dbei.pBlob = pBlob; + dbei.flags = flags; + return db_event_add(hContact, &dbei); } \ No newline at end of file -- cgit v1.2.3