Commit df5398b3 authored by David Jarvie's avatar David Jarvie
Browse files

Refactor AlarmCalendar to split out resources and display calendars

parent 6437967c
KAlarm Change Log
=== Version 2.15.0 --- 11 April 2020 ===
+ Refactor AlarmCalendar to split out resources and display calendars.
=== Version 2.14.0 (KDE Applications 20.04) --- 27 March 2020 ===
+ Warn user if archiving but no default archived alarms calendar is set.
+ Fix some error messages not being displayed.
......
This diff is collapsed.
......@@ -36,105 +36,144 @@
using namespace KAlarmCal;
/** Provides read and write access to calendar files and resources.
/** Base class to provide read and write access to calendar files and resources.
* Either vCalendar or iCalendar files may be read, but the calendar is saved
* only in iCalendar format to avoid information loss.
*/
class AlarmCalendar : public QObject
{
Q_OBJECT
public:
~AlarmCalendar() override;
bool open();
int load();
bool reload();
bool save();
void close();
void startUpdate();
bool endUpdate();
KAEvent* earliestAlarm() const;
void setAlarmPending(KAEvent*, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
void disabledChanged(const KAEvent*);
KAEvent* event(const EventId& uniqueId, bool findUniqueId = false);
KAEvent* templateEvent(const QString& templateName);
KAEvent::List events(const QString& uniqueId) const;
KAEvent::List events(CalEvent::Types s = CalEvent::EMPTY) const { return events(Resource(), s); }
KAEvent::List events(const Resource&, CalEvent::Types = CalEvent::EMPTY) const;
KCalendarCore::Event::Ptr kcalEvent(const QString& uniqueID); // display calendar only
KCalendarCore::Event::List kcalEvents(CalEvent::Type s = CalEvent::EMPTY); // display calendar only
bool eventReadOnly(const QString& eventId) const;
bool addEvent(KAEvent&, QWidget* promptparent = nullptr, bool useEventID = false, Resource* = nullptr, bool noPrompt = false, bool* cancelled = nullptr);
bool modifyEvent(const EventId& oldEventId, KAEvent& newEvent);
KAEvent* updateEvent(const KAEvent&);
KAEvent* updateEvent(const KAEvent*);
bool deleteEvent(const KAEvent&, bool save = false);
bool deleteDisplayEvent(const QString& eventID, bool save = false);
void purgeEvents(const KAEvent::List&);
bool isOpen();
void adjustStartOfDay();
static bool initialiseCalendars();
static void terminateCalendars();
static AlarmCalendar* resources() { return mResourcesCalendar; }
static AlarmCalendar* displayCalendar() { return mDisplayCalendar; }
static AlarmCalendar* displayCalendarOpen();
static KAEvent* getEvent(const EventId&);
Q_SIGNALS:
void earliestAlarmChanged();
void haveDisabledAlarmsChanged(bool haveDisabled);
void atLoginEventAdded(const KAEvent&);
void calendarSaved(AlarmCalendar*);
private Q_SLOTS:
void slotResourceSettingsChanged(Resource&, ResourceType::Changes);
void slotResourcesPopulated();
void slotResourceAdded(Resource&);
void slotEventsAdded(Resource&, const QList<KAEvent>&);
void slotEventsToBeRemoved(Resource&, const QList<KAEvent>&);
void slotEventUpdated(Resource&, const KAEvent&);
private:
enum CalType { RESOURCES, LOCAL_ICAL, LOCAL_VCAL };
typedef QMap<ResourceId, KAEvent::List> ResourceMap; // id = invalid for display calendar
typedef QMap<ResourceId, KAEvent*> EarliestMap;
typedef QHash<EventId, KAEvent*> KAEventMap; // indexed by resource and event UID
AlarmCalendar();
AlarmCalendar(const QString& file, CalEvent::Type);
bool saveCal(const QString& newFile = QString());
bool isValid() const { return mCalType == RESOURCES || mDisplayCalStorage; }
void addNewEvent(const Resource&, KAEvent*, bool replace = false);
CalEvent::Type deleteEventInternal(const KAEvent&, bool deleteFromResources = true);
CalEvent::Type deleteEventInternal(const KAEvent&, Resource&, bool deleteFromResources = true);
CalEvent::Type deleteEventInternal(const QString& eventID, const KAEvent&, Resource&,
bool deleteFromResources = true);
void updateDisplayKAEvents();
void removeKAEvents(ResourceId, bool closing = false, CalEvent::Types = CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
void findEarliestAlarm(const Resource&);
void findEarliestAlarm(ResourceId); //deprecated
void checkForDisabledAlarms();
void checkForDisabledAlarms(bool oldEnabled, bool newEnabled);
static AlarmCalendar* mResourcesCalendar; // the calendar resources
static AlarmCalendar* mDisplayCalendar; // the display calendar
ResourceMap mResourceMap;
KAEventMap mEventMap; // lookup of all events by UID
EarliestMap mEarliestAlarm; // alarm with earliest trigger time, by resource
QSet<QString> mPendingAlarms; // IDs of alarms which are currently being processed after triggering
KCalendarCore::FileStorage::Ptr mDisplayCalStorage; // for display calendar; null if resources calendar
QString mDisplayCalPath; // path of display calendar file
QString mDisplayICalPath; // path of display iCalendar file
CalType mCalType; // what type of calendar mCalendar is (resources/ical/vcal)
CalEvent::Type mEventType; // what type of events the calendar file is for
bool mOpen {false}; // true if the calendar file is open
bool mIgnoreAtLogin {false}; // ignore new/updated repeat-at-login alarms
int mUpdateCount {0}; // nesting level of group of calendar update calls
bool mUpdateSave {false}; // save() was called while mUpdateCount > 0
bool mHaveDisabledAlarms {false}; // there is at least one individually disabled alarm
using QObject::event; // prevent "hidden" warning
Q_OBJECT
public:
KAEvent* event(const EventId& uniqueId);
bool addEvent(KAEvent&, QWidget* promptparent = nullptr, bool useEventID = false, Resource* = nullptr, bool noPrompt = false, bool* cancelled = nullptr);
void adjustStartOfDay();
static void initialise();
protected:
typedef QMap<ResourceId, KAEvent::List> ResourceMap; // id = invalid for display calendar
typedef QHash<EventId, KAEvent*> KAEventMap; // indexed by resource and event UID
AlarmCalendar();
virtual bool isValid() const = 0;
KAEvent::List events(CalEvent::Types, const Resource&) const;
virtual void addNewEvent(const Resource&, KAEvent*, bool replace = false);
KAEvent* deleteEventBase(const QString& eventID, Resource&);
bool removeKAEvents(ResourceId, CalEvent::Types);
ResourceMap mResourceMap;
KAEventMap mEventMap; // lookup of all events by UID
using QObject::event; // prevent "hidden" warning
};
/** Provides read and write access to resource calendars.
*/
class ResourcesCalendar : public AlarmCalendar
{
Q_OBJECT
public:
~ResourcesCalendar() override;
bool reload();
bool save();
void close();
KAEvent* earliestAlarm() const;
void setAlarmPending(KAEvent*, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
void disabledChanged(const KAEvent*);
using AlarmCalendar::event;
KAEvent* event(const EventId& uniqueId, bool findUniqueId);
KAEvent* templateEvent(const QString& templateName);
KAEvent::List events(const QString& uniqueId) const;
KAEvent::List events(const Resource&, CalEvent::Types = CalEvent::EMPTY) const;
KAEvent::List events(CalEvent::Types s = CalEvent::EMPTY) const;
bool eventReadOnly(const QString& eventId) const;
bool addEvent(KAEvent&, QWidget* promptparent = nullptr, bool useEventID = false, Resource* = nullptr, bool noPrompt = false, bool* cancelled = nullptr);
bool modifyEvent(const EventId& oldEventId, KAEvent& newEvent);
KAEvent* updateEvent(const KAEvent&);
bool deleteEvent(const KAEvent&, bool save = false);
void purgeEvents(const KAEvent::List&);
static void initialise();
static void terminate();
static ResourcesCalendar* instance() { return mInstance; }
static KAEvent* getEvent(const EventId&);
Q_SIGNALS:
void earliestAlarmChanged();
void haveDisabledAlarmsChanged(bool haveDisabled);
void atLoginEventAdded(const KAEvent&);
private Q_SLOTS:
void slotResourceSettingsChanged(Resource&, ResourceType::Changes);
void slotResourcesPopulated();
void slotResourceAdded(Resource&);
void slotEventsAdded(Resource&, const QList<KAEvent>&);
void slotEventsToBeRemoved(Resource&, const QList<KAEvent>&);
void slotEventUpdated(Resource&, const KAEvent&);
private:
typedef QMap<ResourceId, KAEvent*> EarliestMap;
ResourcesCalendar();
bool isValid() const override { return true; }
void addNewEvent(const Resource&, KAEvent*, bool replace = false) override;
CalEvent::Type deleteEventInternal(const KAEvent&, bool deleteFromResources = true);
CalEvent::Type deleteEventInternal(const KAEvent&, Resource&, bool deleteFromResources = true);
CalEvent::Type deleteEventInternal(const QString& eventID, const KAEvent&, Resource&,
bool deleteFromResources = true);
bool removeKAEvents(ResourceId, bool closing = false, CalEvent::Types = CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
void findEarliestAlarm(const Resource&);
void findEarliestAlarm(ResourceId);
void checkForDisabledAlarms();
void checkForDisabledAlarms(bool oldEnabled, bool newEnabled);
static ResourcesCalendar* mInstance; // the unique instance
EarliestMap mEarliestAlarm; // alarm with earliest trigger time, by resource
QSet<QString> mPendingAlarms; // IDs of alarms which are currently being processed after triggering
bool mIgnoreAtLogin {false}; // ignore new/updated repeat-at-login alarms
bool mHaveDisabledAlarms {false}; // there is at least one individually disabled alarm
};
/** Provides read and write access to the display calendar.
*/
class DisplayCalendar : public AlarmCalendar
{
Q_OBJECT
public:
~DisplayCalendar() override;
bool open();
int load();
bool reload();
bool save();
void close();
KAEvent::List events(CalEvent::Types = CalEvent::EMPTY) const;
KCalendarCore::Event::Ptr kcalEvent(const QString& uniqueID);
KCalendarCore::Event::List kcalEvents(CalEvent::Type s = CalEvent::EMPTY);
bool addEvent(KAEvent&);
bool deleteEvent(const QString& eventID, bool save = false);
bool isOpen() const { return mOpen; }
static void initialise();
static void terminate();
static DisplayCalendar* instance() { return mInstance; }
static DisplayCalendar* instanceOpen();
private:
enum CalType { LOCAL_ICAL, LOCAL_VCAL };
explicit DisplayCalendar(const QString& file);
bool saveCal(const QString& newFile = QString());
bool isValid() const override { return mCalendarStorage; }
void updateKAEvents();
static DisplayCalendar* mInstance; // the unique instance
KCalendarCore::FileStorage::Ptr mCalendarStorage;
QString mDisplayCalPath; // path of display calendar file
QString mDisplayICalPath; // path of display iCalendar file
CalType mCalType; // what type of calendar mCalendar is (ical/vcal)
bool mOpen {false}; // true if the calendar file is open
};
#endif // ALARMCALENDAR_H
......
......@@ -2,7 +2,7 @@
* birthdaymodel.cpp - model class for birthdays from address book
* Program: kalarm
* Copyright © 2009 by Tobias Koenig <tokoe@kde.org>
* Copyright © 2007-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2007-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -98,7 +98,7 @@ void BirthdaySortModel::setPrefixSuffix(const QString& prefix, const QString& su
mSuffix = suffix;
KAEvent event;
const KAEvent::List events = AlarmCalendar::resources()->events(CalEvent::ACTIVE);
const KAEvent::List events = ResourcesCalendar::instance()->events(CalEvent::ACTIVE);
for (KAEvent* event : events)
{
if (event->actionSubType() == KAEvent::MESSAGE
......
/*
* deferdlg.cpp - dialog to defer an alarm
* Program: kalarm
* Copyright © 2002-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2002-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -94,7 +94,7 @@ void DeferAlarmDlg::slotOk()
if (!mLimitEventId.isEmpty())
{
// Get the event being deferred
const KAEvent* event = AlarmCalendar::getEvent(mLimitEventId);
const KAEvent* event = ResourcesCalendar::getEvent(mLimitEventId);
if (event)
endTime = event->deferralLimit(&limitType);
}
......@@ -168,7 +168,7 @@ DateTime DeferAlarmDlg::setLimit(const KAEvent& event)
{
Q_ASSERT(event.collectionId() >= 0);
mLimitEventId = EventId(event);
const KAEvent* evnt = AlarmCalendar::getEvent(mLimitEventId);
const KAEvent* evnt = ResourcesCalendar::getEvent(mLimitEventId);
mLimitDateTime = evnt ? evnt->deferralLimit() : DateTime();
mTimeWidget->setMaxDateTime(mLimitDateTime);
return mLimitDateTime;
......
/*
* editdlg.cpp - dialog to create or modify an alarm or alarm template
* Program: kalarm
* Copyright © 2001-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2001-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -604,7 +604,7 @@ void EditAlarmDlg::initValues(const KAEvent* event)
if (!deferGroupVisible && mDeferGroup)
mDeferGroup->hide();
bool empty = AlarmCalendar::resources()->events(CalEvent::TEMPLATE).isEmpty();
bool empty = ResourcesCalendar::instance()->events(CalEvent::TEMPLATE).isEmpty();
if (mLoadTemplateButton)
mLoadTemplateButton->setEnabled(!empty);
}
......@@ -1006,7 +1006,7 @@ bool EditAlarmDlg::validate()
errmsg = i18nc("@info", "You must enter a name for the alarm template");
else if (name != mSavedTemplateName)
{
if (AlarmCalendar::resources()->templateEvent(name))
if (ResourcesCalendar::instance()->templateEvent(name))
errmsg = i18nc("@info", "Template name is already in use");
}
if (!errmsg.isEmpty())
......
......@@ -216,7 +216,7 @@ UpdateResult addEvent(KAEvent& event, Resource* resource, QWidget* msgParent, in
else
{
// Save the event details in the calendar file, and get the new event ID
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
// Note that AlarmCalendar::addEvent() updates 'event'.
if (!cal->addEvent(event, msgParent, (options & USE_EVENT_ID), resource, (options & NO_RESOURCE_PROMPT), &cancelled))
{
......@@ -266,7 +266,7 @@ UpdateResult addEvents(QVector<KAEvent>& events, QWidget* msgParent, bool allowK
}
else
{
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
for (int i = 0, end = events.count(); i < end; ++i)
{
// Save the event details in the calendar file, and get the new event ID
......@@ -305,7 +305,7 @@ bool addArchivedEvent(KAEvent& event, Resource* resourceptr)
bool archiving = (event.category() == CalEvent::ACTIVE);
if (archiving && !Preferences::archivedKeepDays())
return false; // expired alarms aren't being kept
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
KAEvent newevent(event);
KAEvent* const newev = &newevent;
if (archiving)
......@@ -333,7 +333,7 @@ UpdateResult addTemplate(KAEvent& event, Resource* resourceptr, QWidget* msgPare
UpdateStatusData status;
// Add the template to the calendar file
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
KAEvent newev(event);
if (!cal->addEvent(newev, msgParent, false, resourceptr))
status.status = UPDATE_FAILED;
......@@ -379,7 +379,7 @@ UpdateResult modifyEvent(KAEvent& oldEvent, KAEvent& newEvent, QWidget* msgParen
deleteFromKOrganizer(oldId.eventId());
}
// Update the event in the calendar file, and get the new event ID
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
if (!cal->modifyEvent(oldId, newEvent))
status.status = UPDATE_FAILED;
else
......@@ -421,7 +421,7 @@ UpdateResult updateEvent(KAEvent& event, QWidget* msgParent, bool archiveOnDelet
else
{
// Update the event in the calendar file.
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
cal->updateEvent(event);
if (!cal->save())
{
......@@ -441,7 +441,7 @@ UpdateResult updateEvent(KAEvent& event, QWidget* msgParent, bool archiveOnDelet
*/
UpdateResult updateTemplate(KAEvent& event, QWidget* msgParent)
{
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
const KAEvent* newEvent = cal->updateEvent(event);
UpdateStatus status = UPDATE_OK;
if (!newEvent)
......@@ -451,7 +451,7 @@ UpdateResult updateTemplate(KAEvent& event, QWidget* msgParent)
if (status != UPDATE_OK)
{
if (msgParent)
displayUpdateError(msgParent, ERR_TEMPLATE, UpdateStatusData(SAVE_FAILED));
displayUpdateError(msgParent, ERR_TEMPLATE, UpdateStatusData(status));
return UpdateResult(status);
}
......@@ -474,7 +474,7 @@ UpdateResult deleteEvents(QVector<KAEvent>& events, bool archive, QWidget* msgPa
if (events.isEmpty())
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
bool deleteWakeFromSuspendAlarm = false;
const QString wakeFromSuspendId = checkRtcWakeConfig().value(0);
for (int i = 0, end = events.count(); i < end; ++i)
......@@ -535,12 +535,11 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
if (!count)
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
for (const KAEvent* event : events)
{
// Update the window lists
// Delete the template from the calendar file
AlarmCalendar* cal = AlarmCalendar::resources();
if (!cal->deleteEvent(*event, false)) // don't save calendar after deleting
status.setError(UPDATE_ERROR);
}
......@@ -560,9 +559,9 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
void deleteDisplayEvent(const QString& eventID)
{
qCDebug(KALARM_LOG) << "KAlarm::deleteDisplayEvent:" << eventID;
AlarmCalendar* cal = AlarmCalendar::displayCalendarOpen();
DisplayCalendar* cal = DisplayCalendar::instanceOpen();
if (cal)
cal->deleteDisplayEvent(eventID, true); // save calendar after deleting
cal->deleteEvent(eventID, true); // save calendar after deleting
}
/******************************************************************************
......@@ -600,7 +599,7 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<EventId>& inelig
else
{
int count = 0;
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
const KADateTime now = KADateTime::currentUtcDateTime();
for (int i = 0, end = events.count(); i < end; ++i)
{
......@@ -661,7 +660,7 @@ UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgPar
if (events.isEmpty())
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
AlarmCalendar* cal = AlarmCalendar::resources();
ResourcesCalendar* cal = ResourcesCalendar::instance();
bool deleteWakeFromSuspendAlarm = false;
const QString wakeFromSuspendId = checkRtcWakeConfig().value(0);
for (int i = 0, end = events.count(); i < end; ++i)
......@@ -676,7 +675,7 @@ UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgPar
deleteWakeFromSuspendAlarm = true;
// Update the event in the calendar file
const KAEvent* newev = cal->updateEvent(event);
const KAEvent* newev = cal->updateEvent(*event);
if (!newev)
qCCritical(KALARM_LOG) << "KAlarm::enableEvents: Error updating event in calendar:" << event->id();
else
......@@ -722,7 +721,7 @@ void purgeArchive(int purgeDays)
const Resource resource = Resources::getStandard(CalEvent::ARCHIVED);
if (!resource.isValid())
return;
KAEvent::List events = AlarmCalendar::resources()->events(resource);
KAEvent::List events = ResourcesCalendar::instance()->events(resource);
for (int i = 0; i < events.count(); )
{
if (purgeDays && events.at(i)->createdDateTime().date() >= cutoff)
......@@ -731,7 +730,7 @@ void purgeArchive(int purgeDays)
++i;
}
if (!events.isEmpty())
AlarmCalendar::resources()->purgeEvents(events); // delete the events and save the calendar
ResourcesCalendar::instance()->purgeEvents(events); // delete the events and save the calendar
}
/******************************************************************************
......@@ -931,7 +930,7 @@ bool editNewAlarm(const QString& templateName, QWidget* parent)
{
if (!templateName.isEmpty())
{
KAEvent* templateEvent = AlarmCalendar::resources()->templateEvent(templateName);
KAEvent* templateEvent = ResourcesCalendar::instance()->templateEvent(templateName);
if (templateEvent->isValid())
{
editNewAlarm(templateEvent, parent);
......@@ -978,7 +977,7 @@ QStringList checkRtcWakeConfig(bool checkEventExists)
if (params.count() == 3 && params[2].toUInt() > KADateTime::currentUtcDateTime().toTime_t())
#endif
{
if (checkEventExists && !AlarmCalendar::getEvent(EventId(params[0].toLongLong(), params[1])))
if (checkEventExists && !ResourcesCalendar::getEvent(EventId(params[0].toLongLong(), params[1])))
return QStringList();
return params; // config entry is valid
}
......@@ -1108,7 +1107,7 @@ namespace KAlarm
*/
void editAlarm(KAEvent* event, QWidget* parent)
{
if (event->expired() || AlarmCalendar::resources()->eventReadOnly(event->id()))
if (event->expired() || ResourcesCalendar::instance()->eventReadOnly(event->id()))
{
viewAlarm(event, parent);
return;
......@@ -1120,7 +1119,7 @@ void editAlarm(KAEvent* event, QWidget* parent)
AutoQPointer<EditAlarmDlg> editDlg = EditAlarmDlg::create(false, event, false, parent, EditAlarmDlg::RES_USE_EVENT_ID);
if (editDlg->exec() == QDialog::Accepted)
{
if (!AlarmCalendar::resources()->event(id))
if (!ResourcesCalendar::instance()->event(id))
{
// Event has been deleted while the user was editing the alarm,
// so treat it as a new alarm.
......@@ -1159,7 +1158,7 @@ void editAlarm(KAEvent* event, QWidget* parent)
bool editAlarmById(const EventId& id, QWidget* parent)
{
const QString eventID(id.eventId());
KAEvent* event = AlarmCalendar::resources()->event(id, true);
KAEvent* event = ResourcesCalendar::instance()->event(id, true);
if (!event)
{
if (id.resourceId() != -1)
......@@ -1168,7 +1167,7 @@ bool editAlarmById(const EventId& id, QWidget* parent)
qCWarning(KALARM_LOG) << "KAlarm::editAlarmById: Event ID not found:" << eventID;
return false;
}
if (AlarmCalendar::resources()->eventReadOnly(event->id()))
if (ResourcesCalendar::instance()->eventReadOnly(event->id()))
{
qCCritical(KALARM_LOG) << "KAlarm::editAlarmById:" << eventID << ": read-only";
return false;
......@@ -1192,7 +1191,7 @@ bool editAlarmById(const EventId& id, QWidget* parent)
*/
void editTemplate(KAEvent* event, QWidget* parent)
{
if (AlarmCalendar::resources()->eventReadOnly(event->id()))
if (ResourcesCalendar::instance()->eventReadOnly(event->id()))
{
// The template is read-only, so make the dialogue read-only.
// Use AutoQPointer to guard against crash on application exit while
......@@ -1248,7 +1247,7 @@ void updateEditedAlarm(EditAlarmDlg* editDlg, KAEvent& event, Resource& resource
// Update the displayed lists and the calendar file
UpdateResult status;
if (AlarmCalendar::resources()->event(EventId(event)))
if (ResourcesCalendar::instance()->event(EventId(event)))
{
// The old alarm hasn't expired yet, so replace it
const Undo::Event undo(event, resource);
......@@ -1277,7 +1276,7 @@ KAEvent::List templateList()
{
KAEvent::List templates;
const bool includeCmdAlarms = ShellProcess::authorised();
const KAEvent::List events = AlarmCalendar::resources()->events(CalEvent::TEMPLATE);
const KAEvent::List events = ResourcesCalendar::instance()->events(CalEvent::TEMPLATE);
for (KAEvent* event : events)
{
if (includeCmdAlarms || !(event->actionTypes() & KAEvent::ACT_COMMAND))
......@@ -1332,10 +1331,10 @@ void refreshAlarmsIfQueued()
if (refreshAlarmsQueued)
{
qCDebug(KALARM_LOG) << "KAlarm::refreshAlarmsIfQueued";
AlarmCalendar::resources()->reload();
ResourcesCalendar::instance()->reload();
// Close any message windows for alarms which are now disabled
const KAEvent::List events = AlarmCalendar::resources()->events(CalEvent::ACTIVE);
const KAEvent::List events = ResourcesCalendar::instance()->events(CalEvent::ACTIVE);
for (KAEvent* event : events)
{
if (!event->enabled() && (event->actionTypes() & KAEvent::ACT_DISPLAY))
......
......@@ -150,7 +150,9 @@ KAlarmApp::~KAlarmApp()
mCommandProcesses.pop_front();
delete pd;
}
AlarmCalendar::terminateCalendars();
ResourcesCalendar::terminate();
DisplayCalendar::terminate();
DataModel::terminate();
}
/******************************************************************************
......@@ -215,15 +217,15 @@ bool KAlarmApp::initialiseTimerResources()
mAlarmTimer->setSingleShot(true);
connect(mAlarmTimer, &QTimer::timeout, this, &KAlarmApp::checkNextDueAlarm);
}
if (!AlarmCalendar::resources())
if (!ResourcesCalendar::instance())
{
qCDebug(KALARM_LOG) << "KAlarmApp::initialise: initialising calendars";
if (AlarmCalendar::initialiseCalendars())
{
connect(AlarmCalendar::resources(), &AlarmCalendar::earliestAlarmChanged, this, &KAlarmApp::checkNextDueAlarm);
connect(AlarmCalendar::resources(), &AlarmCalendar::atLoginEventAdded, this, &KAlarmApp::atLoginEventAdded);
return true;
}
DataModel::initialise();
ResourcesCalendar::initialise();
DisplayCalendar::initialise();
connect(ResourcesCalendar::instance(), &ResourcesCalendar::earliestAlarmChanged, this, &KAlarmApp::checkNextDueAlarm);
connect(ResourcesCalendar::instance(), &ResourcesCalendar::atLoginEventAdded, this, &KAlarmApp::atLoginEventAdded);
return true;
}
return false;
}
......@@ -628,7 +630,7 @@ int KAlarmApp::activateInstance(const QStringList& args, const QString& workingD
* been deleted - if so, don't try to do anything. (This has been known
* to happen under the Xfce desktop.)
*/
if (AlarmCalendar::resources())
if (ResourcesCalendar::instance())
{
if (Resources::allCreated())
{
......@@ -731,7 +733,8 @@ bool KAlarmApp::quitIf(int exitCode, bool force)
delete mAlarmTimer; // prevent checking for alarms after deleting calendars
mAlarmTimer = nullptr;
mInitialised = false; // prevent processQueue() from running
AlarmCalendar::terminateCalendars();