Commit c69dd2af authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move more code to cpp files

parent c56af904
......@@ -43,10 +43,10 @@ public:
bool isValid(QString &msg);
private:
QButtonGroup *m_btnGroup;
QGridLayout *m_btnGroupLayout;
QVBoxLayout *m_pageLayout;
QLabel *m_lblChoose;
QButtonGroup *m_btnGroup = nullptr;
QGridLayout *m_btnGroupLayout = nullptr;
QVBoxLayout *m_pageLayout = nullptr;
QLabel *m_lblChoose = nullptr;
QList<QCheckBox *> levelCheckBoxes;
};
......
......@@ -20,3 +20,23 @@
***************************************************************************/
#include "cronItemBuilder.h"
QString CronItemBuilder::createFormattedText(LogLine *line) const
{
QString result;
result.append(QLatin1String("<table>"));
QListIterator<QString> it(line->logItems());
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Hostname:"), it.next()));
result.append(labelMessageFormat(i18n("Process:"), it.next()));
result.append(labelMessageFormat(i18n("User:"), it.next()));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(labelMessageFormat(i18n("Original file:"), line->sourceFileName()));
result.append(QLatin1String("</table>"));
return result;
}
......@@ -41,25 +41,7 @@ public:
~CronItemBuilder() override {}
QString createFormattedText(LogLine *line) const override
{
QString result;
result.append(QLatin1String("<table>"));
QListIterator<QString> it(line->logItems());
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Hostname:"), it.next()));
result.append(labelMessageFormat(i18n("Process:"), it.next()));
result.append(labelMessageFormat(i18n("User:"), it.next()));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(labelMessageFormat(i18n("Original file:"), line->sourceFileName()));
result.append(QLatin1String("</table>"));
return result;
}
QString createFormattedText(LogLine *line) const override;
};
#endif // _CRON_ITEM_BUILDER_H
......@@ -20,3 +20,55 @@
***************************************************************************/
#include "cupsAccessAnalyzer.h"
CupsAccessAnalyzer::CupsAccessAnalyzer(LogMode *logMode)
: FileAnalyzer(logMode)
, cupsAccessRegex(
QStringLiteral("(\\S*) (\\S*) (\\S*) \\[(.*)\\] \"(.*)\" (\\S*) (\\S*) (\\S*) (\\S*)"))
{
}
LogViewColumns CupsAccessAnalyzer::initColumns()
{
LogViewColumns columns;
columns.addColumn(LogViewColumn(i18n("Date"), true, false));
columns.addColumn(LogViewColumn(i18n("Host"), true, true));
columns.addColumn(LogViewColumn(i18n("Group"), true, true));
columns.addColumn(LogViewColumn(i18n("User"), true, true));
columns.addColumn(LogViewColumn(i18n("HTTP Request"), true, false));
columns.addColumn(LogViewColumn(i18n("Status"), true, true));
columns.addColumn(LogViewColumn(i18n("Bytes"), true, false));
columns.addColumn(LogViewColumn(i18n("IPP Operation"), true, false));
columns.addColumn(LogViewColumn(i18n("IPP Status"), true, false));
return columns;
}
LogFileReader *CupsAccessAnalyzer::createLogFileReader(const LogFile &logFile) { return new LocalLogFileReader(logFile); }
Analyzer::LogFileSortMode CupsAccessAnalyzer::logFileSortMode() { return Analyzer::AscendingSortedLogFile; }
LogLine *CupsAccessAnalyzer::parseMessage(const QString &logLine, const LogFile &originalLogFile)
{
int firstPosition = cupsAccessRegex.indexIn(logLine);
if (firstPosition == -1) {
logDebug() << "Unable to parse line " << logLine;
return nullptr;
}
QStringList capturedTexts = cupsAccessRegex.capturedTexts();
// Remove full line
capturedTexts.removeAt(0);
capturedTexts.replace(5, ParsingHelper::instance()->parseHttpResponse(capturedTexts.at(5)));
capturedTexts.replace(6, ParsingHelper::instance()->parseSize(capturedTexts.at(6)));
QDateTime dateTime = ParsingHelper::instance()->parseHttpDateTime(capturedTexts.takeAt(3));
LogLevel *logLevel = findLevel(capturedTexts.at(capturedTexts.count() - 1));
return new LogLine(logLineInternalIdGenerator++, dateTime, capturedTexts,
originalLogFile.url().toLocalFile(), logLevel, logMode);
}
......@@ -37,38 +37,18 @@ class CupsAccessAnalyzer : public FileAnalyzer
Q_OBJECT
public:
explicit CupsAccessAnalyzer(LogMode *logMode)
: FileAnalyzer(logMode)
, cupsAccessRegex(
QStringLiteral("(\\S*) (\\S*) (\\S*) \\[(.*)\\] \"(.*)\" (\\S*) (\\S*) (\\S*) (\\S*)"))
{
}
explicit CupsAccessAnalyzer(LogMode *logMode);
virtual ~CupsAccessAnalyzer() {}
LogViewColumns initColumns() override
{
LogViewColumns columns;
columns.addColumn(LogViewColumn(i18n("Date"), true, false));
columns.addColumn(LogViewColumn(i18n("Host"), true, true));
columns.addColumn(LogViewColumn(i18n("Group"), true, true));
columns.addColumn(LogViewColumn(i18n("User"), true, true));
columns.addColumn(LogViewColumn(i18n("HTTP Request"), true, false));
columns.addColumn(LogViewColumn(i18n("Status"), true, true));
columns.addColumn(LogViewColumn(i18n("Bytes"), true, false));
columns.addColumn(LogViewColumn(i18n("IPP Operation"), true, false));
columns.addColumn(LogViewColumn(i18n("IPP Status"), true, false));
return columns;
}
LogViewColumns initColumns() override;
protected:
QRegExp cupsAccessRegex;
LogFileReader *createLogFileReader(const LogFile &logFile) override { return new LocalLogFileReader(logFile); }
LogFileReader *createLogFileReader(const LogFile &logFile) override;
Analyzer::LogFileSortMode logFileSortMode() override { return Analyzer::AscendingSortedLogFile; }
Analyzer::LogFileSortMode logFileSortMode() override;
/*
* https://www.cups.org/doc/man-cupsd-logs.html
......@@ -83,29 +63,7 @@ protected:
* localhost - - [01/Dec/2005:21:50:32 +0000] "GET /admin HTTP/1.1" 200 6667 - -
*
*/
LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile) override
{
int firstPosition = cupsAccessRegex.indexIn(logLine);
if (firstPosition == -1) {
logDebug() << "Unable to parse line " << logLine;
return nullptr;
}
QStringList capturedTexts = cupsAccessRegex.capturedTexts();
// Remove full line
capturedTexts.removeAt(0);
capturedTexts.replace(5, ParsingHelper::instance()->parseHttpResponse(capturedTexts.at(5)));
capturedTexts.replace(6, ParsingHelper::instance()->parseSize(capturedTexts.at(6)));
QDateTime dateTime = ParsingHelper::instance()->parseHttpDateTime(capturedTexts.takeAt(3));
LogLevel *logLevel = findLevel(capturedTexts.at(capturedTexts.count() - 1));
return new LogLine(logLineInternalIdGenerator++, dateTime, capturedTexts,
originalLogFile.url().toLocalFile(), logLevel, logMode);
}
LogLine *parseMessage(const QString &logLine, const LogFile &originalLogFile) override;
inline LogLevel *findLevel(const QString &status) const
{
......
......@@ -20,3 +20,24 @@
***************************************************************************/
#include "cupsAccessItemBuilder.h"
QString CupsAccessItemBuilder::createFormattedText(LogLine *line) const
{
QString result;
QListIterator<QString> it(line->logItems());
result.append(QLatin1String("<table>"));
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(labelMessageFormat(i18n("Hostname:"), it.next()));
result.append(labelMessageFormat(i18n("Identification:"), it.next()));
result.append(labelMessageFormat(i18n("Username:"), it.next()));
result.append(labelMessageFormat(i18n("HTTP Response:"), it.next()));
result.append(labelMessageFormat(i18n("Bytes Sent:"), it.next()));
result.append(QLatin1String("</table>"));
return result;
}
......@@ -41,26 +41,7 @@ public:
~CupsAccessItemBuilder() override {}
QString createFormattedText(LogLine *line) const override
{
QString result;
QListIterator<QString> it(line->logItems());
result.append(QLatin1String("<table>"));
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(labelMessageFormat(i18n("Hostname:"), it.next()));
result.append(labelMessageFormat(i18n("Identification:"), it.next()));
result.append(labelMessageFormat(i18n("Username:"), it.next()));
result.append(labelMessageFormat(i18n("HTTP Response:"), it.next()));
result.append(labelMessageFormat(i18n("Bytes Sent:"), it.next()));
result.append(QLatin1String("</table>"));
return result;
}
QString createFormattedText(LogLine *line) const override;
};
#endif // _CUPS_ACCESS_ITEM_BUILDER_H
......@@ -20,3 +20,47 @@
***************************************************************************/
#include "cupsConfiguration.h"
CupsConfiguration::CupsConfiguration()
: d(new CupsConfigurationPrivate())
{
configuration->setCurrentGroup(QStringLiteral("CupsLogMode"));
QStringList defaultCupsPaths;
defaultCupsPaths << QStringLiteral("/var/log/cups/error_log");
configuration->addItemStringList(QStringLiteral("CupsLogFilesPaths"), d->cupsPaths, defaultCupsPaths,
QStringLiteral("CupsLogFilesPaths"));
QStringList defaultCupsAccessPaths;
defaultCupsAccessPaths << QStringLiteral("/var/log/cups/access_log");
configuration->addItemStringList(QStringLiteral("CupsAccessLogFilesPaths"), d->cupsAccessPaths,
defaultCupsAccessPaths, QStringLiteral("CupsAccessLogFilesPaths"));
QStringList defaultCupsPagePaths;
defaultCupsPagePaths << QStringLiteral("/var/log/cups/page_log");
configuration->addItemStringList(QStringLiteral("CupsPageLogFilesPaths"), d->cupsPagePaths,
defaultCupsPagePaths, QStringLiteral("CupsPageLogFilesPaths"));
QStringList defaultCupsPdfPaths;
defaultCupsPdfPaths << QStringLiteral("/var/log/cups/cups-pdf_log");
configuration->addItemStringList(QStringLiteral("CupsPdfLogFilesPaths"), d->cupsPdfPaths,
defaultCupsPdfPaths, QStringLiteral("CupsPdfLogFilesPaths"));
}
CupsConfiguration::~CupsConfiguration() { delete d; }
QStringList CupsConfiguration::cupsPaths() const { return d->cupsPaths; }
QStringList CupsConfiguration::cupsAccessPaths() const { return d->cupsAccessPaths; }
QStringList CupsConfiguration::cupsPagePaths() const { return d->cupsPagePaths; }
QStringList CupsConfiguration::cupsPdfPaths() const { return d->cupsPdfPaths; }
void CupsConfiguration::setCupsPaths(const QStringList &cupsPaths) { d->cupsPaths = cupsPaths; }
void CupsConfiguration::setCupsAccessPaths(const QStringList &cupsAccessPaths) { d->cupsAccessPaths = cupsAccessPaths; }
void CupsConfiguration::setCupsPagePaths(const QStringList &cupsPagePaths) { d->cupsPagePaths = cupsPagePaths; }
void CupsConfiguration::setCupsPdfPaths(const QStringList &cupsPdfPaths) { d->cupsPdfPaths = cupsPdfPaths; }
......@@ -50,49 +50,25 @@ class CupsConfiguration : public LogModeConfiguration
Q_OBJECT
public:
CupsConfiguration()
: d(new CupsConfigurationPrivate())
{
configuration->setCurrentGroup(QStringLiteral("CupsLogMode"));
CupsConfiguration();
QStringList defaultCupsPaths;
defaultCupsPaths << QStringLiteral("/var/log/cups/error_log");
configuration->addItemStringList(QStringLiteral("CupsLogFilesPaths"), d->cupsPaths, defaultCupsPaths,
QStringLiteral("CupsLogFilesPaths"));
~CupsConfiguration() override;
QStringList defaultCupsAccessPaths;
defaultCupsAccessPaths << QStringLiteral("/var/log/cups/access_log");
configuration->addItemStringList(QStringLiteral("CupsAccessLogFilesPaths"), d->cupsAccessPaths,
defaultCupsAccessPaths, QStringLiteral("CupsAccessLogFilesPaths"));
QStringList cupsPaths() const;
QStringList defaultCupsPagePaths;
defaultCupsPagePaths << QStringLiteral("/var/log/cups/page_log");
configuration->addItemStringList(QStringLiteral("CupsPageLogFilesPaths"), d->cupsPagePaths,
defaultCupsPagePaths, QStringLiteral("CupsPageLogFilesPaths"));
QStringList cupsAccessPaths() const;
QStringList defaultCupsPdfPaths;
defaultCupsPdfPaths << QStringLiteral("/var/log/cups/cups-pdf_log");
configuration->addItemStringList(QStringLiteral("CupsPdfLogFilesPaths"), d->cupsPdfPaths,
defaultCupsPdfPaths, QStringLiteral("CupsPdfLogFilesPaths"));
}
QStringList cupsPagePaths() const;
~CupsConfiguration() override { delete d; }
QStringList cupsPdfPaths() const;
QStringList cupsPaths() const { return d->cupsPaths; }
void setCupsPaths(const QStringList &cupsPaths);
QStringList cupsAccessPaths() const { return d->cupsAccessPaths; }
void setCupsAccessPaths(const QStringList &cupsAccessPaths);
QStringList cupsPagePaths() const { return d->cupsPagePaths; }
void setCupsPagePaths(const QStringList &cupsPagePaths);
QStringList cupsPdfPaths() const { return d->cupsPdfPaths; }
void setCupsPaths(const QStringList &cupsPaths) { d->cupsPaths = cupsPaths; }
void setCupsAccessPaths(const QStringList &cupsAccessPaths) { d->cupsAccessPaths = cupsAccessPaths; }
void setCupsPagePaths(const QStringList &cupsPagePaths) { d->cupsPagePaths = cupsPagePaths; }
void setCupsPdfPaths(const QStringList &cupsPdfPaths) { d->cupsPdfPaths = cupsPdfPaths; }
void setCupsPdfPaths(const QStringList &cupsPdfPaths);
private:
CupsConfigurationPrivate *const d;
......
......@@ -20,3 +20,69 @@
***************************************************************************/
#include "cupsConfigurationWidget.h"
CupsConfigurationWidget::CupsConfigurationWidget()
: LogModeConfigurationWidget(i18n("Cups Log"), QStringLiteral(CUPS_MODE_ICON),
i18n("Cups &amp; Cups Web Server Log"))
{
QHBoxLayout *layout = new QHBoxLayout(this);
cupsFileList = new MultipleFileList(this, i18n(
"<p>These files will be analyzed to show the <b>Cups "
"log</b> and the <b>Cups Web Access log</b>.</p>"));
cupsPathsId = cupsFileList->addCategory(i18n("Cups Log Files"), i18n("Add Cups File..."));
cupsAccessPathsId
= cupsFileList->addCategory(i18n("Cups Access Log Files"), i18n("Add Cups Access File..."));
cupsPagePathsId
= cupsFileList->addCategory(i18n("Cups Page Log Files"), i18n("Add Cups Page File..."));
cupsPdfPathsId = cupsFileList->addCategory(i18n("Cups PDF Log Files"), i18n("Add Cups PDF File..."));
connect(cupsFileList, &MultipleFileList::fileListChanged, this, &LogModeConfigurationWidget::configurationChanged);
layout->addWidget(cupsFileList);
}
void CupsConfigurationWidget::saveConfig()
{
logDebug() << "Saving config from Cups Options...";
CupsConfiguration *cupsConfiguration = Globals::instance()
.findLogMode(QStringLiteral(CUPS_LOG_MODE_ID))
->logModeConfiguration<CupsConfiguration *>();
cupsConfiguration->setCupsPaths(cupsFileList->paths(cupsPathsId));
cupsConfiguration->setCupsAccessPaths(cupsFileList->paths(cupsAccessPathsId));
cupsConfiguration->setCupsPagePaths(cupsFileList->paths(cupsPagePathsId));
cupsConfiguration->setCupsPdfPaths(cupsFileList->paths(cupsPdfPathsId));
}
void CupsConfigurationWidget::defaultConfig()
{
// TODO Find a way to read the configuration per default
readConfig();
}
void CupsConfigurationWidget::readConfig()
{
CupsConfiguration *cupsConfiguration = Globals::instance()
.findLogMode(QStringLiteral(CUPS_LOG_MODE_ID))
->logModeConfiguration<CupsConfiguration *>();
cupsFileList->removeAllItems();
cupsFileList->addPaths(cupsPathsId, cupsConfiguration->cupsPaths());
cupsFileList->addPaths(cupsAccessPathsId, cupsConfiguration->cupsAccessPaths());
cupsFileList->addPaths(cupsPagePathsId, cupsConfiguration->cupsPagePaths());
cupsFileList->addPaths(cupsPdfPathsId, cupsConfiguration->cupsPdfPaths());
}
bool CupsConfigurationWidget::isValid() const
{
if (cupsFileList->isOneOfCategoryEmpty() == true) {
logDebug() << "Cups configuration not valid";
return false;
}
logDebug() << "Cups configuration valid";
return true;
}
......@@ -40,79 +40,23 @@ class CupsConfigurationWidget : public LogModeConfigurationWidget
Q_OBJECT
public:
CupsConfigurationWidget()
: LogModeConfigurationWidget(i18n("Cups Log"), QStringLiteral(CUPS_MODE_ICON),
i18n("Cups &amp; Cups Web Server Log"))
{
QHBoxLayout *layout = new QHBoxLayout(this);
cupsFileList = new MultipleFileList(this, i18n(
"<p>These files will be analyzed to show the <b>Cups "
"log</b> and the <b>Cups Web Access log</b>.</p>"));
cupsPathsId = cupsFileList->addCategory(i18n("Cups Log Files"), i18n("Add Cups File..."));
cupsAccessPathsId
= cupsFileList->addCategory(i18n("Cups Access Log Files"), i18n("Add Cups Access File..."));
cupsPagePathsId
= cupsFileList->addCategory(i18n("Cups Page Log Files"), i18n("Add Cups Page File..."));
cupsPdfPathsId = cupsFileList->addCategory(i18n("Cups PDF Log Files"), i18n("Add Cups PDF File..."));
connect(cupsFileList, &MultipleFileList::fileListChanged, this, &LogModeConfigurationWidget::configurationChanged);
layout->addWidget(cupsFileList);
}
CupsConfigurationWidget();
~CupsConfigurationWidget() override {}
public Q_SLOTS:
void saveConfig() override
{
logDebug() << "Saving config from Cups Options...";
CupsConfiguration *cupsConfiguration = Globals::instance()
.findLogMode(QStringLiteral(CUPS_LOG_MODE_ID))
->logModeConfiguration<CupsConfiguration *>();
cupsConfiguration->setCupsPaths(cupsFileList->paths(cupsPathsId));
cupsConfiguration->setCupsAccessPaths(cupsFileList->paths(cupsAccessPathsId));
cupsConfiguration->setCupsPagePaths(cupsFileList->paths(cupsPagePathsId));
cupsConfiguration->setCupsPdfPaths(cupsFileList->paths(cupsPdfPathsId));
}
void defaultConfig() override
{
// TODO Find a way to read the configuration per default
readConfig();
}
void readConfig() override
{
CupsConfiguration *cupsConfiguration = Globals::instance()
.findLogMode(QStringLiteral(CUPS_LOG_MODE_ID))
->logModeConfiguration<CupsConfiguration *>();
cupsFileList->removeAllItems();
cupsFileList->addPaths(cupsPathsId, cupsConfiguration->cupsPaths());
cupsFileList->addPaths(cupsAccessPathsId, cupsConfiguration->cupsAccessPaths());
cupsFileList->addPaths(cupsPagePathsId, cupsConfiguration->cupsPagePaths());
cupsFileList->addPaths(cupsPdfPathsId, cupsConfiguration->cupsPdfPaths());
}
void saveConfig() override;
protected:
bool isValid() const override
{
if (cupsFileList->isOneOfCategoryEmpty() == true) {
logDebug() << "Cups configuration not valid";
return false;
}
void defaultConfig() override;
void readConfig() override;
logDebug() << "Cups configuration valid";
return true;
}
protected:
bool isValid() const override;
private:
MultipleFileList *cupsFileList;
MultipleFileList *cupsFileList = nullptr;
int cupsPathsId;
int cupsAccessPathsId;
......
......@@ -20,3 +20,17 @@
***************************************************************************/
#include "cupsItemBuilder.h"
QString CupsItemBuilder::createFormattedText(LogLine *line) const
{
QString result;
result.append(QLatin1String("<table>"));
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(QLatin1String("</table>"));
return result;
}
......@@ -41,19 +41,7 @@ public:
~CupsItemBuilder() override {}
QString createFormattedText(LogLine *line) const override
{
QString result;
result.append(QLatin1String("<table>"));
result.append(labelMessageFormat(i18n("Date:"), formatDate(line->time())));
result.append(labelMessageFormat(i18n("Level:"), line->logLevel()->name()));
result.append(QLatin1String("</table>"));
return result;
}
QString createFormattedText(LogLine *line) const override;
};
#endif // _CUPS_ITEM_BUILDER_H
......@@ -20,3 +20,47 @@
***************************************************************************/
#include "cupsPageAnalyzer.h"
CupsPageAnalyzer::CupsPageAnalyzer(LogMode *logMode)
: FileAnalyzer(logMode)
, cupsPageRegex(QStringLiteral("(\\S*) (\\S*) (\\S*) \\[(.*)\\] (\\S*) (\\S*) (\\S*)"))
{
}
LogViewColumns CupsPageAnalyzer::initColumns()
{
LogViewColumns columns;
columns.addColumn(LogViewColumn(i18n("Date"), true, false));
columns.addColumn(LogViewColumn(i18n("Printer"), true, true));
columns.addColumn(LogViewColumn(i18n("User"), true, true));
columns.addColumn(LogViewColumn(i18n("Job Id"), true, true));
columns.addColumn(LogViewColumn(i18n("Page Number"), true, false));
columns.addColumn(LogViewColumn(i18n("Num Copies"), true, true));
columns.addColumn(LogViewColumn(i18n("Job Billing"), true, false));
return columns;
}