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
|
||||
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<QString, QMetaMethod> DBusSignals;
|
||||
QString ifaceName;
|
||||
QString serviceName;
|
||||
QString adress;
|
||||
@ -92,6 +95,7 @@ private:
|
||||
bool initialIsSessionBus;
|
||||
|
||||
int status;
|
||||
QStringList initialLog;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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";}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user