Skip to content

Commit 47e6473

Browse files
committed
refactor: simplify notification action handling
1. Removed manual action processing in NotifyAccessor and delegated to DataUpdater 2. Added new actionInvoked method without bubbleId parameter to NotificationManager 3. Simplified action handling logic by removing direct QProcess execution 4. Added corresponding methods in NotifyserverApplet to support new action flow 5. Improved code organization by separating action handling concerns refactor: 简化通知操作处理逻辑 1. 移除 NotifyAccessor 中的手动操作处理,委托给 DataUpdater 2. 在 NotificationManager 中添加不带 bubbleId 参数的 actionInvoked 方法 3. 通过移除直接 QProcess 执行简化操作处理逻辑 4. 在 NotifyserverApplet 中添加对应方法以支持新的操作流程 5. 通过分离操作处理关注点改进代码组织
1 parent 2041ed8 commit 47e6473

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

panels/notification/center/notifyaccessor.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,10 @@ void NotifyAccessor::invokeAction(const NotifyEntity &entity, const QString &act
196196
{
197197
qDebug(notifyLog) << "Invoke action for the notify" << entity.id() << actionId;
198198

199-
QMap<QString, QVariant> hints = entity.hints();
200-
if (hints.isEmpty())
199+
if (!m_dataUpdater)
201200
return;
202-
QMap<QString, QVariant>::const_iterator i = hints.constBegin();
203-
while (i != hints.constEnd()) {
204-
QStringList args = i.value().toString().split(",");
205-
if (!args.isEmpty()) {
206-
QString cmd = args.first();
207-
args.removeFirst();
208-
if (i.key() == "x-deepin-action-" + actionId) {
209-
qDebug(notifyLog) << "Invoke action" << cmd;
210-
QProcess::startDetached(cmd, args);
211-
}
212-
}
213-
++i;
214-
}
201+
const auto id = entity.id();
202+
QMetaObject::invokeMethod(m_dataUpdater, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(const QString &, actionId));
215203
}
216204

217205
void NotifyAccessor::pinApplication(const QString &appId, bool pin)

panels/notification/server/notificationmanager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,22 @@ uint NotificationManager::recordCount() const
113113
return m_persistence->fetchEntityCount(DataAccessor::AllApp(), NotifyEntity::Processed);
114114
}
115115

116-
void NotificationManager::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey)
116+
void NotificationManager::actionInvoked(qint64 id, const QString &actionKey)
117117
{
118-
qInfo(notifyLog) << "Action invoked, bubbleId:" << bubbleId << ", id:" << id << ", actionKey" << actionKey;
118+
qInfo(notifyLog) << "Action invoked, id:" << id << ", actionKey" << actionKey;
119119
auto entity = m_persistence->fetchEntity(id);
120120
if (entity.isValid()) {
121121
doActionInvoked(entity, actionKey);
122122

123123
entity.setProcessedType(NotifyEntity::Removed);
124124
updateEntityProcessed(entity);
125125
}
126+
}
127+
128+
void NotificationManager::actionInvoked(qint64 id, uint bubbleId, const QString &actionKey)
129+
{
130+
qInfo(notifyLog) << "Action invoked, bubbleId:" << bubbleId << ", id:" << id << ", actionKey" << actionKey;
131+
actionInvoked(id, actionKey);
126132

127133
Q_EMIT ActionInvoked(bubbleId, actionKey);
128134
Q_EMIT NotificationClosed(bubbleId, NotifyEntity::Closed);

panels/notification/server/notificationmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class NotificationManager : public QObject, public QDBusContext
2626
bool registerDbusService();
2727

2828
uint recordCount() const;
29+
Q_INVOKABLE void actionInvoked(qint64 id, const QString &actionKey);
2930
Q_INVOKABLE void actionInvoked(qint64 id, uint bubbleId, const QString &actionKey);
3031
Q_INVOKABLE void notificationClosed(qint64 id, uint bubbleId, uint reason);
3132
Q_INVOKABLE void notificationReplaced(qint64 id);

panels/notification/server/notifyserverapplet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ void NotifyServerApplet::actionInvoked(qint64 id, uint bubbleId, const QString &
6767
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(QString, actionKey));
6868
}
6969

70+
void NotifyServerApplet::actionInvoked(qint64 id, const QString &actionKey)
71+
{
72+
QMetaObject::invokeMethod(m_manager, "actionInvoked", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(QString, actionKey));
73+
}
74+
7075
void NotifyServerApplet::notificationClosed(qint64 id, uint bubbleId, uint reason)
7176
{
7277
QMetaObject::invokeMethod(m_manager, "notificationClosed", Qt::DirectConnection, Q_ARG(qint64, id), Q_ARG(uint, bubbleId), Q_ARG(uint, reason));

panels/notification/server/notifyserverapplet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class NotifyServerApplet : public DS_NAMESPACE::DApplet
2424

2525
public Q_SLOTS:
2626
void actionInvoked(qint64 id, uint bubbleId, const QString &actionKey);
27+
void actionInvoked(qint64 id, const QString &actionKey);
2728
void notificationClosed(qint64 id, uint bubbleId, uint reason);
2829
QVariant appValue(const QString &appId, int configItem);
2930
void removeNotification(qint64 id);

0 commit comments

Comments
 (0)