1 /***************************************************************************
2 * KSystemLog, a system log viewer tool *
3 * Copyright (C) 2007 by Nicolas Ternisien *
4 * nicolas.ternisien@gmail.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
22 #include "generalConfigurationWidget.h"
26 #include <QPushButton>
27 #include <QButtonGroup>
30 #include <kiconloader.h>
31 #include <kstandarddirs.h>
36 #include "ksystemlogConfig.h"
38 class GeneralConfigurationWidgetPrivate
{
40 QButtonGroup
* dateFormatGroup
;
43 GeneralConfigurationWidget::GeneralConfigurationWidget() :
45 d(new GeneralConfigurationWidgetPrivate())
50 startupLogMode
->addItem(KIcon(NO_MODE_ICON
), i18n("No Log Mode"), QVariant(""));
51 foreach(LogMode
* logMode
, Globals::instance()->logModes()) {
52 //Ignore this special case
53 if (logMode
->id() == "openLogMode")
56 startupLogMode
->addItem(KIcon(logMode
->icon()), logMode
->name(), QVariant(logMode
->id()));
59 connect(startupLogMode
, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configurationChanged()));
61 connect(maxLines
, SIGNAL(valueChanged(int)), this, SIGNAL(configurationChanged()));
63 connect(deleteDuplicatedLines
, SIGNAL(clicked()), this, SIGNAL(configurationChanged()));
65 connect(deleteProcessId
, SIGNAL(clicked()), this, SIGNAL(configurationChanged()));
67 connect(colorizeLogLines
, SIGNAL(clicked()), this, SIGNAL(configurationChanged()));
69 d
->dateFormatGroup
= new QButtonGroup(this);
70 d
->dateFormatGroup
->addButton(formatShortDate
, KLocale::ShortDate
);
71 d
->dateFormatGroup
->addButton(formatLongDate
, KLocale::LongDate
);
72 d
->dateFormatGroup
->addButton(formatFancyShortDate
, KLocale::FancyShortDate
);
73 d
->dateFormatGroup
->addButton(formatFancyLongDate
, KLocale::FancyLongDate
);
75 connect(d
->dateFormatGroup
, SIGNAL(buttonClicked(int)), this, SIGNAL(configurationChanged()));
77 addDateFormatExample();
81 GeneralConfigurationWidget::~GeneralConfigurationWidget() {
82 //dateFormatGroup is automatically deleted by Qt
87 void GeneralConfigurationWidget::addDateFormatExample() {
88 foreach(QAbstractButton
* button
, d
->dateFormatGroup
->buttons()) {
89 QDateTime
currentDateTime(QDateTime::currentDateTime());
91 KLocale::DateFormat currentButtonFormat
= (KLocale::DateFormat
) d
->dateFormatGroup
->id(button
);
93 QString formattedDate
= KGlobal::locale()->formatDateTime(currentDateTime
, currentButtonFormat
, true);
95 button
->setText( i18nc("Date format Option (Date example)", "%1 (%2)", button
->text(), formattedDate
) );
99 void GeneralConfigurationWidget::readConfig() {
100 for (int i
=0; i
<startupLogMode
->count(); ++i
) {
101 if (KSystemLogConfig::startupLogMode() == startupLogMode
->itemData(i
)) {
102 startupLogMode
->setCurrentIndex(i
);
107 maxLines
->setValue(KSystemLogConfig::maxLines());
109 deleteDuplicatedLines
->setChecked(KSystemLogConfig::deleteDuplicatedLines());
111 deleteProcessId
->setChecked(KSystemLogConfig::deleteProcessIdentifier());
113 colorizeLogLines
->setChecked(KSystemLogConfig::colorizeLogLines());
115 KLocale::DateFormat dateFormat
= (KLocale::DateFormat
) KSystemLogConfig::dateFormat();
116 QAbstractButton
* selectedButton
= d
->dateFormatGroup
->button(dateFormat
);
117 selectedButton
->setChecked(true);
120 void GeneralConfigurationWidget::saveConfig() const {
121 logDebug() << "Save config from General preferences" << endl
;
123 KSystemLogConfig::setStartupLogMode(startupLogMode
->itemData(startupLogMode
->currentIndex()).toString());
125 KSystemLogConfig::setMaxLines(maxLines
->value());
126 KSystemLogConfig::setDeleteDuplicatedLines(deleteDuplicatedLines
->isChecked());
127 KSystemLogConfig::setDeleteProcessIdentifier(deleteProcessId
->isChecked());
128 KSystemLogConfig::setColorizeLogLines(colorizeLogLines
->isChecked());
130 KSystemLogConfig::setDateFormat(d
->dateFormatGroup
->checkedId());
134 void GeneralConfigurationWidget::defaultConfig() {
135 //TODO Find a way to read the configuration per default
139 bool GeneralConfigurationWidget::isValid() const {
140 if (maxLines
->value()>0) {
141 logDebug() << "General configuration valid" << endl
;
145 logDebug() << "General configuration not valid" << endl
;
149 #include "generalConfigurationWidget.moc"