diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/core/KviQString.h | 16 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviHtmlGenerator.cpp | 125 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviHtmlGenerator.h | 4 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.cpp | 91 |
4 files changed, 146 insertions, 90 deletions
diff --git a/src/kvilib/core/KviQString.h b/src/kvilib/core/KviQString.h index 01cea9d0b..ebb0d98c7 100644 --- a/src/kvilib/core/KviQString.h +++ b/src/kvilib/core/KviQString.h @@ -507,6 +507,14 @@ namespace KviQString extern KVILIB_API void bufferToHex(QString & szRetBuffer, const unsigned char * pcBuffer, unsigned int uLen); /** + * \brief Escapes any kvs special character from a string + * \param szData The string to escape + * \param uFlags The flag which correspond to the characters to escape + * \return void + */ + extern KVILIB_API void escapeKvs(QString * szData, uint uFlags = 0); + + /** * \brief Return the string converted to a long * \param szNumber The source number * \param bOk The conversion error handling @@ -535,14 +543,6 @@ namespace KviQString return szNumber.toULongLong(bOk); #endif } - - /** - * \brief Escapes any kvs special character from a string - * \param szData The string to escape - * \param uFlags The flag which correspond to the characters to escape - * \return void - */ - extern KVILIB_API void escapeKvs(QString * szData, uint uFlags = 0); } #endif //_KVI_QSTRING_H_ diff --git a/src/kvirc/kernel/KviHtmlGenerator.cpp b/src/kvirc/kernel/KviHtmlGenerator.cpp index da5e2c4ae..534b711a8 100644 --- a/src/kvirc/kernel/KviHtmlGenerator.cpp +++ b/src/kvirc/kernel/KviHtmlGenerator.cpp @@ -35,16 +35,16 @@ namespace KviHtmlGenerator { - QString convertToHtml(const QString &szText) + QString convertToHtml(const QString & szText) { - QString szResult="<qt>"; + QString szResult = "<qt>"; bool bCurBold = false; bool bCurUnderline = false; - bool bIgnoreIcons = false; - bool bShowIcons = KVI_OPTION_BOOL(KviOption_boolDrawEmoticons); + bool bIgnoreIcons = false; + bool bShowIcons = KVI_OPTION_BOOL(KviOption_boolDrawEmoticons); - unsigned char uCurFore = KVI_LABEL_DEF_FORE; //default fore - unsigned char uCurBack = KVI_LABEL_DEF_BACK; //default back + unsigned char uCurFore = KVI_LABEL_DEF_FORE; //default fore + unsigned char uCurBack = KVI_LABEL_DEF_BACK; //default back unsigned int uIdx = 0; @@ -65,43 +65,46 @@ namespace KviHtmlGenerator ((c != '=') || bIgnoreIcons) ) { - bIgnoreIcons=FALSE; + bIgnoreIcons = false; if(c == '&') { //look for an html entity QString szEntity = szText.mid((int)uIdx,6); - if(szEntity==""") + if(szEntity == """) { - uIdx+=5; + uIdx += 5; } else { szEntity.truncate(5); - if(szEntity=="&") + if(szEntity == "&") { - uIdx+=4; + uIdx += 4; } else { szEntity.truncate(4); - if(szEntity=="<" || szEntity==">") uIdx+=3; + if(szEntity == "<" || szEntity == ">") + uIdx+=3; } } } uIdx++; - if(uIdx >= (unsigned int)szText.length()) break; - else c = szText[(int)uIdx].unicode(); + if(uIdx >= (unsigned int)szText.length()) + break; + + c = szText[(int)uIdx].unicode(); } - bIgnoreIcons=FALSE; + bIgnoreIcons = false; int iLen = uIdx - uStart; if(iLen > 0) { - bool bOpened = FALSE; + bool bOpened = false; if(uCurFore != KVI_LABEL_DEF_FORE) { szResult.append("<span style=\"color:"); szResult.append(KVI_OPTION_MIRCCOLOR(uCurFore).name()); - bOpened = TRUE; + bOpened = true; } if(uCurBack != KVI_LABEL_DEF_BACK) @@ -109,7 +112,7 @@ namespace KviHtmlGenerator if(!bOpened) { szResult.append("<span style=\"background-color:"); - bOpened = TRUE; + bOpened = true; } else { szResult.append(";background-color:"); } @@ -121,7 +124,7 @@ namespace KviHtmlGenerator if(!bOpened) { szResult.append("<span style=\"text-decoration:underline"); - bOpened = TRUE; + bOpened = true; } else { szResult.append(";text-decoration:underline"); } @@ -132,61 +135,70 @@ namespace KviHtmlGenerator if(!bOpened) { szResult.append("<span style=\"font-weight:bold"); - bOpened = TRUE; + bOpened = true; } else { szResult.append(";font-weight:bold"); } } - if(bOpened) szResult.append(";\">"); + if(bOpened) + szResult.append(";\">"); szResult.append(szText.mid(uStart,iLen)); - if( bOpened ) + if(bOpened) szResult.append("</span>"); } switch(c) { case KviControlCodes::Bold: - bCurBold = !bCurBold; ++uIdx; - break; + { + bCurBold = !bCurBold; + ++uIdx; + break; + } case KviControlCodes::Underline: - bCurUnderline = !bCurUnderline; ++uIdx; - break; + { + bCurUnderline = !bCurUnderline; + ++uIdx; + break; + } case KviControlCodes::Reverse: - { - char auxBack = uCurBack; - uCurBack = uCurFore; - uCurFore = auxBack; - } + { + char cAuxBack = uCurBack; + uCurBack = uCurFore; + uCurFore = cAuxBack; ++uIdx; - break; + break; + } case KviControlCodes::Reset: + { uCurFore = KVI_LABEL_DEF_FORE; uCurBack = KVI_LABEL_DEF_BACK; bCurBold = false; bCurUnderline = false; ++uIdx; - break; + break; + } case KviControlCodes::Color: { ++uIdx; - unsigned char fore; - unsigned char back; - uIdx = KviControlCodes::getUnicodeColorBytes(szText,uIdx,&fore,&back); - if(fore != KviControlCodes::NoChange) + unsigned char ucFore; + unsigned char ucBack; + uIdx = KviControlCodes::getUnicodeColorBytes(szText,uIdx,&ucFore,&ucBack); + if(ucFore != KviControlCodes::NoChange) { - uCurFore = fore; - if(back != KviControlCodes::NoChange) - uCurBack = back; + uCurFore = ucFore; + if(ucBack != KviControlCodes::NoChange) + uCurBack = ucBack; } else { // only a CTRL+K uCurBack = KVI_LABEL_DEF_BACK; uCurFore = KVI_LABEL_DEF_FORE; } + break; } - break; case ':': case ';': case '=': @@ -197,7 +209,7 @@ namespace KviHtmlGenerator ++uIdx; QString szLookup; szLookup.append(QChar(c)); - unsigned short uIsEmoticon=0; + unsigned short uIsEmoticon = 0; unsigned int uIcoStart = uIdx; if(uIdx < (unsigned int)szText.length()) @@ -213,8 +225,8 @@ namespace KviHtmlGenerator if(uIdx < (unsigned int)szText.length()) { //look up for a mouth - unsigned short m = szText[(int)uIdx].unicode(); - switch(m) + unsigned short uMouth = szText[(int)uIdx].unicode(); + switch(uMouth) { case ')': case '(': @@ -225,7 +237,7 @@ namespace KviHtmlGenerator case 'O': case '*': case '|': - szLookup+=QChar(m); + szLookup += QChar(uMouth); uIsEmoticon++; uIdx++; break; @@ -246,7 +258,7 @@ namespace KviHtmlGenerator uIsEmoticon++; } - if(uIsEmoticon>1) + if(uIsEmoticon > 1) { KviTextIcon * pIcon = g_pTextIconManager->lookupTextIcon(szLookup); // do we have that emoticon-icon association ? @@ -259,27 +271,29 @@ namespace KviHtmlGenerator szResult.append("\" style=\"background-color:"); szResult.append(KVI_OPTION_MIRCCOLOR(uCurBack).name()); } - szResult.append("\">"); + szResult.append("\" />"); } else { - bIgnoreIcons=TRUE; + bIgnoreIcons = true; uIdx = uIcoStart-1; } } else { - bIgnoreIcons=TRUE; + bIgnoreIcons = true; uIdx = uIcoStart-1; } } else { - bIgnoreIcons=TRUE; + bIgnoreIcons = true; } + + break; } - break; case KviControlCodes::Icon: { ++uIdx; if(bShowIcons) { unsigned int uIcoStart = uIdx; - while((uIdx < (unsigned int)szText.length()) && (szText[(int)uIdx].unicode() > 32))uIdx++; + while((uIdx < (unsigned int)szText.length()) && (szText[(int)uIdx].unicode() > 32)) + uIdx++; QString szLookup = szText.mid(uIcoStart,uIdx - uIcoStart); @@ -293,17 +307,18 @@ namespace KviHtmlGenerator szResult.append("\" style=\"background-color:"); szResult.append(KVI_OPTION_MIRCCOLOR(uCurBack).name()); } - szResult.append("\">"); + szResult.append("\" />"); } else { uIdx = uIcoStart; } } + + break; } - break; } } szResult.append("</qt>"); - //qDebug("%s",szResult.toUtf8().data()); + return szResult; } } diff --git a/src/kvirc/kernel/KviHtmlGenerator.h b/src/kvirc/kernel/KviHtmlGenerator.h index 7a6c0d796..33db2f14b 100644 --- a/src/kvirc/kernel/KviHtmlGenerator.h +++ b/src/kvirc/kernel/KviHtmlGenerator.h @@ -43,7 +43,7 @@ namespace KviHtmlGenerator * \param szText const reference to a message text * \return QString */ - extern KVIRC_API QString convertToHtml(const QString &szText); + extern KVIRC_API QString convertToHtml(const QString & szText); }; -#endif //_KVI_HTMLGENERATOR_H_
\ No newline at end of file +#endif //_KVI_HTMLGENERATOR_H_ diff --git a/src/modules/logview/LogViewWindow.cpp b/src/modules/logview/LogViewWindow.cpp index c392f7c74..6b428f2d3 100644 --- a/src/modules/logview/LogViewWindow.cpp +++ b/src/modules/logview/LogViewWindow.cpp @@ -672,11 +672,11 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) QString szDate = pLog->date().toString("yyyy.MM.dd"); // The fresh new log - QString szLogPath = QDir::homePath(); - KviQString::ensureLastCharIs(szLogPath,QChar(KVI_PATH_SEPARATOR_CHAR)); - szLogPath += "temp"; - szLogPath += KVI_PATH_SEPARATOR_CHAR; - QString szLog = szLogPath+QString("%1_%2.%3_%4").arg(pLog->typeString(),pLog->name(),pLog->network(),szDate); + QString szLog = QDir::homePath(); + KviQString::ensureLastCharIs(szLog,QChar(KVI_PATH_SEPARATOR_CHAR)); + szLog += "temp"; + szLog += KVI_PATH_SEPARATOR_CHAR; + szLog += QString("%1_%2.%3_%4").arg(pLog->typeString(),pLog->name(),pLog->network(),szDate); // Open file for reading QFile file(pLog->fileName()); @@ -700,7 +700,6 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) szLine = KviControlCodes::stripControlBytes(szTmp); // Remove icons' code - QRegExp rx; rx.setPattern("^\\d{1,3}\\s"); szLine.replace(rx,""); @@ -720,7 +719,7 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) szLine.replace(rx,"@"); // Remove link from a channel - // e.g.: !c#reloaded --> #reloaded + // e.g.: !c#KVIrc --> #KVIrc rx.setPattern("!c#"); szLine.replace(rx,"#"); @@ -734,6 +733,8 @@ 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; QString szTitle; switch(pLog->type()) @@ -769,12 +770,19 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) while(!input.atEnd()) { szTmp = input.readLine(); + + // Find who has talked + QString szTmpNick = szTmp.section(" ",2,2); + // locate msgtype QString szNum = szTmp.section(' ',0,0); bool bOk; int iMsgType = szNum.toInt(&bOk); - // only human text at present... - if(iMsgType!=24 && iMsgType!=26 && iMsgType!=25) continue; + + // only human text for now... + if(iMsgType != 24 && iMsgType != 25 && iMsgType != 26) + continue; + // remove msgtype tag szTmp = szTmp.remove(0,szNum.length()+1); @@ -782,32 +790,63 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) // 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+"\">"); - szBuffer += szTmp+"<br>"; - szBuffer += "\n"; + QString szIcon = g_pIconManager->getSmallIconResourceName((KviIconManager::SmallIcon)msg.pixId()); + szTmp.prepend("<img src=\"" + szIcon + "\">"); + + /* + * Check if the nick who has talked is the same of the above line. + * If so, we have to put the line as it is, otherwise we have to + * open a new paragraph + */ + if(szTmpNick != szNick) + { + /* + * People is not the same, close the paragraph opened + * before and open a new one + */ + if(!bFirstLine) + szBuffer += "</p>\n"; + szTmp.prepend("<p>"); + + szNick = szTmpNick; + bFirstLine = false; + } else { + // Break the line + szTmp += "<br />\n"; + } + + szBuffer += szTmp; } + + // Close the last paragraph + szBuffer += "</p>\n"; + // regexp to search all embedded icons - QRegExp expression("<img src=\"smallicons:([^\"]+)"); - int iIndex = szBuffer.indexOf(expression); + rx.setPattern("<img src=\"smallicons:([^\"]+)"); + int iIndex = szBuffer.indexOf(rx); QStringList szImagesList; + // search for icons while (iIndex >= 0) { - int length = expression.matchedLength(); - QString szCap = expression.cap(1); + int iLength = rx.matchedLength(); + QString szCap = rx.cap(1); + // if the icon isn't in the images list then add - if(szImagesList.indexOf(szCap)==-1) + if(szImagesList.indexOf(szCap) == -1) szImagesList.append(szCap); - iIndex = szBuffer.indexOf(expression, iIndex + length); + iIndex = szBuffer.indexOf(rx, iIndex + iLength); } + // get current theme path QString szCurrentThemePath; g_pApp->getLocalKvircDirectory(szCurrentThemePath,KviApplication::Themes,KVI_OPTION_STRING(KviOption_stringIconThemeSubdir)); szCurrentThemePath += KVI_PATH_SEPARATOR_CHAR; + // current coresmall path szCurrentThemePath += "coresmall"; szCurrentThemePath += KVI_PATH_SEPARATOR_CHAR; + // check if coresmall exists in current theme if(!KviFileUtils::directoryExists(szCurrentThemePath)) { @@ -815,23 +854,25 @@ void LogViewWindow::createLog(LogFile * pLog, int iId) g_pApp->getGlobalKvircDirectory(szCurrentThemePath,KviApplication::Pics,"coresmall"); KviQString::ensureLastCharIs(szCurrentThemePath,QChar(KVI_PATH_SEPARATOR_CHAR)); } + // copy all icons to the log destination folder - for(int i=0;i<szImagesList.count();i++) + for(int i=0; i < szImagesList.count(); i++) { - QString szSourceFile=szCurrentThemePath+szImagesList.at(i); - QString szDestFile=szLogPath+szImagesList.at(i); + QString szSourceFile = szCurrentThemePath + szImagesList.at(i); + QString szDestFile = szLog + szImagesList.at(i); KviFileUtils::copyFile(szSourceFile,szDestFile); } + // remove internal tags - szBuffer.replace(QRegExp("<qt>|</qt>|smallicons:"),""); + rx.setPattern("<qt>|</qt>|smallicons:"); + szBuffer.replace(rx,""); szBuffer.replace(">!nc",">"); szBuffer.replace("@!nc","@"); szBuffer.replace("%!nc","%"); + // Close the document szBuffer += "</body>\n</html>\n"; -// qDebug("%s",szBuffer.toUtf8().data()); - break; } } |
