diff options
author | George Hazan <ghazan@miranda.im> | 2023-04-24 12:53:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-04-24 12:53:40 +0300 |
commit | e4a77876719997918082cb4973fe33558292e9a0 (patch) | |
tree | 6b5e0cdb4753a50ace34c18ab2cf69e49cd0f705 | |
parent | 306f00df80ab1f0d9070fa70c8316f4c3b415b4a (diff) |
even less custom shitcode
-rw-r--r-- | include/m_chat_int.h | 2 | ||||
-rw-r--r-- | libs/win32/mir_app.lib | bin | 251480 -> 252050 bytes | |||
-rw-r--r-- | libs/win64/mir_app.lib | bin | 248760 -> 249350 bytes | |||
-rw-r--r-- | plugins/TabSRMM/src/chat_log.cpp | 89 | ||||
-rw-r--r-- | src/mir_app/mir_app.vcxproj | 1 | ||||
-rw-r--r-- | src/mir_app/mir_app.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/mir_app/src/chat_log.cpp | 102 | ||||
-rw-r--r-- | src/mir_app/src/chat_loginfo.cpp | 168 | ||||
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 66 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 |
11 files changed, 183 insertions, 250 deletions
diff --git a/include/m_chat_int.h b/include/m_chat_int.h index 9729a0bc30..a244af5929 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -115,6 +115,8 @@ struct MIR_APP_EXPORT LOGINFO : public MZeroedObject, public MNonCopyable int getIcon() const;
int getIndex() const;
+ void write(struct RtfChatLogStreamData *streamData, bool simpleMode, CMStringA &str, const wchar_t *line) const;
+
ptrW ptszText;
ptrW ptszNick;
ptrW ptszUID;
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib Binary files differindex 9229294dcb..01a9e20ebd 100644 --- a/libs/win32/mir_app.lib +++ b/libs/win32/mir_app.lib diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib Binary files differindex 03e1836c34..e0b7e172d4 100644 --- a/libs/win64/mir_app.lib +++ b/libs/win64/mir_app.lib diff --git a/plugins/TabSRMM/src/chat_log.cpp b/plugins/TabSRMM/src/chat_log.cpp index dd1c11c5f7..ab0e516f35 100644 --- a/plugins/TabSRMM/src/chat_log.cpp +++ b/plugins/TabSRMM/src/chat_log.cpp @@ -63,91 +63,6 @@ static uint8_t EventToSymbol(const LOGINFO &lin) return 0x73;
}
-static void Log_AppendRTF(RtfChatLogStreamData *streamData, const LOGINFO &lin, bool simpleMode, CMStringA &str, const wchar_t *line)
-{
- int textCharsCount = 0;
-
- CMStringA res;
-
- for (; *line; line++, textCharsCount++) {
- if (*line == '\r' && line[1] == '\n') {
- res.Append("\\par ");
- line++;
- }
- else if (*line == '\n') {
- res.Append("\\line ");
- }
- else if (*line == '%' && !simpleMode) {
- char szTemp[200]; szTemp[0] = '\0';
- switch (*++line) {
- case '\0':
- case '%':
- res.AppendChar('%');
- break;
-
- case 'c':
- case 'f':
- if (g_Settings.bStripFormat || streamData->bStripFormat)
- line += 2;
- else if (line[1] != '\0' && line[2] != '\0') {
- wchar_t szTemp3[3], c = *line;
- int col;
- szTemp3[0] = line[1];
- szTemp3[1] = line[2];
- szTemp3[2] = '\0';
- line += 2;
-
- col = _wtoi(szTemp3);
- col += (OPTIONS_FONTCOUNT + 1);
- res.AppendFormat((c == 'c') ? "\\cf%u " : "\\highlight%u ", col);
- }
- break;
- case 'C':
- case 'F':
- if (!g_Settings.bStripFormat && !streamData->bStripFormat) {
- int j = lin.bIsHighlighted ? 16 : lin.getIndex();
- if (*line == 'C')
- res.AppendFormat("\\cf%u ", j + 1);
- else
- res.Append("\\highlight0 ");
- }
- break;
- case 'b':
- case 'u':
- case 'i':
- if (!streamData->bStripFormat)
- res.AppendFormat((*line == 'u') ? "\\%cl " : "\\%c ", *line);
- break;
-
- case 'B':
- case 'U':
- case 'I':
- if (!streamData->bStripFormat)
- res.AppendFormat((*line == 'U') ? "\\%cl0 " : "\\%c0 ", tolower(*line));
- break;
-
- case 'r':
- if (!streamData->bStripFormat)
- res.AppendFormat("%s ", g_chatApi.Log_SetStyle(lin.getIndex()));
- break;
- }
- }
- else if (*line == '\t' && !streamData->bStripFormat) {
- res.Append("\\tab ");
- }
- else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) {
- res.AppendChar('\\');
- res.AppendChar(*line);
- }
- else if (*line > 0 && *line < 128) {
- res.AppendChar((char)*line);
- }
- else res.AppendFormat("\\u%u ?", (uint16_t)*line);
- }
-
- str += res;
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
// RTF header
@@ -282,7 +197,7 @@ void CLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const LOGI 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, lin, TRUE, str, szTimeStamp);
+ lin.write(streamData, true, str, szTimeStamp);
}
str.Append("\\tab ");
}
@@ -314,7 +229,7 @@ void CLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const LOGI if (g_Settings.bNewLineAfterNames)
pszTemp.AppendChar('\n');
- Log_AppendRTF(streamData, lin, TRUE, str, pszTemp);
+ lin.write(streamData, true, str, pszTemp);
str.AppendChar(' ');
}
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj index f2cc3c4900..5cb64ca6a3 100644 --- a/src/mir_app/mir_app.vcxproj +++ b/src/mir_app/mir_app.vcxproj @@ -31,6 +31,7 @@ <ClCompile Include="src\button.cpp" />
<ClCompile Include="src\chat_clist.cpp" />
<ClCompile Include="src\chat_log.cpp" />
+ <ClCompile Include="src\chat_loginfo.cpp" />
<ClCompile Include="src\chat_manager.cpp" />
<ClCompile Include="src\chat_opts.cpp" />
<ClCompile Include="src\chat_rtf.cpp" />
diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters index d18b1ac64c..3a925e5b5a 100644 --- a/src/mir_app/mir_app.vcxproj.filters +++ b/src/mir_app/mir_app.vcxproj.filters @@ -401,6 +401,9 @@ <ClCompile Include="src\clc.cpp">
<Filter>Source Files\MetaContacts</Filter>
</ClCompile>
+ <ClCompile Include="src\chat_loginfo.cpp">
+ <Filter>Source Files\Chats</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\filter.h">
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 45e59c666f..8bbf25805b 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -38,97 +38,6 @@ char* Log_SetStyle(int style) return "";
}
-static int Log_AppendRTF(RtfChatLogStreamData *streamData, const LOGINFO &lin, bool simpleMode, CMStringA &buf, const wchar_t *line)
-{
- int textCharsCount = 0;
-
- for (; *line; line++, textCharsCount++) {
- if (*line == '\r' && line[1] == '\n') {
- buf.Append("\\par ");
- line++;
- }
- else if (*line == '\n') {
- buf.Append("\\line ");
- }
- else if (*line == '%' && !simpleMode) {
- char szTemp[200];
-
- szTemp[0] = '\0';
- switch (*++line) {
- case '\0':
- case '%':
- buf.AppendChar('%');
- break;
-
- case 'c':
- case 'f':
- if (g_Settings->bStripFormat || streamData->bStripFormat)
- line += 2;
-
- else if (line[1] != '\0' && line[2] != '\0') {
- wchar_t szTemp3[3], c = *line;
- int col;
- szTemp3[0] = line[1];
- szTemp3[1] = line[2];
- szTemp3[2] = '\0';
- line += 2;
-
- col = _wtoi(szTemp3);
- col += (OPTIONS_FONTCOUNT + 1);
- mir_snprintf(szTemp, (c == 'c') ? "\\cf%u " : "\\highlight%u ", col);
- }
- break;
- case 'C':
- case 'F':
- if (!g_Settings->bStripFormat && !streamData->bStripFormat) {
- int j = lin.bIsHighlighted ? 16 : lin.getIndex();
- if (*line == 'C')
- mir_snprintf(szTemp, "\\cf%u ", j + 1);
- else
- mir_snprintf(szTemp, "\\highlight0 ");
- }
- break;
- case 'b':
- case 'u':
- case 'i':
- if (!streamData->bStripFormat)
- mir_snprintf(szTemp, (*line == 'u') ? "\\%cl " : "\\%c ", *line);
- break;
-
- case 'B':
- case 'U':
- case 'I':
- if (!streamData->bStripFormat) {
- mir_snprintf(szTemp, (*line == 'U') ? "\\%cl0 " : "\\%c0 ", *line);
- CharLowerA(szTemp);
- }
- break;
-
- case 'r':
- if (!streamData->bStripFormat)
- mir_snprintf(szTemp, "%s ", Log_SetStyle(lin.getIndex()));
- break;
- }
-
- if (szTemp[0])
- buf.Append(szTemp);
- }
- else if (*line == '\t' && !streamData->bStripFormat) {
- buf.Append("\\tab ");
- }
- else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) {
- buf.AppendChar('\\');
- buf.AppendChar(*line);
- }
- else if (*line > 0 && *line < 128) {
- buf.AppendChar(*line);
- }
- else buf.AppendFormat("\\u%u ?", (uint16_t)*line);
- }
-
- return textCharsCount;
-}
-
MIR_APP_DLL(bool) Chat_GetDefaultEventDescr(const SESSION_INFO *si, const LOGINFO *lin, CMStringW &res)
{
CMStringW wszNick;
@@ -366,7 +275,7 @@ void CRtfLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const L 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, lin, true, buf, szTimeStamp);
+ lin.write(streamData, true, buf, szTimeStamp);
}
buf.Append("\\tab ");
}
@@ -377,13 +286,12 @@ void CRtfLogWindow::CreateChatRtfEvent(RtfChatLogStreamData *streamData, const L CMStringW tmp((lin.bIsMe) ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick);
tmp.Replace(L"%n", lin.ptszNick);
- Log_AppendRTF(streamData, lin, true, buf, tmp);
+ lin.write(streamData, true, buf, tmp);
buf.AppendChar(' ');
}
// Insert the message
CreateChatRtfMessage(streamData, lin, buf);
-
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -396,12 +304,12 @@ void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const CMStringW wszCaption;
bool bTextUsed = Chat_GetDefaultEventDescr(streamData->si, &lin, wszCaption);
if (!wszCaption.IsEmpty())
- Log_AppendRTF(streamData, lin, !bTextUsed, buf, wszCaption);
+ lin.write(streamData, !bTextUsed, buf, wszCaption);
if (!bTextUsed && lin.ptszText) {
if (!wszCaption.IsEmpty())
- Log_AppendRTF(streamData, lin, false, buf, L" ");
- Log_AppendRTF(streamData, lin, false, buf, lin.ptszText);
+ lin.write(streamData, false, buf, L" ");
+ lin.write(streamData, false, buf, lin.ptszText);
}
}
diff --git a/src/mir_app/src/chat_loginfo.cpp b/src/mir_app/src/chat_loginfo.cpp new file mode 100644 index 0000000000..e05f3f37c9 --- /dev/null +++ b/src/mir_app/src/chat_loginfo.cpp @@ -0,0 +1,168 @@ +/* + +Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" +#include "chat.h" + +///////////////////////////////////////////////////////////////////////////////////////// +// LOGINFO members + +LOGINFO::LOGINFO(const GCEVENT *gce) : + ptszNick(mir_wstrdup(gce->pszNick.w)), + ptszText(mir_wstrdup(gce->pszText.w)), + ptszStatus(mir_wstrdup(gce->pszStatus.w)), + ptszUserInfo(mir_wstrdup(gce->pszUserInfo.w)) +{ + time = gce->time; + iType = gce->iType; + bIsMe = gce->bIsMe; +} + +LOGINFO::~LOGINFO() +{} + +int LOGINFO::getIndex() const +{ + switch (iType) { + case GC_EVENT_MESSAGE: + if (bIsMe) + return 10; + else + return 9; + + case GC_EVENT_JOIN: return 3; + case GC_EVENT_PART: return 4; + case GC_EVENT_QUIT: return 5; + case GC_EVENT_NICK: return 7; + case GC_EVENT_KICK: return 6; + case GC_EVENT_NOTICE: return 8; + case GC_EVENT_TOPIC: return 11; + case GC_EVENT_INFORMATION:return 12; + case GC_EVENT_ADDSTATUS: return 13; + case GC_EVENT_REMOVESTATUS: return 14; + case GC_EVENT_ACTION: return 15; + } + return 0; +} + +int LOGINFO::getIcon() const +{ + switch (iType) { + case GC_EVENT_MESSAGE: + if (bIsMe) + return ICON_MESSAGEOUT; + else + return ICON_MESSAGE; + + case GC_EVENT_JOIN: return ICON_JOIN; + case GC_EVENT_PART: return ICON_PART; + case GC_EVENT_QUIT: return ICON_QUIT; + case GC_EVENT_NICK: return ICON_NICK; + case GC_EVENT_KICK: return ICON_KICK; + case GC_EVENT_NOTICE: return ICON_NOTICE; + case GC_EVENT_TOPIC: return ICON_TOPIC; + case GC_EVENT_INFORMATION:return ICON_INFO; + case GC_EVENT_ADDSTATUS: return ICON_ADDSTATUS; + case GC_EVENT_REMOVESTATUS: return ICON_REMSTATUS; + case GC_EVENT_ACTION: return ICON_ACTION; + } + return 0; +} + +void LOGINFO::write(RtfChatLogStreamData *streamData, bool simpleMode, CMStringA &str, const wchar_t *line) const +{ + CMStringA buf; + + for (; *line; line++) { + if (*line == '\r' && line[1] == '\n') { + buf.Append("\\par "); + line++; + } + else if (*line == '\n') { + buf.Append("\\line "); + } + else if (*line == '%' && !simpleMode) { + switch (*++line) { + case '\0': + case '%': + buf.AppendChar('%'); + break; + + case 'c': + case 'f': + if (g_Settings->bStripFormat || streamData->bStripFormat) + line += 2; + + else if (line[1] != '\0' && line[2] != '\0') { + wchar_t szTemp3[3], c = *line; + int col; + szTemp3[0] = line[1]; + szTemp3[1] = line[2]; + szTemp3[2] = '\0'; + line += 2; + + col = _wtoi(szTemp3); + col += (OPTIONS_FONTCOUNT + 1); + buf.AppendFormat((c == 'c') ? "\\cf%u " : "\\highlight%u ", col); + } + break; + case 'C': + case 'F': + if (!g_Settings->bStripFormat && !streamData->bStripFormat) { + int j = bIsHighlighted ? 16 : getIndex(); + if (*line == 'C') + buf.AppendFormat("\\cf%u ", j + 1); + else + buf.AppendFormat("\\highlight0 "); + } + break; + case 'b': + case 'u': + case 'i': + if (!streamData->bStripFormat) + buf.AppendFormat((*line == 'u') ? "\\%cl " : "\\%c ", *line); + break; + + case 'B': + case 'U': + case 'I': + if (!streamData->bStripFormat) + buf.AppendFormat((*line == 'U') ? "\\%cl0 " : "\\%c0 ", tolower(*line)); + break; + + case 'r': + if (!streamData->bStripFormat) + buf.AppendFormat("%s ", Log_SetStyle(getIndex())); + break; + } + } + else if (*line == '\t' && !streamData->bStripFormat) { + buf.Append("\\tab "); + } + else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) { + buf.AppendChar('\\'); + buf.AppendChar(*line); + } + else if (*line > 0 && *line < 128) { + buf.AppendChar(*line); + } + else buf.AppendFormat("\\u%u ?", (uint16_t)*line); + } + + str += buf; +} diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index be8ede8b01..49f39c0883 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -56,72 +56,6 @@ static int compareModules(const MODULEINFO *p1, const MODULEINFO *p2) static LIST<MODULEINFO> g_arModules(5, compareModules);
/////////////////////////////////////////////////////////////////////////////////////////
-// LOGINFO members
-
-LOGINFO::LOGINFO(const GCEVENT *gce) :
- ptszNick(mir_wstrdup(gce->pszNick.w)),
- ptszText(mir_wstrdup(gce->pszText.w)),
- ptszStatus(mir_wstrdup(gce->pszStatus.w)),
- ptszUserInfo(mir_wstrdup(gce->pszUserInfo.w))
-{
- time = gce->time;
- iType = gce->iType;
- bIsMe = gce->bIsMe;
-}
-
-LOGINFO::~LOGINFO()
-{
-}
-
-int LOGINFO::getIndex() const
-{
- switch (iType) {
- case GC_EVENT_MESSAGE:
- if (bIsMe)
- return 10;
- else
- return 9;
-
- case GC_EVENT_JOIN: return 3;
- case GC_EVENT_PART: return 4;
- case GC_EVENT_QUIT: return 5;
- case GC_EVENT_NICK: return 7;
- case GC_EVENT_KICK: return 6;
- case GC_EVENT_NOTICE: return 8;
- case GC_EVENT_TOPIC: return 11;
- case GC_EVENT_INFORMATION:return 12;
- case GC_EVENT_ADDSTATUS: return 13;
- case GC_EVENT_REMOVESTATUS: return 14;
- case GC_EVENT_ACTION: return 15;
- }
- return 0;
-}
-
-int LOGINFO::getIcon() const
-{
- switch (iType) {
- case GC_EVENT_MESSAGE:
- if (bIsMe)
- return ICON_MESSAGEOUT;
- else
- return ICON_MESSAGE;
-
- case GC_EVENT_JOIN: return ICON_JOIN;
- case GC_EVENT_PART: return ICON_PART;
- case GC_EVENT_QUIT: return ICON_QUIT;
- case GC_EVENT_NICK: return ICON_NICK;
- case GC_EVENT_KICK: return ICON_KICK;
- case GC_EVENT_NOTICE: return ICON_NOTICE;
- case GC_EVENT_TOPIC: return ICON_TOPIC;
- case GC_EVENT_INFORMATION:return ICON_INFO;
- case GC_EVENT_ADDSTATUS: return ICON_ADDSTATUS;
- case GC_EVENT_REMOVESTATUS: return ICON_REMSTATUS;
- case GC_EVENT_ACTION: return ICON_ACTION;
- }
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Session Manager functions
// Keeps track of all sessions and its windows
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 85a560255c..319027ada5 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -863,3 +863,4 @@ Chat_IsMuted @941 NONAME ?CreateChatRtfMessage@CRtfLogWindow@@QAEXPAURtfChatLogStreamData@@ABULOGINFO@@AAV?$CMStringT@DV?$ChTraitsCRT@D@@@@@Z @980 NONAME
?getIcon@LOGINFO@@QBEHXZ @981 NONAME
?getIndex@LOGINFO@@QBEHXZ @982 NONAME
+?write@LOGINFO@@QBEXPAURtfChatLogStreamData@@_NAAV?$CMStringT@DV?$ChTraitsCRT@D@@@@PB_W@Z @983 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 8fae93a9fd..94c6600242 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -863,3 +863,4 @@ Chat_IsMuted @941 NONAME ?CreateChatRtfMessage@CRtfLogWindow@@QEAAXPEAURtfChatLogStreamData@@AEBULOGINFO@@AEAV?$CMStringT@DV?$ChTraitsCRT@D@@@@@Z @980 NONAME
?getIcon@LOGINFO@@QEBAHXZ @981 NONAME
?getIndex@LOGINFO@@QEBAHXZ @982 NONAME
+?write@LOGINFO@@QEBAXPEAURtfChatLogStreamData@@_NAEAV?$CMStringT@DV?$ChTraitsCRT@D@@@@PEB_W@Z @983 NONAME
|