Commit 28bc226e authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Make the NotificationsModel also async

The code was almost identical to the one in DevicesModel, so I did the same
parent 02a29907
......@@ -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<QStringList> 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<QStringList> 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();
}
}
......@@ -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<NotificationDbusInterface*> m_notificationList;
QString m_deviceId;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment