From b0e45ad1fbbae1d579e2145e340992f721061fdd Mon Sep 17 00:00:00 2001 From: Yuri Kozyrev Date: Tue, 26 Jul 2022 20:58:21 +0400 Subject: [PATCH] implemented logs, started work in connecting signals --- alterator/include/new_interface.h | 12 ++++++--- alterator/src/new_interface.cpp | 43 +++++++++++++++++++++++++++++-- resources/DistInfo.qml | 25 +++++++++++++++++- shared/AlteratorWindow.qml | 20 +++++++++----- 4 files changed, 87 insertions(+), 13 deletions(-) diff --git a/alterator/include/new_interface.h b/alterator/include/new_interface.h index 6343ba1..83c5cff 100644 --- a/alterator/include/new_interface.h +++ b/alterator/include/new_interface.h @@ -35,7 +35,6 @@ class newInterface: public QQmlComponent{ Q_PROPERTY(DBusPropertyMap* properties READ getProperties -// WRITE setProperties NOTIFY propertiesChanged) public: @@ -60,28 +59,32 @@ public: bool updateDBus(QString key, QVariant val); Q_INVOKABLE QVariant call(QString method, QVariantList args); - -// Q_INVOKABLE void connect(QString signal, ) + Q_INVOKABLE void dbusConnect(QString signalOnDBus, QString signalInQML); public slots: void progress(); void propertyUpdatedFromDBus(QDBusMessage mess); + void onCompleted(); signals: void serviceNameChanged(QString serviceName); void ifaceNameChanged(QString ifaceName); void adressChanged(QString adress); void ISBChanged(bool isb); - void step(); void initialServiceNameChanged(QString serviceName); void initialIfaceNameChanged(QString ifaceName); void initialAdressChanged(QString adress); void initialISBChanged(bool isb); void propertiesChanged(DBusPropertyMap *q); + + void step(); void logSignal(QString record); + void completed(); + private: QDBusInterface *realIface; DBusPropertyMap *properties; + QMap DBusSignals; QString ifaceName; QString serviceName; QString adress; @@ -92,6 +95,7 @@ private: bool initialIsSessionBus; int status; + QStringList initialLog; }; } diff --git a/alterator/src/new_interface.cpp b/alterator/src/new_interface.cpp index 5053717..3598c77 100644 --- a/alterator/src/new_interface.cpp +++ b/alterator/src/new_interface.cpp @@ -87,12 +87,22 @@ void newInterface::progress(){ isSessionBus ? QDBusConnection::sessionBus() : QDBusConnection::systemBus(), this); + if(realIface->isValid()){ + initialLog.append("connected to D-Bus interface " + ifaceName); + }else{ + initialLog.append("There is no such service \"" + serviceName + + "\", with adress \"" + adress + "\" and interface\" " + + ifaceName + "\" on " + + (isSessionBus ? "sessionBus" : "systemBus")); + return; + } QDBusInterface props = QDBusInterface(serviceName, adress, "org.freedesktop.DBus.Introspectable", isSessionBus ? QDBusConnection::sessionBus() : QDBusConnection::systemBus()); QStringList propertyNames; +// QStringList signalNames; QString raw = props.call("Introspect").arguments()[0].toString(); QXmlStreamReader xml(raw); @@ -119,8 +129,8 @@ void newInterface::progress(){ if (!xml.readNextStartElement()) break; - // if (xml.name() == QLatin1String("signal")) - // dbusSignals.append(xml.attributes().value(QLatin1String("name")).toString()); +// if (xml.name() == QLatin1String("signal")) +// signalNames.append(xml.attributes().value(QLatin1String("name")).toString()); if (xml.name() == QLatin1String("property")) propertyNames.append(xml.attributes().value(QStringLiteral("name")).toString()); @@ -162,4 +172,33 @@ QVariant newInterface::call(QString method, QVariantList args){ return QVariant(ans.arguments()); } } + +void newInterface::onCompleted(){ + for(int i = 0; i < initialLog.size(); i++){ + emit logSignal(initialLog[i]); + } +} + +void newInterface::dbusConnect(QString signalOnDBus, QString slotInQML){ + const QMetaObject *const meta = metaObject(); + int border = staticMetaObject.methodCount(); + int methodIndex = meta->indexOfMethod(slotInQML.toLocal8Bit()); + if (methodIndex < border){ + return; + } + QMetaMethod method = meta->method(methodIndex); + if(isSessionBus){ + if(QDBusConnection::sessionBus().connect( + serviceName, adress, ifaceName, signalOnDBus, this + , SLOT(method) )) + {qDebug() << "connected to session bus";} + } + else{ + if(QDBusConnection::systemBus().connect( + serviceName, adress, ifaceName, signalOnDBus, this + , SLOT(method) )) + {qDebug() << "connected to system bus";} + else{qDebug() << "didn't connect to system bus";} + } +} } diff --git a/resources/DistInfo.qml b/resources/DistInfo.qml index 815cc27..5dcf576 100644 --- a/resources/DistInfo.qml +++ b/resources/DistInfo.qml @@ -6,7 +6,6 @@ import Alterator.DistInfo 1.0 import Alterator.newInterface 1.0 import shared 1.0 - ScrollView { id: view objectName: "page" @@ -17,9 +16,33 @@ ScrollView { initialAdress: "/org/freedesktop/hostname1" initialInterfaceName: "org.freedesktop.hostname1" initialIsSessionBus : false + + Component.onCompleted:{ + logSignal.connect(window.addRecord) + completed.connect(hostname.onCompleted) + completed() + } + } + + NewInterface{ + id: hostnameProps + initialServiceName: "org.freedesktop.hostname1" + initialAdress: "/org/freedesktop/hostname1" + initialInterfaceName: "org.freedesktop.DBus.Properties" + initialIsSessionBus : false + + Component.onCompleted:{ + logSignal.connect(window.addRecord) + completed.connect(hostname.onCompleted) + completed() + dbusConnect("PropertiesChanged", fun) + } } anchors.fill: parent + + function fun(){console.log("abc")} + ColumnLayout{ id: content diff --git a/shared/AlteratorWindow.qml b/shared/AlteratorWindow.qml index eb7ef2a..c63f1bc 100644 --- a/shared/AlteratorWindow.qml +++ b/shared/AlteratorWindow.qml @@ -9,7 +9,7 @@ Window{ property string url property string windowId property int state: 0 - property var logs: [] + property var log: ["abc", "qwerty", "cba"] width: 600 height: 650 @@ -26,7 +26,8 @@ Window{ signal forvardS(string senderId) function addRecord(record){ - logs.push(record) + log.push(record) + logRepeater.model++ } Rectangle{ @@ -77,7 +78,6 @@ Window{ Loader{ id: currentPage - objectName: "currentPageN" active: true source: url @@ -88,10 +88,18 @@ Window{ } } - TextArea{ - id: logs + ColumnLayout{ + id: logLayout - text: "logs" + Repeater{ + id:logRepeater + + model: window.log.length + + TextArea{ + text: window.log[index] + } + } } } }