Skip to content

fix: add scan completion notification message - #49

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
re2zero:agent/pms-bug-bot/68ef40aef0c8
Oct 12, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
re2zero:agent/pms-bug-bot/68ef40aef0c8

Conversation

@re2zero

@re2zero re2zero commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When a scan completes, ScanWidget::onScanFinished() only writes debug logs via qCDebug/qCWarning and inserts the file path into m_historyEdit, which is hidden (m_historyEdit->hide() at line 178). No user-visible notification is shown after scan completion. The root cause is the absence of any UI feedback mechanism in the scan completion callback. Key evidence: src/ui/scanwidget.cpp:625-636 — only debug logging and hidden text edit update; src/ui/scanwidget.cpp:178 — m_historyEdit is hidden; src/mainwindow.cpp:80,205 — DMessageManager already used elsewhere in the project.

Fix

Added DMessageManager::sendMessage() calls in the onScanFinished() async save callback to display a success message (with saved file path) or a failure message, matching the existing pattern in mainwindow.cpp. Added #include <DMessageManager> to the includes. No existing logic was modified — this is a purely additive change.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target code (lines 617-631) was last modified in commit 36132f3 ("fix: move the scanner and camera work off the UI thread") which introduced the async QFutureWatcher + lambda callback pattern. This fix adds notification calls within that lambda callback without changing the async flow.
  • No function signatures changed; no external callers affected. The change does not revert any prior bug fix (verified against PMS #346173, #317025, #349829).

Business Impact Scope

Affects the scan completion notification flow for all scanner types (document scanners, high-speed cameras). Users will now see a toast message when a scan completes successfully (with the saved file path) or fails to save. No other functional modules are affected.

Verification Suggestion

Test scan completion with various scanner devices (high-speed camera, document scanner) and file formats (PNG/JPEG/PDF/OFD). Verify the success toast displays the saved file path, and the failure toast appears when save fails. Test consecutive scans to ensure each shows a notification.


根因分析

扫描完成后,ScanWidget::onScanFinished() 仅通过 qCDebug/qCWarning 输出调试日志,并将文件路径写入 m_historyEdit(该控件在第 178 行被 hide() 隐藏)。扫描完成后无任何用户可见通知。根因为扫描完成回调中缺少 UI 反馈机制。关键证据:src/ui/scanwidget.cpp:625-636 — 仅有调试日志和隐藏文本控件更新;src/ui/scanwidget.cpp:178 — m_historyEdit 被隐藏;src/mainwindow.cpp:80,205 — 项目已有 DMessageManager 使用先例。

修复方案

在 onScanFinished() 异步保存回调中添加 DMessageManager::sendMessage() 调用,显示成功消息(含保存文件路径)或失败消息,与 mainwindow.cpp 中现有模式一致。添加了 #include <DMessageManager> 头文件。未修改任何现有逻辑,纯属增量改动。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码(617-631 行)最后由 commit 36132f3("fix: move the scanner and camera work off the UI thread")修改,引入了异步 QFutureWatcher + lambda 回调模式。本次修复在该 lambda 回调中添加通知调用,不改变异步流程。
  • 无函数签名变更,无外部调用者受影响。不会撤销任何历史 bug 修复(已验证 PMS #346173、#317025、#349829)。

业务影响范围

影响所有扫描设备类型(高拍仪、扫描仪)的扫描完成通知流程。用户将在扫描成功完成时看到提示消息(含保存文件路径),保存失败时看到失败提示。不影响其他功能模块。

验证建议

测试不同扫描设备(高拍仪、扫描仪)和文件格式(PNG/JPEG/PDF/OFD)的扫描完成流程。验证成功提示显示保存文件路径,失败时显示失败提示。测试连续多次扫描确保每次均显示通知。

Summary by Sourcery

Provide localized success and failure notifications for completed scans.

New Features:

  • Add user-visible notifications when scans are saved successfully or fail to save.

Bug Fixes:

  • Fix missing feedback after scan completion by reporting the save outcome to users.

Chores:

  • Add localized English, Simplified Chinese, Traditional Chinese, and Hong Kong Chinese strings for scan result notifications.

@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The scan completion callback now emits success or failure toast notifications through DMessageManager, making scan-save results visible to users without changing the existing asynchronous save flow.

Sequence diagram for scan completion notifications

sequenceDiagram
    participant ScanWidget
    participant QtConcurrent
    participant DMessageManager

    ScanWidget->>QtConcurrent: saveScan(request)
    QtConcurrent-->>ScanWidget: result
    alt result.success
        ScanWidget->>DMessageManager: sendMessage(window(), successIcon, savedPath)
    else save failed
        ScanWidget->>DMessageManager: sendMessage(window(), warningIcon, failureMessage)
    end
Loading

File-Level Changes

Change Details Files
Add user-visible notifications to the asynchronous scan-save completion path.
  • Include the DMessageManager API.
  • Show a success toast with the saved file path after a successful save.
  • Show a warning toast when saving fails while preserving existing logging and history updates.
src/ui/scanwidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/ui/scanwidget.cpp" line_range="630" />
<code_context>
             m_historyEdit->moveCursor(QTextCursor::Start);
             m_historyEdit->insertPlainText(result.filePath + "\n");
+            DMessageManager::instance()->sendMessage(window(), QIcon::fromTheme("dialog-ok"),
+                                                     tr("Scan completed, saved to: %1").arg(result.filePath));
         } else {
             qCWarning(app) << "Failed to save scan to:" << result.filePath;
</code_context>
<issue_to_address>
**Notifications stay in English**

When the app runs under a supported non-English locale, the translation catalogs lack both strings passed to `tr()`, so Qt falls back to the English source text for the success and failure notifications; users see English toasts.

Add translations for both notification strings to the locale catalogs.

Also at `src/ui/scanwidget.cpp:633-635`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/ui/scanwidget.cpp Resolved
1. Root cause: onScanFinished() only logged debug output and wrote to
   a hidden m_historyEdit widget, no user-visible notification shown
2. Fix: use DMessageManager to display success/failure messages after
   scan save completes, matching existing pattern in mainwindow.cpp
3. Impact: users now see a confirmation message when scan completes
   successfully or fails to save

Log: Added scan completion notification message

Influence:
1. Test scan completion with a connected scanner device
2. Verify success message displays with saved file path
3. Verify failure message displays when save fails

fix: 添加扫描完成提示消息

1. 根因:onScanFinished() 仅输出 debug 日志并写入隐藏的
   m_historyEdit 控件,无任何用户可见通知
2. 方案:使用 DMessageManager 在扫描保存完成后显示成功/失败提示,
   与 mainwindow.cpp 中现有模式一致
3. 影响:用户现在可以看到扫描完成成功或保存失败的提示消息

Log: 添加扫描完成提示消息

Influence:
1. 测试连接扫描仪设备后完成扫描
2. 验证成功时显示包含保存文件路径的提示
3. 验证保存失败时显示失败提示

PMS: BUG-323729
@re2zero
re2zero force-pushed the agent/pms-bug-bot/68ef40aef0c8 branch from e540036 to 8ca9c12 Compare October 12, 2026 08:51
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值,代码质量符合要求。本次变更在扫描完成后添加通知消息,实现简洁清晰,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码语法正确,逻辑清晰,无编译错误风险。DMessageManager::instance()->sendMessage() 调用符合 DTK API 规范,tr() 国际化函数使用正确,QIcon::fromTheme() 使用标准图标主题名称。QFutureWatcher 信号在主线程触发,UI 操作线程安全。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 建议在新增的通知代码处添加简短注释,说明通知的目的。代码结构清晰,翻译文件同步更新完整,4种语言翻译均已覆盖新增字符串。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,DMessageManager 消息通知为轻量级 UI 操作,QIcon::fromTheme 使用图标缓存,无性能瓶颈。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。result.filePath 来自文件保存对话框返回值,非用户直接输入,无注入风险。通知消息中展示文件路径属于正常用户体验需求,不构成敏感信息泄露。


💡 改进建议代码示例

// 扫描完成通知
DMessageManager::instance()->sendMessage(window(),
    QIcon::fromTheme("dialog-ok"),
    tr("Scan completed, saved to: %1").arg(result.filePath));
// 扫描保存失败通知
DMessageManager::instance()->sendMessage(window(),
    QIcon::fromTheme("dialog-warning"),
    tr("Failed to save scan."));

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@re2zero

re2zero commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 7e5136f into linuxdeepin:master Oct 12, 2026
14 of 15 checks passed
@re2zero
re2zero deleted the agent/pms-bug-bot/68ef40aef0c8 branch October 12, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants