aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src/qdbusobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel/src/qdbusobject.cpp')
-rw-r--r--libqmenumodel/src/qdbusobject.cpp55
1 files changed, 48 insertions, 7 deletions
diff --git a/libqmenumodel/src/qdbusobject.cpp b/libqmenumodel/src/qdbusobject.cpp
index c586972..f289bf9 100644
--- a/libqmenumodel/src/qdbusobject.cpp
+++ b/libqmenumodel/src/qdbusobject.cpp
@@ -25,6 +25,9 @@ extern "C" {
#include "qdbusobject.h"
#include <QDebug>
+#include <QCoreApplication>
+
+const QEvent::Type DbusObjectServiceEvent::eventType = static_cast<QEvent::Type>(QEvent::registerEventType());
/*!
\qmltype QDBusObject
@@ -73,8 +76,9 @@ extern "C" {
\endlist
*/
-QDBusObject::QDBusObject()
- :m_watchId(0),
+QDBusObject::QDBusObject(QObject* listener)
+ :m_listener(listener),
+ m_watchId(0),
m_busType(DBusEnums::None),
m_status(DBusEnums::Disconnected)
{
@@ -181,14 +185,51 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *,
{
QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
- self->serviceAppear(connection);
- self->setStatus(DBusEnums::Connected);
+ if (self->m_listener) {
+ DbusObjectServiceEvent dose(connection, true);
+ QCoreApplication::sendEvent(self->m_listener, &dose);
+ }
}
void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data)
{
- QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
+ QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
+
+ if (self->m_listener) {
+ DbusObjectServiceEvent dose(connection, false);
+ QCoreApplication::sendEvent(self->m_listener, &dose);
+ }
+}
+
+bool QDBusObject::event(QEvent* e)
+{
+ if (e->type() == DbusObjectServiceEvent::eventType) {
+ DbusObjectServiceEvent *dose = static_cast<DbusObjectServiceEvent*>(e);
+ if (dose->visible) {
+ serviceAppear(dose->connection);
+ setStatus(DBusEnums::Connected);
+ } else {
+ setStatus(DBusEnums::Connecting);
+ serviceVanish(dose->connection);
+ }
+ return true;
+ }
+ return false;
+}
+
+DbusObjectServiceEvent::DbusObjectServiceEvent(GDBusConnection* _connection, bool _visible)
+ : QEvent(DbusObjectServiceEvent::eventType),
+ connection(_connection),
+ visible(_visible)
+{
+ if (connection) {
+ g_object_ref(connection);
+ }
+}
- self->setStatus(DBusEnums::Connecting);
- self->serviceVanish(connection);
+DbusObjectServiceEvent::~DbusObjectServiceEvent()
+{
+ if (connection) {
+ g_object_unref(connection);
+ }
}