From fd31aa9b05ea215e8071cf76fe21ec746204f3a3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 3 Mar 2016 22:30:07 +0100 Subject: Added a maildir configuration controller that can edit the config in sink. The property binding only works when using actual QObject::property'ies. It doesn't work at all with Q_PROPERTY, even with a NOTIFY signal. --- accounts/maildir/CMakeLists.txt | 15 +++++- accounts/maildir/maildiraccountplugin.cpp | 11 +++++ accounts/maildir/maildiraccountplugin.h | 13 +++++ accounts/maildir/maildirsettings.cpp | 55 ++++++++++++++++++++++ accounts/maildir/maildirsettings.h | 38 +++++++++++++++ .../package/contents/ui/MaildirAccountSettings.qml | 40 ++++++++++------ accounts/maildir/qmldir | 2 + 7 files changed, 158 insertions(+), 16 deletions(-) create mode 100644 accounts/maildir/maildiraccountplugin.cpp create mode 100644 accounts/maildir/maildiraccountplugin.h create mode 100644 accounts/maildir/maildirsettings.cpp create mode 100644 accounts/maildir/maildirsettings.h (limited to 'accounts/maildir') diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt index 7e9894b1..d83ae0be 100644 --- a/accounts/maildir/CMakeLists.txt +++ b/accounts/maildir/CMakeLists.txt @@ -20,8 +20,21 @@ include(KDECompilerSettings) find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui) set (QT_MIN_VERSION "5.4.0") -find_package(KF5 REQUIRED COMPONENTS Package) +find_package(Sink CONFIG REQUIRED) +find_package(KF5Async CONFIG REQUIRED) +include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) + +set(SRCS + maildirsettings.cpp + maildiraccountplugin.cpp +) + +add_library(maildiraccountplugin SHARED ${SRCS}) +qt5_use_modules(maildiraccountplugin Core Quick Qml) +target_link_libraries(maildiraccountplugin sink) + +install(TARGETS maildiraccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) install(FILES package/contents/ui/MaildirAccountSettings.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) diff --git a/accounts/maildir/maildiraccountplugin.cpp b/accounts/maildir/maildiraccountplugin.cpp new file mode 100644 index 00000000..0033613b --- /dev/null +++ b/accounts/maildir/maildiraccountplugin.cpp @@ -0,0 +1,11 @@ +#include "maildiraccountplugin.h" + +#include "maildirsettings.h" + +#include + +void MaildirAccountPlugin::registerTypes (const char *uri) +{ + Q_ASSERT(uri == QLatin1String("org.kde.kube.accounts.maildir")); + qmlRegisterType(uri, 1, 0, "MaildirSettings"); +} diff --git a/accounts/maildir/maildiraccountplugin.h b/accounts/maildir/maildiraccountplugin.h new file mode 100644 index 00000000..aad73dd6 --- /dev/null +++ b/accounts/maildir/maildiraccountplugin.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +class MaildirAccountPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + virtual void registerTypes(const char *uri); +}; diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp new file mode 100644 index 00000000..4a3b1a00 --- /dev/null +++ b/accounts/maildir/maildirsettings.cpp @@ -0,0 +1,55 @@ +/* + 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 "maildirsettings.h" + +#include +#include + +MaildirSettings::MaildirSettings(QObject *parent) + : QObject(parent) +{ +} + +void MaildirSettings::setIdentifier(const QByteArray &id) +{ + mIdentifier = id; + Sink::Store::fetchOne(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList() << "path")) + .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + setProperty("path", resource.getProperty("path")); + }).exec(); +} + +QByteArray MaildirSettings::identifier() const +{ + return mIdentifier; +} + +void MaildirSettings::save() +{ + if (!mIdentifier.isEmpty()) { + Sink::ApplicationDomain::SinkResource resource(mIdentifier); + resource.setProperty("path", property("path")); + Sink::Store::modify(resource).exec(); + } else { + Sink::ApplicationDomain::SinkResource resource; + resource.setProperty("path", property("path")); + Sink::Store::create(resource).exec(); + } +} + diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h new file mode 100644 index 00000000..c0ad95c3 --- /dev/null +++ b/accounts/maildir/maildirsettings.h @@ -0,0 +1,38 @@ +/* + 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. +*/ +#pragma once + +#include + +class MaildirSettings : public QObject +{ + Q_OBJECT + Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) + +public: + MaildirSettings(QObject *parent = 0); + + void setIdentifier(const QByteArray &); + QByteArray identifier() const; + + Q_INVOKABLE void save(); + +private: + QByteArray mIdentifier; +}; diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index 5ba9f0c1..77cf739f 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml @@ -20,12 +20,12 @@ import QtQuick.Controls 1.4 import QtQuick.Layouts 1.1 import org.kde.kube.settings 1.0 as KubeSettings -// import org.kde.kube.accounts.maildir 1.0 as MaildirAccount +import org.kde.kube.accounts.maildir 1.0 as MaildirAccount Rectangle { id: root property string accountId - property string accountName + property string accountName: "Maildir" color: colorPalette.background @@ -40,35 +40,45 @@ Rectangle { text: "Account: " + accountName } + Label { text: "Path" } + TextField { + id: path + placeholderText: "path" + Layout.fillWidth: true + } + + Text { + Layout.columnSpan: 2 + Layout.fillWidth: true + text: "Smtp:" + } + Label { text: "Username" } TextField { id: username - text: "username" + placeholderText: "username" Layout.fillWidth: true } Label { text: "Password" } TextField { id: password - text: "password" + placeholderText: "password" Layout.fillWidth: true } Label { text: "Server" } TextField { id: server - text: "server" + placeholderText: "server" Layout.fillWidth: true } - //If we had a settings controller - // MaildirAccount.SmtpSettings { - // id: smtpSettings - // identifier: accountId - // property alias username: username.text - // property alias password: password.text - // property alias server: server.text - // } + MaildirAccount.MaildirSettings { + id: maildirSettings + identifier: "org.kde.maildir.instance1" + property alias path: path.text + } KubeSettings.Settings { id: accountSettings @@ -92,8 +102,8 @@ Rectangle { id: button text: "Save" onClicked: { - smtpSettings.save(); - root.visible = false; + transportSettings.save(); + maildirSettings.save(); } } } diff --git a/accounts/maildir/qmldir b/accounts/maildir/qmldir index 40e6be1c..70ecc786 100644 --- a/accounts/maildir/qmldir +++ b/accounts/maildir/qmldir @@ -1,3 +1,5 @@ module org.kde.kube.accounts.maildir AccountSettings 1.0 MaildirAccountSettings.qml + +plugin maildiraccountplugin -- cgit v1.2.3