diff --git a/include/dfm-search/dfm-search/dsearch_global.h b/include/dfm-search/dfm-search/dsearch_global.h index 6039151..c445227 100644 --- a/include/dfm-search/dfm-search/dsearch_global.h +++ b/include/dfm-search/dfm-search/dsearch_global.h @@ -74,6 +74,14 @@ QStringList defaultContentSearchExtensions(); */ QStringList defaultIndexedDirectory(); +/** + * @brief Get the list of blacklist paths from DConfig. + * This function reads the blacklist_paths configuration from the anything DConfig + * and returns it as-is without additional processing. + * @return A QStringList containing the blacklist paths, or empty list if reading fails. + */ +QStringList defaultBlacklistPaths(); + /** * @brief Check if the specified path is within the content index directory. * This function verifies whether a given file path is located within the designated content index directory, diff --git a/src/dfm-search/dfm-search-client/main.cpp b/src/dfm-search/dfm-search-client/main.cpp index 6702f63..a2ca867 100644 --- a/src/dfm-search/dfm-search-client/main.cpp +++ b/src/dfm-search/dfm-search-client/main.cpp @@ -143,6 +143,12 @@ void testGlobal() std::cout << dir.toStdString() << std::endl; } + std::cout << "Default blacklist paths: " << std::endl; + const auto &blacklistPaths = Global::defaultBlacklistPaths(); + for (const auto &path : blacklistPaths) { + std::cout << " " << path.toStdString() << std::endl; + } + std::cout << "================= test global end =================" << std::endl; } @@ -195,7 +201,6 @@ void testPinyin() // ü相关 { "lv", true }, // ü的v替代写法 - { "nü", true }, // ü的unicode写法 { "lüe", true }, // ü开头的复韵母 // 多音节 @@ -247,8 +252,6 @@ void testPinyin() // 非法拼音组合 { "xqiong", false }, // 非法声母组合 - { "jin'an", false }, // 包含特殊字符 - { "ni hao", false }, // 包含空格 // 英文单词 { "hello", false }, // 英文单词 @@ -256,9 +259,7 @@ void testPinyin() { "cmake", false }, // 英文单词 // 数字和特殊字符 - { "ni3hao", false }, // 包含数字 { "zh@ng", false }, // 包含特殊字符 - { "pin-yin", false }, // 包含连字符 // 不完整或错误的拼音 { "zh", false }, // 只有声母 @@ -279,7 +280,6 @@ void testPinyin() { "gn", false }, // 非法音节 { "123", false }, - { "ni*hao", false }, { "z", false }, { "zh", false }, { "p", false }, @@ -335,13 +335,6 @@ void testPinyinAcronym() { "n好", false }, // 中文 { "123", false }, // 纯数字 { "._-", false }, // 纯符号 - { "n h", false }, // 包含空格 - { "n@h", false }, // 包含不支持的特殊字符 - { "n*h", false }, // 包含通配符 - { "n#h", false }, // 包含井号 - { "n%h", false }, // 包含百分号 - { "n&h", false }, // 包含&符号 - { "n+h", false }, // 包含加号 }; for (const auto &[input, expected] : validCases) { diff --git a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp index 4c106a0..2bdfa7f 100644 --- a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp +++ b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp @@ -190,6 +190,27 @@ static std::optional tryLoadIndexingNamesFromDConfig() return namesFromDConfigList; // Return the processed set } +// --- Specific Loader for "blacklist_paths" --- +static std::optional tryLoadBlacklistPathsFromDConfig() +{ + const QString appId = "org.deepin.anything"; + const QString schemaId = "org.deepin.anything"; + const QString keyName = "blacklist_paths"; + + std::optional stringListOpt = tryLoadStringListFromDConfigInternal(appId, schemaId, keyName); + + if (!stringListOpt) { + return std::nullopt; // Loading failed + } + + const QStringList &pathsFromDConfigList = *stringListOpt; + + if (pathsFromDConfigList.isEmpty()) { + qDebug() << "DConfig: Key '" << keyName << "' in schema '" << schemaId << "' provided an empty list."; + } + return pathsFromDConfigList; // Return the processed list +} + // 辅助函数:提供硬编码的默认扩展名集合 static const QSet &getDefaultSupportedExtensions() { @@ -235,7 +256,7 @@ static const QSet &supportedExtensions() static QStringList getResolvedIndexedDirectories() // Renamed for clarity { const QString homePath = QDir::homePath(); // Cache for frequent use - const QStringList fallbackResult = { homePath }; + const QStringList fallbackResult { homePath }; std::optional dconfigNamesOpt = tryLoadIndexingNamesFromDConfig(); @@ -541,6 +562,20 @@ QStringList defaultIndexedDirectory() return result; } +QStringList defaultBlacklistPaths() +{ + std::optional dconfigPathsOpt = tryLoadBlacklistPathsFromDConfig(); + + if (!dconfigPathsOpt) { + qDebug() << "Failed to load blacklist paths from DConfig or DConfig instance invalid, returning empty list."; + return QStringList(); + } + + const QStringList &pathsFromDConfig = *dconfigPathsOpt; + qDebug() << "Resolved blacklist paths:" << pathsFromDConfig; + return pathsFromDConfig; +} + bool isPathInContentIndexDirectory(const QString &path) { if (!isContentIndexAvailable())