summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/package/contents/ui/Settings.qml24
-rw-r--r--framework/domain/CMakeLists.txt1
-rw-r--r--framework/domain/accountfactory.cpp54
-rw-r--r--framework/domain/accountfactory.h24
-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, 178 insertions, 56 deletions
diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml
index bada1140..8da372e7 100644
--- a/components/package/contents/ui/Settings.qml
+++ b/components/package/contents/ui/Settings.qml
@@ -58,15 +58,19 @@ Rectangle {
58 id: contextSettings 58 id: contextSettings
59 identifier: "applicationcontext" 59 identifier: "applicationcontext"
60 property string currentAccountId: "current" 60 property string currentAccountId: "current"
61 property var availableAccountTypes: ["maildir"]
62 property var accounts: ["current"]
63 } 61 }
64 62
65 Column { 63 KubeFramework.AccountsController {
64 id: accountsController
65 }
66
67 ColumnLayout {
66 spacing: 5 68 spacing: 5
67 Repeater { 69 Repeater {
68 model: contextSettings.accounts 70 model: accountsController.accounts
69 delegate: Rectangle { 71 delegate: ColumnLayout {
72 height: 100
73 width: 100
70 KubeFramework.AccountFactory { 74 KubeFramework.AccountFactory {
71 id: accountFactory 75 id: accountFactory
72 accountId: modelData 76 accountId: modelData
@@ -82,11 +86,19 @@ Rectangle {
82 Label { 86 Label {
83 text: accountFactory.name 87 text: accountFactory.name
84 } 88 }
85 Loader { source: accountFactory.uiPath } 89 // Loader { source: accountFactory.uiPath }
86 } 90 }
87 } 91 }
88 } 92 }
89 93
94 Button {
95 id: button
96 text: "Create New"
97 onClicked: {
98 accountsController.createAccount("maildir");
99 }
100 }
101
90 //TODO: Add possibility to add more accounts 102 //TODO: Add possibility to add more accounts
91 } 103 }
92} 104}
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 d54f70a2..ab1a09e5 100644
--- a/framework/domain/accountfactory.cpp
+++ b/framework/domain/accountfactory.cpp
@@ -18,55 +18,39 @@
18*/ 18*/
19#include "accountfactory.h" 19#include "accountfactory.h"
20 20
21#include <QQmlComponent>
22#include <QQmlEngine>
23#include <QDebug> 21#include <QDebug>
24 22
25#include <KPackage/PackageLoader> 23#include <KPackage/PackageLoader>
24#include <KPackage/Package>
25#include <KPluginMetaData>
26
27#include "settings/settings.h"
26 28
27AccountFactory::AccountFactory(QObject *parent) 29AccountFactory::AccountFactory(QObject *parent)
28 : QObject(parent) 30 : QObject(parent)
29{ 31{
30
31}
32
33QString AccountFactory::name() const
34{
35 return "Maildir";
36}
37
38QString AccountFactory::icon() const
39{
40 return "icon";
41} 32}
42 33
43QVariant AccountFactory::ui() const 34void AccountFactory::setAccountId(const QString &accountId)
44{ 35{
45 return createComponent(getAccountType()); 36 mAccountId = accountId;
46}
47 37
48QByteArray AccountFactory::getAccountType() const 38 Kube::Account account(mAccountId.toUtf8());
49{ 39 mAccountType = account.type();
50 return "maildir";
51}
52 40
53QString AccountFactory::uiPath() const 41 loadPackage();
54{
55 auto accountType = getAccountType();
56 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType);
57 Q_ASSERT(package.isValid());
58 return package.filePath("mainscript");
59} 42}
60 43
61QVariant AccountFactory::createComponent(const QByteArray &accountType) const const 44void AccountFactory::loadPackage()
62{ 45{
63 qWarning() << "Trying to load accounts package " << accountType << mAccountId; 46 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType);
64 auto engine = qmlEngine(this); 47 if (!package.isValid()) {
65 Q_ASSERT(engine); 48 qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType;
66 auto component = new QQmlComponent(engine, QUrl::fromLocalFile(uiPath()), QQmlComponent::PreferSynchronous); 49 return;
67 for (const auto &error : component->errors()) {
68 qWarning() << error.toString();
69 } 50 }
70 Q_ASSERT(component->isReady()); 51 Q_ASSERT(package.isValid());
71 return QVariant::fromValue(component); 52 mUiPath = package.filePath("mainscript");
53 mName = package.metadata().name();
54 mIcon = package.metadata().iconName();
55 emit accountLoaded();
72} 56}
diff --git a/framework/domain/accountfactory.h b/framework/domain/accountfactory.h
index 0c6afe50..ed3c21d9 100644
--- a/framework/domain/accountfactory.h
+++ b/framework/domain/accountfactory.h
@@ -28,21 +28,23 @@
28class AccountFactory : public QObject 28class AccountFactory : public QObject
29{ 29{
30 Q_OBJECT 30 Q_OBJECT
31 Q_PROPERTY(QString accountId MEMBER mAccountId); 31 Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId);
32 Q_PROPERTY(QString name READ name); 32 Q_PROPERTY(QString name MEMBER mName NOTIFY accountLoaded);
33 Q_PROPERTY(QString icon READ icon); 33 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded);
34 Q_PROPERTY(QVariant ui READ ui); 34 Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded);
35 Q_PROPERTY(QString uiPath READ uiPath);
36public: 35public:
37 explicit AccountFactory(QObject *parent = Q_NULLPTR); 36 explicit AccountFactory(QObject *parent = Q_NULLPTR);
38 37
39 QString name() const; 38 void setAccountId(const QString &);
40 QString icon() const; 39
41 QVariant ui() const; 40signals:
42 QString uiPath() const; 41 void accountLoaded();
43 42
44 Q_INVOKABLE QVariant createComponent(const QByteArray &accountType) const;
45private: 43private:
46 QByteArray getAccountType() const; 44 void loadPackage();
47 QString mAccountId; 45 QString mAccountId;
46 QString mName;
47 QString mIcon;
48 QString mUiPath;
49 QByteArray mAccountType;
48}; 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