diff options
Diffstat (limited to 'framework/settings/resourcelistmodel.cpp')
-rw-r--r-- | framework/settings/resourcelistmodel.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/framework/settings/resourcelistmodel.cpp b/framework/settings/resourcelistmodel.cpp new file mode 100644 index 00000000..ebeaac32 --- /dev/null +++ b/framework/settings/resourcelistmodel.cpp | |||
@@ -0,0 +1,42 @@ | |||
1 | #include "resourcelistmodel.h" | ||
2 | |||
3 | #include <akonadi2common/clientapi.h> | ||
4 | |||
5 | ResourceListModel::ResourceListModel(QObject *parent) : QIdentityProxyModel() | ||
6 | { | ||
7 | Akonadi2::Query query; | ||
8 | query.syncOnDemand = false; | ||
9 | query.processAll = false; | ||
10 | query.liveQuery = true; | ||
11 | query.requestedProperties << "type"; | ||
12 | m_model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::AkonadiResource>(query); | ||
13 | } | ||
14 | |||
15 | ResourceListModel::~ResourceListModel() | ||
16 | { | ||
17 | |||
18 | } | ||
19 | |||
20 | QHash< int, QByteArray > ResourceListModel::roleNames() const | ||
21 | { | ||
22 | QHash<int, QByteArray> roles; | ||
23 | |||
24 | roles[Type] = "type"; | ||
25 | roles[Id] = "id"; | ||
26 | |||
27 | return roles; | ||
28 | } | ||
29 | |||
30 | QVariant ResourceListModel::data(const QModelIndex& index, int role) const | ||
31 | { | ||
32 | auto srcIdx = mapToSource(index); | ||
33 | switch (role) { | ||
34 | case Id: | ||
35 | return srcIdx.data(Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); | ||
36 | case Type: | ||
37 | return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); | ||
38 | } | ||
39 | |||
40 | return QIdentityProxyModel::data(index, role); | ||
41 | } | ||
42 | |||