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{ + KEEP_NOTI, DESTROY_NOTI + }; + 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=DESTROY_NOTI); 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,13 +80,19 @@ } 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); + }); } } @@ -95,16 +101,16 @@ const QString& internalId = noti->internalId(); if (mInternalIdToPublicId.contains(internalId)) { - removeNotification(internalId); + removeNotification(internalId, KEEP_NOTI); } //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,12 +121,12 @@ 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; } @@ -128,13 +134,16 @@ 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==KEEP_NOTI){ + QDBusConnection::sessionBus().unregisterObject(mDevice->dbusPath()+"/notifications/"+publicId); + } else if (removetype==DESTROY_NOTI){ + noti->deleteLater(); + } Q_EMIT notificationRemoved(publicId); }