Commit 55c6e35c authored by Volker Krause's avatar Volker Krause
Browse files

Load Android calendar on first use, not on plugin creation

While generally a good idea, this is particularly important as we need
calendar access permissions to do this, and thus consumer code needs full
control over when calendar access actually happens.
parent bc75072b
......@@ -27,6 +27,21 @@ AndroidCalendarPlugin::AndroidCalendarPlugin(QObject *parent, const QVariantList
#else
, m_jni(Jni::fromHandle<android::content::Context>(QJniObject(QNativeInterface::QAndroidApplication::context())))
#endif
{
}
AndroidCalendarPlugin::~AndroidCalendarPlugin() = default;
QVector<KCalendarCore::Calendar::Ptr> AndroidCalendarPlugin::calendars() const
{
if (m_calendars.isEmpty()) {
loadCalendars();
}
return m_calendars;
}
void AndroidCalendarPlugin::loadCalendars() const
{
const Jni::Array<JniCalendarData> cals = m_jni.getCalendars();
for (const JniCalendarData &calData : cals) {
......@@ -46,10 +61,3 @@ AndroidCalendarPlugin::AndroidCalendarPlugin(QObject *parent, const QVariantList
m_calendars.push_back(KCalendarCore::Calendar::Ptr(cal));
}
}
AndroidCalendarPlugin::~AndroidCalendarPlugin() = default;
QVector<KCalendarCore::Calendar::Ptr> AndroidCalendarPlugin::calendars() const
{
return m_calendars;
}
......@@ -20,7 +20,9 @@ public:
QVector<KCalendarCore::Calendar::Ptr> calendars() const override;
private:
QVector<KCalendarCore::Calendar::Ptr> m_calendars;
void loadCalendars() const;
mutable QVector<KCalendarCore::Calendar::Ptr> m_calendars;
JniCalendarPlugin m_jni;
};
......
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