summaryrefslogtreecommitdiff
path: root/rockwork/pebbles.cpp
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2016-02-18 09:13:32 +0100
committerAndrew Branson <andrew.branson@cern.ch>2016-02-18 09:13:32 +0100
commitf4910b3ac84c72a7e17c99895a3b9abb0e9534fe (patch)
tree91ae8cfd80dc3d7a2adedee9cab0d407c5c23c84 /rockwork/pebbles.cpp
parent7305ce8e080d0a6ee7505fe978a2e601b56a5ce8 (diff)
parent8f014f0915c7bdc97573f953aa9a3ae25a5f953a (diff)
Merge branch 'rockwork'
Conflicts: po/de.po po/en_GB.po po/eu.po po/fr.po po/hu.po po/it.po po/pt.po po/rockwork.mzanetti.pot po/ru.po po/template.pot rockwork/InfoPage.qml rockwork/Main.qml rockwork/NotificationsPage.qml rockworkd/rockworkd.pro version.pri
Diffstat (limited to 'rockwork/pebbles.cpp')
-rw-r--r--rockwork/pebbles.cpp27
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)