From aba4edffe5a0e98ed92bb0177e89f6936c7eeb1f Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Thu, 5 Jan 2017 15:58:47 +0100 Subject: maildir controller based on the new kubecontroller + adjusted create-maildir-ui --- components/accounts/CreateMaildir.qml | 19 ++++++----- framework/accounts/CMakeLists.txt | 1 + framework/accounts/accountsplugin.cpp | 2 ++ framework/accounts/maildircontroller.cpp | 55 ++++++++++++++++++++++++++++++++ framework/accounts/maildircontroller.h | 44 +++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 framework/accounts/maildircontroller.cpp create mode 100644 framework/accounts/maildircontroller.h diff --git a/components/accounts/CreateMaildir.qml b/components/accounts/CreateMaildir.qml index e5d10fd4..99bde452 100644 --- a/components/accounts/CreateMaildir.qml +++ b/components/accounts/CreateMaildir.qml @@ -23,14 +23,14 @@ import QtQuick.Controls 2.0 as Controls2 import org.kde.kirigami 1.0 as Kirigami import QtQuick.Dialogs 1.0 as Dialogs -import org.kube.accounts.maildir 1.0 as MaildirAccount +import org.kube.framework.accounts 1.0 as KubeAccounts Item { id: root //Controller - MaildirAccount.MaildirController { - id: accountsController + KubeAccounts.MaildirController { + id: account } //Navigation @@ -99,10 +99,10 @@ Item { id: title Layout.fillWidth: true - text: accountsController.name + text: account.name onTextChanged: { - accountsController.name = text + account.name = text } } @@ -119,7 +119,7 @@ Item { enabled: false - text: accountsController.path + text: account.path } Controls.Button { @@ -140,7 +140,7 @@ Item { selectFolder: true onAccepted: { - accountsController.path = fileDialog.fileUrl + account.path = fileDialog.fileUrl } } } @@ -175,6 +175,7 @@ Item { text: "Discard" onClicked: { + //account.clear() popup.close() } } @@ -186,8 +187,10 @@ Item { text: "Save" + enabled: account.createAction.enabled + onClicked: { - accountsController.createAccount() + account.createAction.execute() popup.close() } } diff --git a/framework/accounts/CMakeLists.txt b/framework/accounts/CMakeLists.txt index bccafd77..609b26d4 100644 --- a/framework/accounts/CMakeLists.txt +++ b/framework/accounts/CMakeLists.txt @@ -2,6 +2,7 @@ set(accountsplugin_SRCS accountsplugin.cpp accountfactory.cpp accountsmodel.cpp + maildircontroller.cpp ) add_library(accountsplugin SHARED ${accountsplugin_SRCS}) diff --git a/framework/accounts/accountsplugin.cpp b/framework/accounts/accountsplugin.cpp index e980d5f3..51316b52 100644 --- a/framework/accounts/accountsplugin.cpp +++ b/framework/accounts/accountsplugin.cpp @@ -20,6 +20,7 @@ #include "accountsmodel.h" #include "accountfactory.h" +#include "maildircontroller.h" #include @@ -28,4 +29,5 @@ void AccountsPlugin::registerTypes (const char *uri) Q_ASSERT(uri == QLatin1String("org.kube.framework.accounts")); qmlRegisterType(uri, 1, 0, "AccountFactory"); qmlRegisterType(uri, 1, 0, "AccountsModel"); + qmlRegisterType(uri, 1, 0, "MaildirController"); } diff --git a/framework/accounts/maildircontroller.cpp b/framework/accounts/maildircontroller.cpp new file mode 100644 index 00000000..daafccb6 --- /dev/null +++ b/framework/accounts/maildircontroller.cpp @@ -0,0 +1,55 @@ +/* + 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 "maildircontroller.h" + +#include + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +MaildirController::MaildirController() : Kube::Controller(), + action_create{new Kube::ControllerAction{this, &MaildirController::create}}, + action_modify{new Kube::ControllerAction{this, &MaildirController::modify}}, + action_remove{new Kube::ControllerAction{this, &MaildirController::remove}} +{ + +} + +void MaildirController::create() { + auto account = ApplicationDomainType::createEntity(); + account.setProperty("type", "maildir"); + account.setProperty("name", getName()); + //account.setProperty("icon", getIcon()); + Store::create(account).exec().waitForFinished(); + + auto resource = ApplicationDomainType::createEntity(); + resource.setResourceType("sink.maildir"); + resource.setAccount(account); + resource.setProperty("path", getPath().path()); + + Store::create(resource).exec().waitForFinished(); + + clear(); +} + +void MaildirController::modify() { +} + +void MaildirController::remove() { +} diff --git a/framework/accounts/maildircontroller.h b/framework/accounts/maildircontroller.h new file mode 100644 index 00000000..da2a3a62 --- /dev/null +++ b/framework/accounts/maildircontroller.h @@ -0,0 +1,44 @@ +/* + 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 + +#include + +class MaildirController : public Kube::Controller +{ + Q_OBJECT + + //Interface properties + KUBE_CONTROLLER_PROPERTY(QString, Name, name) + KUBE_CONTROLLER_PROPERTY(QString, Icon, icon) + KUBE_CONTROLLER_PROPERTY(QUrl, Path, path) + + //Actions + KUBE_CONTROLLER_ACTION(create) + KUBE_CONTROLLER_ACTION(modify) + KUBE_CONTROLLER_ACTION(remove) + +public: + explicit MaildirController(); +}; -- cgit v1.2.3