diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 14:45:15 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 14:45:15 +0100 |
commit | d8e13159711576394099f8954368aeb9da7fa87a (patch) | |
tree | a498a2a390348abe0522b0203022e48518d32359 /framework/domain | |
parent | 91eca666b5491041c2d095d599b75830c56530dc (diff) | |
download | kube-d8e13159711576394099f8954368aeb9da7fa87a.tar.gz kube-d8e13159711576394099f8954368aeb9da7fa87a.zip |
AccountsController
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/domain/accountfactory.cpp | 20 | ||||
-rw-r--r-- | framework/domain/accountfactory.h | 2 | ||||
-rw-r--r-- | framework/domain/accountscontroller.cpp | 54 | ||||
-rw-r--r-- | framework/domain/accountscontroller.h | 43 | ||||
-rw-r--r-- | framework/domain/mailplugin.cpp | 2 |
6 files changed, 112 insertions, 10 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 | ) |
17 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") | 18 | add_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 | |||
27 | AccountFactory::AccountFactory(QObject *parent) | 29 | AccountFactory::AccountFactory(QObject *parent) |
28 | : QObject(parent) | 30 | : QObject(parent) |
29 | { | 31 | { |
30 | |||
31 | } | 32 | } |
32 | 33 | ||
33 | void AccountFactory::setAccountId(const QString &accountId) | 34 | void AccountFactory::setAccountId(const QString &accountId) |
34 | { | 35 | { |
35 | qWarning() << "setting account id: " << accountId; | ||
36 | mAccountId = accountId; | 36 | mAccountId = accountId; |
37 | loadPackage(); | ||
38 | } | ||
39 | 37 | ||
40 | QByteArray AccountFactory::getAccountType() const | 38 | Kube::Account account(mAccountId.toUtf8()); |
41 | { | 39 | mAccountType = account.type(); |
42 | return "maildir"; | 40 | |
41 | loadPackage(); | ||
43 | } | 42 | } |
44 | 43 | ||
45 | void AccountFactory::loadPackage() | 44 | void 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 | ||
43 | private: | 43 | private: |
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 | |||
29 | AccountsController::AccountsController(QObject *parent) : QObject(parent) | ||
30 | { | ||
31 | Kube::Settings settings("accounts"); | ||
32 | mAccounts = settings.property("accounts").toStringList(); | ||
33 | qWarning() << "Loaded accounts" << mAccounts; | ||
34 | } | ||
35 | |||
36 | void 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 | |||
27 | class AccountsController : public QObject | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | Q_PROPERTY (QStringList accounts MEMBER mAccounts NOTIFY accountsChanged) | ||
31 | |||
32 | public: | ||
33 | explicit AccountsController(QObject *parent = Q_NULLPTR); | ||
34 | |||
35 | signals: | ||
36 | void accountsChanged(); | ||
37 | |||
38 | public slots: | ||
39 | void createAccount(const QString &accountId); | ||
40 | |||
41 | private: | ||
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 | } |