Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Nov 20, 2025

Change the app order in Privacy and Security

Log: Change the app order in Privacy and Security
pms: BUG-303417

Summary by Sourcery

Fix app ordering in Privacy and Security by categorizing names and inserting apps at the correct sorted position.

Bug Fixes:

  • Prefix sort field with a category (digit, ASCII letter, or Chinese/other) before pinyin conversion to ensure correct ordering
  • Insert new applications at the computed sorted position instead of always appending to the end

Change the app order in Privacy and Security

Log: Change the app order in Privacy and Security
pms: BUG-303417
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

The full list of commands accepted by this bot can be found here.

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 Nov 20, 2025

Reviewer's Guide

This PR refactors the app ordering mechanism in Privacy and Security by enhancing the sort field to include a category prefix (digits, letters, others) and updating the model insertion logic to maintain sorted order based on that sort key.

Class diagram for updated ApplicationItem and AppsModel

classDiagram
    class ApplicationItem {
        - QString m_name
        - QString m_sortField
        + void onNameChanged(const QString &name)
        + QString sortField()
    }
    class AppsModel {
        - QList<ApplicationItem*> m_appItems
        + void appendItem(ApplicationItem *appItem)
    }
    ApplicationItem <.. AppsModel : uses
Loading

Flow diagram for new app insertion logic in AppsModel

flowchart TD
    A["New ApplicationItem created"] --> B["Calculate sortField (category + pinyin)"]
    B --> C["Find insert position in m_appItems based on sortField"]
    C --> D["Insert ApplicationItem at correct position"]
    D --> E["App list remains sorted"]
Loading

File-Level Changes

Change Details Files
Enhanced application sort key generation with category prefix
  • Extract uppercase name into a temporary variable
  • Determine category (digit, ASCII letter, other) from the first non-space character
  • Prefix the pinyin conversion with the category number when setting sortField
src/plugin-privacy/operation/applicationitem.cpp
Changed app list insertion to maintain sorted order by sortField
  • Compute insertPos by comparing the new item’s sortField against existing items
  • Use beginInsertRows with the computed insertPos
  • Insert the new item at insertPos instead of appending at the end
src/plugin-privacy/operation/privacysecuritymodel.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你审查这段代码的修改:

  1. 代码逻辑改进:
  • 在 ApplicationItem::onNameChanged() 中,新的排序逻辑更合理:
    • 将应用名分为三类:数字开头(0)、字母开头(1)、其他(2)
    • 使用分类编号 + 拼音作为排序字段
    • 这样可以确保数字开头的应用排在最前,字母次之,其他最后
  1. 代码质量:
  • 代码结构清晰,变量命名合理
  • 使用了 Qt 的标准函数如 isSpace()、isDigit() 等
  • 添加了适当的注释说明排序规则
  1. 性能优化建议:
  • 在 AppsModel::appendItem() 中,每次插入都需要遍历查找位置,当应用数量较多时可能会影响性能
  • 建议:
    1. 可以考虑使用二分查找来优化插入位置的查找
    2. 或者维护一个已排序的列表,使用合适的排序算法
    3. 如果应用数量很大,可以考虑使用数据库或其他索引结构
  1. 安全性:
  • 代码本身没有明显安全问题
  • 使用了 Qt 的标准函数处理字符串,相对安全
  1. 其他建议:
  • 可以考虑将分类逻辑提取为单独的函数,提高代码复用性
  • 在 ApplicationItem 中添加一个枚举类型来表示分类,而不是直接使用数字
  • 考虑添加单元测试来验证排序逻辑的正确性

总体来说,这是一个不错的改进,使应用排序更加合理。主要需要关注的是大量应用时的性能问题。

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 there - I've reviewed your changes - here's some feedback:

  • appendItem uses a linear search for each insertion, leading to O(n²) behavior when resetting; consider sorting once and doing a bulk insert or using std::lower_bound for more efficient insertion.
  • Extract the category-plus-pinyin sortField construction into a shared helper so the sorting logic stays consistent and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- appendItem uses a linear search for each insertion, leading to O(n²) behavior when resetting; consider sorting once and doing a bulk insert or using std::lower_bound for more efficient insertion.
- Extract the category-plus-pinyin sortField construction into a shared helper so the sorting logic stays consistent and easier to maintain.

## Individual Comments

### Comment 1
<location> `src/plugin-privacy/operation/applicationitem.cpp:120` </location>
<code_context>
+        break;
+    }
+
+    QString pinyin = DTK_CORE_NAMESPACE::Chinese2Pinyin(upperName);
+    m_sortField = QString::number(category) + pinyin;
     emitDataChanged();
 }
</code_context>

<issue_to_address>
**suggestion:** Consider adding a separator between category and pinyin for sortField.

Directly joining category and pinyin may cause ambiguity if pinyin begins with a digit. Adding a separator, such as an underscore, will clarify the sortField format.

```suggestion
    m_sortField = QString::number(category) + "_" + pinyin;
```
</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.

}

QString pinyin = DTK_CORE_NAMESPACE::Chinese2Pinyin(upperName);
m_sortField = QString::number(category) + pinyin;
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider adding a separator between category and pinyin for sortField.

Directly joining category and pinyin may cause ambiguity if pinyin begins with a digit. Adding a separator, such as an underscore, will clarify the sortField format.

Suggested change
m_sortField = QString::number(category) + pinyin;
m_sortField = QString::number(category) + "_" + pinyin;

@deepin-bot
Copy link

deepin-bot bot commented Nov 27, 2025

TAG Bot

New tag: 6.1.59
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #2843

@deepin-bot
Copy link

deepin-bot bot commented Nov 28, 2025

TAG Bot

New tag: 6.1.60
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #2844

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