diff --git a/interfaces/notificationsmodel.cpp b/interfaces/notificationsmodel.cpp index caa4dadc9..c17a8162d 100644 --- a/interfaces/notificationsmodel.cpp +++ b/interfaces/notificationsmodel.cpp @@ -106,26 +106,33 @@ void NotificationsModel::refreshNotificationList() return; } - if (!m_notificationList.isEmpty()) { - beginRemoveRows(QModelIndex(), 0, m_notificationList.size() - 1); - qDeleteAll(m_notificationList); - m_notificationList.clear(); - endRemoveRows(); - } + clearNotifications(); if (!m_dbusInterface->isValid()) { - qCDebug(KDECONNECT_INTERFACES) << "dbus interface not valid"; + qCWarning(KDECONNECT_INTERFACES) << "dbus interface not valid"; return; } QDBusPendingReply pendingNotificationIds = m_dbusInterface->activeNotifications(); - pendingNotificationIds.waitForFinished(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingNotificationIds, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(receivedNotifications(QDBusPendingCallWatcher*))); +} + +void NotificationsModel::receivedNotifications(QDBusPendingCallWatcher* watcher) +{ + watcher->deleteLater(); + clearNotifications(); + QDBusPendingReply pendingNotificationIds = *watcher; + + clearNotifications(); if (pendingNotificationIds.isError()) { - qCDebug(KDECONNECT_INTERFACES) << pendingNotificationIds.error(); + qCWarning(KDECONNECT_INTERFACES) << pendingNotificationIds.error(); return; } - const QStringList& notificationIds = pendingNotificationIds.value(); + const QStringList notificationIds = pendingNotificationIds.value(); if (notificationIds.isEmpty()) { return; } @@ -136,8 +143,6 @@ void NotificationsModel::refreshNotificationList() m_notificationList.append(dbusInterface); } endInsertRows(); - - Q_EMIT dataChanged(index(0), index(notificationIds.size() - 1)); } QVariant NotificationsModel::data(const QModelIndex& index, int role) const @@ -219,3 +224,13 @@ void NotificationsModel::dismissAll() } } } + +void NotificationsModel::clearNotifications() +{ + if (!m_notificationList.isEmpty()) { + beginRemoveRows(QModelIndex(), 0, m_notificationList.size() - 1); + qDeleteAll(m_notificationList); + m_notificationList.clear(); + endRemoveRows(); + } +} diff --git a/interfaces/notificationsmodel.h b/interfaces/notificationsmodel.h index 4dba754ea..c54ef65f1 100644 --- a/interfaces/notificationsmodel.h +++ b/interfaces/notificationsmodel.h @@ -68,6 +68,7 @@ private Q_SLOTS: void notificationAdded(const QString& id); void notificationRemoved(const QString& id); void refreshNotificationList(); + void receivedNotifications(QDBusPendingCallWatcher* watcher); Q_SIGNALS: void deviceIdChanged(const QString& value); @@ -75,6 +76,8 @@ Q_SIGNALS: void rowsChanged(); private: + void clearNotifications(); + DeviceNotificationsDbusInterface* m_dbusInterface; QList m_notificationList; QString m_deviceId;