diff --git a/interfaces/notificationsmodel.h b/interfaces/notificationsmodel.h --- a/interfaces/notificationsmodel.h +++ b/interfaces/notificationsmodel.h @@ -71,7 +71,7 @@ private Q_SLOTS: void notificationAdded(const QString& id); void notificationRemoved(const QString& id); - void notificationUpdated(const QString& id); + void notificationUpdated(); void refreshNotificationList(); void receivedNotifications(QDBusPendingCallWatcher* watcher); void clearNotifications(); diff --git a/interfaces/notificationsmodel.cpp b/interfaces/notificationsmodel.cpp --- a/interfaces/notificationsmodel.cpp +++ b/interfaces/notificationsmodel.cpp @@ -95,8 +95,6 @@ this, &NotificationsModel::notificationRemoved); connect(m_dbusInterface, &OrgKdeKdeconnectDeviceNotificationsInterface::allNotificationsRemoved, this, &NotificationsModel::clearNotifications); - connect(m_dbusInterface, &OrgKdeKdeconnectDeviceNotificationsInterface::notificationUpdated, - this, &NotificationsModel::notificationUpdated); refreshNotificationList(); @@ -107,6 +105,7 @@ { beginInsertRows(QModelIndex(), 0, 0); NotificationDbusInterface* dbusInterface = new NotificationDbusInterface(m_deviceId, id, this); + connect(dbusInterface, &NotificationDbusInterface::ready, this, &NotificationsModel::notificationUpdated); m_notificationList.prepend(dbusInterface); endInsertRows(); } @@ -266,9 +265,7 @@ } } -void NotificationsModel::notificationUpdated(const QString& id) +void NotificationsModel::notificationUpdated() { - //TODO only emit the affected indices - Q_UNUSED(id); Q_EMIT dataChanged(index(0,0), index(m_notificationList.size() - 1, 0)); } diff --git a/plugins/notifications/notification.h b/plugins/notifications/notification.h --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -62,17 +62,16 @@ bool silent() const { return m_silent; } void update(const NetworkPacket& np); bool isReady() const { return m_ready; } - KNotification* createKNotification(bool update, const NetworkPacket& np); + KNotification* createKNotification(const NetworkPacket& np); public Q_SLOTS: Q_SCRIPTABLE void dismiss(); Q_SCRIPTABLE void reply(); - void closed(); Q_SIGNALS: void dismissRequested(const QString& m_internalId); void replyRequested(); - void ready(); + Q_SCRIPTABLE void ready(); private: QString m_internalId; @@ -84,10 +83,9 @@ QString m_requestReplyId; bool m_dismissable; bool m_hasIcon; - KNotification* m_notification; + QPointer m_notification; QDir m_imagesDir; bool m_silent; - bool m_closed; QString m_payloadHash; bool m_ready; diff --git a/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -47,11 +47,10 @@ m_imagesDir = QDir::temp().absoluteFilePath(QStringLiteral("kdeconnect_") + username); m_imagesDir.mkpath(m_imagesDir.absolutePath()); QFile(m_imagesDir.absolutePath()).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner); - m_closed = false; m_ready = false; parseNetworkPacket(np); - createKNotification(false, np); + createKNotification(np); } Notification::~Notification() @@ -70,20 +69,19 @@ m_ready = true; Q_EMIT ready(); if (!m_silent) { - m_closed = false; m_notification->sendEvent(); } } void Notification::update(const NetworkPacket& np) { parseNetworkPacket(np); - createKNotification(!m_closed, np); + createKNotification(np); } -KNotification* Notification::createKNotification(bool update, const NetworkPacket& np) +KNotification* Notification::createKNotification(const NetworkPacket& np) { - if (!update) { + if (!m_notification) { m_notification = new KNotification(QStringLiteral("notification"), KNotification::CloseOnTimeout, this); m_notification->setComponentName(QStringLiteral("kdeconnect")); } @@ -121,8 +119,6 @@ connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); } - connect(m_notification, &KNotification::closed, this, &Notification::closed); - return m_notification; } @@ -171,11 +167,6 @@ Q_EMIT replyRequested(); } -void Notification::closed() -{ - m_closed = true; -} - void Notification::parseNetworkPacket(const NetworkPacket& np) { m_internalId = np.get(QStringLiteral("id")); diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -74,35 +74,26 @@ if (id.startsWith(QLatin1String("org.kde.kdeconnect_tp::"))) id = id.mid(id.indexOf(QLatin1String("::")) + 2); removeNotification(id); - } else { - QString id = np.get(QStringLiteral("id")); + return; + } - if (!m_internalIdToPublicId.contains(id)) { - Notification* noti = new Notification(np, this); + QString id = np.get(QStringLiteral("id")); - if (noti->isReady()) { - addNotification(noti); - } else { - connect(noti, &Notification::ready, this, &NotificationsDbusInterface::notificationReady); - } + Notification* noti = nullptr; + + if (!m_internalIdToPublicId.contains(id)) { + noti = new Notification(np, this); + + if (noti->isReady()) { + addNotification(noti); } else { - QString pubId = m_internalIdToPublicId.value(id); - Notification* noti = m_notifications.value(pubId); - if (!noti) - return; - - noti->update(np); - - if (noti->isReady()) { - Q_EMIT notificationUpdated(pubId); - } else { - connect(noti, &Notification::ready, this, [this, pubId]{ - Q_EMIT notificationUpdated(pubId); - }); - } + connect(noti, &Notification::ready, this, &NotificationsDbusInterface::notificationReady); } - + } else { + QString pubId = m_internalIdToPublicId.value(id); + noti = m_notifications.value(pubId); } + noti->update(np); } void NotificationsDbusInterface::addNotification(Notification* noti)