summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-10 14:45:15 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-10 14:45:15 +0100
commitd8e13159711576394099f8954368aeb9da7fa87a (patch)
treea498a2a390348abe0522b0203022e48518d32359
parent91eca666b5491041c2d095d599b75830c56530dc (diff)
downloadkube-d8e13159711576394099f8954368aeb9da7fa87a.tar.gz
kube-d8e13159711576394099f8954368aeb9da7fa87a.zip
AccountsController
-rw-r--r--components/package/contents/ui/Settings.qml24
-rw-r--r--framework/domain/CMakeLists.txt1
-rw-r--r--framework/domain/accountfactory.cpp20
-rw-r--r--framework/domain/accountfactory.h2
-rw-r--r--framework/domain/accountscontroller.cpp54
-rw-r--r--framework/domain/accountscontroller.h43
-rw-r--r--framework/domain/mailplugin.cpp2
-rw-r--r--framework/settings/settings.cpp30
-rw-r--r--framework/settings/settings.h2
9 files changed, 158 insertions, 20 deletions
diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml
index 692ddd0a..1f5fc972 100644
--- a/components/package/contents/ui/Settings.qml
+++ b/components/package/contents/ui/Settings.qml
@@ -57,15 +57,19 @@ Rectangle {
57 id: contextSettings 57 id: contextSettings
58 identifier: "applicationcontext" 58 identifier: "applicationcontext"
59 property string currentAccountId: "current" 59 property string currentAccountId: "current"
60 property var availableAccountTypes: ["maildir"]
61 property var accounts: ["current"]
62 } 60 }
63 61
64 Column { 62 KubeFramework.AccountsController {
63 id: accountsController
64 }
65
66 ColumnLayout {
65 spacing: 5 67 spacing: 5
66 Repeater { 68 Repeater {
67 model: contextSettings.accounts 69 model: accountsController.accounts
68 delegate: Rectangle { 70 delegate: ColumnLayout {
71 height: 100
72 width: 100
69 KubeFramework.AccountFactory { 73 KubeFramework.AccountFactory {
70 id: accountFactory 74 id: accountFactory
71 accountId: modelData 75 accountId: modelData
@@ -81,11 +85,19 @@ Rectangle {
81 Label { 85 Label {
82 text: accountFactory.name 86 text: accountFactory.name
83 } 87 }
84 Loader { source: accountFactory.uiPath } 88 // Loader { source: accountFactory.uiPath }
85 } 89 }
86 } 90 }
87 } 91 }
88 92
93 Button {
94 id: button
95 text: "Create New"
96 onClicked: {
97 accountsController.createAccount("maildir");
98 }
99 }
100
89 //TODO: Add possibility to add more accounts 101 //TODO: Add possibility to add more accounts
90 } 102 }
91} 103}
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt
index 10a8c065..7560219f 100644
--- a/framework/domain/CMakeLists.txt
+++ b/framework/domain/CMakeLists.txt
@@ -13,6 +13,7 @@ set(mailplugin_SRCS
13 mailtemplates.cpp 13 mailtemplates.cpp
14 retriever.cpp 14 retriever.cpp
15 accountfactory.cpp 15 accountfactory.cpp
16 accountscontroller.cpp
16) 17)
17add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") 18add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data")
18 19
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp
index af37710a..ab1a09e5 100644
--- a/framework/domain/accountfactory.cpp
+++ b/framework/domain/accountfactory.cpp
@@ -24,28 +24,30 @@
24#include <KPackage/Package> 24#include <KPackage/Package>
25#include <KPluginMetaData> 25#include <KPluginMetaData>
26 26
27#include "settings/settings.h"
28
27AccountFactory::AccountFactory(QObject *parent) 29AccountFactory::AccountFactory(QObject *parent)
28 : QObject(parent) 30 : QObject(parent)
29{ 31{
30
31} 32}
32 33
33void AccountFactory::setAccountId(const QString &accountId) 34void AccountFactory::setAccountId(const QString &accountId)
34{ 35{
35 qWarning() << "setting account id: " << accountId;
36 mAccountId = accountId; 36 mAccountId = accountId;
37 loadPackage();
38}
39 37
40QByteArray AccountFactory::getAccountType() const 38 Kube::Account account(mAccountId.toUtf8());
41{ 39 mAccountType = account.type();
42 return "maildir"; 40
41 loadPackage();
43} 42}
44 43
45void AccountFactory::loadPackage() 44void AccountFactory::loadPackage()
46{ 45{
47 auto accountType = getAccountType(); 46 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType);
48 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); 47 if (!package.isValid()) {
48 qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType;
49 return;
50 }
49 Q_ASSERT(package.isValid()); 51 Q_ASSERT(package.isValid());
50 mUiPath = package.filePath("mainscript"); 52 mUiPath = package.filePath("mainscript");
51 mName = package.metadata().name(); 53 mName = package.metadata().name();
diff --git a/framework/domain/accountfactory.h b/framework/domain/accountfactory.h
index 1da32885..ed3c21d9 100644
--- a/framework/domain/accountfactory.h
+++ b/framework/domain/accountfactory.h
@@ -42,9 +42,9 @@ signals:
42 42
43private: 43private:
44 void loadPackage(); 44 void loadPackage();
45 QByteArray getAccountType() const;
46 QString mAccountId; 45 QString mAccountId;
47 QString mName; 46 QString mName;
48 QString mIcon; 47 QString mIcon;
49 QString mUiPath; 48 QString mUiPath;
49 QByteArray mAccountType;
50}; 50};
diff --git a/framework/domain/accountscontroller.cpp b/framework/domain/accountscontroller.cpp
new file mode 100644
index 00000000..1be03ba9
--- /dev/null
+++ b/framework/domain/accountscontroller.cpp
@@ -0,0 +1,54 @@
1/*
2 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
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
21#include "accountscontroller.h"
22
23#include <settings/settings.h>
24
25#include <QVariant>
26#include <QUuid>
27#include <QDebug>
28
29AccountsController::AccountsController(QObject *parent) : QObject(parent)
30{
31 Kube::Settings settings("accounts");
32 mAccounts = settings.property("accounts").toStringList();
33 qWarning() << "Loaded accounts" << mAccounts;
34}
35
36void AccountsController::createAccount(const QString &accountType)
37{
38 auto identifier = QUuid::createUuid().toByteArray();
39 Kube::Account accountSettings(identifier);
40 accountSettings.setProperty("type", accountType);
41 accountSettings.save();
42
43 Kube::Settings settings("accounts");
44 auto accounts = settings.property("accounts").toStringList();
45 accounts.append(identifier);
46 settings.setProperty("accounts", accounts);
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}
diff --git a/framework/domain/accountscontroller.h b/framework/domain/accountscontroller.h
new file mode 100644
index 00000000..9d98de71
--- /dev/null
+++ b/framework/domain/accountscontroller.h
@@ -0,0 +1,43 @@
1/*
2 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
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 <QString>
24#include <QStringList>
25#include <QVariant>
26
27class AccountsController : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY (QStringList accounts MEMBER mAccounts NOTIFY accountsChanged)
31
32public:
33 explicit AccountsController(QObject *parent = Q_NULLPTR);
34
35signals:
36 void accountsChanged();
37
38public slots:
39 void createAccount(const QString &accountId);
40
41private:
42 QStringList mAccounts;
43};
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp
index dd438114..c19818ec 100644
--- a/framework/domain/mailplugin.cpp
+++ b/framework/domain/mailplugin.cpp
@@ -26,6 +26,7 @@
26#include "messageparser.h" 26#include "messageparser.h"
27#include "retriever.h" 27#include "retriever.h"
28#include "accountfactory.h" 28#include "accountfactory.h"
29#include "accountscontroller.h"
29 30
30#include <QtQml> 31#include <QtQml>
31 32
@@ -39,4 +40,5 @@ void MailPlugin::registerTypes (const char *uri)
39 qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); 40 qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser");
40 qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); 41 qmlRegisterType<Retriever>(uri, 1, 0, "Retriever");
41 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); 42 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory");
43 qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController");
42} 44}
diff --git a/framework/settings/settings.cpp b/framework/settings/settings.cpp
index a4e28190..246c4a99 100644
--- a/framework/settings/settings.cpp
+++ b/framework/settings/settings.cpp
@@ -26,21 +26,24 @@
26using namespace Kube; 26using namespace Kube;
27 27
28Settings::Settings(QObject *parent) 28Settings::Settings(QObject *parent)
29 : QObject(parent) 29 : QObject(parent),
30 mLoaded(false)
30{ 31{
31 32
32} 33}
33 34
34Settings::Settings(const QByteArray &id, QObject *parent) 35Settings::Settings(const QByteArray &id, QObject *parent)
35 : QObject(parent), 36 : QObject(parent),
36 mIdentifier(id) 37 mIdentifier(id),
38 mLoaded(false)
37{ 39{
38 load(); 40 load();
39} 41}
40 42
41Settings::Settings(const Settings &other) 43Settings::Settings(const Settings &other)
42 : QObject(other.parent()), 44 : QObject(other.parent()),
43 mIdentifier(other.mIdentifier) 45 mIdentifier(other.mIdentifier),
46 mLoaded(false)
44{ 47{
45 load(); 48 load();
46} 49}
@@ -59,8 +62,19 @@ void Settings::save()
59{ 62{
60 qWarning() << "Saving" << mIdentifier; 63 qWarning() << "Saving" << mIdentifier;
61 auto settings = getSettings(); 64 auto settings = getSettings();
65
66 for (const auto &p : dynamicPropertyNames()) {
67 qWarning() << "setting " << p << property(p);
68 if (p == "identifier") {
69 continue;
70 }
71 settings->setValue(p, property(p));
72 }
62 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { 73 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) {
63 const auto p = metaObject()->property(i).name(); 74 const auto p = metaObject()->property(i).name();
75 if (p == QByteArray("identifier")) {
76 continue;
77 }
64 qWarning() << "setting " << p << property(p); 78 qWarning() << "setting " << p << property(p);
65 settings->setValue(p, property(p)); 79 settings->setValue(p, property(p));
66 } 80 }
@@ -69,7 +83,10 @@ void Settings::save()
69 83
70void Settings::load() 84void Settings::load()
71{ 85{
72 qWarning() << "loading" << mIdentifier; 86 if (mLoaded) {
87 return;
88 }
89 mLoaded = true;
73 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { 90 for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) {
74 auto p = metaObject()->property(i).name(); 91 auto p = metaObject()->property(i).name();
75 setProperty(p, QVariant()); 92 setProperty(p, QVariant());
@@ -114,6 +131,11 @@ Identity Account::primaryIdentity() const
114 return Identity(property("primaryIdentityId").toByteArray()); 131 return Identity(property("primaryIdentityId").toByteArray());
115} 132}
116 133
134QByteArray Account::type() const
135{
136 return property("type").toByteArray();
137}
138
117Identity::Identity(const QByteArray &identifier) 139Identity::Identity(const QByteArray &identifier)
118 : Settings("identity." + identifier) 140 : Settings("identity." + identifier)
119{ 141{
diff --git a/framework/settings/settings.h b/framework/settings/settings.h
index bfee55cb..685d67aa 100644
--- a/framework/settings/settings.h
+++ b/framework/settings/settings.h
@@ -42,6 +42,7 @@ private:
42 void load(); 42 void load();
43 QSharedPointer<QSettings> getSettings(); 43 QSharedPointer<QSettings> getSettings();
44 QByteArray mIdentifier; 44 QByteArray mIdentifier;
45 bool mLoaded;
45}; 46};
46 47
47class Account; 48class Account;
@@ -63,6 +64,7 @@ class Account : public Settings
63public: 64public:
64 Account(const QByteArray &identifier); 65 Account(const QByteArray &identifier);
65 Identity primaryIdentity() const; 66 Identity primaryIdentity() const;
67 QByteArray type() const;
66}; 68};
67 69
68class Identity : public Settings 70class Identity : public Settings