Skip to content

fix: only warn about setPalette abuse when AA_SetPalette is set - #418

Open
Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3
Open

Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3

Conversation

@Ivy233

@Ivy233 Ivy233 commented Oct 15, 2026 •

Copy link
Copy Markdown

onApplicationPaletteChanged() warned whenever a custom palette was in use, but isCustomPalette() is also true while DTK itself manages the palette (paletteType != UnknownType). DTK's own setPaletteType() path deliberately triggers processThemeChanged() to make Qt re-fetch the platform palette, and the resulting ApplicationPaletteChange event was then misjudged as the application calling QGuiApplication::setPalette, printing a false-positive warning for a normal public API call (e.g. dde-tray-loader reacting to dock color theme changes).

Qt sets Qt::AA_SetPalette when the application really calls QGuiApplication::setPalette, and never sets it for DTK's internal theme-change path, so use it as the criterion -- consistent with the other two checks in this file (setPaletteType, setApplicationPalette).

Verified with a minimal program under the deepin platform theme: before, both DTK's own setPaletteType and a direct QGuiApplication::setPalette warned; after, setPaletteType is silent while direct setPalette abuse still warns.

修复:仅在 AA_SetPalette 置位时才对 setPalette 滥用告警

onApplicationPaletteChanged() 原先只要处于自定义调色板就告警,但
isCustomPalette() 在 DTK 自身管理调色板(paletteType != UnknownType) 时同样为真。DTK 自己的 setPaletteType() 会有意触发
processThemeChanged() 让 Qt 重新获取平台调色板,由此产生的
ApplicationPaletteChange 事件被误判为应用调用了
QGuiApplication::setPalette,导致正常公开 API 调用(如
dde-tray-loader 响应 dock 颜色主题变化)也误报告警。

Qt 在应用真正调用 QGuiApplication::setPalette 时会置位
Qt::AA_SetPalette,而 DTK 内部主题变更路径永远不会置位,因此改用
该属性作为判据——与本文件另外两处检查(setPaletteType、
setApplicationPalette)保持一致。

已在 deepin 平台主题下用最小程序验证:修复前 DTK 自身
setPaletteType 与直接 QGuiApplication::setPalette 均告警;修复后 setPaletteType 静默,直接 setPalette 滥用仍告警。

PMS: TASK-394335

Summary by Sourcery

Bug Fixes:

  • Restrict palette-abuse warnings to application-triggered palette changes marked by Qt::AA_SetPalette, preventing false positives during DTK-managed theme updates.

onApplicationPaletteChanged() warned whenever a custom palette was in
use, but isCustomPalette() is also true while DTK itself manages the
palette (paletteType != UnknownType). DTK's own setPaletteType() path
deliberately triggers processThemeChanged() to make Qt re-fetch the
platform palette, and the resulting ApplicationPaletteChange event was
then misjudged as the application calling QGuiApplication::setPalette,
printing a false-positive warning for a normal public API call (e.g.
dde-tray-loader reacting to dock color theme changes).

Qt sets Qt::AA_SetPalette when the application really calls
QGuiApplication::setPalette, and never sets it for DTK's internal
theme-change path, so use it as the criterion -- consistent with the
other two checks in this file (setPaletteType, setApplicationPalette).

Verified with a minimal program under the deepin platform theme:
before, both DTK's own setPaletteType and a direct
QGuiApplication::setPalette warned; after, setPaletteType is silent
while direct setPalette abuse still warns.

修复:仅在 AA_SetPalette 置位时才对 setPalette 滥用告警

onApplicationPaletteChanged() 原先只要处于自定义调色板就告警,但
isCustomPalette() 在 DTK 自身管理调色板(paletteType != UnknownType)
时同样为真。DTK 自己的 setPaletteType() 会有意触发
processThemeChanged() 让 Qt 重新获取平台调色板,由此产生的
ApplicationPaletteChange 事件被误判为应用调用了
QGuiApplication::setPalette,导致正常公开 API 调用(如
dde-tray-loader 响应 dock 颜色主题变化)也误报告警。

