diff options
| author | 2011-04-14 21:21:43 +0000 | |
|---|---|---|
| committer | 2011-04-14 21:21:43 +0000 | |
| commit | b051d48fd5eff9045d245aef9ec7b99b32fea375 (patch) | |
| tree | cb4fe4725a9f5962a7d9bcdaf5f46f0f95656d4c | |
| parent | Another fix in theme module (diff) | |
| download | KVIrc-b051d48fd5eff9045d245aef9ec7b99b32fea375.tar.gz KVIrc-b051d48fd5eff9045d245aef9ec7b99b32fea375.tar.bz2 KVIrc-b051d48fd5eff9045d245aef9ec7b99b32fea375.zip | |
added initial implementation of $log.export() (wip);
splitted LogFile class in its own files;
added control procedure to call logview functions from log module
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5785 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | src/kvirc/kernel/KviApplication.h | 11 | ||||
| -rw-r--r-- | src/modules/log/libkvilog.cpp | 76 | ||||
| -rw-r--r-- | src/modules/logview/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/modules/logview/LogFile.cpp | 126 | ||||
| -rw-r--r-- | src/modules/logview/LogFile.h | 134 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.cpp | 109 | ||||
| -rw-r--r-- | src/modules/logview/LogViewWindow.h | 102 | ||||
| -rw-r--r-- | src/modules/logview/libkvilogview.cpp | 27 |
8 files changed, 362 insertions, 224 deletions
diff --git a/src/kvirc/kernel/KviApplication.h b/src/kvirc/kernel/KviApplication.h index f31f419d0..86e3f5c9c 100644 --- a/src/kvirc/kernel/KviApplication.h +++ b/src/kvirc/kernel/KviApplication.h @@ -91,6 +91,17 @@ typedef struct _KviNotifierMessageParam unsigned int uMessageLifetime; /**< The timeout of the notifier; 0 means no hide */ } KviNotifierMessageParam; +/** +* \typedef KviLogFileData +* \struct _KviLogFileData +* \brief A struct that contains the data of a log +*/ +typedef struct _KviLogFileData +{ + QString szName; /**< the name of the log */ + QString szType; /**< the type of the log */ +} KviLogFileData; + typedef struct _KviDBusNotifierMessageQueue { QStringList lMessages; diff --git a/src/modules/log/libkvilog.cpp b/src/modules/log/libkvilog.cpp index 01cf3aa50..316116890 100644 --- a/src/modules/log/libkvilog.cpp +++ b/src/modules/log/libkvilog.cpp @@ -27,7 +27,7 @@ #include "KviApplication.h" #include "KviLocale.h" #include "KviIrcView.h" - +#include "KviModuleManager.h" //#warning "log.stats" //#warning "log.compress (gzip -r the log directory)" @@ -101,7 +101,6 @@ static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } - } else { c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; @@ -110,11 +109,9 @@ static bool log_kvs_cmd_start(KviKvsModuleCommandCall * c) if(pWnd->view()) { - if(szFile.isEmpty()) - { pWnd->getDefaultLogFileName(szFile); - } + if(!pWnd->view()->startLogging(szFile,c->hasSwitch('p',"log-buffer"))) c->warning(__tr2qs_ctx("Can't log to file '%Q'","log"),&szFile); } else { @@ -158,14 +155,14 @@ static bool log_kvs_cmd_stop(KviKvsModuleCommandCall * c) c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } - } else { c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; } } - if(pWnd->view()) pWnd->view()->stopLogging(); + if(pWnd->view()) + pWnd->view()->stopLogging(); return true; } @@ -208,14 +205,14 @@ static bool log_kvs_cmd_flush(KviKvsModuleCommandCall * c) c->warning(__tr2qs_ctx("Window '%Q' not found","log"),&szWindow); return true; } - } else { c->warning(__tr2qs_ctx("Missing window id after the 'w' switch","log")); return true; } } - if(pWnd->view()) pWnd->view()->flushLog(); + if(pWnd->view()) + pWnd->view()->flushLog(); return true; } @@ -250,26 +247,72 @@ static bool log_kvs_cmd_flush(KviKvsModuleCommandCall * c) */ static bool log_kvs_fnc_file(KviKvsModuleFunctionCall * c) { - QString szWindow; - QString buffer; + QString szWindow, szBuffer; + KVSM_PARAMETERS_BEGIN(c) KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWindow) KVSM_PARAMETERS_END(c) - KviWindow * wnd = c->window(); + KviWindow * pWnd = c->window(); if(!szWindow.isEmpty()) { - wnd = g_pApp->findWindow(szWindow); - if(!wnd) + pWnd = g_pApp->findWindow(szWindow); + if(!pWnd) { c->warning(__tr2qs_ctx("Window with id '%Q' not found, returning empty string","log"),&szWindow); return true; } } - if(wnd->view())wnd->view()->getLogFileName(buffer); - c->returnValue()->setString(buffer); + if(pWnd->view()) + pWnd->view()->getLogFileName(szBuffer); + c->returnValue()->setString(szBuffer); + return true; +} + +/* + @doc: log.export + @type: + function + @title: + $log.export + @short: + Exports the specified log to the given format and returns the filename + @syntax: + <string> $log.export(<filename:string>[,<type:string>]) + @description: + + @example: + [example] + [cmd]echo[/cmd] $log.export([fnc]$log.file[/fnc],"html") + [/example] + @seealso: + [cmd]log.start[/cmd], + [cmd]log.stop[/cmd] +*/ +static bool log_kvs_fnc_export(KviKvsModuleFunctionCall * c) +{ + QString szFile, szType; + + KVSM_PARAMETERS_BEGIN(c) + KVSM_PARAMETER("filename",KVS_PT_NONEMPTYSTRING,0,szFile) + KVSM_PARAMETER("type",KVS_PT_STRING,KVS_PF_OPTIONAL,szType) + KVSM_PARAMETERS_END(c) + + if(szType.isEmpty()) + szType = "txt"; + + KviModule * m = g_pModuleManager->getModule("logview"); + if(!m) + return false; + + KviLogFileData log; + log.szName = szFile; + log.szType = szType; + + m->ctrl("logview::export",(void *)&log); + return true; } @@ -280,6 +323,7 @@ static bool log_module_init(KviModule * m) KVSM_REGISTER_SIMPLE_COMMAND(m,"flush",log_kvs_cmd_flush); KVSM_REGISTER_FUNCTION(m,"file",log_kvs_fnc_file); + KVSM_REGISTER_FUNCTION(m,"export",log_kvs_fnc_export); return true; } diff --git a/src/modules/logview/CMakeLists.txt b/src/modules/logview/CMakeLists.txt index d413a069e..dba267ce0 100644 --- a/src/modules/logview/CMakeLists.txt +++ b/src/modules/logview/CMakeLists.txt @@ -8,6 +8,7 @@ SET(kvilogview_MOC_HDRS SET(kvilogview_SRCS libkvilogview.cpp + LogFile.cpp LogViewWidget.cpp LogViewWindow.cpp ) diff --git a/src/modules/logview/LogFile.cpp b/src/modules/logview/LogFile.cpp new file mode 100644 index 000000000..f9c7d0cb3 --- /dev/null +++ b/src/modules/logview/LogFile.cpp @@ -0,0 +1,126 @@ +//============================================================================= +// +// File : LogFile.cpp +// Creation date : Thu Apr 14 2011 19:21:59 by Elvio Basello +// +// This file is part of the KVIrc irc client distribution +// 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 +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// 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, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "LogFile.h" + +#include "KviQString.h" +#include "KviCString.h" + +#include <QFileInfo> + +#ifdef COMPILE_ZLIB_SUPPORT + #include <zlib.h> +#endif + +LogFile::LogFile(const QString & szName) +{ + 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") || KviQString::equalCI(szTypeToken,"deadchannel")) + { + m_szType = "channel"; + m_eType = Channel; + } else if(KviQString::equalCI(szTypeToken,"console")) + { + m_szType = "console"; + m_eType = Console; + } else if(KviQString::equalCI(szTypeToken,"query")) + { + m_szType = "query"; + m_eType = Query; + } else if(KviQString::equalCI(szTypeToken,"dccchat")) + { + m_szType = "dccchat"; + m_eType = DccChat; + } else { + m_szType = ""; + m_eType = 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); +} + +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 +} diff --git a/src/modules/logview/LogFile.h b/src/modules/logview/LogFile.h new file mode 100644 index 000000000..6705ace26 --- /dev/null +++ b/src/modules/logview/LogFile.h @@ -0,0 +1,134 @@ +#ifndef _LOGFILE_H_ +#define _LOGFILE_H_ +//============================================================================= +// +// File : LogFile.h +// Creation date : Thu Apr 14 2011 19:16:59 by Elvio Basello +// +// This file is part of the KVIrc irc client distribution +// 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 +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// 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, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +/** +* \file LogFile.h +* \author Elvio Basello +* \brief +* +* This file was originally part of LogViewWindow.h +*/ + +#include <QDate> + +class QString; + +/** +* \class LogFile +* \brief The LogFile class which handle any log file +* +* 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 +*/ +class LogFile +{ +public: + /** + * \enum Type + * \brief Holds the type of the log file + */ + enum Type { + Channel = 0, /**< the log file of a channel */ + Console = 1, /**< the log file of a console */ + Query = 2, /**< the log file of a query */ + DccChat = 3, /**< the log file of a dcc chat */ + Other = 4, /**< any other log file */ + }; + + /** + * \enum ExportType + * \brief Holds the type of the exported log file + */ + enum ExportType { + PlainText, /**< export log in plain text file */ + HTML, /**< export log in a HTML archive */ + //XML, /**< export log in a XML file */ + //DB /**< export log in a database file */ + }; + + /** + * \brief Constructs the log file object + * \param szName The name of the log + * \return LogFile + */ + LogFile(const QString & szName); +private: + Type m_eType; + QString m_szType; + 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_eType; }; + + /** + * \brief Returns the type of the log + * \return const QString & + */ + const QString & typeString() const { return m_szType; }; + + /** + * \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; }; + + /** + * \brief Returns the date of the log + * \return const QDate & + */ + const QDate & date() const { return 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); +}; + +#endif // _LOGFILE_H_ diff --git a/src/modules/logview/LogViewWindow.cpp b/src/modules/logview/LogViewWindow.cpp index 449c78ffa..8ba981d7d 100644 --- a/src/modules/logview/LogViewWindow.cpp +++ b/src/modules/logview/LogViewWindow.cpp @@ -41,128 +41,25 @@ #include "KviControlCodes.h" #include <QList> -#include <QPixmap> -#include <QToolButton> #include <QFileInfo> #include <QDir> #include <QCursor> #include <QHeaderView> -#include <QLayout> #include <QPushButton> -#include <QDateTimeEdit> +#include <QDateEdit> #include <QLineEdit> #include <QLabel> -#include <QShortcut> #include <QMouseEvent> -#include <QByteArray> #include <QMessageBox> -#include <QSplitter> #include <QProgressBar> #include <QTextStream> - -#ifdef COMPILE_ZLIB_SUPPORT - #include <zlib.h> -#endif +#include <QTabWidget> +#include <QCheckBox> #include <limits.h> //for INT_MAX extern LogViewWindow * g_pLogViewWindow; -LogFile::LogFile(const QString & szName) -{ - 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") || KviQString::equalCI(szTypeToken,"deadchannel")) - { - m_szType = "channel"; - m_eType = Channel; - } else if(KviQString::equalCI(szTypeToken,"console")) - { - m_szType = "console"; - m_eType = Console; - } else if(KviQString::equalCI(szTypeToken,"query")) - { - m_szType = "query"; - m_eType = Query; - } else if(KviQString::equalCI(szTypeToken,"dccchat")) - { - m_szType = "dccchat"; - m_eType = DccChat; - } else { - m_szType = ""; - m_eType = 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_eType,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 -} - - LogViewListView::LogViewListView(QWidget * pParent) : QTreeWidget(pParent) { diff --git a/src/modules/logview/LogViewWindow.h b/src/modules/logview/LogViewWindow.h index 0e65ad18a..c0b06027a 100644 --- a/src/modules/logview/LogViewWindow.h +++ b/src/modules/logview/LogViewWindow.h @@ -26,6 +26,8 @@ // //============================================================================= +#include "LogFile.h" + #include "kvi_settings.h" #include "KviWindow.h" #include "KviModuleExtension.h" @@ -33,9 +35,6 @@ #include "KviPointerList.h" #include <QTreeWidget> -#include <QTabWidget> -#include <QDateTime> -#include <QCheckBox> class KviLogViewWidget; class LogListViewItem; @@ -44,101 +43,8 @@ class QProgressBar; class QStringList; class QLineEdit; class QDateEdit; - -/** -* \class LogFile -* \brief The LogFile class which handle any log file -* -* 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 -*/ -class LogFile -{ -public: - /** - * \enum Type - * \brief Holds the type of the log file - */ - enum Type { - Channel = 0, /**< the log file of a channel */ - Console = 1, /**< the log file of a console */ - Query = 2, /**< the log file of a query */ - DccChat = 3, /**< the log file of a dcc chat */ - Other = 4, /**< any other log file */ - }; - - /** - * \enum ExportType - * \brief Holds the type of the exported log file - */ - enum ExportType { - PlainText, /**< export log in plain text file */ - HTML, /**< export log in a HTML archive */ - //XML, /**< export log in a XML file */ - //DB /**< export log in a database file */ - }; - - /** - * \brief Constructs the log file object - * \param szName The name of the log - * \return LogFile - */ - LogFile(const QString & szName); -private: - Type m_eType; - QString m_szType; - 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_eType; }; - - /** - * \brief Returns the type of the log - * \return const QString & - */ - const QString & typeString() const { return m_szType; }; - - /** - * \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; }; - - /** - * \brief Returns the date of the log - * \return const QDate & - */ - const QDate & date() const { return 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 QTabWidget; +class QCheckBox; class LogViewListView : public QTreeWidget { diff --git a/src/modules/logview/libkvilogview.cpp b/src/modules/logview/libkvilogview.cpp index 5bce7a4ff..abae5ea5b 100644 --- a/src/modules/logview/libkvilogview.cpp +++ b/src/modules/logview/libkvilogview.cpp @@ -1,7 +1,7 @@ //============================================================================= // // File : libkvilogview.cpp -// Creation date : Sun Feb 10 2000 23:25:10 CEST by Juanjo �varez +// Creation date : Sun Feb 10 2000 23:25:10 CEST by Juanjo Alvarez // // This file is part of the KVIrc irc client distribution // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) @@ -95,7 +95,8 @@ static KviModuleExtension * logview_extension_alloc(KviModuleExtensionAllocStruc g_pLogViewWindow = new LogViewWindow(s->pDescriptor,g_pMainWindow); g_pMainWindow->addWindow(g_pLogViewWindow,!bCreateMinimized); - if(bCreateMinimized)g_pLogViewWindow->minimize(); + if(bCreateMinimized) + g_pLogViewWindow->minimize(); return g_pLogViewWindow; } @@ -146,14 +147,32 @@ static bool logview_module_can_unload(KviModule *) return (!g_pLogViewWindow); } +static bool logview_module_ctrl(KviModule *, const char * pcOperation, void * pParam) +{ + if(!kvi_strEqualCI("logview::export",pcOperation)) + return false; + + /* + if(!g_pLogViewWindow) + g_pLogViewWindow = new LogViewWindow(); + */ + KviLogFileData * pLog = (KviLogFileData *)pParam; + if(!pLog) + return false; + + qDebug("name: %s - type: %s",pLog->szName.toUtf8().data(),pLog->szType.toUtf8().data()); + return true; +} + KVIRC_MODULE( "KVIrc Log Viewer Widget", "4.0.0", - "Juanjo Alvarez <juanjux@yahoo.es>", + "Copyright (C) 2000 Juanjo Alvarez <juanjux@yahoo.es>\n" \ + " 2011 Elvio Basello (hellvis69 at gmail dot com)", "A structured log file viewer", logview_module_init, logview_module_can_unload, - 0, + logview_module_ctrl, logview_module_cleanup, "logview" ) |
