Branch 'kolab/integration/4.13.0' - 4 commits - resources/imap resources/kolab

Christian Mollekopf mollekopf at kolabsys.com
Fri Oct 31 13:39:13 CET 2014


 resources/imap/resourcestate.cpp                  |   10 +
 resources/imap/resourcestate.h                    |    6 
 resources/imap/resourcestateinterface.h           |    2 
 resources/imap/tests/dummyresourcestate.cpp       |   10 +
 resources/imap/tests/dummyresourcestate.h         |    3 
 resources/kolab/CMakeLists.txt                    |    1 
 resources/kolab/kolabchangeitemsrelationstask.cpp |  154 ++++++++++++++++++++++
 resources/kolab/kolabchangeitemsrelationstask.h   |   55 +++++++
 resources/kolab/kolabresource.cpp                 |   12 +
 resources/kolab/kolabresource.h                   |    4 
 10 files changed, 256 insertions(+), 1 deletion(-)

New commits:
commit 49aa99c3affbb42e78d5a59f15b07ba2f405d985
Merge: 4832b03 1e604f9
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date:   Fri Oct 31 10:42:30 2014 +0100

    Merge remote-tracking branch 'kolab/feature/sync_relations' into kolab/integration/4.13.0

diff --cc resources/kolab/kolabresource.cpp
index ec3b5d9,4af1d34..7c7576e
--- a/resources/kolab/kolabresource.cpp
+++ b/resources/kolab/kolabresource.cpp
@@@ -31,14 -29,16 +31,16 @@@
  #include <KLocalizedString>
  #include <KLocale>
  
- #include "kolabretrievecollectionstask.h"
+ #include "kolabretrievetagstask.h"
  #include "kolabresourcestate.h"
  #include "kolabhelpers.h"
 -#include "settings.h"
 +#include "kolabsettings.h"
  #include "kolabaddtagtask.h"
  #include "kolabchangeitemstagstask.h"
+ #include "kolabchangeitemsrelationstask.h"
  #include "kolabchangetagtask.h"
  #include "kolabremovetagtask.h"
+ #include "kolabretrievecollectionstask.h"
  #include "kolabretrievetagstask.h"
  
  KolabResource::KolabResource(const QString& id)


commit 1e604f996c67dffe1dac01f99acc223a32d22bb3
Author: Aaron Seigo <aseigo at kde.org>
Date:   Tue Oct 28 14:53:11 2014 +0100

    react to changes in relations on items -> sync to server!

