From d6ded01b2e07981b8c1f6139b25935c8c26db0eb Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Tue, 22 Nov 2016 18:03:24 +0100 Subject: connect maildir controller and maildir account wizzard page --- accounts/maildir/CMakeLists.txt | 1 + accounts/maildir/maildiraccountplugin.cpp | 2 + accounts/maildir/maildircontroller.cpp | 107 ++++++++++++++++++++++++++++++ accounts/maildir/maildircontroller.h | 64 ++++++++++++++++++ components/accounts/CreateMaildir.qml | 18 +++-- 5 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 accounts/maildir/maildircontroller.cpp create mode 100644 accounts/maildir/maildircontroller.h diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt index e50d4179..c8bf37c9 100644 --- a/accounts/maildir/CMakeLists.txt +++ b/accounts/maildir/CMakeLists.txt @@ -31,6 +31,7 @@ include_directories(../../framework/) set(SRCS maildirsettings.cpp maildiraccountplugin.cpp + maildircontroller.cpp ) add_library(maildiraccountplugin SHARED ${SRCS}) diff --git a/accounts/maildir/maildiraccountplugin.cpp b/accounts/maildir/maildiraccountplugin.cpp index 2c3c8c4d..5ae49d8e 100644 --- a/accounts/maildir/maildiraccountplugin.cpp +++ b/accounts/maildir/maildiraccountplugin.cpp @@ -1,6 +1,7 @@ #include "maildiraccountplugin.h" #include "maildirsettings.h" +#include "maildircontroller.h" #include @@ -8,4 +9,5 @@ void MaildirAccountPlugin::registerTypes (const char *uri) { Q_ASSERT(uri == QLatin1String("org.kube.accounts.maildir")); qmlRegisterType(uri, 1, 0, "MaildirSettings"); + qmlRegisterType(uri, 1, 0, "MaildirController"); } diff --git a/accounts/maildir/maildircontroller.cpp b/accounts/maildir/maildircontroller.cpp new file mode 100644 index 00000000..dc34d59a --- /dev/null +++ b/accounts/maildir/maildircontroller.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016 Michael Bohlender + * Copyright (c) 2016 Christian Mollekopf + * + * 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 "maildircontroller.h" + +#include + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +MaildirController::MaildirController(QObject *parent) +: QObject(parent) +{ +} + +QByteArray MaildirController::accountIdentifier() const +{ + return mAccountIdentifier; +} + +void MaildirController::setAccountIdentifier(const QByteArray &id) +{ + if (id.isEmpty()) { + return; + } + mAccountIdentifier = id; + + //clear + mIcon = QString(); + mName = QString(); + mPath = QUrl(); + + //load +} + +QUrl MaildirController::path() const +{ + return QUrl(mPath); +} + +void MaildirController::setPath(const QUrl &path) +{ + auto normalizedPath = path.path(); + if (mPath != normalizedPath) { + mPath = normalizedPath; + emit pathChanged(); + } +} + +void MaildirController::createAccount() +{ + auto account = ApplicationDomainType::createEntity(); + account.setProperty("type", "maildir"); + account.setProperty("name", mName); + account.setProperty("icon", mIcon); + Store::create(account).exec().waitForFinished(); + + auto resource = ApplicationDomainType::createEntity(); + resource.setResourceType("sink.maildir"); + resource.setAccount(account); + resource.setProperty("path", mPath); + //TODO not yet implemented in resource? // resource.setProperty("readonly", readonly); + Store::create(resource).exec().waitForFinished(); +} + +//TODO +void MaildirController::loadAccount(const QByteArray &id) +{ + Q_ASSERT(!mAccountIdentifier.isEmpty()); + Store::fetchOne(Query().filter(mAccountIdentifier)) + .syncThen([this](const SinkAccount &account) { + mIcon = account.getIcon(); + mName = account.getName(); + emit nameChanged(); + emit iconChanged(); + }).exec(); +} + +//TODO +void MaildirController::modifyAccount() +{ +} + +void MaildirController::deleteAccount() +{ + if (!mAccountIdentifier.isEmpty()) { + SinkAccount account(mAccountIdentifier); + Store::remove(account).exec(); + } +} diff --git a/accounts/maildir/maildircontroller.h b/accounts/maildir/maildircontroller.h new file mode 100644 index 00000000..80ffb8ca --- /dev/null +++ b/accounts/maildir/maildircontroller.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2016 Michael Bohlender, + * Copyright (c) 2016 Christian Mollekopf + * + * 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 MaildirController : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier NOTIFY accountIdentifierChanged) + + Q_PROPERTY(QString name MEMBER mName NOTIFY nameChanged) + Q_PROPERTY(QString icon MEMBER mIcon NOTIFY iconChanged) + Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) + +public: + explicit MaildirController(QObject *parent = Q_NULLPTR); + + QByteArray accountIdentifier() const; + void setAccountIdentifier(const QByteArray &id); + + QUrl path() const; + void setPath(const QUrl &path); + +signals: + void accountIdentifierChanged(); + void nameChanged(); + void iconChanged(); + void pathChanged(); + +public slots: + void createAccount(); + void loadAccount(const QByteArray &id); + void modifyAccount(); + void deleteAccount(); + +private: + QByteArray mAccountIdentifier; + QString mIcon; + QString mName; + QUrl mPath; +}; + diff --git a/components/accounts/CreateMaildir.qml b/components/accounts/CreateMaildir.qml index 2b22d8b0..01f1a83d 100644 --- a/components/accounts/CreateMaildir.qml +++ b/components/accounts/CreateMaildir.qml @@ -23,13 +23,13 @@ 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.framework.domain 1.0 as KubeFramework +import org.kube.accounts.maildir 1.0 as MaildirAccount Item { id: root //Controller - KubeFramework.AccountsController { + MaildirAccount.MaildirController { id: accountsController } @@ -98,6 +98,12 @@ Item { Controls.TextField { id: title Layout.fillWidth: true + + text: accountsController.name + + onTextChanged: { + accountsController.name = text + } } Kirigami.Label { @@ -112,6 +118,8 @@ Item { Layout.fillWidth: true enabled: false + + text: accountsController.path } Controls.Button { @@ -132,13 +140,14 @@ Item { selectFolder: true onAccepted: { - //root.path = fileDialog.fileUrl + accountsController.path = fileDialog.fileUrl } } } } } + /* Kirigami.Label { text: "" } @@ -146,6 +155,7 @@ Item { id: readOnly text: "Read only" } + */ Kirigami.Label { text: "" @@ -177,7 +187,7 @@ Item { text: "Save" onClicked: { - //accountsController.createMaildirAccount(root.name, root.path, root.readOnly) + accountsController.createAccount() popup.close() } } -- cgit v1.2.3