diff --git a/panels/notification/bubble/bubbleitem.cpp b/panels/notification/bubble/bubbleitem.cpp index a389b07d8..08b8f1b0a 100644 --- a/panels/notification/bubble/bubbleitem.cpp +++ b/panels/notification/bubble/bubbleitem.cpp @@ -243,12 +243,18 @@ QVariantList BubbleItem::actions() const void BubbleItem::updateActions() { QStringList actions = m_entity.actions(); - const auto defaultIndex = actions.indexOf(QLatin1String("default")); - if (defaultIndex >= 0) { - actions.remove(defaultIndex, 2); + if (actions.contains(QLatin1String("default"))) { + actions.removeAll(QLatin1String("default")); m_defaultAction = QLatin1String("default"); } + Q_ASSERT(actions.size() % 2 != 1); + if (actions.size() % 2 == 1) { + qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName() + << ", actions:" << m_entity.actions(); + return; + } + QVariantList array; for (int i = 0; i < actions.size(); i += 2) { const auto id = actions[i]; diff --git a/panels/notification/center/notifyitem.cpp b/panels/notification/center/notifyitem.cpp index 4430a61bc..f8534e344 100644 --- a/panels/notification/center/notifyitem.cpp +++ b/panels/notification/center/notifyitem.cpp @@ -117,12 +117,18 @@ QVariantList AppNotifyItem::actions() const void AppNotifyItem::updateActions() { QStringList actions = m_entity.actions(); - const auto defaultIndex = actions.indexOf(QLatin1String("default")); - if (defaultIndex >= 0) { - actions.remove(defaultIndex, 2); + if (actions.contains(QLatin1String("default"))) { + actions.removeAll(QLatin1String("default")); m_defaultAction = QLatin1String("default"); } + Q_ASSERT(actions.size() % 2 != 1); + if (actions.size() % 2 == 1) { + qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName() + << ", actions:" << m_entity.actions(); + return; + } + QVariantList array; for (int i = 0; i < actions.size(); i += 2) { const auto id = actions[i];