diff --git a/panels/notification/bubble/bubbleitem.cpp b/panels/notification/bubble/bubbleitem.cpp index 26c13ff9e..0a257321a 100644 --- a/panels/notification/bubble/bubbleitem.cpp +++ b/panels/notification/bubble/bubbleitem.cpp @@ -244,9 +244,15 @@ QVariantList BubbleItem::actions() const void BubbleItem::updateActions() { QStringList actions = m_entity.actions(); - if (actions.contains(QLatin1String("default"))) { - actions.removeAll(QLatin1String("default")); + const auto index = actions.indexOf(QLatin1String("default")); + if (index >= 0) { + // default Action maybe have text. m_defaultAction = QLatin1String("default"); + if (actions.size() % 2 == 1) { + actions.remove(index); + } else { + actions.remove(index, 2); + } } Q_ASSERT(actions.size() % 2 != 1); diff --git a/panels/notification/bubble/package/NormalBubble.qml b/panels/notification/bubble/package/NormalBubble.qml index 9ee8dac12..5ee6c71a9 100644 --- a/panels/notification/bubble/package/NormalBubble.qml +++ b/panels/notification/bubble/package/NormalBubble.qml @@ -52,8 +52,8 @@ D.Control { if (!bubble.defaultAction) return - console.log("default action", bubble.index) - Applet.invokeDefaultAction(bubble.index, bubble.defaultAction) + console.log("default action notify", bubble.appName, bubble.defaultAction) + Applet.invokeAction(bubble.index, bubble.defaultAction) } property bool longPressed onPressAndHold: { diff --git a/panels/notification/center/notifyitem.cpp b/panels/notification/center/notifyitem.cpp index f8534e344..32930c4b9 100644 --- a/panels/notification/center/notifyitem.cpp +++ b/panels/notification/center/notifyitem.cpp @@ -117,9 +117,14 @@ QVariantList AppNotifyItem::actions() const void AppNotifyItem::updateActions() { QStringList actions = m_entity.actions(); - if (actions.contains(QLatin1String("default"))) { - actions.removeAll(QLatin1String("default")); - m_defaultAction = QLatin1String("default"); + const auto index = actions.indexOf(QLatin1String("default")); + if (index >= 0) { + // default Action maybe have text. + if (actions.size() % 2 == 1) { + actions.remove(index); + } else { + actions.remove(index, 2); + } } Q_ASSERT(actions.size() % 2 != 1); diff --git a/panels/notification/common/notifyentity.cpp b/panels/notification/common/notifyentity.cpp index 956e2e180..c4bf52898 100644 --- a/panels/notification/common/notifyentity.cpp +++ b/panels/notification/common/notifyentity.cpp @@ -107,6 +107,11 @@ bool NotifyEntity::operator==(const NotifyEntity &other) const return false; } +bool NotifyEntity::operator!=(const NotifyEntity &other) const +{ + return !(operator==(other)); +} + bool NotifyEntity::isValid() const { return d && d->id > 0; diff --git a/panels/notification/common/notifyentity.h b/panels/notification/common/notifyentity.h index eba3cf960..9a40fcdef 100644 --- a/panels/notification/common/notifyentity.h +++ b/panels/notification/common/notifyentity.h @@ -44,6 +44,7 @@ class NotifyEntity NotifyEntity &operator=(NotifyEntity &&other); bool operator==(const NotifyEntity &other) const; + bool operator!=(const NotifyEntity &other) const; bool isValid() const; diff --git a/panels/notification/server/dbusadaptor.cpp b/panels/notification/server/dbusadaptor.cpp index 51116236a..defed6f61 100644 --- a/panels/notification/server/dbusadaptor.cpp +++ b/panels/notification/server/dbusadaptor.cpp @@ -19,7 +19,7 @@ DbusAdaptor::DbusAdaptor(QObject *parent) QStringList DbusAdaptor::GetCapabilities() { - qDebug(notifyLog) << "GetCapabilities"; + qInfo(notifyLog) << "GetCapabilities"; return manager()->GetCapabilities(); } @@ -40,13 +40,13 @@ uint DbusAdaptor::Notify(const QString &appName, uint replacesId, const QString void DbusAdaptor::CloseNotification(uint id) { - qDebug(notifyLog) << "Close notification" << id; + qInfo(notifyLog) << "Close notification" << id; manager()->CloseNotification(id); } void DbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion) { - qDebug(notifyLog) << "GetServerInformation"; + qInfo(notifyLog) << "GetServerInformation"; manager()->GetServerInformation(name, vendor, version, specVersion); } @@ -63,6 +63,7 @@ DDENotificationDbusAdaptor::DDENotificationDbusAdaptor(QObject *parent) QStringList DDENotificationDbusAdaptor::GetCapabilities() { + qInfo(notifyLog) << "GetCapabilities"; return manager()->GetCapabilities(); } @@ -83,11 +84,13 @@ uint DDENotificationDbusAdaptor::Notify(const QString &appName, uint replacesId, void DDENotificationDbusAdaptor::CloseNotification(uint id) { + qInfo(notifyLog) << "Close Notification" << id; manager()->CloseNotification(id); } void DDENotificationDbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion) { + qInfo(notifyLog) << "GetServerInformation"; manager()->GetServerInformation(name, vendor, version, specVersion); } @@ -118,7 +121,8 @@ void DDENotificationDbusAdaptor::SetAppInfo(const QString &appId, uint configIte QString DDENotificationDbusAdaptor::GetAppSetting(const QString &appName) { - return QString(); + Q_UNUSED(appName) + return {}; } void DDENotificationDbusAdaptor::SetAppSetting(const QString &settings) diff --git a/panels/notification/server/notificationmanager.cpp b/panels/notification/server/notificationmanager.cpp index ed6c70d5b..aba7d07b5 100644 --- a/panels/notification/server/notificationmanager.cpp +++ b/panels/notification/server/notificationmanager.cpp @@ -103,12 +103,14 @@ uint NotificationManager::recordCount() const void NotificationManager::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey) { + qInfo(notifyLog) << "Action invoked, bubbleId:" << bubbleId << ", id:" << id << ", actionKey" << actionKey; auto entity = m_persistence->fetchEntity(id); if (entity.isValid()) { + doActionInvoked(entity, actionKey); + entity.setProcessedType(NotifyEntity::Removed); updateEntityProcessed(entity); } - doActionInvoked(entity, actionKey); Q_EMIT ActionInvoked(bubbleId, actionKey); Q_EMIT NotificationClosed(bubbleId, NotifyEntity::Closed); @@ -257,19 +259,22 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const } } + qInfo(notifyLog) << "Notify done, bubbleId:" << entity.bubbleId() << ", id:" << entity.id(); + // If replaces_id is 0, the return value is a UINT32 that represent the notification. // If replaces_id is not 0, the returned value is the same value as replaces_id. - return replacesId == 0 ? entity.bubbleId() : replacesId; + return entity.bubbleId(); } void NotificationManager::CloseNotification(uint id) { - // TODO If the notification no longer exists, an empty D-BUS Error message is sent back. - const auto entity = m_persistence->fetchLastEntity(id); + auto entity = m_persistence->fetchLastEntity(id); if (entity.isValid()) { - Q_EMIT NotificationStateChanged(entity.id(), entity.processedType()); + entity.setProcessedType(NotifyEntity::Removed); + updateEntityProcessed(entity); } Q_EMIT NotificationClosed(id, NotifyEntity::Closed); + qDebug(notifyLog) << "Close notify, bubbleId" << id << ", id:" << entity.id(); } void NotificationManager::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion) @@ -413,6 +418,7 @@ void NotificationManager::updateEntityProcessed(const NotifyEntity &entity) const auto bluetooth = entity.body().contains("%") && entity.actions().contains("cancel"); if (removed || !showInCenter || bluetooth) { m_persistence->removeEntity(id); + removePendingEntity(entity); } else { m_persistence->updateEntityProcessedType(id, entity.processedType()); } @@ -485,4 +491,18 @@ void NotificationManager::onHandingPendingEntities() } } +void NotificationManager::removePendingEntity(const NotifyEntity &entity) +{ + for (auto iter = m_pendingTimeoutEntities.begin(); iter != m_pendingTimeoutEntities.end();) { + const auto item = iter.value(); + if (item != entity) { + iter++; + continue; + } + m_pendingTimeoutEntities.erase(iter); + onHandingPendingEntities(); + break; + } +} + } // notification diff --git a/panels/notification/server/notificationmanager.h b/panels/notification/server/notificationmanager.h index c3a6dc85f..bdbe1354c 100644 --- a/panels/notification/server/notificationmanager.h +++ b/panels/notification/server/notificationmanager.h @@ -81,6 +81,7 @@ public Q_SLOTS: private slots: void onHandingPendingEntities(); + void removePendingEntity(const NotifyEntity &entity); private: uint m_replacesCount = 0;