diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/domain/accountfactory.cpp | 19 | ||||
-rw-r--r-- | framework/domain/accountfactory.h | 3 | ||||
-rw-r--r-- | framework/domain/accountscontroller.cpp | 29 | ||||
-rw-r--r-- | framework/domain/accountscontroller.h | 10 | ||||
-rw-r--r-- | framework/domain/accountsmodel.cpp | 29 | ||||
-rw-r--r-- | framework/domain/accountsmodel.h | 17 | ||||
-rw-r--r-- | framework/domain/folderlistmodel.cpp | 27 |
7 files changed, 64 insertions, 70 deletions
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp index ab1a09e5..10f01f65 100644 --- a/framework/domain/accountfactory.cpp +++ b/framework/domain/accountfactory.cpp | |||
@@ -25,20 +25,29 @@ | |||
25 | #include <KPluginMetaData> | 25 | #include <KPluginMetaData> |
26 | 26 | ||
27 | #include "settings/settings.h" | 27 | #include "settings/settings.h" |
28 | #include <sink/store.h> | ||
28 | 29 | ||
29 | AccountFactory::AccountFactory(QObject *parent) | 30 | AccountFactory::AccountFactory(QObject *parent) |
30 | : QObject(parent) | 31 | : QObject(parent) |
31 | { | 32 | { |
32 | } | 33 | } |
33 | 34 | ||
35 | QString AccountFactory::name() const | ||
36 | { | ||
37 | if (mName.isEmpty()) { | ||
38 | return tr("Account"); | ||
39 | } | ||
40 | return mName; | ||
41 | } | ||
42 | |||
34 | void AccountFactory::setAccountId(const QString &accountId) | 43 | void AccountFactory::setAccountId(const QString &accountId) |
35 | { | 44 | { |
36 | mAccountId = accountId; | 45 | mAccountId = accountId; |
37 | 46 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(accountId.toUtf8())) | |
38 | Kube::Account account(mAccountId.toUtf8()); | 47 | .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { |
39 | mAccountType = account.type(); | 48 | mAccountType = account.getProperty("type").toByteArray(); |
40 | 49 | loadPackage(); | |
41 | loadPackage(); | 50 | }).exec(); |
42 | } | 51 | } |
43 | 52 | ||
44 | void AccountFactory::loadPackage() | 53 | void AccountFactory::loadPackage() |
diff --git a/framework/domain/accountfactory.h b/framework/domain/accountfactory.h index ed3c21d9..047454ae 100644 --- a/framework/domain/accountfactory.h +++ b/framework/domain/accountfactory.h | |||
@@ -29,13 +29,14 @@ class AccountFactory : public QObject | |||
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); | 31 | Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); |
32 | Q_PROPERTY(QString name MEMBER mName NOTIFY accountLoaded); | 32 | Q_PROPERTY(QString name MEMBER mName READ name NOTIFY accountLoaded); |
33 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); | 33 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); |
34 | Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); | 34 | Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); |
35 | public: | 35 | public: |
36 | explicit AccountFactory(QObject *parent = Q_NULLPTR); | 36 | explicit AccountFactory(QObject *parent = Q_NULLPTR); |
37 | 37 | ||
38 | void setAccountId(const QString &); | 38 | void setAccountId(const QString &); |
39 | QString name() const; | ||
39 | 40 | ||
40 | signals: | 41 | signals: |
41 | void accountLoaded(); | 42 | void accountLoaded(); |
diff --git a/framework/domain/accountscontroller.cpp b/framework/domain/accountscontroller.cpp index 1be03ba9..b5e7e9ca 100644 --- a/framework/domain/accountscontroller.cpp +++ b/framework/domain/accountscontroller.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "accountscontroller.h" | 21 | #include "accountscontroller.h" |
22 | 22 | ||
23 | #include <settings/settings.h> | 23 | #include <settings/settings.h> |
24 | #include <sink/store.h> | ||
24 | 25 | ||
25 | #include <QVariant> | 26 | #include <QVariant> |
26 | #include <QUuid> | 27 | #include <QUuid> |
@@ -28,27 +29,17 @@ | |||
28 | 29 | ||
29 | AccountsController::AccountsController(QObject *parent) : QObject(parent) | 30 | AccountsController::AccountsController(QObject *parent) : QObject(parent) |
30 | { | 31 | { |
31 | Kube::Settings settings("accounts"); | ||
32 | mAccounts = settings.property("accounts").toStringList(); | ||
33 | qWarning() << "Loaded accounts" << mAccounts; | ||
34 | } | 32 | } |
35 | 33 | ||
36 | void AccountsController::createAccount(const QString &accountType) | 34 | void AccountsController::createAccount(const QString &accountType) |
37 | { | 35 | { |
38 | auto identifier = QUuid::createUuid().toByteArray(); | 36 | const auto identifier = QUuid::createUuid().toByteArray(); |
39 | Kube::Account accountSettings(identifier); | 37 | Sink::ApplicationDomain::SinkAccount account; |
40 | accountSettings.setProperty("type", accountType); | 38 | account.setProperty("identifier", identifier); |
41 | accountSettings.save(); | 39 | account.setProperty("type", accountType); |
42 | 40 | Sink::Store::create(account).then<void>([]() {}, | |
43 | Kube::Settings settings("accounts"); | 41 | [](int errorCode, const QString &errorMessage) { |
44 | auto accounts = settings.property("accounts").toStringList(); | 42 | qWarning() << "Error while creating account: " << errorMessage; |
45 | accounts.append(identifier); | 43 | }) |
46 | settings.setProperty("accounts", accounts); | 44 | .exec(); |
47 | settings.save(); | ||
48 | |||
49 | //TODO setup sink resources etc via plugin | ||
50 | |||
51 | qWarning() << "Created account " << identifier; | ||
52 | mAccounts.append(identifier); | ||
53 | emit accountsChanged(); | ||
54 | } | 45 | } |
diff --git a/framework/domain/accountscontroller.h b/framework/domain/accountscontroller.h index 9d98de71..a4421de8 100644 --- a/framework/domain/accountscontroller.h +++ b/framework/domain/accountscontroller.h | |||
@@ -21,23 +21,13 @@ | |||
21 | 21 | ||
22 | #include <QObject> | 22 | #include <QObject> |
23 | #include <QString> | 23 | #include <QString> |
24 | #include <QStringList> | ||
25 | #include <QVariant> | ||
26 | 24 | ||
27 | class AccountsController : public QObject | 25 | class AccountsController : public QObject |
28 | { | 26 | { |
29 | Q_OBJECT | 27 | Q_OBJECT |
30 | Q_PROPERTY (QStringList accounts MEMBER mAccounts NOTIFY accountsChanged) | ||
31 | |||
32 | public: | 28 | public: |
33 | explicit AccountsController(QObject *parent = Q_NULLPTR); | 29 | explicit AccountsController(QObject *parent = Q_NULLPTR); |
34 | 30 | ||
35 | signals: | ||
36 | void accountsChanged(); | ||
37 | |||
38 | public slots: | 31 | public slots: |
39 | void createAccount(const QString &accountId); | 32 | void createAccount(const QString &accountId); |
40 | |||
41 | private: | ||
42 | QStringList mAccounts; | ||
43 | }; | 33 | }; |
diff --git a/framework/domain/accountsmodel.cpp b/framework/domain/accountsmodel.cpp index b5eafd53..8a3ab317 100644 --- a/framework/domain/accountsmodel.cpp +++ b/framework/domain/accountsmodel.cpp | |||
@@ -17,15 +17,14 @@ | |||
17 | 02110-1301, USA. | 17 | 02110-1301, USA. |
18 | */ | 18 | */ |
19 | #include "accountsmodel.h" | 19 | #include "accountsmodel.h" |
20 | #include <sink/store.h> | ||
20 | 21 | ||
21 | #include <settings/settings.h> | 22 | AccountsModel::AccountsModel(QObject *parent) : QIdentityProxyModel() |
22 | |||
23 | #include <QVariant> | ||
24 | |||
25 | AccountsModel::AccountsModel(QObject *parent) : QAbstractListModel() | ||
26 | { | 23 | { |
27 | Kube::Settings settings("accounts"); | 24 | Sink::Query query; |
28 | mAccounts = settings.property("accounts").toStringList(); | 25 | query.liveQuery = true; |
26 | query.requestedProperties << "name" << "icon"; | ||
27 | runQuery(query); | ||
29 | } | 28 | } |
30 | 29 | ||
31 | AccountsModel::~AccountsModel() | 30 | AccountsModel::~AccountsModel() |
@@ -46,20 +45,20 @@ QHash< int, QByteArray > AccountsModel::roleNames() const | |||
46 | 45 | ||
47 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const | 46 | QVariant AccountsModel::data(const QModelIndex &idx, int role) const |
48 | { | 47 | { |
49 | const auto identifier = mAccounts.at(idx.row()); | 48 | auto srcIdx = mapToSource(idx); |
50 | Kube::Account accountSettings(identifier.toLatin1()); | ||
51 | switch (role) { | 49 | switch (role) { |
52 | case Name: | 50 | case Name: |
53 | return accountSettings.property("accountName").toString(); | 51 | return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); |
54 | case Icon: | 52 | case Icon: |
55 | return accountSettings.property("icon").toString(); | 53 | return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); |
56 | case AccountId: | 54 | case AccountId: |
57 | return identifier; | 55 | return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); |
58 | } | 56 | } |
59 | return QVariant(); | 57 | return QIdentityProxyModel::data(idx, role); |
60 | } | 58 | } |
61 | 59 | ||
62 | int AccountsModel::rowCount(const QModelIndex &idx) const | 60 | void AccountsModel::runQuery(const Sink::Query &query) |
63 | { | 61 | { |
64 | return mAccounts.size(); | 62 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::SinkAccount>(query); |
63 | setSourceModel(mModel.data()); | ||
65 | } | 64 | } |
diff --git a/framework/domain/accountsmodel.h b/framework/domain/accountsmodel.h index a50c2e4a..9180bc09 100644 --- a/framework/domain/accountsmodel.h +++ b/framework/domain/accountsmodel.h | |||
@@ -20,11 +20,15 @@ | |||
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include <QObject> | 22 | #include <QObject> |
23 | #include <QAbstractListModel> | 23 | #include <QIdentityProxyModel> |
24 | #include <QSharedPointer> | 24 | #include <QSharedPointer> |
25 | #include <QStringList> | 25 | #include <QStringList> |
26 | 26 | ||
27 | class AccountsModel : public QAbstractListModel | 27 | namespace Sink { |
28 | class Query; | ||
29 | } | ||
30 | |||
31 | class AccountsModel : public QIdentityProxyModel | ||
28 | { | 32 | { |
29 | Q_OBJECT | 33 | Q_OBJECT |
30 | 34 | ||
@@ -32,8 +36,7 @@ public: | |||
32 | AccountsModel(QObject *parent = Q_NULLPTR); | 36 | AccountsModel(QObject *parent = Q_NULLPTR); |
33 | ~AccountsModel(); | 37 | ~AccountsModel(); |
34 | 38 | ||
35 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | 39 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
36 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | ||
37 | 40 | ||
38 | enum Roles { | 41 | enum Roles { |
39 | Name = Qt::UserRole + 1, | 42 | Name = Qt::UserRole + 1, |
@@ -42,7 +45,9 @@ public: | |||
42 | }; | 45 | }; |
43 | Q_ENUMS(Roles) | 46 | Q_ENUMS(Roles) |
44 | 47 | ||
45 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | 48 | QHash<int, QByteArray> roleNames() const; |
49 | |||
46 | private: | 50 | private: |
47 | QStringList mAccounts; | 51 | void runQuery(const Sink::Query &query); |
52 | QSharedPointer<QAbstractItemModel> mModel; | ||
48 | }; | 53 | }; |
diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index f212e336..14d3d5a7 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp | |||
@@ -72,20 +72,19 @@ void FolderListModel::runQuery(const Sink::Query &query) | |||
72 | 72 | ||
73 | void FolderListModel::setAccountId(const QVariant &accountId) | 73 | void FolderListModel::setAccountId(const QVariant &accountId) |
74 | { | 74 | { |
75 | const auto account = accountId.toString(); | 75 | const auto account = accountId.toString().toUtf8(); |
76 | Kube::Account accountSettings(account.toUtf8()); | 76 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(account))) |
77 | //FIXME maildirResource is obviously not good. We need a way to find resources that belong to the account and provide folders. | 77 | .then<void, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([this, account](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) { |
78 | const auto resourceId = accountSettings.property("maildirResource").toString(); | 78 | Sink::Query query; |
79 | qDebug() << "Running query for account " << account; | 79 | query.liveQuery = true; |
80 | qDebug() << "Found resources " << resourceId; | 80 | query.requestedProperties << "name" << "icon" << "parent"; |
81 | 81 | query.parentProperty = "parent"; | |
82 | Sink::Query query; | 82 | for (const auto &r : resources) { |
83 | query.liveQuery = true; | 83 | qDebug() << "Found resources for account: " << r->identifier() << account; |
84 | query.requestedProperties << "name" << "icon" << "parent"; | 84 | query.resources << r->identifier(); |
85 | query.parentProperty = "parent"; | 85 | } |
86 | query.resources << resourceId.toUtf8(); | 86 | runQuery(query); |
87 | 87 | }).exec(); | |
88 | runQuery(query); | ||
89 | } | 88 | } |
90 | 89 | ||
91 | QVariant FolderListModel::accountId() const | 90 | QVariant FolderListModel::accountId() const |