From 3c52767b24f27ac166f9c68e2fc73811527bafe1 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Mon, 30 Jun 2014 01:59:14 +0200 Subject: Reworked WatchConnector connection/disconnection handling Fixed crash after Pebble disconnecting --- daemon/manager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'daemon/manager.cpp') diff --git a/daemon/manager.cpp b/daemon/manager.cpp index 5e09c75..691d7a5 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -5,7 +5,8 @@ #include Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallManager *voice) : - QObject(0), watch(watch), dbus(dbus), voice(voice) + QObject(0), watch(watch), dbus(dbus), voice(voice), + notification(MNotification::DeviceEvent) { // We don't need to handle presence changes, so report them separately and ignore them QMap parameters; @@ -26,10 +27,23 @@ Manager::Manager(watch::WatchConnector *watch, DBusConnector *dbus, VoiceCallMan // Watch instantiated hangup, follow the orders connect(watch, SIGNAL(hangup()), SLOT(hangupAll())); + connect(watch, SIGNAL(connectedChanged()), SLOT(onConnectedChanged())); if (btDevice.isValid()) { qDebug() << "BT local name:" << btDevice.name(); - watch->deviceConnect(dbus->pebbleName, dbus->pebbleAddress); + connect(dbus, SIGNAL(pebbleChanged()), SLOT(onPebbleChanged())); + dbus->findPebble(); + } +} + +void Manager::onPebbleChanged() +{ + const QVariantMap & pebble = dbus->pebble(); + QString name = pebble["Name"].toString(); + if (name.isEmpty()) { + qDebug() << "Pebble gone"; + } else { + watch->deviceConnect(name, pebble["Address"].toString()); } } -- cgit v1.2.3