Skip to content

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Jan 30, 2026

dock add pluginsChanged signal first, then add this function to dcc.

Log: add pluginsChanged signal to reload dock tray plugins dynamically
Pms: BUG-311317

Summary by Sourcery

Propagate new dock D-Bus signals and respond to plugin changes in the DCC dock export to keep tray plugins in sync dynamically.

New Features:

  • Expose a pluginsChanged D-Bus signal through DockDBusProxy and connect it so DccDockExport reloads plugin data when dock plugins change.

Bug Fixes:

  • Route existing showInPrimaryChanged and pluginVisibleChanged D-Bus events through DockDBusProxy signals instead of slots to ensure they are correctly propagated to listeners.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yixinshark

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
Copy link

sourcery-ai bot commented Jan 30, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new pluginsChanged signal to the dock DBus proxy and wires it into DCC so the dock tray plugins can be reloaded dynamically when the dock reports plugin changes. Also adjusts some existing DBus connections to forward signals instead of invoking slots directly.

Sequence diagram for dynamic dock tray plugin reload via pluginsChanged

sequenceDiagram
    participant DockService
    participant DockDBusProxy
    participant DccDockExport
    participant DockPluginModel

    DockService->>DockDBusProxy: pluginsChanged()
    activate DockDBusProxy
    DockDBusProxy-->>DockDBusProxy: emit pluginsChanged()
    DockDBusProxy-->>DccDockExport: pluginsChanged()
    deactivate DockDBusProxy

    activate DccDockExport
    DccDockExport->>DccDockExport: loadPluginData()
    DccDockExport->>DockPluginModel: setPluginVisible(...)
    deactivate DccDockExport
Loading

Sequence diagram for forwarding dock pluginVisibleChanged via DockDBusProxy

sequenceDiagram
    participant DockService
    participant DockDBusProxy
    participant DccDockExport
    participant DockPluginModel

    DockService->>DockDBusProxy: pluginVisibleChanged(pluginName, visible)
    activate DockDBusProxy
    DockDBusProxy-->>DockDBusProxy: emit pluginVisibleChanged(pluginName, visible)
    DockDBusProxy-->>DccDockExport: pluginVisibleChanged(pluginName, visible)
    deactivate DockDBusProxy

    activate DccDockExport
    DccDockExport->>DockPluginModel: setPluginVisible(pluginName, visible)
    deactivate DccDockExport
Loading

Updated class diagram for DockDBusProxy and DccDockExport signals

classDiagram
    class DockDBusProxy {
        +DockDBusProxy(parent)
        +pluginVisibleChanged(pluginName, visible) const
        +showRecentChanged(changed) const
        +pluginsChanged() const
        -m_daemonDockInter
    }

    class DccDockExport {
        +DccDockExport(parent)
        +initDisplayModeConnection()
        +initData()
        +loadPluginData()
        -m_dockDbusProxy
        -m_pluginModel
    }

    class DockPluginModel {
        +setPluginVisible(pluginName, visible)
    }

    DockDBusProxy <.. DccDockExport : uses
    DccDockExport --> DockPluginModel : updates
Loading

File-Level Changes

Change Details Files
Expose new pluginsChanged DBus signal from dock and hook it to reload plugin data in DccDockExport.
  • Declare a new pluginsChanged() const signal-like method in DockDBusProxy to mirror the dock service signal.
  • Connect the Dock DBus session to the new "pluginsChanged" signal from the dock service and re-emit it via DockDBusProxy.
  • Connect DockDBusProxy::pluginsChanged to DccDockExport::loadPluginData so plugin data is reloaded whenever plugins change.
src/plugin-dock/operation/dockdbusproxy.h
src/plugin-dock/operation/dockdbusproxy.cpp
src/plugin-dock/operation/dccdockexport.cpp
Align existing DBus connections to re-emit signals instead of invoking local slots for showInPrimaryChanged and pluginVisibleChanged.
  • Change DBus connections for showInPrimaryChanged and pluginVisibleChanged in DockDBusProxy to emit corresponding Qt signals rather than calling slots, making them consistent with other forwarded DBus signals and usable with the new wiring.
src/plugin-dock/operation/dockdbusproxy.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Now that pluginVisibleChanged, showRecentChanged, and the new pluginsChanged are being used as signals (both in QDBusConnection::connect with SIGNAL() and via &DockDBusProxy::pluginsChanged), consider moving them from the public Q_SLOTS section into a signals section (or otherwise clarifying the comment) so their intent as signals is clear and consistent with their usage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `pluginVisibleChanged`, `showRecentChanged`, and the new `pluginsChanged` are being used as signals (both in `QDBusConnection::connect` with `SIGNAL()` and via `&DockDBusProxy::pluginsChanged`), consider moving them from the `public Q_SLOTS` section into a `signals` section (or otherwise clarifying the comment) so their intent as signals is clear and consistent with their usage.

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.

