From 13c08166b68ba098116faf827a66ce35c6e53d0f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 5 Jan 2015 14:25:08 +0000 Subject: StdMsg redesigned to add events into a database only after confirmation git-svn-id: http://svn.miranda-ng.org/main/trunk@11775 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdmsg/src/cmdlist.cpp | 47 +++++++++++++++++++++++++++---------- src/core/stdmsg/src/cmdlist.h | 6 ++--- src/core/stdmsg/src/commonheaders.h | 3 +++ src/core/stdmsg/src/msgdialog.cpp | 33 ++++---------------------- src/core/stdmsg/src/msgs.h | 6 ++--- src/core/stdmsg/src/msgtimedout.cpp | 6 ++--- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index e95b2b2051..f462ddbb14 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -45,13 +45,13 @@ static VOID CALLBACK MsgTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTi MessageFailureProcess(arTimedOut[i], LPGEN("The message send timed out.")); } -void msgQueue_add(MCONTACT hContact, int id, const TCHAR *szMsg, HANDLE hDbEvent) +void msgQueue_add(MCONTACT hContact, int id, char *szMsg, int flags) { TMsgQueue *item = (TMsgQueue*)mir_alloc(sizeof(TMsgQueue)); item->hContact = hContact; item->id = id; - item->szMsg = mir_tstrdup(szMsg); - item->hDbEvent = hDbEvent; + item->szMsg = szMsg; + item->flags = flags; item->ts = GetTickCount(); mir_cslock lck(csMsgQueue); @@ -60,7 +60,7 @@ void msgQueue_add(MCONTACT hContact, int id, const TCHAR *szMsg, HANDLE hDbEvent msgQueue.insert(item); } -void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* szErr) +TMsgQueue* msgQueue_find(MCONTACT hContact, int id) { MCONTACT hMeta = db_mc_getMeta(hContact); @@ -68,22 +68,45 @@ void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* sz for (int i = 0; i < msgQueue.getCount(); i++) { TMsgQueue *item = msgQueue[i]; if ((item->hContact == hContact || item->hContact == hMeta) && item->id == id) { - msgQueue.remove(i); i--; + msgQueue.remove(i); if (!msgQueue.getCount() && timerId) { KillTimer(NULL, timerId); timerId = 0; } - lck.unlock(); - if (success) { - mir_free(item->szMsg); - mir_free(item); - } - else MessageFailureProcess(item, szErr); - break; + return item; } } + return NULL; +} + +void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char *szErr) +{ + TMsgQueue *p = msgQueue_find(hContact, id); + if (p == NULL) + return; + + if (!success) { + MessageFailureProcess(p, szErr); + return; + } + + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.flags = DBEF_SENT | (p->flags & PREF_UTF ? DBEF_UTF : 0) | (p->flags & PREF_RTL ? DBEF_RTL : 0); + dbei.szModule = GetContactProto(hContact); + dbei.timestamp = time(0); + dbei.cbBlob = (DWORD)mir_strlen(p->szMsg); + dbei.pBlob = (PBYTE)p->szMsg; + + MessageWindowEvent evt = { sizeof(evt), id, hContact, &dbei }; + NotifyEventHooks(hHookWinWrite, 0, (LPARAM)&evt); + + db_event_add(hContact, &dbei); + + mir_free(p->szMsg); + mir_free(p); } void msgQueue_destroy(void) diff --git a/src/core/stdmsg/src/cmdlist.h b/src/core/stdmsg/src/cmdlist.h index caeac3cfd9..7c2d8dbe9c 100644 --- a/src/core/stdmsg/src/cmdlist.h +++ b/src/core/stdmsg/src/cmdlist.h @@ -26,12 +26,12 @@ struct TMsgQueue { int id; MCONTACT hContact; - TCHAR* szMsg; - HANDLE hDbEvent; + char *szMsg; + int flags; unsigned ts; }; -void msgQueue_add(MCONTACT hContact, int id, const TCHAR* szMsg, HANDLE hDbEvent); +void msgQueue_add(MCONTACT hContact, int id, char *szMsg, int flags); void msgQueue_processack(MCONTACT hContact, int id, BOOL success, const char* szErr); void msgQueue_destroy(void); diff --git a/src/core/stdmsg/src/commonheaders.h b/src/core/stdmsg/src/commonheaders.h index b1bfcd6a0d..eacbec6b3f 100644 --- a/src/core/stdmsg/src/commonheaders.h +++ b/src/core/stdmsg/src/commonheaders.h @@ -74,3 +74,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "version.h" extern HINSTANCE g_hInst; +extern HCURSOR hCurSplitNS, hCurSplitWE, hCurHyperlinkHand; +extern HANDLE hHookWinEvt, hHookWinPopup, hHookWinWrite; +extern CREOleCallback reOleCallback; diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 8652435ff6..f0bf138396 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -31,10 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SB_GRIP_WIDTH 20 // pixels - buffer used to prevent sizegrip from overwriting statusbar icons #define VALID_AVATAR(x) (x == PA_FORMAT_PNG || x == PA_FORMAT_JPEG || x == PA_FORMAT_ICON || x == PA_FORMAT_BMP || x == PA_FORMAT_GIF) -extern HCURSOR hCurSplitNS, hCurSplitWE, hCurHyperlinkHand; -extern HANDLE hHookWinEvt, hHookWinPopup, hHookWinWrite; -extern CREOleCallback reOleCallback; - static void UpdateReadChars(HWND hwndDlg, HWND hwndStatus); static const UINT infoLineControls[] = { IDC_PROTOCOL, IDC_NAME }; @@ -79,7 +75,7 @@ static int RTL_Detect(const TCHAR *ptszText) return 0; } -HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) +int SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) { if (hContact == NULL) return NULL; @@ -122,22 +118,8 @@ HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto) hContact = db_mc_getSrmmSub(hContact); int sendId = CallContactService(hContact, PSS_MESSAGE, flags, (LPARAM)sendBuffer); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = DBEF_SENT | (flags & PREF_UTF ? DBEF_UTF : 0) | (flags & PREF_RTL ? DBEF_RTL : 0); - dbei.szModule = szProto; - dbei.timestamp = (DWORD)time(NULL); - dbei.cbBlob = (DWORD)bufSize; - dbei.pBlob = (PBYTE)sendBuffer; - - MessageWindowEvent evt = { sizeof(evt), sendId, hContact, &dbei }; - NotifyEventHooks(hHookWinWrite, 0, (LPARAM)&evt); - - HANDLE hNewEvent = db_event_add(hContact, &dbei); - msgQueue_add(hContact, sendId, szMsg, hNewEvent); - mir_free(dbei.pBlob); - return hNewEvent; + msgQueue_add(hContact, sendId, sendBuffer, flags); + return sendId; } static void AddToFileList(TCHAR ***pppFiles, int *totalCount, const TCHAR* szFilename) @@ -1469,8 +1451,8 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (!temp[0]) break; - HANDLE hNewEvent = SendMessageDirect(temp, dat->hContact, dat->szProto); - if (hNewEvent) { + int sendId = SendMessageDirect(temp, dat->hContact, dat->szProto); + if (sendId) { dat->cmdList.insert(mir_tstrdup(temp)); dat->cmdListInd = -1; @@ -1480,11 +1462,6 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); - if (dat->hDbEventFirst == NULL) { - dat->hDbEventFirst = hNewEvent; - SendMessage(hwndDlg, DM_REMAKELOG, 0, 0); - } - SetDlgItemText(hwndDlg, IDC_MESSAGE, _T("")); if (g_dat.flags & SMF_AUTOCLOSE) diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index 5c20a45c09..0ce9aea114 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -122,10 +122,10 @@ struct CREOleCallback : public IRichEditOleCallback INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -int DbEventIsForMsgWindow(DBEVENTINFO *dbei); -int DbEventIsShown(DBEVENTINFO * dbei); +int DbEventIsForMsgWindow(DBEVENTINFO *dbei); +int DbEventIsShown(DBEVENTINFO * dbei); void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend); -HANDLE SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto); +int SendMessageDirect(const TCHAR *szMsg, MCONTACT hContact, char *szProto); void LoadMsgLogIcons(void); void FreeMsgLogIcons(void); diff --git a/src/core/stdmsg/src/msgtimedout.cpp b/src/core/stdmsg/src/msgtimedout.cpp index d20481c837..fd3f76e324 100644 --- a/src/core/stdmsg/src/msgtimedout.cpp +++ b/src/core/stdmsg/src/msgtimedout.cpp @@ -52,7 +52,7 @@ INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar mir_free(ptszError); } - SetDlgItemText(hwndDlg, IDC_MSGTEXT, item->szMsg); + SetDlgItemText(hwndDlg, IDC_MSGTEXT, ptrT(mir_utf8decodeT(item->szMsg))); GetWindowRect(hwndDlg, &rc); GetWindowRect(GetParent(hwndDlg), &rcParent); @@ -70,7 +70,7 @@ INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: - SendMessageDirect(item->szMsg, item->hContact, GetContactProto(item->hContact)); + SendMessageDirect(ptrT(mir_utf8decodeT(item->szMsg)), item->hContact, GetContactProto(item->hContact)); DestroyWindow(hwndDlg); break; @@ -85,8 +85,6 @@ INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar void MessageFailureProcess(TMsgQueue *item, const char* err) { - db_event_delete(item->hContact, item->hDbEvent); - HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, item->hContact); if (hwnd == NULL) { SendMessageCmd(item->hContact, NULL, 0); -- cgit v1.2.3