From 89d8352ac748a706b3480e04ab02831434701061 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 14 Aug 2012 19:06:19 +0000 Subject: dunno why the old code crashes, but the new one doesn't git-svn-id: http://svn.miranda-ng.org/main/trunk@1457 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/commonheaders.h | 1 + plugins/TabSRMM/src/eventpopups.cpp | 116 ++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 66 deletions(-) diff --git a/plugins/TabSRMM/src/commonheaders.h b/plugins/TabSRMM/src/commonheaders.h index 060c78652c..28a90ca0b9 100644 --- a/plugins/TabSRMM/src/commonheaders.h +++ b/plugins/TabSRMM/src/commonheaders.h @@ -183,6 +183,7 @@ #include #include #include +#include #include #include #include diff --git a/plugins/TabSRMM/src/eventpopups.cpp b/plugins/TabSRMM/src/eventpopups.cpp index 8cf487555f..ee6fb57d43 100644 --- a/plugins/TabSRMM/src/eventpopups.cpp +++ b/plugins/TabSRMM/src/eventpopups.cpp @@ -524,89 +524,73 @@ static BOOL CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM * * @return */ + static TCHAR *GetPreviewT(WORD eventType, DBEVENTINFO* dbe) { - TCHAR *commentFix = NULL; char *pBlob = (char *)dbe->pBlob; bool fAddEllipsis = false; - int iPreviewLimit = nen_options.iLimitPreview; - + int iPreviewLimit = nen_options.iLimitPreview; if (iPreviewLimit > 500 || iPreviewLimit == 0) iPreviewLimit = 500; switch (eventType) { - case EVENTTYPE_MESSAGE: - if (pBlob) { - if (nen_options.bPreview) { - TCHAR* buf = DbGetEventTextT(dbe, CP_ACP); - if (lstrlen(buf) > iPreviewLimit) { - fAddEllipsis = true; - int iIndex = iPreviewLimit; - int iWordThreshold = 20; - while(iIndex && buf[iIndex] != ' ' && iWordThreshold--) { - buf[iIndex--] = 0; - } - buf[iIndex] = 0; + case EVENTTYPE_MESSAGE: + if (pBlob) { + if (nen_options.bPreview) { + TCHAR* buf = DbGetEventTextT(dbe, CP_ACP); + if (lstrlen(buf) > iPreviewLimit) { + fAddEllipsis = true; + int iIndex = iPreviewLimit; + int iWordThreshold = 20; + while(iIndex && buf[iIndex] != ' ' && iWordThreshold--) { + buf[iIndex--] = 0; } - buf = (TCHAR *)mir_realloc(buf, (lstrlen(buf) + 5) * sizeof(TCHAR)); - if (fAddEllipsis) - _tcscat(buf, _T("...")); - return(buf); + buf[iIndex] = 0; } + buf = (TCHAR *)mir_realloc(buf, (lstrlen(buf) + 5) * sizeof(TCHAR)); + if (fAddEllipsis) + _tcscat(buf, _T("...")); + return buf; } - commentFix = mir_tstrdup(TranslateT("Message")); - break; - case EVENTTYPE_FILE: - if (pBlob) { - if (!nen_options.bPreview) { - commentFix = mir_tstrdup(TranslateT("Incoming file")); - break; - } - if (dbe->cbBlob > 5) { // min valid size = (sizeof(DWORD) + 1 character file name + terminating 0) - char* szFileName = (char *)dbe->pBlob + sizeof(DWORD); - char* szDescr = 0; - size_t namelength = Utils::safe_strlen(szFileName, dbe->cbBlob - sizeof(DWORD)); - - if (dbe->cbBlob > (sizeof(DWORD) + namelength + 1)) - szDescr = szFileName + namelength + 1; - - TCHAR* tszFileName = DbGetEventStringT(dbe, szFileName ); - TCHAR* buf = 0; - - if (szDescr && Utils::safe_strlen(szDescr, dbe->cbBlob - sizeof(DWORD) - namelength - 1) > 0) { - TCHAR* tszDescr = DbGetEventStringT(dbe, szDescr); - - if (tszFileName && tszDescr) { - size_t uRequired = sizeof(TCHAR) * (_tcslen(TranslateT("Incoming file")) + namelength + _tcslen(tszDescr) + 10); - buf = (TCHAR *)mir_alloc(uRequired); - mir_sntprintf(buf, uRequired, _T("%s: %s (%s)"), TranslateT("Incoming file"), - tszFileName, tszDescr); - mir_free(tszDescr); - mir_free(tszFileName); - return(buf); - } - } + } + return mir_tstrdup( TranslateT("Message")); - if (tszFileName) { - size_t uRequired = sizeof(TCHAR) * (_tcslen(TranslateT("Incoming file")) + namelength + - _tcslen(TranslateT("No description given")) + 10); - buf = (TCHAR *)mir_alloc(uRequired); - mir_sntprintf(buf, uRequired, _T("%s: %s (%s)"), TranslateT("Incoming file"), - tszFileName, TranslateT("No description given")); - mir_free(tszFileName); + case EVENTTYPE_FILE: + if (pBlob) { + if (!nen_options.bPreview) + return mir_tstrdup(TranslateT("Incoming file")); + + if (dbe->cbBlob > 5) { // min valid size = (sizeof(DWORD) + 1 character file name + terminating 0) + char* szFileName = (char *)dbe->pBlob + sizeof(DWORD); + char* szDescr = 0; + size_t namelength = Utils::safe_strlen(szFileName, dbe->cbBlob - sizeof(DWORD)); + + if (dbe->cbBlob > (sizeof(DWORD) + namelength + 1)) + szDescr = szFileName + namelength + 1; + + mir_ptr tszFileName( DbGetEventStringT(dbe, szFileName)); + TCHAR buf[1024]; + + if (szDescr && Utils::safe_strlen(szDescr, dbe->cbBlob - sizeof(DWORD) - namelength - 1) > 0) { + mir_ptr tszDescr( DbGetEventStringT(dbe, szDescr)); + if (tszFileName && tszDescr) { + mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s (%s)"), TranslateT("Incoming file"), tszFileName, tszDescr); + return mir_tstrdup(buf); } - if (buf) - return(buf); + } + + if (tszFileName) { + mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s (%s)"), TranslateT("Incoming file"), tszFileName, TranslateT("No description given")); + return mir_tstrdup(buf); } } - commentFix = mir_tstrdup(TranslateT("Incoming file (invalid format")); - break; - default: - commentFix = mir_tstrdup(TranslateT("Unknown event")); - break; + } + return mir_tstrdup(TranslateT("Incoming file (invalid format")); + + default: + return mir_tstrdup(TranslateT("Unknown event")); } - return commentFix; } static int PopupUpdateT(HANDLE hContact, HANDLE hEvent) -- cgit v1.2.3