summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/settings/resourcelistmodel.cpp42
-rw-r--r--framework/settings/resourcelistmodel.h26
-rw-r--r--framework/settings/resourcescontroller.cpp12
-rw-r--r--framework/settings/resourcescontroller.h20
4 files changed, 100 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
5ResourceListModel::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
15ResourceListModel::~ResourceListModel()
16{
17
18}
19
20QHash< 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
30QVariant 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
diff --git a/framework/settings/resourcelistmodel.h b/framework/settings/resourcelistmodel.h
new file mode 100644
index 00000000..de1b5a51
--- /dev/null
+++ b/framework/settings/resourcelistmodel.h
@@ -0,0 +1,26 @@
1#pragma once
2
3#include <QIdentityProxyModel>
4#include <QSharedPointer>
5#include <QStringList>
6
7class ResourceListModel : public QIdentityProxyModel
8{
9 Q_OBJECT
10
11public:
12 ResourceListModel(QObject *parent = Q_NULLPTR);
13 ~ResourceListModel();
14
15 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
16
17 enum Roles {
18 Id = Qt::UserRole + 1,
19 Type
20 };
21
22 QHash<int, QByteArray> roleNames() const;
23
24private:
25 QSharedPointer<QAbstractItemModel> m_model;
26};
diff --git a/framework/settings/resourcescontroller.cpp b/framework/settings/resourcescontroller.cpp
new file mode 100644
index 00000000..03016b67
--- /dev/null
+++ b/framework/settings/resourcescontroller.cpp
@@ -0,0 +1,12 @@
1#include "resourcescontroller.h"
2
3ResourcesController::ResourcesController(QObject *parent) : QObject(parent), m_model(new ResourceListModel())
4{
5
6}
7
8
9ResourceListModel* ResourcesController::model() const
10{
11 return m_model.data();
12}
diff --git a/framework/settings/resourcescontroller.h b/framework/settings/resourcescontroller.h
new file mode 100644
index 00000000..0e2e89de
--- /dev/null
+++ b/framework/settings/resourcescontroller.h
@@ -0,0 +1,20 @@
1#pragma once
2
3#include "resourcelistmodel.h"
4
5#include <QObject>
6#include <QScopedPointer>
7
8class ResourcesController : public QObject
9{
10 Q_OBJECT
11 Q_PROPERTY (ResourceListModel *model READ model CONSTANT)
12
13public:
14 explicit ResourcesController(QObject *parent = Q_NULLPTR);
15
16 ResourceListModel *model() const;
17
18private:
19 QScopedPointer<ResourceListModel> m_model;
20};