Skip to content

fix: support dynamic calendar icon in taskbar - #1743

Closed
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:agent/pms-bug-bot/01252583619e
Closed

mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:agent/pms-bug-bot/01252583619e

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

In the V25 architecture, dde-shell's taskbar passes the static icon name "dde-calendar-dynamic" directly to DciIcon for rendering, without intercepting it to synthesize a date-specific SVG. The calendar app declares Icon=dde-calendar-dynamic in its .desktop file, expecting display components to generate a dynamic icon with the current date. The icon flows unchanged through DesktopFileAMParser::updateDesktopIcon() → AppItem::icon() → QML DciIcon, resulting in a generic calendar icon without the date.

Fix Approach

Port the createCalendarIcon() SVG generation logic from dde-launchpad into dde-shell. In AppItem::icon(), intercept "dde-calendar-dynamic", generate a temp SVG file with the current date, and return the file path. In AppItem.qml, wrap DciIcon in a parent Item and add an Image element that renders file paths, with visibility toggled by whether iconName starts with /.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The modified AppItem::icon() code area was last changed in a UI refactor (not a bug fix), so this change does not revert any historical fix.
  • No external callers found via codegraph; the icon() return value is consumed only by QML binding, and non-calendar icons return the same value as before.

Business Impact Scope

Affects taskbar icon rendering for the calendar application only. When the calendar app icon appears in the taskbar (docked or running), it will now display a dynamic icon with the current date instead of a static calendar icon. All other application icons are unaffected.

Verification Suggestion

Verify that the calendar app icon in the taskbar shows the correct current date, and that other app icons display normally without regression. Test icon drag, hover preview, and launch animation to confirm QML container changes have no side effects.


根因分析

V25 架构中,dde-shell 任务栏将静态图标名 "dde-calendar-dynamic" 直接传递给 DciIcon 渲染,未拦截并合成带日期的 SVG。日历应用在 .desktop 文件中声明 Icon=dde-calendar-dynamic,期望显示组件根据当前日期生成动态图标。图标名未经处理地流经 DesktopFileAMParser::updateDesktopIcon() → AppItem::icon() → QML DciIcon,导致显示为不带日期的通用日历图标。

修复方案

将 dde-launchpad 的 createCalendarIcon() SVG 生成逻辑移植到 dde-shell。在 AppItem::icon() 中拦截 "dde-calendar-dynamic",生成带当前日期的临时 SVG 文件并返回文件路径。在 AppItem.qml 中,将 DciIcon 包裹在父 Item 中,新增 Image 元素渲染文件路径,通过 iconName 是否以 / 开头切换显示。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 被修改的 AppItem::icon() 代码区域上次修改为 UI 重构(非 bug 修复),本次改动不会撤销历史修复。
  • codegraph 未发现外部调用者;icon() 返回值仅由 QML 绑定消费,非日历图标返回值与改动前一致。

业务影响范围

仅影响日历应用在任务栏中的图标渲染。当日历应用图标出现在任务栏(驻留或运行中)时,将显示带当前日期的动态图标,而非静态日历图标。其他应用图标不受影响。

验证建议

验证任务栏中日历应用图标显示正确的当前日期,其他应用图标正常显示无回归。测试图标拖拽、悬停预览、启动动画以确认 QML 容器改动无副作用。

Summary by Sourcery

Support dynamic calendar icons in the taskbar by generating date-specific artwork and rendering it alongside standard application icons.

New Features:

  • Render the calendar application’s taskbar icon with the current date and weekday.

Bug Fixes:

  • Fix taskbar rendering of the dynamic calendar icon so it no longer falls back to a generic static icon.

Enhancements:

  • Add support for displaying generated SVG file paths alongside theme icon names in taskbar application icons.

Build:

  • Include the calendar icon helper sources in the taskbar task-manager build.

The taskbar (dde-shell dock) passed the static icon name
'dde-calendar-dynamic' directly to DciIcon without intercepting it to
synthesize a date-specific SVG, so the calendar app icon showed a
generic calendar instead of the current date.

Port the createCalendarIcon() SVG generation logic from dde-launchpad
into dde-shell. In AppItem::icon(), intercept 'dde-calendar-dynamic',
generate a temp SVG with the current date, and return the file path.
In AppItem.qml, wrap DciIcon in a parent Item and add an Image element
that renders file paths, with visibility toggled by whether iconName
starts with '/'.

Log: BUG-295871

@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.

Sorry @mhduiy, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Reviewer's Guide

The taskbar now recognizes the calendar application's dynamic icon name, generates and reuses a current-date SVG in the temporary directory, and renders returned file paths through QML while leaving standard theme icon handling unchanged.

