File indexing completed on 2025-01-05 04:54:28
0001 /* 0002 This file is part of Kontact. 0003 0004 SPDX-FileCopyrightText: 2004 Tobias Koenig <tokoe@kde.org> 0005 SPDX-FileCopyrightText: 2004-2006, 2009 Allen Winter <winter@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0008 */ 0009 0010 #include "kcmsdsummary.h" 0011 0012 #include <KAcceleratorManager> 0013 #include <KConfig> 0014 #include <KConfigGroup> 0015 #include <KLocalizedString> 0016 #include <KPluginFactory> 0017 0018 K_PLUGIN_CLASS_WITH_JSON(KCMSDSummary, "kcmsdsummary.json") 0019 0020 KCMSDSummary::KCMSDSummary(QObject *parent, const KPluginMetaData &data) 0021 : KCModule(parent, data) 0022 { 0023 setupUi(widget()); 0024 0025 customDaysChanged(7); 0026 0027 connect(mDateTodayButton, &QRadioButton::clicked, this, &KCMSDSummary::modified); 0028 connect(mDateMonthButton, &QRadioButton::clicked, this, &KCMSDSummary::modified); 0029 connect(mDateRangeButton, &QRadioButton::clicked, this, &KCMSDSummary::modified); 0030 0031 connect(mCustomDays, &QSpinBox::valueChanged, this, &KCMSDSummary::modified); 0032 connect(mCustomDays, &QSpinBox::valueChanged, this, &KCMSDSummary::customDaysChanged); 0033 0034 connect(mShowBirthdaysFromCalBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0035 connect(mShowAnniversariesFromCalBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0036 connect(mShowHolidaysFromCalBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0037 connect(mShowSpecialsFromCalBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0038 0039 connect(mShowBirthdaysFromKABBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0040 connect(mShowAnniversariesFromKABBox, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0041 0042 connect(mShowMineOnly, &QCheckBox::stateChanged, this, &KCMSDSummary::modified); 0043 0044 KAcceleratorManager::manage(widget()); 0045 0046 load(); 0047 } 0048 0049 void KCMSDSummary::modified() 0050 { 0051 markAsChanged(); 0052 } 0053 0054 void KCMSDSummary::customDaysChanged(int value) 0055 { 0056 mCustomDays->setSuffix(i18np(" day", " days", value)); 0057 } 0058 0059 void KCMSDSummary::load() 0060 { 0061 KConfig config(QStringLiteral("kcmsdsummaryrc")); 0062 0063 KConfigGroup group = config.group(QStringLiteral("Days")); 0064 const int days = group.readEntry("DaysToShow", 7); 0065 if (days == 1) { 0066 mDateTodayButton->setChecked(true); 0067 } else if (days == 31) { 0068 mDateMonthButton->setChecked(true); 0069 } else { 0070 mDateRangeButton->setChecked(true); 0071 mCustomDays->setValue(days); 0072 mCustomDays->setEnabled(true); 0073 } 0074 0075 group = config.group(QStringLiteral("Show")); 0076 0077 mShowBirthdaysFromKABBox->setChecked(group.readEntry("BirthdaysFromContacts", true)); 0078 mShowBirthdaysFromCalBox->setChecked(group.readEntry("BirthdaysFromCalendar", true)); 0079 0080 mShowAnniversariesFromKABBox->setChecked(group.readEntry("AnniversariesFromContacts", true)); 0081 mShowAnniversariesFromCalBox->setChecked(group.readEntry("AnniversariesFromCalendar", true)); 0082 0083 mShowHolidaysFromCalBox->setChecked(group.readEntry("HolidaysFromCalendar", true)); 0084 0085 mShowSpecialsFromCalBox->setChecked(group.readEntry("SpecialsFromCalendar", true)); 0086 0087 group = config.group(QStringLiteral("Groupware")); 0088 mShowMineOnly->setChecked(group.readEntry("ShowMineOnly", false)); 0089 0090 setNeedsSave(false); 0091 } 0092 0093 void KCMSDSummary::save() 0094 { 0095 KConfig config(QStringLiteral("kcmsdsummaryrc")); 0096 0097 KConfigGroup group = config.group(QStringLiteral("Days")); 0098 0099 int days; 0100 if (mDateTodayButton->isChecked()) { 0101 days = 1; 0102 } else if (mDateMonthButton->isChecked()) { 0103 days = 31; 0104 } else { 0105 days = mCustomDays->value(); 0106 } 0107 group.writeEntry("DaysToShow", days); 0108 0109 group = config.group(QStringLiteral("Show")); 0110 0111 group.writeEntry("BirthdaysFromContacts", mShowBirthdaysFromKABBox->isChecked()); 0112 group.writeEntry("BirthdaysFromCalendar", mShowBirthdaysFromCalBox->isChecked()); 0113 0114 group.writeEntry("AnniversariesFromContacts", mShowAnniversariesFromKABBox->isChecked()); 0115 group.writeEntry("AnniversariesFromCalendar", mShowAnniversariesFromCalBox->isChecked()); 0116 0117 group.writeEntry("HolidaysFromCalendar", mShowHolidaysFromCalBox->isChecked()); 0118 0119 group.writeEntry("SpecialsFromCalendar", mShowSpecialsFromCalBox->isChecked()); 0120 0121 group = config.group(QStringLiteral("Groupware")); 0122 group.writeEntry("ShowMineOnly", mShowMineOnly->isChecked()); 0123 0124 group.sync(); 0125 setNeedsSave(false); 0126 } 0127 0128 void KCMSDSummary::defaults() 0129 { 0130 mDateRangeButton->setChecked(true); 0131 mCustomDays->setValue(7); 0132 mCustomDays->setEnabled(true); 0133 0134 mShowBirthdaysFromKABBox->setChecked(true); 0135 mShowBirthdaysFromCalBox->setChecked(true); 0136 mShowAnniversariesFromKABBox->setChecked(true); 0137 mShowAnniversariesFromCalBox->setChecked(true); 0138 mShowHolidaysFromCalBox->setChecked(true); 0139 mShowSpecialsFromCalBox->setChecked(true); 0140 0141 mShowMineOnly->setChecked(false); 0142 markAsChanged(); 0143 } 0144 0145 #include "kcmsdsummary.moc" 0146 0147 #include "moc_kcmsdsummary.cpp"