Commit 89938bdc authored by David Faure's avatar David Faure
Browse files

EventViews::setResourceColor: modify the Akonadi::CollectionColorAttribute in the collection

This gives a chance to the resource to store the color server side
(implemented for DAV).

This commit improves upon D7500 (1ec2e08a) which only implemented reading
from the attribute.

Test Plan:
(after implementing saving in the dav resource) changing a calendar color
in korganizer now propagates to the server, F5 in roundcube and the new color appears.
This helps when using multiple computers, or when the dav resource temporarily forgets
about all folder (ahem).

Reviewers: dvratil, ochurlaud

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision:
parent 2f4406e2
......@@ -22,11 +22,13 @@
#include "helper.h"
#include "prefs.h"
#include "calendarview_debug.h"
#include <Collection>
#include <Item>
#include <AkonadiCore/CollectionColorAttribute>
#include <AkonadiCore/CollectionModifyJob>
#include <QIcon>
#include <QPixmap>
......@@ -49,15 +51,20 @@ void EventViews::setResourceColor(const Akonadi::Collection &coll, const QColor
const QString id = QString::number(;
if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) {
const Akonadi::CollectionColorAttribute *colorAttr
= coll.attribute<Akonadi::CollectionColorAttribute>();
if (colorAttr && colorAttr->color().isValid() && (colorAttr->color() == color)) {
// It's the same color: we save an invalid color
preferences->setResourceColor(id, QColor());
// Save the color in akonadi (so the resource can even save it server-side)
Akonadi::Collection collection = coll;
Akonadi::CollectionColorAttribute *colorAttr
= collection.attribute<Akonadi::CollectionColorAttribute>(Akonadi::Collection::AddIfMissing);
Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob(collection, nullptr);
QObject::connect(job, &Akonadi::CollectionModifyJob::result, [=]() {
if (job->error()) {
qCWarning(CALENDARVIEW_LOG) << "Failed to set CollectionColorAttribute:" << job->errorString();
// in all other cases, we save the resourceColor
// Also save the color in eventviewsrc (mostly historical)
preferences->setResourceColor(id, color);
......@@ -73,8 +73,8 @@ Q_REQUIRED_RESULT EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Item &in
Q_REQUIRED_RESULT EVENTVIEWS_EXPORT QColor resourceColor(const Akonadi::Collection &collection, const PrefsPtr &preferences);
This method sets the resource color in the preferences, only if it is
different from the CollectionColorAttribute. It is preferred to use this
This method sets the resource color as an Akonadi collection attribute and
in the local preferences. It is preferred to use this
instead of the EventViews::Prefs::setResourceColor function.
@param collection the collection for which the resource color should be stored
@param color the color to stored
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