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

When a resource is re-enabled, ensure its alarms are displayed

If the user disabled and then re-enabled a resource, its alarms were
not re-displayed in the alarm list.
parent 3d723001
Pipeline #160368 passed with stage
in 3 minutes and 49 seconds
KAlarm Change Log
=== Version 3.4.0 (KDE Gear 22.04) --- 10 March 2022 ===
=== Version 3.4.0 (KDE Gear 22.04) --- 6 April 2022 ===
* Allow calendars and date picker to be shown together in side panel [KDE Bug 440250]
* Shrink calendar list to remove empty space when too large.
* When a resource is re-enabled, ensure its alarms are displayed.
* Cancel sound file playback if audio alarm edit dialogue is closed after clicking Try.
* Remove all 'speak' functions if KAlarm is built with text-to-speech disabled.
* Add option to disable wake-from-suspend alarms if KAlarm is built without KAuth.
......
......@@ -352,6 +352,7 @@ bool FileResource::load(bool readThroughCache)
if (!errorMessage.isEmpty())
Resources::notifyResourceMessage(this, MessageType::Error, xi18nc("@info", "Error loading calendar <resource>%1</resource>.", displayName()), errorMessage);
setNewlyEnabled(false);
return false;
}
......@@ -685,6 +686,7 @@ void FileResource::handleSettingsChange(Changes& changes)
// types, changes are not processed when disabled calendar files
// are updated. Also, when the calendar is loaded, disabled alarm
// types are not fully processed by loaded().
setNewlyEnabled(); // ensure all events are notified
load();
changes |= Loaded;
}
......
/*
* resourcetype.cpp - base class for an alarm calendar resource type
* Program: kalarm
* SPDX-FileCopyrightText: 2019-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2019-2022 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -191,6 +191,7 @@ void ResourceType::setLoadedEvents(QHash<QString, KAEvent>& newEvents)
// longer exist.
QStringList eventsToDelete;
QList<KAEvent> eventsToNotifyDelete;
QList<KAEvent> eventsToNotifyNewlyEnabled; // only if mNewlyEnabled is true
for (auto it = mEvents.begin(); it != mEvents.end(); ++it)
{
const QString& id = it.key();
......@@ -208,6 +209,8 @@ void ResourceType::setLoadedEvents(QHash<QString, KAEvent>& newEvents)
event = newit.value(); // update existing event
event.setResourceId(mId);
newEvents.erase(newit);
if (mNewlyEnabled)
eventsToNotifyNewlyEnabled << event;
if (changed && (event.category() & types))
Resources::notifyEventUpdated(this, event);
}
......@@ -231,10 +234,11 @@ void ResourceType::setLoadedEvents(QHash<QString, KAEvent>& newEvents)
else
newit = newEvents.erase(newit); // remove disabled event from notification list
}
if (!newEvents.isEmpty())
Resources::notifyEventsAdded(this, newEvents.values());
if (!newEvents.isEmpty() || !eventsToNotifyNewlyEnabled.isEmpty())
Resources::notifyEventsAdded(this, newEvents.values() + eventsToNotifyNewlyEnabled);
newEvents.clear();
mNewlyEnabled = false;
setLoaded(true);
}
......
......@@ -457,6 +457,12 @@ protected:
/** To be called when the loaded status of the resource has changed. */
void setLoaded(bool loaded) const;
/** Mark the resource as being newly enabled, so that all its events
* will be notified by setLoadedEvents() even if they already exist.
* The flag is reset by setLoadedEvents() on completion.
*/
void setNewlyEnabled(bool enabled = true) { mNewlyEnabled = enabled; }
/** To be called if the resource has encountered a fatal error.
* A fatal error is one that can never be recovered from.
*/
......@@ -484,6 +490,7 @@ private:
bool mInError {false}; // the resource has a non-fatal error
mutable bool mLoaded {false}; // the resource has finished loading
bool mBeingDeleted {false}; // the resource is currently being deleted
bool mNewlyEnabled {false}; // the resource is being enabled, so notify all events
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceType::Changes)
......
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