diff --git a/dserial-server/controller.cpp b/dserial-server/controller.cpp index 463083546a8680eec4856ee4ea92aa875d351d7a..cb9cf6aa2f714a049c701cbcec725eea65ee2817 100644 --- a/dserial-server/controller.cpp +++ b/dserial-server/controller.cpp @@ -10,6 +10,7 @@ Controller::Controller(QObject *parent) : QObject(parent), connection(QDBusConne port->dbusPath.setPath("/fake/test0"); connection.registerObject(port->dbusPath.path(), port); ports.append(port); + notifyPropertyChanged("PortList"); } QStringList Controller::PortList() const @@ -37,9 +38,10 @@ void Controller::CreateFilePort(QString) void Controller::Autodetect() { qDebug() << "Autodetect"; + bool changed = false; // Remove nonexistent for(Port *port : ports) { - port->Exists(); + if(!port->Exists()) changed = true; } // Detect new @@ -54,6 +56,7 @@ void Controller::Autodetect() } if(!isInList) { + changed = true; Port *port = new Port(info.systemLocation()); new PortAdaptor(port); port->dbusPath.setPath("/autodetected"+info.systemLocation()); @@ -63,6 +66,7 @@ void Controller::Autodetect() ports.append(port); } } + if(changed) notifyPropertyChanged("PortList"); qDebug() << "Autodetect done"; } @@ -85,3 +89,17 @@ void Controller::removePort(QDBusObjectPath id) } } } + +void Controller::notifyPropertyChanged( const char *propertyName ) +{ + QDBusMessage signal = QDBusMessage::createSignal( + "/controller", + "org.freedesktop.DBus.Properties", + "PropertiesChanged"); + signal << QString("info.skorepa.DSerial.controller"); + QVariantMap changedProps; + changedProps.insert(propertyName, property(propertyName)); + signal << changedProps; + signal << QStringList(); + QDBusConnection::sessionBus().send(signal); +} diff --git a/dserial-server/controller.h b/dserial-server/controller.h index 9d9bb3adc0fe84eb44995c25dc1f87680f4fd773..c6148b8acaa65755c8389882603de748db9821c6 100644 --- a/dserial-server/controller.h +++ b/dserial-server/controller.h @@ -33,6 +33,9 @@ class Controller : public QObject public: QDBusConnection connection; + + private: + void notifyPropertyChanged( const char *propertyName ); }; #endif // CONTROLLER_H