diff options
Diffstat (limited to 'rockwork/pebbles.cpp')
| -rw-r--r-- | rockwork/pebbles.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/rockwork/pebbles.cpp b/rockwork/pebbles.cpp index e45691e..65eeb6a 100644 --- a/rockwork/pebbles.cpp +++ b/rockwork/pebbles.cpp @@ -16,12 +16,22 @@ Pebbles::Pebbles(QObject *parent): QAbstractListModel(parent) { refresh(); - m_watcher = new QDBusServiceWatcher(ROCKWORK_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this); + m_watcher = new QDBusServiceWatcher(ROCKWORK_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); QDBusConnection::sessionBus().connect(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE, "PebblesChanged", this, SLOT(refresh())); connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, [this]() { + qDebug() << "service Registered!"; refresh(); QDBusConnection::sessionBus().connect(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE, "PebblesChanged", this, SLOT(refresh())); }); + connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, [this]() { + qDebug() << "service Unregistered!"; + beginResetModel(); + qDeleteAll(m_pebbles); + m_pebbles.clear(); + endResetModel(); + m_connectedToService = false; + emit connectedToServiceChanged(); + }); } int Pebbles::rowCount(const QModelIndex &parent) const @@ -56,6 +66,11 @@ QHash<int, QByteArray> Pebbles::roleNames() const return roles; } +bool Pebbles::connectedToService() +{ + return m_connectedToService; +} + QString Pebbles::version() const { QDBusInterface iface(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE); @@ -77,7 +92,10 @@ QString Pebbles::version() const Pebble *Pebbles::get(int index) const { - return m_pebbles.at(index); + if (index >= 0 && index < m_pebbles.count()) { + return m_pebbles.at(index); + } + return nullptr; } int Pebbles::find(const QString &address) const @@ -148,6 +166,11 @@ void Pebbles::refresh() endRemoveRows(); emit countChanged(); } + + if (!m_connectedToService) { + m_connectedToService = true; + emit connectedToServiceChanged(); + } } bool Pebbles::sortPebbles(Pebble *a, Pebble *b) |
