diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/domain/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/domain/accountsmodel.cpp | 65 | ||||
-rw-r--r-- | framework/domain/accountsmodel.h | 48 | ||||
-rw-r--r-- | framework/domain/folderlistmodel.cpp | 34 | ||||
-rw-r--r-- | framework/domain/folderlistmodel.h | 10 | ||||
-rw-r--r-- | framework/domain/mailplugin.cpp | 2 |
6 files changed, 158 insertions, 2 deletions
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index 7560219f..435db5cf 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -14,6 +14,7 @@ set(mailplugin_SRCS | |||
14 | retriever.cpp | 14 | retriever.cpp |
15 | accountfactory.cpp | 15 | accountfactory.cpp |
16 | accountscontroller.cpp | 16 | accountscontroller.cpp |
17 | accountsmodel.cpp | ||
17 | ) | 18 | ) |
18 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") | 19 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") |
19 | 20 | ||
diff --git a/framework/domain/accountsmodel.cpp b/framework/domain/accountsmodel.cpp new file mode 100644 index 00000000..96306464 --- /dev/null +++ b/framework/domain/accountsmodel.cpp | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.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 | #include "accountsmodel.h" | ||
20 | |||
21 | #include <settings/settings.h> | ||
22 | |||
23 | #include <QVariant> | ||
24 | |||
25 | AccountsModel::AccountsModel(QObject *parent) : QAbstractListModel() | ||
26 | { | ||
27 | Kube::Settings settings("accounts"); | ||
28 | mAccounts = settings.property("accounts").toStringList(); | ||
29 | } | ||
30 | |||
31 | AccountsModel::~AccountsModel() | ||
32 | { | ||
33 | |||
34 | } | ||
35 | |||
36 | QHash< int, QByteArray > AccountsModel::roleNames() const | ||
37 | { | ||
38 | QHash<int, QByteArray> roles; | ||
39 | |||
40 | roles[Name] = "name"; | ||
41 | roles[Icon] = "icon"; | ||
42 | roles[AccountId] = "accountId"; | ||
43 | |||
44 | return roles; | ||
45 | } | ||
46 | |||
47 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const | ||
48 | { | ||
49 | const auto identifier = mAccounts.at(idx.row()); | ||
50 | Kube::Account accountSettings(identifier.toLatin1()); | ||
51 | switch (role) { | ||
52 | case Name: | ||
53 | return accountSettings.property("name").toString(); | ||
54 | case Icon: | ||
55 | return accountSettings.property("icon").toString(); | ||
56 | case AccountId: | ||
57 | return identifier; | ||
58 | } | ||
59 | return QVariant(); | ||
60 | } | ||
61 | |||
62 | int AccountsModel::rowCount(const QModelIndex &idx) const | ||
63 | { | ||
64 | return mAccounts.size(); | ||
65 | } | ||
diff --git a/framework/domain/accountsmodel.h b/framework/domain/accountsmodel.h new file mode 100644 index 00000000..a50c2e4a --- /dev/null +++ b/framework/domain/accountsmodel.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.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 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | #include <QAbstractListModel> | ||
24 | #include <QSharedPointer> | ||
25 | #include <QStringList> | ||
26 | |||
27 | class AccountsModel : public QAbstractListModel | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | |||
31 | public: | ||
32 | AccountsModel(QObject *parent = Q_NULLPTR); | ||
33 | ~AccountsModel(); | ||
34 | |||
35 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | ||
36 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | ||
37 | |||
38 | enum Roles { | ||
39 | Name = Qt::UserRole + 1, | ||
40 | Icon, | ||
41 | AccountId | ||
42 | }; | ||
43 | Q_ENUMS(Roles) | ||
44 | |||
45 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | ||
46 | private: | ||
47 | QStringList mAccounts; | ||
48 | }; | ||
diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index ce6fb4fd..f212e336 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "folderlistmodel.h" | 21 | #include "folderlistmodel.h" |
22 | #include <sink/store.h> | 22 | #include <sink/store.h> |
23 | #include <settings/settings.h> | ||
23 | 24 | ||
24 | FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() | 25 | FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() |
25 | { | 26 | { |
@@ -27,8 +28,7 @@ FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() | |||
27 | query.liveQuery = true; | 28 | query.liveQuery = true; |
28 | query.requestedProperties << "name" << "icon" << "parent"; | 29 | query.requestedProperties << "name" << "icon" << "parent"; |
29 | query.parentProperty = "parent"; | 30 | query.parentProperty = "parent"; |
30 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | 31 | runQuery(query); |
31 | setSourceModel(mModel.data()); | ||
32 | } | 32 | } |
33 | 33 | ||
34 | FolderListModel::~FolderListModel() | 34 | FolderListModel::~FolderListModel() |
@@ -63,3 +63,33 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const | |||
63 | } | 63 | } |
64 | return QIdentityProxyModel::data(idx, role); | 64 | return QIdentityProxyModel::data(idx, role); |
65 | } | 65 | } |
66 | |||
67 | void FolderListModel::runQuery(const Sink::Query &query) | ||
68 | { | ||
69 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); | ||
70 | setSourceModel(mModel.data()); | ||
71 | } | ||
72 | |||
73 | void FolderListModel::setAccountId(const QVariant &accountId) | ||
74 | { | ||
75 | const auto account = accountId.toString(); | ||
76 | Kube::Account accountSettings(account.toUtf8()); | ||
77 | //FIXME maildirResource is obviously not good. We need a way to find resources that belong to the account and provide folders. | ||
78 | const auto resourceId = accountSettings.property("maildirResource").toString(); | ||
79 | qDebug() << "Running query for account " << account; | ||
80 | qDebug() << "Found resources " << resourceId; | ||
81 | |||
82 | Sink::Query query; | ||
83 | query.liveQuery = true; | ||
84 | query.requestedProperties << "name" << "icon" << "parent"; | ||
85 | query.parentProperty = "parent"; | ||
86 | query.resources << resourceId.toUtf8(); | ||
87 | |||
88 | runQuery(query); | ||
89 | } | ||
90 | |||
91 | QVariant FolderListModel::accountId() const | ||
92 | { | ||
93 | return QVariant(); | ||
94 | } | ||
95 | |||
diff --git a/framework/domain/folderlistmodel.h b/framework/domain/folderlistmodel.h index 7844e59a..d30393db 100644 --- a/framework/domain/folderlistmodel.h +++ b/framework/domain/folderlistmodel.h | |||
@@ -25,10 +25,16 @@ | |||
25 | #include <QSharedPointer> | 25 | #include <QSharedPointer> |
26 | #include <QStringList> | 26 | #include <QStringList> |
27 | 27 | ||
28 | namespace Sink { | ||
29 | class Query; | ||
30 | } | ||
31 | |||
28 | class FolderListModel : public QIdentityProxyModel | 32 | class FolderListModel : public QIdentityProxyModel |
29 | { | 33 | { |
30 | Q_OBJECT | 34 | Q_OBJECT |
31 | 35 | ||
36 | Q_PROPERTY (QVariant accountId READ accountId WRITE setAccountId) | ||
37 | |||
32 | public: | 38 | public: |
33 | FolderListModel(QObject *parent = Q_NULLPTR); | 39 | FolderListModel(QObject *parent = Q_NULLPTR); |
34 | ~FolderListModel(); | 40 | ~FolderListModel(); |
@@ -45,6 +51,10 @@ public: | |||
45 | 51 | ||
46 | QHash<int, QByteArray> roleNames() const; | 52 | QHash<int, QByteArray> roleNames() const; |
47 | 53 | ||
54 | void setAccountId(const QVariant &accountId); | ||
55 | QVariant accountId() const; | ||
56 | |||
48 | private: | 57 | private: |
58 | void runQuery(const Sink::Query &query); | ||
49 | QSharedPointer<QAbstractItemModel> mModel; | 59 | QSharedPointer<QAbstractItemModel> mModel; |
50 | }; | 60 | }; |
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index c19818ec..9f06fd5f 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "retriever.h" | 27 | #include "retriever.h" |
28 | #include "accountfactory.h" | 28 | #include "accountfactory.h" |
29 | #include "accountscontroller.h" | 29 | #include "accountscontroller.h" |
30 | #include "accountsmodel.h" | ||
30 | 31 | ||
31 | #include <QtQml> | 32 | #include <QtQml> |
32 | 33 | ||
@@ -41,4 +42,5 @@ void MailPlugin::registerTypes (const char *uri) | |||
41 | qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); | 42 | qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); |
42 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); | 43 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); |
43 | qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController"); | 44 | qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController"); |
45 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); | ||
44 | } | 46 | } |