[Kde-bindings] KDE/kdepimlibs/akonadi
Stephen Kelly
steveire at gmail.com
Tue Jun 22 13:21:25 UTC 2010
SVN commit 1141303 by skelly:
Add FetchState reporting to EntityTreeModel
CCMAIL: kde-bindings at kde.org
M +4 -0 entitytreemodel.cpp
M +19 -0 entitytreemodel.h
M +18 -4 entitytreemodel_p.cpp
--- trunk/KDE/kdepimlibs/akonadi/entitytreemodel.cpp #1141302:1141303
@@ -240,6 +240,10 @@
CollectionStatistics statistics = collection.statistics();
return statistics.unreadCount();
}
+ case FetchStateRole :
+ {
+ return d->m_pendingCollectionRetrieveJobs.contains(collection.id()) ? FetchingState : IdleState;
+ }
case Qt::BackgroundRole:
{
if ( collection.hasAttribute<EntityDisplayAttribute>() )
--- trunk/KDE/kdepimlibs/akonadi/entitytreemodel.h #1141302:1141303
@@ -292,6 +292,16 @@
* itemList->setHeaderGroup( EntityTreeModel::ItemListHeaders );
* @endcode
*
+ * <h3>Progress reporting</h3>
+ *
+ * The EntityTreeModel uses asynchronous Akonadi::Job instances to fill and update itself.
+ * For example, a job is run to fetch the contents of collections (that is, list the items in it).
+ * Additionally, individual Akonadi::Items can be fetched in different parts at different times.
+ *
+ * To indicate that such a job is underway, the EntityTreeModel makes the FetchState available. The
+ * FetchState returned from a QModelIndex representing a Akonadi::Collection will be FetchingState if a
+ * listing of the items in that collection is underway, otherwise the state is IdleState.
+ *
* @author Stephen Kelly <steveire at gmail.com>
* @since 4.4
*/
@@ -328,11 +338,20 @@
PendingCutRole, ///< @internal Used to indicate items which are to be cut
EntityUrlRole, ///< The akonadi:/ Url of the entity as a string. Item urls will contain the mimetype.
UnreadCountRole, ///< Returns the number of unread items in a collection. @since 4.5
+ FetchStateRole, ///< Returns the FetchState of a particular item. @since 4.5
UserRole = Qt::UserRole + 500, ///< First role for user extensions.
TerminalUserRole = 2000, ///< Last role for user extensions. Don't use a role beyond this or headerData will break.
EndRole = 65535
};
+ /**
+ * Describes the state of fetch jobs related to particular entities.
+ */
+ enum FetchState {
+ IdleState, ///< There is no fetch in progress.
+ FetchingState ///< There is a fetch in progress.
+ // TODO: Change states for reporting of fetching payload parts of items.
+ };
/**
* Describes what header information the model shall return.
--- trunk/KDE/kdepimlibs/akonadi/entitytreemodel_p.cpp #1141302:1141303
@@ -170,13 +170,19 @@
void EntityTreeModelPrivate::runItemFetchJob( ItemFetchJob *itemFetchJob, const Collection &parent ) const
{
Q_Q( const EntityTreeModel );
-
- // TODO: This hack is probably not needed anymore. Remove it.
- // ### HACK: itemsReceivedFromJob needs to know which collection items were added to.
- // That is not provided by akonadi, so we attach it in a property.
itemFetchJob->setProperty( FetchCollectionId(), QVariant( parent.id() ) );
m_pendingCollectionRetrieveJobs.insert( parent.id() );
+ // If collections are not in the model, there will be no valid index for them.
+ if (!((m_collectionFetchStrategy == EntityTreeModel::InvisibleCollectionFetch)
+ || (m_collectionFetchStrategy == EntityTreeModel::FetchNoCollections)))
+ {
+ QModelIndex collectionIndex = indexForCollection(parent);
+ // TODO: Add a signal to QAIM roleDataChanged(QModelIndex, QModelIndex, QSet<int> roles)
+ // Indicate to observers to re-query the FetchState.
+ emit const_cast<EntityTreeModel *>(q)->dataChanged(collectionIndex, collectionIndex);
+ }
+
q->connect( itemFetchJob, SIGNAL( itemsReceived( const Akonadi::Item::List& ) ),
q, SLOT( itemsFetched( const Akonadi::Item::List& ) ) );
q->connect( itemFetchJob, SIGNAL( result( KJob* ) ),
@@ -937,6 +943,14 @@
m_pendingCollectionRetrieveJobs.remove( collectionId );
+ // If collections are not in the model, there will be no valid index for them.
+ if (!((m_collectionFetchStrategy == EntityTreeModel::InvisibleCollectionFetch)
+ || (m_collectionFetchStrategy == EntityTreeModel::FetchNoCollections)))
+ {
+ QModelIndex index = indexForCollection(Collection(collectionId));
+ emit dataChanged(index, index);
+ }
+
#ifdef DBG_TRACK_JOB_TIMES
kDebug() << "Fetch job took " << jobTimeTracker.take(job).elapsed() << "msec";
if ( CollectionFetchJob* cJob = dynamic_cast<CollectionFetchJob*>( job ) ) {
More information about the Kde-bindings
mailing list