Skip to content

Feat: Add group setting to show screen size.#630

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
GongHeng2017:202603311050-master-fix
Mar 31, 2026
Merged

Feat: Add group setting to show screen size.#630
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
GongHeng2017:202603311050-master-fix

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Mar 31, 2026

-- Add group setting to show screen size.

Log: add feature
Task: https://pms.uniontech.com/task-view-387965.html

Summary by Sourcery

Add configurable control for displaying monitor screen size in device manager views.

New Features:

  • Introduce a reusable Common::isShowScreenSize configuration helper for the showScreenSize setting.

Enhancements:

  • Update monitor overview text and other device info to respect the showScreenSize configuration flag instead of always including screen size.

-- Add group setting to show screen size.

Log: add feature
Task: https://pms.uniontech.com/task-view-387965.html
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 31, 2026

Reviewer's Guide

Refactors screen size visibility into a reusable Common::isShowScreenSize() helper and applies it to both monitor overview text formatting and the "Size" field display, with behavior dependent on a configuration flag and special device types.

Sequence diagram for screen size visibility decision using Common_isShowScreenSize

sequenceDiagram
    participant DeviceMonitor
    participant Common
    participant DConfig

    DeviceMonitor->>Common: isShowScreenSize()
    activate Common
    Common->>DConfig: create(org.deepin.devicemanager, org.deepin.devicemanager)
    activate DConfig
    DConfig-->>Common: dconfig
    deactivate DConfig

    alt DConfig_valid_and_has_showScreenSize
        Common->>DConfig: isValid()
        DConfig-->>Common: true
        Common->>DConfig: keyList()
        DConfig-->>Common: keys_with_showScreenSize
        Common->>DConfig: value(showScreenSize)
        DConfig-->>Common: bool
        Common-->>DeviceMonitor: showScreenSize_flag
    else DConfig_invalid_or_missing_key
        Common-->>DeviceMonitor: true
    end
    deactivate Common

    Note over DeviceMonitor,Common: DeviceMonitor then uses the flag to decide whether to show screen size in overview and Size field
Loading

Sequence diagram for adding Size field in loadOtherDeviceInfo based on Common_isShowScreenSize

sequenceDiagram
    participant DeviceMonitor
    participant Common

    DeviceMonitor->>DeviceMonitor: addOtherDeviceInfo(Primary_Monitor, m_MainScreen)
    DeviceMonitor->>Common: isShowScreenSize()
    Common-->>DeviceMonitor: showScreenSize_flag

    alt showScreenSize_flag_true
        DeviceMonitor->>DeviceMonitor: addOtherDeviceInfo(Size, m_ScreenSize)
    else showScreenSize_flag_false
        DeviceMonitor->>DeviceMonitor: skip_Size_field
    end

    DeviceMonitor->>DeviceMonitor: addOtherDeviceInfo(Serial_Number, m_SerialNumber)
Loading

Updated class diagram for Common_and_DeviceMonitor_screen_size_logic

classDiagram
    class Common {
        <<static>> int specialComType
        <<static>> QByteArray executeClientCmd(QString cmd, QStringList args, QString workPath, int msecsWaiting, bool useEnv)
        <<static>> bool isShowScreenSize()
    }

    class DeviceMonitor {
        QString m_Name
        QString m_ScreenSize
        QString m_MainScreen
        QString m_SerialNumber
        QString getOverviewInfo()
        void loadOtherDeviceInfo()
    }

    class DConfig {
        static DConfig* create(QString name, QString applicationId)
        bool isValid()
        QStringList keyList()
        QVariant value(QString key)
    }

    DeviceMonitor ..> Common : uses
    Common ..> DConfig : reads_showScreenSize_config
Loading

Flow diagram for monitor overview string based on screen size setting

flowchart TD
    A[Start getOverviewInfo] --> B[Call Common_isShowScreenSize]
    B --> C{isShowScreenSize == true}

    C -->|true| D{specialComType == 6 or 7}
    D -->|true| E[Set ov to m_ScreenSize]
    D -->|false| F[Set ov to m_Name of m_ScreenSize]

    C -->|false| G{specialComType == 6 or 7}
    G -->|true| H[Set ov to empty]
    G -->|false| I[Set ov to m_Name]

    E --> J[Return ov]
    F --> J
    H --> J
    I --> J
