From d8e13159711576394099f8954368aeb9da7fa87a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 10 Mar 2016 14:45:15 +0100 Subject: AccountsController --- framework/domain/CMakeLists.txt | 1 + framework/domain/accountfactory.cpp | 20 ++++++------ framework/domain/accountfactory.h | 2 +- framework/domain/accountscontroller.cpp | 54 +++++++++++++++++++++++++++++++++ framework/domain/accountscontroller.h | 43 ++++++++++++++++++++++++++ framework/domain/mailplugin.cpp | 2 ++ 6 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 framework/domain/accountscontroller.cpp create mode 100644 framework/domain/accountscontroller.h (limited to 'framework/domain') 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 mailtemplates.cpp retriever.cpp accountfactory.cpp + accountscontroller.cpp ) add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") 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 @@ #include #include +#include "settings/settings.h" + AccountFactory::AccountFactory(QObject *parent) : QObject(parent) { - } void AccountFactory::setAccountId(const QString &accountId) { - qWarning() << "setting account id: " << accountId; mAccountId = accountId; - loadPackage(); -} -QByteArray AccountFactory::getAccountType() const -{ - return "maildir"; + Kube::Account account(mAccountId.toUtf8()); + mAccountType = account.type(); + + loadPackage(); } void AccountFactory::loadPackage() { - auto accountType = getAccountType(); - auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); + auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType); + if (!package.isValid()) { + qWarning() << "Failed to load account package: " << "org.kube.accounts." + mAccountType; + return; + } Q_ASSERT(package.isValid()); mUiPath = package.filePath("mainscript"); 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: private: void loadPackage(); - QByteArray getAccountType() const; QString mAccountId; QString mName; QString mIcon; QString mUiPath; + QByteArray mAccountType; }; 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 @@ +/* + Copyright (c) 2016 Michael Bohlender + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#include "accountscontroller.h" + +#include + +#include +#include +#include + +AccountsController::AccountsController(QObject *parent) : QObject(parent) +{ + Kube::Settings settings("accounts"); + mAccounts = settings.property("accounts").toStringList(); + qWarning() << "Loaded accounts" << mAccounts; +} + +void AccountsController::createAccount(const QString &accountType) +{ + auto identifier = QUuid::createUuid().toByteArray(); + Kube::Account accountSettings(identifier); + accountSettings.setProperty("type", accountType); + accountSettings.save(); + + Kube::Settings settings("accounts"); + auto accounts = settings.property("accounts").toStringList(); + accounts.append(identifier); + settings.setProperty("accounts", accounts); + settings.save(); + + //TODO setup sink resources etc via plugin + + qWarning() << "Created account " << identifier; + mAccounts.append(identifier); + emit accountsChanged(); +} 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 @@ +/* + Copyright (c) 2016 Michael Bohlender + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#pragma once + +#include +#include +#include +#include + +class AccountsController : public QObject +{ + Q_OBJECT + Q_PROPERTY (QStringList accounts MEMBER mAccounts NOTIFY accountsChanged) + +public: + explicit AccountsController(QObject *parent = Q_NULLPTR); + +signals: + void accountsChanged(); + +public slots: + void createAccount(const QString &accountId); + +private: + QStringList mAccounts; +}; 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 @@ #include "messageparser.h" #include "retriever.h" #include "accountfactory.h" +#include "accountscontroller.h" #include @@ -39,4 +40,5 @@ void MailPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "MessageParser"); qmlRegisterType(uri, 1, 0, "Retriever"); qmlRegisterType(uri, 1, 0, "AccountFactory"); + qmlRegisterType(uri, 1, 0, "AccountsController"); } -- cgit v1.2.3