Skip to content

refactor(tests): auto-discover reader sources and include dirs - #327

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:task-394181-brighten-night-mode-text
Aug 20, 2026
Merged

refactor(tests): auto-discover reader sources and include dirs#327
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:task-394181-brighten-night-mode-text

Conversation

@add-uos

@add-uos add-uos commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

修改内容

将 tests/CMakeLists.txt 中源文件收集和 include 目录配置从逐个手动列举改为自动扫描发现:

  • reader 源文件:用一条 GLOB_RECURSE 递归收集 reader/ 下全部源文件,排除 main.cpp
  • reader include 目录:自动扫描 reader/ 下所有一级子目录,全部加入 include path
  • 测试源文件:用一条 GLOB_RECURSE 收集测试源文件,FILTER EXCLUDE 排除辅助目录

效果

以后在 reader/ 下新增任何子模块(如 reader/newmodule/),tests/CMakeLists.txt 不再需要任何修改——新模块的头文件路径和源文件会被自动发现。

测试

运行 ./tests/test-prj-running.sh,编译通过,1057 个测试全部通过,覆盖率 82.7% 不变。

Summary by Sourcery

将测试工程的源文件与头文件目录配置改为自动发现,以便新 reader 子模块无需修改 CMake 配置即可纳入测试构建。

Enhancements:

  • 自动递归发现 reader 源文件并排除入口文件。
  • 自动将 reader 一级子目录加入头文件搜索路径。
  • 自动递归发现测试源文件并排除辅助资源目录。

Build:

  • 简化 tests/CMakeLists.txt 中的源文件和 include 目录配置,新增 reader 子模块无需手动更新构建配置。

@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 @add-uos, your pull request is larger than the review limit of 150000 diff characters

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors tests CMake configuration to auto-discover reader sources and includes, and introduces persistent reading-state features (scroll position, sidebar width/catalog expansion, tab groups), an eye-protection reading mode UI, and session/tab restoration, along with corresponding database schema changes and translation updates.

Sequence diagram for restoring reading state when opening a document

sequenceDiagram
    participant CentralDocPage
    participant DocSheet
    participant Database
    participant SheetBrowser
    participant SheetSidebar
    participant Central
    participant RestoreTipWidget

    CentralDocPage->>DocSheet: addFileAsync(filePath)
    DocSheet->>Database: readOperation(this)
    alt operation found by filePath
        Database-->>DocSheet: fill m_operation
    else no operation by filePath
        DocSheet->>Database: matchOperationByContent(QFileInfo, this)
        alt content match success
            Database-->>DocSheet: fill m_operation
        else no content match
            DocSheet->>DocSheet: readLastFileOperation()
        end
    end
    DocSheet->>DocSheet: setAlive(true)
    DocSheet->>DocSheet: onOpened(error)
    DocSheet->>SheetBrowser: init(m_operation, m_bookmarks)
    opt restoredFromState
        DocSheet->>SheetBrowser: restoreScrollPosition(m_operation.scrollPosition)
        DocSheet->>SheetSidebar: restoreExpandedSections(m_operation.expandedSections)
        DocSheet->>DocSheet: setSidebarWidth(m_operation.sidebarWidth)
        DocSheet-->>CentralDocPage: sigShowRestoreTip
        CentralDocPage-->>Central: sigShowRestoreTip
        Central->>RestoreTipWidget: showTip()
    end
    DocSheet-->>CentralDocPage: sigFileOpened
    CentralDocPage->>CentralDocPage: onOpened(sheet, error)
Loading

File-Level Changes

