Commit b4b12c4e authored by Sandro Knauß's avatar Sandro Knauß Committed by Sandro Knauß

sync collectioncolor with vendor/color annotation

Reviewers: bohlender, mollekopf

Maniphest Tasks: T204

Differential Revision: https://git.kolab.org/D68
parent 5139b622
......@@ -59,7 +59,7 @@ set(KDEPIMLIBS_LIB_VERSION "5.2.40")
set(KDEPIMRUNTIME_LIB_VERSION "${KDEPIM_RUNTIME_VERSION_NUMBER}")
set(KDEPIMRUNTIME_LIB_SOVERSION "5")
set(AKONADI_VERSION "5.2.40")
set(AKONADI_VERSION "5.2.41")
set(KCONTACTS_LIB_VERSION "5.2.40")
set(KCALENDARCORE_LIB_VERSION "5.2.40")
......
......@@ -28,6 +28,7 @@
#include <kolabobject.h>
#include <errorhandler.h>
#include <KLocalizedString>
#include <QColor>
#include "tracer.h"
bool KolabHelpers::checkForErrors(const Akonadi::Item &item)
......@@ -426,6 +427,23 @@ void KolabHelpers::setFolderTypeAnnotation(QMap< QByteArray, QByteArray > &annot
annotations["/shared" KOLAB_FOLDER_TYPE_ANNOTATION] = value;
}
QColor KolabHelpers::getFolderColor(const QMap<QByteArray, QByteArray> &annotations)
{
// kolab saves the color without a "#", so we need to add it to the rgb string to have a propper QColor
if (annotations.contains("/shared" KOLAB_COLOR_ANNOTATION) && !annotations.value("/shared" KOLAB_COLOR_ANNOTATION).isEmpty()) {
return QColor(QStringLiteral("#").append(QString::fromUtf8(annotations.value("/shared" KOLAB_COLOR_ANNOTATION))));
} else if (annotations.contains("/private" KOLAB_COLOR_ANNOTATION) && !annotations.value("/private" KOLAB_COLOR_ANNOTATION).isEmpty()) {
return QColor(QStringLiteral("#").append(QString::fromUtf8(annotations.value("/private" KOLAB_COLOR_ANNOTATION))));
}
return QColor();
}
void KolabHelpers::setFolderColor(QMap<QByteArray, QByteArray> &annotations, const QColor &color)
{
// kolab saves the color without a "#", so we need to delete the prefix "#" if we save it to the annotations
annotations["/shared" KOLAB_COLOR_ANNOTATION] = color.name().toAscii().remove(0,1);
}
QString KolabHelpers::getIcon(Kolab::FolderType type)
{
switch (type) {
......
......@@ -24,6 +24,10 @@
#include <kolabdefinitions.h> //libkolab
#include <formathelpers.h> //libkolab
#define KOLAB_COLOR_ANNOTATION "/vendor/kolab/color"
class QColor;
class KolabHelpers
{
public:
......@@ -34,6 +38,8 @@ public:
static Kolab::FolderType folderTypeFromString(const QByteArray &folderTypeName);
static QByteArray getFolderTypeAnnotation(const QMap<QByteArray, QByteArray> &annotations);
static void setFolderTypeAnnotation(QMap<QByteArray, QByteArray> &annotations, const QByteArray &value);
static QColor getFolderColor(const QMap<QByteArray, QByteArray> &annotations);
static void setFolderColor(QMap<QByteArray, QByteArray> &annotations, const QColor &color);
static Kolab::ObjectType getKolabTypeFromMimeType(const QString &type);
static QByteArray kolabTypeForMimeType(const QStringList &contentMimeTypes);
static QStringList getContentMimeTypes(Kolab::FolderType type);
......
......@@ -26,6 +26,8 @@
#include <retrieveitemstask.h>
#include <collectionannotationsattribute.h>
#include <changecollectiontask.h>
#include <AkonadiCore/AttributeFactory>
#include <AkonadiCore/CollectionColorAttribute>
#include <akonadi/calendar/blockalarmsattribute.h>
#include <KWindowSystem>
......@@ -48,6 +50,7 @@
KolabResource::KolabResource(const QString &id)
: ImapResource(id)
{
Akonadi::AttributeFactory::registerAttribute<Akonadi::CollectionColorAttribute>();
//Ensure we have up-to date metadata before attempting to sync folder
setScheduleAttributeSyncBeforeItemSync(true);
setKeepLocalCollectionChanges(QSet<QByteArray>() << "ENTITYDISPLAY" << Akonadi::BlockAlarmsAttribute().type());
......@@ -147,11 +150,26 @@ static Akonadi::Collection updateAnnotations(const Akonadi::Collection &collecti
Trace() << collection.id();
//Set the annotations on new folders
const QByteArray kolabType = KolabHelpers::kolabTypeForMimeType(collection.contentMimeTypes());
Akonadi::Collection col = collection;
Akonadi::CollectionAnnotationsAttribute *attr = col.attribute<Akonadi::CollectionAnnotationsAttribute>(Akonadi::Collection::AddIfMissing);
QMap<QByteArray, QByteArray> annotations = attr->annotations();
bool changed = false;
Akonadi::CollectionColorAttribute *colorAttribute = col.attribute<Akonadi::CollectionColorAttribute>();
if (colorAttribute) {
const QColor color = colorAttribute->color();
if (color.isValid()) {
KolabHelpers::setFolderColor(annotations, color);
changed = true;
}
}
if (!kolabType.isEmpty()) {
Akonadi::Collection col = collection;
Akonadi::CollectionAnnotationsAttribute *attr = col.attribute<Akonadi::CollectionAnnotationsAttribute>(Akonadi::Collection::AddIfMissing);
QMap<QByteArray, QByteArray> annotations = attr->annotations();
KolabHelpers::setFolderTypeAnnotation(annotations, kolabType);
changed = true;
}
if (changed) {
attr->setAnnotations(annotations);
return col;
}
......@@ -171,11 +189,16 @@ void KolabResource::collectionAdded(const Akonadi::Collection &collection, const
void KolabResource::collectionChanged(const Akonadi::Collection &collection, const QSet< QByteArray > &parts)
{
Trace() << collection.id() << parts;
QSet<QByteArray> p = parts;
//Update annotations if necessary
const Akonadi::Collection col = updateAnnotations(collection);
if(parts.contains(Akonadi::CollectionColorAttribute().type())) {
p << Akonadi::CollectionAnnotationsAttribute().type();
}
//TODO we need to save the collections as well if the annotations have changed
emit status(AgentBase::Running, i18nc("@info:status", "Updating folder '%1'", collection.name()));
ChangeCollectionTask *task = new ChangeCollectionTask(createResourceState(TaskArguments(collection, parts)), this);
ChangeCollectionTask *task = new ChangeCollectionTask(createResourceState(TaskArguments(collection, p)), this);
task->syncEnabledState(true);
startTask(task);
}
......
......@@ -35,6 +35,7 @@
#include <AkonadiCore/CachePolicy>
#include <AkonadiCore/EntityDisplayAttribute>
#include <AkonadiCore/CollectionColorAttribute>
#include <akonadi/kmime/messageparts.h>
#include <AkonadiCore/CollectionIdentificationAttribute>
#include <akonadi/calendar/blockalarmsattribute.h>
......@@ -43,6 +44,8 @@
#include <kmime/kmime_message.h>
#include <KLocalizedString>
#include <QColor>
static bool isNamespaceFolder(const QString &path, const QList<KIMAP::MailBoxDescriptor> &namespaces, bool matchCompletePath = false)
{
Q_FOREACH (const KIMAP::MailBoxDescriptor &desc, namespaces) {
......@@ -195,6 +198,8 @@ KolabRetrieveCollectionsTask::KolabRetrieveCollectionsTask(ResourceStateInterfac
{
mRequestedMetadata << "/shared/vendor/kolab/folder-type";
mRequestedMetadata << "/private/vendor/kolab/folder-type";
mRequestedMetadata << "/shared" KOLAB_COLOR_ANNOTATION
<< "/private" KOLAB_COLOR_ANNOTATION;
}
KolabRetrieveCollectionsTask::~KolabRetrieveCollectionsTask()
......@@ -479,6 +484,10 @@ void KolabRetrieveCollectionsTask::applyMetadata(QHash<QString, QMap<QByteArray,
const QByteArray type = KolabHelpers::getFolderTypeAnnotation(metadata);
const Kolab::FolderType folderType = KolabHelpers::folderTypeFromString(type);
collection.setContentMimeTypes(KolabHelpers::getContentMimeTypes(folderType));
const QColor color = KolabHelpers::getFolderColor(metadata);
if (color.isValid()) {
collection.attribute<Akonadi::CollectionColorAttribute>(Akonadi::Collection::AddIfMissing)->setColor(color);
}
QSet<QByteArray> keepLocalChanges = collection.keepLocalChanges();
keepLocalChanges.remove(cContentMimeTypes);
collection.setKeepLocalChanges(keepLocalChanges);
......
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