File indexing completed on 2024-05-19 05:49:17

0001 /*
0002     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "systemConfigurationWidget.h"
0008 
0009 SystemConfigurationWidget::SystemConfigurationWidget()
0010     : LogModeConfigurationWidget(i18n("System Log"), QStringLiteral(SYSTEM_MODE_ICON), i18n("System Log"))
0011 {
0012     auto layout = new QVBoxLayout(this);
0013 
0014     const QString description = i18n("<p>These files will be analyzed to show the <b>System logs</b>.</p>");
0015 
0016     mFileList = new LogLevelFileList(this, description);
0017 
0018     connect(mFileList, &FileList::fileListChanged, this, &LogModeConfigurationWidget::configurationChanged);
0019 
0020     layout->addWidget(mFileList);
0021 }
0022 
0023 bool SystemConfigurationWidget::isValid() const
0024 {
0025     if (!mFileList->isEmpty()) {
0026         qCDebug(KSYSTEMLOG) << "System configuration valid";
0027         return true;
0028     }
0029 
0030     qCDebug(KSYSTEMLOG) << "System configuration not valid";
0031     return false;
0032 }
0033 
0034 void SystemConfigurationWidget::saveConfig()
0035 {
0036     qCDebug(KSYSTEMLOG) << "Saving config from System Options...";
0037 
0038     auto *systemConfiguration = Globals::instance().findLogMode(QStringLiteral(SYSTEM_LOG_MODE_ID))->logModeConfiguration<SystemConfiguration *>();
0039     systemConfiguration->setLogFilesPaths(mFileList->paths());
0040     systemConfiguration->setLogFilesLevels(mFileList->levels());
0041 }
0042 
0043 void SystemConfigurationWidget::readConfig()
0044 {
0045     auto *systemConfiguration = Globals::instance().findLogMode(QStringLiteral(SYSTEM_LOG_MODE_ID))->logModeConfiguration<SystemConfiguration *>();
0046 
0047     mFileList->removeAllItems();
0048 
0049     mFileList->addPaths(systemConfiguration->logFilesPaths(), systemConfiguration->logFilesLevels());
0050 }
0051 
0052 void SystemConfigurationWidget::defaultConfig()
0053 {
0054     // TODO Find a way to read the configuration per default
0055     readConfig();
0056 }
0057 
0058 #include "moc_systemConfigurationWidget.cpp"