Change Details Files
Refactor tests build to automatically discover reader sources, include directories, and test sources via globbing and filtering.
  • Replace manual per-subdirectory source lists with a single recursive glob of reader sources excluding main.cpp.
  • Automatically collect all reader/* subdirectories as include paths instead of hardcoding them.
  • Use a single recursive glob for test sources and filter out non-test resource/helper directories.
  • Simplify the ALL_SOURCES aggregation to use the new globbed reader and test source lists.
tests/CMakeLists.txt
Extend the database schema and logic to persist richer document state (scroll, sidebar, catalog expansion, content hash, tab groups) and support content-based state matching and cleanup.
  • Add new columns to the operation table (sidebarWidth, scrollPosition, expandedSections, fileSize, lastModified, contentHash) and implement migration for existing installations.
  • Update readOperation/saveOperation to handle the new fields, including JSON serialization for expandedSections and bounded scaleFactor.
  • Introduce computeContentHash using SHA256 over the first 64KB and use it with fileSize/lastModified for content-based matching when file paths change.
  • Add APIs to match operations by content, clean orphan state/bookmark records for missing files, and persist/read/clear tabgroup table for window tab sessions.
  • Initialize/migrate the new tables/columns in the Database constructor and remove noisy debug logs while retaining error/info logs.
reader/app/Database.cpp
reader/app/Database.h
Persist and restore per-document UI state in DocSheet, including scroll position, sidebar width, catalog expansion, and periodic autosave, with signals for UI restore hints.
  • Extend SheetOperation to include sidebarWidth, scrollPosition, and expandedSections, and add helpers to set sidebar width and read/write scroll/catalog state.
  • On document open, restore scroll position, catalog tree expansion, and sidebar width using small delays; emit signals for "state restored" and "show restore tip".
  • Introduce a QTimer-based autosave that updates scroll/catalog state and uses cached contentHash to avoid frequent disk reads.
  • On close, save final scroll/catalog state, stop autosave, recompute content hash, and persist via the extended saveOperation API.
  • Provide utility methods to save/restore scroll position when switching tabs, and track whether state came from DB/content match.
reader/uiframe/DocSheet.cpp
reader/uiframe/DocSheet.h
Add APIs to propagate catalog expansion state through the sidebar widgets and tree view so it can be persisted and restored.
  • Implement getExpandedSections/restoreExpandedSections on CatalogTreeView using title-paths built from the item hierarchy.
  • Expose the same methods on CatalogWidget and SheetSidebar, delegating to the underlying tree widget.
  • Update SheetSidebar resizeEvent to write sidebar width into the current DocSheet operation for persistence.
reader/sidebar/CatalogTreeView.cpp
reader/sidebar/CatalogTreeView.h
reader/sidebar/CatalogWidget.cpp
reader/sidebar/CatalogWidget.h
reader/sidebar/SheetSidebar.cpp
reader/sidebar/SheetSidebar.h
Implement eye-protection reading modes (classic, green, night) with a central manager, a main-menu action, and visual integration with page rendering and browser viewport.
  • Introduce EyeProtectionManager singleton with four modes, color schemes for page/viewport/foreground, and persistence via QSettings.
  • Create EyeProtectionAction QWidgetAction that shows four RoundColorWidget choices with translated labels and binds to the manager’s mode.
  • Update SheetBrowser to listen to EyeProtectionManager mode changes and set viewport background brushes/palette accordingly.
  • Modify BrowserPage::paint to overlay the page with eye-protection colors using composition modes (Multiply for classic/green, Exclusion+dark overlay for night).
  • Extend RoundColorWidget so the selected state uses the application highlight color and unselected state draws a subtle border for better affordance.
reader/eyeprotection/EyeProtectionManager.h
reader/eyeprotection/EyeProtectionManager.cpp
reader/eyeprotection/EyeProtectionAction.h
reader/eyeprotection/EyeProtectionAction.cpp
reader/browser/SheetBrowser.cpp
reader/browser/SheetBrowser.h
reader/widgets/RoundColorWidget.cpp
reader/uiframe/TitleMenu.cpp
reader/uiframe/TitleMenu.h
reader/CMakeLists.txt
Introduce a bottom restore-tip UI component and wire it to document/tab state restoration events.
  • Add RestoreTipWidget (DWidget-based) that shows a themed bar with icon, text, "Jump to first page" and "Close" buttons; handles theme/font changes and bottom-centering logic.
  • Integrate RestoreTipWidget into Central (member, created in ctor, resized with Central, hooked to DocSheet/CentralDocPage signals).
  • Wire DocSheet and CentralDocPage to emit sigShowRestoreTip on state restoration or open events, and to jump to first page when the tip’s action is triggered.
reader/widgets/RestoreTipWidget.h
reader/widgets/RestoreTipWidget.cpp
reader/uiframe/Central.cpp
reader/uiframe/Central.h
reader/uiframe/CentralDocPage.cpp
reader/uiframe/CentralDocPage.h
Enhance session/tab restoration and close behavior to persist tab groups and restore previous session files on startup.
  • Update MainWindow::closeEvent to save the current sheet’s scroll position and persist the window’s tab group (ordered file paths and active index) via Database before closing sheets.
  • Modify main.cpp to, when no CLI documents are specified, read the last tab group for window 0 from the database, filter out non-existent files, and use the remaining as positional arguments.
  • Include Database in main.cpp and hook the new startup restoration logic into the existing argument flow.
reader/MainWindow.cpp
reader/main.cpp
Update translations and TS files for new features and adjusted locations, including eye-protection strings, restore-tip text, and batch-print CLI help.
  • Normalize TS XML header/DOCTYPES and update line-number locations for many existing messages to reflect code changes.
  • Add translations/unfinished entries for EyeProtection/EyeProtectionAction texts and RestoreTipWidget strings in multiple locales.
  • Add new main.cpp CLI help text for batch printing documents without UI across locales.
  • Adjust some SaveDialog strings to use plain double quotes instead of " where appropriate.
translations/deepin-reader_zh_CN.ts
translations/deepin-reader.ts
translations/deepin-reader_bo.ts
translations/deepin-reader_ug.ts
translations/deepin-reader_zh_HK.ts
translations/deepin-reader_zh_TW.ts
Minor copyright header updates and resource wiring.
  • Update SPDX-FileCopyrightText year ranges from 2023 to 2023–2026 in several source files.
  • Ensure new eyeprotection and restore-tip sources are compiled and included via reader/CMakeLists.txt and resources.qrc if applicable.
reader/app/Database.cpp
reader/app/Database.h
reader/sidebar/CatalogTreeView.cpp
reader/sidebar/CatalogTreeView.h
reader/sidebar/CatalogWidget.cpp
reader/sidebar/CatalogWidget.h
reader/sidebar/SheetSidebar.cpp
reader/sidebar/SheetSidebar.h
reader/uiframe/DocSheet.cpp
reader/uiframe/DocSheet.h
reader/browser/BrowserPage.cpp
reader/uiframe/Central.cpp
reader/uiframe/Central.h
reader/uiframe/CentralDocPage.cpp
reader/uiframe/CentralDocPage.h
reader/MainWindow.cpp
reader/main.cpp
reader/widgets/RoundColorWidget.cpp
reader/uiframe/TitleMenu.cpp
reader/uiframe/TitleMenu.h

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

Use GLOB_RECURSE and auto-scan reader subdirectories instead of
listing each module manually in tests/CMakeLists.txt.

将测试CMakeLists改为递归收集源文件和自动发现include路径,
新增子模块时无需再手动修改测试构建配置。

Log: 测试CMakeLists自动发现reader源文件和include路径
Influence: 新增reader子模块时测试构建自动适配,无需手动同步CMakeLists
@add-uos
add-uos force-pushed the task-394181-brighten-night-mode-text branch from 4ec9501 to 3d5223c Compare August 20, 2026 01:56
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码通过自动化目录发现和递归文件收集,大幅简化了CMake配置,提升了可维护性
逻辑正确且无安全漏洞,因递归遍历可能带来的轻微构建配置延迟扣5分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码使用了正确的CMake语法,file(GLOB_RECURSE ...) 递归收集文件,list(FILTER ... EXCLUDE REGEX ...) 排除特定目录,file(GLOB ... LIST_DIRECTORIES true ...) 结合 IS_DIRECTORY 判断子目录。逻辑严密,变量传递正确。
潜在问题:无
建议:无

  • 2.代码质量(优秀)✓

重构消除了大量重复的 file(GLOB_RECURSE ...)target_include_directories 硬编码路径,新增子模块时无需修改CMakeLists.txt,极大提高了可扩展性和可读性。注释清晰说明了改动意图。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

GLOB_RECURSE 会遍历目录树,在源文件极多的情况下可能轻微增加CMake配置阶段的时间,但对于常规项目影响可忽略不计。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码变更仅涉及构建系统的文件收集和路径配置,不涉及可执行代码逻辑、外部输入处理或权限操作,不存在安全风险。

  • 建议:无

■ 【改进建议代码示例】

# 当前代码已具备良好的结构和安全性,无需额外修复。
# 若项目规模进一步扩大,可考虑使用 CMake 的 CONFIGURE_DEPENDS 特性确保新增文件被正确追踪:

file(GLOB_RECURSE READER_ALL_SOURCES CONFIGURE_DEPENDS
    "${CMAKE_SOURCE_DIR}/reader/*.cpp"
    "${CMAKE_SOURCE_DIR}/reader/*.c"
    "${CMAKE_SOURCE_DIR}/reader/*.h"
)
list(REMOVE_ITEM READER_ALL_SOURCES "${CMAKE_SOURCE_DIR}/reader/main.cpp")

file(GLOB_READER_SUBDIRS LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/reader/*")
foreach(_dir ${READER_SUBDIRS})
    if(IS_DIRECTORY "${_dir}")
        list(APPEND READER_INCLUDE_DIRS "${_dir}")
    endif()
endforeach()
list(APPEND READER_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/reader")

file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/*.h"
)
list(FILTER TEST_SOURCES EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/at/")
list(FILTER TEST_SOURCES EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/files/")
list(FILTER TEST_SOURCES EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/include/")

set(ALL_SOURCES
    ${READER_ALL_SOURCES}
    ${TEST_SOURCES}
)

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@add-uos

add-uos commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit ece87a9 into linuxdeepin:master Aug 20, 2026
12 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