From 35818d321e26daf0ea8c323a748fae81d73321a0 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Tue, 25 Apr 2023 10:14:43 +0800 Subject: [PATCH] Fix the problem that path witch is hidden dir or is not exists can be choosen as search&block dir. --- search-ukcc-plugin/search.cpp | 73 ++++++---- search-ukcc-plugin/search.h | 14 +- search-ukcc-plugin/translations/bo_CN.ts | 116 +++++++++------- search-ukcc-plugin/translations/en_US.ts | 128 ++++++++++-------- search-ukcc-plugin/translations/zh_CN.ts | 122 ++++++++--------- .../dirwatcher/search-dir.cpp | 10 +- 6 files changed, 253 insertions(+), 210 deletions(-) diff --git a/search-ukcc-plugin/search.cpp b/search-ukcc-plugin/search.cpp index 5936739..09d6019 100644 --- a/search-ukcc-plugin/search.cpp +++ b/search-ukcc-plugin/search.cpp @@ -445,25 +445,25 @@ void Search::initFileDialog() qDebug() << "Selected a folder in onBtnAddClicked(): " << selectedDir; int returnCode = setBlockDir(selectedDir, true); switch (returnCode) { - case ReturnCode::Succeed : + case ReturnCode::Successful : qDebug() << "Add blocked folder succeed! path = " << selectedDir; getBlockDirs(); break; - case ReturnCode::PathEmpty : - qWarning() << "Add blocked folder failed, choosen path is empty! path = " << selectedDir; - QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, choosen path is empty!")); - break; -// case ReturnCode::NotInHomeDir : -// qWarning() << "Add blocked folder failed, it is not in home path! path = " << selectedDir; -// QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, it is not in home path!")); -// break; - case ReturnCode::ParentExist : + case ReturnCode::Duplicated : qWarning() << "Add blocked folder failed, its parent dir is exist! path = " << selectedDir; - QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, its parent dir is exist!")); + QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, its parent dir has been added!")); + break; + case ReturnCode::NotExists : + qWarning() << "Add blocked folder failed, it's not exist! path = " << selectedDir; + QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, choosen path is not exist!")); break; case ReturnCode::HasBeenBlocked : qWarning() << "Add blocked folder failed, it has been already blocked! path = " << selectedDir; - QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, it has been already blocked!")); + QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add blocked folder failed, it has already been blocked!")); + break; + case ReturnCode::Hidden : + qWarning() << "Add blocked folder failed, it has been hidden! path = " << selectedDir; + QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, hidden path is not supported!")); break; default: break; @@ -488,24 +488,27 @@ void Search::initFileDialog() qDebug() << "Selected a folder in onAddSearchDirBtnClicked(): " << selectedDir; int returnCode = setSearchDir(selectedDir, true); switch (returnCode) { - case 0: + case ReturnCode::Successful: qDebug() << "Add search folder succeed! path = " << selectedDir; break; - case 1: + case ReturnCode::Duplicated: QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path or its parent dir has been added!")); break; - case 2: + case ReturnCode::UnderBlackList: QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path is not supported currently!")); break; - case 3: + case ReturnCode::RepeatMount1: QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added!")); break; - case 4: + case ReturnCode::RepeatMount2: QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, another path which is in the same device has been added!")); break; - case 5: + case ReturnCode::NotExists: QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path is not exists!")); break; + case ReturnCode::Hidden : + QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, hidden path is not supported!")); + break; default: break; } @@ -542,15 +545,23 @@ void Search::getBlockDirs() */ int Search::setBlockDir(const QString &dirPath, const bool &is_add) { - if (!is_add) { - if (dirPath.isEmpty()) { - return ReturnCode::PathEmpty; + if (!QFile::exists(dirPath)) { + return ReturnCode::NotExists; + } + + QStringList pathSections = dirPath.split("/"); + for (const QString §ion : pathSections) { + if (section.startsWith(".")) { + return ReturnCode::Hidden; } + } + + if (!is_add) { //删除黑名单目录 m_dirSettings->remove(dirPath); m_dirSettings->sync(); removeBlockDirFromList(dirPath); - return ReturnCode::Succeed; + return ReturnCode::Successful; } QStringList oldBlockList = m_blockDirs; @@ -561,14 +572,13 @@ int Search::setBlockDir(const QString &dirPath, const bool &is_add) } } - for (QString dir : m_blockDirs) { if (dirPath == dir) { return ReturnCode::HasBeenBlocked; } if (dirPath.startsWith(dir + "/") || dir == "/") { - return ReturnCode::ParentExist; + return ReturnCode::Duplicated; } //有它的子文件夹已被添加,删除这些子文件夹 @@ -577,10 +587,10 @@ int Search::setBlockDir(const QString &dirPath, const bool &is_add) removeBlockDirFromList(dir); } } - m_dirSettings->setValue(dirPath.right(dirPath.length() - 1), "0"); + m_dirSettings->setValue(dirPath, "0"); m_dirSettings->sync(); appendBlockDirToList(dirPath); - return ReturnCode::Succeed; + return ReturnCode::Successful; } /** @@ -615,7 +625,14 @@ void Search::initSearchDirs() int Search::setSearchDir(const QString &dirPath, const bool isAdd) { if (!m_setSearchDirInterface->isValid()) { - return -1; + return ReturnCode::DirWatcherError; + } + + QStringList pathSections = dirPath.split("/"); + for (const QString §ion : pathSections) { + if (section.startsWith(".")) { + return ReturnCode::Hidden; + } } if (isAdd) { @@ -653,7 +670,7 @@ int Search::setSearchDir(const QString &dirPath, const bool isAdd) } } - return 0; + return ReturnCode::Successful; } void Search::appendSearchDirToList(const QString &path) diff --git a/search-ukcc-plugin/search.h b/search-ukcc-plugin/search.h index 75aadca..68dc0de 100644 --- a/search-ukcc-plugin/search.h +++ b/search-ukcc-plugin/search.h @@ -55,11 +55,15 @@ #define CONFIG_FILE "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf" enum ReturnCode { - Succeed, - PathEmpty, - NotInHomeDir, - ParentExist, - HasBeenBlocked + DirWatcherError = -1, + Successful, + Duplicated, + UnderBlackList, + RepeatMount1, + RepeatMount2, + NotExists, + HasBeenBlocked, + Hidden }; class Search : public QObject, CommonInterface diff --git a/search-ukcc-plugin/translations/bo_CN.ts b/search-ukcc-plugin/translations/bo_CN.ts index 65199f2..7220b0b 100644 --- a/search-ukcc-plugin/translations/bo_CN.ts +++ b/search-ukcc-plugin/translations/bo_CN.ts @@ -4,52 +4,52 @@ Search - - + + Search འཚོལ་ཞིབ། /Search/Search - + Create index གསར་འཛུགས་འཚོལ་ཞིབ་བྱེད་པར་ཁྲིད་སྟོན། /Search/Create index - + Creating index can help you getting results quickly. སྟོན་གྲངས་གསར་སྐྲུན་བྱས་ན་ཁྱོད་ལ་མགྱོགས་མྱུར་ངང་གྲུབ་འབྲས་ཐོབ་པར་རོགས་རམ་བྱེད་ཐུབ། - + Default web searching engine ཁོག་གི་དྲ་ཤོག་གཏོད་པ་བཤེར་འཚོལ་རིགས་དབྱིབས། /Search/Default web searching engine - + baidu པའེ་ཏུའུ། - + sougou སོའོ་གོའུ། - + 360 360 - + Block Folders ལྐོག་བཀོད་མིང་ཐོ། /Search/Block Folders - + Following folders will not be searched. You can set it by adding and removing folders. གཤམ་གྱི་ཡིག་སྣོད་འཚོལ་བཤེར་མི་བྱེད། ཡིག་སྣོད་གསར་སྣོན་དང་གསུབ་འཕྲི་བྱས་ཚེ་ཡིག་ཆའི་དཀར་ཆག་སྒྲིག་འགོད་བྱ་ཐུབ། @@ -58,147 +58,159 @@ བསལ་འདེམས་ཀྱི་དཀར་ཆག། - - + + delete བསུབ་པ། - - + + Directories དཀར་ཆག - + File Content Search /Search/File Content Search - + show more results that match the keyword - + Fuzzy Search - + Precise Search - + show the results that exactly match the keyword - + Search Folders /Search/Search Folders - + Following folders will be searched. You can set it by adding and removing folders. - + select blocked folder བཀག་སྡོམ་བྱས་པའི་ཡིག་སྣོད་གདམ་གསེས - - + + Select བདམས་ཐོན་བྱུང་བ། - - + + Position: གོ་གནས་ནི། - - + + FileName: ཡིག་ཆའི་མིང་ནི། - - + + FileType: ཡིག་ཆའི་རིགས་དབྱིབས་ནི། - - + + Cancel ཕྱིར་འཐེན། - - - - - - - - + + + + + + + + + + Warning ཐ་ཚིག་སྒྲོག་པ། - + + + Add search folder failed, hidden path is not supported! + + + Add blocked folder failed, choosen path is empty! - སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་ཐབས་ལམ་སྟོང་བ་རེད། + སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་ཐབས་ལམ་སྟོང་བ་རེད། Add blocked folder failed, it is not in home path! སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་མི་ཁྱིམ་དཀར་ཆག་འོག། - - Add blocked folder failed, its parent dir is exist! + + Add blocked folder failed, its parent dir has been added! སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་ནི་ལྐོག་བཀོད་མིང་ཐོ་འི་ཁྲོད་ཀྱི་དཀར་ཆག་འོག - - Add blocked folder failed, it has been already blocked! + + Add blocked folder failed, choosen path is not exist! + + + + + Add blocked folder failed, it has already been blocked! སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་ནི་ལྐོག་བཀོད་མིང་ཐོ་འི་ཁྲོད་ཀྱི་དཀར་ཆག་འོག - + select search folder - + Add search folder failed, choosen path is not supported currently! - + Add search folder failed, another path which is in the same device has been added! - + Add search folder failed, choosen path or its parent dir has been added! - + Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added! - + Add search folder failed, choosen path is not exists! diff --git a/search-ukcc-plugin/translations/en_US.ts b/search-ukcc-plugin/translations/en_US.ts index c85460d..70a61ff 100644 --- a/search-ukcc-plugin/translations/en_US.ts +++ b/search-ukcc-plugin/translations/en_US.ts @@ -4,193 +4,201 @@ Search - - + + Search Search /Search/Search - + Default web searching engine Default web searching engine /Search/Default web searching engine - + baidu - + sougou - + 360 - + Create index Create index /Search/Create index - + Creating index can help you getting results quickly. - + File Content Search File Content Search /Search/File Content Search - + Precise Search - + show the results that exactly match the keyword - + Fuzzy Search - + show more results that match the keyword - + Search Folders Search Folders /Search/Search Folders - + Following folders will be searched. You can set it by adding and removing folders. - + Block Folders Block Folders /Search/Block Folders - + Following folders will not be searched. You can set it by adding and removing folders. - - + + Directories - + select blocked folder - - + + Select - - + + Position: - - + + FileName: - - + + FileType: - - + + Cancel - - - - - - - - + + + + + + + + + + Warning - - Add blocked folder failed, choosen path is empty! + + Add blocked folder failed, its parent dir has been added! - - Add blocked folder failed, its parent dir is exist! - + + Add blocked folder failed, choosen path is not exist! + - - Add blocked folder failed, it has been already blocked! - - - - - select search folder - - - - - Add search folder failed, choosen path or its parent dir has been added! + + Add blocked folder failed, it has already been blocked! + select search folder + + + + + Add search folder failed, choosen path or its parent dir has been added! + + + + Add search folder failed, choosen path is not supported currently! - + Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added! - + Add search folder failed, another path which is in the same device has been added! - + Add search folder failed, choosen path is not exists! - - + + + Add search folder failed, hidden path is not supported! + + + + + delete diff --git a/search-ukcc-plugin/translations/zh_CN.ts b/search-ukcc-plugin/translations/zh_CN.ts index c8c403c..cf480f2 100644 --- a/search-ukcc-plugin/translations/zh_CN.ts +++ b/search-ukcc-plugin/translations/zh_CN.ts @@ -4,52 +4,52 @@ Search - - + + Search 全局搜索 /Search/Search - + Create index 创建索引 /Search/Create index - + Creating index can help you getting results quickly. 开启之后可以快速获取搜索结果 - + Default web searching engine 默认互联网搜索引擎 /Search/Default web searching engine - + baidu 百度 - + sougou 搜狗 - + 360 360 - + Block Folders 排除的文件夹 /Search/Block Folders - + Following folders will not be searched. You can set it by adding and removing folders. 搜索将不查看以下文件夹,通过添加和删除可以设置排除的文件夹位置 @@ -58,151 +58,151 @@ 添加 - - + + delete 删除 - - + + Directories 文件夹 - + File Content Search 搜索文本内容 /Search/File Content Search - precise Search - 精确搜索 - - - + show more results that match the keyword 显示更多与输入内容匹配的搜索结果 - + Fuzzy Search 模糊搜索 - + Precise Search 精确搜索 - + show the results that exactly match the keyword 仅显示与输入内容完全一致的搜索结果 - + Search Folders 搜索范围 /Search/Search Folders - + Following folders will be searched. You can set it by adding and removing folders. 以下文件的内容将出现在全局搜索的结果中 - + select blocked folder 选择排除的文件夹 - - + + Select 选择 - - + + Position: 位置 - - + + FileName: 文件名 - - + + FileType: 类型 - - + + Cancel 取消 - - - - - - - - + + + + + + + + + + Warning 警告 - - Add blocked folder failed, choosen path is empty! - 添加失败,选择的路径为空! + + + Add search folder failed, hidden path is not supported! + 添加失败,不支持隐藏目录! - Add blocked folder failed, it is not in home path! - 添加失败,添加的路径不在家目录下! - - - - Add blocked folder failed, its parent dir is exist! + + Add blocked folder failed, its parent dir has been added! 添加失败,父目录已被添加! - - Add blocked folder failed, it has been already blocked! + + Add blocked folder failed, choosen path is not exist! + 添加失败,要添加的路径不存在! + + + + Add blocked folder failed, it has already been blocked! 添加失败,这个文件夹已经被添加过了! - + select search folder 选择要搜索的文件夹 - + Add search folder failed, choosen path is not supported currently! 添加失败!暂不支持该目录! - + Add search folder failed, another path which is in the same device has been added! 添加失败!文件夹位于重复挂载设备下,相同内容的文件夹已被添加! - + Add search folder failed, choosen path or its parent dir has been added! 添加失败!该目录或其父目录已被添加! - + Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added! 添加失败!文件夹位于重复挂载设备下,且该设备另一个挂载点的文件夹已被添加! - + Add search folder failed, choosen path is not exists! 添加失败!要添加的路径不存在! diff --git a/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp b/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp index 6dde2a8..bcaa323 100644 --- a/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp +++ b/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp @@ -134,10 +134,12 @@ void SearchDir::handleBlackListGenerate() { QStringList searchDirs = Config::self()->searchDirs(); - //目录已被索引 - if (searchDirs.contains(m_path)) { - m_error = Duplicated; - return; + //目录已被索引(根目录被添加过直接返回) + for (const QString searchDir : searchDirs) { + if (searchDir == m_path || searchDir == "/") { + m_error = Duplicated; + return; + } } //根目录特殊处理