Skip to content

feat: add override icon search path for system tray#369

Merged
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:icon
Sep 24, 2025
Merged

feat: add override icon search path for system tray#369
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:icon

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 22, 2025

Copy link
Copy Markdown
Contributor
  1. Changed resource prefix from /dsg/built-in-icons to /dsg-icon/ override in application-tray.qrc
  2. Added DIconTheme include and modified DCI theme search paths in trayplugin.cpp
  3. Prepended the override path to ensure system icons take precedence over theme icons
  4. This allows system icons to remain consistent regardless of theme changes

feat: 为系统托盘添加图标覆盖搜索路径

  1. 将 application-tray.qrc 中的资源前缀从 /dsg/built-in-icons 改为 /dsg- icon/override
  2. 在 trayplugin.cpp 中添加 DIconTheme 包含并修改 DCI 主题搜索路径
  3. 将覆盖路径前置以确保系统图标优先于主题图标
  4. 这使得系统图标在不同主题下保持一致性

pms: BUG-332583

Summary by Sourcery

New Features:

  • Add override resource prefix /dsg-icon/override in application-tray.qrc and prepend it to the DIconTheme search paths for system tray icons

@sourcery-ai

sourcery-ai Bot commented Sep 22, 2025

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

Reviewer's Guide

This PR implements an override icon search path for the system tray by updating the QRC resource prefix and modifying the DIconTheme search paths in the tray plugin initialization so that system icons take precedence over theme icons.

File-Level Changes

Change Details Files
Integrate override icon search path into DIconTheme
  • Include DIconTheme header
  • Retrieve existing DCI theme search paths
  • Prepend override path to search paths
  • Set updated search paths back into DIconTheme
plugins/application-tray/trayplugin.cpp
Update QRC resource prefix for override icons
  • Change resource prefix from /dsg/built-in-icons to /dsg-icon/override
plugins/application-tray/application-tray.qrc

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 there - I've reviewed your changes and they look great!


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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

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

1. Changed resource prefix from /dsg/built-in-icons to /dsg-icon/
override in application-tray.qrc
2. Added DIconTheme include and modified DCI theme search paths in
trayplugin.cpp
3. Prepended the override path to ensure system icons take precedence
over theme icons
4. This allows system icons to remain consistent regardless of theme
changes

feat: 为系统托盘添加图标覆盖搜索路径

1. 将 application-tray.qrc 中的资源前缀从 /dsg/built-in-icons 改为 /dsg-
icon/override
2. 在 trayplugin.cpp 中添加 DIconTheme 包含并修改 DCI 主题搜索路径
3. 将覆盖路径前置以确保系统图标优先于主题图标
4. 这使得系统图标在不同主题下保持一致性

pms: BUG-332583
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来审查这段代码的变更,从语法逻辑、代码质量、代码性能和代码安全四个方面进行分析:

语法逻辑

  1. 语法上没有问题,代码变更符合C++和Qt的语法规范。
  2. 逻辑上,代码通过修改资源文件前缀并添加了图标主题搜索路径的设置,实现了图标资源的重定向。

代码质量

  1. 资源文件前缀从"/dsg/built-in-icons"改为"/dsg-icon/override",命名更加清晰明确,表明这是用于覆盖默认图标的资源。
  2. 添加了DIconTheme头文件包含,这是一个良好的实践。
  3. 代码结构清晰,初始化逻辑合理。

代码性能

  1. 在init函数中,每次初始化都会获取和设置图标主题搜索路径,这部分可以考虑是否可以优化为一次性的初始化操作。
  2. 使用prepend将自定义路径添加到搜索路径列表的前面,确保优先使用自定义图标,这是一个合理的性能考虑。

代码安全

  1. 使用DIconTheme是安全的,它提供了标准的图标主题管理机制。
  2. 路径操作使用了Qt提供的API,避免了直接的文件系统操作,减少了潜在的安全风险。

改进建议

  1. 性能优化:可以将图标主题路径的设置移到类的构造函数或静态初始化部分,避免每次初始化插件时都重复设置。
  2. 错误处理:可以添加对DIconTheme::setDciThemeSearchPaths返回值的检查,确保设置成功。
  3. 资源管理:可以考虑使用RAII方式管理这些路径设置,确保在插件卸载时能够正确清理。

改进后的代码示例:

void TrayPlugin::init(PluginProxyInterface *proxyInter)
{
    m_proyInter = proxyInter;
    
    // 静态初始化图标主题路径
    static bool pathsInitialized = false;
    if (!pathsInitialized) {
        auto dciPaths = Dtk::Gui::DIconTheme::dciThemeSearchPaths();
        dciPaths.prepend(":/dsg-icon/override");
        if (!Dtk::Gui::DIconTheme::setDciThemeSearchPaths(dciPaths)) {
            qWarning() << "Failed to set DCI theme search paths";
        }
        pathsInitialized = true;
    }

    auto sniProtocol = new SniTrayProtocol();
    auto xembedProtocol = new XembedProtocol();
    auto indicatorProtocol = new DDEindicatorProtocol();
    // ... 其余代码
}

这样的改进可以避免重复设置路径,并增加了错误处理机制,提高了代码的健壮性。

@mhduiy mhduiy merged commit 7968908 into linuxdeepin:master Sep 24, 2025
9 of 10 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