diff --git a/resources/kolab/CMakeLists.txt b/resources/kolab/CMakeLists.txt
index 4c410c8..cde197a 100644
--- a/resources/kolab/CMakeLists.txt
+++ b/resources/kolab/CMakeLists.txt
@@ -20,6 +20,7 @@ set(kolabresource_LIB_SRCS
     kolabhelpers.cpp
     kolabmessagehelper.cpp
     kolabaddtagtask.cpp
+    kolabchangeitemsrelationstask.cpp
     kolabchangeitemstagstask.cpp
     kolabchangetagtask.cpp
     kolabrelationresourcetask.cpp
diff --git a/resources/kolab/kolabchangeitemsrelationstask.cpp b/resources/kolab/kolabchangeitemsrelationstask.cpp
new file mode 100644
index 0000000..5348497
--- /dev/null
+++ b/resources/kolab/kolabchangeitemsrelationstask.cpp
@@ -0,0 +1,154 @@
+/*
+    Copyright (c) 2014 Klarälvdalens Datakonsult AB,
+                       a KDAB Group company <info at kdab.com>
+    Author: Kevin Krammer <kevin.krammer at kdab.com>
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This library is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+    License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to the
+    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+*/
+
+#include "kolabchangeitemsrelationstask.h"
+
+#include <imapflags.h>
+#include <kolabobject.h>
+
+#include <kimap/appendjob.h>
+#include <kimap/imapset.h>
+#include <kimap/selectjob.h>
+#include <kimap/session.h>
+#include <kimap/storejob.h>
+
+#include <akonadi/relationfetchjob.h>
+
+KolabChangeItemsRelationsTask::KolabChangeItemsRelationsTask(ResourceStateInterface::Ptr resource, QObject *parent)
+    : KolabRelationResourceTask(resource, parent)
+{
+}
+
+void KolabChangeItemsRelationsTask::startRelationTask(KIMAP::Session *session)
+{
+    mSession = session;
+    mAddedRelations = resourceState()->addedRelations();
+    mRemovedRelations = resourceState()->removedRelations();
+
+    processNextRelation();
+}
+
+void KolabChangeItemsRelationsTask::processNextRelation()
+{
+    Akonadi::Relation relation;
+    if (!mAddedRelations.isEmpty()) {
+        relation = mAddedRelations.takeFirst();
+        mAdding = true;
+    } else if (!mRemovedRelations.isEmpty()) {
+        relation = mRemovedRelations.takeFirst();
+        mAdding = false;
+    } else {
+        changeProcessed();
+        return;
+    }
+
+    //We have to fetch it again in case it changed since the notification was emitted (which is likely)
+    //Otherwise we get an empty remoteid for new tags that were immediately applied on an item
+    Akonadi::RelationFetchJob *fetch = new Akonadi::RelationFetchJob(relation);
+    connect(fetch, SIGNAL(result(KJob*)), this, SLOT(onRelationFetchDone(KJob*)));
+}
+
+void KolabChangeItemsRelationsTask::onRelationFetchDone(KJob *job)
+{
+    if (job->error()) {
+        kWarning() << "RelatonFetch failed: " << job->errorString();
+        processNextRelation();
+        return;
+    }
+
+    const Akonadi::Relation::List relations = static_cast<Akonadi::RelationFetchJob *>(job)->relations();
+    Q_ASSERT(relations.size() == 1);
+    if (relations.size() != 1) {
+        kWarning() << "Invalid number of relations retrieved: " << relations.size();
+        processNextRelation();
+        return;
+    }
+
+    Akonadi::Relation relation = relations.first();
+    if (mAdding) {
+        addRelation(relation);
+    } else {
+        removeRelation(relation);
+    }
+}
+
+void KolabChangeItemsRelationsTask::addRelation(const Akonadi::Relation &relation)
+{
+    const QLatin1String productId("Akonadi-Kolab-Resource");
+    const KMime::Message::Ptr message = Kolab::KolabObjectWriter::writeRelation(relation, Kolab::KolabV3, productId);
+
+    KIMAP::AppendJob *job = new KIMAP::AppendJob(mSession);
+    job->setMailBox(mailBoxForCollection(relationCollection()));
+    job->setContent(message->encodedContent(true));
+    job->setInternalDate(message->date()->dateTime());
+    connect(job, SIGNAL(result(KJob*)), SLOT(onChangeCommitted(KJob*)));
+}
+
+void KolabChangeItemsRelationsTask::removeRelation(const Akonadi::Relation &relation)
+{
+    mCurrentRelation = relation;
+    const QString mailBox = mailBoxForCollection(relationCollection());
+
+    if (mSession->selectedMailBox() != mailBox) {
+        KIMAP::SelectJob *select = new KIMAP::SelectJob(mSession);
+        select->setMailBox(mailBox);
+
+        connect(select, SIGNAL(result(KJob*)), this, SLOT(onSelectDone(KJob*)));
+
+        select->start();
+    } else {
+        triggerStoreJob();
+    }
+}
+
+void KolabChangeItemsRelationsTask::onSelectDone(KJob *job)
+{
+    if (job->error()) {
+        kWarning() << "Failed to select mailbox: " << job->errorString();
+        cancelTask(job->errorString());
+    } else {
+        triggerStoreJob();
+    }
+}
+
+void KolabChangeItemsRelationsTask::triggerStoreJob()
+{
+    KIMAP::ImapSet set;
+    set.add(mCurrentRelation.remoteId().toLong());
+
+    KIMAP::StoreJob *store = new KIMAP::StoreJob(mSession);
+    store->setUidBased(true);
+    store->setSequenceSet(set);
+    store->setFlags(QList<QByteArray>() << ImapFlags::Deleted);
+    store->setMode(KIMAP::StoreJob::AppendFlags);
+    connect(store, SIGNAL(result(KJob*)), SLOT(onChangeCommitted(KJob*)));
+    store->start();
+}
+
+void KolabChangeItemsRelationsTask::onChangeCommitted(KJob *job)
+{
+    if (job->error()) {
+        cancelTask(job->errorString());
+    } else {
+        processNextRelation();
+    }
+}
+
diff --git a/resources/kolab/kolabchangeitemsrelationstask.h b/resources/kolab/kolabchangeitemsrelationstask.h
new file mode 100644
index 0000000..5feda71
--- /dev/null
+++ b/resources/kolab/kolabchangeitemsrelationstask.h
@@ -0,0 +1,55 @@
+/*
+    Copyright (c) 2014 Klarälvdalens Datakonsult AB,
+                       a KDAB Group company <info at kdab.com>
+    Author: Kevin Krammer <kevin.krammer at kdab.com>
+
+    This library is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Library General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    This library is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+    License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to the
+    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+*/
+
+#ifndef KOLABCHANGEITEMSRELATIONSTASK_H
+#define KOLABCHANGEITEMSRELATIONSTASK_H
+
+#include "kolabrelationresourcetask.h"
+
+class KolabChangeItemsRelationsTask : public KolabRelationResourceTask
+{
+    Q_OBJECT
+public:
+    explicit KolabChangeItemsRelationsTask(ResourceStateInterface::Ptr resource, QObject *parent = 0);
+
+protected:
+    virtual void startRelationTask(KIMAP::Session *session);
+
+private Q_SLOTS:
+    void onRelationFetchDone(KJob *job);
+
+    void addRelation(const Akonadi::Relation &relation);
+    void removeRelation(const Akonadi::Relation &relation);
+    void onSelectDone(KJob *job);
+    void triggerStoreJob();
+    void onChangeCommitted(KJob *job);
+
+private:
+    void processNextRelation();
+
+    KIMAP::Session *mSession;
+    Akonadi::Relation::List mAddedRelations;
+    Akonadi::Relation::List mRemovedRelations;
+    Akonadi::Relation mCurrentRelation;
+    bool mAdding;
+};
+
+#endif
diff --git a/resources/kolab/kolabresource.cpp b/resources/kolab/kolabresource.cpp
index 1d80a3c..4af1d34 100644
--- a/resources/kolab/kolabresource.cpp
+++ b/resources/kolab/kolabresource.cpp
@@ -35,8 +35,10 @@
 #include "settings.h"
 #include "kolabaddtagtask.h"
 #include "kolabchangeitemstagstask.h"
+#include "kolabchangeitemsrelationstask.h"
 #include "kolabchangetagtask.h"
 #include "kolabremovetagtask.h"
+#include "kolabretrievecollectionstask.h"
 #include "kolabretrievetagstask.h"
 
 KolabResource::KolabResource(const QString& id)
@@ -184,7 +186,7 @@ void KolabResource::itemsRelationsChanged(const Akonadi::Item::List &items,
                                           const Akonadi::Relation::List &removedRelations)
 {
     qDebug() << "WORKS .. relations added!" << items.count();
-    changeProcessed();
+    KolabChangeItemsRelationsTask *task = new KolabChangeItemsRelationsTask(createResourceState(TaskArguments(items, addedRelations, removedRelations)));
 }
 
 AKONADI_RESOURCE_MAIN( KolabResource )


commit 6cceafa3de57d2a8c8238ce2b70bb3266489c814
Author: Aaron Seigo <aseigo at kde.org>
Date:   Tue Oct 28 14:52:53 2014 +0100

    added and removed relations support in resource state

diff --git a/resources/imap/resourcestate.cpp b/resources/imap/resourcestate.cpp
index 77d8081..b2460c4 100644
--- a/resources/imap/resourcestate.cpp
+++ b/resources/imap/resourcestate.cpp
@@ -170,6 +170,16 @@ QSet<Akonadi::Tag> ResourceState::removedTags() const
     return m_arguments.removedTags;
 }
 
