Skip to content

Conversation

@JWWTSL
Copy link
Contributor

@JWWTSL JWWTSL commented Dec 8, 2025

log: Design Issues

bug: https://pms.uniontech.com/bug-view-337467.html

Summary by Sourcery

Fix system album sidebar context menu behavior and extend system album management capabilities.

Bug Fixes:

  • Ensure the system album right-click menu appears even when the album has no content, with actions disabled as appropriate.
  • Correct album renaming to work for all album types, including system and auto-import albums, and refresh their names in the view.

Enhancements:

  • Allow renaming and deletion of system albums from the sidebar context menu while keeping underlying files intact.
  • Track and manage the currently selected system album in the sidebar to keep selection consistent after deletions.
  • Show the import prompt for empty system and auto-import albums, aligning the empty-state experience with custom albums.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查和分析:

  1. 语法逻辑方面:
  • 代码整体语法正确,没有明显的语法错误
  • 重命名系统相册的逻辑从 albumControl.getAllCustomAlbumId()[index] 改为直接使用 model.uuid 是合理的改进,避免了数组索引访问可能带来的问题
  1. 代码质量方面:
  • 新增了系统相册的删除功能,代码结构清晰,但建议在 deleteSystemAlbum() 函数中添加更多的错误处理和边界条件检查
  • 系统相册的 editable 属性统一设置为 true,建议添加相应的权限检查逻辑
  • 右键菜单项的可见性改为始终显示但根据条件禁用,提高了界面一致性
  1. 代码性能方面:
  • 使用 model.uuid 替代数组索引访问可以提高性能
  • renameAlbum 函数中添加了相册类型判断,建议将类型判断逻辑缓存或优化,避免重复判断
  1. 代码安全方面:
  • 系统相册的删除操作仅移除数据库记录和侧边栏入口,不会删除实际文件,这是安全的做法
  • 建议在 renameAlbum 函数中添加对 newName 的合法性检查,防止SQL注入或非法字符
  • 建议在删除系统相册时添加确认对话框,防止误操作

具体改进建议:

  1. renameAlbum 函数中添加输入验证:
bool AlbumControl::renameAlbum(int UID, const QString &newName)
{
    if (newName.isEmpty() || newName.length() > MAX_ALBUM_NAME_LENGTH) {
        return false;
    }
    
    // 添加对特殊字符的检查
    if (newName.contains(QRegExp("[<>:\"/\\|?*]"))) {
        return false;
    }
    
    // 现有的类型判断逻辑...
}
  1. deleteSystemAlbum 函数中添加错误处理:
function deleteSystemAlbum() {
    if (sysListModel.count === 0) {
        return;
    }
    
    var delAlbumName = albumControl.getCustomAlbumByUid(GStatus.currentCustomAlbumUId);
    if (!delAlbumName) {
        console.error("Failed to get album name");
        return;
    }
    
    try {
        albumControl.removeAlbum(GStatus.currentCustomAlbumUId);
        // 其余逻辑...
    } catch (e) {
        console.error("Failed to delete album:", e);
        DTK.sendMessage(thumbnailImage, qsTr("Failed to delete album"), "error");
    }
}
  1. 建议添加系统相册权限检查:
bool AlbumControl::isSystemAlbumEditable(int UID) {
    // 检查是否有编辑系统相册的权限
    return checkSystemAlbumPermission(UID);
}
  1. 优化类型判断逻辑,可以考虑使用枚举或常量:
enum AlbumType {
    Custom = 0,
    Favourite = 1,
    AutoImport = 2,
    System = 3
};

AlbumType getAlbumType(int UID) {
    if (UID == 0) return AlbumType::Favourite;
    if (isAutoImportAlbum(UID)) return AlbumType::AutoImport;
    if (isSystemAlbum(UID)) return AlbumType::System;
    return AlbumType::Custom;
}

这些改进可以提高代码的健壮性、安全性和可维护性。

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 8, 2025

Reviewer's Guide

Adjusts system album sidebar behavior and menus so right-click always shows a populated context menu, adds rename/delete actions for system albums, wires up album deletion flow, broadens the empty-view handling to system/auto-import albums, and updates backend album renaming to handle multiple album types.

Sequence diagram for system album right-click rename flow

