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:
parent
8074df1dc4
commit
6b06460e79
|
@ -494,7 +494,7 @@ DirectSearch::DirectSearch(QString keyword, DataQueue<SearchPluginIface::ResultI
|
|||
|
||||
void DirectSearch::run() {
|
||||
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
|
||||
QStringList searchPath = DirWatcher::getDirWatcher()->searchableDirForSearchApplication();
|
||||
QStringList searchPath = DirWatcher::getDirWatcher()->currentIndexableDir();
|
||||
QQueue<QString> bfs;
|
||||
for (const QString &path : searchPath) {
|
||||
if (blockList.contains(path)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
QT += widgets
|
||||
QT += widgets dbus
|
||||
|
||||
TEMPLATE = lib
|
||||
TARGET = $$qtLibraryTarget(search-ukcc-plugin)
|
||||
|
|
|
@ -13,6 +13,18 @@ Search::Search()
|
|||
m_plugin_name = tr("Search");
|
||||
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->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
|
@ -37,8 +49,11 @@ int Search::pluginTypes()
|
|||
QWidget *Search::pluginUi()
|
||||
{
|
||||
initUi();
|
||||
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddFolderClicked);
|
||||
initFileDialog();
|
||||
initSearchDirs();
|
||||
initBlockDirsList();
|
||||
connect(m_addSearchDirBtn, &QPushButton::clicked, this, &Search::onAddSearchDirBtnClicked);
|
||||
connect(m_addBlockDirWidget, &QPushButton::clicked, this, &Search::onBtnAddBlockFolderClicked);
|
||||
|
||||
if (m_gsettings) {
|
||||
//按钮状态初始化
|
||||
|
@ -46,9 +61,13 @@ QWidget *Search::pluginUi()
|
|||
//当前是否使用索引搜索/暴力搜索
|
||||
bool is_index_search_on = m_gsettings->get(SEARCH_METHOD_KEY).toBool();
|
||||
m_searchMethodBtn->setChecked(is_index_search_on);
|
||||
if (is_index_search_on) {
|
||||
m_indexSetFrame->show();
|
||||
}
|
||||
} else {
|
||||
m_searchMethodBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
if (m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
|
||||
//当前网页搜索的搜索引擎
|
||||
QString engine = m_gsettings->get(WEB_ENGINE_KEY).toString();
|
||||
|
@ -56,6 +75,19 @@ QWidget *Search::pluginUi()
|
|||
} else {
|
||||
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
|
||||
connect(m_gsettings, &QGSettings::changed, this, [ = ](const QString &key) {
|
||||
if (key == SEARCH_METHOD_KEY) {
|
||||
|
@ -68,12 +100,31 @@ QWidget *Search::pluginUi()
|
|||
m_webEngineFrame->mCombox->blockSignals(true);
|
||||
m_webEngineFrame->mCombox->setCurrentIndex(m_webEngineFrame->mCombox->findData(engine));
|
||||
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) {
|
||||
if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
|
||||
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) {
|
||||
if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) {
|
||||
|
@ -124,17 +175,30 @@ void Search::initUi()
|
|||
m_mainLyt = new QVBoxLayout(m_pluginWidget);
|
||||
m_pluginWidget->setLayout(m_mainLyt);
|
||||
|
||||
m_titleLabel = new TitleLabel(m_setFrame);
|
||||
m_titleLabel = new TitleLabel(m_pluginWidget);
|
||||
m_titleLabel->setText(tr("Search"));
|
||||
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->setFrameShape(QFrame::Shape::Box);
|
||||
m_setFrameLyt = new QVBoxLayout(m_setFrame);
|
||||
m_setFrameLyt->setContentsMargins(0, 0, 0, 0);
|
||||
m_setFrameLyt->setSpacing(0);
|
||||
|
||||
//~ contents_path /Search/Create index
|
||||
//索引开关UI
|
||||
m_searchMethodFrame = new QFrame(m_setFrame);
|
||||
m_searchMethodFrame->setMinimumWidth(550);
|
||||
m_searchMethodLyt = new QHBoxLayout(m_searchMethodFrame);
|
||||
|
@ -148,7 +212,6 @@ void Search::initUi()
|
|||
m_descLabel1 = new QLabel(m_descFrame);
|
||||
m_descLabel2 = new QLabel(m_descFrame);
|
||||
|
||||
//~ contents_path /Search/Create index
|
||||
m_descLabel1->setText(tr("Create index"));
|
||||
m_descLabel2->setText(tr("Creating index can help you getting results quickly."));
|
||||
m_descLabel2->setEnabled(false);
|
||||
|
@ -158,27 +221,100 @@ void Search::initUi()
|
|||
m_searchMethodLyt->addWidget(m_descFrame);
|
||||
m_searchMethodLyt->addStretch();
|
||||
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->setLineWidth(0);
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
m_setFrameLyt->addWidget(line);
|
||||
|
||||
//设置网页搜索引擎部分的ui
|
||||
//~ contents_path /Search/Default web searching engine
|
||||
m_webEngineFrame = new ComboxFrame(tr("Default web searching engine"), m_searchMethodFrame);
|
||||
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_setFrameLyt->addWidget(m_webEngineFrame);
|
||||
//设置索引模式的ui
|
||||
m_indexMethodFrame = new QFrame(m_indexSetFrame);
|
||||
m_indexMethodLyt = new QVBoxLayout(m_indexMethodFrame);
|
||||
m_indexMethodLyt->setContentsMargins(8, 16, 0, 0);//radiobutton本身左边有8间距
|
||||
m_indexMethodFrame->setLayout(m_indexMethodLyt);
|
||||
|
||||
m_indexMethodDescLabel = new QLabel(m_indexMethodFrame);
|
||||
m_indexMethodDescLabel->setContentsMargins(8, 0, 0, 0);
|
||||
m_indexMethodDescLabel->setText(tr("File Content Search"));
|
||||
|
||||
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);
|
||||
|
||||
//添加搜索目录部分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
|
||||
m_blockDirTitleLabel = new TitleLabel(m_pluginWidget);
|
||||
|
||||
|
@ -250,6 +386,97 @@ void Search::initUi()
|
|||
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 从配置文件获取黑名单并将黑名单列表传入
|
||||
*/
|
||||
|
@ -277,9 +504,9 @@ int Search::setBlockDir(const QString &dirPath, const bool &is_add)
|
|||
removeBlockDirFromList(dirPath);
|
||||
return ReturnCode::Succeed;
|
||||
}
|
||||
if (!dirPath.startsWith(QDir::homePath())) {
|
||||
return ReturnCode::NotInHomeDir;
|
||||
}
|
||||
// if (!dirPath.startsWith(QDir::homePath())) {
|
||||
// return ReturnCode::NotInHomeDir;
|
||||
// }
|
||||
|
||||
QString pathKey = dirPath.right(dirPath.length() - 1);
|
||||
|
||||
|
@ -311,18 +538,148 @@ void Search::initBlockDirsList()
|
|||
getBlockDirs();
|
||||
for (QString path: m_blockDirs) {
|
||||
QString wholePath = QString("/%1").arg(path);
|
||||
if (QFileInfo(wholePath).isDir() && path.startsWith("home")) {
|
||||
if (QFileInfo(wholePath).isDir() /*&& path.startsWith("home")*/) {
|
||||
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)
|
||||
{
|
||||
HoverWidget * dirWidget = new HoverWidget(path, m_blockDirsFrame);
|
||||
dirWidget->setObjectName(path);
|
||||
dirWidget->setMinimumWidth(550);
|
||||
dirWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QHBoxLayout * dirWidgetLyt = new QHBoxLayout(dirWidget);
|
||||
dirWidgetLyt->setSpacing(8);
|
||||
dirWidgetLyt->setContentsMargins(0, 0, 0, 0);
|
||||
|
@ -355,6 +712,7 @@ void Search::appendBlockDirToList(const QString &path)
|
|||
// dirWidgetLyt->addWidget(delBtn);
|
||||
|
||||
QFrame *line = new QFrame(m_blockDirsFrame);
|
||||
line->setObjectName(path);
|
||||
line->setFixedHeight(1);
|
||||
line->setLineWidth(0);
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
|
@ -366,8 +724,6 @@ void Search::appendBlockDirToList(const QString &path)
|
|||
connect(delBtn, &QPushButton::clicked, this, [ = ]() {
|
||||
setBlockDir(path, false);
|
||||
getBlockDirs();
|
||||
m_blockDirsLyt->removeWidget(line);
|
||||
line->deleteLater();
|
||||
});
|
||||
connect(dirWidget, &HoverWidget::enterWidget, this, [ = ]() {
|
||||
delBtn->show();
|
||||
|
@ -381,60 +737,29 @@ void Search::removeBlockDirFromList(const QString &path)
|
|||
{
|
||||
HoverWidget * delDirWidget = m_blockDirsFrame->findChild<HoverWidget *>(path);
|
||||
if (delDirWidget) {
|
||||
qDebug() << "Delete folder succeed! path = " << path;
|
||||
delDirWidget->close();
|
||||
qDebug() << "Delete blocked folder succeed! path = " << path;
|
||||
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()
|
||||
{
|
||||
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);
|
||||
// fileDialog->setFileMode(QFileDialog::Directory); //允许查看文件和文件夹,但只允许选择文件夹
|
||||
fileDialog->setFileMode(QFileDialog::DirectoryOnly); //只允许查看文件夹
|
||||
// fileDialog->setViewMode(QFileDialog::Detail);
|
||||
fileDialog->setDirectory(QDir::homePath());
|
||||
fileDialog->setNameFilter(tr("Directories"));
|
||||
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;
|
||||
m_blockDirDialog->open();
|
||||
}
|
||||
|
||||
void Search::onAddSearchDirBtnClicked()
|
||||
{
|
||||
m_searchDirDialog->open();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QGSettings>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
|
@ -11,6 +13,8 @@
|
|||
#include <QFileDialog>
|
||||
#include <QTextCodec>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QButtonGroup>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <kswitchbutton.h>
|
||||
|
@ -27,6 +31,7 @@
|
|||
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
|
||||
#define SEARCH_METHOD_KEY "fileIndexEnable"
|
||||
#define WEB_ENGINE_KEY "webEngine"
|
||||
#define CONTENT_SEARCH_KEY "contentFuzzySearch"
|
||||
//TODO
|
||||
#define CONFIG_FILE "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf"
|
||||
|
||||
|
@ -68,9 +73,15 @@ private:
|
|||
QVBoxLayout * m_mainLyt = nullptr;
|
||||
TitleLabel * m_titleLabel = nullptr;
|
||||
|
||||
//设置搜索引擎
|
||||
// TitleLabel * m_webEngineLabel = nullptr;
|
||||
ComboxFrame * m_webEngineFrame = nullptr;
|
||||
QVBoxLayout * m_webEngineLyt = nullptr;
|
||||
|
||||
//索引详细设置
|
||||
QFrame *m_setFrame = nullptr;
|
||||
QVBoxLayout *m_setFrameLyt = nullptr;
|
||||
//设置搜索模式
|
||||
//索引开关
|
||||
QFrame *m_descFrame = nullptr;
|
||||
QVBoxLayout *m_descFrameLyt = nullptr;
|
||||
QLabel *m_descLabel1 = nullptr;
|
||||
|
@ -79,10 +90,33 @@ private:
|
|||
QHBoxLayout *m_searchMethodLyt = nullptr;
|
||||
// QLabel *m_searchMethodLabel = nullptr;
|
||||
kdk::KSwitchButton *m_searchMethodBtn = nullptr;
|
||||
//设置搜索引擎
|
||||
TitleLabel * m_webEngineLabel = nullptr;
|
||||
ComboxFrame * m_webEngineFrame = nullptr;
|
||||
QVBoxLayout * m_webEngineLyt = nullptr;
|
||||
//设置索引搜索模式
|
||||
QFrame *m_indexSetFrame = nullptr;
|
||||
QVBoxLayout *m_indexSetLyt = 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;
|
||||
|
@ -95,6 +129,10 @@ private:
|
|||
QLabel * m_addBlockDirLabel = nullptr;
|
||||
QHBoxLayout * m_addBlockDirLyt = nullptr;
|
||||
|
||||
void initFileDialog();
|
||||
QFileDialog *m_blockDirDialog = nullptr;
|
||||
QFileDialog *m_searchDirDialog = nullptr;
|
||||
|
||||
QStringList m_blockDirs;
|
||||
QSettings * m_dirSettings = nullptr;
|
||||
void getBlockDirs();
|
||||
|
@ -104,11 +142,18 @@ private:
|
|||
void initBlockDirsList();
|
||||
// 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();
|
||||
|
||||
private slots:
|
||||
void onBtnAddFolderClicked();
|
||||
void onBtnAddBlockFolderClicked();
|
||||
void onAddSearchDirBtnClicked();
|
||||
};
|
||||
|
||||
#endif // SEARCH_H
|
||||
|
|
|
@ -5,50 +5,49 @@
|
|||
<name>Search</name>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="13"/>
|
||||
<location filename="../search.cpp" line="121"/>
|
||||
<location filename="../search.cpp" line="179"/>
|
||||
<source>Search</source>
|
||||
<translation>འཚོལ་ཞིབ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="145"/>
|
||||
<location filename="../search.cpp" line="215"/>
|
||||
<source>Create index</source>
|
||||
<translation>གསར་འཛུགས་འཚོལ་ཞིབ་བྱེད་པར་ཁྲིད་སྟོན།</translation>
|
||||
<extra-contents_path>/Search/Create index</extra-contents_path>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="146"/>
|
||||
<location filename="../search.cpp" line="216"/>
|
||||
<source>Creating index can help you getting results quickly.</source>
|
||||
<translation>སྟོན་གྲངས་གསར་སྐྲུན་བྱས་ན་ཁྱོད་ལ་མགྱོགས་མྱུར་ངང་གྲུབ་འབྲས་ཐོབ་པར་རོགས་རམ་བྱེད་ཐུབ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="165"/>
|
||||
<location filename="../search.cpp" line="184"/>
|
||||
<source>Default web searching engine</source>
|
||||
<translation>ཁོག་གི་དྲ་ཤོག་གཏོད་པ་བཤེར་འཚོལ་རིགས་དབྱིབས།</translation>
|
||||
<extra-contents_path>/Search/Default web searching engine</extra-contents_path>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="169"/>
|
||||
<location filename="../search.cpp" line="188"/>
|
||||
<source>baidu</source>
|
||||
<translation>པའེ་ཏུའུ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="170"/>
|
||||
<location filename="../search.cpp" line="189"/>
|
||||
<source>sougou</source>
|
||||
<translation>སོའོ་གོའུ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="171"/>
|
||||
<location filename="../search.cpp" line="190"/>
|
||||
<source>360</source>
|
||||
<translation>360</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="179"/>
|
||||
<location filename="../search.cpp" line="322"/>
|
||||
<source>Block Folders</source>
|
||||
<translation>ལྐོག་བཀོད་མིང་ཐོ།</translation>
|
||||
<extra-contents_path>/Search/Block Folders</extra-contents_path>
|
||||
</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>
|
||||
<translation>གཤམ་གྱི་ཡིག་སྣོད་འཚོལ་བཤེར་མི་བྱེད། ཡིག་སྣོད་གསར་སྣོན་དང་གསུབ་འཕྲི་བྱས་ཚེ་ཡིག་ཆའི་དཀར་ཆག་སྒྲིག་འགོད་བྱ་ཐུབ།</translation>
|
||||
</message>
|
||||
|
@ -57,50 +56,96 @@
|
|||
<translation type="vanished">བསལ་འདེམས་ཀྱི་དཀར་ཆག།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="340"/>
|
||||
<location filename="../search.cpp" line="634"/>
|
||||
<location filename="../search.cpp" line="705"/>
|
||||
<source>delete</source>
|
||||
<translation>བསུབ་པ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="395"/>
|
||||
<location filename="../search.cpp" line="397"/>
|
||||
<location filename="../search.cpp" line="441"/>
|
||||
<source>Directories</source>
|
||||
<translation>དཀར་ཆག</translation>
|
||||
</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>
|
||||
<translation>བཀག་སྡོམ་བྱས་པའི་ཡིག་སྣོད་གདམ་གསེས</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="397"/>
|
||||
<location filename="../search.cpp" line="399"/>
|
||||
<location filename="../search.cpp" line="443"/>
|
||||
<source>Select</source>
|
||||
<translation>བདམས་ཐོན་བྱུང་བ།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="398"/>
|
||||
<location filename="../search.cpp" line="400"/>
|
||||
<location filename="../search.cpp" line="444"/>
|
||||
<source>Position: </source>
|
||||
<translation>གོ་གནས་ནི། </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="399"/>
|
||||
<location filename="../search.cpp" line="401"/>
|
||||
<location filename="../search.cpp" line="445"/>
|
||||
<source>FileName: </source>
|
||||
<translation>ཡིག་ཆའི་མིང་ནི། </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="400"/>
|
||||
<location filename="../search.cpp" line="402"/>
|
||||
<location filename="../search.cpp" line="446"/>
|
||||
<source>FileType: </source>
|
||||
<translation>ཡིག་ཆའི་རིགས་དབྱིབས་ནི། </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="401"/>
|
||||
<location filename="../search.cpp" line="403"/>
|
||||
<location filename="../search.cpp" line="447"/>
|
||||
<source>Cancel</source>
|
||||
<translation>ཕྱིར་འཐེན།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="417"/>
|
||||
<location filename="../search.cpp" line="421"/>
|
||||
<location filename="../search.cpp" line="425"/>
|
||||
<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>
|
||||
<translation>ཐ་ཚིག་སྒྲོག་པ།</translation>
|
||||
</message>
|
||||
|
@ -110,9 +155,8 @@
|
|||
<translation>སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་ཐབས་ལམ་སྟོང་བ་རེད།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="421"/>
|
||||
<source>Add blocked folder failed, it is not in home path!</source>
|
||||
<translation>སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་མི་ཁྱིམ་དཀར་ཆག་འོག།</translation>
|
||||
<translation type="vanished">སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་མི་ཁྱིམ་དཀར་ཆག་འོག།</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="425"/>
|
||||
|
@ -124,5 +168,35 @@
|
|||
<source>Add blocked folder failed, it has been already blocked!</source>
|
||||
<translation>སྦྱོར་རྟ་ལྐོག་བཀོད་མིང་ཐོ་ཕམ་ཁ་བསལ་འདེམས་ཀྱི་དཀར་ཆག་ནི་ལྐོག་བཀོད་མིང་ཐོ་འི་ཁྲོད་ཀྱི་དཀར་ཆག་འོག</translation>
|
||||
</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>
|
||||
</TS>
|
||||
|
|
|
@ -5,50 +5,49 @@
|
|||
<name>Search</name>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="13"/>
|
||||
<location filename="../search.cpp" line="121"/>
|
||||
<location filename="../search.cpp" line="179"/>
|
||||
<source>Search</source>
|
||||
<translation>全局搜索</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="145"/>
|
||||
<location filename="../search.cpp" line="215"/>
|
||||
<source>Create index</source>
|
||||
<translation>创建索引</translation>
|
||||
<extra-contents_path>/Search/Create index</extra-contents_path>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="146"/>
|
||||
<location filename="../search.cpp" line="216"/>
|
||||
<source>Creating index can help you getting results quickly.</source>
|
||||
<translation>开启之后可以快速获取搜索结果</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="165"/>
|
||||
<location filename="../search.cpp" line="184"/>
|
||||
<source>Default web searching engine</source>
|
||||
<translation>默认互联网搜索引擎</translation>
|
||||
<extra-contents_path>/Search/Default web searching engine</extra-contents_path>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="169"/>
|
||||
<location filename="../search.cpp" line="188"/>
|
||||
<source>baidu</source>
|
||||
<translation>百度</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="170"/>
|
||||
<location filename="../search.cpp" line="189"/>
|
||||
<source>sougou</source>
|
||||
<translation>搜狗</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="171"/>
|
||||
<location filename="../search.cpp" line="190"/>
|
||||
<source>360</source>
|
||||
<translation>360</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="179"/>
|
||||
<location filename="../search.cpp" line="322"/>
|
||||
<source>Block Folders</source>
|
||||
<translation>排除的文件夹</translation>
|
||||
<extra-contents_path>/Search/Block Folders</extra-contents_path>
|
||||
</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>
|
||||
<translation>搜索将不查看以下文件夹,通过添加和删除可以设置排除的文件夹位置</translation>
|
||||
</message>
|
||||
|
@ -57,50 +56,96 @@
|
|||
<translation type="vanished">添加</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="340"/>
|
||||
<location filename="../search.cpp" line="634"/>
|
||||
<location filename="../search.cpp" line="705"/>
|
||||
<source>delete</source>
|
||||
<translation>删除</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="395"/>
|
||||
<location filename="../search.cpp" line="397"/>
|
||||
<location filename="../search.cpp" line="441"/>
|
||||
<source>Directories</source>
|
||||
<translation>文件夹</translation>
|
||||
</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>
|
||||
<translation>选择排除的文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="397"/>
|
||||
<location filename="../search.cpp" line="399"/>
|
||||
<location filename="../search.cpp" line="443"/>
|
||||
<source>Select</source>
|
||||
<translation>选择</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="398"/>
|
||||
<location filename="../search.cpp" line="400"/>
|
||||
<location filename="../search.cpp" line="444"/>
|
||||
<source>Position: </source>
|
||||
<translation>位置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="399"/>
|
||||
<location filename="../search.cpp" line="401"/>
|
||||
<location filename="../search.cpp" line="445"/>
|
||||
<source>FileName: </source>
|
||||
<translation>文件名</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="400"/>
|
||||
<location filename="../search.cpp" line="402"/>
|
||||
<location filename="../search.cpp" line="446"/>
|
||||
<source>FileType: </source>
|
||||
<translation>类型</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="401"/>
|
||||
<location filename="../search.cpp" line="403"/>
|
||||
<location filename="../search.cpp" line="447"/>
|
||||
<source>Cancel</source>
|
||||
<translation>取消</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="417"/>
|
||||
<location filename="../search.cpp" line="421"/>
|
||||
<location filename="../search.cpp" line="425"/>
|
||||
<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>
|
||||
<translation>警告</translation>
|
||||
</message>
|
||||
|
@ -110,9 +155,8 @@
|
|||
<translation>添加失败,选择的路径为空!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="421"/>
|
||||
<source>Add blocked folder failed, it is not in home path!</source>
|
||||
<translation>添加失败,添加的路径不在家目录下!</translation>
|
||||
<translation type="vanished">添加失败,添加的路径不在家目录下!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../search.cpp" line="425"/>
|
||||
|
@ -124,5 +168,35 @@
|
|||
<source>Add blocked folder failed, it has been already blocked!</source>
|
||||
<translation>添加失败,这个文件夹已经被添加过了!</translation>
|
||||
</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>
|
||||
</TS>
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
<node>
|
||||
<interface name="org.ukui.search.fileindex">
|
||||
<method name="appendIndexableListItem">
|
||||
<arg type="i" direction="out"/>
|
||||
<arg name="path" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="removeIndexableListItem">
|
||||
<arg type="b" direction="out"/>
|
||||
<arg name="path" type="s" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
|
|
|
@ -33,15 +33,19 @@ DirWatcherAdaptor::~DirWatcherAdaptor()
|
|||
// destructor
|
||||
}
|
||||
|
||||
void DirWatcherAdaptor::appendIndexableListItem(const QString &path)
|
||||
int DirWatcherAdaptor::appendIndexableListItem(const QString &path)
|
||||
{
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,11 @@ class DirWatcherAdaptor: public QDBusAbstractAdaptor
|
|||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"org.ukui.search.fileindex\">\n"
|
||||
" <method name=\"appendIndexableListItem\">\n"
|
||||
" <arg direction=\"out\" type=\"i\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"removeIndexableListItem\">\n"
|
||||
" <arg direction=\"out\" type=\"b\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"path\"/>\n"
|
||||
" </method>\n"
|
||||
" </interface>\n"
|
||||
|
@ -46,8 +48,8 @@ public:
|
|||
|
||||
public: // PROPERTIES
|
||||
public Q_SLOTS: // METHODS
|
||||
void appendIndexableListItem(const QString &path);
|
||||
void removeIndexableListItem(const QString &path);
|
||||
int appendIndexableListItem(const QString &path);
|
||||
bool removeIndexableListItem(const QString &path);
|
||||
Q_SIGNALS: // SIGNALS
|
||||
};
|
||||
|
||||
|
|
|
@ -56,11 +56,25 @@ DirWatcher *DirWatcher::getDirWatcher()
|
|||
QStringList DirWatcher::currentIndexableDir()
|
||||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
this->updateIndexableDirs();
|
||||
return m_indexableDirList;
|
||||
}
|
||||
|
||||
void DirWatcher::updateIndexableDirs()
|
||||
{
|
||||
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
|
||||
m_indexableDirList = m_qSettings->value(INDEXABLE_DIR_VALUE).toStringList();
|
||||
m_qSettings->endGroup();
|
||||
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()
|
||||
|
@ -70,28 +84,30 @@ QStringList DirWatcher::currentBlackListOfIndex()
|
|||
return blackListOfIndex;
|
||||
}
|
||||
|
||||
void DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackList)
|
||||
bool DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackList)
|
||||
{
|
||||
//排除要添加的路径已被索引的情况
|
||||
if (m_indexableDirList.contains(path)) {
|
||||
qDebug() << QString("index path %1 is already added.").arg(path);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
//处理添加路径非根目录时,要添加索引的路径与已索引路径为父子关系的情况
|
||||
if (path != "/") {
|
||||
QString indexablePath;
|
||||
QStringList tmp = m_indexableDirList;
|
||||
for (int i = 0; i < m_indexableDirList.length(); i++) {
|
||||
indexablePath = m_indexableDirList.at(i);
|
||||
if (path.startsWith(indexablePath + "/")) {
|
||||
qCritical() << QString("The parent of the path:%1 has been added.").arg(path);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (indexablePath.startsWith(path + "/")) {
|
||||
m_indexableDirList.removeAll(indexablePath);
|
||||
tmp.removeAll(indexablePath);
|
||||
blackList.append(indexablePath);
|
||||
}
|
||||
}
|
||||
m_indexableDirList = tmp;
|
||||
}
|
||||
|
||||
m_indexableDirList << path;
|
||||
|
@ -101,20 +117,22 @@ void DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackLi
|
|||
blackList.removeDuplicates();
|
||||
Q_EMIT this->appendIndexItem(path, blackList);
|
||||
qDebug() << "index path:" << path << "blacklist:" << blackList;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirWatcher::handleIndexItemRemove(const QString &path)
|
||||
bool DirWatcher::handleIndexItemRemove(const QString &path)
|
||||
{
|
||||
this->currentIndexableDir();
|
||||
QMutexLocker locker(&s_mutex);
|
||||
if (!m_indexableDirList.contains(path)) {
|
||||
qWarning() << QString("The path: %1 is not indexed").arg(path);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
m_indexableDirList.removeAll(path);
|
||||
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
|
||||
m_qSettings->setValue(INDEXABLE_DIR_VALUE, m_indexableDirList);
|
||||
m_qSettings->endGroup();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,13 +296,24 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di
|
|||
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不存在的情况
|
||||
QFile file(path);
|
||||
if (!file.exists()) {
|
||||
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 == "/") {
|
||||
this->handleIndexItemAppend(path, m_blackListOfIndex);
|
||||
return;
|
||||
if (!this->handleIndexItemAppend(path, m_blackListOfIndex)) {
|
||||
resultCode = -1;
|
||||
}
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
//处理要添加索引的路径与索引黑名单中路径为父子关系的情况
|
||||
for (const QString& blackListPath : m_blackListOfIndex) {
|
||||
if (path.startsWith(blackListPath + "/") or path == blackListPath) {
|
||||
qCritical() << QString("path:%1 is or under the blacklistpath:%2.").arg(path, blackListPath);
|
||||
return;
|
||||
resultCode = -2;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
if (blackListPath.startsWith(path + "/")) {
|
||||
|
@ -348,7 +380,8 @@ void DirWatcher::appendIndexableListItem(const QString &path)
|
|||
//(1)(4)直接返回
|
||||
if (pathToBeAddedIsRepeatedDevice and addedPathHasRepeatedDevice) {
|
||||
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)将要添加索引目录相应的重复挂载路径添加到黑名单
|
||||
if (pathToBeAddedHasRepeatedDevice and addedPathHasRepeatedDevice) {
|
||||
|
@ -360,7 +393,8 @@ void DirWatcher::appendIndexableListItem(const QString &path)
|
|||
QString pathAfterReplace = repeatedDir + addedRelativeDir;
|
||||
if (path.startsWith(pathAfterReplace) or path == pathAfterReplace) {
|
||||
qCritical() << QString("another path:%1 which is in the same device has been indexed").arg(pathAfterReplace);
|
||||
return;
|
||||
resultCode = -4;
|
||||
return resultCode;
|
||||
} else {
|
||||
blackList.append(pathAfterReplace);
|
||||
break;
|
||||
|
@ -405,19 +439,26 @@ void DirWatcher::appendIndexableListItem(const QString &path)
|
|||
|
||||
if (path.startsWith(spec + "/") or path == spec) {
|
||||
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);
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
|
||||
void DirWatcher::initData()
|
||||
|
@ -437,9 +478,11 @@ void DirWatcher::initData()
|
|||
*/
|
||||
//将磁盘分区后其他分区都会挂载到media下,多块硬盘也会挂到media,因此media放开,mnt同理;
|
||||
//backup是备份文件,tmp是临时文件,也都放开
|
||||
m_blackListOfIndex << "/boot" << "/bin" << "/dev" << "/etc" << "/usr" << "/var"
|
||||
<< "/lib" << "/lib32" << "/lib64" << "/libx32" << "/cdrom"
|
||||
<< "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt";
|
||||
// m_blackListOfIndex << "/boot" << "/bin" << "/dev" << "/etc" << "/usr" << "/var"
|
||||
// << "/lib" << "/lib32" << "/lib64" << "/libx32" << "/cdrom"
|
||||
// << "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt";
|
||||
//专用机需求:只屏蔽/proc, /sys, /dev, /tmp, /run
|
||||
m_blackListOfIndex << "/proc" << "/sys" << "/dev" << "/tmp" << "/run";
|
||||
|
||||
//目前方案:可搜索目录(服务)默认根目录,可搜索目录(应用)默认家目录和/data目录
|
||||
QDir dir("/data");
|
||||
|
@ -553,13 +596,13 @@ void DirWatcher::handleDisk()
|
|||
}
|
||||
}
|
||||
|
||||
//将u盘设备在/data和/home下的所有挂载点添加到索引黑名单, 目前由于未知原因收不到udisk挂载信号因此暂时不生效
|
||||
//将u盘设备添加到索引黑名单
|
||||
if (!m_currentUDiskDeviceInfo.isEmpty()) {
|
||||
for (auto t = m_currentUDiskDeviceInfo.constBegin(); t != m_currentUDiskDeviceInfo.constEnd(); t++) {
|
||||
for (QString udiskDevice: t.value()) {
|
||||
if (udiskDevice.startsWith("/data") || udiskDevice.startsWith("/home")) {
|
||||
// if (udiskDevice.startsWith("/data") || udiskDevice.startsWith("/home")) {
|
||||
m_blackListOfIndex.append(udiskDevice);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,19 +48,32 @@ public Q_SLOTS:
|
|||
QStringList searchableDirForSearchApplication();
|
||||
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:
|
||||
DirWatcher(QObject *parent = nullptr);
|
||||
~DirWatcher();
|
||||
void initData();
|
||||
void initDiskWatcher();
|
||||
void updateIndexableDirs();
|
||||
|
||||
void handleDisk();
|
||||
|
||||
void handleIndexItemAppend(const QString &path, QStringList &blackList);
|
||||
void handleIndexItemRemove(const QString &path);
|
||||
bool handleIndexItemAppend(const QString &path, QStringList &blackList);
|
||||
bool handleIndexItemRemove(const QString &path);
|
||||
|
||||
static QMutex s_mutex;
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ void UkuiSearchDirManagerDbus::parseCmd(QString msg, bool isPrimary)
|
|||
parser.addOption(quitOption);
|
||||
|
||||
if (isPrimary) {
|
||||
const QStringList args = QString(msg).split(' ');
|
||||
parser.process(args);
|
||||
if (parser.isSet(quitOption)) {
|
||||
qApp->quit();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue