Add a switch for fuzzy search.

Add the logic to custom the search scope.

Modify the ui of search plugin of ukcc.
This commit is contained in:
JunjieBai 2022-12-07 14:04:21 +08:00 committed by iaom
parent 567b72e7dc
commit 918fd9846c
12 changed files with 742 additions and 158 deletions

View File

@ -494,7 +494,7 @@ DirectSearch::DirectSearch(QString keyword, DataQueue<SearchPluginIface::ResultI
void DirectSearch::run() { void DirectSearch::run() {
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs(); QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
QStringList searchPath = DirWatcher::getDirWatcher()->searchableDirForSearchApplication(); QStringList searchPath = DirWatcher::getDirWatcher()->currentIndexableDir();
QQueue<QString> bfs; QQueue<QString> bfs;
for (const QString &path : searchPath) { for (const QString &path : searchPath) {
if (blockList.contains(path)) { if (blockList.contains(path)) {

View File

@ -1,4 +1,4 @@
QT += widgets QT += widgets dbus
TEMPLATE = lib TEMPLATE = lib
TARGET = $$qtLibraryTarget(search-ukcc-plugin) TARGET = $$qtLibraryTarget(search-ukcc-plugin)

View File

@ -13,6 +13,18 @@ Search::Search()
m_plugin_name = tr("Search"); m_plugin_name = tr("Search");
m_plugin_type = SEARCH_F; m_plugin_type = SEARCH_F;
m_interface = new QDBusInterface("com.ukui.search.fileindex.service",
"/org/ukui/search/privateDirWatcher",
"org.ukui.search.fileindex",
QDBusConnection::sessionBus(),
this);
m_setSearchDirInterface = new QDBusInterface("com.ukui.search.fileindex.service",
"/org/ukui/search/fileindex",
"org.ukui.search.fileindex",
QDBusConnection::sessionBus(),
this);
m_dirSettings = new QSettings(QDir::homePath() + CONFIG_FILE, QSettings::NativeFormat, this); m_dirSettings = new QSettings(QDir::homePath() + CONFIG_FILE, QSettings::NativeFormat, this);
m_dirSettings->setIniCodec(QTextCodec::codecForName("UTF-8")); m_dirSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
@ -37,8 +49,11 @@ int Search::pluginTypes()
QWidget *Search::pluginUi() QWidget *Search::pluginUi()
{ {
initUi(); initUi();
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddFolderClicked); initFileDialog();
initSearchDirs();
initBlockDirsList(); initBlockDirsList();
connect(m_addSearchDirBtn, &QPushButton::clicked, this, &Search::onAddSearchDirBtnClicked);
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddBlockFolderClicked);
if (m_gsettings) { if (m_gsettings) {
//按钮状态初始化 //按钮状态初始化
@ -46,9 +61,13 @@ QWidget *Search::pluginUi()
//当前是否使用索引搜索/暴力搜索 //当前是否使用索引搜索/暴力搜索
bool is_index_search_on = m_gsettings->get(SEARCH_METHOD_KEY).toBool(); bool is_index_search_on = m_gsettings->get(SEARCH_METHOD_KEY).toBool();
m_searchMethodBtn->setChecked(is_index_search_on); m_searchMethodBtn->setChecked(is_index_search_on);
if (is_index_search_on) {
m_indexSetFrame->show();
}
} else { } else {
m_searchMethodBtn->setEnabled(false); m_searchMethodBtn->setEnabled(false);
} }
if (m_gsettings->keys().contains(WEB_ENGINE_KEY)) { if (m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
//当前网页搜索的搜索引擎 //当前网页搜索的搜索引擎
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString(); QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
@ -56,6 +75,19 @@ QWidget *Search::pluginUi()
} else { } else {
m_webEngineFrame->mCombox->setEnabled(false); m_webEngineFrame->mCombox->setEnabled(false);
} }
if (m_gsettings->keys().contains(CONTENT_SEARCH_KEY)) {
//是否为模糊搜索
bool isFuzzy = m_gsettings->get(CONTENT_SEARCH_KEY).toBool();
if (isFuzzy) {
m_fuzzyBtn->setChecked(true);
} else {
m_preciseBtn->setChecked(true);
}
} else {
m_fuzzyBtn->setEnabled(false);
m_preciseBtn->setEnabled(false);
}
//监听gsettings值改变更新控制面板UI //监听gsettings值改变更新控制面板UI
connect(m_gsettings, &QGSettings::changed, this, [ = ](const QString &key) { connect(m_gsettings, &QGSettings::changed, this, [ = ](const QString &key) {
if (key == SEARCH_METHOD_KEY) { if (key == SEARCH_METHOD_KEY) {
@ -68,12 +100,31 @@ QWidget *Search::pluginUi()
m_webEngineFrame->mCombox->blockSignals(true); m_webEngineFrame->mCombox->blockSignals(true);
m_webEngineFrame->mCombox->setCurrentIndex(m_webEngineFrame->mCombox->findData(engine)); m_webEngineFrame->mCombox->setCurrentIndex(m_webEngineFrame->mCombox->findData(engine));
m_webEngineFrame->mCombox->blockSignals(false); m_webEngineFrame->mCombox->blockSignals(false);
} else if (key == CONTENT_SEARCH_KEY) {
bool isFuzzy = m_gsettings->get(CONTENT_SEARCH_KEY).toBool();
if (isFuzzy) {
m_fuzzyBtn->setChecked(true);
} else {
m_preciseBtn->setChecked(true);
}
} }
}); });
connect(m_searchMethodBtn, &kdk::KSwitchButton::stateChanged, this, [ = ](bool checked) { connect(m_searchMethodBtn, &kdk::KSwitchButton::stateChanged, this, [ = ](bool checked) {
if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) { if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
m_gsettings->set(SEARCH_METHOD_KEY, checked); m_gsettings->set(SEARCH_METHOD_KEY, checked);
} }
if (checked) {
m_indexSetFrame->show();
} else {
m_indexSetFrame->hide();
}
});
connect(m_indexMethodBtnGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),[ = ](int id, bool checked) {
if (id == -3) {//fuzzyBtn's id
if (m_gsettings && m_gsettings->keys().contains(CONTENT_SEARCH_KEY)) {
m_gsettings->set(CONTENT_SEARCH_KEY, checked);
}
}
}); });
connect(m_webEngineFrame->mCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) { connect(m_webEngineFrame->mCombox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) { if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
@ -124,17 +175,30 @@ void Search::initUi()
m_mainLyt = new QVBoxLayout(m_pluginWidget); m_mainLyt = new QVBoxLayout(m_pluginWidget);
m_pluginWidget->setLayout(m_mainLyt); m_pluginWidget->setLayout(m_mainLyt);
m_titleLabel = new TitleLabel(m_setFrame); m_titleLabel = new TitleLabel(m_pluginWidget);
m_titleLabel->setText(tr("Search")); m_titleLabel->setText(tr("Search"));
m_mainLyt->addWidget(m_titleLabel); m_mainLyt->addWidget(m_titleLabel);
//设置搜索模式部分的ui //设置网页搜索引擎部分的ui
//~ contents_path /Search/Default web searching engine
m_webEngineFrame = new ComboxFrame(tr("Default web searching engine"), m_pluginWidget);
m_webEngineFrame->setContentsMargins(8, 0, 8, 0);// ComboxFrame右侧自带8的边距左右边距各是16所以分别设为8
m_webEngineFrame->setFixedHeight(56);
m_webEngineFrame->setMinimumWidth(550);
m_webEngineFrame->mCombox->insertItem(0, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/baidu.svg"), tr("baidu"), "baidu");
m_webEngineFrame->mCombox->insertItem(1, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/sougou.svg"), tr("sougou"), "sougou");
m_webEngineFrame->mCombox->insertItem(2, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/360.svg"), tr("360"), "360");
m_mainLyt->addWidget(m_webEngineFrame);
//设置索引部分的ui
m_setFrame = new QFrame(m_pluginWidget); m_setFrame = new QFrame(m_pluginWidget);
m_setFrame->setFrameShape(QFrame::Shape::Box); m_setFrame->setFrameShape(QFrame::Shape::Box);
m_setFrameLyt = new QVBoxLayout(m_setFrame); m_setFrameLyt = new QVBoxLayout(m_setFrame);
m_setFrameLyt->setContentsMargins(0, 0, 0, 0); m_setFrameLyt->setContentsMargins(0, 0, 0, 0);
m_setFrameLyt->setSpacing(0); m_setFrameLyt->setSpacing(0);
//~ contents_path /Search/Create index
//索引开关UI
m_searchMethodFrame = new QFrame(m_setFrame); m_searchMethodFrame = new QFrame(m_setFrame);
m_searchMethodFrame->setMinimumWidth(550); m_searchMethodFrame->setMinimumWidth(550);
m_searchMethodLyt = new QHBoxLayout(m_searchMethodFrame); m_searchMethodLyt = new QHBoxLayout(m_searchMethodFrame);
@ -148,7 +212,6 @@ void Search::initUi()
m_descLabel1 = new QLabel(m_descFrame); m_descLabel1 = new QLabel(m_descFrame);
m_descLabel2 = new QLabel(m_descFrame); m_descLabel2 = new QLabel(m_descFrame);
//~ contents_path /Search/Create index
m_descLabel1->setText(tr("Create index")); m_descLabel1->setText(tr("Create index"));
m_descLabel2->setText(tr("Creating index can help you getting results quickly.")); m_descLabel2->setText(tr("Creating index can help you getting results quickly."));
m_descLabel2->setEnabled(false); m_descLabel2->setEnabled(false);
@ -158,27 +221,100 @@ void Search::initUi()
m_searchMethodLyt->addWidget(m_descFrame); m_searchMethodLyt->addWidget(m_descFrame);
m_searchMethodLyt->addStretch(); m_searchMethodLyt->addStretch();
m_searchMethodLyt->addWidget(m_searchMethodBtn); m_searchMethodLyt->addWidget(m_searchMethodBtn);
m_setFrameLyt->addWidget(m_searchMethodFrame);
QFrame *line = new QFrame(m_setFrame); m_indexSetFrame = new QFrame(m_setFrame);
m_indexSetLyt = new QVBoxLayout(m_indexSetFrame);
m_indexSetLyt->setContentsMargins(0, 0, 0, 0);
m_indexSetLyt->setSpacing(0);
//分隔线
QFrame *line = new QFrame(m_indexSetFrame);
line->setFixedHeight(1); line->setFixedHeight(1);
line->setLineWidth(0); line->setLineWidth(0);
line->setFrameShape(QFrame::HLine); line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken); line->setFrameShadow(QFrame::Sunken);
m_setFrameLyt->addWidget(line);
//设置网页搜索引擎部分的ui //设置索引模式的ui
//~ contents_path /Search/Default web searching engine m_indexMethodFrame = new QFrame(m_indexSetFrame);
m_webEngineFrame = new ComboxFrame(tr("Default web searching engine"), m_searchMethodFrame); m_indexMethodLyt = new QVBoxLayout(m_indexMethodFrame);
m_webEngineFrame->setContentsMargins(8, 0, 8, 0);// ComboxFrame右侧自带8的边距左右边距各是16所以分别设为8 m_indexMethodLyt->setContentsMargins(8, 16, 0, 0);//radiobutton本身左边有8间距
m_webEngineFrame->setFixedHeight(56); m_indexMethodFrame->setLayout(m_indexMethodLyt);
m_webEngineFrame->setMinimumWidth(550);
m_webEngineFrame->mCombox->insertItem(0, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/baidu.svg"), tr("baidu"), "baidu"); m_indexMethodDescLabel = new QLabel(m_indexMethodFrame);
m_webEngineFrame->mCombox->insertItem(1, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/sougou.svg"), tr("sougou"), "sougou"); m_indexMethodDescLabel->setContentsMargins(8, 0, 0, 0);
m_webEngineFrame->mCombox->insertItem(2, QIcon("/usr/share/ukui-search/search-ukcc-plugin/image/360.svg"), tr("360"), "360"); m_indexMethodDescLabel->setText(tr("File Content Search"));
m_setFrameLyt->addWidget(m_webEngineFrame);
m_preciseBtnFrame = new QFrame(m_indexMethodFrame);
m_preciseBtnLyt = new QHBoxLayout(m_preciseBtnFrame);
m_preciseBtnFrame->setLayout(m_preciseBtnLyt);
m_preciseBtn = new QRadioButton(tr("precise Search"), m_indexMethodFrame);
m_preciseDescLabel = new QLabel(m_indexMethodFrame);
m_preciseDescLabel->setText(tr("show the results that exactly match the keyword"));
m_preciseDescLabel->setEnabled(false);
m_preciseBtnLyt->addWidget(m_preciseBtn);
m_preciseBtnLyt->addWidget(m_preciseDescLabel);
m_preciseBtnLyt->addStretch();
m_fuzzyBtnFrame = new QFrame(m_indexMethodFrame);
m_fuzzyBtnLyt = new QHBoxLayout(m_fuzzyBtnFrame);
m_fuzzyBtnFrame->setLayout(m_fuzzyBtnLyt);
m_fuzzyBtn = new QRadioButton(tr("Fuzzy Search"), m_indexMethodFrame);
m_fuzzyDescLabel = new QLabel(m_indexMethodFrame);
m_fuzzyDescLabel->setText(tr("show more results that match the keyword"));
m_fuzzyDescLabel->setEnabled(false);
m_fuzzyBtnLyt->addWidget(m_fuzzyBtn);
m_fuzzyBtnLyt->addWidget(m_fuzzyDescLabel);
m_fuzzyBtnLyt->addStretch();
m_indexMethodBtnGroup = new QButtonGroup(m_indexSetFrame);
m_indexMethodBtnGroup->addButton(m_preciseBtn);
m_indexMethodBtnGroup->addButton(m_fuzzyBtn);
m_indexMethodBtnGroup->setExclusive(true);
m_indexMethodLyt->addWidget(m_indexMethodDescLabel);
m_indexMethodLyt->addWidget(m_preciseBtnFrame);
m_indexMethodLyt->addWidget(m_fuzzyBtnFrame);
m_indexSetLyt->addWidget(line);
m_indexSetLyt->addWidget(m_indexMethodFrame);
m_setFrameLyt->addWidget(m_searchMethodFrame);
m_setFrameLyt->addWidget(m_indexSetFrame);
m_indexSetFrame->hide();//默认隐藏,根据是否开索引来初始化
m_mainLyt->addWidget(m_setFrame); m_mainLyt->addWidget(m_setFrame);
//添加搜索目录部分ui
m_searchDirTitleLabel = new TitleLabel(m_pluginWidget);
m_searchDirTitleLabel->setText(tr("Search Folders"));
m_searchDirDescLabel = new QLabel(m_pluginWidget);
m_searchDirDescLabel->setContentsMargins(16, 0, 0, 0); //TitleLabel自带16边距,QLabel需要自己设
m_searchDirDescLabel->setEnabled(false);
m_searchDirDescLabel->setWordWrap(true);
m_searchDirDescLabel->setText(tr("Following folders will be searched. You can set it by adding and removing folders."));
m_searchDirsFrame = new QFrame(m_pluginWidget);
m_searchDirsFrame->setFrameShape(QFrame::Shape::Box);
m_searchDirLyt = new QVBoxLayout(m_searchDirsFrame);
m_searchDirsFrame->setLayout(m_searchDirLyt);
m_searchDirLyt->setContentsMargins(0, 0, 0, 0);
m_searchDirLyt->setSpacing(2);
m_searchDirLyt->setDirection(QBoxLayout::BottomToTop);
m_addSearchDirFrame = new QFrame(m_searchDirsFrame);
m_addSearchDirFrame->setFrameShape(QFrame::Shape::NoFrame);
m_addSearchDirFrame->setFixedHeight(60);
m_addSearchDirBtn = new AddBtn(m_addSearchDirFrame);
m_searchDirLyt->addWidget(m_addSearchDirBtn);
m_mainLyt->addSpacing(32);
m_mainLyt->addWidget(m_searchDirTitleLabel);
m_mainLyt->addWidget(m_searchDirDescLabel);
m_mainLyt->addWidget(m_searchDirsFrame);
//设置黑名单文件夹部分的ui //设置黑名单文件夹部分的ui
m_blockDirTitleLabel = new TitleLabel(m_pluginWidget); m_blockDirTitleLabel = new TitleLabel(m_pluginWidget);
@ -250,6 +386,97 @@ void Search::initUi()
m_mainLyt->setContentsMargins(0, 0, 0, 0); m_mainLyt->setContentsMargins(0, 0, 0, 0);
} }
void Search::initFileDialog()
{
//添加黑名单对话框
m_blockDirDialog = new QFileDialog(m_pluginWidget);
// fileDialog->setFileMode(QFileDialog::Directory); //允许查看文件和文件夹,但只允许选择文件夹
m_blockDirDialog->setFileMode(QFileDialog::DirectoryOnly); //只允许查看文件夹
// fileDialog->setViewMode(QFileDialog::Detail);
m_blockDirDialog->setDirectory(QDir::homePath());
m_blockDirDialog->setNameFilter(tr("Directories"));
m_blockDirDialog->setWindowTitle(tr("select blocked folder"));
m_blockDirDialog->setLabelText(QFileDialog::Accept, tr("Select"));
m_blockDirDialog->setLabelText(QFileDialog::LookIn, tr("Position: "));
m_blockDirDialog->setLabelText(QFileDialog::FileName, tr("FileName: "));
m_blockDirDialog->setLabelText(QFileDialog::FileType, tr("FileType: "));
m_blockDirDialog->setLabelText(QFileDialog::Reject, tr("Cancel"));
connect(m_blockDirDialog, &QFileDialog::finished, [ = ] (int result) {
qWarning() << "=======" << result;
if (result == QDialog::Accepted) {
QString selectedDir = m_blockDirDialog->selectedFiles().first();
qDebug() << "Selected a folder in onBtnAddClicked(): " << selectedDir;
int returnCode = setBlockDir(selectedDir, true);
switch (returnCode) {
case ReturnCode::Succeed :
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 :
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!"));
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!"));
break;
default:
break;
}
}
});
//添加搜索目录对话框
m_searchDirDialog = new QFileDialog(m_pluginWidget);
m_searchDirDialog->setFileMode(QFileDialog::DirectoryOnly); //只允许查看文件夹
m_searchDirDialog->setDirectory(QDir::homePath());
m_searchDirDialog->setNameFilter(tr("Directories"));
m_searchDirDialog->setWindowTitle(tr("select search folder"));
m_searchDirDialog->setLabelText(QFileDialog::Accept, tr("Select"));
m_searchDirDialog->setLabelText(QFileDialog::LookIn, tr("Position: "));
m_searchDirDialog->setLabelText(QFileDialog::FileName, tr("FileName: "));
m_searchDirDialog->setLabelText(QFileDialog::FileType, tr("FileType: "));
m_searchDirDialog->setLabelText(QFileDialog::Reject, tr("Cancel"));
connect(m_searchDirDialog, &QFileDialog::finished, this, [ = ] (int result) {
if (result == QDialog::Accepted) {
QString selectedDir = m_searchDirDialog->selectedFiles().first();
qDebug() << "Selected a folder in onAddSearchDirBtnClicked(): " << selectedDir;
int returnCode = setSearchDir(selectedDir, true);
switch (returnCode) {
case 1:
qDebug() << "Add search folder succeed! path = " << selectedDir;
break;
case -1:
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path or its parent dir has been added!"));
break;
case -2:
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path is not supported currently!"));
break;
case -3:
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:
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:
QMessageBox::warning(m_pluginWidget, tr("Warning"), tr("Add search folder failed, choosen path is not exists!"));
break;
default:
break;
}
}
});
}
/** /**
* @brief Search::getBlockDirs * @brief Search::getBlockDirs
*/ */
@ -277,9 +504,9 @@ int Search::setBlockDir(const QString &dirPath, const bool &is_add)
removeBlockDirFromList(dirPath); removeBlockDirFromList(dirPath);
return ReturnCode::Succeed; return ReturnCode::Succeed;
} }
if (!dirPath.startsWith(QDir::homePath())) { // if (!dirPath.startsWith(QDir::homePath())) {
return ReturnCode::NotInHomeDir; // return ReturnCode::NotInHomeDir;
} // }
QString pathKey = dirPath.right(dirPath.length() - 1); QString pathKey = dirPath.right(dirPath.length() - 1);
@ -311,18 +538,148 @@ void Search::initBlockDirsList()
getBlockDirs(); getBlockDirs();
for (QString path: m_blockDirs) { for (QString path: m_blockDirs) {
QString wholePath = QString("/%1").arg(path); QString wholePath = QString("/%1").arg(path);
if (QFileInfo(wholePath).isDir() && path.startsWith("home")) { if (QFileInfo(wholePath).isDir() /*&& path.startsWith("home")*/) {
appendBlockDirToList(wholePath); appendBlockDirToList(wholePath);
} }
} }
} }
void Search::initSearchDirs()
{
if (m_interface->isValid()) {
QDBusReply<QStringList> reply = m_interface->call("currentIndexableDir");
if (reply.isValid()) {
for (const QString &path : reply.value()) {
appendSearchDirToList(path);
}
} else {
qCritical() << "Fail to call currentIndexableDir.";
}
} else {
qCritical() << "fileindex dbus error:" << m_interface->lastError();
}
}
int Search::setSearchDir(const QString &dirPath, const bool isAdd)
{
if (!m_setSearchDirInterface->isValid()) {
return 0;
}
if (isAdd) {
QDBusReply<QStringList> indexDirsRpl = m_interface->call("currentIndexableDir");
QStringList indexDirs;
if (indexDirsRpl.isValid()) {
indexDirs = indexDirsRpl.value();
}
QDBusReply<int> appendIndexRpl = m_setSearchDirInterface->call("appendIndexableListItem", dirPath);
if (appendIndexRpl.isValid()) {
if (appendIndexRpl.value() == 1) {
this->appendSearchDirToList(dirPath);
if (!indexDirs.isEmpty()) {
indexDirsRpl = m_interface->call("currentIndexableDir");
if (indexDirsRpl.isValid() && (indexDirsRpl.value().size() < indexDirs.size() + 1)) {
QStringList dirsAfterAppend = indexDirsRpl.value();
for (const QString& dir : indexDirs) {
if (!dirsAfterAppend.contains(dir)) {
this->removeSearchDirFromList(dir);
}
}
}
}
}
return appendIndexRpl.value();
}
} else {
QDBusReply<bool> reply = m_setSearchDirInterface->call("removeIndexableListItem", dirPath);
if (reply.isValid()) {
if (reply.value()) {
this->removeSearchDirFromList(dirPath);
}
return reply.value();
}
}
return 0;
}
void Search::appendSearchDirToList(const QString &path)
{
HoverWidget * dirWidget = new HoverWidget(path, m_searchDirsFrame);
dirWidget->setObjectName(path);
dirWidget->setMinimumWidth(550);
QHBoxLayout * dirWidgetLyt = new QHBoxLayout(dirWidget);
dirWidgetLyt->setSpacing(8);
dirWidgetLyt->setContentsMargins(0, 0, 0, 0);
dirWidget->setLayout(dirWidgetLyt);
QFrame * dirFrame = new QFrame(dirWidget);
dirFrame->setFrameShape(QFrame::Shape::Box);
dirFrame->setFixedHeight(50);
QHBoxLayout * dirFrameLayout = new QHBoxLayout(dirFrame);
dirFrameLayout->setSpacing(16);
dirFrameLayout->setContentsMargins(16, 0, 16, 0);
QLabel * iconLabel = new QLabel(dirFrame);
QLabel * pathLabel = new QLabel(dirFrame);
dirFrameLayout->addWidget(iconLabel);
iconLabel->setPixmap(QIcon::fromTheme("inode-directory").pixmap(QSize(24, 24)));
pathLabel->setText(path);
dirFrameLayout->addWidget(pathLabel);
dirFrameLayout->addStretch();
QPushButton * delBtn = new QPushButton(dirFrame);
delBtn->setIcon(QIcon::fromTheme("edit-delete-symbolic"));
delBtn->setProperty("useButtonPalette", true);
delBtn->setFixedSize(30, 30);
delBtn->setToolTip(tr("delete"));
delBtn->setFlat(true);
delBtn->hide();
dirFrameLayout->addWidget(delBtn);
dirWidgetLyt->addWidget(dirFrame);
QFrame *line = new QFrame(dirWidget);
line->setObjectName(path);
line->setFixedHeight(1);
line->setLineWidth(0);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
m_searchDirLyt->addWidget(line);
m_searchDirLyt->addWidget(dirWidget);
connect(delBtn, &QPushButton::clicked, this, [ = ]() {
setSearchDir(path, false);
});
connect(dirWidget, &HoverWidget::enterWidget, this, [ = ]() {
delBtn->show();
});
connect(dirWidget, &HoverWidget::leaveWidget, this, [ = ]() {
delBtn->hide();
});
}
void Search::removeSearchDirFromList(const QString &path)
{
HoverWidget *delDirWidget = m_searchDirsFrame->findChild<HoverWidget *>(path);
if (delDirWidget) {
m_searchDirLyt->removeWidget(delDirWidget);
delDirWidget->deleteLater();
qDebug() << "Delete folder of search succeed! path = " << path;
}
QFrame *line = m_searchDirsFrame->findChild<QFrame*>(path);
if (line) {
m_searchDirLyt->removeWidget(line);
line->deleteLater();
qDebug()<< "Delete line of search folder:" << path;
}
}
void Search::appendBlockDirToList(const QString &path) void Search::appendBlockDirToList(const QString &path)
{ {
HoverWidget * dirWidget = new HoverWidget(path, m_blockDirsFrame); HoverWidget * dirWidget = new HoverWidget(path, m_blockDirsFrame);
dirWidget->setObjectName(path); dirWidget->setObjectName(path);
dirWidget->setMinimumWidth(550); dirWidget->setMinimumWidth(550);
dirWidget->setAttribute(Qt::WA_DeleteOnClose);
QHBoxLayout * dirWidgetLyt = new QHBoxLayout(dirWidget); QHBoxLayout * dirWidgetLyt = new QHBoxLayout(dirWidget);
dirWidgetLyt->setSpacing(8); dirWidgetLyt->setSpacing(8);
dirWidgetLyt->setContentsMargins(0, 0, 0, 0); dirWidgetLyt->setContentsMargins(0, 0, 0, 0);
@ -355,6 +712,7 @@ void Search::appendBlockDirToList(const QString &path)
// dirWidgetLyt->addWidget(delBtn); // dirWidgetLyt->addWidget(delBtn);
QFrame *line = new QFrame(m_blockDirsFrame); QFrame *line = new QFrame(m_blockDirsFrame);
line->setObjectName(path);
line->setFixedHeight(1); line->setFixedHeight(1);
line->setLineWidth(0); line->setLineWidth(0);
line->setFrameShape(QFrame::HLine); line->setFrameShape(QFrame::HLine);
@ -366,8 +724,6 @@ void Search::appendBlockDirToList(const QString &path)
connect(delBtn, &QPushButton::clicked, this, [ = ]() { connect(delBtn, &QPushButton::clicked, this, [ = ]() {
setBlockDir(path, false); setBlockDir(path, false);
getBlockDirs(); getBlockDirs();
m_blockDirsLyt->removeWidget(line);
line->deleteLater();
}); });
connect(dirWidget, &HoverWidget::enterWidget, this, [ = ]() { connect(dirWidget, &HoverWidget::enterWidget, this, [ = ]() {
delBtn->show(); delBtn->show();
@ -381,60 +737,29 @@ void Search::removeBlockDirFromList(const QString &path)
{ {
HoverWidget * delDirWidget = m_blockDirsFrame->findChild<HoverWidget *>(path); HoverWidget * delDirWidget = m_blockDirsFrame->findChild<HoverWidget *>(path);
if (delDirWidget) { if (delDirWidget) {
qDebug() << "Delete folder succeed! path = " << path; qDebug() << "Delete blocked folder succeed! path = " << path;
delDirWidget->close(); m_blockDirsLyt->removeWidget(delDirWidget);
delDirWidget->deleteLater();
}
QFrame *line = m_blockDirsFrame->findChild<QFrame*>(path);
if (line) {
m_blockDirsLyt->removeWidget(line);
line->deleteLater();
qDebug() << "Delete line of blocked folder:" << path;
} }
} }
void Search::setupConnection() void Search::setupConnection()
{ {
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddFolderClicked); connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddBlockFolderClicked);
} }
void Search::onBtnAddFolderClicked() void Search::onBtnAddBlockFolderClicked()
{ {
QFileDialog * fileDialog = new QFileDialog(m_pluginWidget); m_blockDirDialog->open();
// fileDialog->setFileMode(QFileDialog::Directory); //允许查看文件和文件夹,但只允许选择文件夹 }
fileDialog->setFileMode(QFileDialog::DirectoryOnly); //只允许查看文件夹
// fileDialog->setViewMode(QFileDialog::Detail); void Search::onAddSearchDirBtnClicked()
fileDialog->setDirectory(QDir::homePath()); {
fileDialog->setNameFilter(tr("Directories")); m_searchDirDialog->open();
fileDialog->setWindowTitle(tr("select blocked folder"));
fileDialog->setLabelText(QFileDialog::Accept, tr("Select"));
fileDialog->setLabelText(QFileDialog::LookIn, tr("Position: "));
fileDialog->setLabelText(QFileDialog::FileName, tr("FileName: "));
fileDialog->setLabelText(QFileDialog::FileType, tr("FileType: "));
fileDialog->setLabelText(QFileDialog::Reject, tr("Cancel"));
if(fileDialog->exec() != QDialog::Accepted) {
fileDialog->deleteLater();
return;
}
QString selectedDir = 0;
selectedDir = fileDialog->selectedFiles().first();
qDebug() << "Selected a folder in onBtnAddClicked(): " << selectedDir;
int returnCode = setBlockDir(selectedDir, true);
switch (returnCode) {
case ReturnCode::Succeed :
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 :
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!"));
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!"));
break;
default:
break;
}
} }

View File

@ -3,6 +3,8 @@
#include <QObject> #include <QObject>
#include <QGSettings> #include <QGSettings>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug> #include <QDebug>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
@ -11,6 +13,8 @@
#include <QFileDialog> #include <QFileDialog>
#include <QTextCodec> #include <QTextCodec>
#include <QPushButton> #include <QPushButton>
#include <QRadioButton>
#include <QButtonGroup>
#include <QMessageBox> #include <QMessageBox>
#include <kswitchbutton.h> #include <kswitchbutton.h>
@ -27,6 +31,7 @@
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings" #define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define SEARCH_METHOD_KEY "fileIndexEnable" #define SEARCH_METHOD_KEY "fileIndexEnable"
#define WEB_ENGINE_KEY "webEngine" #define WEB_ENGINE_KEY "webEngine"
#define CONTENT_SEARCH_KEY "contentFuzzySearch"
//TODO //TODO
#define CONFIG_FILE "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf" #define CONFIG_FILE "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf"
@ -68,9 +73,15 @@ private:
QVBoxLayout * m_mainLyt = nullptr; QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr; TitleLabel * m_titleLabel = nullptr;
//设置搜索引擎
// TitleLabel * m_webEngineLabel = nullptr;
ComboxFrame * m_webEngineFrame = nullptr;
QVBoxLayout * m_webEngineLyt = nullptr;
//索引详细设置
QFrame *m_setFrame = nullptr; QFrame *m_setFrame = nullptr;
QVBoxLayout *m_setFrameLyt = nullptr; QVBoxLayout *m_setFrameLyt = nullptr;
//设置搜索模式 //索引开关
QFrame *m_descFrame = nullptr; QFrame *m_descFrame = nullptr;
QVBoxLayout *m_descFrameLyt = nullptr; QVBoxLayout *m_descFrameLyt = nullptr;
QLabel *m_descLabel1 = nullptr; QLabel *m_descLabel1 = nullptr;
@ -79,10 +90,33 @@ private:
QHBoxLayout *m_searchMethodLyt = nullptr; QHBoxLayout *m_searchMethodLyt = nullptr;
// QLabel *m_searchMethodLabel = nullptr; // QLabel *m_searchMethodLabel = nullptr;
kdk::KSwitchButton *m_searchMethodBtn = nullptr; kdk::KSwitchButton *m_searchMethodBtn = nullptr;
//设置搜索引擎 //设置索引搜索模式
TitleLabel * m_webEngineLabel = nullptr; QFrame *m_indexSetFrame = nullptr;
ComboxFrame * m_webEngineFrame = nullptr; QVBoxLayout *m_indexSetLyt = nullptr;
QVBoxLayout * m_webEngineLyt = nullptr; //模糊搜索开关
QFrame *m_indexMethodFrame = nullptr;
QVBoxLayout *m_indexMethodLyt = nullptr;
QLabel *m_indexMethodDescLabel = nullptr;
//模糊搜索按钮
QButtonGroup *m_indexMethodBtnGroup = nullptr;
QFrame *m_fuzzyBtnFrame = nullptr;
QHBoxLayout *m_fuzzyBtnLyt = nullptr;
QRadioButton *m_fuzzyBtn = nullptr;
QLabel *m_fuzzyDescLabel = nullptr;
//精确搜索按钮
QFrame *m_preciseBtnFrame = nullptr;
QHBoxLayout *m_preciseBtnLyt = nullptr;
QRadioButton *m_preciseBtn = nullptr;
QLabel *m_preciseDescLabel = nullptr;
//设置当前搜索目录
TitleLabel *m_searchDirTitleLabel = nullptr;
QLabel *m_searchDirDescLabel = nullptr;
QFrame *m_searchDirsFrame = nullptr;
QVBoxLayout *m_searchDirLyt = nullptr;
QLabel *m_searchDirLabel = nullptr;
AddBtn *m_addSearchDirBtn = nullptr;
QFrame *m_addSearchDirFrame = nullptr;
//设置黑名单 //设置黑名单
TitleLabel * m_blockDirTitleLabel = nullptr; TitleLabel * m_blockDirTitleLabel = nullptr;
@ -95,6 +129,10 @@ private:
QLabel * m_addBlockDirLabel = nullptr; QLabel * m_addBlockDirLabel = nullptr;
QHBoxLayout * m_addBlockDirLyt = nullptr; QHBoxLayout * m_addBlockDirLyt = nullptr;
void initFileDialog();
QFileDialog *m_blockDirDialog = nullptr;
QFileDialog *m_searchDirDialog = nullptr;
QStringList m_blockDirs; QStringList m_blockDirs;
QSettings * m_dirSettings = nullptr; QSettings * m_dirSettings = nullptr;
void getBlockDirs(); void getBlockDirs();
@ -104,11 +142,18 @@ private:
void initBlockDirsList(); void initBlockDirsList();
// void refreshBlockDirsList(); // void refreshBlockDirsList();
QDBusInterface *m_interface = nullptr;
QDBusInterface *m_setSearchDirInterface = nullptr;
void initSearchDirs();
int setSearchDir(const QString &dirPath, const bool isAdd);
void appendSearchDirToList(const QString &path);
void removeSearchDirFromList(const QString &path);
void setupConnection(); void setupConnection();
private slots: private slots:
void onBtnAddFolderClicked(); void onBtnAddBlockFolderClicked();
void onAddSearchDirBtnClicked();
}; };
#endif // SEARCH_H #endif // SEARCH_H

View File

@ -5,50 +5,49 @@
<name>Search</name> <name>Search</name>
<message> <message>
<location filename="../search.cpp" line="13"/> <location filename="../search.cpp" line="13"/>
<location filename="../search.cpp" line="121"/> <location filename="../search.cpp" line="179"/>
<source>Search</source> <source>Search</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="145"/> <location filename="../search.cpp" line="215"/>
<source>Create index</source> <source>Create index</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Create index</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="146"/> <location filename="../search.cpp" line="216"/>
<source>Creating index can help you getting results quickly.</source> <source>Creating index can help you getting results quickly.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="165"/> <location filename="../search.cpp" line="184"/>
<source>Default web searching engine</source> <source>Default web searching engine</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Default web searching engine</extra-contents_path> <extra-contents_path>/Search/Default web searching engine</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="169"/> <location filename="../search.cpp" line="188"/>
<source>baidu</source> <source>baidu</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="170"/> <location filename="../search.cpp" line="189"/>
<source>sougou</source> <source>sougou</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="171"/> <location filename="../search.cpp" line="190"/>
<source>360</source> <source>360</source>
<translation>360</translation> <translation>360</translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="179"/> <location filename="../search.cpp" line="322"/>
<source>Block Folders</source> <source>Block Folders</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Block Folders</extra-contents_path> <extra-contents_path>/Search/Block Folders</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="184"/> <location filename="../search.cpp" line="327"/>
<source>Following folders will not be searched. You can set it by adding and removing folders.</source> <source>Following folders will not be searched. You can set it by adding and removing folders.</source>
<translation> </translation> <translation> </translation>
</message> </message>
@ -57,50 +56,96 @@
<translation type="vanished"></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="340"/> <location filename="../search.cpp" line="634"/>
<location filename="../search.cpp" line="705"/>
<source>delete</source> <source>delete</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="395"/> <location filename="../search.cpp" line="397"/>
<location filename="../search.cpp" line="441"/>
<source>Directories</source> <source>Directories</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="396"/> <location filename="../search.cpp" line="245"/>
<source>File Content Search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="250"/>
<source>precise Search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="263"/>
<source>show more results that match the keyword</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="261"/>
<source>Fuzzy Search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="252"/>
<source>show the results that exactly match the keyword</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="289"/>
<source>Search Folders</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="295"/>
<source>Following folders will be searched. You can set it by adding and removing folders.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="398"/>
<source>select blocked folder</source> <source>select blocked folder</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="397"/> <location filename="../search.cpp" line="399"/>
<location filename="../search.cpp" line="443"/>
<source>Select</source> <source>Select</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="398"/> <location filename="../search.cpp" line="400"/>
<location filename="../search.cpp" line="444"/>
<source>Position: </source> <source>Position: </source>
<translation> </translation> <translation> </translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="399"/> <location filename="../search.cpp" line="401"/>
<location filename="../search.cpp" line="445"/>
<source>FileName: </source> <source>FileName: </source>
<translation> </translation> <translation> </translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="400"/> <location filename="../search.cpp" line="402"/>
<location filename="../search.cpp" line="446"/>
<source>FileType: </source> <source>FileType: </source>
<translation> </translation> <translation> </translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="401"/> <location filename="../search.cpp" line="403"/>
<location filename="../search.cpp" line="447"/>
<source>Cancel</source> <source>Cancel</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="417"/> <location filename="../search.cpp" line="417"/>
<location filename="../search.cpp" line="421"/>
<location filename="../search.cpp" line="425"/> <location filename="../search.cpp" line="425"/>
<location filename="../search.cpp" line="429"/> <location filename="../search.cpp" line="429"/>
<location filename="../search.cpp" line="458"/>
<location filename="../search.cpp" line="461"/>
<location filename="../search.cpp" line="464"/>
<location filename="../search.cpp" line="467"/>
<location filename="../search.cpp" line="470"/>
<source>Warning</source> <source>Warning</source>
<translation></translation> <translation></translation>
</message> </message>
@ -110,9 +155,8 @@
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="421"/>
<source>Add blocked folder failed, it is not in home path!</source> <source>Add blocked folder failed, it is not in home path!</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="425"/> <location filename="../search.cpp" line="425"/>
@ -124,5 +168,35 @@
<source>Add blocked folder failed, it has been already blocked!</source> <source>Add blocked folder failed, it has been already blocked!</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<location filename="../search.cpp" line="442"/>
<source>select search folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="461"/>
<source>Add search folder failed, choosen path is not supported currently!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="467"/>
<source>Add search folder failed, another path which is in the same device has been added!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="458"/>
<source>Add search folder failed, choosen path or its parent dir has been added!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="464"/>
<source>Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../search.cpp" line="470"/>
<source>Add search folder failed, choosen path is not exists!</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -5,50 +5,49 @@
<name>Search</name> <name>Search</name>
<message> <message>
<location filename="../search.cpp" line="13"/> <location filename="../search.cpp" line="13"/>
<location filename="../search.cpp" line="121"/> <location filename="../search.cpp" line="179"/>
<source>Search</source> <source>Search</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="145"/> <location filename="../search.cpp" line="215"/>
<source>Create index</source> <source>Create index</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Create index</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="146"/> <location filename="../search.cpp" line="216"/>
<source>Creating index can help you getting results quickly.</source> <source>Creating index can help you getting results quickly.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="165"/> <location filename="../search.cpp" line="184"/>
<source>Default web searching engine</source> <source>Default web searching engine</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Default web searching engine</extra-contents_path> <extra-contents_path>/Search/Default web searching engine</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="169"/> <location filename="../search.cpp" line="188"/>
<source>baidu</source> <source>baidu</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="170"/> <location filename="../search.cpp" line="189"/>
<source>sougou</source> <source>sougou</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="171"/> <location filename="../search.cpp" line="190"/>
<source>360</source> <source>360</source>
<translation>360</translation> <translation>360</translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="179"/> <location filename="../search.cpp" line="322"/>
<source>Block Folders</source> <source>Block Folders</source>
<translation></translation> <translation></translation>
<extra-contents_path>/Search/Block Folders</extra-contents_path> <extra-contents_path>/Search/Block Folders</extra-contents_path>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="184"/> <location filename="../search.cpp" line="327"/>
<source>Following folders will not be searched. You can set it by adding and removing folders.</source> <source>Following folders will not be searched. You can set it by adding and removing folders.</source>
<translation></translation> <translation></translation>
</message> </message>
@ -57,50 +56,96 @@
<translation type="vanished"></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="340"/> <location filename="../search.cpp" line="634"/>
<location filename="../search.cpp" line="705"/>
<source>delete</source> <source>delete</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="395"/> <location filename="../search.cpp" line="397"/>
<location filename="../search.cpp" line="441"/>
<source>Directories</source> <source>Directories</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="396"/> <location filename="../search.cpp" line="245"/>
<source>File Content Search</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="250"/>
<source>precise Search</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="263"/>
<source>show more results that match the keyword</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="261"/>
<source>Fuzzy Search</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="252"/>
<source>show the results that exactly match the keyword</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="289"/>
<source>Search Folders</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="295"/>
<source>Following folders will be searched. You can set it by adding and removing folders.</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="398"/>
<source>select blocked folder</source> <source>select blocked folder</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="397"/> <location filename="../search.cpp" line="399"/>
<location filename="../search.cpp" line="443"/>
<source>Select</source> <source>Select</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="398"/> <location filename="../search.cpp" line="400"/>
<location filename="../search.cpp" line="444"/>
<source>Position: </source> <source>Position: </source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="399"/> <location filename="../search.cpp" line="401"/>
<location filename="../search.cpp" line="445"/>
<source>FileName: </source> <source>FileName: </source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="400"/> <location filename="../search.cpp" line="402"/>
<location filename="../search.cpp" line="446"/>
<source>FileType: </source> <source>FileType: </source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="401"/> <location filename="../search.cpp" line="403"/>
<location filename="../search.cpp" line="447"/>
<source>Cancel</source> <source>Cancel</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="417"/> <location filename="../search.cpp" line="417"/>
<location filename="../search.cpp" line="421"/>
<location filename="../search.cpp" line="425"/> <location filename="../search.cpp" line="425"/>
<location filename="../search.cpp" line="429"/> <location filename="../search.cpp" line="429"/>
<location filename="../search.cpp" line="458"/>
<location filename="../search.cpp" line="461"/>
<location filename="../search.cpp" line="464"/>
<location filename="../search.cpp" line="467"/>
<location filename="../search.cpp" line="470"/>
<source>Warning</source> <source>Warning</source>
<translation></translation> <translation></translation>
</message> </message>
@ -110,9 +155,8 @@
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="421"/>
<source>Add blocked folder failed, it is not in home path!</source> <source>Add blocked folder failed, it is not in home path!</source>
<translation></translation> <translation type="vanished"></translation>
</message> </message>
<message> <message>
<location filename="../search.cpp" line="425"/> <location filename="../search.cpp" line="425"/>
@ -124,5 +168,35 @@
<source>Add blocked folder failed, it has been already blocked!</source> <source>Add blocked folder failed, it has been already blocked!</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<location filename="../search.cpp" line="442"/>
<source>select search folder</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="461"/>
<source>Add search folder failed, choosen path is not supported currently!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="467"/>
<source>Add search folder failed, another path which is in the same device has been added!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="458"/>
<source>Add search folder failed, choosen path or its parent dir has been added!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="464"/>
<source>Add search folder failed, choosen path is in repeat mounted devices and another path which is in the same device has been added!</source>
<translation></translation>
</message>
<message>
<location filename="../search.cpp" line="470"/>
<source>Add search folder failed, choosen path is not exists!</source>
<translation></translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -2,9 +2,11 @@
<node> <node>
<interface name="org.ukui.search.fileindex"> <interface name="org.ukui.search.fileindex">
<method name="appendIndexableListItem"> <method name="appendIndexableListItem">
<arg type="i" direction="out"/>
<arg name="path" type="s" direction="in"/> <arg name="path" type="s" direction="in"/>
</method> </method>
<method name="removeIndexableListItem"> <method name="removeIndexableListItem">
<arg type="b" direction="out"/>
<arg name="path" type="s" direction="in"/> <arg name="path" type="s" direction="in"/>
</method> </method>
</interface> </interface>

View File

@ -33,15 +33,19 @@ DirWatcherAdaptor::~DirWatcherAdaptor()
// destructor // destructor
} }
void DirWatcherAdaptor::appendIndexableListItem(const QString &path) int DirWatcherAdaptor::appendIndexableListItem(const QString &path)
{ {
// handle method call org.ukui.search.fileindex.appendIndexableListItem // handle method call org.ukui.search.fileindex.appendIndexableListItem
QMetaObject::invokeMethod(parent(), "appendIndexableListItem", Q_ARG(QString, path)); int out0;
QMetaObject::invokeMethod(parent(), "appendIndexableListItem", Q_RETURN_ARG(int, out0), Q_ARG(QString, path));
return out0;
} }
void DirWatcherAdaptor::removeIndexableListItem(const QString &path) bool DirWatcherAdaptor::removeIndexableListItem(const QString &path)
{ {
// handle method call org.ukui.search.fileindex.removeIndexableListItem // handle method call org.ukui.search.fileindex.removeIndexableListItem
QMetaObject::invokeMethod(parent(), "removeIndexableListItem", Q_ARG(QString, path)); bool out0;
QMetaObject::invokeMethod(parent(), "removeIndexableListItem", Q_RETURN_ARG(bool, out0), Q_ARG(QString, path));
return out0;
} }

View File

@ -33,9 +33,11 @@ class DirWatcherAdaptor: public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Introspection", "" Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"org.ukui.search.fileindex\">\n" " <interface name=\"org.ukui.search.fileindex\">\n"
" <method name=\"appendIndexableListItem\">\n" " <method name=\"appendIndexableListItem\">\n"
" <arg direction=\"out\" type=\"i\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n" " <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
" </method>\n" " </method>\n"
" <method name=\"removeIndexableListItem\">\n" " <method name=\"removeIndexableListItem\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n" " <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
" </method>\n" " </method>\n"
" </interface>\n" " </interface>\n"
@ -46,8 +48,8 @@ public:
public: // PROPERTIES public: // PROPERTIES
public Q_SLOTS: // METHODS public Q_SLOTS: // METHODS
void appendIndexableListItem(const QString &path); int appendIndexableListItem(const QString &path);
void removeIndexableListItem(const QString &path); bool removeIndexableListItem(const QString &path);
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
}; };

View File

@ -56,11 +56,25 @@ DirWatcher *DirWatcher::getDirWatcher()
QStringList DirWatcher::currentIndexableDir() QStringList DirWatcher::currentIndexableDir()
{ {
QMutexLocker locker(&s_mutex); QMutexLocker locker(&s_mutex);
this->updateIndexableDirs();
return m_indexableDirList;
}
void DirWatcher::updateIndexableDirs()
{
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE); m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList(); m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList();
m_qSettings->endGroup(); m_qSettings->endGroup();
QStringList indexableDirs = m_indexableDirList; QStringList indexableDirs = m_indexableDirList;
return indexableDirs; for (const QString& dir : m_indexableDirList) {
if (!QFileInfo(dir).isDir()) {
indexableDirs.removeAll(dir);
}
}
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
m_qSettings->setValue(INDEXABLE_DIR_VALUE, indexableDirs);
m_qSettings->endGroup();
m_indexableDirList = indexableDirs;
} }
QStringList DirWatcher::currentBlackListOfIndex() QStringList DirWatcher::currentBlackListOfIndex()
@ -70,28 +84,30 @@ QStringList DirWatcher::currentBlackListOfIndex()
return blackListOfIndex; return blackListOfIndex;
} }
void DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackList) bool DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackList)
{ {
//排除要添加的路径已被索引的情况 //排除要添加的路径已被索引的情况
if (m_indexableDirList.contains(path)) { if (m_indexableDirList.contains(path)) {
qDebug() << QString("index path %1 is already added.").arg(path); qDebug() << QString("index path %1 is already added.").arg(path);
return; return false;
} }
//处理添加路径非根目录时,要添加索引的路径与已索引路径为父子关系的情况 //处理添加路径非根目录时,要添加索引的路径与已索引路径为父子关系的情况
if (path != "/") { if (path != "/") {
QString indexablePath; QString indexablePath;
QStringList tmp = m_indexableDirList;
for (int i = 0; i < m_indexableDirList.length(); i++) { for (int i = 0; i < m_indexableDirList.length(); i++) {
indexablePath = m_indexableDirList.at(i); indexablePath = m_indexableDirList.at(i);
if (path.startsWith(indexablePath + "/")) { if (path.startsWith(indexablePath + "/")) {
qCritical() << QString("The parent of the path:%1 has been added.").arg(path); qCritical() << QString("The parent of the path:%1 has been added.").arg(path);
return; return false;
} }
if (indexablePath.startsWith(path + "/")) { if (indexablePath.startsWith(path + "/")) {
m_indexableDirList.removeAll(indexablePath); tmp.removeAll(indexablePath);
blackList.append(indexablePath); blackList.append(indexablePath);
} }
} }
m_indexableDirList = tmp;
} }
m_indexableDirList << path; m_indexableDirList << path;
@ -101,20 +117,22 @@ void DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackLi
blackList.removeDuplicates(); blackList.removeDuplicates();
Q_EMIT this->appendIndexItem(path, blackList); Q_EMIT this->appendIndexItem(path, blackList);
qDebug() << "index path:" << path << "blacklist:" << blackList; qDebug() << "index path:" << path << "blacklist:" << blackList;
return true;
} }
void DirWatcher::handleIndexItemRemove(const QString &path) bool DirWatcher::handleIndexItemRemove(const QString &path)
{ {
this->currentIndexableDir(); this->currentIndexableDir();
QMutexLocker locker(&s_mutex); QMutexLocker locker(&s_mutex);
if (!m_indexableDirList.contains(path)) { if (!m_indexableDirList.contains(path)) {
qWarning() << QString("The path: %1 is not indexed").arg(path); qWarning() << QString("The path: %1 is not indexed").arg(path);
return; return false;
} }
m_indexableDirList.removeAll(path); m_indexableDirList.removeAll(path);
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE); m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
m_qSettings->setValue(INDEXABLE_DIR_VALUE, m_indexableDirList); m_qSettings->setValue(INDEXABLE_DIR_VALUE, m_indexableDirList);
m_qSettings->endGroup(); m_qSettings->endGroup();
return true;
} }
/** /**
@ -278,13 +296,24 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di
g_object_unref(rootFile); g_object_unref(rootFile);
} }
void DirWatcher::appendIndexableListItem(const QString &path) int DirWatcher::appendIndexableListItem(const QString &path)
{ {
int resultCode = 1;
/* code:
* 1: successful
* -1: path or its parent dir has been added
* -2: path is or under blacklist
* -3: path is in repeat mounted devices and another path which is in the same device has been indexed
* -4: another path which is in the same device has been indexed
* -5: path is not exists
*/
//排除path不存在的情况 //排除path不存在的情况
QFile file(path); QFile file(path);
if (!file.exists()) { if (!file.exists()) {
qWarning() << QString("target path:%1 is not exists!").arg(path); qWarning() << QString("target path:%1 is not exists!").arg(path);
return; resultCode = -5;
return resultCode;
} }
//同步配置文件中的已索引目录 //同步配置文件中的已索引目录
@ -296,15 +325,18 @@ void DirWatcher::appendIndexableListItem(const QString &path)
//根目录特殊处理 //根目录特殊处理
if (path == "/") { if (path == "/") {
this->handleIndexItemAppend(path, m_blackListOfIndex); if (!this->handleIndexItemAppend(path, m_blackListOfIndex)) {
return; resultCode = -1;
}
return resultCode;
} }
//处理要添加索引的路径与索引黑名单中路径为父子关系的情况 //处理要添加索引的路径与索引黑名单中路径为父子关系的情况
for (const QString& blackListPath : m_blackListOfIndex) { for (const QString& blackListPath : m_blackListOfIndex) {
if (path.startsWith(blackListPath + "/") or path == blackListPath) { if (path.startsWith(blackListPath + "/") or path == blackListPath) {
qCritical() << QString("path:%1 is or under the blacklistpath:%2.").arg(path, blackListPath); qCritical() << QString("path:%1 is or under the blacklistpath:%2.").arg(path, blackListPath);
return; resultCode = -2;
return resultCode;
} }
if (blackListPath.startsWith(path + "/")) { if (blackListPath.startsWith(path + "/")) {
@ -348,7 +380,8 @@ void DirWatcher::appendIndexableListItem(const QString &path)
//(1)(4)直接返回 //(1)(4)直接返回
if (pathToBeAddedIsRepeatedDevice and addedPathHasRepeatedDevice) { if (pathToBeAddedIsRepeatedDevice and addedPathHasRepeatedDevice) {
qCritical() << "current path is in repeat mounted devices and another path which is in the same device has been indexed!"; qCritical() << "current path is in repeat mounted devices and another path which is in the same device has been indexed!";
return; resultCode = -3;
return resultCode;
} }
//(2)(4)将要添加索引目录相应的重复挂载路径添加到黑名单 //(2)(4)将要添加索引目录相应的重复挂载路径添加到黑名单
if (pathToBeAddedHasRepeatedDevice and addedPathHasRepeatedDevice) { if (pathToBeAddedHasRepeatedDevice and addedPathHasRepeatedDevice) {
@ -360,7 +393,8 @@ void DirWatcher::appendIndexableListItem(const QString &path)
QString pathAfterReplace = repeatedDir + addedRelativeDir; QString pathAfterReplace = repeatedDir + addedRelativeDir;
if (path.startsWith(pathAfterReplace) or path == pathAfterReplace) { if (path.startsWith(pathAfterReplace) or path == pathAfterReplace) {
qCritical() << QString("another path:%1 which is in the same device has been indexed").arg(pathAfterReplace); qCritical() << QString("another path:%1 which is in the same device has been indexed").arg(pathAfterReplace);
return; resultCode = -4;
return resultCode;
} else { } else {
blackList.append(pathAfterReplace); blackList.append(pathAfterReplace);
break; break;
@ -405,19 +439,26 @@ void DirWatcher::appendIndexableListItem(const QString &path)
if (path.startsWith(spec + "/") or path == spec) { if (path.startsWith(spec + "/") or path == spec) {
tmp.replace(0, spec.length(), mountPoint); tmp.replace(0, spec.length(), mountPoint);
this->handleIndexItemAppend(tmp, blackList); if (this->handleIndexItemAppend(tmp, blackList)) {
qDebug() << QString("The path:%1 has been replaced into %2").arg(path, tmp); qDebug() << QString("The path:%1 has been replaced into %2").arg(path, tmp);
return; } else {
resultCode = -1;
}
return resultCode;
} }
} }
this->handleIndexItemAppend(path, blackList); if (!this->handleIndexItemAppend(path, blackList)) {
resultCode = -1;
}
return resultCode;
} }
void DirWatcher::removeIndexableListItem(const QString &path) bool DirWatcher::removeIndexableListItem(const QString &path)
{ {
this->handleIndexItemRemove(path); bool res = this->handleIndexItemRemove(path);
Q_EMIT this->removeIndexItem(path); Q_EMIT this->removeIndexItem(path);
return res;
} }
void DirWatcher::initData() void DirWatcher::initData()
@ -437,9 +478,11 @@ void DirWatcher::initData()
*/ */
//将磁盘分区后其他分区都会挂载到media下多块硬盘也会挂到media因此media放开mnt同理 //将磁盘分区后其他分区都会挂载到media下多块硬盘也会挂到media因此media放开mnt同理
//backup是备份文件tmp是临时文件也都放开 //backup是备份文件tmp是临时文件也都放开
m_blackListOfIndex << "/boot" << "/bin" << "/dev" << "/etc" << "/usr" << "/var" // m_blackListOfIndex << "/boot" << "/bin" << "/dev" << "/etc" << "/usr" << "/var"
<< "/lib" << "/lib32" << "/lib64" << "/libx32" << "/cdrom" // << "/lib" << "/lib32" << "/lib64" << "/libx32" << "/cdrom"
<< "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt"; // << "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt";
//专用机需求:只屏蔽/proc, /sys, /dev, /tmp, /run
m_blackListOfIndex << "/proc" << "/sys" << "/dev" << "/tmp" << "/run";
//目前方案:可搜索目录(服务)默认根目录,可搜索目录(应用)默认家目录和/data目录 //目前方案:可搜索目录(服务)默认根目录,可搜索目录(应用)默认家目录和/data目录
QDir dir("/data"); QDir dir("/data");
@ -553,13 +596,13 @@ void DirWatcher::handleDisk()
} }
} }
//将u盘设备在/data和/home下的所有挂载点添加到索引黑名单, 目前由于未知原因收不到udisk挂载信号因此暂时不生效 //将u盘设备添加到索引黑名单
if (!m_currentUDiskDeviceInfo.isEmpty()) { if (!m_currentUDiskDeviceInfo.isEmpty()) {
for (auto t = m_currentUDiskDeviceInfo.constBegin(); t != m_currentUDiskDeviceInfo.constEnd(); t++) { for (auto t = m_currentUDiskDeviceInfo.constBegin(); t != m_currentUDiskDeviceInfo.constEnd(); t++) {
for (QString udiskDevice: t.value()) { for (QString udiskDevice: t.value()) {
if (udiskDevice.startsWith("/data") || udiskDevice.startsWith("/home")) { // if (udiskDevice.startsWith("/data") || udiskDevice.startsWith("/home")) {
m_blackListOfIndex.append(udiskDevice); m_blackListOfIndex.append(udiskDevice);
} // }
} }
} }
} }