Sequence diagram for dynamic calendar taskbar icon rendering

sequenceDiagram
    participant DesktopFileAMParser
    participant AppItem
    participant CalendarIconHelper
    participant TempDirectory
    participant AppItemQML

    DesktopFileAMParser->>AppItem: desktopIcon()
    AppItem->>AppItem: icon()
    alt iconName == dde-calendar-dynamic
        AppItem->>AppItem: QDate::currentDate()
        AppItem->>CalendarIconHelper: createCalendarIcon(svgPath)
        CalendarIconHelper->>TempDirectory: QFile::exists(svgPath)
        alt SVG does not exist
            CalendarIconHelper->>TempDirectory: write current-date SVG
        end
        CalendarIconHelper-->>AppItem: true
        AppItem-->>AppItemQML: svgPath
        AppItemQML->>AppItemQML: Image renders file path
    else standard icon
        AppItem-->>AppItemQML: iconName
        AppItemQML->>AppItemQML: DciIcon renders theme icon
    end
Loading

File-Level Changes

Change Details Files
Add taskbar-side generation and caching of date-specific calendar SVG icons.
  • Introduce a reusable helper containing the ported SVG assets and file-generation logic.
  • Intercept the dynamic calendar icon name in AppItem and return a temp SVG path keyed by year and day-of-year.
  • Preserve the existing icon name when generation fails and for all non-calendar applications.
panels/dock/taskmanager/CMakeLists.txt
panels/dock/taskmanager/appitem.cpp
panels/dock/taskmanager/calendariconhelper.cpp
panels/dock/taskmanager/calendariconhelper.h
Update taskbar QML icon rendering to support both theme icon names and generated file paths.
  • Wrap the icon renderer in a shared Item container.
  • Use DciIcon for named icons and Image for absolute file paths with mutually exclusive visibility.
  • Retain existing sizing, centering, loading, and smoothing behavior for taskbar interactions.
panels/dock/taskmanager/package/AppItem.qml

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Fail


📊 总体评价

项目 结果
审查结论 代码审查不通过
评分详情 存在1个非安全维度(语法逻辑)不通过,含一般逻辑错误(createCalendarIcon返回值未校验写入结果),代码安全维度无漏洞
项目名称 linuxdeepin/dde-shell
PR #1743
Commit a186cf2
分析模式 全量分析

📝 提交信息

标题: fix: support dynamic calendar icon in taskbar

描述:

The taskbar (dde-shell dock) passed the static icon name 'dde-calendar-dynamic' directly to DciIcon without intercepting it to synthesize a date-specific SVG, so the calendar app icon showed a generic calendar instead of the current date.

Port the createCalendarIcon() SVG generation logic from dde-launchpad into dde-shell. In AppItem::icon(), intercept 'dde-calendar-dynamic', generate a temp SVG with the current date, and return the file path. In AppItem.qml, wrap DciIcon in a parent Item and add an Image element that renders file paths, with visibility toggled by whether iconName starts with '/'.

Log: BUG-295871

修改文件:

  1. panels/dock/taskmanager/CMakeLists.txt - 添加新源文件到构建
  2. panels/dock/taskmanager/appitem.cpp - 修改icon()函数支持动态日历图标
  3. panels/dock/taskmanager/calendariconhelper.cpp - 新增:SVG日历图标生成逻辑
  4. panels/dock/taskmanager/calendariconhelper.h - 新增:头文件声明
  5. panels/dock/taskmanager/package/AppItem.qml - 修改QML支持文件路径图标

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

评分: 14/25 分

潜在问题:

  1. calendariconhelper.cpp 第210行,createCalendarIcon()函数在文件写入操作后无条件返回true。如果file.write()写入失败(如磁盘空间不足),函数仍返回true,导致icon()返回一个可能损坏或空的SVG文件路径。后续调用因文件已存在而跳过重新生成,损坏的图标将持续存在。(-8分)

  2. appitem.cpp 第69行,QStandardPaths::standardLocations(QStandardPaths::TempLocation).constFirst()直接调用constFirst(),若返回空列表则为未定义行为,可能导致崩溃。虽然在Linux上TempLocation通常返回/tmp,但仍应进行防御性检查。(-3分)

建议:

  • createCalendarIcon()在file.close()后检查file.error()是否为QFile::NoError,失败时返回false并删除损坏的文件
  • icon()中先检查standardLocations()返回值是否为空

2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

评分: 20/25 分

