summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Jarvie <djarvie@kde.org>2012-02-12 17:24:39 (GMT)
committerDavid Jarvie <djarvie@kde.org>2012-02-15 22:45:23 (GMT)
commitcd37be53796388dac990f2c5cd64731900bf5b50 (patch)
treed3fbfdebbd1fac9a97f053673f9e23ab6ae97e2b
parentfc34101c8a56178c3648e6d327db487d12035c1e (diff)
Prevent multiple standard calendars for any alarm type
When a new collection was added, it was possible for it to be marked as standard in addition to the existing standard collection for an alarm type. Backport of e3060ed30659230eede752a66700bed5e8cea207 (master)
-rw-r--r--kalarm/Changelog1
-rw-r--r--kalarm/collectionmodel.cpp41
2 files changed, 40 insertions, 2 deletions
diff --git a/kalarm/Changelog b/kalarm/Changelog
index 53d778e..8c5eb18 100644
--- a/kalarm/Changelog
+++ b/kalarm/Changelog
@@ -5,6 +5,7 @@ KAlarm Change Log
- [Akonadi] Prevent duplicate prompts to update format of new calendar resource.
- [Akonadi] Automatically disable duplicated calendar resources.
- [Akonadi] Fix errors when creating default calendar resources.
+- [Akonadi] Prevent multiple standard calendars for any alarm type.
- Output cmake error if Akonadi option incompatible with kdepimlibs/kalarmcal.
=== Version 2.8.0 (KDE 4.8.0) --- 16 January 2012 ===
diff --git a/kalarm/collectionmodel.cpp b/kalarm/collectionmodel.cpp
index 57a0c55..f6c415f 100644
--- a/kalarm/collectionmodel.cpp
+++ b/kalarm/collectionmodel.cpp
@@ -735,6 +735,8 @@ CalEvent::Types CollectionControlModel::setEnabled(const Collection& collection,
CalEvent::Types CollectionControlModel::setEnabledStatus(const Collection& collection, CalEvent::Types types, bool inserted)
{
kDebug() << "id:" << collection.id() << ", types=" << types;
+ CalEvent::Types disallowedStdTypes(0);
+ CalEvent::Types stdTypes(0);
// Prevent the enabling of duplicate alarm types if another collection
// uses the same backend storage.
@@ -755,17 +757,52 @@ CalEvent::Types CollectionControlModel::setEnabledStatus(const Collection& colle
}
}
if (!inList)
+ {
+ // It's a new collection.
+ // Prevent duplicate standard collections being created for any alarm type.
+ stdTypes = collection.hasAttribute<CollectionAttribute>()
+ ? collection.attribute<CollectionAttribute>()->standard()
+ : CalEvent::EMPTY;
+ if (stdTypes)
+ {
+ foreach (const Collection& col, cols)
+ {
+ Collection c(col);
+ AkonadiModel::instance()->refresh(c); // update with latest data
+ if (c.isValid())
+ {
+ CalEvent::Types t = stdTypes & CalEvent::types(c.contentMimeTypes());
+ if (t)
+ {
+ if (c.hasAttribute<CollectionAttribute>()
+ && AkonadiModel::isCompatible(c))
+ {
+ disallowedStdTypes |= c.attribute<CollectionAttribute>()->standard() & t;
+ if (disallowedStdTypes == stdTypes)
+ break;
+ }
+ }
+ }
+ }
+ }
addCollection(collection);
+ }
}
else
removeCollection(collection);
- if (!inserted || canEnable != types)
+ if (disallowedStdTypes || !inserted || canEnable != types)
{
// Update the collection's status
AkonadiModel* model = static_cast<AkonadiModel*>(sourceModel());
if (!model->isCollectionBeingDeleted(collection.id()))
- model->setData(model->collectionIndex(collection), static_cast<int>(canEnable), AkonadiModel::EnabledTypesRole);
+ {
+ QModelIndex ix = model->collectionIndex(collection);
+ if (!inserted || canEnable != types)
+ model->setData(ix, static_cast<int>(canEnable), AkonadiModel::EnabledTypesRole);
+ if (disallowedStdTypes)
+ model->setData(ix, static_cast<int>(stdTypes & ~disallowedStdTypes), AkonadiModel::IsStandardRole);
+ }
}
return canEnable;
}