Akonadi

entitytreemodel.h
1 /*
2  SPDX-FileCopyrightText: 2008 Stephen Kelly <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef AKONADI_ENTITYTREEMODEL_H
8 #define AKONADI_ENTITYTREEMODEL_H
9 
10 #include "akonadicore_export.h"
11 #include "collection.h"
12 #include "collectionfetchscope.h"
13 #include "item.h"
14 
15 #include <QAbstractItemModel>
16 #include <QStringList>
17 
18 namespace Akonadi
19 {
20 
21 class CollectionStatistics;
22 class Item;
23 class ItemFetchScope;
24 class Monitor;
25 class Session;
26 
27 class EntityTreeModelPrivate;
28 
303 class AKONADICORE_EXPORT EntityTreeModel : public QAbstractItemModel
304 {
305  Q_OBJECT
306 
307 public:
311  enum Roles {
312  //sebsauer, 2009-05-07; to be able here to keep the akonadi_next EntityTreeModel compatible with
313  //the akonadi_old ItemModel and CollectionModel, we need to use the same int-values for
314  //ItemRole, ItemIdRole and MimeTypeRole like the Akonadi::ItemModel is using and the same
315  //CollectionIdRole and CollectionRole like the Akonadi::CollectionModel is using.
316  ItemIdRole = Qt::UserRole + 1,
317  ItemRole = Qt::UserRole + 2,
318  MimeTypeRole = Qt::UserRole + 3,
319 
320  CollectionIdRole = Qt::UserRole + 10,
321  CollectionRole = Qt::UserRole + 11,
322 
338  UserRole = Qt::UserRole + 500,
339  TerminalUserRole = 2000,
340  EndRole = 65535
341  };
342 
357  enum FetchState {
359  FetchingState
360  // TODO: Change states for reporting of fetching payload parts of items.
361  };
362 
366  enum HeaderGroup {
370  UserHeaders = 10,
371  EndHeaderGroup = 32
372  // Note that we're splitting up available roles for the header data hack and int(EndRole / TerminalUserRole) == 32
373  };
374 
381  explicit EntityTreeModel(Monitor *monitor, QObject *parent = nullptr);
382 
386  ~EntityTreeModel() override;
387 
394  LazyPopulation
395  };
396 
404  void setShowSystemEntities(bool show);
405 
409  Q_REQUIRED_RESULT bool systemEntitiesShown() const;
410 
416  Q_REQUIRED_RESULT Akonadi::CollectionFetchScope::ListFilter listFilter() const;
417 
423  void setListFilter(Akonadi::CollectionFetchScope::ListFilter filter);
424 
430  void setCollectionsMonitored(const Akonadi::Collection::List &collections);
431 
439  void setCollectionMonitored(const Akonadi::Collection &col, bool monitored = true);
440 
444  void setItemPopulationStrategy(ItemPopulationStrategy strategy);
445 
449  Q_REQUIRED_RESULT ItemPopulationStrategy itemPopulationStrategy() const;
450 
456  void setIncludeRootCollection(bool include);
457 
461  Q_REQUIRED_RESULT bool includeRootCollection() const;
462 
470  void setRootCollectionDisplayName(const QString &name);
471 
475  Q_REQUIRED_RESULT QString rootCollectionDisplayName() const;
476 
484  InvisibleCollectionFetch
485  };
486 
490  void setCollectionFetchStrategy(CollectionFetchStrategy strategy);
491 
495  Q_REQUIRED_RESULT CollectionFetchStrategy collectionFetchStrategy() const;
496 
497  Q_REQUIRED_RESULT QHash<int, QByteArray> roleNames() const override;
498 
499  Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent = QModelIndex()) const override;
500  Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent = QModelIndex()) const override;
501 
502  Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
503  Q_REQUIRED_RESULT QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
504 
505  Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
506  Q_REQUIRED_RESULT QStringList mimeTypes() const override;
507 
508  Q_REQUIRED_RESULT Qt::DropActions supportedDropActions() const override;
509  Q_REQUIRED_RESULT QMimeData *mimeData(const QModelIndexList &indexes) const override;
510  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
511  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
512 
513  Q_REQUIRED_RESULT QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
514  Q_REQUIRED_RESULT QModelIndex parent(const QModelIndex &index) const override;
515 
516  // TODO: Review the implementations of these. I think they could be better.
517  Q_REQUIRED_RESULT bool canFetchMore(const QModelIndex &parent) const override;
518  void fetchMore(const QModelIndex &parent) override;
519  Q_REQUIRED_RESULT bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
520 
527  Q_REQUIRED_RESULT bool isCollectionTreeFetched() const;
528 
535  Q_REQUIRED_RESULT bool isCollectionPopulated(Akonadi::Collection::Id) const;
536 
546  Q_REQUIRED_RESULT bool isFullyPopulated() const;
547 
551  Q_REQUIRED_RESULT QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override;
552 
583  static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection);
584 
593  static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item);
594 
601  static Collection updatedCollection(const QAbstractItemModel *model, qint64 collectionId);
602  static Collection updatedCollection(const QAbstractItemModel *model, const Collection &col);
603 
604 Q_SIGNALS:
612  void collectionTreeFetched(const Akonadi::Collection::List &collections);
613 
621  void collectionPopulated(Akonadi::Collection::Id collectionId);
630  void collectionFetched(int collectionId);
631 
632 protected:
637  void clearAndReset();
638 
642  virtual QVariant entityData(const Item &item, int column, int role = Qt::DisplayRole) const;
643 
647  virtual QVariant entityData(const Collection &collection, int column, int role = Qt::DisplayRole) const;
648 
653  virtual QVariant entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const;
654 
655  virtual int entityColumnCount(HeaderGroup headerGroup) const;
656 
657 protected:
658  //@cond PRIVATE
659  Q_DECLARE_PRIVATE(EntityTreeModel)
660  EntityTreeModelPrivate *d_ptr;
661  EntityTreeModel(Monitor *monitor, EntityTreeModelPrivate *d, QObject *parent = nullptr);
662  //@endcond
663 
664 private:
665  //@cond PRIVATE
666  // Make these private, they shouldn't be called by applications
667  bool insertRows(int row, int count, const QModelIndex &index = QModelIndex()) override;
668  bool insertColumns(int column, int count, const QModelIndex &index = QModelIndex()) override;
669  bool removeColumns(int column, int count, const QModelIndex &index = QModelIndex()) override;
670  bool removeRows(int row, int count, const QModelIndex &index = QModelIndex()) override;
671 
672  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionStatisticsChanged(Akonadi::Collection::Id,
673  const Akonadi::CollectionStatistics &))
674 
675  Q_PRIVATE_SLOT(d_func(), void startFirstListJob())
676  Q_PRIVATE_SLOT(d_func(), void serverStarted())
677 
678  Q_PRIVATE_SLOT(d_func(), void collectionFetchJobDone(KJob *job))
679  Q_PRIVATE_SLOT(d_func(), void rootFetchJobDone(KJob *job))
680  Q_PRIVATE_SLOT(d_func(), void pasteJobDone(KJob *job))
681  Q_PRIVATE_SLOT(d_func(), void updateJobDone(KJob *job))
682 
683  Q_PRIVATE_SLOT(d_func(), void collectionsFetched(Akonadi::Collection::List))
684  Q_PRIVATE_SLOT(d_func(), void topLevelCollectionsFetched(Akonadi::Collection::List))
685  Q_PRIVATE_SLOT(d_func(), void ancestorsFetched(Akonadi::Collection::List))
686 
687  Q_PRIVATE_SLOT(d_func(), void monitoredMimeTypeChanged(const QString &, bool))
688  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionsChanged(const Akonadi::Collection &, bool))
689  Q_PRIVATE_SLOT(d_func(), void monitoredItemsChanged(const Akonadi::Item &, bool))
690  Q_PRIVATE_SLOT(d_func(), void monitoredResourcesChanged(const QByteArray &, bool))
691 
692  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionAdded(const Akonadi::Collection &, const Akonadi::Collection &))
693  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionRemoved(const Akonadi::Collection &))
694  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionChanged(const Akonadi::Collection &))
695  Q_PRIVATE_SLOT(d_func(), void monitoredCollectionMoved(const Akonadi::Collection &, const Akonadi::Collection &,
696  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 agentInstanceRemoved(Akonadi::AgentInstance))
709  Q_PRIVATE_SLOT(d_func(), void monitoredItemsRetrieved(KJob *job))
710  //@endcond
711 };
712 
713 } // namespace
714 
715 #endif
Parts available in the model for the item.
Returns the number of unread items in a collection.
typedef MatchFlags
Header information for a tree with collections and items.
Provides statistics information of a Collection.
Returns the FetchState of a particular item.
ItemPopulationStrategy
Describes how the model should populated its items.
Represents a collection of PIM items.
Definition: collection.h:63
Do not include items in the model.
qint64 Id
Describes the unique id type.
Definition: collection.h:69
Fetches collections in the root collection recursively. This is the default.
Fetches first level collections in the root collection.
There is no fetch of items in this collection in progress.
Header information for a collection-only tree.
ListFilter
Describes the list filter.
HeaderGroup
Describes what header information the model shall return.
Returns whether a Collection has been populated, i.e. whether its items have been fetched...
UserRole
The parent collection of the entity.
The remoteId of the entity.
Retrieve items immediately when their parent is in the model. This is the default.
Returns original name for collection.
Fetches nothing. This creates an empty model.
Monitors an item or collection for changes.
Definition: monitor.h:71
Header information for a list of items.
Parts available in the Akonadi server for the item.
ASAP CLI session.
Helper integration between Akonadi and Qt.
A model for collections and items together.
Used to indicate items which are to be cut.
Roles
Describes the roles for items.
A representation of an agent instance.
Orientation
FetchState
Describes the state of fetch jobs related to particular collections.
Ordered list of child items if available.
The akonadi:/ Url of the entity as a string. Item urls will contain the mimetype. ...
CollectionFetchStrategy
Describes what collections shall be fetched by and represent in the model.
typedef DropActions
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 2 2020 23:14:26 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.