[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepimlibs
From: Kevin Ottens <ervin () kde ! org>
Date: 2010-09-14 9:55:38
Message-ID: 20100914100022.88AD8AC888 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1175138 by ervin:
Allow resources to sync only the attributes of a collection. Add a job
which allows clients to request that forcibly.
M +2 -0 akonadi/CMakeLists.txt
A akonadi/collectionattributessynchronizationjob.cpp [License: LGPL \
(v2.1+)] A akonadi/collectionattributessynchronizationjob.h [License: \
LGPL (v2.1+)] M +61 -0 akonadi/resourcebase.cpp
M +36 -0 akonadi/resourcebase.h
M +17 -0 akonadi/resourcescheduler.cpp
M +8 -0 akonadi/resourcescheduler_p.h
M +17 -0 akonadi/tests/resourceschedulertest.cpp
A includes/Akonadi/CollectionAttributesSynchronizationJob
--- trunk/KDE/kdepimlibs/akonadi/CMakeLists.txt #1175137:1175138
@@ -57,6 +57,7 @@
cachepolicy.cpp
changerecorder.cpp
collection.cpp
+ collectionattributessynchronizationjob.cpp
collectioncombobox.cpp
collectioncopyjob.cpp
collectioncreatejob.cpp
@@ -256,6 +257,7 @@
cachepolicy.h
changerecorder.h
collection.h
+ collectionattributessynchronizationjob.h
collectioncombobox.h
collectioncopyjob.h
collectioncreatejob.h
--- trunk/KDE/kdepimlibs/akonadi/resourcebase.cpp #1175137:1175138
@@ -110,6 +110,9 @@
void slotLocalListDone( KJob *job );
void slotSynchronizeCollection( const Collection &col );
void slotCollectionListDone( KJob *job );
+ void slotSynchronizeCollectionAttributes( const Collection &col );
+ void slotCollectionListForAttributesDone( KJob *job );
+ void slotCollectionAttributesSyncDone( KJob *job );
void slotItemSyncDone( KJob *job );
@@ -183,6 +186,8 @@
SLOT( retrieveCollections() ) );
connect( d->scheduler, SIGNAL( executeCollectionSync( const Akonadi::Collection& ) \
),
SLOT( slotSynchronizeCollection( const Akonadi::Collection& ) ) );
+ connect( d->scheduler, SIGNAL( executeCollectionAttributesSync( const \
Akonadi::Collection& ) ), + SLOT( \
slotSynchronizeCollectionAttributes(Akonadi::Collection)) ); connect( d->scheduler, \
SIGNAL( executeItemFetch( const Akonadi::Item&, const QSet<QByteArray>& ) ), SLOT( \
slotPrepareItemRetrieval(Akonadi::Item)) ); connect( d->scheduler, SIGNAL( \
executeResourceCollectionDeletion() ), @@ -307,6 +312,31 @@
scheduler->taskDone();
}
+void ResourceBase::collectionAttributesRetrieved( const Collection &collection )
+{
+ Q_D( ResourceBase );
+ Q_ASSERT( d->scheduler->currentTask().type == \
ResourceScheduler::SyncCollectionAttributes ); + if ( !collection.isValid() ) {
+ emit attributesSynchronized( d->scheduler->currentTask().collection.id() );
+ d->scheduler->taskDone();
+ return;
+ }
+
+ CollectionModifyJob *job = new CollectionModifyJob( collection );
+ connect( job, SIGNAL( result( KJob* ) ), SLOT( slotCollectionAttributesSyncDone( \
KJob* ) ) ); +}
+
+void ResourceBasePrivate::slotCollectionAttributesSyncDone(KJob * job)
+{
+ Q_Q( ResourceBase );
+ Q_ASSERT( scheduler->currentTask().type == \
ResourceScheduler::SyncCollectionAttributes ); + if ( job->error() ) {
+ emit q->error( QLatin1String( "Error while updating collection: " ) + \
job->errorString() ); + }
+ emit q->attributesSynchronized( scheduler->currentTask().collection.id() );
+ scheduler->taskDone();
+}
+
void ResourceBasePrivate::slotDeleteResourceCollection()
{
Q_Q( ResourceBase );
@@ -510,6 +540,12 @@
scheduler->taskDone();
}
+void ResourceBasePrivate::slotSynchronizeCollectionAttributes( const Collection &col \
) +{
+ Q_Q( ResourceBase );
+ QMetaObject::invokeMethod( q, "retrieveCollectionAttributes", Q_ARG( \
Akonadi::Collection, col ) ); +}
+
void ResourceBasePrivate::slotPrepareItemRetrieval( const Akonadi::Item &item )
{
Q_Q( ResourceBase );
@@ -654,6 +690,26 @@
// TODO: error handling
}
+void ResourceBase::synchronizeCollectionAttributes( qint64 collectionId )
+{
+ CollectionFetchJob* job = new CollectionFetchJob( Collection( collectionId ), \
CollectionFetchJob::Base ); + job->setFetchScope( \
changeRecorder()->collectionFetchScope() ); + job->fetchScope().setResource( \
identifier() ); + connect( job, SIGNAL( result( KJob* ) ), SLOT( \
slotCollectionListForAttributesDone( KJob* ) ) ); +}
+
+void ResourceBasePrivate::slotCollectionListForAttributesDone( KJob *job )
+{
+ if ( !job->error() ) {
+ Collection::List list = static_cast<CollectionFetchJob*>( job )->collections();
+ if ( !list.isEmpty() ) {
+ Collection col = list.first();
+ scheduler->scheduleAttributesSync( col );
+ }
+ }
+ // TODO: error handling
+}
+
void ResourceBase::setTotalItems( int amount )
{
kDebug() << amount;
@@ -718,6 +774,11 @@
d->scheduler->taskDone();
}
+void ResourceBase::retrieveCollectionAttributes( const Collection &collection )
+{
+ collectionAttributesRetrieved( collection );
+}
+
void ResourceBase::setItemTransactionMode(ItemSync::TransactionMode mode)
{
Q_D( ResourceBase );
--- trunk/KDE/kdepimlibs/akonadi/resourcebase.h #1175137:1175138
@@ -210,6 +210,13 @@
*/
void synchronized();
+ /**
+ * Emitted when a collection attributes synchronization has been completed.
+ *
+ * @param collectionId The identifier of the collection whose attributes got \
synchronized. + */
+ void attributesSynchronized( qlonglong collectionId );
+
protected Q_SLOTS:
/**
* Retrieve the collection tree from the remote server and supply it via
@@ -219,6 +226,19 @@
virtual void retrieveCollections() = 0;
/**
+ * Retrieve the attributes of a single collection from the backend. The
+ * collection to retrieve attributes for is provided as @p collection.
+ * Add the attributes parts and call collectionAttributesRetrieved()
+ * when done.
+ *
+ * @param collection The collection whose attributes should be retrieved.
+ * @see collectionAttributesRetrieved()
+ */
+ // KDE5: Make it pure virtual, for now can be called only by invokeMethod()
+ // in order to simulate polymorphism
+ void retrieveCollectionAttributes( const Akonadi::Collection &collection );
+
+ /**
* Retrieve all (new/changed) items in collection @p collection.
* It is recommended to use incremental retrieval if the backend supports that
* and provide the result by calling itemsRetrievedIncremental().
@@ -265,6 +285,13 @@
void itemRetrieved( const Item &item );
/**
+ * Call this method from retrieveCollectionAttributes() once the result is \
available. + *
+ * @param item The collection whose attributes got retrieved.
+ */
+ void collectionAttributesRetrieved( const Collection &collection );
+
+ /**
* Resets the dirty flag of the given item and updates the remote id.
*
* Call whenever you have successfully written changes back to the server.
@@ -420,6 +447,12 @@
void synchronizeCollection( qint64 id );
/**
+ * This method is called whenever the collection with the given @p id
+ * shall have its attributes synchronized.
+ */
+ void synchronizeCollectionAttributes( qint64 id );
+
+ /**
* Refetches the Collections.
*/
void synchronizeCollectionTree();
@@ -521,6 +554,9 @@
Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) )
Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const \
Akonadi::Collection& ) ) Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( \
KJob* ) ) + Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollectionAttributes( \
const Akonadi::Collection& ) ) + Q_PRIVATE_SLOT( d_func(), void \
slotCollectionListForAttributesDone( KJob* ) ) + Q_PRIVATE_SLOT( d_func(), void \
slotCollectionAttributesSyncDone( KJob* ) ) Q_PRIVATE_SLOT( d_func(), void \
slotItemSyncDone( KJob* ) ) Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, \
unsigned long ) )
Q_PRIVATE_SLOT( d_func(), void slotPrepareItemRetrieval( const Akonadi::Item& \
item ) )
--- trunk/KDE/kdepimlibs/akonadi/resourcescheduler.cpp #1175137:1175138
@@ -77,6 +77,20 @@
scheduleNext();
}
+void ResourceScheduler::scheduleAttributesSync( const Collection &collection )
+{
+ Task t;
+ t.type = SyncCollectionAttributes;
+ t.collection = collection;
+
+ TaskList& queue = queueForTaskType( t.type );
+ if ( queue.contains( t ) || mCurrentTask == t )
+ return;
+ queue << t;
+ signalTaskToTracker( t, "SyncCollectionAttributes" );
+ scheduleNext();
+}
+
void ResourceScheduler::scheduleItemFetch(const Item & item, const QSet<QByteArray> \
&parts, const QDBusMessage & msg) {
Task t;
@@ -246,6 +260,9 @@
case SyncCollection:
emit executeCollectionSync( mCurrentTask.collection );
break;
+ case SyncCollectionAttributes:
+ emit executeCollectionAttributesSync( mCurrentTask.collection );
+ break;
case FetchItem:
emit executeItemFetch( mCurrentTask.item, mCurrentTask.itemParts );
break;
--- trunk/KDE/kdepimlibs/akonadi/resourcescheduler_p.h #1175137:1175138
@@ -50,6 +50,7 @@
SyncAll,
SyncCollectionTree,
SyncCollection,
+ SyncCollectionAttributes,
FetchItem,
ChangeReplay,
DeleteResourceCollection,
@@ -105,6 +106,12 @@
void scheduleSync( const Collection &col );
/**
+ Schedules synchronizing the attributes of a single collection.
+ @param collection The collection to synchronize attributes from.
+ */
+ void scheduleAttributesSync( const Collection &collection );
+
+ /**
Schedules fetching of a single PIM item.
@param item The item to fetch.
@param parts List of names of the parts of the item to fetch.
@@ -179,6 +186,7 @@
Q_SIGNALS:
void executeFullSync();
+ void executeCollectionAttributesSync( const Akonadi::Collection &col );
void executeCollectionSync( const Akonadi::Collection &col );
void executeCollectionTreeSync();
void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts \
);
--- trunk/KDE/kdepimlibs/akonadi/tests/resourceschedulertest.cpp #1175137:1175138
@@ -281,16 +281,19 @@
QSignalSpy collectionTreeSyncSpy( &scheduler, SIGNAL(executeCollectionTreeSync()) \
); QSignalSpy syncSpy( &scheduler, SIGNAL(executeCollectionSync(Akonadi::Collection) \
) ); QSignalSpy fetchSpy( &scheduler, \
SIGNAL(executeItemFetch(Akonadi::Item,QSet<QByteArray>)) ); + QSignalSpy \
attributesSyncSpy( &scheduler, \
SIGNAL(executeCollectionAttributesSync(Akonadi::Collection)) ); QVERIFY( \
changeReplaySpy.isValid() ); QVERIFY( fullSyncSpy.isValid() );
QVERIFY( collectionTreeSyncSpy.isValid() );
QVERIFY( syncSpy.isValid() );
QVERIFY( fetchSpy.isValid() );
+ QVERIFY( attributesSyncSpy.isValid() );
scheduler.scheduleCollectionTreeSync();
scheduler.scheduleChangeReplay();
scheduler.scheduleSync( Akonadi::Collection( 42 ) );
scheduler.scheduleItemFetch( Akonadi::Item( 42 ), QSet<QByteArray>(), \
QDBusMessage() ); + scheduler.scheduleAttributesSync( Akonadi::Collection( 42 ) );
scheduler.scheduleFullSync();
QTest::qWait( 1 );
@@ -299,6 +302,7 @@
QCOMPARE( syncSpy.count(), 0 );
QCOMPARE( fullSyncSpy.count(), 0 );
QCOMPARE( fetchSpy.count(), 0 );
+ QCOMPARE( attributesSyncSpy.count(), 0 );
scheduler.taskDone();
QTest::qWait( 1 );
@@ -307,6 +311,7 @@
QCOMPARE( syncSpy.count(), 0 );
QCOMPARE( fullSyncSpy.count(), 0 );
QCOMPARE( fetchSpy.count(), 1 );
+ QCOMPARE( attributesSyncSpy.count(), 0 );
scheduler.taskDone();
QTest::qWait( 1 );
@@ -315,6 +320,7 @@
QCOMPARE( syncSpy.count(), 0 );
QCOMPARE( fullSyncSpy.count(), 0 );
QCOMPARE( fetchSpy.count(), 1 );
+ QCOMPARE( attributesSyncSpy.count(), 0 );
scheduler.taskDone();
QTest::qWait( 1 );
@@ -323,14 +329,25 @@
QCOMPARE( syncSpy.count(), 1 );
QCOMPARE( fullSyncSpy.count(), 0 );
QCOMPARE( fetchSpy.count(), 1 );
+ QCOMPARE( attributesSyncSpy.count(), 0 );
scheduler.taskDone();
QTest::qWait( 1 );
QCOMPARE( collectionTreeSyncSpy.count(), 1 );
QCOMPARE( changeReplaySpy.count(), 1 );
QCOMPARE( syncSpy.count(), 1 );
+ QCOMPARE( fullSyncSpy.count(), 0 );
+ QCOMPARE( fetchSpy.count(), 1 );
+ QCOMPARE( attributesSyncSpy.count(), 1 );
+ scheduler.taskDone();
+
+ QTest::qWait( 1 );
+ QCOMPARE( collectionTreeSyncSpy.count(), 1 );
+ QCOMPARE( changeReplaySpy.count(), 1 );
+ QCOMPARE( syncSpy.count(), 1 );
QCOMPARE( fullSyncSpy.count(), 1 );
QCOMPARE( fetchSpy.count(), 1 );
+ QCOMPARE( attributesSyncSpy.count(), 1 );
scheduler.taskDone();
QVERIFY( scheduler.isEmpty() );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic