Skip to content

Commit deb20e9

Browse files
committed
fix: default action can't work for notification
Default action maybe have text, and it's actionId is default. Remove entity when manually closing it before timeout. CloseNotification can't work. pms: BUG-290767
1 parent 381b797 commit deb20e9

File tree

8 files changed

+58
-16
lines changed

8 files changed

+58
-16
lines changed

panels/notification/bubble/bubbleitem.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,15 @@ QVariantList BubbleItem::actions() const
244244
void BubbleItem::updateActions()
245245
{
246246
QStringList actions = m_entity.actions();
247-
if (actions.contains(QLatin1String("default"))) {
248-
actions.removeAll(QLatin1String("default"));
247+
const auto index = actions.indexOf(QLatin1String("default"));
248+
if (index >= 0) {
249+
// default Action maybe have text.
249250
m_defaultAction = QLatin1String("default");
251+
if (actions.size() % 2 == 1) {
252+
actions.remove(index);
253+
} else {
254+
actions.remove(index, 2);
255+
}
250256
}
251257

252258
Q_ASSERT(actions.size() % 2 != 1);

panels/notification/bubble/package/NormalBubble.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ D.Control {
5252
if (!bubble.defaultAction)
5353
return
5454

55-
console.log("default action", bubble.index)
56-
Applet.invokeDefaultAction(bubble.index, bubble.defaultAction)
55+
console.log("default action notify", bubble.appName, bubble.defaultAction)
56+
Applet.invokeAction(bubble.index, bubble.defaultAction)
5757
}
5858
property bool longPressed
5959
onPressAndHold: {

panels/notification/center/notifyitem.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ QVariantList AppNotifyItem::actions() const
117117
void AppNotifyItem::updateActions()
118118
{
119119
QStringList actions = m_entity.actions();
120-
if (actions.contains(QLatin1String("default"))) {
121-
actions.removeAll(QLatin1String("default"));
122-
m_defaultAction = QLatin1String("default");
120+
const auto index = actions.indexOf(QLatin1String("default"));
121+
if (index >= 0) {
122+
// default Action maybe have text.
123+
if (actions.size() % 2 == 1) {
124+
actions.remove(index);
125+
} else {
126+
actions.remove(index, 2);
127+
}
123128
}
124129

125130
Q_ASSERT(actions.size() % 2 != 1);

panels/notification/common/notifyentity.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bool NotifyEntity::operator==(const NotifyEntity &other) const
107107
return false;
108108
}
109109

110+
bool NotifyEntity::operator!=(const NotifyEntity &other) const
111+
{
112+
return !(operator==(other));
113+
}
114+
110115
bool NotifyEntity::isValid() const
111116
{
112117
return d && d->id > 0;

panels/notification/common/notifyentity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class NotifyEntity
4444
NotifyEntity &operator=(NotifyEntity &&other);
4545

4646
bool operator==(const NotifyEntity &other) const;
47+
bool operator!=(const NotifyEntity &other) const;
4748

4849
bool isValid() const;
4950

panels/notification/server/dbusadaptor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DbusAdaptor::DbusAdaptor(QObject *parent)
1919

2020
QStringList DbusAdaptor::GetCapabilities()
2121
{
22-
qDebug(notifyLog) << "GetCapabilities";
22+
qInfo(notifyLog) << "GetCapabilities";
2323
return manager()->GetCapabilities();
2424
}
2525

@@ -32,13 +32,13 @@ uint DbusAdaptor::Notify(const QString &appName, uint replacesId, const QString
3232

3333
void DbusAdaptor::CloseNotification(uint id)
3434
{
35-
qDebug(notifyLog) << "Close notification" << id;
35+
qInfo(notifyLog) << "Close notification" << id;
3636
manager()->CloseNotification(id);
3737
}
3838

3939
void DbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
4040
{
41-
qDebug(notifyLog) << "GetServerInformation";
41+
qInfo(notifyLog) << "GetServerInformation";
4242
manager()->GetServerInformation(name, vendor, version, specVersion);
4343
}
4444

@@ -55,6 +55,7 @@ DDENotificationDbusAdaptor::DDENotificationDbusAdaptor(QObject *parent)
5555

5656
QStringList DDENotificationDbusAdaptor::GetCapabilities()
5757
{
58+
qInfo(notifyLog) << "GetCapabilities";
5859
return manager()->GetCapabilities();
5960
}
6061

@@ -67,11 +68,13 @@ uint DDENotificationDbusAdaptor::Notify(const QString &appName, uint replacesId,
6768

6869
void DDENotificationDbusAdaptor::CloseNotification(uint id)
6970
{
71+
qInfo(notifyLog) << "Close Notification" << id;
7072
manager()->CloseNotification(id);
7173
}
7274

7375
void DDENotificationDbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
7476
{
77+
qInfo(notifyLog) << "GetServerInformation";
7578
manager()->GetServerInformation(name, vendor, version, specVersion);
7679
}
7780

@@ -102,7 +105,8 @@ void DDENotificationDbusAdaptor::SetAppInfo(const QString &appId, uint configIte
102105

103106
QString DDENotificationDbusAdaptor::GetAppSetting(const QString &appName)
104107
{
105-
return QString();
108+
Q_UNUSED(appName)
109+
return {};
106110
}
107111

108112
void DDENotificationDbusAdaptor::SetAppSetting(const QString &settings)

panels/notification/server/notificationmanager.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ uint NotificationManager::recordCount() const
103103

104104
void NotificationManager::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey)
105105
{
106+
qInfo(notifyLog) << "Action invoked, bubbleId:" << bubbleId << ", id:" << id << ", actionKey" << actionKey;
106107
auto entity = m_persistence->fetchEntity(id);
107108
if (entity.isValid()) {
109+
doActionInvoked(entity, actionKey);
110+
108111
entity.setProcessedType(NotifyEntity::Removed);
109112
updateEntityProcessed(entity);
110113
}
111-
doActionInvoked(entity, actionKey);
112114

113115
Q_EMIT ActionInvoked(bubbleId, actionKey);
114116
Q_EMIT NotificationClosed(bubbleId, NotifyEntity::Closed);
@@ -253,19 +255,22 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
253255
}
254256
}
255257

258+
qInfo(notifyLog) << "Notify done, bubbleId:" << entity.bubbleId() << ", id:" << entity.id();
259+
256260
// If replaces_id is 0, the return value is a UINT32 that represent the notification.
257261
// If replaces_id is not 0, the returned value is the same value as replaces_id.
258-
return replacesId == 0 ? entity.bubbleId() : replacesId;
262+
return entity.bubbleId();
259263
}
260264
void NotificationManager::CloseNotification(uint id)
261265
{
262-
// TODO If the notification no longer exists, an empty D-BUS Error message is sent back.
263-
const auto entity = m_persistence->fetchLastEntity(id);
266+
auto entity = m_persistence->fetchLastEntity(id);
264267
if (entity.isValid()) {
265-
Q_EMIT NotificationStateChanged(entity.id(), entity.processedType());
268+
entity.setProcessedType(NotifyEntity::Removed);
269+
updateEntityProcessed(entity);
266270
}
267271

268272
Q_EMIT NotificationClosed(id, NotifyEntity::Closed);
273+
qDebug(notifyLog) << "Close notify, bubbleId" << id << ", id:" << entity.id();
269274
}
270275

271276
void NotificationManager::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
@@ -409,6 +414,7 @@ void NotificationManager::updateEntityProcessed(const NotifyEntity &entity)
409414
const auto bluetooth = entity.body().contains("%") && entity.actions().contains("cancel");
410415
if (removed || !showInCenter || bluetooth) {
411416
m_persistence->removeEntity(id);
417+
removePendingEntity(entity);
412418
} else {
413419
m_persistence->updateEntityProcessedType(id, entity.processedType());
414420
}
@@ -481,4 +487,18 @@ void NotificationManager::onHandingPendingEntities()
481487
}
482488
}
483489

490+
void NotificationManager::removePendingEntity(const NotifyEntity &entity)
491+
{
492+
for (auto iter = m_pendingTimeoutEntities.begin(); iter != m_pendingTimeoutEntities.end();) {
493+
const auto item = iter.value();
494+
if (item != entity) {
495+
iter++;
496+
continue;
497+
}
498+
m_pendingTimeoutEntities.erase(iter);
499+
onHandingPendingEntities();
500+
break;
501+
}
502+
}
503+
484504
} // notification

panels/notification/server/notificationmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public Q_SLOTS:
8181

8282
private slots:
8383
void onHandingPendingEntities();
84+
void removePendingEntity(const NotifyEntity &entity);
8485

8586
private:
8687
uint m_replacesCount = 0;

0 commit comments

Comments
 (0)