sequenceDiagram
    actor User
    participant SystemSideBar as SystemSideBarView
    participant SideBarItem as SideBarItemDelegate
    participant SystemMenu
    participant AlbumControl
    participant DBManager
    participant GStatus

    User->>SystemSideBar: Click system album item
    SystemSideBar->>GStatus: set currentViewType = ViewCustomAlbum
    SystemSideBar->>GStatus: set currentCustomAlbumUId = uuid
    SystemSideBar->>SystemSideBar: set currentSystemIndex

    User->>SystemSideBar: Right click current system album
    SystemSideBar->>SystemMenu: popup()

    User->>SystemMenu: Choose Rename
    SystemMenu->>SideBarItem: invoke rename() on currentItem
    SideBarItem->>SideBarItem: show keyLineEdit, user edits name
    User->>SideBarItem: Confirm rename (editingFinished)

    SideBarItem->>AlbumControl: renameAlbum(model.uuid, newName)
    AlbumControl->>AlbumControl: infer AlbumDBType from UID
    AlbumControl->>DBManager: renameAlbum(UID, newName, atype)
    DBManager-->>AlbumControl: bool ok
    AlbumControl-->>SideBarItem: ok

    SideBarItem->>SideBarItem: update songName.text
    SideBarItem->>GStatus: sigCustomAlbumNameChaged(currentCustomAlbumUId, newName)
Loading

Sequence diagram for deleting a system album via context menu

sequenceDiagram
    actor User
    participant SystemSideBar as SystemSideBarView
    participant SystemMenu
    participant RemoveDialog as RemoveAlbumDialog
    participant SidebarView as SidebarScrollView
    participant AlbumControl
    participant SysListModel
    participant GStatus

    User->>SystemSideBar: Right click system album
    SystemSideBar->>SystemMenu: popup()

    User->>SystemMenu: Choose Delete
    SystemMenu->>RemoveDialog: set deleteType = 2
    SystemMenu->>RemoveDialog: show()

    User->>RemoveDialog: Confirm delete
    RemoveDialog->>SidebarView: deleteAlbum(type = 2)
    SidebarView->>SidebarView: branch to deleteSystemAlbum()

    SidebarView->>AlbumControl: getCustomAlbumByUid(currentCustomAlbumUId)
    SidebarView->>AlbumControl: removeAlbum(currentCustomAlbumUId)

    SidebarView->>SysListModel: adjust currentSystemIndex
    SidebarView->>SysListModel: remove(currentSystemIndex)
    SidebarView->>SidebarView: send DTK.sendMessage

    alt sysListModel.count > 0
        SidebarView->>SystemSideBar: set view.currentIndex
        SidebarView->>SystemSideBar: set currentItem.checked = true
        SidebarView->>GStatus: set currentViewType = ViewCustomAlbum
        SidebarView->>GStatus: set currentCustomAlbumUId = sysListModel.get(newIndex).uuid
        SidebarView->>GStatus: set searchEditText = ""
        SidebarView->>SystemSideBar: currentItem.forceActiveFocus()
    else no system albums left
        SidebarView->>SidebarView: backCollection()
    end
Loading

Class diagram for updated AlbumControl rename logic

classDiagram
    class AlbumControl {
        +bool renameAlbum(int UID, QString newName)
        +bool isAutoImportAlbum(int UID)
        +QString getCustomAlbumByUid(int UID)
        +QVariant getAllCustomAlbumId()
        +void removeAlbum(int UID)
    }

    class DBManager {
        <<singleton>>
        +static DBManager* instance()
        +bool renameAlbum(int UID, QString newName, AlbumDBType atype)
    }

    class AlbumDBType {
        <<enum>>
        Favourite
        Custom
        AutoImport
    }

    AlbumControl --> DBManager : uses
    AlbumControl --> AlbumDBType : infers
    DBManager --> AlbumDBType : parameter
Loading

Flow diagram for NoPictureView visibility and behavior in custom and auto-import albums

flowchart TD
    A[Album opened in CustomAlbumView] --> B{numLabelText is empty?}
    B -- no --> Z[NoPictureView.visible = false]
    B -- yes --> C{filterType == 0?}
    C -- no --> Z
    C -- yes --> D{isCustom or isSystemAutoImport or isNormalAutoImport?}

    D -- yes --> E[NoPictureView.visible = true]
    E --> F[bShowImportBtn = true]
    E --> G[iconName = nopicture1]

    D -- no --> E
    E --> H[bShowImportBtn = false]
    E --> I{GStatus.currentViewType == ViewCustomAlbum?}
    I -- yes --> J[iconName = nopicture2]
    I -- no --> K[iconName = nopicture3]
Loading

File-Level Changes

Change Details Files
Track and delete system albums from the sidebar, and ensure selection updates correctly after deletion.
  • Add currentSystemIndex property to track currently selected system album index in the sidebar model.
  • Implement deleteSystemAlbum() to remove the album via AlbumControl, update sysListModel, select a valid neighboring album or return to collection view, and send a notification.
  • Wire removeAlbumDialog type === 2 to invoke deleteSystemAlbum().
