akonadi
entitytreemodel_p.h
00001 /* 00002 Copyright (c) 2008 Stephen Kelly <steveire@gmail.com> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #ifndef ENTITYTREEMODELPRIVATE_H 00021 #define ENTITYTREEMODELPRIVATE_H 00022 00023 #include <akonadi/item.h> 00024 #include <KJob> 00025 #include <QTime> 00026 00027 #include <akonadi/collectionfetchjob.h> 00028 #include <akonadi/itemfetchscope.h> 00029 #include <akonadi/mimetypechecker.h> 00030 00031 #include "entitytreemodel.h" 00032 00033 #include "akonadiprivate_export.h" 00034 00035 namespace Akonadi 00036 { 00037 class ItemFetchJob; 00038 class ChangeRecorder; 00039 class AgentInstance; 00040 } 00041 00042 struct Node 00043 { 00044 Akonadi::Entity::Id id; 00045 Akonadi::Entity::Id parent; 00046 00047 enum Type 00048 { 00049 Item, 00050 Collection 00051 }; 00052 00053 int type; 00054 }; 00055 00056 namespace Akonadi 00057 { 00061 class AKONADI_TESTS_EXPORT EntityTreeModelPrivate 00062 { 00063 public: 00064 00065 EntityTreeModelPrivate( EntityTreeModel *parent ); 00066 ~EntityTreeModelPrivate(); 00067 EntityTreeModel * const q_ptr; 00068 00069 enum RetrieveDepth { 00070 Base, 00071 Recursive 00072 }; 00073 00074 enum ListingOrder 00075 { 00076 NotFirstListing, 00077 FirstListing 00078 }; 00079 00080 void init( ChangeRecorder *monitor ); 00081 00082 void fetchCollections( const Collection &collection, CollectionFetchJob::Type = CollectionFetchJob::FirstLevel, ListingOrder = NotFirstListing ); 00083 void fetchItems( const Collection &collection ); 00084 void collectionsFetched( const Akonadi::Collection::List& ); 00085 void firstCollectionsFetched( const Akonadi::Collection::List& ); 00086 void collectionListFetched( const Akonadi::Collection::List& ); 00087 void itemsFetched( KJob* ); 00088 void itemsFetched( const Akonadi::Item::List &items ); 00089 void itemsFetched( const Collection::Id collectionId, const Akonadi::Item::List &items ); 00090 00091 void monitoredCollectionAdded( const Akonadi::Collection&, const Akonadi::Collection& ); 00092 void monitoredCollectionRemoved( const Akonadi::Collection& ); 00093 void monitoredCollectionChanged( const Akonadi::Collection& ); 00094 void monitoredCollectionStatisticsChanged( Akonadi::Collection::Id, const Akonadi::CollectionStatistics& ); 00095 void monitoredCollectionMoved( const Akonadi::Collection&, const Akonadi::Collection&, const Akonadi::Collection& ); 00096 00097 void collectionSubscribed( const Akonadi::Collection&, const Akonadi::Collection& ); 00098 void monitoredCollectionUnsubscribed( const Akonadi::Collection& ); 00099 00100 void monitoredItemAdded( const Akonadi::Item&, const Akonadi::Collection& ); 00101 void monitoredItemRemoved( const Akonadi::Item& ); 00102 void monitoredItemChanged( const Akonadi::Item&, const QSet<QByteArray>& ); 00103 void monitoredItemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& ); 00104 00105 void monitoredItemLinked( const Akonadi::Item&, const Akonadi::Collection& ); 00106 void monitoredItemUnlinked( const Akonadi::Item&, const Akonadi::Collection& ); 00107 00108 void monitoredMimeTypeChanged( const QString &mimeType, bool monitored ); 00109 void monitoredCollectionsChanged( const Akonadi::Collection &collection, bool monitored ); 00110 void monitoredItemsChanged( const Akonadi::Item &item, bool monitored ); 00111 void monitoredResourcesChanged( const QByteArray &resource, bool monitored ); 00112 00113 Collection::List getParentCollections( const Item &item ) const; 00114 void removeChildEntities( Collection::Id collectionId ); 00115 00119 QStringList childCollectionNames( const Collection &collection ) const; 00120 00124 void retrieveAncestors( const Akonadi::Collection& collection ); 00125 void ancestorsFetched( const Akonadi::Collection::List& collectionList ); 00126 void insertCollection( const Akonadi::Collection &collection, const Akonadi::Collection& parent ); 00127 void insertPendingCollection( const Akonadi::Collection &collection, const Akonadi::Collection& parent, QMutableListIterator<Collection> &it ); 00128 00129 void beginResetModel(); 00130 void endResetModel(); 00135 void fillModel(); 00136 00137 ItemFetchJob* getItemFetchJob( const Collection &parent, const ItemFetchScope &scope ) const; 00138 ItemFetchJob* getItemFetchJob( const Item &item, const ItemFetchScope &scope ) const; 00139 void runItemFetchJob( ItemFetchJob* itemFetchJob, const Collection &parent ) const; 00140 void changeFetchState( const Collection &parent ); 00141 void agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ); 00142 void agentInstanceRemoved( const Akonadi::AgentInstance &instace ); 00143 00144 QHash<Collection::Id, Collection> m_collections; 00145 QHash<Entity::Id, Item> m_items; 00146 QHash<Collection::Id, QList<Node*> > m_childEntities; 00147 QSet<Collection::Id> m_populatedCols; 00148 00149 QVector<Entity::Id> m_pendingCutItems; 00150 QVector<Entity::Id> m_pendingCutCollections; 00151 mutable QSet<Collection::Id> m_pendingCollectionRetrieveJobs; 00152 00153 ChangeRecorder *m_monitor; 00154 Collection m_rootCollection; 00155 Node *m_rootNode; 00156 QString m_rootCollectionDisplayName; 00157 QStringList m_mimeTypeFilter; 00158 MimeTypeChecker m_mimeChecker; 00159 EntityTreeModel::CollectionFetchStrategy m_collectionFetchStrategy; 00160 EntityTreeModel::ItemPopulationStrategy m_itemPopulation; 00161 bool m_includeUnsubscribed; 00162 bool m_includeStatistics; 00163 bool m_showRootCollection; 00164 QHash<Collection::Id, uint> m_collectionSyncProgress; 00165 00176 void startFirstListJob(); 00177 00178 void serverStarted(); 00179 00180 void monitoredItemsRetrieved( KJob* job ); 00181 void firstFetchJobDone( KJob *job ); 00182 void rootFetchJobDone( KJob *job ); 00183 void fetchJobDone( KJob *job ); 00184 void updateJobDone( KJob *job ); 00185 void pasteJobDone( KJob *job ); 00186 00190 template<Node::Type Type> 00191 int indexOf( const QList<Node*> &nodes, Entity::Id id ) const 00192 { 00193 int i = 0; 00194 foreach ( const Node *node, nodes ) { 00195 if ( node->id == id && node->type == Type ) 00196 { 00197 return i; 00198 } 00199 i++; 00200 } 00201 00202 return -1; 00203 } 00204 00209 static QByteArray FetchCollectionId() { 00210 return "FetchCollectionId"; 00211 } 00212 00213 Session *m_session; 00214 00215 Q_DECLARE_PUBLIC( EntityTreeModel ) 00216 00217 void fetchTopLevelCollections() const; 00218 void topLevelCollectionsFetched( const Akonadi::Collection::List& collectionList ); 00219 00223 bool isHidden( const Entity &entity, Node::Type type ) const; 00224 00225 template<typename T> 00226 bool isHidden( const T &entity ) const; 00227 00228 bool m_showSystemEntities; 00229 00230 void ref( Collection::Id id ); 00231 void deref( Collection::Id id ); 00232 00236 bool shouldPurge( Collection::Id id ); 00237 00241 void purgeItems( Collection::Id id ); 00242 00250 QList<Node*>::iterator removeItems( QList<Node*>::iterator it, QList<Node*>::iterator end, 00251 int *pos, const Collection &col ); 00252 00260 QList<Node*>::iterator skipCollections( QList<Node*>::iterator it, QList<Node*>::iterator end, int *pos ); 00261 00265 void dataChanged( const QModelIndex &top, const QModelIndex &bottom ); 00266 00270 QModelIndex indexForCollection( const Collection &collection ) const; 00271 00275 QModelIndexList indexesForItem( const Item &item ) const; 00276 00280 Collection collectionForId( Collection::Id id ) const; 00281 00285 Item itemForId( Item::Id id ) const; 00286 00287 bool canFetchMore( const QModelIndex & parent ) const; 00288 }; 00289 00290 } 00291 00292 #endif 00293