[pim/korganizer] /: Implement holiday category selection and filtering.

Allen Winter null at kde.org
Fri Apr 10 19:17:58 BST 2026


Git commit 654e389543c6d48c23fc238593c9d95c2853c9e1 by Allen Winter.
Committed on 10/04/2026 at 15:00.
Pushed by winterz into branch 'master'.

Implement holiday category selection and filtering.

BUG:336147

M  +2    -2    CMakeLists.txt
M  +15   -5    doc/index.docbook
M  +24   -2    src/koglobals.cpp
M  +15   -2    src/koglobals.h
M  +2    -0    src/kontactplugin/specialdates/sdsummarywidget.cpp
M  +55   -2    src/prefs/koprefsdialogtime.cpp
M  +1    -0    src/prefs/koprefsdialogtime.h
M  +2    -0    src/whatsnew/whatsnewtranslations.cpp

https://invent.kde.org/pim/korganizer/-/commit/654e389543c6d48c23fc238593c9d95c2853c9e1

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49841d835..f3ab3c8ff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,8 +148,8 @@ find_package(
 set(PIMCOMMON_LIB_VERSION "6.7.40")
 set(LIBKDEPIM_LIB_VERSION "6.7.40")
 set(LIBINCIDENCEEDITOR_LIB_VERSION "6.7.40")
-set(CALENDARSUPPORT_LIB_VERSION "6.7.40")
-set(EVENTVIEW_LIB_VERSION "6.7.41")
+set(CALENDARSUPPORT_LIB_VERSION "6.7.41")
+set(EVENTVIEW_LIB_VERSION "6.7.42")
 
 # Find KF6 package
 find_package(KF6I18n ${KF_MIN_VERSION} CONFIG REQUIRED)
diff --git a/doc/index.docbook b/doc/index.docbook
index 887a662de..145fb3c57 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -2060,11 +2060,21 @@ in the Agenda view.</para></listitem>
 </varlistentry>
 
 <varlistentry>
-<term><guilabel>Holidays</guilabel></term>
-<listitem><para>Select your country from the drop down list, or if
-it is not listed, select <guilabel>(None)</guilabel>.
-If your country is selected, &korganizer; will recognize and display
-its important dates and holidays in the calendar view.</para></listitem>
+<term><guilabel>Holiday Regions</guilabel></term>
+<listitem><para>Select holiday regions from the drop down list.
+For each selected region, &korganizer; will recognize and display
+its important dates and holidays in the agenda and month views.
+You can configure the types of holidays to display with the
+Holiday Categories drop down list (see next entry).
+</para></listitem>
+</varlistentry>
+
+<varlistentry>
+<term><guilabel>Holiday Categories</guilabel></term>
+<listitem><para>Select the holiday categories from the drop down list.
+By default all holiday types are enabled.  Select the holiday categories
+you want to hide, for example some people are not interesting in religious holidays.
+</para></listitem>
 </varlistentry>
 
 <varlistentry>
diff --git a/src/koglobals.cpp b/src/koglobals.cpp
index d57a78397..e57d66473 100644
--- a/src/koglobals.cpp
+++ b/src/koglobals.cpp
@@ -8,6 +8,10 @@
 
 #include "koglobals.h"
 #include "prefs/koprefs.h"
+
+#include <CalendarSupport/KCalPrefs>
+
+#include <KHolidays/HolidayCategories>
 #include <KHolidays/HolidayRegion>
 
 #include <QApplication>
@@ -30,6 +34,7 @@ KOGlobals::KOGlobals() = default;
 KOGlobals::~KOGlobals()
 {
     qDeleteAll(mHolidayRegions);
+    mHolidayCategories.clear();
 }
 
 bool KOGlobals::reverseLayout()
@@ -37,7 +42,7 @@ bool KOGlobals::reverseLayout()
     return QApplication::isRightToLeft();
 }
 
