diff --git a/plugins/notifications/notification.h b/plugins/notifications/notification.h --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -71,6 +71,7 @@ Q_SIGNALS: void dismissRequested(const QString& mInternalId); void replyRequested(); + void ready(); private: QString mInternalId; diff --git a/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -55,6 +55,7 @@ void Notification::show() { + Q_EMIT ready(); if (!mSilent) { mClosed = false; mNotification->sendEvent(); diff --git a/plugins/notifications/notificationsdbusinterface.h b/plugins/notifications/notificationsdbusinterface.h --- a/plugins/notifications/notificationsdbusinterface.h +++ b/plugins/notifications/notificationsdbusinterface.h @@ -39,6 +39,10 @@ Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications") public: + enum RemoveType{ + KeepNotification, DestroyNotification + }; + explicit NotificationsDbusInterface(KdeConnectPlugin* plugin); ~NotificationsDbusInterface() override; @@ -58,7 +62,7 @@ Q_SCRIPTABLE void allNotificationsRemoved(); private /*methods*/: - void removeNotification(const QString& internalId); + void removeNotification(const QString& internalId, RemoveType removetype=DestroyNotification); QString newId(); //Generates successive identifitiers to use as public ids private /*attributes*/: diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -80,31 +80,37 @@ } else { QString id = np.get(QStringLiteral("id")); + Notification* noti; + if (!mInternalIdToPublicId.contains(id)) { - Notification* noti = new Notification(np, this); - addNotification(noti); + noti = new Notification(np, this); } else { QString pubId = mInternalIdToPublicId[id]; - mNotifications[pubId]->update(np); + noti = mNotifications[pubId]; + noti->update(np); } + + connect(noti, &Notification::ready, this, [this, noti]{ + addNotification(noti); + }); } } void NotificationsDbusInterface::addNotification(Notification* noti) { const QString& internalId = noti->internalId(); if (mInternalIdToPublicId.contains(internalId)) { - removeNotification(internalId); + removeNotification(internalId, KeepNotification); } //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId; connect(noti, &Notification::dismissRequested, this, &NotificationsDbusInterface::dismissRequested); - - connect(noti, &Notification::replyRequested, this, [this,noti]{ - replyRequested(noti); + + connect(noti, &Notification::replyRequested, this, [this,noti]{ + replyRequested(noti); }); const QString& publicId = newId(); @@ -115,26 +121,29 @@ Q_EMIT notificationPosted(publicId); } -void NotificationsDbusInterface::removeNotification(const QString& internalId) +void NotificationsDbusInterface::removeNotification(const QString& internalId, RemoveType removetype) { //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "removeNotification" << internalId; if (!mInternalIdToPublicId.contains(internalId)) { - qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId; + //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by internal Id: " << internalId; return; } QString publicId = mInternalIdToPublicId.take(internalId); Notification* noti = mNotifications.take(publicId); if (!noti) { - qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId; + //qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "Not found noti by public Id: " << publicId; return; } //Deleting the notification will unregister it automatically - //QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); - noti->deleteLater(); + if (removetype==KeepNotification){ + QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); + } else if (removetype==DestroyNotification){ + noti->deleteLater(); + } Q_EMIT notificationRemoved(publicId); }