Verified Commit 3985df28 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

alternatecalendar: Add Indian national calendar system support

The Indian national calendar, sometimes called the Saka calendar, is
used, alongside the Gregorian calendar, by The Gazette of India, in
news broadcasts by All India Radio and in calendars and communications
issued by the Government of India.

CCBUG: 429892
parent 47bcfc37
Pipeline #178563 passed with stage
in 2 minutes and 42 seconds
......@@ -25,6 +25,7 @@ if(ICU_FOUND)
${alternatecalendar_LIB_SRCS}
provider/icucalendar_p.cpp
provider/chinesecalendar.cpp
provider/indiancalendar.cpp
)
set(alternatecalendar_LINK_LIBRARIES
${alternatecalendar_LINK_LIBRARIES}
......
......@@ -15,6 +15,7 @@
#include "provider/qtcalendar.h"
#ifdef HAVE_ICU
#include "provider/chinesecalendar.h"
#include "provider/indiancalendar.h"
#endif
class AlternateCalendarPluginPrivate
......@@ -64,6 +65,9 @@ void AlternateCalendarPluginPrivate::init()
case CalendarSystem::Chinese:
m_calendarProvider.reset(new ChineseCalendarProvider(q, m_calendarSystem));
break;
case CalendarSystem::Indian:
m_calendarProvider.reset(new IndianCalendarProvider(q, m_calendarSystem));
break;
#endif
#ifndef QT_BOOTSTRAPPED
case CalendarSystem::Julian:
......
......@@ -30,6 +30,7 @@ public:
IslamicCivil = static_cast<int>(QCalendar::System::IslamicCivil),
#endif
Chinese = static_cast<int>(QCalendar::System::Last) + 1, // QTBUG-89824: QCalendar doesn't support Chinese calendar system
Indian, // QCalendar doesn't support India calendar system
};
Q_ENUM(System)
};
......
......@@ -29,6 +29,7 @@ CalendarSystemModel::CalendarSystemModel(QObject *parent)
#endif
#ifdef HAVE_ICU
{CalendarSystem::Chinese, i18ndc("plasma_calendar_alternatecalendar", "@item:inlist", "Chinese Lunar Calendar")},
{CalendarSystem::Indian, i18ndc("plasma_calendar_alternatecalendar", "@item:inlist", "Indian National Calendar")},
#endif
};
const QMetaEnum e = QMetaEnum::fromType<CalendarSystem::System>();
......
/*
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "indiancalendar.h"
class IndianCalendarProviderPrivate : public ICUCalendarPrivate
{
public:
explicit IndianCalendarProviderPrivate();
QDate fromGregorian(const QDate &_date);
CalendarEvents::CalendarEventsPlugin::SubLabel subLabels(const QDate &date);
};
IndianCalendarProviderPrivate::IndianCalendarProviderPrivate()
: ICUCalendarPrivate()
{
if (U_FAILURE(m_errorCode)) {
return; // Failed to create m_GregorianCalendar
}
m_calendar.reset(icu::Calendar::createInstance("en_US@calendar=indian", m_errorCode));
}
QDate IndianCalendarProviderPrivate::fromGregorian(const QDate &_date)
{
if (U_FAILURE(m_errorCode) || !_date.isValid() || !setDate(_date)) {
return QDate();
}
return date();
}
CalendarEvents::CalendarEventsPlugin::SubLabel IndianCalendarProviderPrivate::subLabels(const QDate &date)
{
auto sublabel = CalendarEvents::CalendarEventsPlugin::SubLabel{};
if (U_FAILURE(m_errorCode) || !date.isValid() || !setDate(date)) {
return sublabel;
}
sublabel.dayLabel = QString::number(day());
sublabel.label = QLocale(QLocale::English, QLocale::India).toString(QDate(year(), month(), day()));
sublabel.priority = CalendarEvents::CalendarEventsPlugin::SubLabelPriority::Low;
return sublabel;
}
IndianCalendarProvider::IndianCalendarProvider(QObject *parent, CalendarSystem::System calendarSystem)
: AbstractCalendarProvider(parent, calendarSystem)
, d(std::make_unique<IndianCalendarProviderPrivate>())
{
Q_ASSERT(m_calendarSystem == CalendarSystem::Indian);
}
IndianCalendarProvider::~IndianCalendarProvider()
{
}
QDate IndianCalendarProvider::fromGregorian(const QDate &date) const
{
return d->fromGregorian(date);
}
CalendarEvents::CalendarEventsPlugin::SubLabel IndianCalendarProvider::subLabels(const QDate &date) const
{
return d->subLabels(date);
}
/*
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include "abstractcalendarprovider.h"
#include "icucalendar_p.h"
/**
* @short An alternate calendar provider for Indian calendar system.
*
* This class presents an alternate calendar provider for Indian calendar system.
*/
class IndianCalendarProvider : public AbstractCalendarProvider
{
Q_OBJECT
public:
explicit IndianCalendarProvider(QObject *parent, CalendarSystem::System calendarSystem);
~IndianCalendarProvider() override;
QDate fromGregorian(const QDate &date) const override;
CalendarEvents::CalendarEventsPlugin::SubLabel subLabels(const QDate &date) const override;
private:
const std::unique_ptr<class IndianCalendarProviderPrivate> d;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment