Branch 'kolab/integration/4.13.0' - 2 commits - resources/imap resources/kolab
Christian Mollekopf
mollekopf at kolabsys.com
Sun Oct 19 19:25:42 CEST 2014
resources/imap/imapresourcebase.cpp | 54 +++---------------------------------
resources/imap/imapresourcebase.h | 5 ---
resources/imap/resourcestate.cpp | 12 +-------
resources/kolab/kolabresource.cpp | 49 +-------------------------------
resources/kolab/kolabresource.h | 2 -
5 files changed, 10 insertions(+), 112 deletions(-)
New commits:
commit bdc9b82ab8e89717cf717833b93d293d6eeecdd4
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date: Sun Oct 19 12:41:42 2014 +0200
KolabResource: Resourcebase can now schedule the attribute sync.
diff --git a/resources/kolab/kolabresource.cpp b/resources/kolab/kolabresource.cpp
index 2e8abf2..b64b7de 100644
--- a/resources/kolab/kolabresource.cpp
+++ b/resources/kolab/kolabresource.cpp
@@ -27,8 +27,6 @@
#include <changecollectiontask.h>
#include <KLocalizedString>
-#include <Akonadi/CollectionFetchJob>
-#include <Akonadi/CollectionFetchScope>
#include <KLocale>
#include "kolabretrievecollectionstask.h"
@@ -46,6 +44,8 @@ KolabResource::KolabResource(const QString& id)
{
//Load translations from imap resource
KGlobal::locale()->insertCatalog(QLatin1String("akonadi_imap_resource"));
+ //Ensure we have up-to date metadata before attempting to sync folder
+ setScheduleAttributeSyncBeforeItemSync(true);
}
KolabResource::~KolabResource()
@@ -78,51 +78,6 @@ void KolabResource::retrieveCollections()
synchronizeTags();
}
-void KolabResource::retrieveItems(const Akonadi::Collection &col)
-{
- //The collection that we receive was fetched when the task was scheduled, it is therefore possible that it is outdated.
- //We refetch the collection since we rely on up-to-date annotations.
- //FIXME: because this is async and not part of the resourcetask, it can't be killed. ResourceBase should just provide an up-to date copy of the collection.
- Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(col, Akonadi::CollectionFetchJob::Base, this);
- fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All);
- fetchJob->fetchScope().setIncludeStatistics(true);
- fetchJob->fetchScope().setIncludeUnsubscribed(true);
- connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onItemRetrievalCollectionFetchDone(KJob*)));
-}
-
-void KolabResource::onItemRetrievalCollectionFetchDone(KJob *job)
-{
- if (job->error()) {
- kWarning() << "Failed to retrieve collection before RetrieveItemsTask: " << job->errorString();
- cancelTask(i18n("Failed to retrieve items."));
- return;
- }
-
- Akonadi::CollectionFetchJob *fetchJob = static_cast<Akonadi::CollectionFetchJob*>(job);
- Q_ASSERT(fetchJob->collections().size() == 1);
- const Akonadi::Collection col = fetchJob->collections().first();
-
- //This is the only part that differs form the imap resource: We make sure the annotations are up-to date before synchronizing
- //HACK avoid infinite recursions, the metadatatask should be scheduled at most once per retrieveItemsJob
- static QSet<Akonadi::Collection::Id> updatedCollections;
- if (!updatedCollections.contains(col.id()) &&
- (!col.attribute<TimestampAttribute>() ||
- col.attribute<TimestampAttribute>()->timestamp() < QDateTime::currentDateTime().addSecs(-60).toTime_t())) {
- updatedCollections.insert(col.id());
- scheduleCustomTask(this, "triggerCollectionExtraInfoJobs", QVariant::fromValue(col), Akonadi::ResourceBase::Prepend);
- deferTask();
- return;
- }
- updatedCollections.remove(col.id());
-
- setItemStreamingEnabled(true);
-
- RetrieveItemsTask *task = new RetrieveItemsTask( createResourceState(TaskArguments(col)), this);
- connect(task, SIGNAL(status(int,QString)), SIGNAL(status(int,QString)));
- connect(this, SIGNAL(retrieveNextItemSyncBatch(int)), task, SLOT(onReadyForNextBatch(int)));
- startTask(task);
-}
-
void KolabResource::itemAdded(const Akonadi::Item& item, const Akonadi::Collection& collection)
{
bool ok = true;
diff --git a/resources/kolab/kolabresource.h b/resources/kolab/kolabresource.h
index 1f9bad8..53eaf2b 100644
--- a/resources/kolab/kolabresource.h
+++ b/resources/kolab/kolabresource.h
@@ -35,7 +35,6 @@ public:
protected Q_SLOTS:
virtual void retrieveCollections();
- virtual void retrieveItems(const Akonadi::Collection& col);
virtual void delayedInit();
protected:
@@ -59,7 +58,6 @@ protected:
virtual QString defaultName();
private Q_SLOTS:
- void onItemRetrievalCollectionFetchDone(KJob *job);
void retrieveTags();
};
commit fdd2d4ea501ab10a1555104462a91defa259f27b
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date: Sun Oct 19 12:41:07 2014 +0200
ImapResource: We no longer need to fetch collections first.
ResourceBase does that now for us. We do have to use synchronizeCollectionAttributes
instead of the custom task though.
diff --git a/resources/imap/imapresourcebase.cpp b/resources/imap/imapresourcebase.cpp
index 78ad4a1..7689b86 100644
--- a/resources/imap/imapresourcebase.cpp
+++ b/resources/imap/imapresourcebase.cpp
@@ -427,63 +427,19 @@ void ImapResourceBase::retrieveCollections()
startTask(new RetrieveCollectionsTask( createResourceState(TaskArguments()), this ));
}
-void ImapResourceBase::triggerCollectionExtraInfoJobs( const QVariant &collectionVariant )
+void ImapResourceBase::retrieveCollectionAttributes( const Akonadi::Collection &col )
{
- const Collection collection( collectionVariant.value<Collection>() );
- emit status( AgentBase::Running, i18nc( "@info:status", "Retrieving extra folder information for '%1'", collection.name() ) );
-
- //The collection that we received is potentially outdated.
- //Using it would overwrite attributes with old values.
- //FIXME: because this is async and not part of the resourcetask, it can't be killed. ResourceBase should just provide an up-to date copy of the collection.
- Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(collection, CollectionFetchJob::Base, this);
- fetchJob->fetchScope().setAncestorRetrieval( CollectionFetchScope::All );
- fetchJob->fetchScope().setIncludeStatistics( true );
- fetchJob->fetchScope().setIncludeUnsubscribed( true );
- connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onMetadataCollectionFetchDone(KJob*)));
-}
-
-void ImapResourceBase::onMetadataCollectionFetchDone(KJob *job)
-{
- if (job->error()) {
- kWarning() << "Failed to retrieve collection before RetrieveCollectionMetadataTask " << job->errorString();
- cancelTask(i18n("Failed to collect metadata."));
- return;
- }
-
- Akonadi::CollectionFetchJob *fetchJob = static_cast<Akonadi::CollectionFetchJob*>(job);
- Q_ASSERT(fetchJob->collections().size() == 1);
-
- startTask(new RetrieveCollectionMetadataTask( createResourceState(TaskArguments(fetchJob->collections().first())), this ));
+ emit status( AgentBase::Running, i18nc( "@info:status", "Retrieving extra folder information for '%1'", col.name() ) );
+ startTask(new RetrieveCollectionMetadataTask( createResourceState(TaskArguments(col)), this ));
}
void ImapResourceBase::retrieveItems( const Collection &col )
{
- scheduleCustomTask( this, "triggerCollectionExtraInfoJobs", QVariant::fromValue( col ), ResourceBase::Append );
-
- //The collection that we receive was fetched when the task was scheduled, it is therefore possible that it is outdated.
- //We refetch the collection since we rely on up-to-date annotations.
- //FIXME: because this is async and not part of the resourcetask, it can't be killed. ResourceBase should just provide an up-to date copy of the collection.
- Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(col, CollectionFetchJob::Base, this);
- fetchJob->fetchScope().setAncestorRetrieval( CollectionFetchScope::All );
- fetchJob->fetchScope().setIncludeStatistics( true );
- fetchJob->fetchScope().setIncludeUnsubscribed( true );
- connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onItemRetrievalCollectionFetchDone(KJob*)));
-}
-
-void ImapResourceBase::onItemRetrievalCollectionFetchDone(KJob *job)
-{
- if (job->error()) {
- kWarning() << "Failed to retrieve collection before RetrieveItemsTask: " << job->errorString();
- cancelTask(i18n("Failed to retrieve items."));
- return;
- }
-
- Akonadi::CollectionFetchJob *fetchJob = static_cast<Akonadi::CollectionFetchJob*>(job);
- Q_ASSERT(fetchJob->collections().size() == 1);
+ synchronizeCollectionAttributes(col);
setItemStreamingEnabled( true );
- RetrieveItemsTask *task = new RetrieveItemsTask( createResourceState(TaskArguments(fetchJob->collections().first())), this);
+ RetrieveItemsTask *task = new RetrieveItemsTask( createResourceState(TaskArguments(col)), this);
connect(task, SIGNAL(status(int,QString)), SIGNAL(status(int,QString)));
connect(this, SIGNAL(retrieveNextItemSyncBatch(int)), task, SLOT(onReadyForNextBatch(int)));
startTask(task);
diff --git a/resources/imap/imapresourcebase.h b/resources/imap/imapresourcebase.h
index 5e5979d..e4b234b 100644
--- a/resources/imap/imapresourcebase.h
+++ b/resources/imap/imapresourcebase.h
@@ -84,6 +84,7 @@ protected Q_SLOTS:
void abortActivity();
virtual void retrieveCollections();
+ void retrieveCollectionAttributes( const Akonadi::Collection &col );
virtual void retrieveItems( const Akonadi::Collection &col );
virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
@@ -130,15 +131,11 @@ private Q_SLOTS:
void onIdleCollectionFetchDone( KJob *job );
- void onItemRetrievalCollectionFetchDone( KJob *job );
- void onMetadataCollectionFetchDone( KJob *job );
void onExpungeCollectionFetchDone( KJob *job );
void triggerCollectionExpunge( const QVariant &collectionVariant );
- void triggerCollectionExtraInfoJobs( const QVariant &collection );
-
void taskDestroyed( QObject *task );
void showError( const QString &message );
diff --git a/resources/imap/resourcestate.cpp b/resources/imap/resourcestate.cpp
index ad6172e..77d8081 100644
--- a/resources/imap/resourcestate.cpp
+++ b/resources/imap/resourcestate.cpp
@@ -196,12 +196,7 @@ void ResourceState::applyCollectionChanges( const Akonadi::Collection &collectio
void ResourceState::collectionAttributesRetrieved( const Akonadi::Collection &collection )
{
- //TODO use collection attributes retrieved properly. (Currently we're only emulating the behaviour)
-// m_resource->collectionAttributesRetrieved( collection );
- if (collection.isValid() || !collection.remoteId().isEmpty()) {
- applyCollectionChanges(collection);
- }
- taskDone();
+ m_resource->collectionAttributesRetrieved( collection );
}
void ResourceState::itemRetrieved( const Akonadi::Item &item )
@@ -254,10 +249,7 @@ void ResourceState::collectionsRetrieved( const Akonadi::Collection::List &colle
if ( !c.hasAttribute<NoSelectAttribute>()
&& !oldMailBoxes.contains( mailBox ) ) {
- m_resource->scheduleCustomTask( m_resource,
- "triggerCollectionExtraInfoJobs",
- QVariant::fromValue( c ),
- Akonadi::ResourceBase::Append );
+ m_resource->synchronizeCollectionAttributes(c);
}
newMailBoxes << mailBox;
More information about the commits
mailing list