Loading

File-Level Changes

Change Details Files
Centralize the screen-size visibility decision in a new Common::isShowScreenSize() helper and reuse it where needed.
  • Introduce Common::isShowScreenSize() that reads the showScreenSize DConfig key with a default of true and returns the resulting boolean.
  • Declare the new isShowScreenSize() static method in the Common class header for shared use.
  • Replace the inline DConfig handling in DeviceMonitor::loadOtherDeviceInfo() with a call to Common::isShowScreenSize() before adding the "Size" field.
deepin-devicemanager/src/commonfunction.cpp
deepin-devicemanager/src/commonfunction.h
deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Adjust monitor overview string formatting to respect the screen-size visibility setting and special device types.
  • Wrap the monitor overview construction in DeviceMonitor::getOverviewInfo() with a call to Common::isShowScreenSize() to decide whether to include size, name, or both.
  • For specialComType 6 and 7, show only size in parentheses when size display is enabled, and an empty string when disabled.
  • For other types, show "Name(Size)" when size display is enabled, and just "Name" when disabled.
deepin-devicemanager/src/DeviceManager/DeviceMonitor.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
Copy Markdown

@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 found 2 issues, and left some high level feedback:

  • Common::isShowScreenSize() creates a DConfig instance on every call without managing its lifetime; consider reusing a shared DConfig instance or ensuring it is properly destroyed to avoid repeated allocations or potential leaks.
  • The branching in DeviceMonitor::getOverviewInfo() for specialComType 6/7 vs others is now duplicated in both the isShowScreenSize() and !isShowScreenSize() paths; consider refactoring this into a small helper or more compact conditional to reduce repetition and make the logic easier to follow.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Common::isShowScreenSize() creates a DConfig instance on every call without managing its lifetime; consider reusing a shared DConfig instance or ensuring it is properly destroyed to avoid repeated allocations or potential leaks.
- The branching in DeviceMonitor::getOverviewInfo() for specialComType 6/7 vs others is now duplicated in both the isShowScreenSize() and !isShowScreenSize() paths; consider refactoring this into a small helper or more compact conditional to reduce repetition and make the logic easier to follow.

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/commonfunction.cpp" line_range="307-308" />
<code_context>
     addOtherDeviceInfo("Primary Monitor", m_MainScreen);
-    bool showScreenSize { true };
-#ifdef DTKCORE_CLASS_DConfigFile
-    DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
-    if(dconfig && dconfig->isValid() && dconfig->keyList().contains("showScreenSize")){
-        showScreenSize = dconfig->value("showScreenSize").toBool();
-    }
</code_context>
<issue_to_address>
**issue (bug_risk):** Clarify and enforce ownership of the DConfig instance to avoid potential leaks.

The raw pointer from `DConfig::create` isn’t freed here. Unless DTK guarantees ownership via a parent or other mechanism, this risks leaking on each call. Consider assigning a parent, wrapping it in a smart pointer, or reusing a shared instance if repeated calls are expected.
</issue_to_address>

### Comment 2
<location path="deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp" line_range="359-360" />
<code_context>
-
-    if (Common::specialComType == 6 || Common::specialComType == 7) {
-        ov = QString("(%1)").arg(m_ScreenSize);
+    if (Common::isShowScreenSize()) {
+        if (Common::specialComType == 6 || Common::specialComType == 7) {
+            ov = QString("(%1)").arg(m_ScreenSize);
+        } else {
</code_context>
<issue_to_address>
**suggestion:** Reduce duplication by extracting the repeated specialComType check.

The `Common::specialComType == 6 || Common::specialComType == 7` condition appears in both branches of the outer `if`. Extract it into a local `bool isSpecial = ...;` or a small helper to simplify the control flow and reduce future maintenance risk if special types change.
</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 +307 to +308
DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("showScreenSize")){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Clarify and enforce ownership of the DConfig instance to avoid potential leaks.

The raw pointer from DConfig::create isn’t freed here. Unless DTK guarantees ownership via a parent or other mechanism, this risks leaking on each call. Consider assigning a parent, wrapping it in a smart pointer, or reusing a shared instance if repeated calls are expected.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, lzwind

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

@GongHeng2017
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit 45b3cf6 into linuxdeepin:master Mar 31, 2026
22 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