From d9e7f308c21fc78fb3f75270e7c67e9a1e4a3536 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sun, 21 Aug 2016 19:38:15 +0200 Subject: [PATCH] Show the announcedName in the qml app Makes it possible to display it and modify it Introduces a DBusProperty component that can be used if we don't want to go through the QtDBus property generation hell. --- app/qml/main.qml | 18 +++++ core/daemon.cpp | 1 + core/daemon.h | 1 + plasmoid/declarativeplugin/CMakeLists.txt | 2 +- .../kdeconnectdeclarativeplugin.cpp | 5 ++ .../declarativeplugin/qml/DBusProperty.qml | 69 +++++++++++++++++++ plasmoid/declarativeplugin/qmldir | 1 + 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 plasmoid/declarativeplugin/qml/DBusProperty.qml diff --git a/app/qml/main.qml b/app/qml/main.qml index 0e58b304f..46541cd73 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -50,6 +50,24 @@ Kirigami.ApplicationWindow titleIcon: "kdeconnect" // bannerImageSource: "/home/apol/devel/kde5/share/wallpapers/Next/contents/images/1024x768.png" + topContent: [ + TextField { + Layout.fillWidth: true + + DBusProperty { + id: announcedNameProperty + object: DaemonDbusInterface + read: "announcedName" + defaultValue: "" + } + + text: announcedNameProperty.value + onAccepted: { + DaemonDbusInterface.setAnnouncedName(text) + text = Qt.binding(function() {return announcedNameProperty.value}) + } + } + ] property var objects: [findDevicesAction] Instantiator { model: DevicesSortProxyModel { diff --git a/core/daemon.cpp b/core/daemon.cpp index 129a5350f..b8323e6c3 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -214,6 +214,7 @@ void Daemon::setAnnouncedName(const QString &name) qCDebug(KDECONNECT_CORE()) << "Announcing name"; KdeConnectConfig::instance()->setName(name); forceOnNetworkChange(); + Q_EMIT announcedNameChanged(name); } QString Daemon::announcedName() diff --git a/core/daemon.h b/core/daemon.h index 8b3fab041..dde33d331 100644 --- a/core/daemon.h +++ b/core/daemon.h @@ -73,6 +73,7 @@ Q_SIGNALS: Q_SCRIPTABLE void deviceAdded(const QString& id); Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed Q_SCRIPTABLE void deviceVisibilityChanged(const QString& id, bool isVisible); + Q_SCRIPTABLE void announcedNameChanged(const QString &announcedName); private Q_SLOTS: void onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl); diff --git a/plasmoid/declarativeplugin/CMakeLists.txt b/plasmoid/declarativeplugin/CMakeLists.txt index ec86925c0..b32738aeb 100644 --- a/plasmoid/declarativeplugin/CMakeLists.txt +++ b/plasmoid/declarativeplugin/CMakeLists.txt @@ -21,4 +21,4 @@ target_link_libraries(kdeconnectdeclarativeplugin kdeconnectinterfaces ) install(TARGETS kdeconnectdeclarativeplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kdeconnect) -install(FILES qmldir qml/PluginChecker.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kdeconnect) +install(FILES qmldir qml/PluginChecker.qml qml/DBusProperty.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kdeconnect) diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index aec6be43a..1a1a4a378 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -86,6 +86,11 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri) qmlRegisterUncreatableType(uri, 1, 0, "LockDeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterUncreatableType(uri, 1, 0, "FindMyPhoneDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterUncreatableType(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); + qmlRegisterSingletonType(uri, 1, 0, "DaemonDbusInterface", + [](QQmlEngine*, QJSEngine*) -> QObject* { + return new DaemonDbusInterface; + } + ); } void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri) diff --git a/plasmoid/declarativeplugin/qml/DBusProperty.qml b/plasmoid/declarativeplugin/qml/DBusProperty.qml new file mode 100644 index 000000000..30527de19 --- /dev/null +++ b/plasmoid/declarativeplugin/qml/DBusProperty.qml @@ -0,0 +1,69 @@ +/** + * Copyright 2016 Aleix Pol Gonzalez + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +import QtQml 2.2 +import org.kde.kdeconnect 1.0 + +QtObject { + id: prop + property QtObject object: null + property string read + property string change: read+"Changed" + + Component.onCompleted: get(); + + onChangeChanged: { + if (object) { + var theSignal = object[change]; + if (theSignal) { + theSignal.connect(valueReceived); + } else { + console.warn("couldn't find signal", change, "for", object) + } + } + } + + function valueReceived(val) { + if (!val) { + get(); + } else { + _value = val; + } + } + + property var defaultValue + property var _value: defaultValue + readonly property var value: _value + + readonly property var v: DBusAsyncResponse { + id: response + autoDelete: false + onSuccess: { + prop._value = result; + } + onError: { + console.warn("failed call", object, read, write, change) + } + } + + function get() { + response.setPendingCall(object[read]()); + } +} diff --git a/plasmoid/declarativeplugin/qmldir b/plasmoid/declarativeplugin/qmldir index 638deac72..80d0bc184 100644 --- a/plasmoid/declarativeplugin/qmldir +++ b/plasmoid/declarativeplugin/qmldir @@ -2,3 +2,4 @@ module org.kde.kdeconnect plugin kdeconnectdeclarativeplugin PluginChecker 1.0 PluginChecker.qml +DBusProperty 1.0 DBusProperty.qml