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.
This commit is contained in:
Aleix Pol 2016-08-21 19:38:15 +02:00
parent b69247b4e5
commit d9e7f308c2
7 changed files with 96 additions and 1 deletions

View file

@ -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 {

View file

@ -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()

View file

@ -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);

View file

@ -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)

View file

@ -86,6 +86,11 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
qmlRegisterUncreatableType<LockDeviceDbusInterface>(uri, 1, 0, "LockDeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
qmlRegisterUncreatableType<FindMyPhoneDeviceDbusInterface>(uri, 1, 0, "FindMyPhoneDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
qmlRegisterUncreatableType<DeviceDbusInterface>(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
qmlRegisterSingletonType<DaemonDbusInterface>(uri, 1, 0, "DaemonDbusInterface",
[](QQmlEngine*, QJSEngine*) -> QObject* {
return new DaemonDbusInterface;
}
);
}
void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri)

View file

@ -0,0 +1,69 @@
/**
* Copyright 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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]());
}
}

View file

@ -2,3 +2,4 @@ module org.kde.kdeconnect
plugin kdeconnectdeclarativeplugin
PluginChecker 1.0 PluginChecker.qml
DBusProperty 1.0 DBusProperty.qml