Akonadi

favoritecollectionsmodel.h
1/*
2 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadicore_export.h"
10#include "collection.h"
11#include <KSelectionProxyModel>
12
13#include <memory>
14
15class KConfigGroup;
16class KJob;
17
18namespace Akonadi
19{
20class EntityTreeModel;
21class FavoriteCollectionsModelPrivate;
22
23/**
24 * @short A model that lists a set of favorite collections.
25 *
26 * In some applications you want to provide fast access to a list
27 * of often used collections (e.g. Inboxes from different email accounts
28 * in a mail application). Therefore you can use the FavoriteCollectionsModel
29 * which stores the list of favorite collections in a given configuration
30 * file.
31 *
32 * Example:
33 *
34 * @code
35 *
36 * using namespace Akonadi;
37 *
38 * EntityTreeModel *sourceModel = new EntityTreeModel( ... );
39 *
40 * const KConfigGroup group = KGlobal::config()->group( "Favorite Collections" );
41 *
42 * FavoriteCollectionsModel *model = new FavoriteCollectionsModel( sourceModel, group, this );
43 *
44 * EntityListView *view = new EntityListView( this );
45 * view->setModel( model );
46 *
47 * @endcode
48 *
49 * @author Kevin Ottens <ervin@kde.org>
50 * @since 4.4
51 */
52class AKONADICORE_EXPORT FavoriteCollectionsModel : public KSelectionProxyModel
53{
54 Q_OBJECT
55
56public:
57 /**
58 * Creates a new favorite collections model.
59 *
60 * @param model The source model where the favorite collections
61 * come from.
62 * @param group The config group that shall be used to save the
63 * selection of favorite collections.
64 * @param parent The parent object.
65 */
66 FavoriteCollectionsModel(QAbstractItemModel *model, const KConfigGroup &group, QObject *parent = nullptr);
67
68 /**
69 * Destroys the favorite collections model.
70 */
72
73 /**
74 * Returns the list of favorite collections.
75 * @deprecated Use collectionIds instead.
76 */
77 [[nodiscard]] AKONADICORE_DEPRECATED Collection::List collections() const;
78
79 /**
80 * Returns the list of ids of favorite collections set on the FavoriteCollectionsModel.
81 *
82 * Note that if you want Collections with actual data
83 * you should use something like this instead:
84 *
85 * @code
86 * FavoriteCollectionsModel* favs = getFavsModel();
87 * Collection::List cols;
88 * const int rowCount = favs->rowCount();
89 * for (int row = 0; row < rowcount; ++row) {
90 * static const int column = 0;
91 * const QModelIndex index = favs->index(row, column);
92 * const Collection col = index.data(EntityTreeModel::CollectionRole).value<Collection>();
93 * cols << col;
94 * }
95 * @endcode
96 *
97 * Note that due to the asynchronous nature of the model, this method returns collection ids
98 * of collections which may not be in the model yet. If you want the ids of the collections
99 * that are actually in the model, use a loop similar to above with the CollectionIdRole.
100 */
101 [[nodiscard]] QList<Collection::Id> collectionIds() const;
102
103 /**
104 * Return associate label for collection
105 */
106 [[nodiscard]] QString favoriteLabel(const Akonadi::Collection &col);
107 [[nodiscard]] QString defaultFavoriteLabel(const Akonadi::Collection &col);
108
109 [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
110 [[nodiscard]] bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
111 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
112 [[nodiscard]] bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
113 [[nodiscard]] QStringList mimeTypes() const override;
114 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
115
116public Q_SLOTS:
117 /**
118 * Sets the @p collections as favorite collections.
119 */
120 void setCollections(const Akonadi::Collection::List &collections);
121
122 /**
123 * Adds a @p collection to the list of favorite collections.
124 */
125 void addCollection(const Akonadi::Collection &collection);
126
127 /**
128 * Removes a @p collection from the list of favorite collections.
129 */
130 void removeCollection(const Akonadi::Collection &collection);
131
132 /**
133 * Sets a custom @p label that will be used when showing the
134 * favorite @p collection.
135 */
136 void setFavoriteLabel(const Akonadi::Collection &collection, const QString &label);
137
138private:
139 AKONADICORE_NO_EXPORT void pasteJobDone(KJob *job);
140 /// @cond PRIVATE
142
143 std::unique_ptr<FavoriteCollectionsModelPrivate> const d;
144 /// @endcond
145};
146
147}
Represents a collection of PIM items.
Definition collection.h:62
A model that lists a set of favorite collections.
~FavoriteCollectionsModel() override
Destroys the favorite collections model.
void setSourceModel(QAbstractItemModel *sourceModel) override
Helper integration between Akonadi and Qt.
DropAction
DisplayRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.