summaryrefslogtreecommitdiffstats
path: root/framework/domain
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain')
-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
6 files changed, 132 insertions, 46 deletions
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}