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 "hebrew.h"
0011 #include "configdialog.h"
0012 #include "converter.h"
0013 #include "holiday.h"
0014 
0015 #include <KCalendarSystem>
0016 #include <KConfig>
0017 #include <KConfigGroup>
0018 #include <KLocalizedString>
0019 #include <KPluginFactory>
0020 #include <QLocale>
0021 
0022 K_PLUGIN_CLASS_WITH_JSON(Hebrew, "hebrew.json")
0023 
0024 using namespace EventViews::CalendarDecoration;
0025 
0026 Hebrew::Hebrew(QObject *parent, const QVariantList &args)
0027     : Decoration(parent, args)
0028 {
0029     KConfig config(QStringLiteral("korganizerrc"), KConfig::NoGlobals);
0030 
0031     KConfigGroup group(&config, QStringLiteral("Hebrew Calendar Plugin"));
0032     areWeInIsrael = group.readEntry("UseIsraelSettings", QLocale::territoryToString(QLocale().territory()) == QLatin1StringView(".il"));
0033     showParsha = group.readEntry("ShowParsha", true);
0034     showChol = group.readEntry("ShowChol_HaMoed", true);
0035     showOmer = group.readEntry("ShowOmer", true);
0036 }
0037 
0038 void Hebrew::configure(QWidget *parent)
0039 {
0040     ConfigDialog dlg(parent);
0041     dlg.exec();
0042 }
0043 
0044 Element::List Hebrew::createDayElements(const QDate &date)
0045 {
0046     Element::List el;
0047     QString text;
0048     HebrewDate hd = HebrewDate::fromSecular(date.year(), date.month(), date.day());
0049 
0050     const QStringList holidays = Holiday::findHoliday(hd, areWeInIsrael, showParsha, showChol, showOmer);
0051 
0052     KCalendarSystem *cal = KCalendarSystem::create(KLocale::HebrewCalendar);
0053 
0054     text = cal->formatDate(date, KLocale::Day, KLocale::LongNumber) + QLatin1Char(' ') + cal->monthName(date);
0055 
0056     for (const QString &holiday : holidays) {
0057         text += QLatin1StringView("<br/>\n") + holiday;
0058     }
0059 
0060     text = i18nc("Change the next two strings if emphasis is done differently in your language.", "<qt><p align=\"center\"><i>\n%1\n</i></p></qt>", text);
0061     el.append(new StoredElement(QStringLiteral("main element"), text));
0062     return el;
0063 }
0064 
0065 QString Hebrew::info() const
0066 {
0067     return i18n("This plugin provides the date in the Jewish calendar.");
0068 }
0069 
0070 #include "hebrew.moc"