Skip to content

fix(print): use valid file name for print preview output#178

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:feature/fix-BUG369191-eagle
Jul 14, 2026
Merged

fix(print): use valid file name for print preview output#178
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:feature/fix-BUG369191-eagle

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Jul 13, 2026

Copy link
Copy Markdown

Use the current image path and pass only its file name to the print dialog.

使用当前图片路径并仅向打印对话框传递文件名。

Log: 修复打印预览保存默认路径和文件名异常
Bug: https://pms.uniontech.com/bug-view-369191.html
Influence: 保存 PDF 或图片时默认路径可用,并显示当前图片文件名。

Summary by Sourcery

Bug Fixes:

  • Ensure print preview uses a valid current image path and file name when setting the document name.

@sourcery-ai

sourcery-ai Bot commented Jul 13, 2026

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

Reviewer's Guide

Fixes print preview output document naming by using the currently viewed image path, filtering out empty paths, and passing only a valid file name (with a safe fallback) to the print dialog.

File-Level Changes

Change Details Files
Ensure the print dialog receives a valid, non-empty document name derived from the current image file, with a robust fallback.
  • Only non-empty current image paths are collected into the temporary path list used for print preview
  • For supported DTK runtime versions, derive the document name from the first existing path’s file name instead of its absolute file path
  • Introduce a default document name of "print" when no valid path or file name is available, ensuring the print dialog always has a valid name
libimageviewer/widgets/printhelper.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="libimageviewer/widgets/printhelper.cpp" line_range="72-73" />
<code_context>
             }
         }
-        tempExsitPaths << paths;
+        if (!path.isEmpty()) {
+            tempExsitPaths << path;
+        }
     }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Align tempExsitPaths with successfully loaded images rather than non-empty paths.

Currently any non-empty path is added to tempExsitPaths, even when image loading/appendImage fails. This can produce doc names based on files that were never printed. Please only append to tempExsitPaths after the image has been successfully loaded/handled so the doc name matches the actual printed content.

Suggested implementation:

```cpp
                m_re->appendImage(img);
                if (!path.isEmpty()) {
                    tempExsitPaths << path;
                }
            }
        }

    }

```

Depending on the surrounding code, you may also want to ensure this block is only reached when the image has been successfully loaded (e.g. `!img.isNull()` or a successful return value from a loader). In that case, make sure the `if (!path.isEmpty()) { tempExsitPaths << path; }` remains inside that success-checking `if` so `tempExsitPaths` reflects only successfully loaded/printed images.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +72 to +73
if (!path.isEmpty()) {
tempExsitPaths << path;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Align tempExsitPaths with successfully loaded images rather than non-empty paths.

Currently any non-empty path is added to tempExsitPaths, even when image loading/appendImage fails. This can produce doc names based on files that were never printed. Please only append to tempExsitPaths after the image has been successfully loaded/handled so the doc name matches the actual printed content.

Suggested implementation:

                m_re->appendImage(img);
                if (!path.isEmpty()) {
                    tempExsitPaths << path;
                }
            }
        }

    }

Depending on the surrounding code, you may also want to ensure this block is only reached when the image has been successfully loaded (e.g. !img.isNull() or a successful return value from a loader). In that case, make sure the if (!path.isEmpty()) { tempExsitPaths << path; } remains inside that success-checking if so tempExsitPaths reflects only successfully loaded/printed images.

Use the current image path and pass only its file name to the print dialog.

使用当前图片路径并仅向打印对话框传递文件名。

Log: 修复打印预览保存默认路径和文件名异常
Bug: https://pms.uniontech.com/bug-view-369191.html
Influence: 保存 PDF 或图片时默认路径可用,并显示当前图片文件名。
@Resurgamz Resurgamz force-pushed the feature/fix-BUG369191-eagle branch from d1ea8fa to f50f78f Compare July 13, 2026 09:50
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了路径信息泄露和列表追加逻辑错误,提升了安全性和稳定性
逻辑严谨且消除了敏感信息暴露风险,代码质量优秀

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修改后的代码在 PrintHelper::showPrintDialog 中正确处理了路径追加和文档名设置。原代码 tempExsitPaths << paths 会将整个列表作为单个元素追加,修改为 tempExsitPaths << path 并增加非空判断,逻辑正确。文档名设置部分增加了空列表和空文件名的兜底处理,避免了潜在的异常。
潜在问题:无
建议:无需额外修改

  • 2.代码质量(良好)✓

代码结构清晰,使用三元运算符简化了条件判断,QStringLiteral 提高了字符串效率。变量命名 documentName 语义明确。版权年份更新至 2026 年,虽然可能是预期行为,但通常当前年份为 2024,建议确认。
潜在问题:版权年份可能更新过早
建议:确认版权年份修改是否符合项目规范

  • 3.代码性能(无性能问题)✓

使用 QFileInfo::fileName() 相比 absoluteFilePath() 避免了不必要的绝对路径计算,性能略有提升。first()at(0) 性能相当。
潜在问题:无
建议:无需额外修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 1 个,持平 0 个
本次修改修复了原有的路径信息泄露问题,未引入新的安全漏洞。原代码通过 setDocName 传递 absoluteFilePath(),可能将用户文件系统的完整路径暴露给打印子系统或对话框界面。

  • 建议:保持当前的安全编码实践,避免在不需要的场景暴露完整路径

■ 【改进建议代码示例】

// SPDX-FileCopyrightText: 2020 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent)
{
    // ... 前置逻辑
    if (!path.isEmpty()) {
        tempExsitPaths << path;
    }
    // ... 前置逻辑

    if (DApplication::runtimeDtkVersion() >= DTK_VERSION_CHECK(5, 4, 10, 0)) {
        QString documentName = tempExsitPaths.isEmpty()
                ? QStringLiteral("print")
                : QFileInfo(tempExsitPaths.first()).fileName();
        if (documentName.isEmpty()) {
            documentName = QStringLiteral("print");
        }
        printDialog2.setDocName(documentName);
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, Resurgamz

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

@Resurgamz

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit a555336 into linuxdeepin:develop/eagle Jul 14, 2026
22 of 23 checks passed
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