File indexing completed on 2025-01-05 04:49:35

0001 /*
0002   This file is part of KOrganizer.
0003 
0004   SPDX-FileCopyrightText: 2003 Jonathan Singer <jsinger@leeta.net>
0005   SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com>
0006 
0007   SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "configdialog.h"
0011 
0012 #include <KConfig>
0013 #include <KLocalizedString>
0014 #include <QLocale>
0015 
0016 #include <KConfigGroup>
0017 #include <QCheckBox>
0018 #include <QDialogButtonBox>
0019 #include <QFrame>
0020 #include <QPushButton>
0021 #include <QVBoxLayout>
0022 
0023 ConfigDialog::ConfigDialog(QWidget *parent)
0024     : QDialog(parent)
0025 {
0026     QFrame *topFrame = new QFrame(this);
0027 
0028     setWindowTitle(i18nc("@title:window", "Configure Holidays"));
0029     QVBoxLayout *mainLayout = new QVBoxLayout(this);
0030     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0031     mainLayout->addWidget(topFrame);
0032     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0033     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0034     connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigDialog::reject);
0035     mainLayout->addWidget(buttonBox);
0036     okButton->setDefault(true);
0037     setModal(true);
0038     QVBoxLayout *topLayout = new QVBoxLayout(topFrame);
0039     topLayout->setContentsMargins(0, 0, 0, 0);
0040 
0041     mIsraelBox = new QCheckBox(topFrame);
0042     mIsraelBox->setText(i18n("Use Israeli holidays"));
0043     topLayout->addWidget(mIsraelBox);
0044 
0045     mParshaBox = new QCheckBox(topFrame);
0046     mParshaBox->setText(i18n("Show weekly parsha"));
0047     topLayout->addWidget(mParshaBox);
0048 
0049     mOmerBox = new QCheckBox(topFrame);
0050     mOmerBox->setText(i18n("Show day of Omer"));
0051     topLayout->addWidget(mOmerBox);
0052 
0053     mCholBox = new QCheckBox(topFrame);
0054     mCholBox->setText(i18n("Show Chol HaMoed"));
0055     topLayout->addWidget(mCholBox);
0056     topLayout->addStretch(1);
0057     connect(okButton, &QPushButton::clicked, this, &ConfigDialog::slotOk);
0058     load();
0059 }
0060 
0061 ConfigDialog::~ConfigDialog()
0062 {
0063 }
0064 
0065 void ConfigDialog::load()
0066 {
0067     KConfig config(QStringLiteral("korganizerrc"));
0068 
0069     KConfigGroup group(&config, QStringLiteral("Hebrew Calendar Plugin"));
0070     mIsraelBox->setChecked(group.readEntry("UseIsraelSettings", QLocale::territoryToString(QLocale().territory()) == QLatin1StringView(".il")));
0071     mParshaBox->setChecked(group.readEntry("ShowParsha", true));
0072     mCholBox->setChecked(group.readEntry("ShowChol_HaMoed", true));
0073     mOmerBox->setChecked(group.readEntry("ShowOmer", true));
0074 }
0075 
0076 void ConfigDialog::save()
0077 {
0078     KConfig config(QStringLiteral("korganizerrc"));
0079     KConfigGroup group(&config, QStringLiteral("Hebrew Calendar Plugin"));
0080     group.writeEntry("UseIsraelSettings", mIsraelBox->isChecked());
0081     group.writeEntry("ShowParsha", mParshaBox->isChecked());
0082     group.writeEntry("ShowChol_HaMoed", mCholBox->isChecked());
0083     group.writeEntry("ShowOmer", mOmerBox->isChecked());
0084     group.sync();
0085 }
0086 
0087 void ConfigDialog::slotOk()
0088 {
0089     save();
0090     accept();
0091 }
0092 
0093 #include "moc_configdialog.cpp"