implemented logs, started work in connecting signals
This commit is contained in:
parent
d7e5322f85
commit
b0e45ad1fb
@ -35,7 +35,6 @@ class newInterface: public QQmlComponent{
|
|||||||
|
|
||||||
Q_PROPERTY(DBusPropertyMap* properties
|
Q_PROPERTY(DBusPropertyMap* properties
|
||||||
READ getProperties
|
READ getProperties
|
||||||
// WRITE setProperties
|
|
||||||
NOTIFY propertiesChanged)
|
NOTIFY propertiesChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -60,28 +59,32 @@ public:
|
|||||||
bool updateDBus(QString key, QVariant val);
|
bool updateDBus(QString key, QVariant val);
|
||||||
|
|
||||||
Q_INVOKABLE QVariant call(QString method, QVariantList args);
|
Q_INVOKABLE QVariant call(QString method, QVariantList args);
|
||||||
|
Q_INVOKABLE void dbusConnect(QString signalOnDBus, QString signalInQML);
|
||||||
// Q_INVOKABLE void connect(QString signal, )
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void progress();
|
void progress();
|
||||||
void propertyUpdatedFromDBus(QDBusMessage mess);
|
void propertyUpdatedFromDBus(QDBusMessage mess);
|
||||||
|
void onCompleted();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void serviceNameChanged(QString serviceName);
|
void serviceNameChanged(QString serviceName);
|
||||||
void ifaceNameChanged(QString ifaceName);
|
void ifaceNameChanged(QString ifaceName);
|
||||||
void adressChanged(QString adress);
|
void adressChanged(QString adress);
|
||||||
void ISBChanged(bool isb);
|
void ISBChanged(bool isb);
|
||||||
void step();
|
|
||||||
void initialServiceNameChanged(QString serviceName);
|
void initialServiceNameChanged(QString serviceName);
|
||||||
void initialIfaceNameChanged(QString ifaceName);
|
void initialIfaceNameChanged(QString ifaceName);
|
||||||
void initialAdressChanged(QString adress);
|
void initialAdressChanged(QString adress);
|
||||||
void initialISBChanged(bool isb);
|
void initialISBChanged(bool isb);
|
||||||
void propertiesChanged(DBusPropertyMap *q);
|
void propertiesChanged(DBusPropertyMap *q);
|
||||||
|
|
||||||
|
void step();
|
||||||
void logSignal(QString record);
|
void logSignal(QString record);
|
||||||
|
void completed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDBusInterface *realIface;
|
QDBusInterface *realIface;
|
||||||
DBusPropertyMap *properties;
|
DBusPropertyMap *properties;
|
||||||
|
QMap<QString, QMetaMethod> DBusSignals;
|
||||||
QString ifaceName;
|
QString ifaceName;
|
||||||
QString serviceName;
|
QString serviceName;
|
||||||
QString adress;
|
QString adress;
|
||||||
@ -92,6 +95,7 @@ private:
|
|||||||
bool initialIsSessionBus;
|
bool initialIsSessionBus;
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
|
QStringList initialLog;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,12 +87,22 @@ void newInterface::progress(){
|
|||||||
isSessionBus ? QDBusConnection::sessionBus()
|
isSessionBus ? QDBusConnection::sessionBus()
|
||||||
: QDBusConnection::systemBus(),
|
: QDBusConnection::systemBus(),
|
||||||
this);
|
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 props =
|
||||||
QDBusInterface(serviceName, adress,
|
QDBusInterface(serviceName, adress,
|
||||||
"org.freedesktop.DBus.Introspectable",
|
"org.freedesktop.DBus.Introspectable",
|
||||||
isSessionBus ? QDBusConnection::sessionBus()
|
isSessionBus ? QDBusConnection::sessionBus()
|
||||||
: QDBusConnection::systemBus());
|
: QDBusConnection::systemBus());
|
||||||
QStringList propertyNames;
|
QStringList propertyNames;
|
||||||
|
// QStringList signalNames;
|
||||||
QString raw = props.call("Introspect").arguments()[0].toString();
|
QString raw = props.call("Introspect").arguments()[0].toString();
|
||||||
|
|
||||||
QXmlStreamReader xml(raw);
|
QXmlStreamReader xml(raw);
|
||||||
@ -120,7 +130,7 @@ void newInterface::progress(){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// if (xml.name() == QLatin1String("signal"))
|
// if (xml.name() == QLatin1String("signal"))
|
||||||
// dbusSignals.append(xml.attributes().value(QLatin1String("name")).toString());
|
// signalNames.append(xml.attributes().value(QLatin1String("name")).toString());
|
||||||
if (xml.name() == QLatin1String("property"))
|
if (xml.name() == QLatin1String("property"))
|
||||||
propertyNames.append(xml.attributes().value(QStringLiteral("name")).toString());
|
propertyNames.append(xml.attributes().value(QStringLiteral("name")).toString());
|
||||||
|
|
||||||
@ -162,4 +172,33 @@ QVariant newInterface::call(QString method, QVariantList args){
|
|||||||
return QVariant(ans.arguments());
|
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";}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import Alterator.DistInfo 1.0
|
|||||||
import Alterator.newInterface 1.0
|
import Alterator.newInterface 1.0
|
||||||
import shared 1.0
|
import shared 1.0
|
||||||
|
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
id: view
|
id: view
|
||||||
objectName: "page"
|
objectName: "page"
|
||||||
@ -17,9 +16,33 @@ ScrollView {
|
|||||||
initialAdress: "/org/freedesktop/hostname1"
|
initialAdress: "/org/freedesktop/hostname1"
|
||||||
initialInterfaceName: "org.freedesktop.hostname1"
|
initialInterfaceName: "org.freedesktop.hostname1"
|
||||||
initialIsSessionBus : false
|
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
|
anchors.fill: parent
|
||||||
|
|
||||||
|
function fun(){console.log("abc")}
|
||||||
|
|
||||||
ColumnLayout{
|
ColumnLayout{
|
||||||
id: content
|
id: content
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ Window{
|
|||||||
property string url
|
property string url
|
||||||
property string windowId
|
property string windowId
|
||||||
property int state: 0
|
property int state: 0
|
||||||
property var logs: []
|
property var log: ["abc", "qwerty", "cba"]
|
||||||
|
|
||||||
width: 600
|
width: 600
|
||||||
height: 650
|
height: 650
|
||||||
@ -26,7 +26,8 @@ Window{
|
|||||||
signal forvardS(string senderId)
|
signal forvardS(string senderId)
|
||||||
|
|
||||||
function addRecord(record){
|
function addRecord(record){
|
||||||
logs.push(record)
|
log.push(record)
|
||||||
|
logRepeater.model++
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
@ -77,7 +78,6 @@ Window{
|
|||||||
|
|
||||||
Loader{
|
Loader{
|
||||||
id: currentPage
|
id: currentPage
|
||||||
objectName: "currentPageN"
|
|
||||||
|
|
||||||
active: true
|
active: true
|
||||||
source: url
|
source: url
|
||||||
@ -88,10 +88,18 @@ Window{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextArea{
|
ColumnLayout{
|
||||||
id: logs
|
id: logLayout
|
||||||
|
|
||||||
text: "logs"
|
Repeater{
|
||||||
|
id:logRepeater
|
||||||
|
|
||||||
|
model: window.log.length
|
||||||
|
|
||||||
|
TextArea{
|
||||||
|
text: window.log[index]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user