From 7726fc6e03c09a5a1cb2dad62bd9ed6438e8bd8b Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Thu, 5 Jan 2017 19:44:27 +0100 Subject: kolabnow controller and create ui --- framework/accounts/CMakeLists.txt | 1 + framework/accounts/accountsplugin.cpp | 2 + framework/accounts/kolabnowcontroller.cpp | 88 +++++++++++++++++++++++++++++++ framework/accounts/kolabnowcontroller.h | 54 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 framework/accounts/kolabnowcontroller.cpp create mode 100644 framework/accounts/kolabnowcontroller.h (limited to 'framework/accounts') diff --git a/framework/accounts/CMakeLists.txt b/framework/accounts/CMakeLists.txt index 609b26d4..327d360e 100644 --- a/framework/accounts/CMakeLists.txt +++ b/framework/accounts/CMakeLists.txt @@ -3,6 +3,7 @@ set(accountsplugin_SRCS accountfactory.cpp accountsmodel.cpp maildircontroller.cpp + kolabnowcontroller.cpp ) add_library(accountsplugin SHARED ${accountsplugin_SRCS}) diff --git a/framework/accounts/accountsplugin.cpp b/framework/accounts/accountsplugin.cpp index 51316b52..0d77376b 100644 --- a/framework/accounts/accountsplugin.cpp +++ b/framework/accounts/accountsplugin.cpp @@ -21,6 +21,7 @@ #include "accountsmodel.h" #include "accountfactory.h" #include "maildircontroller.h" +#include "kolabnowcontroller.h" #include @@ -30,4 +31,5 @@ void AccountsPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "AccountFactory"); qmlRegisterType(uri, 1, 0, "AccountsModel"); qmlRegisterType(uri, 1, 0, "MaildirController"); + qmlRegisterType(uri, 1, 0, "KolabNowController"); } diff --git a/framework/accounts/kolabnowcontroller.cpp b/framework/accounts/kolabnowcontroller.cpp new file mode 100644 index 00000000..94ca2e01 --- /dev/null +++ b/framework/accounts/kolabnowcontroller.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2017 Michael Bohlender, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kolabnowcontroller.h" + +#include + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +KolabNowController::KolabNowController() : Kube::Controller(), +action_create{new Kube::ControllerAction{this, &KolabNowController::create}}, +action_modify{new Kube::ControllerAction{this, &KolabNowController::modify}}, +action_remove{new Kube::ControllerAction{this, &KolabNowController::remove}} +{ + +} + +void KolabNowController::create() { + + //account + auto account = ApplicationDomainType::createEntity(); + account.setProperty("type", "kolabnow"); + account.setProperty("name", getName()); + Store::create(account).exec().waitForFinished(); + + //imap + auto resource = ApplicationDomainType::createEntity(); + resource.setResourceType("sink.imap"); + resource.setAccount(account); + resource.setProperty("server","imaps://imap.kolabnow.com:993"); + resource.setProperty("username", getEmailAddress()); + resource.setProperty("password", getPassword()); + Store::create(resource).exec().waitForFinished(); + + //smtp + resource = ApplicationDomainType::createEntity(); + resource.setResourceType("sink.smtp"); + resource.setAccount(account); + resource.setProperty("server", "smtps://smtp.kolabnow.com:465"); + resource.setProperty("username", getEmailAddress()); + resource.setProperty("password", getPassword()); + Store::create(resource).exec().waitForFinished(); + + //identity + auto identity = ApplicationDomainType::createEntity(); + m_identityId = identity.identifier(); + identity.setAccount(account); + identity.setName(getIdentityName()); + identity.setAddress(getEmailAddress()); + Store::create(identity).exec(); +} + +void KolabNowController::modify() { + //TODO +} + +void KolabNowController::remove() { + SinkAccount account(m_accountId); + Store::remove(account).exec(); +} + +void KolabNowController::load(const QByteArray &id) { + + m_accountId = id; + + Store::fetchOne(Query().filter(m_accountId)) + .syncThen([this](const SinkAccount &account) { + setName(account.getName()); + }).exec(); + + //TODO +} diff --git a/framework/accounts/kolabnowcontroller.h b/framework/accounts/kolabnowcontroller.h new file mode 100644 index 00000000..85918800 --- /dev/null +++ b/framework/accounts/kolabnowcontroller.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2017 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; 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 KolabNowController : public Kube::Controller +{ + Q_OBJECT + + //Interface properties + KUBE_CONTROLLER_PROPERTY(QString, Name, name) + + KUBE_CONTROLLER_PROPERTY(QString, EmailAddress, emailAddress) + KUBE_CONTROLLER_PROPERTY(QString, Password, password) + KUBE_CONTROLLER_PROPERTY(QString, IdentityName, identityName) + + //Actions + KUBE_CONTROLLER_ACTION(create) + KUBE_CONTROLLER_ACTION(modify) + KUBE_CONTROLLER_ACTION(remove) + +public: + explicit KolabNowController(); + +public slots: + void load(const QByteArray &id); + +private: + QByteArray m_accountId; + QByteArray m_smtpId; + QByteArray m_imapId; + QByteArray m_identityId; +}; -- cgit v1.2.3