Commit 4aca027e authored by David Jarvie's avatar David Jarvie

Alter priority for removing duplicate Akonadi resources

Give priority to keeping enabled, standard, resources.
parent 4658689a
Pipeline #44445 passed with stage
in 12 minutes and 37 seconds
KAlarm Change Log
=== Version 3.1.1 (KDE Applications 20.12.1) --- 16 December 2020 ===
=== Version 3.1.1 (KDE Applications 20.12.1) --- 18 December 2020 ===
* Ensure that build uses the file resources option.
* When removing duplicate Akonadi resources, in priority keep enabled/standard ones.
* Fix regression introduced in version 3.1.0:
Show correct alarm columns in main window on first run of KAlarm.
......
......@@ -34,6 +34,20 @@ using namespace Akonadi;
namespace
{
// Holds an Akonadi Collection's properties.
struct CollectionProperties
{
QColor backgroundColour;
CalEvent::Types alarmTypes;
CalEvent::Types enabledTypes {CalEvent::EMPTY};
CalEvent::Types standardTypes {CalEvent::EMPTY};
bool readOnly;
// Fetch the properties of a Collection which has been fetched by CollectionFetchJob.
CollectionProperties(const Collection&);
};
const Collection::Rights WritableRights = Collection::CanChangeItem | Collection::CanCreateItem | Collection::CanDeleteItem;
const QRegularExpression MatchMimeType(QStringLiteral("^application/x-vnd\\.kde\\.alarm.*"),
......@@ -65,10 +79,10 @@ private:
struct ResourceCol
{
QString resourceId; // Akonadi resource identifier
ResourceId collectionId; // Akonadi collection ID
Collection collection; // Akonadi collection
ResourceCol() {}
ResourceCol(const QString& r, ResourceId c)
: resourceId(r), collectionId(c) {}
ResourceCol(const QString& r, const Collection& c)
: resourceId(r), collection(c) {}
};
QHash<QString, ResourceCol> mAgentPaths; // path, (resource identifier, collection ID) pairs
void (*mCompletionFunc)() {nullptr}; // function to call on completion
......@@ -597,14 +611,25 @@ void DuplicateResourceObject::collectionFetchResult(KJob* j)
{
if (c.contentMimeTypes().indexOf(MatchMimeType) >= 0)
{
ResourceCol thisRes(job->fetchScope().resource(), c.id());
ResourceCol thisRes(job->fetchScope().resource(), c);
auto it = mAgentPaths.constFind(c.remoteId());
if (it != mAgentPaths.constEnd())
{
// Remove the resource containing the higher numbered Collection
// ID, which is likely to be the more recently created.
// Remove the resource which, in decreasing order of priority:
// - Is disabled;
// - Is not a standard resource;
// - Contains the higher numbered Collection ID, which is likely
// to be the more recently created.
const ResourceCol prevRes = it.value();
if (thisRes.collectionId > prevRes.collectionId)
const CollectionProperties properties[2] = { CollectionProperties(prevRes.collection),
CollectionProperties(thisRes.collection) };
int propToUse = (thisRes.collection.id() < prevRes.collection.id()) ? 1 : 0;
if (properties[1 - propToUse].standardTypes && !properties[propToUse].standardTypes)
propToUse = 1 - propToUse;
if (properties[1 - propToUse].enabledTypes && !properties[propToUse].enabledTypes)
propToUse = 1 - propToUse;
if (propToUse == 0)
{
qCWarning(KALARM_LOG) << "AkonadiResource::collectionFetchResult: Removing duplicate resource" << thisRes.resourceId;
agentManager->removeInstance(agentManager->instance(thisRes.resourceId));
......@@ -967,6 +992,27 @@ void AkonadiResource::modifyCollectionAttrJobDone(KJob* j)
}
}
namespace
{
/******************************************************************************
* Fetch an Akonadi collection's properties.
*/
CollectionProperties::CollectionProperties(const Collection& collection)
{
readOnly = (collection.rights() & WritableRights) != WritableRights;
alarmTypes = CalEvent::types(collection.contentMimeTypes());
if (collection.hasAttribute<CollectionAttribute>())
{
const auto* attr = collection.attribute<CollectionAttribute>();
enabledTypes = attr->enabled() & alarmTypes;
standardTypes = attr->standard() & enabledTypes;
backgroundColour = attr->backgroundColor();
}
}
}
#include "akonadiresource.moc"
// vim: et sw=4:
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