Skip to content

Commit f2f0ead

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: support string list in notification hints
1. Added LIST_VALUE_SEGMENT constant for string list serialization 2. Modified convertHintsToString to handle QStringList values by joining with separator 3. Updated parseHint to reconstruct QStringList from serialized format 4. Improved action handling in NotificationManager to properly process string list hints 5. Added deprecation warning for old string format hints These changes were necessary to properly support complex hint values in notifications, particularly for action parameters that may contain multiple values. The previous implementation only supported simple string values, which limited functionality. fix: 支持通知提示中的字符串列表 1. 添加 LIST_VALUE_SEGMENT 常量用于字符串列表序列化 2. 修改 convertHintsToString 方法以处理 QStringList 值并使用分隔符连接 3. 更新 parseHint 方法从序列化格式重建 QStringList 4. 改进 NotificationManager 中的动作处理以正确处理字符串列表提示 5. 为旧的字符串格式提示添加弃用警告 这些变更是为了在通知中正确支持复杂的提示值,特别是可能包含多个值的动作参 数。之前的实现仅支持简单字符串值,限制了功能。 pms: BUG-317649
1 parent 099fb8a commit f2f0ead

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

panels/notification/common/notifyentity.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Q_LOGGING_CATEGORY(notifyLog, "dde.shell.notification")
1414
#define ACTION_SEGMENT ("|")
1515
#define HINT_SEGMENT ("|")
1616
#define KEY_VALUE_SEGMENT ("!!!")
17+
#define LIST_VALUE_SEGMENT (":::")
1718

1819
static const uint NoReplaceId = 0;
1920

@@ -294,7 +295,13 @@ QString NotifyEntity::convertHintsToString(const QVariantMap &map)
294295
QString key = it.key();
295296
text += key;
296297
text += KEY_VALUE_SEGMENT;
297-
QString value = it.value().toString();
298+
QString value;
299+
if (it.value().typeId() == QMetaType::QStringList) {
300+
QStringList tmp = it.value().toStringList();
301+
value = tmp.join(LIST_VALUE_SEGMENT);
302+
} else {
303+
value = it.value().toString();
304+
}
298305
text += value;
299306
text += HINT_SEGMENT;
300307
}
@@ -328,7 +335,13 @@ QVariantMap NotifyEntity::parseHint(const QString &hint)
328335
if (list.size() != 2)
329336
continue;
330337
const QString &key = list[0];
331-
QVariant value = QVariant::fromValue(list[1]);
338+
QVariant value;
339+
auto listValue = list[1].split(LIST_VALUE_SEGMENT);
340+
if (listValue.size() > 1) {
341+
value = QVariant::fromValue(listValue);
342+
} else {
343+
value = QVariant::fromValue(list[1]);
344+
}
332345

333346
map.insert(key, value);
334347
}

panels/notification/server/notificationmanager.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,14 @@ void NotificationManager::doActionInvoked(const NotifyEntity &entity, const QStr
512512
QMap<QString, QVariant>::const_iterator i = hints.constBegin();
513513
while (i != hints.constEnd()) {
514514
if (i.key() == "x-deepin-action-" + actionId) {
515-
QStringList args = i.value().toString().split(",");
515+
QStringList args;
516+
if (i.value().typeId() == QMetaType::QStringList) {
517+
args = i.value().toStringList();
518+
} else {
519+
qDebug(notifyLog) << "Deprecate hint format, use string list instead of string."
520+
<< "actionId:" << actionId << ", value:" << i.value();
521+
args = i.value().toString().split(",");
522+
}
516523
if (!args.isEmpty()) {
517524
QString cmd = args.takeFirst(); // 命令
518525

0 commit comments

Comments
 (0)