diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/log/libkvilog.cpp | 23 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWidget.cpp | 18 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWidget.h | 10 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.cpp | 416 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.h | 150 | ||||
| -rw-r--r-- | src/modules/logview/libkvilogview.cpp | 32 |
6 files changed, 335 insertions, 314 deletions
diff --git a/src/modules/log/libkvilog.cpp b/src/modules/log/libkvilog.cpp index 67d6ea1a1..01cf3aa50 100644 --- a/src/modules/log/libkvilog.cpp +++ b/src/modules/log/libkvilog.cpp @@ -82,8 +82,6 @@ [fnc]$log.file[/fnc], [doc:window_naming_conventions]window naming conventions documentation[/doc] */ - - static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) { QString szFile; @@ -100,12 +98,12 @@ static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) pWnd = g_pApp->findWindow(szWindow); if(!pWnd) { - c->warning(__tr2qs("Window %Q not found"),&szWindow); + c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } } else { - c->warning(__tr2qs("Missing window id after the 'w' switch")); + c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; } } @@ -118,9 +116,9 @@ static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) pWnd->getDefaultLogFileName(szFile); } if(!pWnd->view()->startLogging(szFile,c->hasSwitch('p',"log-buffer"))) - c->warning(__tr2qs("Can't log to file %Q"),&szFile); + c->warning(__tr2qs_ctx("Can't log to file '%Q'","log"),&szFile); } else { - c->warning(__tr2qs("This window has no logging capabilities")); + c->warning(__tr2qs_ctx("This window has no logging capabilities","log")); return true; } return true; @@ -146,7 +144,6 @@ static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) [cmd]log.start[/cmd], [doc:window_naming_conventions]window naming conventions documentation[/doc] */ - static bool log_kvs_cmd_stop(KviKvsModuleCommandCall * c) { KviWindow * pWnd = c->window(); @@ -158,12 +155,12 @@ static bool log_kvs_cmd_stop(KviKvsModuleCommandCall * c) pWnd = g_pApp->findWindow(szWindow); if(!pWnd) { - c->warning(__tr2qs("Window %Q not found"),&szWindow); + c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } } else { - c->warning(__tr2qs("Missing window id after the 'w' switch")); + c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; } } @@ -197,7 +194,6 @@ static bool log_kvs_cmd_stop(KviKvsModuleCommandCall * c) [cmd]log.stop[/cmd], [doc:window_naming_conventions]window naming conventions documentation[/doc] */ - static bool log_kvs_cmd_flush(KviKvsModuleCommandCall * c) { KviWindow * pWnd = c->window(); @@ -209,12 +205,12 @@ static bool log_kvs_cmd_flush(KviKvsModuleCommandCall * c) pWnd = g_pApp->findWindow(szWindow); if(!pWnd) { - c->warning(__tr2qs("Window %Q not found"),&szWindow); + c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } } else { - c->warning(__tr2qs("Missing window id after the 'w' switch")); + c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; } } @@ -252,7 +248,6 @@ static bool log_kvs_cmd_flush(KviKvsModuleCommandCall * c) [cmd]log.stop[/cmd], [doc:window_naming_conventions]window naming conventions documentation[/doc] */ - static bool log_kvs_fnc_file(KviKvsModuleFunctionCall * c) { QString szWindow; @@ -268,7 +263,7 @@ static bool log_kvs_fnc_file(KviKvsModuleFunctionCall * c) wnd = g_pApp->findWindow(szWindow); if(!wnd) { - c->warning(__tr2qs("Window with id '%Q' not found, returning empty string"),&szWindow); + c->warning(__tr2qs_ctx("Window with id '%Q' not found, returning empty string","log"),&szWindow); return true; } } diff --git a/src/modules/logview/LogViewWidget.cpp b/src/modules/logview/LogViewWidget.cpp index 303436d08..72bfefebb 100644 --- a/src/modules/logview/LogViewWidget.cpp +++ b/src/modules/logview/LogViewWidget.cpp @@ -39,13 +39,13 @@ #include <zlib.h> #endif -LogListViewItem::LogListViewItem(QTreeWidgetItem * par, LogFile::KviLogTypes type, LogFile * fileData) +LogListViewItem::LogListViewItem(QTreeWidgetItem * par, LogFile::Type type, LogFile * fileData) : QTreeWidgetItem(par), m_type(type), m_pFileData(fileData) { setText(0,m_pFileData ? m_pFileData->name() : QString()); } -LogListViewItem::LogListViewItem(QTreeWidget * par, LogFile::KviLogTypes type, LogFile * fileData) +LogListViewItem::LogListViewItem(QTreeWidget * par, LogFile::Type type, LogFile * fileData) : QTreeWidgetItem(par), m_type(type), m_pFileData(fileData) { setText(0,m_pFileData ? m_pFileData->name() : QString()); @@ -57,7 +57,7 @@ LogListViewItemFolder::LogListViewItemFolder(QTreeWidgetItem * par, const QStrin setText(0,label); } -LogListViewItemType::LogListViewItemType(QTreeWidget * par, LogFile::KviLogTypes type) +LogListViewItemType::LogListViewItemType(QTreeWidget * par, LogFile::Type type) : LogListViewItem(par,type,0) { QIcon icon; @@ -67,23 +67,23 @@ LogListViewItemType::LogListViewItemType(QTreeWidget * par, LogFile::KviLogTypes { case LogFile::Channel: icon= QIcon(*g_pIconManager->getSmallIcon(KviIconManager::Channel)); - text = __tr2qs_ctx("Channel","logview"); + text = __tr2qs_ctx("Channel","log"); break; case LogFile::Query: icon= QIcon(*g_pIconManager->getSmallIcon(KviIconManager::Query)); - text = __tr2qs_ctx("Query","logview"); + text = __tr2qs_ctx("Query","log"); break; case LogFile::DccChat: icon= QIcon(*g_pIconManager->getSmallIcon(KviIconManager::DccMsg)); - text = __tr2qs_ctx("DCC Chat","logview"); + text = __tr2qs_ctx("DCC Chat","log"); break; case LogFile::Console: icon= QIcon(*g_pIconManager->getSmallIcon(KviIconManager::Console)); - text = __tr2qs_ctx("Console","logview"); + text = __tr2qs_ctx("Console","log"); break; default: icon= QIcon(*g_pIconManager->getSmallIcon(KviIconManager::Help)); - text = __tr2qs_ctx("Other","logview"); + text = __tr2qs_ctx("Other","log"); break; } @@ -91,7 +91,7 @@ LogListViewItemType::LogListViewItemType(QTreeWidget * par, LogFile::KviLogTypes setText(0, text); } -LogListViewLog::LogListViewLog(QTreeWidgetItem * par, LogFile::KviLogTypes type, LogFile * fileData) +LogListViewLog::LogListViewLog(QTreeWidgetItem * par, LogFile::Type type, LogFile * fileData) : LogListViewItem(par,type,fileData) { setText(0, m_pFileData->date().toString("yyyy-MM-dd")); diff --git a/src/modules/logview/LogViewWidget.h b/src/modules/logview/LogViewWidget.h index c1f33e4ea..66ce64019 100644 --- a/src/modules/logview/LogViewWidget.h +++ b/src/modules/logview/LogViewWidget.h @@ -36,11 +36,11 @@ class KviScriptEditor; class LogListViewItem : public QTreeWidgetItem { public: - LogListViewItem(QTreeWidgetItem * par, LogFile::KviLogTypes type, LogFile * fileData); - LogListViewItem(QTreeWidget * par, LogFile::KviLogTypes type, LogFile * fileData); + LogListViewItem(QTreeWidgetItem * par, LogFile::Type type, LogFile * fileData); + LogListViewItem(QTreeWidget * par, LogFile::Type type, LogFile * fileData); ~LogListViewItem() {}; public: - LogFile::KviLogTypes m_type; + LogFile::Type m_type; LogFile* m_pFileData; virtual QString fileName() const { return QString(); }; }; @@ -56,7 +56,7 @@ public: class LogListViewItemType : public LogListViewItem { public: - LogListViewItemType(QTreeWidget * par, LogFile::KviLogTypes type); + LogListViewItemType(QTreeWidget * par, LogFile::Type type); ~LogListViewItemType() {}; }; @@ -64,7 +64,7 @@ public: class LogListViewLog : public LogListViewItem { public: - LogListViewLog(QTreeWidgetItem * par, LogFile::KviLogTypes type, LogFile * fileData); + LogListViewLog(QTreeWidgetItem * par, LogFile::Type type, LogFile * fileData); ~LogListViewLog() {}; virtual QString fileName() const { return m_pFileData->fileName(); }; protected: diff --git a/src/modules/logview/LogViewWindow.cpp b/src/modules/logview/LogViewWindow.cpp index 4d67ad86d..7d5c5f3c1 100644 --- a/src/modules/logview/LogViewWindow.cpp +++ b/src/modules/logview/LogViewWindow.cpp @@ -65,11 +65,104 @@ extern LogViewWindow * g_pLogViewWindow; -LogViewWindow::LogViewWindow(KviModuleExtensionDescriptor * d,KviMainWindow * lpFrm) -: KviWindow(KviWindow::LogView,lpFrm,"logview"), KviModuleExtension(d) +LogFile::LogFile(const QString & szName) +{ + /* + Log is in the format + $type_$nick.$network_$YYYY.$MM.$DD.log + Examples: + query_noldor.azzurra_2009.05.20.log + channel_#slackware.azzurra_2009.11.03.log + */ + + m_szFilename = szName; + + QFileInfo fi(m_szFilename); + QString szTmpName = fi.fileName(); + + m_bCompressed = (fi.suffix() == "gz"); + if(m_bCompressed) + { + //removes trailing dot and extension + szTmpName.chop(3); + } + QString szTypeToken = szTmpName.section('_',0,0); + // Ignore non-logs files, this includes '.' and '..' + if(KviQString::equalCI(szTypeToken,"channel")) + m_type = Channel; + else if(KviQString::equalCI(szTypeToken,"console")) + m_type = Console; + else if(KviQString::equalCI(szTypeToken,"dccchat")) + m_type = DccChat; + else if(KviQString::equalCI(szTypeToken,"query")) + m_type = Query; + else + m_type = Other; + + KviCString szUndecoded = szTmpName.section('.',0,0); + szUndecoded.cutToFirst('_'); + m_szName = szUndecoded.hexDecode(szUndecoded.ptr()).ptr(); + + szUndecoded = szTmpName.section('.',1).section('_',0,-2); + m_szNetwork = szUndecoded.hexDecode(szUndecoded.ptr()).ptr(); + + QString szDate = szTmpName.section('_',-1).section('.',0,-2); + int iYear = szDate.section('.',0,0).toInt(); + int iMonth = szDate.section('.',1,1).toInt(); + int iDay = szDate.section('.',2,2).toInt(); + m_date.setYMD(iYear,iMonth,iDay); + + //qDebug("type=%i, name=%s, net=%s, date=%i %i %i",m_type,m_szName.ascii(),m_szNetwork.ascii(),iYear,iMonth,iDay); +} + +void LogFile::getText(QString & szText) +{ + QString szLogName = fileName(); + QFile logFile; +#ifdef COMPILE_ZLIB_SUPPORT + if(m_bCompressed) + { + gzFile file = gzopen(szLogName.toLocal8Bit().data(),"rb"); + if(file) + { + char cBuff[1025]; + int iLen; + QByteArray data; + //QCString data; + iLen = gzread(file,cBuff,1024); + while(iLen > 0) + { + cBuff[iLen] = 0; + data.append(cBuff); + iLen = gzread(file,cBuff,1024); + } + gzclose(file); + szText = QString::fromUtf8(data); + } else { + qDebug("Cannot open compressed file %s",szLogName.toLocal8Bit().data()); + } + } else { +#endif + logFile.setFileName(szLogName); + + if(!logFile.open(QIODevice::ReadOnly)) + return; + + QByteArray bytes; + bytes = logFile.readAll(); + szText = QString::fromUtf8(bytes.data(),bytes.size()); + logFile.close(); +#ifdef COMPILE_ZLIB_SUPPORT + } +#endif +} + + +LogViewWindow::LogViewWindow(KviModuleExtensionDescriptor * pDesc, KviMainWindow * pMain) +: KviWindow(KviWindow::LogView,pMain,"log"),KviModuleExtension(pDesc) { g_pLogViewWindow = this; -// m_pLogViewWidget = new KviLogViewWidget(this); + //m_pLogViewWidget = new KviLogViewWidget(this); m_pSplitter = new KviTalSplitter(Qt::Horizontal,this); m_pSplitter->setObjectName("main_splitter"); @@ -81,83 +174,82 @@ LogViewWindow::LogViewWindow(KviModuleExtensionDescriptor * d,KviMainWindow * lp m_pProgressBar = new QProgressBar(m_pBottomLayout); m_pCancelButton = new QPushButton(m_pBottomLayout); - m_pCancelButton->setText(__tr2qs_ctx("Cancel","logview")); + m_pCancelButton->setText(__tr2qs_ctx("Cancel","log")); connect(m_pCancelButton,SIGNAL(clicked()),this,SLOT(abortFilter())); m_pBottomLayout->setVisible(false); m_pIndexTab = new KviTalVBox(m_pTabWidget); - m_pTabWidget->addTab(m_pIndexTab,__tr2qs_ctx("HelpIndex","logview")); + m_pTabWidget->addTab(m_pIndexTab,__tr2qs_ctx("HelpIndex","log")); m_pListView = new LogViewListView(m_pIndexTab); connect(m_pListView,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(itemSelected(QTreeWidgetItem *,QTreeWidgetItem *))); - connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)), - this,SLOT(rightButtonClicked(QTreeWidgetItem *,QPoint))); + connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)),this,SLOT(rightButtonClicked(QTreeWidgetItem *,QPoint))); m_pSearchTab = new QWidget(m_pTabWidget); - m_pTabWidget->addTab(m_pSearchTab,__tr2qs_ctx("Filter","logview")); + m_pTabWidget->addTab(m_pSearchTab,__tr2qs_ctx("Filter","log")); - QGridLayout *layout = new QGridLayout(m_pSearchTab); + QGridLayout * pLayout = new QGridLayout(m_pSearchTab); - m_pShowChannelsCheck = new QCheckBox(__tr2qs_ctx("Show channel logs","logview"),m_pSearchTab); + m_pShowChannelsCheck = new QCheckBox(__tr2qs_ctx("Show channel logs","log"),m_pSearchTab); m_pShowChannelsCheck->setChecked(true); - layout->addWidget(m_pShowChannelsCheck,0,0,1,2); + pLayout->addWidget(m_pShowChannelsCheck,0,0,1,2); - m_pShowQueryesCheck = new QCheckBox(__tr2qs_ctx("Show query logs","logview"),m_pSearchTab); + m_pShowQueryesCheck = new QCheckBox(__tr2qs_ctx("Show query logs","log"),m_pSearchTab); m_pShowQueryesCheck->setChecked(true); - layout->addWidget(m_pShowQueryesCheck,1,0,1,2); + pLayout->addWidget(m_pShowQueryesCheck,1,0,1,2); - m_pShowConsolesCheck = new QCheckBox(__tr2qs_ctx("Show console logs","logview"),m_pSearchTab); + m_pShowConsolesCheck = new QCheckBox(__tr2qs_ctx("Show console logs","log"),m_pSearchTab); m_pShowConsolesCheck->setChecked(true); - layout->addWidget(m_pShowConsolesCheck,2,0,1,2); + pLayout->addWidget(m_pShowConsolesCheck,2,0,1,2); - m_pShowDccChatCheck = new QCheckBox(__tr2qs_ctx("Show DCC chat logs","logview"),m_pSearchTab); + m_pShowDccChatCheck = new QCheckBox(__tr2qs_ctx("Show DCC chat logs","log"),m_pSearchTab); m_pShowDccChatCheck->setChecked(true); - layout->addWidget(m_pShowDccChatCheck,3,0,1,2); + pLayout->addWidget(m_pShowDccChatCheck,3,0,1,2); - m_pShowOtherCheck = new QCheckBox(__tr2qs_ctx("Show other logs","logview"),m_pSearchTab); + m_pShowOtherCheck = new QCheckBox(__tr2qs_ctx("Show other logs","log"),m_pSearchTab); m_pShowOtherCheck->setChecked(true); - layout->addWidget(m_pShowOtherCheck,4,0,1,2); + pLayout->addWidget(m_pShowOtherCheck,4,0,1,2); - QLabel *l; - l = new QLabel(__tr2qs_ctx("Contents filter","logview"),m_pSearchTab); - layout->addWidget(l,5,0,1,2); + QLabel * pLabel; + pLabel = new QLabel(__tr2qs_ctx("Contents filter","log"),m_pSearchTab); + pLayout->addWidget(pLabel,5,0,1,2); - l = new QLabel(__tr2qs_ctx("Log name mask:","logview"),m_pSearchTab); + pLabel = new QLabel(__tr2qs_ctx("Log name mask:","log"),m_pSearchTab); m_pFileNameMask = new QLineEdit(m_pSearchTab); + pLayout->addWidget(pLabel,6,0); + pLayout->addWidget(m_pFileNameMask,6,1); connect(m_pFileNameMask,SIGNAL(returnPressed()),this,SLOT(applyFilter())); - layout->addWidget(l,6,0); - layout->addWidget(m_pFileNameMask,6,1); - l = new QLabel(__tr2qs_ctx("Log contents mask:","logview"),m_pSearchTab); + pLabel = new QLabel(__tr2qs_ctx("Log contents mask:","log"),m_pSearchTab); m_pContentsMask = new QLineEdit(m_pSearchTab); + pLayout->addWidget(pLabel,7,0); + pLayout->addWidget(m_pContentsMask,7,1); connect(m_pContentsMask,SIGNAL(returnPressed()),this,SLOT(applyFilter())); - layout->addWidget(l,7,0); - layout->addWidget(m_pContentsMask,7,1); - m_pEnableFromFilter = new QCheckBox(__tr2qs_ctx("Only older than","logview"),m_pSearchTab); + m_pEnableFromFilter = new QCheckBox(__tr2qs_ctx("Only older than","log"),m_pSearchTab); m_pFromDateEdit = new QDateEdit(m_pSearchTab); m_pFromDateEdit->setDate(QDate::currentDate()); - layout->addWidget(m_pEnableFromFilter,8,0); - layout->addWidget(m_pFromDateEdit,8,1); - connect(m_pEnableFromFilter,SIGNAL(toggled(bool)),m_pFromDateEdit,SLOT(setEnabled(bool))); m_pFromDateEdit->setEnabled(false); + pLayout->addWidget(m_pEnableFromFilter,8,0); + pLayout->addWidget(m_pFromDateEdit,8,1); + connect(m_pEnableFromFilter,SIGNAL(toggled(bool)),m_pFromDateEdit,SLOT(setEnabled(bool))); - m_pEnableToFilter = new QCheckBox(__tr2qs_ctx("Only newier than","logview"),m_pSearchTab); + m_pEnableToFilter = new QCheckBox(__tr2qs_ctx("Only newier than","log"),m_pSearchTab); m_pToDateEdit = new QDateEdit(m_pSearchTab); m_pToDateEdit->setDate(QDate::currentDate()); - layout->addWidget(m_pEnableToFilter,9,0); - layout->addWidget(m_pToDateEdit,9,1); - connect(m_pEnableToFilter,SIGNAL(toggled(bool)),m_pToDateEdit,SLOT(setEnabled(bool))); m_pToDateEdit->setEnabled(false); + pLayout->addWidget(m_pEnableToFilter,9,0); + pLayout->addWidget(m_pToDateEdit,9,1); + connect(m_pEnableToFilter,SIGNAL(toggled(bool)),m_pToDateEdit,SLOT(setEnabled(bool))); - m_pFilterButton = new QPushButton(__tr2qs_ctx("Apply filter","logview"),m_pSearchTab); + m_pFilterButton = new QPushButton(__tr2qs_ctx("Apply filter","log"),m_pSearchTab); + pLayout->addWidget(m_pFilterButton,10,1); connect(m_pFilterButton,SIGNAL(clicked()),this,SLOT(applyFilter())); - layout->addWidget(m_pFilterButton,10,1); - QWidget *w = new QWidget(m_pSearchTab); - w->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); - layout->addWidget(w,11,1); + QWidget * pWidget = new QWidget(m_pSearchTab); + pWidget->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); + pLayout->addWidget(pWidget,11,1); m_pIrcView = new KviIrcView(m_pSplitter,g_pMainWindow,this); m_pIrcView->setMaxBufferSize(INT_MAX); @@ -168,16 +260,13 @@ LogViewWindow::LogViewWindow(KviModuleExtensionDescriptor * d,KviMainWindow * lp li.append(width()-110); m_pSplitter->setSizes(li); - g_pApp->getLocalKvircDirectory(m_szLogDirectory,KviApplication::Log); - KviQString::ensureLastCharIs(m_szLogDirectory,'/'); // Does this work on Windows? - m_pTimer = new QTimer(this); m_pTimer->setSingleShot(true); m_pTimer->setInterval(0); - connect(m_pTimer, SIGNAL(timeout()), this, SLOT(filterNext())); + connect(m_pTimer,SIGNAL(timeout()),this,SLOT(filterNext())); //avoid to execute the long time-consuming procedure of log indexing here: //we could still be inside the context of the "Browse log files" QAction - QTimer::singleShot( 0, this, SLOT(cacheFileList()) ); + QTimer::singleShot(0,this,SLOT(cacheFileList())); } LogViewWindow::~LogViewWindow() @@ -185,19 +274,17 @@ LogViewWindow::~LogViewWindow() g_pLogViewWindow = 0; } -void LogViewWindow::keyPressEvent(QKeyEvent *e) +void LogViewWindow::keyPressEvent(QKeyEvent * pEvent) { -//Make CtrlKey and CommandKey ("Apple") behave equally on MacOSX. -//This way typical X11 and Apple shortcuts can be used simultanously within the input line. - if((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::AltModifier) || (e->modifiers() & Qt::MetaModifier)) + if((pEvent->modifiers() & Qt::ControlModifier) || (pEvent->modifiers() & Qt::AltModifier) || (pEvent->modifiers() & Qt::MetaModifier)) { - if(e->key() == Qt::Key_F) + if(pEvent->key() == Qt::Key_F) { m_pIrcView->toggleToolWidget(); return; } } - KviWindow::keyPressEvent(e); + KviWindow::keyPressEvent(pEvent); } void LogViewWindow::applyFilter() @@ -217,7 +304,7 @@ void LogViewWindow::resizeEvent(QResizeEvent *) void LogViewWindow::fillCaptionBuffers() { - m_szPlainTextCaption = __tr2qs_ctx("Log Viewer","logview"); + m_szPlainTextCaption = __tr2qs_ctx("Log Viewer","log"); } void LogViewWindow::die() @@ -241,7 +328,7 @@ void LogViewWindow::setupItemList() m_bAborted=false; m_pBottomLayout->setVisible(true); - m_pProgressBar->setRange(0, m_logList.count()); + m_pProgressBar->setRange(0,m_logList.count()); m_pProgressBar->setValue(0); m_pLastCategory=0; @@ -252,13 +339,13 @@ void LogViewWindow::setupItemList() void LogViewWindow::abortFilter() { - m_bAborted=true; + m_bAborted = true; } void LogViewWindow::filterNext() { QString szCurGroup; - LogFile * pFile=m_logList.current(); + LogFile * pFile = m_logList.current(); if(!pFile) goto filter_last; @@ -287,9 +374,9 @@ void LogViewWindow::filterNext() if(!m_pContentsMask->text().isEmpty()) { - QString textBuffer; - pFile->getText(textBuffer,m_szLogDirectory); - if(!KviQString::matchString(m_pContentsMask->text(),textBuffer)) + QString szBuffer; + pFile->getText(szBuffer); + if(!KviQString::matchString(m_pContentsMask->text(),szBuffer)) goto filter_next; } @@ -298,7 +385,7 @@ void LogViewWindow::filterNext() if(m_pLastCategory->m_type!=pFile->type()) { m_pLastCategory=0; - for(int i=0;i<m_pListView->topLevelItemCount(); ++i) + for(int i=0; i < m_pListView->topLevelItemCount(); ++i) { LogListViewItemType * pTmp = (LogListViewItemType*) m_pListView->topLevelItem(i); if(pTmp->m_type == pFile->type()) @@ -314,24 +401,24 @@ void LogViewWindow::filterNext() m_pLastCategory = new LogListViewItemType(m_pListView,pFile->type()); } - szCurGroup = QString(__tr2qs_ctx("%1 on %2","logview")).arg(pFile->name(),pFile->network()); + szCurGroup = QString(__tr2qs_ctx("%1 on %2","log")).arg(pFile->name(),pFile->network()); - if(m_szLastGroup!=szCurGroup) + if(m_szLastGroup != szCurGroup) { - m_szLastGroup=szCurGroup; - m_pLastGroupItem=0; - for(int i=0;i<m_pLastCategory->childCount(); ++i) + m_szLastGroup = szCurGroup; + m_pLastGroupItem = 0; + for(int i=0; i < m_pLastCategory->childCount(); ++i) { LogListViewItemFolder * pTmp = (LogListViewItemFolder*) m_pLastCategory->child(i); if(pTmp->text(0) == m_szLastGroup) { - m_pLastGroupItem=pTmp; + m_pLastGroupItem = pTmp; break; } } if(!m_pLastGroupItem) - m_pLastGroupItem=new LogListViewItemFolder(m_pLastCategory,m_szLastGroup); + m_pLastGroupItem = new LogListViewItemFolder(m_pLastCategory,m_szLastGroup); } new LogListViewLog(m_pLastGroupItem,pFile->type(),pFile); @@ -354,51 +441,49 @@ filter_last: void LogViewWindow::cacheFileList() { - QString logPath; - g_pApp->getLocalKvircDirectory(logPath,KviApplication::Log); - recurseDirectory(logPath); + QString szLogPath; + g_pApp->getLocalKvircDirectory(szLogPath,KviApplication::Log); + recurseDirectory(szLogPath); setupItemList(); } -void LogViewWindow::recurseDirectory(const QString& sDir) +void LogViewWindow::recurseDirectory(const QString & szDir) { - QDir dir(sDir); + QDir dir(szDir); QFileInfoList list = dir.entryInfoList(); - for (int iList=0;iList<list.count();iList++) + for(int iList=0; iList < list.count(); iList++) { QFileInfo info = list[iList]; - if (info.isDir()) + if(info.isDir()) { // recursive - if (info.fileName()!=".." && info.fileName()!=".") - { + if(info.fileName()!=".." && info.fileName()!=".") recurseDirectory(info.filePath()); - } - } else if(info.suffix()=="gz" || info.suffix()=="log") { + } else if(info.suffix() == "gz" || info.suffix() == "log") + { m_logList.append(new LogFile(info.filePath())); } } } -void LogViewWindow::itemSelected(QTreeWidgetItem * it,QTreeWidgetItem *) +void LogViewWindow::itemSelected(QTreeWidgetItem * it, QTreeWidgetItem *) { //A parent node m_pIrcView->clearBuffer(); - if(!it || !it->parent() || !(((LogListViewItem *)it)->m_pFileData) ) - { + if(!it || !it->parent() || !(((LogListViewItem *)it)->m_pFileData)) return; - } - QString text; - ((LogListViewItem *)it)->m_pFileData->getText(text,m_szLogDirectory); + QString szText; + ((LogListViewItem *)it)->m_pFileData->getText(szText); - QStringList lines= text.split('\n'); + QStringList lines = szText.split('\n'); bool bOk; int iMsgType; - for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) { - QString num=(*it).section(' ',0,0); - iMsgType=num.toInt(&bOk); + for(QStringList::Iterator it = lines.begin(); it != lines.end(); ++it) + { + QString szNum = (*it).section(' ',0,0); + iMsgType = szNum.toInt(&bOk); if(bOk) outputNoFmt(iMsgType,(*it).section(' ',1),KviIrcView::NoRepaint | KviIrcView::NoTimestamp); else @@ -407,45 +492,47 @@ void LogViewWindow::itemSelected(QTreeWidgetItem * it,QTreeWidgetItem *) m_pIrcView->repaint(); } -void LogViewWindow::rightButtonClicked ( QTreeWidgetItem * it, const QPoint &) +void LogViewWindow::rightButtonClicked( QTreeWidgetItem * it, const QPoint &) { - if(!it) return; + if(!it) + return; m_pListView->setCurrentItem(it); - KviTalPopupMenu* popup = new KviTalPopupMenu(this); + KviTalPopupMenu * pPopup = new KviTalPopupMenu(this); if(((LogListViewItem *)it)->childCount()) - popup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove all these channel/query log files","logview"),this,SLOT(deleteCurrent())); - else popup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove file","logview"),this,SLOT(deleteCurrent())); + pPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove all these channel/query log files","log"),this,SLOT(deleteCurrent())); + else + pPopup->insertItem(*(g_pIconManager->getSmallIcon(KviIconManager::Quit)),__tr2qs_ctx("Remove file","log"),this,SLOT(deleteCurrent())); - popup->exec( QCursor::pos() ); + pPopup->exec(QCursor::pos()); } void LogViewWindow::deleteCurrent() { - LogListViewItem* pItem = (LogListViewItem *)(m_pListView->currentItem()); + LogListViewItem * pItem = (LogListViewItem *)(m_pListView->currentItem()); if(pItem) { - if (pItem->childCount()) + if(pItem->childCount()) { if(QMessageBox::question( this, - __tr2qs_ctx("Confirm current user logs delete","logview"), - __tr2qs_ctx("Do you really wish to delete all these channel/query logs?","logview"), - __tr2qs("&Yes"),__tr2qs("&No"),0,1 - ) != 0) return; + __tr2qs_ctx("Confirm current user logs delete","log"), + __tr2qs_ctx("Do you really wish to delete all these channel/query logs?","log"), + __tr2qs("&Yes"),__tr2qs("&No"),0,1) != 0) + return; KviPointerList <LogListViewItem> itemsList; itemsList.setAutoDelete(false); - for(int i=0;i<pItem->childCount();i++) + for(int i=0; i < pItem->childCount(); i++) { - if (!pItem->child(i)->childCount()) + if(!pItem->child(i)->childCount()) { itemsList.append((LogListViewItem*)pItem->child(i)); continue; } - LogListViewItem* pChild=(LogListViewItem*)pItem->child(i); - for(int j=0;j<pChild->childCount();j++) + LogListViewItem * pChild = (LogListViewItem*)pItem->child(i); + for(int j=0; j < pChild->childCount(); j++) { - if (!(LogListViewItem*)pChild->child(j)) + if(!(LogListViewItem*)pChild->child(j)) { qDebug("Null pointer in logviewitem"); continue; @@ -453,9 +540,9 @@ void LogViewWindow::deleteCurrent() itemsList.append((LogListViewItem*)pChild->child(j)); } } - for(unsigned int i=0;i<itemsList.count();i++) + for(unsigned int u=0; u < itemsList.count(); u++) { - LogListViewItem *pCurItem=itemsList.at(i); + LogListViewItem * pCurItem = itemsList.at(u); if(!pCurItem->fileName().isNull()) { QString szFname; @@ -466,132 +553,43 @@ void LogViewWindow::deleteCurrent() delete pItem; return; } - if(!pItem->fileName().isNull()) + if(!pItem->fileName().isNull()) { QString szFname; g_pApp->getLocalKvircDirectory(szFname,KviApplication::Log,pItem->fileName()); KviFileUtils::removeFile(szFname); delete pItem; m_pIrcView->clearBuffer(); - if (!pItem->parent()->childCount()) delete pItem->parent(); + if(!pItem->parent()->childCount()) + delete pItem->parent(); } } } -LogFile::LogFile(const QString & szName) -{ - /* - Log is in the format - $type_$nick.$network_$YYYY.$MM.$DD.log - Examples: - query_noldor.azzurra_2009.05.20.log - channel_#slackware.azzurra_2009.11.03.log - */ - - m_szFilename = szName; - - QFileInfo fi(m_szFilename); - QString szTmpName = fi.fileName(); - - m_bCompressed = (fi.suffix() == "gz"); - if(m_bCompressed) - { - //removes trailing dot and extension - szTmpName.chop(3); - } - QString szTypeToken = szTmpName.section('_',0,0); - // Ignore non-logs files, this includes '.' and '..' - if(KviQString::equalCI(szTypeToken,"channel")) - m_type = Channel; - else if(KviQString::equalCI(szTypeToken,"console")) - m_type = Console; - else if(KviQString::equalCI(szTypeToken,"dccchat")) - m_type = DccChat; - else if(KviQString::equalCI(szTypeToken,"query")) - m_type = Query; - else - m_type = Other; - - KviCString szUndecoded = szTmpName.section('.',0,0); - szUndecoded.cutToFirst('_'); - m_szName = szUndecoded.hexDecode(szUndecoded.ptr()).ptr(); - - szUndecoded = szTmpName.section('.',1).section('_',0,-2); - m_szNetwork = szUndecoded.hexDecode(szUndecoded.ptr()).ptr(); - - QString szDate = szTmpName.section('_',-1).section('.',0,-2); - int iYear = szDate.section('.',0,0).toInt(); - int iMonth = szDate.section('.',1,1).toInt(); - int iDay = szDate.section('.',2,2).toInt(); - m_date.setYMD(iYear,iMonth,iDay); - - //qDebug("type=%i, name=%s, net=%s, date=%i %i %i",m_type,m_szName.ascii(),m_szNetwork.ascii(),iYear,iMonth,iDay); -} - -void LogFile::getText(QString & text,const QString&) -{ - QString logName = fileName(); - QFile logFile; -#ifdef COMPILE_ZLIB_SUPPORT - if(m_bCompressed) - { - gzFile file=gzopen(logName.toLocal8Bit().data(),"rb"); - if(file) - { - char buff[1025]; - int len; - QByteArray data; - //QCString data; - len=gzread(file,buff,1024); - while(len>0) - { - buff[len]=0; - data.append(buff); - len=gzread(file,buff,1024); - } - gzclose(file); - text = QString::fromUtf8(data); - } else { - qDebug("Cannot open compressed file %s",logName.toLocal8Bit().data()); - } - } else { -#endif - logFile.setFileName(logName); - - if(!logFile.open(QIODevice::ReadOnly)) - return; - - QByteArray bytes; - bytes=logFile.readAll(); - text = QString::fromUtf8(bytes.data(), bytes.size()); - logFile.close(); -#ifdef COMPILE_ZLIB_SUPPORT - } -#endif -} -LogViewListView::LogViewListView(QWidget * par) -: QTreeWidget(par) +LogViewListView::LogViewListView(QWidget * pParent) +: QTreeWidget(pParent) { header()->setSortIndicatorShown(true); setColumnCount(1); - setHeaderLabel(__tr2qs_ctx("Log File","logview")); + setHeaderLabel(__tr2qs_ctx("Log File","log")); setSelectionMode(QAbstractItemView::SingleSelection); setSortingEnabled(true); setRootIsDecorated(true); setAnimated(true); } -void LogViewListView::mousePressEvent (QMouseEvent *e) +void LogViewListView::mousePressEvent(QMouseEvent * pEvent) { - if (e->button() == Qt::RightButton) + if(pEvent->button() == Qt::RightButton) { - QTreeWidgetItem *i=itemAt(e->pos()); - if (i) emit rightButtonPressed(i,QCursor::pos()); + QTreeWidgetItem * pItem = itemAt(pEvent->pos()); + if(pItem) + emit rightButtonPressed(pItem,QCursor::pos()); } - QTreeWidget::mousePressEvent(e); + QTreeWidget::mousePressEvent(pEvent); } #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES #include "LogViewWindow.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES +#endif //COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/logview/LogViewWindow.h b/src/modules/logview/LogViewWindow.h index 2cd9b61ad..2cea68d2c 100644 --- a/src/modules/logview/LogViewWindow.h +++ b/src/modules/logview/LogViewWindow.h @@ -1,5 +1,5 @@ -#ifndef _LOGVIEWMDIWINDOW_H_ -#define _LOGVIEWMDIWINDOW_H_ +#ifndef _LOGVIEWWINDOW_H_ +#define _LOGVIEWWINDOW_H_ //============================================================================= // // File : LogViewWindow.h @@ -8,6 +8,7 @@ // This file is part of the KVIrc irc client distribution // Copyright (C) 2002 Juanjo Alvarez // Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2011 Elvio Basello (hellvis69 at gmail dot com) // // This program is FREE software. You can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -29,50 +30,90 @@ #include "KviWindow.h" #include "KviModuleExtension.h" #include "KviTalVBox.h" -#include <QTreeWidget> #include "KviPointerList.h" +#include <QTreeWidget> #include <QTabWidget> #include <QDateTime> #include <QCheckBox> +class KviLogViewWidget; +class LogListViewItem; +class LogListViewItemFolder; class QProgressBar; class QStringList; class QLineEdit; class QDateEdit; -class KviLogViewWidget; -class LogListViewItem; -class LogListViewItemFolder; - -class LogFile { +/** +* \class LogFile +* \brief The LogFile class which handle any log file +*/ +class LogFile +{ public: - - enum KviLogTypes { - Channel, - Console, - Query, - DccChat, - Other + /** + * \enum Type + * \brief Holds the type of the log + */ + enum Type { + Channel, /**< the log file of a channel */ + Console, /**< the log file of a console */ + Query, /**< the log file of a query */ + DccChat, /**< the log file of a dcc chat */ + Other /**< any other log file */ }; - LogFile(const QString& name); + /** + * \brief Constructs the log file object + * \param szName The name of the log + * \return LogFile + */ + LogFile(const QString & szName); +private: + Type m_type; + QString m_szFilename; + bool m_bCompressed; + QString m_szName; + QString m_szNetwork; + QDate m_date; +public: + /** + * \brief Returns the type of the log + * \return Type + */ + Type type() const { return m_type; }; + /** + * \brief Returns the filename of the log + * \return const QString & + */ const QString & fileName() const { return m_szFilename; }; + + /** + * \brief Returns the name of the log + * \return const QString & + */ const QString & name() const { return m_szName; }; + + /** + * \brief Returns the network of the log + * \return const QString & + */ const QString & network() const { return m_szNetwork; }; - const QDate & date() const { return m_date; }; - void getText(QString & text,const QString& logDir); + /** + * \brief Returns the date of the log + * \return const QDate & + */ + const QDate & date() const { return m_date; }; - KviLogTypes type() const { return m_type; }; -private: - KviLogTypes m_type; - QString m_szFilename; - bool m_bCompressed; - QString m_szName; - QString m_szNetwork; - QDate m_date; + /** + * \brief Returns the text of the log file + * \param szText The buffer where to save the contents of the log + * \return void + */ + void getText(QString & szText); }; class LogViewListView : public QTreeWidget @@ -89,47 +130,46 @@ signals: class LogViewWindow : public KviWindow, public KviModuleExtension { - Q_OBJECT + Q_OBJECT public: LogViewWindow(KviModuleExtensionDescriptor * d,KviMainWindow * lpFrm); ~LogViewWindow(); protected: KviPointerList<LogFile> m_logList; - LogViewListView * m_pListView; + LogViewListView * m_pListView; // Type filter - QCheckBox * m_pShowChannelsCheck; - QCheckBox * m_pShowQueryesCheck; - QCheckBox * m_pShowConsolesCheck; - QCheckBox * m_pShowOtherCheck; - QCheckBox * m_pShowDccChatCheck; + QCheckBox * m_pShowChannelsCheck; + QCheckBox * m_pShowQueryesCheck; + QCheckBox * m_pShowConsolesCheck; + QCheckBox * m_pShowOtherCheck; + QCheckBox * m_pShowDccChatCheck; // Content filter - QLineEdit * m_pFileNameMask; - QLineEdit * m_pContentsMask; + QLineEdit * m_pFileNameMask; + QLineEdit * m_pContentsMask; // Date/time mask - QCheckBox * m_pEnableFromFilter; - QCheckBox * m_pEnableToFilter; - QDateEdit * m_pFromDateEdit; - QDateEdit * m_pToDateEdit; + QCheckBox * m_pEnableFromFilter; + QCheckBox * m_pEnableToFilter; + QDateEdit * m_pFromDateEdit; + QDateEdit * m_pToDateEdit; - QStringList * m_pFileNames; - QString m_szLogDirectory; - QTabWidget * m_pTabWidget; - KviTalVBox * m_pIndexTab; - KviTalVBox * m_pLeftLayout; - QWidget * m_pSearchTab; - QPushButton * m_pFilterButton; - QPushButton * m_pCancelButton; - KviTalHBox * m_pBottomLayout; - QProgressBar * m_pProgressBar; - LogListViewItem * m_pLastCategory; - LogListViewItemFolder *m_pLastGroupItem; - QString m_szLastGroup; - bool m_bAborted; - QTimer * m_pTimer; + QStringList * m_pFileNames; + QTabWidget * m_pTabWidget; + KviTalVBox * m_pIndexTab; + KviTalVBox * m_pLeftLayout; + QWidget * m_pSearchTab; + QPushButton * m_pFilterButton; + QPushButton * m_pCancelButton; + KviTalHBox * m_pBottomLayout; + QProgressBar * m_pProgressBar; + LogListViewItem * m_pLastCategory; + LogListViewItemFolder * m_pLastGroupItem; + QString m_szLastGroup; + bool m_bAborted; + QTimer * m_pTimer; protected: void recurseDirectory(const QString& sDir); @@ -150,4 +190,4 @@ protected slots: void filterNext(); }; -#endif //_LOGVIEWMDIWINDOW_H_ +#endif //_LOGVIEWWINDOW_H_ diff --git a/src/modules/logview/libkvilogview.cpp b/src/modules/logview/libkvilogview.cpp index 66e63cefa..5bce7a4ff 100644 --- a/src/modules/logview/libkvilogview.cpp +++ b/src/modules/logview/libkvilogview.cpp @@ -32,8 +32,8 @@ #include "KviLocale.h" #include "KviApplication.h" -static QRect g_rectLogViewGeometry; -LogViewWindow * g_pLogViewWindow = 0; +static QRect g_rectLogViewGeometry; +LogViewWindow * g_pLogViewWindow = 0; #define LOGVIEW_MODULE_EXTENSION_NAME "Log viewer extension" @@ -56,11 +56,6 @@ LogViewWindow * g_pLogViewWindow = 0; Opens a window that allows visual browsing of the logs stored on disk. */ - -// ============================================ -// Module stuff -// ============================================ - static bool logview_kvs_cmd_open(KviKvsModuleCommandCall * c) { KviModuleExtensionDescriptor * d = c->module()->findExtensionDescriptor("tool",LOGVIEW_MODULE_EXTENSION_NAME); @@ -74,7 +69,7 @@ static bool logview_kvs_cmd_open(KviKvsModuleCommandCall * c) d->allocate(c->window(),&dict,0); } else { - c->warning("Ops.. internal error"); + c->warning(__tr2qs_ctx("Ops.. internal error","log")); } return true; } @@ -93,9 +88,7 @@ static KviModuleExtension * logview_extension_alloc(KviModuleExtensionAllocStruc if(v->isValid()) { if(v->type() == QVariant::Bool) - { bCreateMinimized = v->toBool(); - } } } } @@ -118,7 +111,8 @@ static KviModuleExtension * logview_extension_alloc(KviModuleExtensionAllocStruc } } - if(!bNoRaise)g_pLogViewWindow->delayedAutoRaise(); + if(!bNoRaise) + g_pLogViewWindow->delayedAutoRaise(); return g_pLogViewWindow; } @@ -128,14 +122,13 @@ static bool logview_module_init(KviModule * m) KVSM_REGISTER_SIMPLE_COMMAND(m,"open",logview_kvs_cmd_open); - - KviModuleExtensionDescriptor * d = m->registerExtension("tool", - LOGVIEW_MODULE_EXTENSION_NAME, - __tr2qs_ctx("Browse &Log Files","logview"), - logview_extension_alloc); + LOGVIEW_MODULE_EXTENSION_NAME, + __tr2qs_ctx("Browse Log Files","log"), + logview_extension_alloc); - if(d)d->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Log))); + if(d) + d->setIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Log))); return true; } @@ -153,11 +146,6 @@ static bool logview_module_can_unload(KviModule *) return (!g_pLogViewWindow); } - -// ============================================ -// module definition structure -// ============================================ - KVIRC_MODULE( "KVIrc Log Viewer Widget", "4.0.0", |
