Skip to content

Commit 81ba22f

Browse files
18202781743deepin-bot[bot]
authored andcommitted
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 242a1dc commit 81ba22f

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

@@ -40,13 +40,13 @@ uint DbusAdaptor::Notify(const QString &appName, uint replacesId, const QString
4040

4141
void DbusAdaptor::CloseNotification(uint id)
4242
{
43-
qDebug(notifyLog) << "Close notification" << id;
43+
qInfo(notifyLog) << "Close notification" << id;
4444
manager()->CloseNotification(id);
4545
}
4646

4747
void DbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
4848
{
49-
qDebug(notifyLog) << "GetServerInformation";
49+
qInfo(notifyLog) << "GetServerInformation";
5050
manager()->GetServerInformation(name, vendor, version, specVersion);
5151
}
5252

@@ -63,6 +63,7 @@ DDENotificationDbusAdaptor::DDENotificationDbusAdaptor(QObject *parent)
6363

6464
QStringList DDENotificationDbusAdaptor::GetCapabilities()
6565
{
66+
qInfo(notifyLog) << "GetCapabilities";
6667
return manager()->GetCapabilities();
6768
}
6869

@@ -83,11 +84,13 @@ uint DDENotificationDbusAdaptor::Notify(const QString &appName, uint replacesId,
8384

8485
void DDENotificationDbusAdaptor::CloseNotification(uint id)
8586
{
87+
qInfo(notifyLog) << "Close Notification" << id;
8688
manager()->CloseNotification(id);
8789
}
8890

8991
void DDENotificationDbusAdaptor::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
9092
{
93+
qInfo(notifyLog) << "GetServerInformation";
9194
manager()->GetServerInformation(name, vendor, version, specVersion);
9295
}
9396

@@ -118,7 +121,8 @@ void DDENotificationDbusAdaptor::SetAppInfo(const QString &appId, uint configIte
118121

119122
QString DDENotificationDbusAdaptor::GetAppSetting(const QString &appName)
120123
{
121-
return QString();
124+
Q_UNUSED(appName)
125+
return {};
122126
}
123127

124128
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);
@@ -257,19 +259,22 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
257259
}
258260
}
259261

262+
qInfo(notifyLog) << "Notify done, bubbleId:" << entity.bubbleId() << ", id:" << entity.id();
263+
260264
// If replaces_id is 0, the return value is a UINT32 that represent the notification.
261265
// If replaces_id is not 0, the returned value is the same value as replaces_id.
262-
return replacesId == 0 ? entity.bubbleId() : replacesId;
266+
return entity.bubbleId();
263267
}
264268
void NotificationManager::CloseNotification(uint id)
265269
{
266-
// TODO If the notification no longer exists, an empty D-BUS Error message is sent back.
267-
const auto entity = m_persistence->fetchLastEntity(id);
270+
auto entity = m_persistence->fetchLastEntity(id);
268271
if (entity.isValid()) {
269-
Q_EMIT NotificationStateChanged(entity.id(), entity.processedType());
272+
entity.setProcessedType(NotifyEntity::Removed);
273+
updateEntityProcessed(entity);
270274
}
271275

272276
Q_EMIT NotificationClosed(id, NotifyEntity::Closed);
277+
qDebug(notifyLog) << "Close notify, bubbleId" << id << ", id:" << entity.id();
273278
}
274279

275280
void NotificationManager::GetServerInformation(QString &name, QString &vendor, QString &version, QString &specVersion)
@@ -413,6 +418,7 @@ void NotificationManager::updateEntityProcessed(const NotifyEntity &entity)
413418
const auto bluetooth = entity.body().contains("%") && entity.actions().contains("cancel");
414419
if (removed || !showInCenter || bluetooth) {
415420
m_persistence->removeEntity(id);
421+
removePendingEntity(entity);
416422
} else {
417423
m_persistence->updateEntityProcessedType(id, entity.processedType());
418424
}
@@ -485,4 +491,18 @@ void NotificationManager::onHandingPendingEntities()
485491
}
486492
}
487493

494+
void NotificationManager::removePendingEntity(const NotifyEntity &entity)
495+
{
496+
for (auto iter = m_pendingTimeoutEntities.begin(); iter != m_pendingTimeoutEntities.end();) {
497+
const auto item = iter.value();
498+
if (item != entity) {
499+
iter++;
500+
continue;
501+
}
502+
m_pendingTimeoutEntities.erase(iter);
503+
onHandingPendingEntities();
504+
break;
505+
}
506+
}
507+
488508
} // 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)