潜在问题:

  1. calendariconhelper.cpp 第153行,file.write()的返回值未检查,无法确认数据是否完整写入文件。(-2分)

  2. calendariconhelper.cpp 第92行,static const QByteArrayList &dayList = {...}使用引用绑定到静态局部变量,语法不常见且无必要。虽然C++标准允许,但容易引起混淆。(-1分)

  3. calendariconhelper.h 第13行,代码注释标注为从dde-launchpad移植,存在跨项目代码重复,后续维护时两处代码可能产生不一致。(-2分)

正面评价:

  • SPDX许可证头完整 ✓
  • 头文件文档注释清晰 ✓
  • 命名空间使用规范 ✓
  • QML结构清晰,逻辑合理 ✓
  • 移除了旧的注释代码块 ✓
  • Commit message详细且目的明确 ✓

3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

评分: 17/20 分

潜在问题:

  1. appitem.cpp 第67行,icon()作为const getter可能被QML属性绑定频繁调用。当图标为dde-calendar-dynamic时,每次调用都会执行QDate::currentDate()、QStandardPaths::standardLocations()字符串拼接和createCalendarIcon()(内部含文件存在性检查)。虽然文件存在性检查开销很小,但可以考虑缓存svgPath。(-3分)

正面评价:

  • SVG文件基于年+日序号命名,每天仅生成一次,具有良好的缓存机制 ✓
  • 静态SVG数据数组仅初始化一次 ✓
  • 文件存在性检查避免了不必要的SVG重新生成 ✓

4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

评分: 30/30 分

🔐 存在 0 个安全漏洞

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

安全分析:

  • 文件路径构造使用QDate整数(年份+日序号),无用户输入参与,无路径遍历风险 ✓
  • SVG内容全部为硬编码数据,无注入风险 ✓
  • 无硬编码密钥、密码或Token ✓
  • 临时文件写入操作安全,无非敏感数据泄露 ✓
  • QML中root.iconName.startsWith("/")判断逻辑安全,无注入风险 ✓
  • 无命令注入、SQL注入、XSS等安全漏洞 ✓

🔧 OCR 审查结果

序号 文件 行号 类别 严重度 描述 备注
1 appitem.cpp 67 performance high icon()方法被频繁调用时,createCalendarIcon()每次都会被调用,涉及磁盘I/O。建议在调用前检查文件是否已存在。 OCR描述部分不准确:createCalendarIcon内部已有文件存在性检查,不会每次都写入文件。已计入性能维度。
2 appitem.cpp 69 bug medium QStandardPaths::standardLocations()可能返回空列表,对空列表调用constFirst()是未定义行为,可能导致崩溃。 与AI审计发现的问题一致,已计入语法逻辑维度。

💡 改进建议代码示例

修复1:createCalendarIcon返回值校验(calendariconhelper.cpp)

bool createCalendarIcon(const QString &fileName)
{
    qCDebug(calendarIconLog) << "Creating calendar icon:" << fileName;
    // ... SVG data definitions ...

    if (!QFile(fileName).exists()) {
        QFile file(fileName);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
            return false;

        // ... write SVG content ...
        file.write(QByteArray("    </g>\n</svg>"));
        file.close();

        // 检查写入是否成功
        if (file.error() != QFile::NoError) {
            QFile::remove(fileName);  // 删除可能损坏的文件
            return false;
        }
    }

    return true;
}

修复2:constFirst()防御性检查(appitem.cpp)

if (iconName == QStringLiteral("dde-calendar-dynamic")) {
    const QDate today = QDate::currentDate();
    const auto locations = QStandardPaths::standardLocations(QStandardPaths::TempLocation);
    if (locations.isEmpty())
        return iconName;  // 回退到原始图标名

    const QString tempDir = locations.constFirst();
    const QString svgPath = tempDir + QStringLiteral("/%1_%2.svg").arg(today.year()).arg(today.dayOfYear());
    if (dock::createCalendarIcon(svgPath))
        return svgPath;
}

📋 审查清单

  • 已按四维度标准完成代码分析(语法逻辑、代码质量、代码性能、代码安全)
  • 代码安全维度第一行包含"存在0个安全漏洞"
  • 安全漏洞已按等级分类(无安全漏洞)
  • 包含漏洞对比统计行(新增0/减少0/持平0)
  • 每个维度标记✓/✕与评价词一致
  • 审查结论考虑了commit message的目的(修复日历动态图标显示)
  • 问题定位准确,行号和函数名正确
  • OCR审查结果已合并

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

审查时间: 2026-09-14 19:14

@mhduiy

mhduiy commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

方案不合理, AM 已经支持动态刷新图标,应该在日历本身进行处理,刷新自己的图标

@mhduiy mhduiy closed this Sep 21, 2026
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