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 ++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 accounts/maildir/maildircontroller.cpp create mode 100644 accounts/maildir/maildircontroller.h (limited to 'accounts/maildir') 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; +}; + -- cgit v1.2.3