File indexing completed on 2025-01-05 04:49:34
0001 /* 0002 This file is part of KOrganizer. 0003 0004 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "configdialog.h" 0011 #include "datenums.h" 0012 0013 #include <KConfig> 0014 #include <KLocalizedString> 0015 0016 #include <KConfigGroup> 0017 #include <QButtonGroup> 0018 #include <QDialogButtonBox> 0019 #include <QGroupBox> 0020 #include <QPushButton> 0021 #include <QRadioButton> 0022 #include <QVBoxLayout> 0023 0024 ConfigDialog::ConfigDialog(QWidget *parent) 0025 : QDialog(parent) 0026 , mDayNumGroup(new QButtonGroup(this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Configure Day Numbers")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0031 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0032 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0033 connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigDialog::reject); 0034 okButton->setDefault(true); 0035 setModal(true); 0036 auto topFrame = new QFrame(this); 0037 mainLayout->addWidget(topFrame); 0038 mainLayout->addStretch(1); 0039 mainLayout->addWidget(buttonBox); 0040 auto topLayout = new QVBoxLayout(topFrame); 0041 topLayout->setContentsMargins({}); 0042 0043 auto dayNumBox = new QGroupBox(i18n("Show Date Number"), topFrame); 0044 dayNumBox->setFlat(true); 0045 topLayout->addWidget(dayNumBox); 0046 auto groupLayout = new QVBoxLayout(dayNumBox); 0047 0048 auto btn = new QRadioButton(i18n("Show day number"), dayNumBox); 0049 mDayNumGroup->addButton(btn, int(Datenums::DayOfYear)); 0050 groupLayout->addWidget(btn); 0051 btn = new QRadioButton(i18n("Show days to end of year"), dayNumBox); 0052 mDayNumGroup->addButton(btn, int(Datenums::DaysRemaining)); 0053 groupLayout->addWidget(btn); 0054 btn = new QRadioButton(i18n("Show both"), dayNumBox); 0055 mDayNumGroup->addButton(btn, int(Datenums::DayOfYear | Datenums::DaysRemaining)); 0056 groupLayout->addWidget(btn); 0057 0058 connect(okButton, &QPushButton::clicked, this, &ConfigDialog::slotOk); 0059 0060 load(); 0061 } 0062 0063 ConfigDialog::~ConfigDialog() = default; 0064 0065 void ConfigDialog::load() 0066 { 0067 KConfig _config(QStringLiteral("korganizerrc"), KConfig::NoGlobals); 0068 KConfigGroup config(&_config, QStringLiteral("Calendar/Datenums Plugin")); 0069 int datenum = config.readEntry("ShowDayNumbers", int(Datenums::DayOfYear | Datenums::DaysRemaining)); 0070 QAbstractButton *btn = mDayNumGroup->button(datenum); 0071 if (!btn) { 0072 btn = mDayNumGroup->button(int(Datenums::DayOfYear | Datenums::DaysRemaining)); 0073 } 0074 btn->setChecked(true); 0075 } 0076 0077 void ConfigDialog::save() 0078 { 0079 KConfig _config(QStringLiteral("korganizerrc"), KConfig::NoGlobals); 0080 KConfigGroup config(&_config, QStringLiteral("Calendar/Datenums Plugin")); 0081 config.writeEntry("ShowDayNumbers", mDayNumGroup->checkedId()); 0082 config.sync(); 0083 } 0084 0085 void ConfigDialog::slotOk() 0086 { 0087 save(); 0088 accept(); 0089 } 0090 0091 #include "moc_configdialog.cpp"