diff --git a/src/generalConfigurationWidget.cpp b/src/generalConfigurationWidget.cpp index f00a676..80a0571 100644 --- a/src/generalConfigurationWidget.cpp +++ b/src/generalConfigurationWidget.cpp @@ -1,174 +1,174 @@ /*************************************************************************** * KSystemLog, a system log viewer tool * * Copyright (C) 2007 by Nicolas Ternisien * * nicolas.ternisien@gmail.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 option) 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 "generalConfigurationWidget.h" #include #include #include #include #include #include #include "logging.h" #include "defaults.h" #include "globals.h" #include "ksystemlogConfig.h" class GeneralConfigurationWidgetPrivate { public: QButtonGroup *dateFormatGroup; KMessageWidget *warningBox; }; GeneralConfigurationWidget::GeneralConfigurationWidget() : QWidget() , d(new GeneralConfigurationWidgetPrivate()) { setupUi(this); d->warningBox = new KMessageWidget(this); d->warningBox->setVisible(false); d->warningBox->setMessageType(KMessageWidget::Warning); d->warningBox->setText(i18n("This mode is unavailable because its log files do not exist.")); d->warningBox->setCloseButtonVisible(false); d->warningBox->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); startupModeVerticalLayout->addWidget(d->warningBox); startupLogMode->addItem(QIcon::fromTheme(QStringLiteral(NO_MODE_ICON)), i18n("No Log Mode"), QVariant(QLatin1String(""))); foreach (LogMode *logMode, Globals::instance().logModes()) { // Ignore this special case if (logMode->id() == QLatin1String("openLogMode")) continue; - startupLogMode->addItem(QIcon(logMode->icon()), logMode->name(), QVariant(logMode->id())); + startupLogMode->addItem(logMode->icon(), logMode->name(), QVariant(logMode->id())); } connect(startupLogMode, QOverload::of(&QComboBox::currentIndexChanged), this, &GeneralConfigurationWidget::configurationChanged); connect(maxLines, QOverload::of(&QSpinBox::valueChanged), this, &GeneralConfigurationWidget::configurationChanged); connect(deleteDuplicatedLines, &QAbstractButton::clicked, this, &GeneralConfigurationWidget::configurationChanged); connect(deleteProcessId, &QAbstractButton::clicked, this, &GeneralConfigurationWidget::configurationChanged); connect(colorizeLogLines, &QAbstractButton::clicked, this, &GeneralConfigurationWidget::configurationChanged); d->dateFormatGroup = new QButtonGroup(this); d->dateFormatGroup->addButton(formatLongDate, Globals::LongFormat); d->dateFormatGroup->addButton(formatShortDate, Globals::ShortFormat); d->dateFormatGroup->addButton(formatPreciseDate, Globals::PreciseFormat); connect(d->dateFormatGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &GeneralConfigurationWidget::configurationChanged); addDateFormatExample(); } GeneralConfigurationWidget::~GeneralConfigurationWidget() { // dateFormatGroup is automatically deleted by Qt delete d; } void GeneralConfigurationWidget::addDateFormatExample() { foreach (QAbstractButton *button, d->dateFormatGroup->buttons()) { Globals::DateFormat currentButtonFormat = (Globals::DateFormat)d->dateFormatGroup->id(button); QString formattedDate = Globals::instance().formatDate(currentButtonFormat, QDateTime().currentDateTime()); button->setText(i18nc("Date format option (date example)", "%1 (%2)", button->text(), formattedDate)); } } void GeneralConfigurationWidget::readConfig() { for (int i = 0; i < startupLogMode->count(); ++i) { if (KSystemLogConfig::startupLogMode() == startupLogMode->itemData(i)) { startupLogMode->setCurrentIndex(i); break; } } maxLines->setValue(KSystemLogConfig::maxLines()); deleteDuplicatedLines->setChecked(KSystemLogConfig::deleteDuplicatedLines()); deleteProcessId->setChecked(KSystemLogConfig::deleteProcessIdentifier()); colorizeLogLines->setChecked(KSystemLogConfig::colorizeLogLines()); // KLocale::DateFormat dateFormat = (KLocale::DateFormat) KSystemLogConfig::dateFormat(); QLocale::FormatType dateFormat = (QLocale::FormatType)KSystemLogConfig::dateFormat(); QAbstractButton *selectedButton = d->dateFormatGroup->button(dateFormat); selectedButton->setChecked(true); } void GeneralConfigurationWidget::saveConfig() const { logDebug() << "Save config from General preferences"; KSystemLogConfig::setStartupLogMode(startupLogMode->itemData(startupLogMode->currentIndex()).toString()); KSystemLogConfig::setMaxLines(maxLines->value()); KSystemLogConfig::setDeleteDuplicatedLines(deleteDuplicatedLines->isChecked()); KSystemLogConfig::setDeleteProcessIdentifier(deleteProcessId->isChecked()); KSystemLogConfig::setColorizeLogLines(colorizeLogLines->isChecked()); KSystemLogConfig::setDateFormat(d->dateFormatGroup->checkedId()); } void GeneralConfigurationWidget::defaultConfig() { // TODO Find a way to read the configuration per default readConfig(); } bool GeneralConfigurationWidget::isValid() const { if (maxLines->value() > 0) { // Check if log files exist for selected mode. QVariant modeID = startupLogMode->currentData(); if (!modeID.isNull()) { QString modeString = modeID.toString(); LogMode *mode = Globals::instance().findLogMode(modeString); if (mode) { if (!mode->filesExist()) { logDebug() << "Log files are missing for mode" << mode->name(); d->warningBox->setVisible(true); } else { logDebug() << "General configuration is valid"; d->warningBox->setVisible(false); return true; } } else { // Empty log mode is selected. d->warningBox->setVisible(false); return true; } } } logDebug() << "General configuration is not valid"; return false; } diff --git a/src/lib/logMode.cpp b/src/lib/logMode.cpp index 4a25c2a..1095f17 100644 --- a/src/lib/logMode.cpp +++ b/src/lib/logMode.cpp @@ -1,108 +1,108 @@ /*************************************************************************** * KSystemLog, a system log viewer tool * * Copyright (C) 2007 by Nicolas Ternisien * * nicolas.ternisien@gmail.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 option) 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 "logMode.h" #include #include #include #include "multipleActions.h" #include "logModeItemBuilder.h" LogMode::LogMode(const QString &id, const QString &name, const QString &iconName) : d(new LogModePrivate()) { d->id = id; d->name = name; - d->icon = QIcon::fromTheme(iconName).pixmap(KIconLoader::SizeSmall);; + d->icon = QIcon::fromTheme(iconName); d->logFilesExist = true; } LogMode::~LogMode() { delete d->action; delete d->itemBuilder; delete d; } QString LogMode::id() const { return d->id; } QString LogMode::name() const { return d->name; } -QPixmap LogMode::icon() const +QIcon LogMode::icon() const { return d->icon; } QAction *LogMode::action() const { return d->action; } LogModeItemBuilder *LogMode::itemBuilder() const { return d->itemBuilder; } bool LogMode::filesExist() const { return d->logFilesExist; } LogModeConfigurationWidget *LogMode::logModeConfigurationWidget() const { return d->logModeConfigurationWidget; } LogModeConfiguration *LogMode::innerConfiguration() const { return d->logModeConfiguration.data(); } QAction *LogMode::createDefaultAction() { QAction *action = new QAction(d->icon, d->name, this); ActionData data; data.id = d->id; action->setData(QVariant::fromValue(data)); return action; } void LogMode::checkLogFilesPresence(const QStringList &paths) { d->logFilesExist = false; for (const QString &path : paths) { QFileInfo fileInfo(path); if (fileInfo.exists()) d->logFilesExist = true; } } diff --git a/src/lib/logMode.h b/src/lib/logMode.h index 82617f1..f970d02 100644 --- a/src/lib/logMode.h +++ b/src/lib/logMode.h @@ -1,129 +1,129 @@ /*************************************************************************** * KSystemLog, a system log viewer tool * * Copyright (C) 2007 by Nicolas Ternisien * * nicolas.ternisien@gmail.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 option) 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. * ***************************************************************************/ #ifndef LOG_MODE_H #define LOG_MODE_H #include -#include +#include #include #include #include "logFile.h" class Analyzer; class LogModeItemBuilder; class LogModeConfiguration; class LogModeConfigurationWidget; class QAction; struct ActionData { QString id; bool addToActionCollection = true; QVariant analyzerOptions; }; Q_DECLARE_METATYPE(ActionData) // TODO Do not let this class visible to other classes (except sub-classes) class LogModePrivate { public: QString id; QString name; QString iconName; - QPixmap icon; + QIcon icon; QAction *action; LogModeItemBuilder *itemBuilder; LogModeConfigurationWidget *logModeConfigurationWidget; QSharedPointer logModeConfiguration; bool logFilesExist; }; class LogMode : public QObject { Q_OBJECT public: LogMode(const QString &id, const QString &name, const QString &iconName); virtual ~LogMode(); QString id() const; QString name() const; - QPixmap icon() const; + QIcon icon() const; QAction *action() const; LogModeItemBuilder *itemBuilder() const; /** * Returns true if at least one log file exists for this mode. */ bool filesExist() const; /** * Log mode configuration widget */ LogModeConfigurationWidget *logModeConfigurationWidget() const; template T logModeConfiguration() { return static_cast(innerConfiguration()); } /** * Create the Analyzer used to parse the log file */ virtual Analyzer *createAnalyzer(const QVariant &options = QVariant()) = 0; /** * Create the log file list which will be read */ virtual QList createLogFiles() = 0; Q_SIGNALS: void menuChanged(); protected: QAction *createDefaultAction(); /** * Initializes the flag returned by filesExist(). */ void checkLogFilesPresence(const QStringList &paths); LogModePrivate *const d; private: /** * Log Mode Configuration */ LogModeConfiguration *innerConfiguration() const; }; #endif // LOG_MODE_H