src/qml/SideBar/Sidebar.qml
Fix system album right-click menu visibility and enrich it with rename/delete options.
  • On system album click, update currentSystemIndex via systemSideBar.indexFromUuid(uuid).
  • Change onItemRightClicked to always popup systemMenu regardless of albumPaths length, relying on item visibility/enabled state instead.
  • Always show Slide show and Export menu items but disable them when albumPaths is empty.
  • Add Rename and Delete RightMenuItem entries to the system album context menu, with Delete opening removeAlbumDialog as type 2.
src/qml/SideBar/Sidebar.qml
Support renaming various album types in the backend when invoked from the sidebar delegate.
  • Update AlbumControl::renameAlbum to infer album DB type (Favourite, AutoImport, or Custom) based on UID and isAutoImportAlbum().
  • Pass the inferred AlbumDBType to DBManager::renameAlbum and return the DB call result instead of always true.
  • Modify SideBarItemDelegate rename logic to use model.uuid instead of getAllCustomAlbumId()[index] and clarify that rename signal applies to all album types.
src/src/albumControl.cpp
src/qml/SideBar/SideBarItemDelegate.qml
Unify the empty-album view behavior across custom, system auto-import, and normal auto-import albums.
  • Adjust NoPictureView visibility and properties so that empty custom, system auto-import, and normal auto-import albums all show the import button and use the same icon.
  • Base the NoPictureView icon and import button on isCustom, isSystemAutoImport, and isNormalAutoImport flags rather than only isCustom.
src/qml/ThumbnailImageView/CustomAlbum/CustomAlbum.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

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 and found some issues that need to be addressed.

  • In Sidebar.qml, currentSystemIndex is only updated in onItemClicked, so if a user right-clicks a non-selected system album, deleteSystemAlbum() may act on the previously selected album instead of the one under the cursor; consider setting currentSystemIndex in onItemRightClicked (e.g. via indexFromUuid) or passing the index/uuid directly to the delete path.
  • System albums (uuid 1/2/3) are now marked editable: true and wired into the generic renameAlbum/delete flow; double-check whether system albums are intended to be user-renamable/deletable, and if not, gate the new "Rename"/"Delete" menu actions and delegate editing on a dedicated property rather than reusing editable for both.
  • The new deleteSystemAlbum() largely duplicates selection-management logic from other delete paths; consider extracting a small helper to compute and apply the next selected index to keep the behavior consistent and easier to maintain across custom/import/system albums.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Sidebar.qml`, `currentSystemIndex` is only updated in `onItemClicked`, so if a user right-clicks a non-selected system album, `deleteSystemAlbum()` may act on the previously selected album instead of the one under the cursor; consider setting `currentSystemIndex` in `onItemRightClicked` (e.g. via `indexFromUuid`) or passing the index/uuid directly to the delete path.
- System albums (`uuid` 1/2/3) are now marked `editable: true` and wired into the generic `renameAlbum`/delete flow; double-check whether system albums are intended to be user-renamable/deletable, and if not, gate the new "Rename"/"Delete" menu actions and delegate editing on a dedicated property rather than reusing `editable` for both.
- The new `deleteSystemAlbum()` largely duplicates selection-management logic from other delete paths; consider extracting a small helper to compute and apply the next selected index to keep the behavior consistent and easier to maintain across custom/import/system albums.

## Individual Comments

### Comment 1
<location> `src/qml/SideBar/Sidebar.qml:23-26` </location>
<code_context>
     signal sideBarListChanged(string type, string displayName)
     property int currentImportCustomIndex: 0 //自动导入相册当前索引值
     property int currentCustomIndex: 0 //自定义相册当前索引值
+    property int currentSystemIndex: 0 //系统相册当前索引值
     property var devicePaths : albumControl.getDevicePaths()
     property var albumPaths : albumControl.getAlbumPaths(GStatus.currentCustomAlbumUId)
</code_context>

<issue_to_address>
**issue (bug_risk):** Using a separate `currentSystemIndex` risks going out of sync with the actual selection and deleting the wrong album.

`currentSystemIndex` is only updated in `onItemClicked`, but the current item in `systemSideBar.view` can also change via keyboard, programmatic selection, or state restore. In `deleteSystemAlbum()` this can delete a different album from `sysListModel` than the one visibly selected. Use `systemSideBar.view.currentIndex` (or `indexFromUuid(GStatus.currentCustomAlbumUId)`) directly in `deleteSystemAlbum()` instead of maintaining a separate index property.
</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.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 12, 2025

TAG Bot

New tag: 6.0.49
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #381

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