• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
entitytreemodel.h
1 /*
2  Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef AKONADI_ENTITYTREEMODEL_H
21 #define AKONADI_ENTITYTREEMODEL_H
22 
23 #include "akonadi_export.h"
24 
25 #include <akonadi/collection.h>
26 #include <akonadi/item.h>
27 
28 #include <QtCore/QAbstractItemModel>
29 #include <QtCore/QStringList>
30 
31 namespace Akonadi
32 {
33 
34 class ChangeRecorder;
35 class CollectionStatistics;
36 class Item;
37 class ItemFetchScope;
38 class Monitor;
39 class Session;
40 
41 class EntityTreeModelPrivate;
42 
317 class AKONADI_EXPORT EntityTreeModel : public QAbstractItemModel
318 {
319  Q_OBJECT
320 
321  public:
325  enum Roles {
326  //sebsauer, 2009-05-07; to be able here to keep the akonadi_next EntityTreeModel compatible with
327  //the akonadi_old ItemModel and CollectionModel, we need to use the same int-values for
328  //ItemRole, ItemIdRole and MimeTypeRole like the Akonadi::ItemModel is using and the same
329  //CollectionIdRole and CollectionRole like the Akonadi::CollectionModel is using.
330  ItemIdRole = Qt::UserRole + 1,
331  ItemRole = Qt::UserRole + 2,
332  MimeTypeRole = Qt::UserRole + 3,
333 
334  CollectionIdRole = Qt::UserRole + 10,
335  CollectionRole = Qt::UserRole + 11,
336 
337  RemoteIdRole,
338  CollectionChildOrderRole,
339  AmazingCompletionRole,
340  ParentCollectionRole,
341  ColumnCountRole,
342  LoadedPartsRole,
343  AvailablePartsRole,
344  SessionRole,
345  CollectionRefRole,
346  CollectionDerefRole,
347  PendingCutRole,
348  EntityUrlRole,
349  UnreadCountRole,
350  FetchStateRole,
351  CollectionSyncProgressRole,
352  IsPopulatedRole,
353  UserRole = Qt::UserRole + 500,
354  TerminalUserRole = 2000,
355  EndRole = 65535
356  };
357 
372  enum FetchState {
373  IdleState,
374  FetchingState
375  // TODO: Change states for reporting of fetching payload parts of items.
376  };
377 
381  enum HeaderGroup {
382  EntityTreeHeaders,
383  CollectionTreeHeaders,
384  ItemListHeaders,
385  UserHeaders = 10,
386  EndHeaderGroup = 32
387  // Note that we're splitting up available roles for the header data hack and int(EndRole / TerminalUserRole) == 32
388  };
389 
396  explicit EntityTreeModel( ChangeRecorder *monitor, QObject *parent = 0 );
397 
401  virtual ~EntityTreeModel();
402 
406  enum ItemPopulationStrategy {
407  NoItemPopulation,
408  ImmediatePopulation,
409  LazyPopulation
410  };
411 
419  void setShowSystemEntities( bool show );
420 
424  bool systemEntitiesShown() const;
425 
431  bool includeUnsubscribed() const;
432 
443  void setIncludeUnsubscribed( bool show );
444 
448  void setItemPopulationStrategy( ItemPopulationStrategy strategy );
449 
453  ItemPopulationStrategy itemPopulationStrategy() const;
454 
460  void setIncludeRootCollection( bool include );
461 
465  bool includeRootCollection() const;
466 
474  void setRootCollectionDisplayName( const QString &name );
475 
479  QString rootCollectionDisplayName() const;
480 
484  enum CollectionFetchStrategy {
485  FetchNoCollections,
486  FetchFirstLevelChildCollections,
487  FetchCollectionsRecursive,
488  InvisibleCollectionFetch
489  };
490 
494  void setCollectionFetchStrategy( CollectionFetchStrategy strategy );
495 
499  CollectionFetchStrategy collectionFetchStrategy() const;
500 
501  virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
502  virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
503 
504  virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
505  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
506 
507  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
508  virtual QStringList mimeTypes() const;
509 
510  virtual Qt::DropActions supportedDropActions() const;
511  virtual QMimeData *mimeData( const QModelIndexList &indexes ) const;
512  virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
513  virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
514 
515  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
516  virtual QModelIndex parent( const QModelIndex & index ) const;
517 
518  // TODO: Review the implementations of these. I think they could be better.
519  virtual bool canFetchMore( const QModelIndex & parent ) const;
520  virtual void fetchMore( const QModelIndex & parent );
521  virtual bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;
522 
529  bool isCollectionTreeFetched() const;
530 
537  bool isCollectionPopulated( Akonadi::Collection::Id ) const;
538 
542  virtual QModelIndexList match( const QModelIndex& start, int role, const QVariant& value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const;
543 
574  static QModelIndex modelIndexForCollection( const QAbstractItemModel *model, const Collection &collection );
575 
584  static QModelIndexList modelIndexesForItem( const QAbstractItemModel *model, const Item &item );
585 
586  Q_SIGNALS:
594  void collectionTreeFetched( const Akonadi::Collection::List &collections );
595 
603  void collectionPopulated( Akonadi::Collection::Id collectionId );
612  void collectionFetched(int collectionId);
613 
614  protected:
619  void clearAndReset();
620 
624  virtual QVariant entityData( const Item &item, int column, int role = Qt::DisplayRole ) const;
625 
629  virtual QVariant entityData( const Collection &collection, int column, int role = Qt::DisplayRole ) const;
630 
635  virtual QVariant entityHeaderData( int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup ) const;
636 
637  virtual int entityColumnCount( HeaderGroup headerGroup ) const;
638 
642  virtual bool entityMatch( const Item &item, const QVariant &value, Qt::MatchFlags flags ) const;
643 
647  virtual bool entityMatch( const Collection &collection, const QVariant &value, Qt::MatchFlags flags ) const;
648 
649 protected:
650  //@cond PRIVATE
651  Q_DECLARE_PRIVATE( EntityTreeModel )
652  EntityTreeModelPrivate * d_ptr;
653  EntityTreeModel( ChangeRecorder *monitor, EntityTreeModelPrivate *d, QObject* parent = 0 );
654  //@endcond
655 
656 private:
657  //@cond PRIVATE
658  // Make these private, they shouldn't be called by applications
659  virtual bool insertRows( int , int, const QModelIndex& = QModelIndex() );
660  virtual bool insertColumns( int, int, const QModelIndex& = QModelIndex() );
661  virtual bool removeColumns( int, int, const QModelIndex& = QModelIndex() );
662  virtual bool removeRows( int, int, const QModelIndex & = QModelIndex() );
663 
664  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionStatisticsChanged( Akonadi::Collection::Id,
665  const Akonadi::CollectionStatistics& ) )
666 
667  Q_PRIVATE_SLOT( d_func(), void startFirstListJob() )
668  Q_PRIVATE_SLOT( d_func(), void serverStarted() )
669 
670  Q_PRIVATE_SLOT( d_func(), void fetchJobDone( KJob *job ) )
671  Q_PRIVATE_SLOT( d_func(), void rootFetchJobDone( KJob *job ) )
672  Q_PRIVATE_SLOT( d_func(), void pasteJobDone( KJob *job ) )
673  Q_PRIVATE_SLOT( d_func(), void updateJobDone( KJob *job ) )
674  Q_PRIVATE_SLOT( d_func(), void firstFetchJobDone( KJob *job ) )
675 
676  Q_PRIVATE_SLOT( d_func(), void itemsFetched( Akonadi::Item::List ) )
677  Q_PRIVATE_SLOT( d_func(), void itemsFetched( KJob* ) )
678  Q_PRIVATE_SLOT( d_func(), void collectionsFetched( Akonadi::Collection::List ) )
679  Q_PRIVATE_SLOT( d_func(), void allCollectionsFetched( Akonadi::Collection::List ) )
680  Q_PRIVATE_SLOT( d_func(), void firstCollectionsFetched( Akonadi::Collection::List ) )
681  Q_PRIVATE_SLOT( d_func(), void collectionListFetched( Akonadi::Collection::List ) )
682  Q_PRIVATE_SLOT( d_func(), void topLevelCollectionsFetched( Akonadi::Collection::List ) )
683  Q_PRIVATE_SLOT( d_func(), void ancestorsFetched( Akonadi::Collection::List ) )
684 
685  Q_PRIVATE_SLOT( d_func(), void monitoredMimeTypeChanged( const QString&, bool ) )
686  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionsChanged( const Akonadi::Collection&, bool ) )
687  Q_PRIVATE_SLOT( d_func(), void monitoredItemsChanged( const Akonadi::Item&, bool ) )
688  Q_PRIVATE_SLOT( d_func(), void monitoredResourcesChanged( const QByteArray&, bool ) )
689 
690  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionAdded( const Akonadi::Collection&, const Akonadi::Collection& ) )
691  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionRemoved( const Akonadi::Collection& ) )
692  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionChanged( const Akonadi::Collection& ) )
693  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionMoved( const Akonadi::Collection&, const Akonadi::Collection&,
694  const Akonadi::Collection&) )
695  Q_PRIVATE_SLOT( d_func(), void collectionSubscribed( const Akonadi::Collection&, const Akonadi::Collection& ) )
696  Q_PRIVATE_SLOT( d_func(), void monitoredCollectionUnsubscribed( const Akonadi::Collection& ) )
697 
698  Q_PRIVATE_SLOT( d_func(), void monitoredItemAdded( const Akonadi::Item&, const Akonadi::Collection& ) )
699  Q_PRIVATE_SLOT( d_func(), void monitoredItemRemoved( const Akonadi::Item& ) )
700  Q_PRIVATE_SLOT( d_func(), void monitoredItemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) )
701  Q_PRIVATE_SLOT( d_func(), void monitoredItemMoved( const Akonadi::Item&, const Akonadi::Collection&,
702  const Akonadi::Collection& ) )
703 
704  Q_PRIVATE_SLOT( d_func(), void monitoredItemLinked( const Akonadi::Item&, const Akonadi::Collection& ) )
705  Q_PRIVATE_SLOT( d_func(), void monitoredItemUnlinked( const Akonadi::Item&, const Akonadi::Collection& ) )
706  Q_PRIVATE_SLOT( d_func(), void changeFetchState( const Akonadi::Collection & ) )
707 
708  Q_PRIVATE_SLOT( d_func(), void agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ) )
709  Q_PRIVATE_SLOT( d_func(), void agentInstanceRemoved( Akonadi::AgentInstance ) )
710  Q_PRIVATE_SLOT( d_func(), void monitoredItemsRetrieved(KJob* job) )
711  //@endcond
712 };
713 
714 } // namespace
715 
716 #endif
Akonadi::EntityTreeModel::LoadedPartsRole
Parts available in the model for the item.
Definition: entitytreemodel.h:342
Akonadi::EntityTreeModel::UnreadCountRole
Returns the number of unread items in a collection.
Definition: entitytreemodel.h:349
Akonadi::EntityTreeModel::EntityTreeHeaders
Header information for a tree with collections and items.
Definition: entitytreemodel.h:382
Akonadi::EntityTreeModel::CollectionRefRole
Definition: entitytreemodel.h:345
Akonadi::CollectionStatistics
Provides statistics information of a Collection.
Definition: collectionstatistics.h:69
Akonadi::EntityTreeModel::FetchStateRole
Returns the FetchState of a particular item.
Definition: entitytreemodel.h:350
Akonadi::EntityTreeModel::ItemPopulationStrategy
ItemPopulationStrategy
Describes how the model should populated its items.
Definition: entitytreemodel.h:406
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityTreeModel::NoItemPopulation
Do not include items in the model.
Definition: entitytreemodel.h:407
Akonadi::EntityTreeModel::FetchCollectionsRecursive
Fetches collections in the root collection recursively. This is the default.
Definition: entitytreemodel.h:487
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::EntityTreeModel::FetchFirstLevelChildCollections
Fetches first level collections in the root collection.
Definition: entitytreemodel.h:486
Akonadi::EntityTreeModel::IdleState
There is no fetch of items in this collection in progress.
Definition: entitytreemodel.h:373
Akonadi::EntityTreeModel::CollectionSyncProgressRole
Returns the progress of synchronization in percent for a particular collection.
Definition: entitytreemodel.h:351
Akonadi::EntityTreeModel::CollectionTreeHeaders
Header information for a collection-only tree.
Definition: entitytreemodel.h:383
Akonadi::EntityTreeModel::HeaderGroup
HeaderGroup
Describes what header information the model shall return.
Definition: entitytreemodel.h:381
Akonadi::EntityTreeModel::IsPopulatedRole
Returns whether a Collection has been populated, i.e. whether its items have been fetched...
Definition: entitytreemodel.h:352
Akonadi::EntityTreeModel::AmazingCompletionRole
Role used to implement amazing completion.
Definition: entitytreemodel.h:339
Akonadi::EntityTreeModel::ParentCollectionRole
The parent collection of the entity.
Definition: entitytreemodel.h:340
Akonadi::EntityTreeModel::RemoteIdRole
The remoteId of the entity.
Definition: entitytreemodel.h:337
Akonadi::EntityTreeModel::ImmediatePopulation
Retrieve items immediately when their parent is in the model. This is the default.
Definition: entitytreemodel.h:408
Akonadi::EntityTreeModel::FetchNoCollections
Fetches nothing. This creates an empty model.
Definition: entitytreemodel.h:485
Akonadi::EntityTreeModel::ItemListHeaders
Header information for a list of items.
Definition: entitytreemodel.h:384
Akonadi::EntityTreeModel::AvailablePartsRole
Parts available in the Akonadi server for the item.
Definition: entitytreemodel.h:343
Akonadi::EntityTreeModel
A model for collections and items together.
Definition: entitytreemodel.h:317
Akonadi::EntityTreeModel::PendingCutRole
Definition: entitytreemodel.h:347
Akonadi::EntityTreeModel::ColumnCountRole
Definition: entitytreemodel.h:341
Akonadi::EntityTreeModel::Roles
Roles
Describes the roles for items.
Definition: entitytreemodel.h:325
Akonadi::EntityTreeModelPrivate
Definition: entitytreemodel_p.h:61
Akonadi::AgentInstance
A representation of an agent instance.
Definition: agentinstance.h:62
Akonadi::EntityTreeModel::FetchState
FetchState
Describes the state of fetch jobs related to particular collections.
Definition: entitytreemodel.h:372
Akonadi::EntityTreeModel::CollectionChildOrderRole
Ordered list of child items if available.
Definition: entitytreemodel.h:338
Akonadi::EntityTreeModel::EntityUrlRole
The akonadi:/ Url of the entity as a string. Item urls will contain the mimetype. ...
Definition: entitytreemodel.h:348
Akonadi::EntityTreeModel::CollectionFetchStrategy
CollectionFetchStrategy
Describes what collections shall be fetched by and represent in the model.
Definition: entitytreemodel.h:484
Akonadi::EntityTreeModel::SessionRole
Definition: entitytreemodel.h:344
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::EntityTreeModel::CollectionDerefRole
Definition: entitytreemodel.h:346
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal