From 68a41da9b16091a577a94cec7eccd4c892905391 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 11 Mar 2016 20:57:54 +0100 Subject: Extended maildir settings to create and register the sink resource --- accounts/maildir/CMakeLists.txt | 4 +- accounts/maildir/maildirsettings.cpp | 65 ++++++++++++++++- accounts/maildir/maildirsettings.h | 14 ++++ .../package/contents/ui/MaildirAccountSettings.qml | 37 +++++----- components/package/contents/ui/Settings.qml | 84 +++++++++++----------- framework/settings/settings.cpp | 7 +- framework/settings/settings.h | 1 + 7 files changed, 147 insertions(+), 65 deletions(-) diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt index cd25f09d..eafd430f 100644 --- a/accounts/maildir/CMakeLists.txt +++ b/accounts/maildir/CMakeLists.txt @@ -25,6 +25,8 @@ find_package(KF5Async CONFIG REQUIRED) find_package(KF5 REQUIRED COMPONENTS Package) include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) +#FIXME +include_directories(../../framework/) set(SRCS maildirsettings.cpp @@ -33,7 +35,7 @@ set(SRCS add_library(maildiraccountplugin SHARED ${SRCS}) qt5_use_modules(maildiraccountplugin Core Quick Qml) -target_link_libraries(maildiraccountplugin sink) +target_link_libraries(maildiraccountplugin sink settingsplugin) kpackage_install_package(package org.kube.accounts.maildir "genericqml") diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 4a3b1a00..a2e2e96e 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp @@ -18,8 +18,11 @@ */ #include "maildirsettings.h" +#include + #include #include +#include MaildirSettings::MaildirSettings(QObject *parent) : QObject(parent) @@ -31,7 +34,11 @@ 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")); + auto path = resource.getProperty("path").toString(); + if (mPath != path) { + mPath = path; + emit pathChanged(); + } }).exec(); } @@ -40,16 +47,70 @@ QByteArray MaildirSettings::identifier() const return mIdentifier; } +void MaildirSettings::setAccountIdentifier(const QByteArray &id) +{ + mAccountIdentifier = id; + Kube::Account account(id); + account.property("maildirResource").toByteArray(); + setIdentifier(account.property("maildirResource").toByteArray()); +} + +QByteArray MaildirSettings::accountIdentifier() const +{ + return mAccountIdentifier; +} + +void MaildirSettings::setPath(const QString &path) +{ + if (mPath != path) { + mPath = path; + emit pathChanged(); + } +} + +QString MaildirSettings::path() const +{ + return mPath; +} + void MaildirSettings::save() { if (!mIdentifier.isEmpty()) { Sink::ApplicationDomain::SinkResource resource(mIdentifier); - resource.setProperty("path", property("path")); + resource.setProperty("path", mPath); Sink::Store::modify(resource).exec(); } else { + const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray(); + mIdentifier = resourceIdentifier; + Sink::ApplicationDomain::SinkResource resource; resource.setProperty("path", property("path")); + resource.setProperty("identifier", resourceIdentifier); + resource.setProperty("type", "org.kde.maildir"); Sink::Store::create(resource).exec(); + Kube::Account account(mAccountIdentifier); + account.setProperty("maildirResource", resourceIdentifier); + account.save(); + //TODO deal with errors while creating + } +} + +void MaildirSettings::remove() +{ + if (!mIdentifier.isEmpty()) { + qWarning() << "We're missing an identifier"; + } else { + Sink::ApplicationDomain::SinkResource resource(mIdentifier); + Sink::Store::remove(resource).exec(); + Kube::Account account(mAccountIdentifier); + account.remove(); + + Kube::Settings settings("accounts"); + auto accounts = settings.property("accounts").toStringList(); + accounts.removeAll(mAccountIdentifier); + settings.setProperty("accounts", accounts); + settings.save(); + //TODO deal with errors while removing } } diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h index c0ad95c3..9a65cf39 100644 --- a/accounts/maildir/maildirsettings.h +++ b/accounts/maildir/maildirsettings.h @@ -24,6 +24,8 @@ class MaildirSettings : public QObject { Q_OBJECT Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) + Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) public: MaildirSettings(QObject *parent = 0); @@ -31,8 +33,20 @@ public: void setIdentifier(const QByteArray &); QByteArray identifier() const; + void setAccountIdentifier(const QByteArray &); + QByteArray accountIdentifier() const; + + void setPath(const QString &); + QString path() const; + Q_INVOKABLE void save(); + Q_INVOKABLE void remove(); + +signals: + void pathChanged(); private: QByteArray mIdentifier; + QByteArray mAccountIdentifier; + QString mPath; }; diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index 99814a06..189089fa 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml @@ -21,7 +21,7 @@ import QtQuick.Layouts 1.1 import org.kube.framework.settings 1.0 as KubeSettings import org.kube.framework.theme 1.0 -import org.kde.kube.accounts.maildir 1.0 as MaildirAccount +import org.kube.accounts.maildir 1.0 as MaildirAccount Rectangle { @@ -47,6 +47,8 @@ Rectangle { id: path placeholderText: "path" Layout.fillWidth: true + text: maildirSettings.path + onTextChanged: { maildirSettings.path = text; } } Text { @@ -60,6 +62,8 @@ Rectangle { id: username placeholderText: "username" Layout.fillWidth: true + text: transportSettings.username + onTextChanged: { transportSettings.username = text; } } Label { text: "Password" } @@ -67,6 +71,8 @@ Rectangle { id: password placeholderText: "password" Layout.fillWidth: true + text: transportSettings.password + onTextChanged: { transportSettings.password = text; } } Label { text: "Server" } @@ -74,39 +80,36 @@ Rectangle { id: server placeholderText: "server" Layout.fillWidth: true + text: transportSettings.server + onTextChanged: { transportSettings.server = text; } } MaildirAccount.MaildirSettings { id: maildirSettings - identifier: "org.kde.maildir.instance1" - property alias path: path.text + accountIdentifier: accountId } - KubeSettings.Settings { - id: accountSettings - identifier: "account." + accountId - property string primaryIdentity: "current" - } - KubeSettings.Settings { - id: identitySettings - identifier: "identity.current" - property string transport: "current" - } KubeSettings.Settings { id: transportSettings + //TODO set a proper identifier identifier: "transport.current" - property alias username: username.text - property alias password: password.text - property alias server: server.text + property string server; + property string username; + property string password; } Button { - id: button text: "Save" onClicked: { transportSettings.save(); maildirSettings.save(); } } + Button { + text: "Remove" + onClicked: { + maildirSettings.remove(); + } + } } } diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml index f6a03945..acdc42d7 100644 --- a/components/package/contents/ui/Settings.qml +++ b/components/package/contents/ui/Settings.qml @@ -68,57 +68,67 @@ Rectangle { SplitView { anchors.fill: parent - ScrollView { - id: accountsList + ColumnLayout { + ScrollView { + id: accountsList width: Unit.size * 55 Layout.maximumWidth: Unit.size * 150 Layout.minimumWidth: Unit.size * 30 - ListView { - id: listView + ListView { + id: listView - model: accountsController.accounts + model: accountsController.accounts - currentIndex: -1 + currentIndex: -1 - delegate: PlasmaComponents.ListItem { + delegate: PlasmaComponents.ListItem { - width: listView.width - height: Unit.size * 10 + width: listView.width + height: Unit.size * 10 - enabled: true - checked: listView.currentIndex == index + enabled: true + checked: listView.currentIndex == index - KubeFramework.AccountFactory { - id: accountFactory - accountId: modelData - } - - MouseArea { - anchors { - fill: parent + KubeFramework.AccountFactory { + id: accountFactory + accountId: modelData } - onClicked: { - accountDetails.source = accountFactory.uiPath + MouseArea { + anchors { + fill: parent + } - listView.currentIndex = model.index + onClicked: { + console.warn("Loading module is ", accountFactory.acountId); + accountDetails.source = accountFactory.uiPath + listView.currentIndex = model.index + } } - } - RowLayout { - anchors.fill: parent + RowLayout { + anchors.fill: parent - PlasmaCore.IconItem { - source: accountFactory.icon - } + PlasmaCore.IconItem { + source: accountFactory.icon + } - Label { - text: accountFactory.name + Label { + text: accountFactory.name + } } } } + + } + Button { + id: button + text: "Create New" + onClicked: { + accountsController.createAccount("maildir"); + } } } @@ -128,19 +138,5 @@ Rectangle { Layout.fillWidth: true } } - - /* - Button { - id: button - text: "Create New" - onClicked: { - accountsController.createAccount("maildir"); - } - } - - //TODO: Add possibility to add more accounts - - */ } - } diff --git a/framework/settings/settings.cpp b/framework/settings/settings.cpp index 246c4a99..64bc28ba 100644 --- a/framework/settings/settings.cpp +++ b/framework/settings/settings.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace Kube; @@ -50,7 +51,6 @@ Settings::Settings(const Settings &other) Settings::~Settings() { - // save(); } QSharedPointer Settings::getSettings() @@ -81,6 +81,11 @@ void Settings::save() settings->sync(); } +void Settings::remove() +{ + QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("/kube/%1.ini").arg(QString::fromLatin1(mIdentifier))); +} + void Settings::load() { if (mLoaded) { diff --git a/framework/settings/settings.h b/framework/settings/settings.h index 685d67aa..c5cff76b 100644 --- a/framework/settings/settings.h +++ b/framework/settings/settings.h @@ -38,6 +38,7 @@ public: QByteArray identifier() const; Q_INVOKABLE void save(); + Q_INVOKABLE void remove(); private: void load(); QSharedPointer getSettings(); -- cgit v1.2.3