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

Minor fixes and tweaks

parent 9777fa45
......@@ -4,7 +4,7 @@ KAlarm Change Log
+ Add Show/Hide Menubar menu option; change New Email Alarm shortcut to Ctrl-L.
=== Version 2.13.1 (KDE Applications 19.12.1) --- 30 December 2019 ===
+ Make defer dialogue accessible when a full screen window is active.
+ Make defer dialogue accessible when a full screen window is active [KDE Bug 414383]
+ Only show 'Cancel Deferral' in defer dialogue if a deferral is already active.
=== Version 2.13.0 (KDE Applications 19.12) --- 19 November 2019 ===
......
......@@ -401,7 +401,7 @@ void AkonadiDataModel::slotUpdateWorkingHours()
/******************************************************************************
* Reload a collection from Akonadi storage. The backend data is not reloaded.
*/
bool AkonadiDataModel::reload(const Resource& resource)
bool AkonadiDataModel::reload(Resource& resource)
{
if (!resource.isValid())
return false;
......
......@@ -70,7 +70,7 @@ public:
Akonadi::Collection* collection(const Resource&) const;
/** Reload a collection's data from Akonadi storage (not from the backend). */
bool reload(const Resource&);
bool reload(Resource&);
/** Reload all collections' data from Akonadi storage (not from the backend). */
void reload();
......
......@@ -424,17 +424,19 @@ bool AkonadiResource::isPopulated() const
return true;
}
bool AkonadiResource::save(bool writeThroughCache)
bool AkonadiResource::save(bool writeThroughCache, bool force)
{
Q_UNUSED(writeThroughCache);
Q_UNUSED(force);
AgentManager::self()->instance(mCollection.resource()).synchronize();
return true;
}
#if 0
/** Reload the resource. Any cached data is first discarded. */
bool reload() override;
#endif
bool AkonadiResource::reload()
{
// Akonadi provides no means to reload from the backend.
return false;
}
/******************************************************************************
* Add an event to the resource, and add it to Akonadi.
......
......@@ -236,10 +236,8 @@ public:
*/
bool load(bool readThroughCache = true) override;
#if 0
/** Reload the resource. Any cached data is first discarded. */
bool reload() override;
#endif
/** Return whether the resource has fully loaded. */
bool isPopulated() const override;
......@@ -249,7 +247,7 @@ public:
* automatically.
* @return true.
*/
bool save(bool writeThroughCache = true) override;
bool save(bool writeThroughCache = true, bool force = false) override;
/** Add an event to the resource, and add it to Akonadi. */
bool addEvent(const KAEvent&) override;
......
......@@ -250,6 +250,11 @@ bool Resource::load(bool readThroughCache)
return mResource.isNull() ? false : mResource->load(readThroughCache);
}
bool Resource::reload()
{
return mResource.isNull() ? false : mResource->reload();
}
bool Resource::isPopulated() const
{
return mResource.isNull() ? false : mResource->isPopulated();
......
......@@ -293,10 +293,8 @@ public:
*/
bool load(bool readThroughCache = true);
#if 0
/** Reload the resource. Any cached data is first discarded. */
bool reload();
#endif
/** Return whether the resource has fully loaded. */
bool isPopulated() const;
......
......@@ -491,24 +491,17 @@ QString ResourceDataModelBase::tooltip(const Resource& resource, CalEvent::Types
const bool inactive = !(resource.enabledTypes() & types);
const QString readonly = readOnlyTooltip(resource);
const bool writable = readonly.isEmpty();
//TODO: should the above line be = resource.isWritable() ?
const QString disabled = i18nc("@info", "Disabled");
if (inactive && !writable)
return xi18nc("@info:tooltip",
"%1"
"<nl/>%2: <filename>%3</filename>"
"<nl/>%4, %5",
name, type, locn, disabled, readonly);
if (inactive || !writable)
return xi18nc("@info:tooltip",
"%1"
"<nl/>%2: <filename>%3</filename>"
"<nl/>%4",
name, type, locn, (inactive ? disabled : readonly));
"%1"
"<nl/>%2: <filename>%3</filename>"
"<nl/>%4",
name, type, locn, (inactive ? disabled : readonly));
return xi18nc("@info:tooltip",
"%1"
"<nl/>%2: <filename>%3</filename>",
name, type, locn);
"%1"
"<nl/>%2: <filename>%3</filename>",
name, type, locn);
}
/******************************************************************************
......
......@@ -68,32 +68,28 @@ QColor ResourceType::foregroundColour(CalEvent::Types types) const
else
types &= alarmTypes();
//TODO: Should this look for the first writable alarm type?
// Find the highest priority alarm type.
// Note that resources currently only contain a single alarm type.
CalEvent::Type type;
QColor colour; // default to invalid colour
if (types & CalEvent::ACTIVE)
type = CalEvent::ACTIVE;
{
type = CalEvent::ACTIVE;
colour = KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText).color();
}
else if (types & CalEvent::ARCHIVED)
type = CalEvent::ARCHIVED;
{
type = CalEvent::ARCHIVED;
colour = Preferences::archivedColour();
}
else if (types & CalEvent::TEMPLATE)
type = CalEvent::TEMPLATE;
{
type = CalEvent::TEMPLATE;
colour = KColorScheme(QPalette::Active).foreground(KColorScheme::LinkText).color();
}
else
type = CalEvent::EMPTY;
QColor colour;
switch (type)
{
case CalEvent::ACTIVE:
colour = KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText).color();
break;
case CalEvent::ARCHIVED:
colour = Preferences::archivedColour();
break;
case CalEvent::TEMPLATE:
colour = KColorScheme(QPalette::Active).foreground(KColorScheme::LinkText).color();
break;
default:
break;
}
if (colour.isValid() && !isWritable(type))
return KColorUtils::lighten(colour, 0.2);
return colour;
......@@ -236,10 +232,11 @@ void ResourceType::setLoadedEvents(QHash<QString, KAEvent>& newEvents)
* To be called when events have been created or updated, to amend them in the
* resource's list.
*/
void ResourceType::setUpdatedEvents(const QList<KAEvent>& events)
void ResourceType::setUpdatedEvents(const QList<KAEvent>& events, bool notify)
{
const CalEvent::Types types = enabledTypes();
QList<KAEvent> eventsAdded;
mEventsAdded.clear();
mEventsUpdated.clear();
for (const KAEvent& event : events)
{
auto it = mEvents.find(event.id());
......@@ -247,7 +244,7 @@ void ResourceType::setUpdatedEvents(const QList<KAEvent>& events)
{
mEvents[event.id()] = event;
if (event.category() & types)
eventsAdded += event;
mEventsAdded += event;
}
else
{
......@@ -255,11 +252,31 @@ void ResourceType::setUpdatedEvents(const QList<KAEvent>& events)
bool changed = !ev.compare(event, KAEvent::Compare::Id | KAEvent::Compare::CurrentState);
ev = event; // update existing event
if (changed && (event.category() & types))
Resources::notifyEventUpdated(this, event);
{
if (notify)
Resources::notifyEventUpdated(this, event);
else
mEventsUpdated += event;
}
}
}
if (!eventsAdded.isEmpty())
Resources::notifyEventsAdded(this, eventsAdded);
if (notify && !mEventsAdded.isEmpty())
Resources::notifyEventsAdded(this, mEventsAdded);
}
/******************************************************************************
* Notifies added and updated events, after setUpdatedEvents() was called with
* notify = false.
*/
void ResourceType::notifyUpdatedEvents()
{
for (const KAEvent& event : qAsConst(mEventsUpdated))
Resources::notifyEventUpdated(this, event);
mEventsUpdated.clear();
if (!mEventsAdded.isEmpty())
Resources::notifyEventsAdded(this, mEventsAdded);
mEventsAdded.clear();
}
/******************************************************************************
......@@ -281,7 +298,8 @@ void ResourceType::setDeletedEvents(const QList<KAEvent>& events)
eventsToNotify += event;
}
}
Resources::notifyEventsToBeRemoved(this, eventsToNotify);
if (!eventsToNotify.isEmpty())
Resources::notifyEventsToBeRemoved(this, eventsToNotify);
for (const QString& id : eventsToDelete)
mEvents.remove(id);
}
......
......@@ -319,10 +319,8 @@ public:
*/
virtual bool load(bool readThroughCache = true) = 0;
#if 0
/** Reload the resource. Any cached data is first discarded. */
virtual bool reload() = 0;
#endif
/** Return whether the resource has fully loaded.
* Once loading completes after the resource has initialised, this should
......@@ -336,10 +334,12 @@ public:
* if @p writeThroughCache is true, will then be uploaded from the resource file).
* @param writeThroughCache If the resource is cached, update the file
* after writing to the cache.
* @param force Save even if no changes have been made since last
* loaded or saved.
* @return true if saving succeeded or has been initiated.
* false if it failed.
*/
virtual bool save(bool writeThroughCache = true) = 0;
virtual bool save(bool writeThroughCache = true, bool force = false) = 0;
/** Return whether the resource is waiting for a save() to complete. */
virtual bool isSaving() const { return false; }
......@@ -416,9 +416,16 @@ protected:
void setLoadedEvents(QHash<QString, KAEvent>& newEvents);
/** To be called when events have been created or updated, to amend them in
* the resource's list.
* the resource's list.
* @param notify Whether to notify added and updated events; if false,
* notifyUpdatedEvents() must be called afterwards.
*/
void setUpdatedEvents(const QList<KAEvent>& events, bool notify = true);
/** Notify added and updated events, if setUpdatedEvents() was called with
* notify = false.
*/
void setUpdatedEvents(const QList<KAEvent>& events);
void notifyUpdatedEvents();
/** To be called when events have been deleted, to delete them from the resource's list. */
void setDeletedEvents(const QList<KAEvent>& events);
......@@ -440,6 +447,8 @@ private:
static const ResourceType* data(const Resource&);
QHash<QString, KAEvent> mEvents; // all events (of ALL types) in the resource, indexed by ID
QList<KAEvent> mEventsAdded; // events added to mEvents but not yet notified
QList<KAEvent> mEventsUpdated; // events updated in mEvents but not yet notified
ResourceId mId{-1}; // resource's ID, which can't be changed
bool mFailed{false}; // the resource has a fatal error
mutable bool mLoaded{false}; // the resource has finished loading
......
Markdown is supported
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