Qt 在应用真正调用 QGuiApplication::setPalette 时会置位
Qt::AA_SetPalette,而 DTK 内部主题变更路径永远不会置位,因此改用
该属性作为判据——与本文件另外两处检查(setPaletteType、
setApplicationPalette)保持一致。

已在 deepin 平台主题下用最小程序验证:修复前 DTK 自身
setPaletteType 与直接 QGuiApplication::setPalette 均告警;修复后
setPaletteType 静默,直接 setPalette 滥用仍告警。

PMS: TASK-394335
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233

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

@sourcery-ai

sourcery-ai Bot commented Oct 15, 2026

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

Reviewer's Guide

Updates palette-change handling to distinguish application-driven QGuiApplication::setPalette() calls from DTK-managed theme refreshes by checking Qt::AA_SetPalette, eliminating false-positive warnings without weakening detection of actual palette abuse.

Sequence diagram for palette-change warning discrimination

sequenceDiagram
    participant App as Application
    participant Qt as QGuiApplication
    participant DTK as DGuiApplicationHelper

    App->>DTK: setPaletteType()
    DTK->>DTK: processThemeChanged()
    DTK->>Qt: ApplicationPaletteChange
    Qt-->>DTK: testAttribute(Qt::AA_SetPalette) = false
    DTK-->>App: No warning

    App->>Qt: setPalette()
    Qt->>DTK: ApplicationPaletteChange
    Qt-->>DTK: testAttribute(Qt::AA_SetPalette) = true
    DTK-->>App: qWarning()
Loading

File-Level Changes

Change Details Files
Gate the custom-palette misuse warning on Qt’s AA_SetPalette application attribute.
  • Preserve existing theme and palette change signals for non-custom palettes.
  • Suppress warnings for DTK-internal palette refreshes triggered by theme changes.
  • Continue warning when an application directly invokes QGuiApplication::setPalette().
src/kernel/dguiapplicationhelper.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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次修改将 onApplicationPaletteChanged() 中的 setPalette 滥用告警条件从 isCustomPalette() 改为 Qt::AA_SetPalette 属性检查,消除了 DTK 内部主题变更路径触发的误报,与文件中 setPaletteType() 和 setApplicationPalette() 两处检查保持一致,修改精准、注释清晰、无安全风险。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。if-else if 链正确地将告警条件从 isCustomPalette() 缩窄为 Qt::AA_SetPalette 属性检查。qGuiApp 在同一函数的第459行已被解引用(qGuiApp->palette()),此处使用安全。边界处理完善:当 isCustomPalette() 为 true 但 AA_SetPalette 未置位时,函数静默返回,符合 DTK 内部主题变更的正常流程。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

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

建议: 代码结构清晰,注释完整。新增的4行注释详细解释了使用 AA_SetPalette 作为判据的原因,并引用了 notifyAppThemeChangedByEvent() 函数说明 DTK 内部流程。修改与文件中 setPaletteType()(第480行)和 setApplicationPalette()(第1353行)两处类似检查保持一致,无重复代码,无残留调试信息。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。testAttribute() 是 Qt 内联方法,时间复杂度 O(1),仅为属性标志位检查。本次修改还减少了不必要的 qWarning() 调用(消除误报),对性能有轻微正面影响。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞,安全合规。本次修改不涉及用户输入处理、外部数据交互或敏感信息操作。qWarning() 输出内容为固定字符串,不含敏感信息,无日志注入风险。无缓冲区溢出、注入或其他安全风险。


💡 改进建议代码示例

// 当前修改已为最佳实践,无需额外修复
// 修改前(存在误报):
//   } else {
//       qWarning() << "DGuiApplicationHelper: Don't use QGuiApplication::setPalette on DTK application.";
//   }

// 修改后(精准告警):
//   } else if (qGuiApp->testAttribute(Qt::AA_SetPalette)) {
//       // 仅在调色板变化确由应用自行调用 QGuiApplication::setPalette 引发
//       qWarning() << "DGuiApplicationHelper: Don't use QGuiApplication::setPalette on DTK application.";
//   }

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

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.51
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #419

This branch has not been deployed

No deployments
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.

2 participants