From b051d48fd5eff9045d245aef9ec7b99b32fea375 Mon Sep 17 00:00:00 2001 From: Elvio Basello Date: Thu, 14 Apr 2011 21:21:43 +0000 Subject: 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 --- src/modules/logview/CMakeLists.txt | 1 + src/modules/logview/LogFile.cpp | 126 ++++++++++++++++++++++++++++++++ src/modules/logview/LogFile.h | 134 ++++++++++++++++++++++++++++++++++ src/modules/logview/LogViewWindow.cpp | 109 +-------------------------- src/modules/logview/LogViewWindow.h | 102 +------------------------- src/modules/logview/libkvilogview.cpp | 27 ++++++- 6 files changed, 291 insertions(+), 208 deletions(-) create mode 100644 src/modules/logview/LogFile.cpp create mode 100644 src/modules/logview/LogFile.h (limited to 'src/modules/logview') 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 + +#ifdef COMPILE_ZLIB_SUPPORT + #include +#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 + +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 -#include -#include #include #include #include #include -#include #include -#include +#include #include #include -#include #include -#include #include -#include #include #include - -#ifdef COMPILE_ZLIB_SUPPORT - #include -#endif +#include +#include #include //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 -#include -#include -#include 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 ", + "Copyright (C) 2000 Juanjo Alvarez \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" ) -- cgit v1.3.1-10-gc9f91