From e4a77876719997918082cb4973fe33558292e9a0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 24 Apr 2023 12:53:40 +0300 Subject: even less custom shitcode --- src/mir_app/mir_app.vcxproj | 1 + src/mir_app/mir_app.vcxproj.filters | 3 + src/mir_app/src/chat_log.cpp | 102 ++-------------------- src/mir_app/src/chat_loginfo.cpp | 168 ++++++++++++++++++++++++++++++++++++ src/mir_app/src/chat_manager.cpp | 66 -------------- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + 7 files changed, 179 insertions(+), 163 deletions(-) create mode 100644 src/mir_app/src/chat_loginfo.cpp (limited to 'src') 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 @@ + 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 @@ Source Files\MetaContacts + + Source Files\Chats + 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 . +*/ + +#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 @@ -55,72 +55,6 @@ static int compareModules(const MODULEINFO *p1, const MODULEINFO *p2) static LIST 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 -- cgit v1.2.3