summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-04-26 15:19:01 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-04-26 15:19:09 +0300
commit68f119cb70d7047c20910ea6db33c3bc94149a75 (patch)
tree27d17ab42b1e9b8a55df7352b7d8b3e104f89b1c
parent27987283c94b4e9f3f966ca3336d4dfb8c8992be (diff)
Chat api:
- function Chat_GetDefaultEventDescr() added not to translate the same strings in 5 different places; - function CHAT_INTERFACE::CreateNick added to process nick name creation for group chats; - unused variable LOGINFO::dwFlags removed; - variable LOGINFO::bSimple added for events without possible formatting; - bunch of duplicate code remoed;
-rw-r--r--include/m_chat.h12
-rw-r--r--include/m_chat_int.h11
-rw-r--r--include/m_srmm_int.h1
-rw-r--r--libs/win32/mir_app.libbin204724 -> 204628 bytes
-rw-r--r--libs/win64/mir_app.libbin200360 -> 200230 bytes
-rw-r--r--plugins/TabSRMM/src/chat.h2
-rw-r--r--plugins/TabSRMM/src/chat_log.cpp115
-rw-r--r--plugins/TabSRMM/src/chat_main.cpp3
-rw-r--r--plugins/TabSRMM/src/chat_manager.cpp20
-rw-r--r--plugins/TabSRMM/src/msgs.h2
-rw-r--r--src/mir_app/src/chat_log.cpp144
-rw-r--r--src/mir_app/src/chat_manager.cpp17
-rw-r--r--src/mir_app/src/chat_tools.cpp104
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
15 files changed, 187 insertions, 246 deletions
diff --git a/include/m_chat.h b/include/m_chat.h
index d3b91c1e3d..446124f1b2 100644
--- a/include/m_chat.h
+++ b/include/m_chat.h
@@ -351,9 +351,9 @@ EXTERN_C MIR_APP_DLL(struct SESSION_INFO*) Chat_NewSession(
struct GCEVENT
{
- LPCSTR pszModule; // Name of the protocol (same as you registered with)
+ LPCSTR pszModule; // Name of the protocol (same as you registered with)
MAllCStrings pszID; // Unique identifier of the session, or NULL to broadcast to all sessions as specified above
- int iType; // Use GC_EVENT_* as defined above. Only one event per service call.
+ int iType; // Use GC_EVENT_* as defined above. Only one event per service call.
MAllCStrings pszText; //
MAllCStrings pszNick; //
@@ -361,11 +361,11 @@ struct GCEVENT
MAllCStrings pszStatus; //
MAllCStrings pszUserInfo; //
- BOOL bIsMe; // Is this event from the Miranda user?
- DWORD dwFlags; // event flags: GCEF_*
+ BOOL bIsMe; // Is this event from the Miranda user?
+ DWORD dwFlags; // event flags: GCEF_*
- INT_PTR dwItemData; // User specified data.
- DWORD time; // Timestamp of the event
+ INT_PTR dwItemData; // User specified data.
+ DWORD time; // Timestamp of the event
};
EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT*);
diff --git a/include/m_chat_int.h b/include/m_chat_int.h
index 68de22ce03..24f368caf4 100644
--- a/include/m_chat_int.h
+++ b/include/m_chat_int.h
@@ -121,11 +121,11 @@ struct LOGINFO
wchar_t *ptszUID;
wchar_t *ptszStatus;
wchar_t *ptszUserInfo;
- BOOL bIsMe;
- BOOL bIsHighlighted;
+ bool bIsMe;
+ bool bIsHighlighted;
+ bool bSimple;
time_t time;
int iType;
- DWORD dwFlags;
LOGINFO *next, *prev;
};
@@ -334,6 +334,7 @@ struct CHAT_MANAGER
void (*ReloadSettings)(void);
int (*DoRtfToTags)(CMStringW &pszText, int iNumColors, COLORREF *pColors);
+ void (*CreateNick)(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &dest);
int logPixelSY, logPixelSX;
char *szActiveWndModule;
@@ -397,4 +398,8 @@ EXTERN_C MIR_APP_DLL(BOOL) Chat_DoEventHook(SESSION_INFO *si, int iType, const U
// calculates width or height of a string
EXTERN_C MIR_APP_DLL(int) Chat_GetTextPixelSize(const wchar_t *pszText, HFONT hFont, bool bWidth);
+// creates a default description of a groupchat event
+// returns true if lin->ptszText is already utilized, you need to add it manually then otherwise
+EXTERN_C MIR_APP_DLL(bool) Chat_GetDefaultEventDescr(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &res);
+
#endif // M_CHAT_INT_H__
diff --git a/include/m_srmm_int.h b/include/m_srmm_int.h
index d81426d63b..8c95a761fa 100644
--- a/include/m_srmm_int.h
+++ b/include/m_srmm_int.h
@@ -248,6 +248,7 @@ public:
virtual LRESULT WndProc_Nicklist(UINT msg, WPARAM wParam, LPARAM lParam);
__forceinline bool isChat() const { return m_si != nullptr; }
+ __forceinline SESSION_INFO *getChat() const { return m_si; }
__forceinline CSrmmLogWindow *log() const { return m_pLog; }
__inline void *operator new(size_t size) { return calloc(1, size); }
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index 3c29c31e24..c65803b3a1 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index 39a656ef22..f614fce63c 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/plugins/TabSRMM/src/chat.h b/plugins/TabSRMM/src/chat.h
index 8e64d6c09b..abb39a9634 100644
--- a/plugins/TabSRMM/src/chat.h
+++ b/plugins/TabSRMM/src/chat.h
@@ -118,6 +118,8 @@ SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* cu
BOOL SM_ReconfigureFilters();
+void OnCreateNick(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &wszNick);
+
int UM_CompareItem(const USERINFO *u1, const USERINFO *u2);
// tools.c
diff --git a/plugins/TabSRMM/src/chat_log.cpp b/plugins/TabSRMM/src/chat_log.cpp
index 9af0f40605..837a457a76 100644
--- a/plugins/TabSRMM/src/chat_log.cpp
+++ b/plugins/TabSRMM/src/chat_log.cpp
@@ -133,18 +133,9 @@ static int EventToIcon(LOGINFO *lin)
return 0;
}
-static void Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, CMStringA &str, const wchar_t *fmt, ...)
+static void Log_AppendRTF(LOGSTREAMDATA *streamData, bool simpleMode, CMStringA &str, const wchar_t *line)
{
int textCharsCount = 0;
- wchar_t *line = (wchar_t *)_alloca(8001 * sizeof(wchar_t));
-
- va_list va;
- va_start(va, fmt);
- int lineLen = mir_vsnwprintf(line, 8000, fmt, va);
- if (lineLen < 0)
- lineLen = 8000;
- line[lineLen] = 0;
- va_end(va);
CMStringA res;
@@ -234,94 +225,14 @@ static void AddEventToBuffer(CMStringA &str, LOGSTREAMDATA *streamData)
if (streamData == nullptr || streamData->lin == nullptr)
return;
- CMStringW wszNick;
- if (streamData->lin->ptszNick) {
- if (g_Settings.bLogLimitNames && mir_wstrlen(streamData->lin->ptszNick) > 20) {
- wszNick.Append(streamData->lin->ptszNick, 20);
- wszNick.Append(L"...");
- }
- else wszNick.Append(streamData->lin->ptszNick);
-
- if (g_Settings.bClickableNicks) {
- wszNick.Insert(0, CLICKNICK_BEGIN);
- wszNick.Append(CLICKNICK_END);
- }
-
- if (streamData->lin->ptszUserInfo && streamData->lin->iType != GC_EVENT_TOPIC)
- wszNick.AppendFormat(L" (%s)", streamData->lin->ptszUserInfo);
- }
-
- switch (streamData->lin->iType) {
- case GC_EVENT_MESSAGE:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, L"%s", streamData->lin->ptszText);
- break;
- case GC_EVENT_ACTION:
- if (streamData->lin->ptszNick && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, str, L"%s ", streamData->lin->ptszNick);
- Log_AppendRTF(streamData, FALSE, str, L"%s", streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_JOIN:
- if (!wszNick.IsEmpty()) {
- if (!streamData->lin->bIsMe)
- /* replace nick of a newcomer with a link */
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s has joined"), wszNick.c_str());
- else
- Log_AppendRTF(streamData, TRUE, str, TranslateT("You have joined %s"), streamData->si->ptszName);
- }
- break;
- case GC_EVENT_PART:
- if (!wszNick.IsEmpty())
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s has left"), wszNick.c_str());
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, L": %s", streamData->lin->ptszText);
- break;
- case GC_EVENT_QUIT:
- if (!wszNick.IsEmpty())
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s has disconnected"), wszNick.c_str());
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, L": %s", streamData->lin->ptszText);
- break;
- case GC_EVENT_NICK:
- if (!wszNick.IsEmpty() && streamData->lin->ptszText) {
- if (!streamData->lin->bIsMe)
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s is now known as %s"), wszNick.c_str(), streamData->lin->ptszText);
- else
- Log_AppendRTF(streamData, TRUE, str, TranslateT("You are now known as %s"), streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_KICK:
- if (!wszNick.IsEmpty() && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s kicked %s"), streamData->lin->ptszStatus, wszNick.c_str());
-
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, L": %s", streamData->lin->ptszText);
- break;
- case GC_EVENT_NOTICE:
- if (!wszNick.IsEmpty() && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, str, TranslateT("Notice from %s: "), wszNick.c_str());
- Log_AppendRTF(streamData, FALSE, str, L"%s", streamData->lin->ptszText);
- }
- break;
- case GC_EVENT_TOPIC:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, TranslateT("The topic is '%s%s'"), streamData->lin->ptszText, L"%r");
- if (!wszNick.IsEmpty())
- Log_AppendRTF(streamData, TRUE, str, (streamData->lin->ptszUserInfo) ? TranslateT(" (set by %s on %s)") : TranslateT(" (set by %s)"), wszNick.c_str(), streamData->lin->ptszUserInfo);
- break;
- case GC_EVENT_INFORMATION:
- if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, str, (streamData->lin->bIsMe) ? L"--> %s" : L"%s", streamData->lin->ptszText);
- break;
- case GC_EVENT_ADDSTATUS:
- if (!wszNick.IsEmpty() && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s enables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, wszNick.c_str());
- break;
- case GC_EVENT_REMOVESTATUS:
- if (!wszNick.IsEmpty() && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, str, TranslateT("%s disables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, wszNick.c_str());
- break;
+ CMStringW wszCaption;
+ bool bTextUsed = Chat_GetDefaultEventDescr(streamData->si, streamData->lin, wszCaption);
+ if (!wszCaption.IsEmpty())
+ Log_AppendRTF(streamData, !bTextUsed, str, wszCaption);
+ if (!bTextUsed && streamData->lin->ptszText) {
+ if (!wszCaption.IsEmpty())
+ Log_AppendRTF(streamData, false, str, L": ");
+ Log_AppendRTF(streamData, false, str, streamData->lin->ptszText);
}
}
@@ -468,7 +379,7 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData)
wcsncpy_s(szOldTimeStamp, g_chatApi.MakeTimeStamp(g_Settings.pszTimeStamp, si->LastTime), _TRUNCATE);
if (!g_Settings.bShowTimeIfChanged || si->LastTime == 0 || mir_wstrcmp(szTimeStamp, szOldTimeStamp)) {
si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, str, L"%s", szTimeStamp);
+ Log_AppendRTF(streamData, TRUE, str, szTimeStamp);
}
str.Append("\\tab ");
}
@@ -488,19 +399,19 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData)
str.Append(pszIndicator);
CMStringW pszTemp(lin->bIsMe ? g_Settings.pszOutgoingNick : g_Settings.pszIncomingNick);
- pszTemp.Replace(L"%n", L"%s");
if (!lin->bIsMe) {
if (g_Settings.bClickableNicks)
- pszTemp.Replace(L"%s", CLICKNICK_BEGIN L"%s" CLICKNICK_END);
+ pszTemp.Replace(L"%n", CLICKNICK_BEGIN L"%n" CLICKNICK_END);
if (g_Settings.bColorizeNicksInLog && pszIndicator[0])
str.AppendFormat("\\cf%u ", OPTIONS_FONTCOUNT + Utils::rtf_clrs.getCount() + streamData->crCount + crNickIndex);
}
+ pszTemp.Replace(L"%n", lin->ptszNick);
if (g_Settings.bNewLineAfterNames)
pszTemp.AppendChar('\n');
- Log_AppendRTF(streamData, TRUE, str, pszTemp, lin->ptszNick);
+ Log_AppendRTF(streamData, TRUE, str, pszTemp);
str.AppendChar(' ');
}
diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp
index ecea5d89e5..45a64cb83d 100644
--- a/plugins/TabSRMM/src/chat_main.cpp
+++ b/plugins/TabSRMM/src/chat_main.cpp
@@ -353,7 +353,8 @@ int Chat_Load()
CHAT_MANAGER_INITDATA data = { &g_Settings, sizeof(MODULEINFO), sizeof(SESSION_INFO), LPGENW("Message sessions") L"/" LPGENW("Group chats"), FONTMODE_ALTER, &g_plugin };
Chat_CustomizeApi(&data);
-
+
+ g_chatApi.CreateNick = OnCreateNick;
g_chatApi.MM_CreateModule = MM_CreateModule;
g_chatApi.OnCreateModule = OnCreateModule;
g_chatApi.OnNewUser = OnNewUser;
diff --git a/plugins/TabSRMM/src/chat_manager.cpp b/plugins/TabSRMM/src/chat_manager.cpp
index b1c6a78e9a..1639b446e1 100644
--- a/plugins/TabSRMM/src/chat_manager.cpp
+++ b/plugins/TabSRMM/src/chat_manager.cpp
@@ -118,3 +118,23 @@ SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO* cu
return pResult;
}
+
+void OnCreateNick(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &wszNick)
+{
+ if (lin->ptszNick) {
+ if (g_Settings.bLogLimitNames && mir_wstrlen(lin->ptszNick) > 20) {
+ wszNick.Append(lin->ptszNick, 20);
+ wszNick.Append(L"...");
+ }
+ else wszNick.Append(lin->ptszNick);
+
+ int logMode = (si->pDlg) ? si->pDlg->m_iLogMode : 1;
+ if (g_Settings.bClickableNicks && !logMode && !lin->bSimple) {
+ wszNick.Insert(0, CLICKNICK_BEGIN);
+ wszNick.Append(CLICKNICK_END);
+ }
+
+ if (lin->ptszUserInfo && lin->iType != GC_EVENT_TOPIC)
+ wszNick.AppendFormat(L" (%s)", lin->ptszUserInfo);
+ }
+}
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h
index 60d429910d..31da231d74 100644
--- a/plugins/TabSRMM/src/msgs.h
+++ b/plugins/TabSRMM/src/msgs.h
@@ -409,7 +409,6 @@ class CMsgDialog : public CSrmmBaseDialog
int m_originalSplitterY;
SIZE m_minEditBoxSize;
int m_nTypeMode;
- int m_iLogMode;
DWORD m_nLastTyping;
DWORD m_lastMessage;
DWORD m_dwTickLastEvent;
@@ -460,6 +459,7 @@ protected:
public:
char *m_szProto;
int m_iTabID;
+ int m_iLogMode;
BYTE m_bShowTyping;
bool m_bIsHistory, m_bNotOnList, m_bIsIdle;
bool m_bActualHistory;
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp
index 5308ea58fa..ff61461d4f 100644
--- a/src/mir_app/src/chat_log.cpp
+++ b/src/mir_app/src/chat_log.cpp
@@ -86,19 +86,9 @@ char* Log_SetStyle(int style)
return "";
}
-static int Log_AppendRTF(LOGSTREAMDATA *streamData, bool simpleMode, CMStringA &buf, const wchar_t *fmt, ...)
+static int Log_AppendRTF(LOGSTREAMDATA *streamData, bool simpleMode, CMStringA &buf, const wchar_t *line)
{
- va_list va;
- int lineLen, textCharsCount = 0;
- wchar_t *line = (wchar_t*)alloca(8001 * sizeof(wchar_t));
-
- va_start(va, fmt);
- lineLen = mir_vsnwprintf(line, 8000, fmt, va);
- if (lineLen < 0) lineLen = 8000;
- line[lineLen] = 0;
- va_end(va);
-
- lineLen = lineLen * 20 + 8;
+ int textCharsCount = 0;
for (; *line; line++, textCharsCount++) {
if (*line == '\r' && line[1] == '\n') {
@@ -189,97 +179,89 @@ static int Log_AppendRTF(LOGSTREAMDATA *streamData, bool simpleMode, CMStringA &
return textCharsCount;
}
-static void AddEventToBuffer(CMStringA &buf, LOGSTREAMDATA *streamData)
+MIR_APP_DLL(bool) Chat_GetDefaultEventDescr(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &res)
{
- LOGINFO *lin = streamData->lin;
-
- wchar_t szTemp[512], szTemp2[512];
- wchar_t* pszNick = nullptr;
- if (lin->ptszNick) {
- if (g_Settings->bLogLimitNames && mir_wstrlen(lin->ptszNick) > 20) {
- mir_wstrncpy(szTemp2, lin->ptszNick, 20);
- mir_wstrncpy(szTemp2 + 20, L"...", 4);
- }
- else mir_wstrncpy(szTemp2, lin->ptszNick, 511);
-
- if (lin->ptszUserInfo)
- mir_snwprintf(szTemp, L"%s (%s)", szTemp2, lin->ptszUserInfo);
- else
- wcsncpy_s(szTemp, szTemp2, _TRUNCATE);
- pszNick = szTemp;
- }
+ CMStringW wszNick;
+ g_chatApi.CreateNick(si, lin, wszNick);
switch (lin->iType) {
- case GC_EVENT_MESSAGE:
- if (lin->ptszText)
- Log_AppendRTF(streamData, false, buf, L"%s", lin->ptszText);
- break;
case GC_EVENT_ACTION:
- if (lin->ptszNick && lin->ptszText) {
- Log_AppendRTF(streamData, true, buf, L"%s ", lin->ptszNick);
- Log_AppendRTF(streamData, false, buf, L"%s", lin->ptszText);
- }
+ if (lin->ptszNick)
+ res = lin->ptszNick;
break;
+
case GC_EVENT_JOIN:
- if (pszNick) {
- if (!lin->bIsMe)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s has joined"), pszNick);
- else
- Log_AppendRTF(streamData, false, buf, TranslateT("You have joined %s"), streamData->si->ptszName);
+ if (!lin->bIsMe) {
+ if (!wszNick.IsEmpty())
+ res.AppendFormat(TranslateT("%s has joined"), wszNick.c_str());
}
+ else res.AppendFormat(TranslateT("You have joined %s"), si->ptszName);
break;
+
case GC_EVENT_PART:
- if (pszNick)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s has left"), pszNick);
- if (lin->ptszText)
- Log_AppendRTF(streamData, true, buf, L": %s", lin->ptszText);
+ if (!wszNick.IsEmpty())
+ res.AppendFormat(TranslateT("%s has left"), wszNick.c_str());
break;
+
case GC_EVENT_QUIT:
- if (pszNick)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s has disconnected"), pszNick);
- if (lin->ptszText)
- Log_AppendRTF(streamData, false, buf, L": %s", lin->ptszText);
+ if (!wszNick.IsEmpty())
+ res.AppendFormat(TranslateT("%s has disconnected"), wszNick.c_str());
break;
+
case GC_EVENT_NICK:
- if (pszNick && lin->ptszText) {
- if (!lin->bIsMe)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s is now known as %s"), pszNick, lin->ptszText);
- else
- Log_AppendRTF(streamData, true, buf, TranslateT("You are now known as %s"), lin->ptszText);
+ if (!lin->bIsMe) {
+ if (!wszNick.IsEmpty())
+ res.AppendFormat(TranslateT("%s is now known as %s"), wszNick.c_str(), lin->ptszText);
}
- break;
+ else res.AppendFormat(TranslateT("You are now known as %s"), lin->ptszText);
+ return true;
+
case GC_EVENT_KICK:
if (lin->ptszNick && lin->ptszStatus)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s kicked %s"), lin->ptszStatus, lin->ptszNick);
- if (lin->ptszText)
- Log_AppendRTF(streamData, false, buf, L": %s", lin->ptszText);
+ res.AppendFormat(TranslateT("%s kicked %s"), lin->ptszStatus, lin->ptszNick);
break;
+
case GC_EVENT_NOTICE:
- if (pszNick && lin->ptszText) {
- Log_AppendRTF(streamData, true, buf, TranslateT("Notice from %s: "), pszNick);
- Log_AppendRTF(streamData, false, buf, L"%s", lin->ptszText);
- }
+ if (!wszNick.IsEmpty())
+ res.AppendFormat(TranslateT("Notice from %s"), wszNick.c_str());
break;
+
case GC_EVENT_TOPIC:
if (lin->ptszText)
- Log_AppendRTF(streamData, false, buf, TranslateT("The topic is '%s%s'"), lin->ptszText, L"%r");
+ res.AppendFormat(TranslateT("The topic is '%s'"), lin->ptszText);
if (lin->ptszNick)
- Log_AppendRTF(streamData, true, buf,
- lin->ptszUserInfo ? TranslateT(" (set by %s on %s)") : TranslateT(" (set by %s)"),
- lin->ptszNick, lin->ptszUserInfo);
- break;
+ res.AppendFormat((lin->ptszUserInfo) ? TranslateT(" (set by %s on %s)") : TranslateT(" (set by %s)"), lin->ptszNick, lin->ptszUserInfo);
+ return true;
+
case GC_EVENT_INFORMATION:
if (lin->ptszText)
- Log_AppendRTF(streamData, false, buf, (lin->bIsMe) ? L"--> %s" : L"%s", lin->ptszText);
- break;
+ res.AppendFormat((lin->bIsMe) ? L"--> %s" : L"%s", lin->ptszText);
+ return true;
+
case GC_EVENT_ADDSTATUS:
if (lin->ptszNick && lin->ptszText && lin->ptszStatus)
- Log_AppendRTF(streamData, true, buf, TranslateT("%s enables '%s' status for %s"), lin->ptszText, lin->ptszStatus, lin->ptszNick);
- break;
+ res.AppendFormat(TranslateT("%s enables '%s' status for %s"), lin->ptszText, lin->ptszStatus, lin->ptszNick);
+ return true;
+
case GC_EVENT_REMOVESTATUS:
if (lin->ptszNick && lin->ptszText && lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buf, TranslateT("%s disables '%s' status for %s"), lin->ptszText, lin->ptszStatus, lin->ptszNick);
- break;
+ res.AppendFormat(TranslateT("%s disables '%s' status for %s"), lin->ptszText, lin->ptszStatus, lin->ptszNick);
+ return true;
+ }
+
+ return false;
+}
+
+static void AddEventToBuffer(CMStringA &buf, LOGSTREAMDATA *streamData)
+{
+ CMStringW wszCaption;
+ bool bTextUsed = Chat_GetDefaultEventDescr(streamData->si, streamData->lin, wszCaption);
+ if (!wszCaption.IsEmpty())
+ Log_AppendRTF(streamData, !bTextUsed, buf, wszCaption);
+ if (!bTextUsed && streamData->lin->ptszText) {
+ if (!wszCaption.IsEmpty())
+ Log_AppendRTF(streamData, false, buf, L": ");
+ Log_AppendRTF(streamData, false, buf, streamData->lin->ptszText);
}
}
@@ -349,22 +331,18 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData)
wcsncpy_s(szOldTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, si->LastTime), _TRUNCATE);
if (!g_Settings->bShowTimeIfChanged || si->LastTime == 0 || mir_wstrcmp(szTimeStamp, szOldTimeStamp)) {
si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, buf, L"%s", szTimeStamp);
+ Log_AppendRTF(streamData, true, buf, szTimeStamp);
}
buf.Append("\\tab ");
}
// Insert the nick
if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
- wchar_t pszTemp[300], *p1;
-
buf.AppendFormat("%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
- mir_wstrncpy(pszTemp, lin->bIsMe ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick, 299);
- p1 = wcsstr(pszTemp, L"%n");
- if (p1)
- p1[1] = 's';
- Log_AppendRTF(streamData, TRUE, buf, pszTemp, lin->ptszNick);
+ CMStringW tmp((lin->bIsMe) ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick);
+ tmp.Replace(L"%n", lin->ptszNick);
+ Log_AppendRTF(streamData, TRUE, buf, tmp);
buf.AppendChar(' ');
}
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp
index e1b1627741..3111d6f548 100644
--- a/src/mir_app/src/chat_manager.cpp
+++ b/src/mir_app/src/chat_manager.cpp
@@ -846,6 +846,22 @@ BOOL UM_RemoveAll(SESSION_INFO *si)
/////////////////////////////////////////////////////////////////////////////////////////
+static void CreateNick(const SESSION_INFO *, const LOGINFO *lin, CMStringW &wszNick)
+{
+ if (lin->ptszNick) {
+ wszNick = lin->ptszNick;
+ if (g_Settings->bLogLimitNames && mir_wstrlen(lin->ptszNick) > 20) {
+ wszNick.Truncate(20);
+ wszNick.Append(L"...");
+ }
+
+ if (lin->ptszUserInfo && lin->iType != GC_EVENT_TOPIC)
+ wszNick.AppendFormat(L" (%s)", lin->ptszUserInfo);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static void ResetApi()
{
g_chatApi.SetActiveSession = ::SetActiveSession;
@@ -898,6 +914,7 @@ static void ResetApi()
g_chatApi.GetChatLogsFilename = ::GetChatLogsFilename;
g_chatApi.Log_SetStyle = ::Log_SetStyle;
+ g_chatApi.CreateNick = ::CreateNick;
g_chatApi.IsHighlighted = ::IsHighlighted;
g_chatApi.RemoveFormatting = ::RemoveFormatting;
g_chatApi.ReloadSettings = ::LoadGlobalSettings;
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp
index 9a514bb6cd..8602f59168 100644
--- a/src/mir_app/src/chat_tools.cpp
+++ b/src/mir_app/src/chat_tools.cpp
@@ -26,6 +26,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma comment(lib, "Shlwapi.lib")
+struct fakeLOGINFO : public LOGINFO
+{
+ fakeLOGINFO(const GCEVENT *gce)
+ {
+ bSimple = true;
+ bIsMe = gce->bIsMe;
+ iType = gce->iType;
+ ptszText = (wchar_t *)gce->pszText.w;
+ ptszNick = (wchar_t *)gce->pszNick.w;
+ ptszStatus = (wchar_t *)gce->pszStatus.w;
+ ptszUserInfo = (wchar_t *)gce->pszUserInfo.w;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
int GetRichTextLength(HWND hwnd)
{
GETTEXTLENGTHEX gtl;
@@ -209,63 +225,65 @@ int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char *pszProtoNa
BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce)
{
+ fakeLOGINFO lin(gce);
+ CMStringW wszText;
+ bool bTextUsed = Chat_GetDefaultEventDescr(si, &lin, wszText);
+
+ HICON hIcon = nullptr;
+ COLORREF dwColor = 0;
+
switch (gce->iType) {
case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT:
- g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, TranslateT("%s says: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); dwColor = g_chatApi.aFonts[16].color; wszText = TranslateT("%s says");
break;
case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT:
- g_chatApi.ShowPopup(si->hContact, si, Skin_LoadIcon(SKINICON_EVENT_MESSAGE), si->pszModule, si->ptszName, g_chatApi.aFonts[16].color, L"%s %s", gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); dwColor = g_chatApi.aFonts[16].color;
break;
case GC_EVENT_MESSAGE:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, g_chatApi.aFonts[9].color, TranslateT("%s says: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_MESSAGE]; dwColor = g_chatApi.aFonts[9].color; wszText = TranslateT("%s says");
break;
case GC_EVENT_ACTION:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ACTION], si->pszModule, si->ptszName, g_chatApi.aFonts[15].color, L"%s %s", gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_ACTION]; dwColor = g_chatApi.aFonts[15].color;
break;
case GC_EVENT_JOIN:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_JOIN], si->pszModule, si->ptszName, g_chatApi.aFonts[3].color, TranslateT("%s has joined"), gce->pszNick.w);
+ hIcon = g_chatApi.hIcons[ICON_JOIN]; dwColor = g_chatApi.aFonts[3].color;
break;
case GC_EVENT_PART:
- if (!gce->pszText.w)
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left"), gce->pszNick.w);
- else
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_PART], si->pszModule, si->ptszName, g_chatApi.aFonts[4].color, TranslateT("%s has left (%s)"), gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_PART]; dwColor = g_chatApi.aFonts[4].color;
break;
case GC_EVENT_QUIT:
- if (!gce->pszText.w)
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected"), gce->pszNick.w);
- else
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_QUIT], si->pszModule, si->ptszName, g_chatApi.aFonts[5].color, TranslateT("%s has disconnected (%s)"), gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_QUIT]; dwColor = g_chatApi.aFonts[5].color;
break;
case GC_EVENT_NICK:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NICK], si->pszModule, si->ptszName, g_chatApi.aFonts[7].color, TranslateT("%s is now known as %s"), gce->pszNick.w, gce->pszText.w);
+ hIcon = g_chatApi.hIcons[ICON_NICK]; dwColor = g_chatApi.aFonts[7].color;
break;
case GC_EVENT_KICK:
- if (!gce->pszText.w)
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s"), gce->pszStatus.w, gce->pszNick.w);
- else
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_KICK], si->pszModule, si->ptszName, g_chatApi.aFonts[6].color, TranslateT("%s kicked %s (%s)"), gce->pszStatus.w, gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_KICK]; dwColor = g_chatApi.aFonts[6].color;
break;
case GC_EVENT_NOTICE:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_NOTICE], si->pszModule, si->ptszName, g_chatApi.aFonts[8].color, TranslateT("Notice from %s: %s"), gce->pszNick.w, RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_NOTICE]; dwColor = g_chatApi.aFonts[8].color;
break;
case GC_EVENT_TOPIC:
- if (!gce->pszNick.w)
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s'"), RemoveFormatting(gce->pszText.w));
- else
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_TOPIC], si->pszModule, si->ptszName, g_chatApi.aFonts[11].color, TranslateT("The topic is '%s' (set by %s)"), RemoveFormatting(gce->pszText.w), gce->pszNick.w);
+ hIcon = g_chatApi.hIcons[ICON_TOPIC]; dwColor = g_chatApi.aFonts[11].color;
break;
case GC_EVENT_INFORMATION:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_INFO], si->pszModule, si->ptszName, g_chatApi.aFonts[12].color, L"%s", RemoveFormatting(gce->pszText.w));
+ hIcon = g_chatApi.hIcons[ICON_INFO]; dwColor = g_chatApi.aFonts[12].color;
break;
case GC_EVENT_ADDSTATUS:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_ADDSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[13].color, TranslateT("%s enables '%s' status for %s"), gce->pszText.w, (char *)gce->pszStatus.w, gce->pszNick.w);
+ hIcon = g_chatApi.hIcons[ICON_ADDSTATUS]; dwColor = g_chatApi.aFonts[13].color;
break;
case GC_EVENT_REMOVESTATUS:
- g_chatApi.ShowPopup(si->hContact, si, g_chatApi.hIcons[ICON_REMSTATUS], si->pszModule, si->ptszName, g_chatApi.aFonts[14].color, TranslateT("%s disables '%s' status for %s"), gce->pszText.w, (char *)gce->pszStatus.w, gce->pszNick.w);
+ hIcon = g_chatApi.hIcons[ICON_REMSTATUS]; dwColor = g_chatApi.aFonts[14].color;
break;
}
+ if (!bTextUsed && lin.ptszText) {
+ if (!wszText.IsEmpty())
+ wszText.Append(L": ");
+ wszText.Append(RemoveFormatting(gce->pszText.w));
+ }
+
+ g_chatApi.ShowPopup(si->hContact, si, hIcon, si->pszModule, si->ptszName, dwColor, L"%s", wszText.c_str());
return TRUE;
}
@@ -436,72 +454,58 @@ BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce)
pszNick = szTemp;
}
+ fakeLOGINFO lin(gce);
CMStringW buf;
+ bool bTextUsed = Chat_GetDefaultEventDescr(si, &lin, buf);
+
switch (gce->iType) {
case GC_EVENT_MESSAGE:
case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT:
p = '*';
- buf.AppendFormat(L"%s: %s", gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w));
+ buf = gce->pszNick.w;
break;
case GC_EVENT_ACTION:
case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT:
p = '*';
- buf.AppendFormat(L"%s %s", gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w));
break;
case GC_EVENT_JOIN:
p = '>';
- buf.AppendFormat(TranslateT("%s has joined"), pszNick);
break;
case GC_EVENT_PART:
p = '<';
- if (!gce->pszText.w)
- buf.AppendFormat(TranslateT("%s has left"), pszNick);
- else
- buf.AppendFormat(TranslateT("%s has left (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->pszText.w));
break;
case GC_EVENT_QUIT:
p = '<';
- if (!gce->pszText.w)
- buf.AppendFormat(TranslateT("%s has disconnected"), pszNick);
- else
- buf.AppendFormat(TranslateT("%s has disconnected (%s)"), pszNick, g_chatApi.RemoveFormatting(gce->pszText.w));
break;
case GC_EVENT_NICK:
p = '^';
- buf.AppendFormat(TranslateT("%s is now known as %s"), gce->pszNick.w, gce->pszText.w);
break;
case GC_EVENT_KICK:
p = '~';
- if (!gce->pszText.w)
- buf.AppendFormat(TranslateT("%s kicked %s"), gce->pszStatus.w, gce->pszNick.w);
- else
- buf.AppendFormat(TranslateT("%s kicked %s (%s)"), gce->pszStatus.w, gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w));
break;
case GC_EVENT_NOTICE:
p = 'o';
- buf.AppendFormat(TranslateT("Notice from %s: %s"), gce->pszNick.w, g_chatApi.RemoveFormatting(gce->pszText.w));
break;
case GC_EVENT_TOPIC:
p = '#';
- if (!gce->pszNick.w)
- buf.AppendFormat(TranslateT("The topic is '%s'"), g_chatApi.RemoveFormatting(gce->pszText.w));
- else
- buf.AppendFormat(TranslateT("The topic is '%s' (set by %s)"), g_chatApi.RemoveFormatting(gce->pszText.w), gce->pszNick.w);
break;
case GC_EVENT_INFORMATION:
p = '!';
- buf = g_chatApi.RemoveFormatting(gce->pszText.w);
break;
case GC_EVENT_ADDSTATUS:
p = '+';
- buf.AppendFormat(TranslateT("%s enables '%s' status for %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w);
break;
case GC_EVENT_REMOVESTATUS:
p = '-';
- buf.AppendFormat(TranslateT("%s disables '%s' status for %s"), gce->pszText.w, gce->pszStatus.w, gce->pszNick.w);
break;
}
+ if (!bTextUsed && lin.ptszText) {
+ if (!buf.IsEmpty())
+ buf.Append(L": ");
+ buf.Append(RemoveFormatting(gce->pszText.w));
+ }
+
// formatting strings don't need to be translatable - changing them via language pack would
// only screw up the log format.
wchar_t *szTime = g_chatApi.MakeTimeStamp(g_Settings->pszTimeStampLog, gce->time);
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 8ba3de0e9b..9f21d4237e 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -223,6 +223,7 @@ Profile_GetNameW @291
Profile_GetPathA @292
Profile_GetPathW @293
Profile_SetDefault @294
+Chat_GetDefaultEventDescr @295
FindDatabasePlugin @296
RegisterDatabasePlugin @298
Chat_CustomizeApi @299
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 430ffd6917..be1764ac69 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -223,6 +223,7 @@ Profile_GetNameW @291
Profile_GetPathA @292
Profile_GetPathW @293
Profile_SetDefault @294
+Chat_GetDefaultEventDescr @295
FindDatabasePlugin @296
RegisterDatabasePlugin @298
Chat_CustomizeApi @299