@yixinshark yixinshark requested a review from mhduiy January 30, 2026 03:02
@yixinshark yixinshark force-pushed the fix-reloadDockPlugins branch from a194a21 to bc5d854 Compare January 30, 2026 03:02
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要是为了在插件发生变化时能够及时刷新数据。整体逻辑是正确的,但我在语法、代码质量、性能和安全性方面有以下改进建议:

1. 代码语法与规范

问题:Qt 信号槽连接方式不一致
dockdbusproxy.cpp 中,代码混用了 SIGNAL/SLOT 宏和函数指针语法。

  • 现状
    QDBusConnection::sessionBus().connect(..., SIGNAL(ShowInPrimaryChanged(bool)));
  • 改进建议:Qt 5 推荐使用函数指针语法,因为它在编译时进行类型检查,而 SIGNAL/SLOT 宏只在运行时通过字符串匹配检查,容易出错。
  • 修改后
    // 在 dockdbusproxy.cpp 中
    QDBusConnection::sessionBus().connect(DockService, DockPath, DockInterface, "showInPrimaryChanged", this, &DockDBusProxy::ShowInPrimaryChanged);
    QDBusConnection::sessionBus().connect(DockService, DockPath, DockInterface, "pluginVisibleChanged", this, &DockDBusProxy::pluginVisibleChanged);
    QDBusConnection::sessionBus().connect(DockService, DockPath, DockInterface, "pluginsChanged", this, &DockDBusProxy::pluginsChanged);

问题:信号命名风格不统一

  • 现状ShowInPrimaryChanged 使用了大写开头,而 pluginVisibleChanged 使用了小写开头。
  • 改进建议:Qt 信号通常遵循驼峰命名法且首字母小写(如 showInPrimaryChanged),以与标准 Qt 库风格保持一致。如果 DBus 接口强制要求大写,请在注释中说明。

2. 代码质量

问题:缺少注释

  • 现状:新增的 pluginsChanged 信号及其连接没有注释说明其用途。
  • 改进建议:在 dockdbusproxy.h 中为 pluginsChanged 添加注释,说明该信号在插件列表发生变化时触发。

修改后

// 在 dockdbusproxy.h 中
/**
 * @brief 插件列表发生变化时触发该信号
 */
void pluginsChanged() const;

3. 代码性能

潜在问题:频繁触发数据加载

  • 现状pluginsChanged 信号连接到 loadPluginData,如果 DBus 服务频繁发送 pluginsChanged 信号,可能导致频繁的数据加载操作。
  • 改进建议
    1. 检查 loadPluginData 是否执行了耗时操作(如文件 I/O 或网络请求)。如果是,考虑增加防抖(debounce)机制。
    2. 如果 loadPluginData 只是更新内存中的数据,则当前实现是可以接受的。

4. 代码安全

问题:DBus 连接错误处理缺失

  • 现状QDBusConnection::sessionBus().connect 的返回值未被检查。如果连接失败,程序会在静默中失效,导致功能不可用。
  • 改进建议:检查 connect 的返回值,并在失败时记录日志。

修改后

// 在 dockdbusproxy.cpp 中
bool connected = QDBusConnection::sessionBus().connect(
    DockService, DockPath, DockInterface, "pluginsChanged", 
    this, &DockDBusProxy::pluginsChanged
);
if (!connected) {
    qWarning() << "Failed to connect to DBus signal: pluginsChanged";
}

5. 其他建议

问题:信号声明位置

  • 现状pluginsChanged 被声明在 public Q_SLOTS 下,但它是作为信号使用的。
  • 改进建议:将 pluginsChanged 移动到 signals 部分,以明确其语义。

修改后

// 在 dockdbusproxy.h 中
signals:
    void pluginVisibleChanged(const QString &pluginName, bool visible);
    void showRecentChanged(bool);
    void pluginsChanged();

总结修改后的代码

dockdbusproxy.h

signals:
    void pluginVisibleChanged(const QString &pluginName, bool visible);
    void showRecentChanged(bool);
    void pluginsChanged();  // 插件列表发生变化时触发

dockdbusproxy.cpp

DockDBusProxy::DockDBusProxy(QObject *parent)
    : QObject(parent)
{
    // ... 其他代码 ...

    bool connected = QDBusConnection::sessionBus().connect(
        DockService, DockPath, DockInterface, "pluginsChanged", 
        this, &DockDBusProxy::pluginsChanged
    );
    if (!connected) {
        qWarning() << "Failed to connect to DBus signal: pluginsChanged";
    }

    // ... 其他代码 ...
}

dccdockexport.cpp

DccDockExport::DccDockExport(QObject *parent)
    : QObject(parent)
{
    // ... 其他代码 ...

    connect(m_dockDbusProxy, &DockDBusProxy::pluginsChanged, 
            this, &DccDockExport::loadPluginData);

    // ... 其他代码 ...
}

这些修改可以提高代码的可读性、健壮性和安全性。

dock add pluginsChanged signal first, then add this function to dcc.

Log: add pluginsChanged signal to reload dock tray plugins dynamically
Pms: BUG-311317
@yixinshark yixinshark force-pushed the fix-reloadDockPlugins branch from bc5d854 to aa0a77e Compare February 2, 2026 02:22
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