feat(keyboard): wire Wayland custom shortcut CRUD#3332
Conversation
There was a problem hiding this comment.
Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
fc6436e to
38ddd00
Compare
Wire the control center's add/modify/delete custom shortcut flows to the new dde-services Keybinding1 custom CRUD methods on Wayland, replacing the previous early-return stubs. Each Wayland call is observed with a QDBusPendingCallWatcher so failures trigger refreshShortcut()/onAdded/ onShortcutChanged instead of mutating the local model optimistically. Fetch a custom shortcut's command via the new GetShortcutCommand D-Bus method: requestShortcutCommand fires one async call per custom shortcut after ListAllShortcuts/SearchShortcuts/GetShortcut/ShortcutChanged, and onGetShortcutCommandFinished overlays the Exec field onto the already- built JSON object and re-emits shortcutQueried. The whole ShortcutInfo JSON is stashed on the watcher so the handler needs no field-by-field reconstruction. ShortcutModel::onKeyBindingChanged now handles insert-on-change for new ids arriving via ShortcutChanged: section-bearing configs are grouped into m_groupInfos, sectionless Custom configs get the legacy "Custom" group, and a dead unreachable tail (invalidateSystemShortcutNamesCache + addCustomInfo after two returning branches) is removed. Extract KeyboardWorker::callModifyCustomShortcut() so the Wayland modify path (modifyCustomShortcut and setNewCustomShortcut) shares one watcher/id/type/connect setup. setNewCustomShortcut keeps the X11 fallback calling ModifyCustomShortcut directly, since on X11 it is also invoked from onCustomConflictCleanFinished after conflict cleanup. 将控制中心自定义快捷键的增删改流程在 Wayland 下接入新的 dde-services Keybinding1 自定义增删改方法,替换原先的提前 return 桩。每次 Wayland 调用 均用 QDBusPendingCallWatcher 观察结果,失败时触发 refreshShortcut()/ onAdded/onShortcutChanged,而不再乐观地修改本地模型。 通过新增的 GetShortcutCommand D-Bus 方法获取自定义快捷键命令: requestShortcutCommand 在 ListAllShortcuts/SearchShortcuts/GetShortcut/ ShortcutChanged 之后对每个自定义快捷键发起一次异步调用, onGetShortcutCommandFinished 将 Exec 字段叠加到已构建好的 JSON 对象上并 重新发射 shortcutQueried。整个 ShortcutInfo JSON 暂存在 watcher 上,处理 函数无需逐字段重建。 ShortcutModel::onKeyBindingChanged 现支持通过 ShortcutChanged 到达的新 id 的"变更即插入":带 Section 的配置归入 m_groupInfos,无 Section 的 Custom 配置归入传统"Custom"分组,并删除了两个 return 分支之后不可达的死代码尾段。 抽取 KeyboardWorker::callModifyCustomShortcut(),让 Wayland 修改路径 (modifyCustomShortcut 与 setNewCustomShortcut)共用一份 watcher/id/type/ connect 设置。setNewCustomShortcut 保留 X11 直接调用 ModifyCustomShortcut 的兜底,因为 X11 下它也会在冲突清理完成后由 onCustomConflictCleanFinished 调用。 Log: feat(keyboard): wire custom shortcut CRUD on Wayland Change-Id: I793aa520968c92d03bb603721f00b1c7ac252fa5
38ddd00 to
fcc40a4
Compare
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 无严重安全或逻辑缺陷,仅提供一处微小的防御性编程与性能改进示例
// 在 shortcutmodel.cpp 的 onKeyBindingChanged 中,优化字符串转换并增加防御性检查
void ShortcutModel::onKeyBindingChanged(const QString &value)
{
// 建议改用 toUtf8() 避免 toStdString().c_str() 带来的隐式内存分配与转换开销
const QJsonObject obj = QJsonDocument::fromJson(value.toUtf8()).object();
const QString update_id = obj["Id"].toString();
const int update_type = obj["Type"].toInt();
// ... existing code ...
// 新增 insert 分支时的防御性编程
ShortcutInfo *info = new ShortcutInfo();
if (!info) {
qWarning() << "Failed to allocate ShortcutInfo";
return;
}
fillShortcutInfoFromJson(info, obj);
if (!info->sectionKey.isEmpty()) {
m_infos.append(info);
// ...
}
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: robertkill, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
2e5e19c
into
linuxdeepin:stack/shortcut-dynamic-categories-base
Summary
Test plan
Dependency
Stacked on #3320. Base branch stack/shortcut-dynamic-categories-base points to the #3320 commit so this PR contains only the Wayland custom shortcut CRUD commit.