Changeset View
Changeset View
Standalone View
Standalone View
resources/kolab/kolabresource.cpp
Show All 19 Lines | |||||
#include "kolabresource.h" | #include "kolabresource.h" | ||||
#include "setupserver.h" | #include "setupserver.h" | ||||
#include <resourcestateinterface.h> | #include <resourcestateinterface.h> | ||||
#include <resourcestate.h> | #include <resourcestate.h> | ||||
#include <retrieveitemstask.h> | #include <retrieveitemstask.h> | ||||
#include <collectionannotationsattribute.h> | #include <collectionannotationsattribute.h> | ||||
#include <changecollectiontask.h> | #include <changecollectiontask.h> | ||||
#include <akonadi/attributefactory.h> | |||||
#include <akonadi/collectioncolorattribute.h> | |||||
#include <akonadi/calendar/blockalarmsattribute.h> | #include <akonadi/calendar/blockalarmsattribute.h> | ||||
#include <KWindowSystem> | #include <KWindowSystem> | ||||
#include <KLocalizedString> | #include <KLocalizedString> | ||||
#include <KLocale> | #include <KLocale> | ||||
#include "kolabretrievetagstask.h" | #include "kolabretrievetagstask.h" | ||||
#include "kolabresourcestate.h" | #include "kolabresourcestate.h" | ||||
#include "kolabhelpers.h" | #include "kolabhelpers.h" | ||||
#include "kolabsettings.h" | #include "kolabsettings.h" | ||||
#include "kolabaddtagtask.h" | #include "kolabaddtagtask.h" | ||||
#include "kolabchangeitemstagstask.h" | #include "kolabchangeitemstagstask.h" | ||||
#include "kolabchangeitemsrelationstask.h" | #include "kolabchangeitemsrelationstask.h" | ||||
#include "kolabchangetagtask.h" | #include "kolabchangetagtask.h" | ||||
#include "kolabremovetagtask.h" | #include "kolabremovetagtask.h" | ||||
#include "kolabretrievecollectionstask.h" | #include "kolabretrievecollectionstask.h" | ||||
#include "kolabretrievetagstask.h" | #include "kolabretrievetagstask.h" | ||||
#include "tracer.h" | #include "tracer.h" | ||||
KolabResource::KolabResource(const QString& id) | KolabResource::KolabResource(const QString& id) | ||||
:ImapResource(id) | :ImapResource(id) | ||||
{ | { | ||||
Akonadi::AttributeFactory::registerAttribute<Akonadi::CollectionColorAttribute>(); | |||||
//Load translations from imap resource | //Load translations from imap resource | ||||
KGlobal::locale()->insertCatalog(QLatin1String("akonadi_imap_resource")); | KGlobal::locale()->insertCatalog(QLatin1String("akonadi_imap_resource")); | ||||
//Ensure we have up-to date metadata before attempting to sync folder | //Ensure we have up-to date metadata before attempting to sync folder | ||||
setScheduleAttributeSyncBeforeItemSync(true); | setScheduleAttributeSyncBeforeItemSync(true); | ||||
setKeepLocalCollectionChanges(QSet<QByteArray>() << "ENTITYDISPLAY" << Akonadi::BlockAlarmsAttribute().type()); | setKeepLocalCollectionChanges(QSet<QByteArray>() << "ENTITYDISPLAY" << Akonadi::BlockAlarmsAttribute().type()); | ||||
} | } | ||||
KolabResource::~KolabResource() | KolabResource::~KolabResource() | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | void KolabResource::itemsMoved(const Akonadi::Item::List& items, const Akonadi::Collection& source, const Akonadi::Collection& destination) | ||||
ImapResource::itemsMoved(imapItems, source, destination); | ImapResource::itemsMoved(imapItems, source, destination); | ||||
} | } | ||||
static Akonadi::Collection updateAnnotations(const Akonadi::Collection &collection) | static Akonadi::Collection updateAnnotations(const Akonadi::Collection &collection) | ||||
{ | { | ||||
Trace() << collection.id(); | Trace() << collection.id(); | ||||
//Set the annotations on new folders | //Set the annotations on new folders | ||||
const QByteArray kolabType = KolabHelpers::kolabTypeForMimeType(collection.contentMimeTypes()); | const QByteArray kolabType = KolabHelpers::kolabTypeForMimeType(collection.contentMimeTypes()); | ||||
if (!kolabType.isEmpty()) { | |||||
Akonadi::Collection col = collection; | Akonadi::Collection col = collection; | ||||
Akonadi::CollectionAnnotationsAttribute *attr = col.attribute<Akonadi::CollectionAnnotationsAttribute>(Akonadi::Collection::AddIfMissing); | Akonadi::CollectionAnnotationsAttribute *attr = col.attribute<Akonadi::CollectionAnnotationsAttribute>(Akonadi::Collection::AddIfMissing); | ||||
QMap<QByteArray, QByteArray> annotations = attr->annotations(); | 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()) { | |||||
KolabHelpers::setFolderTypeAnnotation(annotations, kolabType); | KolabHelpers::setFolderTypeAnnotation(annotations, kolabType); | ||||
changed = true; | |||||
} | |||||
if (changed) { | |||||
mollekopf: Doesn't this mean we don't set the folder type annotation on new folders if they don't have a… | |||||
knaussAuthorUnsubmitted Not Done Inline ActionsYes, but this was the behaviour before, too. The comple logic was in a "if (!kolabType.isEmpty()) { " (l151). Now the annotations are pushed, if either the kolabType is set or there is a foldercolor. Or do you mean we should not push the color to the server without kolabType set? knauss: Yes, but this was the behaviour before, too. The comple logic was in a "if (!kolabType.isEmpty… | |||||
attr->setAnnotations(annotations); | attr->setAnnotations(annotations); | ||||
return col; | return col; | ||||
} | } | ||||
return collection; | return collection; | ||||
} | } | ||||
void KolabResource::collectionAdded(const Akonadi::Collection& collection, const Akonadi::Collection& parent) | void KolabResource::collectionAdded(const Akonadi::Collection& collection, const Akonadi::Collection& parent) | ||||
{ | { | ||||
Trace() << collection.id() << parent.id(); | Trace() << collection.id() << parent.id(); | ||||
//Set the annotations on new folders | //Set the annotations on new folders | ||||
const Akonadi::Collection col = updateAnnotations(collection); | const Akonadi::Collection col = updateAnnotations(collection); | ||||
//TODO we need to save the collections as well if the annotations have changed | //TODO we need to save the collections as well if the annotations have changed | ||||
//or we simply don't have the annotations locally, which perhaps is also not required? | //or we simply don't have the annotations locally, which perhaps is also not required? | ||||
ImapResource::collectionAdded(col, parent); | ImapResource::collectionAdded(col, parent); | ||||
} | } | ||||
void KolabResource::collectionChanged(const Akonadi::Collection& collection, const QSet< QByteArray >& parts) | void KolabResource::collectionChanged(const Akonadi::Collection& collection, const QSet< QByteArray >& parts) | ||||
{ | { | ||||
Trace() << collection.id() << parts; | Trace() << collection.id() << parts; | ||||
QSet<QByteArray> p = parts; | |||||
//Update annotations if necessary | //Update annotations if necessary | ||||
const Akonadi::Collection col = updateAnnotations(collection); | 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 | //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() ) ); | 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); | task->syncEnabledState(true); | ||||
startTask(task); | startTask(task); | ||||
} | } | ||||
void KolabResource::tagAdded(const Akonadi::Tag &tag) | void KolabResource::tagAdded(const Akonadi::Tag &tag) | ||||
{ | { | ||||
Trace() << tag.id(); | Trace() << tag.id(); | ||||
KolabAddTagTask *task = new KolabAddTagTask(createResourceState(TaskArguments(tag)), this); | KolabAddTagTask *task = new KolabAddTagTask(createResourceState(TaskArguments(tag)), this); | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
Doesn't this mean we don't set the folder type annotation on new folders if they don't have a color?
So changed would also have to be true on !kolabType.isEmpty()