-QMap<QDate, QStringList> KOGlobals::holiday(const QDate &start, const QDate &end) const
+QMap<QDate, QStringList> KOGlobals::holiday(const QDate &start, const QDate &end)
 {
     QMap<QDate, QStringList> holidaysByDate;
 
@@ -45,8 +50,10 @@ QMap<QDate, QStringList> KOGlobals::holiday(const QDate &start, const QDate &end
         return holidaysByDate;
     }
 
-    for (const KHolidays::HolidayRegion *region : std::as_const(mHolidayRegions)) {
+    setHolidayCategories(CalendarSupport::KCalPrefs::instance()->holidayCategories());
+    for (KHolidays::HolidayRegion *region : std::as_const(mHolidayRegions)) {
         if (region && region->isValid()) {
+            region->setCategories(holidayCategories());
             const KHolidays::Holiday::List list = region->rawHolidaysWithAstroSeasons(start, end);
             const int listCount(list.count());
             for (int i = 0; i < listCount; ++i) {
@@ -92,3 +99,18 @@ QList<KHolidays::HolidayRegion *> &KOGlobals::holidays()
 {
     return mHolidayRegions;
 }
+
+void KOGlobals::setHolidayCategories(const QStringList &categories)
+{
+    mHolidayCategories.clear();
+    for (const QString &category : categories) {
+        if (KHolidays::isHolidayCategoryValid(category)) {
+            mHolidayCategories.append(category);
+        }
+    }
+}
+
+QStringList KOGlobals::holidayCategories() const
+{
+    return mHolidayCategories;
+}
diff --git a/src/koglobals.h b/src/koglobals.h
index 7375b3e52..e4386789b 100644
--- a/src/koglobals.h
+++ b/src/koglobals.h
@@ -31,7 +31,7 @@ public:
 
     ~KOGlobals();
 
-    [[nodiscard]] QMap<QDate, QStringList> holiday(const QDate &start, const QDate &end) const;
+    [[nodiscard]] QMap<QDate, QStringList> holiday(const QDate &start, const QDate &end);
 
     [[nodiscard]] int firstDayOfWeek() const;
 
@@ -43,13 +43,26 @@ public:
     */
     void setHolidays(const QStringList &regions);
 
-    /** return the HolidayRegion object or 0 if none has been defined
+    /**
+     * Returns the HolidayRegion object or 0 if none has been defined
      */
     [[nodiscard]] QList<KHolidays::HolidayRegion *> &holidays();
 
+    /**
+     * Set which holiday categories the user wants to use.
+     * @param categories a list of Holiday Category strings.
+     */
+    void setHolidayCategories(const QStringList &categories);
+
+    /**
+     * Returns the holiday categories list
+     */
+    [[nodiscard]] QStringList holidayCategories() const;
+
 protected:
     KOGlobals();
 
 private:
     QList<KHolidays::HolidayRegion *> mHolidayRegions;
+    QStringList mHolidayCategories;
 };
diff --git a/src/kontactplugin/specialdates/sdsummarywidget.cpp b/src/kontactplugin/specialdates/sdsummarywidget.cpp
index 34d551730..109411d42 100644
--- a/src/kontactplugin/specialdates/sdsummarywidget.cpp
+++ b/src/kontactplugin/specialdates/sdsummarywidget.cpp
@@ -19,6 +19,7 @@
 #include <Akonadi/ItemFetchScope>
 #include <Akonadi/SearchQuery>
 #include <CalendarSupport/CalendarSingleton>
+#include <CalendarSupport/KCalPrefs>
 #include <CalendarSupport/Utils>
 
 #include <KCalendarCore/Calendar>
@@ -355,6 +356,7 @@ void SDSummaryWidget::createLabels()
     if (mShowHolidays) {
         if (initHolidays()) {
             for (dt = QDate::currentDate(); dt <= QDate::currentDate().addDays(mDaysAhead - 1); dt = dt.addDays(1)) {
+                mHolidays->setCategories(CalendarSupport::KCalPrefs::instance()->holidayCategories());
                 QList<Holiday> const holidays = mHolidays->rawHolidaysWithAstroSeasons(dt);
                 QList<Holiday>::ConstIterator it = holidays.constBegin();
                 for (; it != holidays.constEnd(); ++it) {
diff --git a/src/prefs/koprefsdialogtime.cpp b/src/prefs/koprefsdialogtime.cpp
index 69f398ac1..225f119f6 100644
--- a/src/prefs/koprefsdialogtime.cpp
+++ b/src/prefs/koprefsdialogtime.cpp
@@ -3,6 +3,7 @@
 
   SPDX-FileCopyrightText: 2000-2003 Cornelius Schumacher <schumacher at kde.org>
   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold at kainhofer.com>
+  SPDX-FileCopyrightText: 2025 Allen Winter <winter at kde.org>
 
   SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Qt-Commercial-exception-1.0
 */
@@ -11,12 +12,14 @@
 #include "koprefs.h"
 #include <CalendarSupport/KCalPrefs>
 #include <KComboBox>
+#include <KHolidays/HolidayCategories>
 #include <KHolidays/HolidayRegion>
 #include <KLocalizedString>
 #include <KPluginFactory>
 #include <KTimeComboBox>
 #include <KUrlRequester>
 #include <Libkdepim/KCheckComboBox>
+#include <QButtonGroup>
 #include <QCheckBox>
 #include <QComboBox>
 #include <QFrame>
@@ -62,11 +65,12 @@ KOPrefsDialogTime::KOPrefsDialogTime(QObject *parent, const KPluginMetaData &dat
     auto holidayRegBox = new QWidget(regionalPage);
     auto holidayRegBoxHBoxLayout = new QHBoxLayout(holidayRegBox);
     holidayRegBoxHBoxLayout->setContentsMargins({});
-    holidaysLayout->addWidget(holidayRegBox, 1, 0, 1, 2);
+    holidaysLayout->addWidget(holidayRegBox, 1, 0, 1, 1);
 
-    auto holidayLabel = new QLabel(i18nc("@label", "Use holiday region:"), holidayRegBox);
+    auto holidayLabel = new QLabel(i18nc("@label", "Use holiday regions:"), holidayRegBox);
     holidayLabel->setToolTip(CalendarSupport::KCalPrefs::instance()->holidaysItem()->toolTip());
     holidayLabel->setWhatsThis(CalendarSupport::KCalPrefs::instance()->holidaysItem()->whatsThis());
+    holidayRegBoxHBoxLayout->addWidget(holidayLabel);
 
     mHolidayCheckCombo = new KPIM::KCheckComboBox(holidayRegBox);
     holidayRegBoxHBoxLayout->addWidget(mHolidayCheckCombo);
@@ -108,6 +112,45 @@ KOPrefsDialogTime::KOPrefsDialogTime(QObject *parent, const KPluginMetaData &dat
         mHolidayCheckCombo->setItemCheckState(mHolidayCheckCombo->findData(regionStr), Qt::Checked);
     }
 
+    // holiday region selection
+    auto holidayCatBox = new QWidget(regionalPage);
+    auto holidayCatBoxHBoxLayout = new QHBoxLayout(holidayCatBox);
+    holidayCatBoxHBoxLayout->setContentsMargins({});
+    holidaysLayout->addWidget(holidayCatBox, 2, 0, 1, 1);
+
+    auto holidayCatLabel = new QLabel(i18nc("@label", "Use holiday categories:"), holidayCatBox);
+    holidayCatLabel->setToolTip(CalendarSupport::KCalPrefs::instance()->holidayCategoriesItem()->toolTip());
+    holidayCatLabel->setWhatsThis(CalendarSupport::KCalPrefs::instance()->holidayCategoriesItem()->whatsThis());
+    holidayCatBoxHBoxLayout->addWidget(holidayCatLabel);
+
+    mHolidayTypeCheckCombo = new KPIM::KCheckComboBox(holidayCatBox);
+    holidayCatBoxHBoxLayout->addWidget(mHolidayTypeCheckCombo);
+    connect(mHolidayTypeCheckCombo, &KPIM::KCheckComboBox::checkedItemsChanged, this, &KOPrefsDialogTime::slotWidChanged);
+    holidaysLayout->addWidget(mHolidayTypeCheckCombo);
+
+    mHolidayTypeCheckCombo->setToolTip(CalendarSupport::KCalPrefs::instance()->holidayCategoriesItem()->toolTip());
+    mHolidayTypeCheckCombo->setWhatsThis(CalendarSupport::KCalPrefs::instance()->holidayCategoriesItem()->whatsThis());
+
+    mHolidayTypeCheckCombo->clear();
+    mHolidayTypeCheckCombo->setDefaultText(i18nc("@item:inlistbox", "Select Holiday Categories"));
+    const QStringList categories = KHolidays::allHolidayCategories();
+    int itemNo = 0;
+    for (const auto &category : std::as_const(categories)) {
+        const QString trCategory = KHolidays::translateHolidayCategory(category);
+        mHolidayTypeCheckCombo->addItem(trCategory, category);
+        mHolidayTypeCheckCombo->setItemData(itemNo++, KHolidays::holidayCategoryDescription(category), Qt::ToolTipRole);
+    }
+    const auto holidayCategories = CalendarSupport::KCalPrefs::instance()->holidayCategories();
+    if (!holidayCategories.isEmpty()) {
+        for (const QString &type : holidayCategories) {
+            mHolidayTypeCheckCombo->setItemCheckState(mHolidayTypeCheckCombo->findData(type), Qt::Checked);
+        }
+    } else {
+        for (const QString &type : categories) {
+            mHolidayTypeCheckCombo->setItemCheckState(mHolidayTypeCheckCombo->findData(type), Qt::Checked);
+        }
+    }
+
     auto workingHoursGroupBox = new QGroupBox(i18nc("@title:group", "Weekly Schedule"), regionalPage);
     regionalLayout->addWidget(workingHoursGroupBox, 2, 0);
 
@@ -260,6 +303,16 @@ void KOPrefsDialogTime::usrWriteConfig()
     }
     CalendarSupport::KCalPrefs::instance()->mHolidays = HolidayRegions;
 
+    QStringList HolidayTypes;
+    const auto holidayTypesCheckedItems = mHolidayTypeCheckCombo->checkedItems();
+    for (const QString &str : holidayTypesCheckedItems) {
+        const int index = mHolidayTypeCheckCombo->findText(str);
+        if (index >= 0) {
+            HolidayTypes.append(mHolidayTypeCheckCombo->itemData(index).toString());
+        }
+    }
+    CalendarSupport::KCalPrefs::instance()->mHolidayCategories = HolidayTypes;
+
     CalendarSupport::KCalPrefs::instance()->mReminderTime = mReminderTimeSpin->value();
     CalendarSupport::KCalPrefs::instance()->mReminderTimeUnits = mReminderUnitsCombo->currentIndex();
 
diff --git a/src/prefs/koprefsdialogtime.h b/src/prefs/koprefsdialogtime.h
index 6a7b0bd3f..e4442c31f 100644
--- a/src/prefs/koprefsdialogtime.h
+++ b/src/prefs/koprefsdialogtime.h
@@ -30,6 +30,7 @@ protected:
 private:
     QStringList tzonenames;
     KPIM::KCheckComboBox *mHolidayCheckCombo = nullptr;
+    KPIM::KCheckComboBox *mHolidayTypeCheckCombo = nullptr;
     QSpinBox *mReminderTimeSpin = nullptr;
     KComboBox *mReminderUnitsCombo = nullptr;
     QCheckBox *mWorkDays[7];
diff --git a/src/whatsnew/whatsnewtranslations.cpp b/src/whatsnew/whatsnewtranslations.cpp
index fb137b28f..43548b1bf 100644
--- a/src/whatsnew/whatsnewtranslations.cpp
+++ b/src/whatsnew/whatsnewtranslations.cpp
@@ -19,6 +19,8 @@ QList<KLazyLocalizedString> WhatsNewTranslations::lastNewFeatures() const
                "Setting a default Event calendar has been supported for a long time.  See the Calendar Manager context menu \"Set as Default Todo Calendar\""),
         kli18n("Agenda view: optionally draw bolder/fatter horizontal grid lines every two hours. To enable this behaviour, check the \"Draw bold horizontal "
                "grid lines for the even hours\" option in the View->Agenda View tab"),
+        kli18n("It is now possible to hide holidays that belong to specific categories, for example to hide religious holidays. See the Categories combobox in "
+               "the Holidays section of the Time&Date->Regional tab"),
     };
     return info;
 }



More information about the kde-doc-english mailing list