View File

@ -48,19 +48,32 @@ public Q_SLOTS:
QStringList searchableDirForSearchApplication(); QStringList searchableDirForSearchApplication();
QStringList blackListOfDir(const QString &dirPath); QStringList blackListOfDir(const QString &dirPath);
Q_SCRIPTABLE void appendIndexableListItem(const QString &path); /**
Q_SCRIPTABLE void removeIndexableListItem(const QString &path); * @brief DirWatcher::appendIndexableListItem
* add a item to indexable dirs
* @param path: the path to be added to the index dirs list
* @return int: the result code
* 1: successful
* -1: path or its parent dir has been added
* -2: path is or under blacklist
* -3: path is in repeat mounted devices and another path which is in the same device has been indexed
* -4: another path which is in the same device has been indexed
* -5: path is not exists
*/
Q_SCRIPTABLE int appendIndexableListItem(const QString &path);
Q_SCRIPTABLE bool removeIndexableListItem(const QString &path);
private: private:
DirWatcher(QObject *parent = nullptr); DirWatcher(QObject *parent = nullptr);
~DirWatcher(); ~DirWatcher();
void initData(); void initData();
void initDiskWatcher(); void initDiskWatcher();
void updateIndexableDirs();
void handleDisk(); void handleDisk();
void handleIndexItemAppend(const QString &path, QStringList &blackList); bool handleIndexItemAppend(const QString &path, QStringList &blackList);
void handleIndexItemRemove(const QString &path); bool handleIndexItemRemove(const QString &path);
static QMutex s_mutex; static QMutex s_mutex;

View File

@ -46,6 +46,8 @@ void UkuiSearchDirManagerDbus::parseCmd(QString msg, bool isPrimary)
parser.addOption(quitOption); parser.addOption(quitOption);
if (isPrimary) { if (isPrimary) {
const QStringList args = QString(msg).split(' ');
parser.process(args);
if (parser.isSet(quitOption)) { if (parser.isSet(quitOption)) {
qApp->quit(); qApp->quit();
return; return;