+Akonadi::Relation::List ResourceState::addedRelations() const
+{
+    return m_arguments.addedRelations;
+}
+
+Akonadi::Relation::List ResourceState::removedRelations() const
+{
+    return m_arguments.removedRelations;
+}
+
 QString ResourceState::rootRemoteId() const
 {
   return m_resource->settings()->rootRemoteId();
diff --git a/resources/imap/resourcestate.h b/resources/imap/resourcestate.h
index e615f52..9588be5 100644
--- a/resources/imap/resourcestate.h
+++ b/resources/imap/resourcestate.h
@@ -36,6 +36,7 @@ struct TaskArguments {
     TaskArguments(const Akonadi::Item::List &_items, const QSet<QByteArray> &_addedFlags, const QSet<QByteArray> &_removedFlags): items(_items), addedFlags(_addedFlags), removedFlags(_removedFlags) {}
     TaskArguments(const Akonadi::Item::List &_items, const Akonadi::Collection &_sourceCollection, const Akonadi::Collection &_targetCollection): items(_items), sourceCollection(_sourceCollection), targetCollection(_targetCollection){}
     TaskArguments(const Akonadi::Item::List &_items, const QSet<Akonadi::Tag> &_addedTags, const QSet<Akonadi::Tag> &_removedTags): items(_items), addedTags(_addedTags), removedTags(_removedTags) {}
+    TaskArguments(const Akonadi::Item::List &_items, const Akonadi::Relation::List &_addedRelations, const Akonadi::Relation::List &_removedRelations): items(_items), addedRelations(_addedRelations), removedRelations(_removedRelations) {}
     TaskArguments(const Akonadi::Collection &_collection): collection(_collection){}
     TaskArguments(const Akonadi::Collection &_collection, const Akonadi::Collection &_parentCollection): collection(_collection), parentCollection(_parentCollection){}
     TaskArguments(const Akonadi::Collection &_collection, const Akonadi::Collection &_sourceCollection, const Akonadi::Collection &_targetCollection): collection(_collection), sourceCollection(_sourceCollection), targetCollection(_targetCollection){}
@@ -52,6 +53,8 @@ struct TaskArguments {
     QSet<QByteArray> removedFlags;
     QSet<Akonadi::Tag> addedTags;
     QSet<Akonadi::Tag> removedTags;
+    Akonadi::Relation::List addedRelations;
+    Akonadi::Relation::List removedRelations;
 };
 
 class ResourceState : public ResourceStateInterface
@@ -93,6 +96,9 @@ public:
   virtual QSet<Akonadi::Tag> addedTags() const;
   virtual QSet<Akonadi::Tag> removedTags() const;
 
+  virtual Akonadi::Relation::List addedRelations() const;
+  virtual Akonadi::Relation::List removedRelations() const;
+
   virtual QString rootRemoteId() const;
 
   virtual void setIdleCollection( const Akonadi::Collection &collection );
diff --git a/resources/imap/resourcestateinterface.h b/resources/imap/resourcestateinterface.h
index 2ead8b6..d920199 100644
--- a/resources/imap/resourcestateinterface.h
+++ b/resources/imap/resourcestateinterface.h
@@ -121,6 +121,8 @@ public:
   virtual MessageHelper::Ptr messageHelper() const = 0;
   virtual void tagsRetrieved( const Akonadi::Tag::List &tags, const QHash<QString, Akonadi::Item::List> & ) = 0;
 
+  virtual Akonadi::Relation::List addedRelations() const = 0;
+  virtual Akonadi::Relation::List removedRelations() const = 0;
 };
 
 #endif
diff --git a/resources/imap/tests/dummyresourcestate.cpp b/resources/imap/tests/dummyresourcestate.cpp
index 6dec2ec..0e554e7 100644
--- a/resources/imap/tests/dummyresourcestate.cpp
+++ b/resources/imap/tests/dummyresourcestate.cpp
@@ -240,6 +240,16 @@ QSet<Akonadi::Tag> DummyResourceState::removedTags() const
     return m_removedTags;
 }
 
