diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvirc/kernel/KviHtmlGenerator.cpp | 60 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviHtmlGenerator.h | 5 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.cpp | 24 |
3 files changed, 47 insertions, 42 deletions
diff --git a/src/kvirc/kernel/KviHtmlGenerator.cpp b/src/kvirc/kernel/KviHtmlGenerator.cpp index 534b711a8..b9fa4ed4d 100644 --- a/src/kvirc/kernel/KviHtmlGenerator.cpp +++ b/src/kvirc/kernel/KviHtmlGenerator.cpp @@ -29,13 +29,14 @@ #include "KviOptions.h" #include "KviTextIconManager.h" +#include <QTextDocument> // for Qt::escape + #define KVI_LABEL_DEF_BACK 100 #define KVI_LABEL_DEF_FORE 101 namespace KviHtmlGenerator { - - QString convertToHtml(const QString & szText) + QString convertToHtml(const QString & szText, bool bEscape) { QString szResult = "<qt>"; bool bCurBold = false; @@ -48,28 +49,29 @@ namespace KviHtmlGenerator unsigned int uIdx = 0; - while(uIdx < (unsigned int)szText.length()) + QString szTxt = bEscape ? Qt::escape(szText) : szText; + + while(uIdx < (unsigned int)szTxt.length()) { - unsigned short c = szText[(int)uIdx].unicode(); + unsigned short c = szTxt[(int)uIdx].unicode(); unsigned int uStart = uIdx; while( - (c != KviControlCodes::Color) && - (c != KviControlCodes::Bold) && - (c != KviControlCodes::Underline) && - (c != KviControlCodes::Reverse) && - (c != KviControlCodes::Reset) && - (c != KviControlCodes::Icon) && - ((c != ':') || bIgnoreIcons) && - ((c != ';') || bIgnoreIcons) && - ((c != '=') || bIgnoreIcons) - ) + (c != KviControlCodes::Color) && + (c != KviControlCodes::Bold) && + (c != KviControlCodes::Underline) && + (c != KviControlCodes::Reverse) && + (c != KviControlCodes::Reset) && + (c != KviControlCodes::Icon) && + ((c != ':') || bIgnoreIcons) && + ((c != ';') || bIgnoreIcons) && + ((c != '=') || bIgnoreIcons)) { bIgnoreIcons = false; if(c == '&') { //look for an html entity - QString szEntity = szText.mid((int)uIdx,6); + QString szEntity = szTxt.mid((int)uIdx,6); if(szEntity == """) { uIdx += 5; @@ -81,16 +83,16 @@ namespace KviHtmlGenerator } else { szEntity.truncate(4); if(szEntity == "<" || szEntity == ">") - uIdx+=3; + uIdx += 3; } } } uIdx++; - if(uIdx >= (unsigned int)szText.length()) + if(uIdx >= (unsigned int)szTxt.length()) break; - c = szText[(int)uIdx].unicode(); + c = szTxt[(int)uIdx].unicode(); } bIgnoreIcons = false; @@ -144,7 +146,7 @@ namespace KviHtmlGenerator if(bOpened) szResult.append(";\">"); - szResult.append(szText.mid(uStart,iLen)); + szResult.append(szTxt.mid(uStart,iLen)); if(bOpened) szResult.append("</span>"); @@ -186,7 +188,7 @@ namespace KviHtmlGenerator ++uIdx; unsigned char ucFore; unsigned char ucBack; - uIdx = KviControlCodes::getUnicodeColorBytes(szText,uIdx,&ucFore,&ucBack); + uIdx = KviControlCodes::getUnicodeColorBytes(szTxt,uIdx,&ucFore,&ucBack); if(ucFore != KviControlCodes::NoChange) { uCurFore = ucFore; @@ -212,20 +214,20 @@ namespace KviHtmlGenerator unsigned short uIsEmoticon = 0; unsigned int uIcoStart = uIdx; - if(uIdx < (unsigned int)szText.length()) + if(uIdx < (unsigned int)szTxt.length()) { //look up for a nose - if(szText[(int)uIdx] == '-') + if(szTxt[(int)uIdx] == '-') { szLookup.append('-'); uIdx++; } } - if(uIdx < (unsigned int)szText.length()) + if(uIdx < (unsigned int)szTxt.length()) { //look up for a mouth - unsigned short uMouth = szText[(int)uIdx].unicode(); + unsigned short uMouth = szTxt[(int)uIdx].unicode(); switch(uMouth) { case ')': @@ -246,15 +248,15 @@ namespace KviHtmlGenerator } } - if(uIdx < (unsigned int)szText.length()) + if(uIdx < (unsigned int)szTxt.length()) { //look up for a space - if(szText[(int)uIdx]== ' ') + if(szTxt[(int)uIdx]== ' ') { uIsEmoticon++; } } else { - //got a smile at the end of the szText + //got a smile at the end of the szTxt uIsEmoticon++; } @@ -292,10 +294,10 @@ namespace KviHtmlGenerator if(bShowIcons) { unsigned int uIcoStart = uIdx; - while((uIdx < (unsigned int)szText.length()) && (szText[(int)uIdx].unicode() > 32)) + while((uIdx < (unsigned int)szTxt.length()) && (szTxt[(int)uIdx].unicode() > 32)) uIdx++; - QString szLookup = szText.mid(uIcoStart,uIdx - uIcoStart); + QString szLookup = szTxt.mid(uIcoStart,uIdx - uIcoStart); KviTextIcon * pIcon = g_pTextIconManager->lookupTextIcon(szLookup); if(pIcon) diff --git a/src/kvirc/kernel/KviHtmlGenerator.h b/src/kvirc/kernel/KviHtmlGenerator.h index 33db2f14b..dfb8624e7 100644 --- a/src/kvirc/kernel/KviHtmlGenerator.h +++ b/src/kvirc/kernel/KviHtmlGenerator.h @@ -40,10 +40,11 @@ namespace KviHtmlGenerator { /** * \brief Converts a raw irc message to its html equivalent text - * \param szText const reference to a message text + * \param szText Const reference to a message text + * \param bEscape Whether to escape chars to HTML entities * \return QString */ - extern KVIRC_API QString convertToHtml(const QString & szText); + extern KVIRC_API QString convertToHtml(const QString & szText, bool bEscape = false); }; #endif //_KVI_HTMLGENERATOR_H_ diff --git a/src/modules/logview/LogViewWindow.cpp b/src/modules/logview/LogViewWindow.cpp index 6b428f2d3..449c78ffa 100644 --- a/src/modules/logview/LogViewWindow.cpp +++ b/src/modules/logview/LogViewWindow.cpp @@ -668,14 +668,14 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) return; QRegExp rx; - QString szBuffer, szLine, szTmp; + QString szLog, szLogDir, szBuffer, szLine, szTmp; QString szDate = pLog->date().toString("yyyy.MM.dd"); // The fresh new log - QString szLog = QDir::homePath(); - KviQString::ensureLastCharIs(szLog,QChar(KVI_PATH_SEPARATOR_CHAR)); - szLog += "temp"; - szLog += KVI_PATH_SEPARATOR_CHAR; + g_pApp->getLocalKvircDirectory(szLogDir,KviApplication::Tmp); + KviFileUtils::adjustFilePath(szLogDir); + szLogDir += KVI_PATH_SEPARATOR_CHAR; + szLog += szLogDir; szLog += QString("%1_%2.%3_%4").arg(pLog->typeString(),pLog->name(),pLog->network(),szDate); // Open file for reading @@ -734,7 +734,7 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) szLog += ".html"; szTmp = QString("KVIrc %1 %2").arg(KVI_VERSION).arg(KVI_RELEASE_NAME); QString szNick = ""; - static bool bFirstLine = true; + bool bFirstLine = true; QString szTitle; switch(pLog->type()) @@ -773,6 +773,8 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) // Find who has talked QString szTmpNick = szTmp.section(" ",2,2); + if((szTmpNick.left(1) != "<") && (szTmpNick.right(1) != ">")) + szTmpNick = ""; // locate msgtype QString szNum = szTmp.section(' ',0,0); @@ -786,12 +788,12 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) // remove msgtype tag szTmp = szTmp.remove(0,szNum.length()+1); - szTmp = KviHtmlGenerator::convertToHtml(szTmp); + szTmp = KviHtmlGenerator::convertToHtml(szTmp,true); // insert msgtype icon at start of the current text line KviMessageTypeSettings msg(KVI_OPTION_MSGTYPE(iMsgType)); QString szIcon = g_pIconManager->getSmallIconResourceName((KviIconManager::SmallIcon)msg.pixId()); - szTmp.prepend("<img src=\"" + szIcon + "\">"); + szTmp.prepend("<img src=\"" + szIcon + "\" alt=\"\" /> "); /* * Check if the nick who has talked is the same of the above line. @@ -809,13 +811,13 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) szTmp.prepend("<p>"); szNick = szTmpNick; - bFirstLine = false; } else { // Break the line - szTmp += "<br />\n"; + szTmp.prepend("<br />\n"); } szBuffer += szTmp; + bFirstLine = false; } // Close the last paragraph @@ -859,7 +861,7 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) for(int i=0; i < szImagesList.count(); i++) { QString szSourceFile = szCurrentThemePath + szImagesList.at(i); - QString szDestFile = szLog + szImagesList.at(i); + QString szDestFile = szLogDir + szImagesList.at(i); KviFileUtils::copyFile(szSourceFile,szDestFile); } |
