Commit 2fdf29a9 authored by David Jarvie's avatar David Jarvie
Browse files

Make all public ResourcesCalendar methods static

parent 0d64852b
Pipeline #27830 passed with stage
in 10 minutes and 14 seconds
......@@ -97,7 +97,7 @@ void BirthdaySortModel::setPrefixSuffix(const QString& prefix, const QString& su
mPrefix = prefix;
mSuffix = suffix;
const QVector<KAEvent> events = ResourcesCalendar::instance()->events(CalEvent::ACTIVE);
const QVector<KAEvent> events = ResourcesCalendar::events(CalEvent::ACTIVE);
for (const KAEvent& event : events)
{
if (event.actionSubType() == KAEvent::MESSAGE
......
......@@ -308,7 +308,7 @@ bool DisplayCalendar::addEvent(KAEvent& evnt)
{
if (remove)
{
// Adding to mCalendar failed, so undo AlarmCalendar::addEvent()
// Adding to mCalendar failed, so undo DisplayCalendar::addEvent()
mEventMap.remove(event->id());
int i = mEventList.indexOf(event);
if (i >= 0)
......
......@@ -589,7 +589,7 @@ void EditAlarmDlg::initValues(const KAEvent* event)
if (!deferGroupVisible && mDeferGroup)
mDeferGroup->hide();
bool empty = ResourcesCalendar::instance()->events(CalEvent::TEMPLATE).isEmpty();
bool empty = ResourcesCalendar::events(CalEvent::TEMPLATE).isEmpty();
if (mLoadTemplateButton)
mLoadTemplateButton->setEnabled(!empty);
}
......@@ -991,7 +991,7 @@ bool EditAlarmDlg::validate()
errmsg = i18nc("@info", "You must enter a name for the alarm template");
else if (name != mSavedTemplateName)
{
if (ResourcesCalendar::instance()->templateEvent(name).isValid())
if (ResourcesCalendar::templateEvent(name).isValid())
errmsg = i18nc("@info", "Template name is already in use");
}
if (!errmsg.isEmpty())
......
......@@ -247,9 +247,8 @@ UpdateResult addEvent(KAEvent& event, Resource& resource, QWidget* msgParent, in
else
{
// Save the event details in the calendar file, and get the new event ID
ResourcesCalendar* cal = ResourcesCalendar::instance();
// Note that AlarmCalendar::addEvent() updates 'event'.
if (!cal->addEvent(event, resource, msgParent, (options & USE_EVENT_ID), (options & NO_RESOURCE_PROMPT), &cancelled))
// Note that ResourcesCalendar::addEvent() updates 'event'.
if (!ResourcesCalendar::addEvent(event, resource, msgParent, (options & USE_EVENT_ID), (options & NO_RESOURCE_PROMPT), &cancelled))
{
status.status = UPDATE_FAILED;
}
......@@ -299,12 +298,11 @@ UpdateResult addEvents(QVector<KAEvent>& events, Resource& resource, QWidget* ms
}
else
{
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
KAEvent& event = events[i];
if (!cal->addEvent(event, resource, msgParent, false))
if (!ResourcesCalendar::addEvent(event, resource, msgParent, false))
{
status.appendFailed(i);
status.setError(UPDATE_ERROR);
......@@ -342,7 +340,6 @@ bool addArchivedEvent(KAEvent& event, Resource& resource)
bool archiving = (event.category() == CalEvent::ACTIVE);
if (archiving && !Preferences::archivedKeepDays())
return false; // expired alarms aren't being kept
ResourcesCalendar* cal = ResourcesCalendar::instance();
KAEvent newevent(event);
KAEvent* const newev = &newevent;
if (archiving)
......@@ -353,7 +350,7 @@ bool addArchivedEvent(KAEvent& event, Resource& resource)
// Add the event from the archived resource. It's not too important whether
// the resource is saved successfully after the deletion, so allow it to be
// saved automatically.
if (!cal->addEvent(newevent, resource, nullptr, false))
if (!ResourcesCalendar::addEvent(newevent, resource, nullptr, false))
return false;
event = *newev; // update event ID etc.
......@@ -371,9 +368,8 @@ UpdateResult addTemplate(KAEvent& event, Resource& resource, QWidget* msgParent)
UpdateStatusData status;
// Add the template to the calendar file
ResourcesCalendar* cal = ResourcesCalendar::instance();
KAEvent newev(event);
if (!cal->addEvent(newev, resource, msgParent, false))
if (!ResourcesCalendar::addEvent(newev, resource, msgParent, false))
status.status = UPDATE_FAILED;
else
{
......@@ -418,8 +414,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
ResourcesCalendar* cal = ResourcesCalendar::instance();
if (!cal->modifyEvent(oldId, newEvent))
if (!ResourcesCalendar::modifyEvent(oldId, newEvent))
status.status = UPDATE_FAILED;
else
{
......@@ -492,7 +487,6 @@ UpdateResult deleteEvents(QVector<KAEvent>& events, Resource& resource, bool arc
if (events.isEmpty())
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
ResourcesCalendar* cal = ResourcesCalendar::instance();
bool deleteWakeFromSuspendAlarm = false;
const QString wakeFromSuspendId = checkRtcWakeConfig().value(0);
QSet<Resource> resources; // resources which events have been deleted from
......@@ -521,7 +515,7 @@ UpdateResult deleteEvents(QVector<KAEvent>& events, Resource& resource, bool arc
}
}
Resource res = resource;
if (cal->deleteEvent(*event, res, false)) // don't save calendar after deleting
if (ResourcesCalendar::deleteEvent(*event, res, false)) // don't save calendar after deleting
resources.insert(res);
else
status.appendFailed(i);
......@@ -568,7 +562,6 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
if (!count)
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
ResourcesCalendar* cal = ResourcesCalendar::instance();
QSet<Resource> resources; // resources which events have been deleted from
for (int i = 0, end = events.count(); i < end; ++i)
{
......@@ -576,7 +569,7 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
// Delete the template from the calendar file
const KAEvent* event = events[i];
Resource resource;
if (!cal->deleteEvent(*event, resource, false)) // don't save calendar after deleting
if (!ResourcesCalendar::deleteEvent(*event, resource, false)) // don't save calendar after deleting
resources.insert(resource);
else
status.appendFailed(i);
......@@ -644,7 +637,6 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
else
{
int count = 0;
ResourcesCalendar* cal = ResourcesCalendar::instance();
const KADateTime now = KADateTime::currentUtcDateTime();
QVector<KAEvent> eventsToDelete;
for (int i = 0, end = events.count(); i < end; ++i)
......@@ -668,7 +660,7 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
// Save the event details in the calendar file.
// This converts the event ID.
if (!cal->addEvent(newevent, resource, msgParent, true))
if (!ResourcesCalendar::addEvent(newevent, resource, msgParent, true))
{
status.appendFailed(i);
continue;
......@@ -679,7 +671,7 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
status.korgUpdate(st);
}
if (cal->event(EventId(*event)).isValid()) // no error if event doesn't exist in archived resource
if (ResourcesCalendar::event(EventId(*event)).isValid()) // no error if event doesn't exist in archived resource
eventsToDelete.append(*event);
events[i] = newevent;
}
......@@ -701,7 +693,7 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
for (const KAEvent& event : eventsToDelete)
{
Resource res = Resources::resource(event.resourceId());
if (!cal->deleteEvent(event, res, false))
if (!ResourcesCalendar::deleteEvent(event, res, false))
status.setError(UPDATE_ERROR);
}
}
......@@ -722,7 +714,6 @@ UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgPar
if (events.isEmpty())
return UpdateResult(UPDATE_OK);
UpdateStatusData status;
ResourcesCalendar* cal = ResourcesCalendar::instance();
bool deleteWakeFromSuspendAlarm = false;
const QString wakeFromSuspendId = checkRtcWakeConfig().value(0);
QSet<ResourceId> resourceIds; // resources whose events have been updated
......@@ -738,7 +729,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 = ResourcesCalendar::updateEvent(*event);
if (!newev.isValid())
{
qCCritical(KALARM_LOG) << "KAlarm::enableEvents: Error updating event in calendar:" << event->id();
......@@ -747,7 +738,7 @@ UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgPar
else
{
resourceIds.insert(event->resourceId());
cal->disabledChanged(newev);
ResourcesCalendar::disabledChanged(newev);
// If we're disabling a display alarm, close any message window
if (!enable && (event->actionTypes() & KAEvent::ACT_DISPLAY))
......@@ -803,7 +794,7 @@ void purgeArchive(int purgeDays)
const Resource resource = Resources::getStandard(CalEvent::ARCHIVED);
if (!resource.isValid())
return;
QVector<KAEvent> events = ResourcesCalendar::instance()->events(resource);
QVector<KAEvent> events = ResourcesCalendar::events(resource);
for (int i = 0; i < events.count(); )
{
if (purgeDays && events.at(i).createdDateTime().date() >= cutoff)
......@@ -812,7 +803,18 @@ void purgeArchive(int purgeDays)
++i;
}
if (!events.isEmpty())
ResourcesCalendar::instance()->purgeEvents(events); // delete the events and save the calendar
ResourcesCalendar::purgeEvents(events); // delete the events and save the calendar
}
/******************************************************************************
* Return whether an event is read-only.
*/
bool eventReadOnly(const QString& eventId)
{
KAEvent event;
const Resource resource = Resources::resourceForEvent(eventId, event);
return !event.isValid() || event.isReadOnly()
|| !resource.isWritable(event.category());
}
/******************************************************************************
......@@ -1185,7 +1187,7 @@ bool editNewAlarm(const QString& templateName, QWidget* parent)
{
if (!templateName.isEmpty())
{
KAEvent templateEvent = ResourcesCalendar::instance()->templateEvent(templateName);
KAEvent templateEvent = ResourcesCalendar::templateEvent(templateName);
if (templateEvent.isValid())
{
editNewAlarm(&templateEvent, parent);
......@@ -1330,8 +1332,7 @@ namespace
KAlarm::UpdateResult updateEvent(KAEvent& event, KAlarm::UpdateError err, QWidget* msgParent)
{
UpdateStatusData status;
ResourcesCalendar* cal = ResourcesCalendar::instance();
const KAEvent newEvent = cal->updateEvent(event);
const KAEvent newEvent = ResourcesCalendar::updateEvent(event);
if (!newEvent.isValid())
status.status = KAlarm::UPDATE_FAILED;
else
......@@ -1393,7 +1394,7 @@ namespace KAlarm
*/
void editAlarm(KAEvent* event, QWidget* parent)
{
if (event->expired() || ResourcesCalendar::instance()->eventReadOnly(event->id()))
if (event->expired() || eventReadOnly(event->id()))
{
viewAlarm(event, parent);
return;
......@@ -1405,7 +1406,7 @@ void editAlarm(KAEvent* event, QWidget* parent)
AutoQPointer<EditAlarmDlg> editDlg = EditAlarmDlg::create(false, event, false, parent, EditAlarmDlg::RES_USE_EVENT_ID);
if (editDlg && editDlg->exec() == QDialog::Accepted)
{
if (!ResourcesCalendar::instance()->event(id).isValid())
if (!ResourcesCalendar::event(id).isValid())
{
// Event has been deleted while the user was editing the alarm,
// so treat it as a new alarm.
......@@ -1444,7 +1445,7 @@ void editAlarm(KAEvent* event, QWidget* parent)
bool editAlarmById(const EventId& id, QWidget* parent)
{
const QString eventID(id.eventId());
KAEvent event = ResourcesCalendar::instance()->event(id, true);
KAEvent event = ResourcesCalendar::event(id, true);
if (!event.isValid())
{
if (id.resourceId() != -1)
......@@ -1453,7 +1454,7 @@ bool editAlarmById(const EventId& id, QWidget* parent)
qCWarning(KALARM_LOG) << "KAlarm::editAlarmById: Event ID not found:" << eventID;
return false;
}
if (ResourcesCalendar::instance()->eventReadOnly(event.id()))
if (eventReadOnly(event.id()))
{
qCCritical(KALARM_LOG) << "KAlarm::editAlarmById:" << eventID << ": read-only";
return false;
......@@ -1477,7 +1478,7 @@ bool editAlarmById(const EventId& id, QWidget* parent)
*/
void editTemplate(KAEvent* event, QWidget* parent)
{
if (ResourcesCalendar::instance()->eventReadOnly(event->id()))
if (eventReadOnly(event->id()))
{
// The template is read-only, so make the dialogue read-only.
// Use AutoQPointer to guard against crash on application exit while
......@@ -1535,7 +1536,7 @@ void updateEditedAlarm(EditAlarmDlg* editDlg, KAEvent& event, Resource& resource
// Update the displayed lists and the calendar file
UpdateResult status;
if (ResourcesCalendar::instance()->event(EventId(event)).isValid())
if (ResourcesCalendar::event(EventId(event)).isValid())
{
// The old alarm hasn't expired yet, so replace it
const Undo::Event undo(event, resource);
......@@ -1564,7 +1565,7 @@ QVector<KAEvent> templateList()
{
QVector<KAEvent> templates;
const bool includeCmdAlarms = ShellProcess::authorised();
const QVector<KAEvent> events = ResourcesCalendar::instance()->events(CalEvent::TEMPLATE);
const QVector<KAEvent> events = ResourcesCalendar::events(CalEvent::TEMPLATE);
for (const KAEvent& event : events)
{
if (includeCmdAlarms || !(event.actionTypes() & KAEvent::ACT_COMMAND))
......@@ -1624,7 +1625,7 @@ void refreshAlarmsIfQueued()
resource.reload();
// Close any message windows for alarms which are now disabled
const QVector<KAEvent> events = ResourcesCalendar::instance()->events(CalEvent::ACTIVE);
const QVector<KAEvent> events = ResourcesCalendar::events(CalEvent::ACTIVE);
for (const KAEvent& event : events)
{
if (!event.enabled() && (event.actionTypes() & KAEvent::ACT_DISPLAY))
......
......@@ -271,6 +271,11 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
*/
UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgParent = nullptr);
/** Return whether an event is read-only.
* This depends on whether the event or its resource is read-only.
*/
bool eventReadOnly(const QString& eventId);
QVector<KAEvent> getSortedActiveEvents(QObject* parent, AlarmListModel** model = nullptr);
void purgeArchive(int purgeDays); // must only be called from KAlarmApp::processQueue()
......
......@@ -847,7 +847,7 @@ void KAlarmApp::checkNextDueAlarm()
if (!mAlarmsEnabled)
return;
// Find the first alarm due
const KAEvent nextEvent = ResourcesCalendar::instance()->earliestAlarm();
const KAEvent nextEvent = ResourcesCalendar::earliestAlarm();
if (!nextEvent.isValid())
return; // there are no alarms pending
const KADateTime nextDt = nextEvent.nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
......@@ -1694,7 +1694,7 @@ bool KAlarmApp::handleEvent(const EventId& id, QueuedAction action, bool findUni
KAlarm::checkRtcWakeConfig();
const QString eventID(id.eventId());
KAEvent event = ResourcesCalendar::instance()->event(id, findUniqueId);
KAEvent event = ResourcesCalendar::event(id, findUniqueId);
if (!event.isValid())
{
if (id.resourceId() != -1)
......@@ -2170,7 +2170,7 @@ void* KAlarmApp::execAlarm(KAEvent& event, const KAAlarm& alarm, bool reschedule
const int flags = (reschedule ? ProcData::RESCHEDULE : 0) | (allowDefer ? ProcData::ALLOW_DEFER : 0);
if (doShellCommand(command, event, &alarm, (flags | ProcData::PRE_ACTION)))
{
ResourcesCalendar::instance()->setAlarmPending(event);
ResourcesCalendar::setAlarmPending(event);
return result; // display the message after the command completes
}
// Error executing command
......@@ -2546,7 +2546,7 @@ void KAlarmApp::slotCommandExited(ShellProcess* proc)
}
}
if (pd->preAction())
ResourcesCalendar::instance()->setAlarmPending(*pd->event, false);
ResourcesCalendar::setAlarmPending(*pd->event, false);
if (executeAlarm)
execAlarm(*pd->event, *pd->alarm, pd->reschedule(), pd->allowDefer(), true);
mCommandProcesses.removeAt(i);
......@@ -2683,11 +2683,11 @@ void KAlarmApp::setEventCommandError(const KAEvent& event, KAEvent::CmdErrType e
if (err == KAEvent::CMD_ERROR_POST && event.commandError() == KAEvent::CMD_ERROR_PRE)
err = KAEvent::CMD_ERROR_PRE_POST;
event.setCommandError(err);
KAEvent ev = ResourcesCalendar::instance()->event(EventId(event));
KAEvent ev = ResourcesCalendar::event(EventId(event));
if (ev.isValid() && ev.commandError() != err)
{
ev.setCommandError(err);
ResourcesCalendar::instance()->updateEvent(ev);
ResourcesCalendar::updateEvent(ev);
}
Resource resource = Resources::resourceForEvent(event.id());
resource.handleCommandErrorChange(event);
......@@ -2704,12 +2704,12 @@ void KAlarmApp::clearEventCommandError(const KAEvent& event, KAEvent::CmdErrType
KAEvent::CmdErrType newerr = static_cast<KAEvent::CmdErrType>(event.commandError() & ~err);
event.setCommandError(newerr);
KAEvent ev = ResourcesCalendar::instance()->event(EventId(event));
KAEvent ev = ResourcesCalendar::event(EventId(event));
if (ev.isValid())
{
newerr = static_cast<KAEvent::CmdErrType>(ev.commandError() & ~err);
ev.setCommandError(newerr);
ResourcesCalendar::instance()->updateEvent(ev);
ResourcesCalendar::updateEvent(ev);
}
Resource resource = Resources::resourceForEvent(event.id());
resource.handleCommandErrorChange(event);
......
......@@ -1412,16 +1412,15 @@ void MainWindow::slotSelection()
bool enableEnableDisable = true;
bool enableEnable = false;
bool enableDisable = false;
ResourcesCalendar* resources = ResourcesCalendar::instance();
const KADateTime now = KADateTime::currentUtcDateTime();
for (int i = 0; i < count; ++i)
{
const KAEvent ev = resources->event(EventId(events.at(i))); // get up-to-date status
const KAEvent ev = ResourcesCalendar::event(EventId(events.at(i))); // get up-to-date status
const KAEvent& event = ev.isValid() ? ev : events[i];
bool expired = event.expired();
if (!expired)
allArchived = false;
if (resources->eventReadOnly(event.id()))
if (KAlarm::eventReadOnly(event.id()))
readOnly = true;
if (enableReactivate
&& (!expired || !event.occursAfter(now, true)))
......
......@@ -219,7 +219,7 @@ MessageWin::MessageWin(const KAEvent* event, const KAAlarm& alarm, int flags)
mDateTime = alarm.dateTime(true);
if (!(flags & (NO_INIT_VIEW | ALWAYS_HIDE)))
{
const bool readonly = ResourcesCalendar::instance()->eventReadOnly(mEventId.eventId());
const bool readonly = KAlarm::eventReadOnly(mEventId.eventId());
mShowEdit = !mEventId.isEmpty() && !readonly;
mNoDefer = readonly || (flags & NO_DEFER) || alarm.repeatAtLogin();
initView();
......@@ -1073,7 +1073,7 @@ void MessageWin::redisplayAlarm()
qCDebug(KALARM_LOG) << "MessageWin::redisplayAlarm: Deleting duplicate window:" << mEventId;
delete duplicate;
const KAEvent event = ResourcesCalendar::instance()->event(mEventId);
const KAEvent event = ResourcesCalendar::event(mEventId);
if (event.isValid())
{
mEvent = event;
......@@ -1152,7 +1152,7 @@ bool MessageWin::retrieveEvent(KAEvent& event, Resource& resource, bool& showEdi
KAEvent ev;
Resource archiveRes = Resources::getStandard(CalEvent::ARCHIVED);
if (archiveRes.isValid())
ev = ResourcesCalendar::instance()->event(EventId(archiveRes.id(), CalEvent::uid(mEventId.eventId(), CalEvent::ARCHIVED)));
ev = ResourcesCalendar::event(EventId(archiveRes.id(), CalEvent::uid(mEventId.eventId(), CalEvent::ARCHIVED)));
if (!ev.isValid())
return false;
event = ev;
......@@ -1658,7 +1658,7 @@ void MessageWin::repeat(const KAAlarm& alarm)
}
if (mEventId.isEmpty())
return;
KAEvent event = ResourcesCalendar::instance()->event(mEventId);
KAEvent event = ResourcesCalendar::event(mEventId);
if (event.isValid())
{
mAlarmType = alarm.type(); // store new alarm type for use if it is later deferred
......@@ -1678,7 +1678,7 @@ void MessageWin::repeat(const KAAlarm& alarm)
}
}
if (alarmShowing(event))
ResourcesCalendar::instance()->updateEvent(event);
ResourcesCalendar::updateEvent(event);
}
}
......@@ -2156,7 +2156,7 @@ void MessageWin::slotDefer()
// changed since it was displayed.
KAEvent event;
if (!mEventId.isEmpty())
event = ResourcesCalendar::instance()->event(mEventId);
event = ResourcesCalendar::event(mEventId);
if (event.isValid())
{
// The event still exists in the active calendar
......
......@@ -29,7 +29,12 @@
using namespace KAlarmCal;
ResourcesCalendar* ResourcesCalendar::mInstance = nullptr;
ResourcesCalendar* ResourcesCalendar::mInstance {nullptr};
ResourcesCalendar::ResourceMap ResourcesCalendar::mResourceMap;
ResourcesCalendar::EarliestMap ResourcesCalendar::mEarliestAlarm;
QSet<QString> ResourcesCalendar::mPendingAlarms;
bool ResourcesCalendar::mIgnoreAtLogin {false};
bool ResourcesCalendar::mHaveDisabledAlarms {false};
/******************************************************************************
......@@ -250,7 +255,7 @@ void ResourcesCalendar::purgeEvents(const QVector<KAEvent>& events)
deleteEventInternal(event.id(), event, resource, true);
}
if (mHaveDisabledAlarms)
checkForDisabledAlarms();
mInstance->checkForDisabledAlarms();
}
/******************************************************************************
......@@ -315,7 +320,7 @@ bool ResourcesCalendar::addEvent(KAEvent& evnt, Resource& resource, QWidget* pro
// the resource signals eventsAdded().
ok = resource.addEvent(event);
if (ok && type == CalEvent::ACTIVE && !event.enabled())
checkForDisabledAlarms(true, false);
mInstance->checkForDisabledAlarms(true, false);
event.setResourceId(resource.id());
}
if (ok)
......@@ -364,7 +369,7 @@ bool ResourcesCalendar::modifyEvent(const EventId& oldEventId, KAEvent& newEvent
return false;
deleteEventInternal(oldEvent, resource);
if (mHaveDisabledAlarms)
checkForDisabledAlarms();
mInstance->checkForDisabledAlarms();
return true;
}
......@@ -413,7 +418,7 @@ bool ResourcesCalendar::deleteEvent(const KAEvent& event, Resource& resource, bo
qCDebug(KALARM_LOG) << "ResourcesCalendar::deleteEvent:" << event.id();
const CalEvent::Type status = deleteEventInternal(event.id(), event, resource, true);
if (mHaveDisabledAlarms)
checkForDisabledAlarms();
mInstance->checkForDisabledAlarms();
return status != CalEvent::EMPTY;
}
......@@ -440,7 +445,7 @@ CalEvent::Type ResourcesCalendar::deleteEventInternal(const QString& eventID, co
const ResourceId key = resource.id();
mResourceMap[key].remove(eventID);
if (mEarliestAlarm.value(key) == eventID)
findEarliestAlarm(resource);
mInstance->findEarliestAlarm(resource);
CalEvent::Type status = CalEvent::EMPTY;
if (deleteFromResource)
......@@ -503,7 +508,7 @@ KAEvent ResourcesCalendar::templateEvent(const QString& templateName)
/******************************************************************************
* Return all events with the specified ID, from all calendars.
*/
QVector<KAEvent> ResourcesCalendar::events(const QString& uniqueId) const
QVector<KAEvent> ResourcesCalendar::events(const QString& uniqueId)
{
QVector<KAEvent> list;
for (ResourceMap::ConstIterator rit = mResourceMap.constBegin(); rit != mResourceMap.constEnd(); ++rit)
......@@ -514,18 +519,18 @@ QVector<KAEvent> ResourcesCalendar::events(const QString& uniqueId) const
return list;
}
QVector<KAEvent> ResourcesCalendar::events(const Resource& resource, CalEvent::Types type) const
QVector<KAEvent> ResourcesCalendar::events(const Resource& resource, CalEvent::Types type)
{
return events(type, resource);
}
QVector<KAEvent> ResourcesCalendar::events(CalEvent::Types type) const
QVector<KAEvent> ResourcesCalendar::events(CalEvent::Types type)
{
Resource resource;
return events(type, resource);
}
QVector<KAEvent> ResourcesCalendar::events(CalEvent::Types type, const Resource& resource) const
QVector<KAEvent> ResourcesCalendar::events(CalEvent::Types type, const Resource& resource)
{
QVector<KAEvent> list;
if (resource.isValid())
......@@ -559,18 +564,6 @@ QVector<KAEvent> ResourcesCalendar::events(CalEvent::Types type, const Resource&
return list;
}
/******************************************************************************
* Return whether an event is read-only.
* Display calendar events are always returned as read-only.
*/
bool ResourcesCalendar::eventReadOnly(const QString& eventId) const
{
KAEvent event;
const Resource resource = Resources::resourceForEvent(eventId, event);
return !event.isValid() || event.isReadOnly()
|| !resource.isWritable(event.category());
}
/******************************************************************************
* Called when an alarm's enabled status has changed.
*/
......@@ -579,7 +572,7 @@ void ResourcesCalendar::disabledChanged(const KAEvent& event)
if (event.category() == CalEvent::ACTIVE)
{
bool status = event.enabled();
checkForDisabledAlarms(!status, status);
mInstance->checkForDisabledAlarms(!status, status);
}
}
......@@ -677,7 +670,7 @@ KAEvent ResourcesCalendar::earliestAlarm()
{
// Something went wrong: mEarliestAlarm wasn't updated when it should have been!!
qCCritical(KALARM_LOG) << "ResourcesCalendar::earliestAlarm: resource" << eit.key() << "does not contain" << id;
findEarliestAlarm(res);
mInstance->findEarliestAlarm(res);
return earliestAlarm();
}
const KADateTime dt = event.nextTrigger(KAEvent::ALL_TRIGGER).effectiveKDateTime();
......@@ -712,13 +705,13 @@ void ResourcesCalendar::setAlarmPending(const KAEvent& event, bool pending)
mPendingAlarms.remove(id);
}
// Now update the earliest alarm to trigger for its calendar
findEarliestAlarm(Resources::resourceForEvent(event.id()));
mInstance->findEarliestAlarm(Resources::resourceForEvent(event.id()));
}
/******************************************************************************
* Get the events for a list of event IDs.
*/
QVector<KAEvent> ResourcesCalendar::eventsForResource(const Resource& resource, const QSet<QString>& eventIds) const
QVector<KAEvent> ResourcesCalendar::eventsForResource(const Resource& resource, const QSet<QString>& eventIds)
{
QVector<KAEvent> events;
for (const QString& eventId : eventIds)
......
......@@ -41,25 +41,24 @@ class ResourcesCalendar : public QObject
Q_OBJECT
public:
~ResourcesCalendar() override;
KAEvent earliestAlarm();
void setAlarmPending(const KAEvent&, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
void disabledChanged(const KAEvent&);
static KAEvent earliestAlarm();
static void setAlarmPending(const KAEvent&, bool pending = true);
static bool haveDisabledAlarms() { return mHaveDisabledAlarms; }
static void disabledChanged(const KAEvent&);
using QObject::event;
KAEvent event(const EventId& uniqueId, bool findUniqueId = false);
KAEvent templateEvent(const QString& templateName);
QVector<KAEvent> events(const QString& uniqueId) const;
QVector<KAEvent> events(const Resource&, CalEvent::Types = CalEvent::EMPTY) const;
QVector<KAEvent> events(CalEvent::