diff --git a/interfaces/notificationsmodel.cpp b/interfaces/notificationsmodel.cpp index 16fbcd3b5..2a6a24c22 100644 --- a/interfaces/notificationsmodel.cpp +++ b/interfaces/notificationsmodel.cpp @@ -95,8 +95,6 @@ void NotificationsModel::setDeviceId(const QString& deviceId) this, &NotificationsModel::notificationRemoved); connect(m_dbusInterface, &OrgKdeKdeconnectDeviceNotificationsInterface::allNotificationsRemoved, this, &NotificationsModel::clearNotifications); - connect(m_dbusInterface, &OrgKdeKdeconnectDeviceNotificationsInterface::notificationUpdated, - this, &NotificationsModel::notificationUpdated); refreshNotificationList(); @@ -107,6 +105,7 @@ void NotificationsModel::notificationAdded(const QString& id) { 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::clearNotifications() } } -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/interfaces/notificationsmodel.h b/interfaces/notificationsmodel.h index a1bf24b62..9da5830c2 100644 --- a/interfaces/notificationsmodel.h +++ b/interfaces/notificationsmodel.h @@ -71,7 +71,7 @@ public Q_SLOTS: 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/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp index fcd73cd37..4f498c9cf 100644 --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -47,11 +47,10 @@ Notification::Notification(const NetworkPacket& np, QObject* parent) 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,7 +69,6 @@ void Notification::show() m_ready = true; Q_EMIT ready(); if (!m_silent) { - m_closed = false; m_notification->sendEvent(); } } @@ -78,12 +76,12 @@ void Notification::show() 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 @@ KNotification* Notification::createKNotification(bool update, const NetworkPacke connect(m_notification, &KNotification::action1Activated, this, &Notification::reply); } - connect(m_notification, &KNotification::closed, this, &Notification::closed); - return m_notification; } @@ -171,11 +167,6 @@ void Notification::reply() 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/notification.h b/plugins/notifications/notification.h index b902334fd..44b212dd8 100644 --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -62,17 +62,16 @@ public: 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 @@ private: 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/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp index 683043230..417149795 100644 --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -74,35 +74,26 @@ void NotificationsDbusInterface::processPacket(const NetworkPacket& np) if (id.startsWith(QLatin1String("org.kde.kdeconnect_tp::"))) id = id.mid(id.indexOf(QLatin1String("::")) + 2); removeNotification(id); - } else { - QString id = np.get(QStringLiteral("id")); - - if (!m_internalIdToPublicId.contains(id)) { - Notification* noti = new Notification(np, this); - - if (noti->isReady()) { - addNotification(noti); - } else { - connect(noti, &Notification::ready, this, &NotificationsDbusInterface::notificationReady); - } - } 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); - }); - } - } - + return; } + + QString id = np.get(QStringLiteral("id")); + + Notification* noti = nullptr; + + if (!m_internalIdToPublicId.contains(id)) { + noti = new Notification(np, this); + + if (noti->isReady()) { + addNotification(noti); + } else { + 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)