+Akonadi::Relation::List DummyResourceState::addedRelations() const
+{
+    return Akonadi::Relation::List();
+}
+
+Akonadi::Relation::List DummyResourceState::removedRelations() const
+{
+    return Akonadi::Relation::List();
+}
+
 QString DummyResourceState::rootRemoteId() const
 {
   return QLatin1String("root-id");
diff --git a/resources/imap/tests/dummyresourcestate.h b/resources/imap/tests/dummyresourcestate.h
index 8ef77d6..ba80a4c 100644
--- a/resources/imap/tests/dummyresourcestate.h
+++ b/resources/imap/tests/dummyresourcestate.h
@@ -90,6 +90,9 @@ public:
   void setRemovedTags( const QSet<Akonadi::Tag> &removedTags );
   virtual QSet<Akonadi::Tag> removedTags() const;
 
+  virtual Akonadi::Relation::List addedRelations() const;
+  virtual Akonadi::Relation::List removedRelations() const;
+
   virtual QString rootRemoteId() const;
 
   virtual void setIdleCollection( const Akonadi::Collection &collection );


commit ac10c56e0227c252ab2661c4be458e365e2f9f33
Author: Aaron Seigo <aseigo at kde.org>
Date:   Mon Oct 27 11:32:08 2014 +0100

    stub in relations related functions to the kolab resource

diff --git a/resources/kolab/kolabresource.cpp b/resources/kolab/kolabresource.cpp
index b64b7de..1d80a3c 100644
--- a/resources/kolab/kolabresource.cpp
+++ b/resources/kolab/kolabresource.cpp
@@ -29,7 +29,7 @@
 #include <KLocalizedString>
 #include <KLocale>
 
-#include "kolabretrievecollectionstask.h"
+#include "kolabretrievetagstask.h"
 #include "kolabresourcestate.h"
 #include "kolabhelpers.h"
 #include "settings.h"
@@ -179,4 +179,12 @@ void KolabResource::retrieveTags()
     startTask(task);
 }
 
+void KolabResource::itemsRelationsChanged(const Akonadi::Item::List &items,
+                                          const Akonadi::Relation::List &addedRelations,
+                                          const Akonadi::Relation::List &removedRelations)
+{
+    qDebug() << "WORKS .. relations added!" << items.count();
+    changeProcessed();
+}
+
 AKONADI_RESOURCE_MAIN( KolabResource )
diff --git a/resources/kolab/kolabresource.h b/resources/kolab/kolabresource.h
index 53eaf2b..c418254 100644
--- a/resources/kolab/kolabresource.h
+++ b/resources/kolab/kolabresource.h
@@ -55,6 +55,10 @@ protected:
     virtual void tagRemoved(const Akonadi::Tag &tag);
     virtual void itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags, const QSet<Akonadi::Tag> &removedTags);
 
+    virtual void itemsRelationsChanged(const Akonadi::Item::List &items,
+                                       const Akonadi::Relation::List &addedRelations,
+                                       const Akonadi::Relation::List &removedRelations);
+
     virtual QString defaultName();
 
 private Q_SLOTS:




More information about the commits mailing list