增加文件内容模糊搜索功能,优化全局设置代码
This commit is contained in:
parent
3d8cebba41
commit
134d2039ec
|
@ -10,5 +10,10 @@
|
||||||
<summary>web engine</summary>
|
<summary>web engine</summary>
|
||||||
<description>Web engine to search keyword online.</description>
|
<description>Web engine to search keyword online.</description>
|
||||||
</key>
|
</key>
|
||||||
|
<key name="content-fuzzy-search" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>content fuzzy search</summary>
|
||||||
|
<description>Enable or disable fuzzy search for file content.</description>
|
||||||
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
|
|
@ -5,10 +5,10 @@ INCLUDEPATH += $$PWD
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/search-line-edit.h \
|
$$PWD/search-line-edit.h \
|
||||||
$$PWD/settings-widget.h \
|
# $$PWD/settings-widget.h \
|
||||||
$$PWD/create-index-ask-dialog.h \
|
$$PWD/create-index-ask-dialog.h \
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/search-line-edit.cpp \
|
$$PWD/search-line-edit.cpp \
|
||||||
$$PWD/settings-widget.cpp \
|
# $$PWD/settings-widget.cpp \
|
||||||
$$PWD/create-index-ask-dialog.cpp \
|
$$PWD/create-index-ask-dialog.cpp \
|
||||||
|
|
|
@ -29,11 +29,8 @@
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
#include <KWindowEffects>
|
#include <KWindowEffects>
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
|
|
||||||
#endif
|
|
||||||
#include <QtX11Extras/QX11Info>
|
#include <QtX11Extras/QX11Info>
|
||||||
#include "ukuistylehelper/ukuistylehelper.h"
|
#include "ukuistylehelper/ukuistylehelper.h"
|
||||||
#include "windowmanager/windowmanager.h"
|
#include "windowmanager/windowmanager.h"
|
||||||
|
@ -42,9 +39,6 @@
|
||||||
|
|
||||||
#define MAIN_MARGINS 0, 0, 0, 0
|
#define MAIN_MARGINS 0, 0, 0, 0
|
||||||
#define TITLE_MARGINS 0,0,0,0
|
#define TITLE_MARGINS 0,0,0,0
|
||||||
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
|
|
||||||
#define SEARCH_METHOD_KEY "fileIndexEnable"
|
|
||||||
#define WEB_ENGINE_KEY "webEngine"
|
|
||||||
#define WINDOW_WIDTH 700
|
#define WINDOW_WIDTH 700
|
||||||
#define WINDOW_HEIGHT 610
|
#define WINDOW_HEIGHT 610
|
||||||
#define TITLE_HEIGHT 40
|
#define TITLE_HEIGHT 40
|
||||||
|
@ -54,6 +48,10 @@
|
||||||
#define ASK_INDEX_TIME 5*1000
|
#define ASK_INDEX_TIME 5*1000
|
||||||
#define RESEARCH_TIME 10*1000
|
#define RESEARCH_TIME 10*1000
|
||||||
|
|
||||||
|
#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf"
|
||||||
|
#define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog"
|
||||||
|
|
||||||
|
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||||||
/**
|
/**
|
||||||
|
@ -72,6 +70,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
this->setWindowTitle(tr("ukui-search"));
|
this->setWindowTitle(tr("ukui-search"));
|
||||||
KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher );
|
KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher );
|
||||||
|
initSettings();
|
||||||
initUi();
|
initUi();
|
||||||
initTimer();
|
initTimer();
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
m_sys_tray_icon->show();
|
m_sys_tray_icon->show();
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
initConnections();
|
initConnections();
|
||||||
initGsettings();
|
|
||||||
|
|
||||||
// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){
|
// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){
|
||||||
// qDebug() << "activeWindowChanged!!!" << activeWindowId;
|
// qDebug() << "activeWindowChanged!!!" << activeWindowId;
|
||||||
|
@ -97,19 +96,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
this->setText(keyword);
|
this->setText(keyword);
|
||||||
});
|
});
|
||||||
connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow);
|
connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow);
|
||||||
//NEW_TODO, register plugins
|
|
||||||
// SearchPluginManager::getInstance()->registerPlugin(\\);
|
|
||||||
// m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds());
|
|
||||||
// m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
if(m_settingsWidget) {
|
|
||||||
delete m_settingsWidget;
|
|
||||||
m_settingsWidget = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if(m_askDialog) {
|
if(m_askDialog) {
|
||||||
delete m_askDialog;
|
delete m_askDialog;
|
||||||
m_askDialog = NULL;
|
m_askDialog = NULL;
|
||||||
|
@ -118,9 +107,9 @@ MainWindow::~MainWindow() {
|
||||||
delete m_askTimer;
|
delete m_askTimer;
|
||||||
m_askTimer = NULL;
|
m_askTimer = NULL;
|
||||||
}
|
}
|
||||||
if(m_search_gsettings) {
|
if(m_searchGsettings) {
|
||||||
delete m_search_gsettings;
|
delete m_searchGsettings;
|
||||||
m_search_gsettings = NULL;
|
m_searchGsettings = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,17 +118,7 @@ MainWindow::~MainWindow() {
|
||||||
*/
|
*/
|
||||||
void MainWindow::initUi() {
|
void MainWindow::initUi() {
|
||||||
this->setFixedSize(WINDOW_WIDTH, 68);
|
this->setFixedSize(WINDOW_WIDTH, 68);
|
||||||
// this->setStyleSheet("QMainWindow{border:2px solid red;}");
|
|
||||||
|
|
||||||
// m_widget = new QWidget(this);
|
|
||||||
|
|
||||||
// this->setCentralWidget(m_widget);
|
|
||||||
// m_widget->setFixedSize(this->size());
|
|
||||||
// QVBoxLayout * mainlayout = new QVBoxLayout(m_frame);
|
|
||||||
// mainlayout->setContentsMargins(MAIN_MARGINS);
|
|
||||||
// m_frame->setLayout(mainlayout);
|
|
||||||
|
|
||||||
// m_stackedWidget = new StackedWidget(m_frame);//内容栏
|
|
||||||
m_searchBarWidget = new SeachBarWidget(this);
|
m_searchBarWidget = new SeachBarWidget(this);
|
||||||
m_searchBarWidget->move(this->rect().topLeft());
|
m_searchBarWidget->move(this->rect().topLeft());
|
||||||
m_searchBarWidget->show();
|
m_searchBarWidget->show();
|
||||||
|
@ -148,41 +127,20 @@ void MainWindow::initUi() {
|
||||||
m_searchResultPage->move(0, 58);
|
m_searchResultPage->move(0, 58);
|
||||||
this->setFocusProxy(m_searchBarWidget);
|
this->setFocusProxy(m_searchBarWidget);
|
||||||
|
|
||||||
// m_searchResultPage->show();
|
|
||||||
// m_searchWidget = new SeachBarWidget(this);
|
|
||||||
// m_searchLayout = new SearchBarHLayout(this);
|
|
||||||
// m_searchWidget->setLayout(m_searchLayout);
|
|
||||||
// m_searchWidget->setFixedHeight(SEARCH_BAR_SIZE);
|
|
||||||
|
|
||||||
// mainlayout->addWidget(m_titleFrame);
|
|
||||||
// mainlayout->addWidget(m_seachBarWidget);
|
|
||||||
// mainlayout->addSpacing(8);
|
|
||||||
// mainlayout->addWidget(m_searchResultPage);
|
|
||||||
|
|
||||||
//创建索引询问弹窗
|
//创建索引询问弹窗
|
||||||
m_askDialog = new CreateIndexAskDialog(this);
|
m_askDialog = new CreateIndexAskDialog(this);
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
// MotifWmHints ask_dialog_hints;
|
|
||||||
// ask_dialog_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
|
|
||||||
// ask_dialog_hints.functions = MWM_FUNC_ALL;
|
|
||||||
// ask_dialog_hints.decorations = MWM_DECOR_BORDER;
|
|
||||||
// XAtomHelper::getInstance()->setWindowMotifHint(m_askDialog->winId(), ask_dialog_hints);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initConnections()
|
void MainWindow::initConnections()
|
||||||
{
|
{
|
||||||
connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot);
|
connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot);
|
||||||
QObject::connect(this, &MainWindow::searchMethodChanged, this, [ = ](FileUtils::SearchMethod sm) {
|
|
||||||
FileUtils::searchMethod = sm;
|
|
||||||
});
|
|
||||||
connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange);
|
connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange);
|
||||||
connect(qApp, &QApplication::primaryScreenChanged, this, &MainWindow::primaryScreenChangedSlot);
|
connect(qApp, &QApplication::primaryScreenChanged, this, &MainWindow::primaryScreenChangedSlot);
|
||||||
connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() {
|
connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() {
|
||||||
m_isAskDialogVisible = false;
|
m_isAskDialogVisible = false;
|
||||||
});
|
});
|
||||||
connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &is_create_index, const bool &is_ask_again) {
|
connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) {
|
||||||
setSearchMethodConfig(is_create_index, is_ask_again);
|
setSearchMethodConfig(isCreateIndex, isAskAgain);
|
||||||
});
|
});
|
||||||
// connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot);
|
// connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot);
|
||||||
//主题改变时,更新自定义标题栏的图标
|
//主题改变时,更新自定义标题栏的图标
|
||||||
|
@ -242,74 +200,28 @@ void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason)
|
||||||
* @param create_index 是否同意创建索引
|
* @param create_index 是否同意创建索引
|
||||||
* @param no_longer_ask 是否勾选了不再提示
|
* @param no_longer_ask 是否勾选了不再提示
|
||||||
*/
|
*/
|
||||||
void MainWindow::setSearchMethodConfig(const bool &create_index, const bool &no_longer_ask)
|
void MainWindow::setSearchMethodConfig(const bool& createIndex, const bool& noLongerAsk)
|
||||||
{
|
{
|
||||||
if(no_longer_ask) {
|
if(noLongerAsk) {
|
||||||
GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "false");
|
m_settings->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, false);
|
||||||
} else {
|
} else {
|
||||||
GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "true");
|
m_settings->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, true);
|
||||||
}
|
}
|
||||||
if(create_index) {
|
if(createIndex) {
|
||||||
if(m_search_gsettings && m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
|
if(m_searchGsettings && m_searchGsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
||||||
m_search_gsettings->set(SEARCH_METHOD_KEY, true);
|
m_searchGsettings->set(FILE_INDEX_ENABLE_KEY, true);
|
||||||
}
|
}
|
||||||
Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH);
|
|
||||||
//创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索)
|
//创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索)
|
||||||
m_researchTimer->start();
|
m_researchTimer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MainWindow::settingsBtnClickedSlot 点击设置按钮的槽函数
|
|
||||||
*/
|
|
||||||
void MainWindow::settingsBtnClickedSlot()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
if(m_settingsWidget) { //当此窗口已存在时,仅需置顶
|
|
||||||
if(!m_settingsWidget->isVisible()) {
|
|
||||||
centerToScreen(m_settingsWidget);
|
|
||||||
}
|
|
||||||
m_settingsWidget->showWidget();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_settingsWidget = new SettingsWidget();
|
|
||||||
connect(this, &MainWindow::webEngineChanged, m_settingsWidget, [ = ]() {
|
|
||||||
m_settingsWidget->resetWebEngine();
|
|
||||||
});
|
|
||||||
connect(m_settingsWidget, &SettingsWidget::webEngineChanged, this, [ = ](const QString & engine) {
|
|
||||||
if(m_search_gsettings && m_search_gsettings->keys().contains(WEB_ENGINE_KEY)) {
|
|
||||||
m_search_gsettings->set(WEB_ENGINE_KEY, engine);
|
|
||||||
} else {
|
|
||||||
GlobalSettings::getInstance()->setValue(WEB_ENGINE, engine);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
centerToScreen(m_settingsWidget);
|
|
||||||
m_settingsWidget->show();
|
|
||||||
connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() {
|
|
||||||
QTimer::singleShot(100, this, [ = ] {
|
|
||||||
// clearSearchResult(); //现暂定从设置页返回主页面不清空搜索结果
|
|
||||||
this->setWindowState(this->windowState() & ~Qt::WindowMinimized);
|
|
||||||
this->raise();
|
|
||||||
this->showNormal();
|
|
||||||
this->activateWindow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
//打开控制面板的设置页
|
|
||||||
QProcess process;
|
|
||||||
process.startDetached("ukui-control-center -m search");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MainWindow::searchKeywordSlot 执行搜索的槽函数
|
* @brief MainWindow::searchKeywordSlot 执行搜索的槽函数
|
||||||
* @param keyword 关键词
|
* @param keyword 关键词
|
||||||
*/
|
*/
|
||||||
void MainWindow::searchKeywordSlot(const QString &keyword)
|
void MainWindow::searchKeywordSlot(const QString &keyword)
|
||||||
{
|
{
|
||||||
//NEW_TODO
|
if(keyword == "" || keyword.isEmpty()) {
|
||||||
if(keyword == "") {
|
|
||||||
// m_stackedWidget->setPage(int(StackedPage::HomePage));
|
// m_stackedWidget->setPage(int(StackedPage::HomePage));
|
||||||
QTimer::singleShot(10, this, [ = ]() {
|
QTimer::singleShot(10, this, [ = ]() {
|
||||||
m_askTimer->stop();
|
m_askTimer->stop();
|
||||||
|
@ -319,11 +231,13 @@ void MainWindow::searchKeywordSlot(const QString &keyword)
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// m_stackedWidget->setPage(int(StackedPage::SearchPage));
|
|
||||||
QTimer::singleShot(10, this, [ = ]() {
|
QTimer::singleShot(10, this, [ = ]() {
|
||||||
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
||||||
if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH)
|
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG).toBool()
|
||||||
|
&& !m_currentSearchAsked
|
||||||
|
&& GlobalSettings::getInstance()->getValue(FILE_INDEX_ENABLE_KEY).toBool() == false) {
|
||||||
m_askTimer->start();
|
m_askTimer->start();
|
||||||
|
}
|
||||||
Q_EMIT m_searchResultPage->startSearch(keyword);
|
Q_EMIT m_searchResultPage->startSearch(keyword);
|
||||||
this->resizeHeight(WINDOW_HEIGHT);
|
this->resizeHeight(WINDOW_HEIGHT);
|
||||||
|
|
||||||
|
@ -428,16 +342,6 @@ void MainWindow::centerToScreen(QWidget* widget) {
|
||||||
int desk_y = desk_rect.height();
|
int desk_y = desk_rect.height();
|
||||||
int x = widget->width();
|
int x = widget->width();
|
||||||
int y = widget->height();
|
int y = widget->height();
|
||||||
// QDBusInterface primaryScreenInterface("org.ukui.SettingsDaemon",
|
|
||||||
// "/org/ukui/SettingsDaemon/wayland",
|
|
||||||
// "org.ukui.SettingsDaemon.wayland",
|
|
||||||
// QDBusConnection::sessionBus());
|
|
||||||
// if(QDBusReply<int>(primaryScreenInterface.call("x")).isValid()) {
|
|
||||||
// QDBusReply<int> width = primaryScreenInterface.call("width");
|
|
||||||
// QDBusReply<int> height = primaryScreenInterface.call("height");
|
|
||||||
// desk_x = width;
|
|
||||||
// desk_y = height;
|
|
||||||
// }
|
|
||||||
widget->show();
|
widget->show();
|
||||||
kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(),
|
||||||
desk_y / 3 + desk_rect.top(),
|
desk_y / 3 + desk_rect.top(),
|
||||||
|
@ -450,29 +354,20 @@ void MainWindow::centerToScreen(QWidget* widget) {
|
||||||
// widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 3 + desk_rect.top());
|
// widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 3 + desk_rect.top());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initGsettings() {
|
void MainWindow::initSettings() {
|
||||||
const QByteArray id(UKUI_SEARCH_SCHEMAS);
|
const QByteArray id(UKUI_SEARCH_SCHEMAS);
|
||||||
if(QGSettings::isSchemaInstalled(id)) {
|
if(QGSettings::isSchemaInstalled(id)) {
|
||||||
m_search_gsettings = new QGSettings(id);
|
m_searchGsettings = new QGSettings(id);
|
||||||
connect(m_search_gsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
connect(m_searchGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
||||||
if(key == SEARCH_METHOD_KEY) {
|
if(key == FILE_INDEX_ENABLE_KEY) {
|
||||||
bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool();
|
bool isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
||||||
this->setSearchMethod(is_index_search);
|
if(m_researchTimer->isActive() && !isIndexSearch) {
|
||||||
} else if(key == WEB_ENGINE_KEY) {
|
m_researchTimer->stop();
|
||||||
QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString();
|
}
|
||||||
GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine);
|
|
||||||
Q_EMIT this->webEngineChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
|
|
||||||
bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool();
|
|
||||||
this->setSearchMethod(is_index_search);
|
|
||||||
}
|
|
||||||
if(m_search_gsettings->keys().contains(WEB_ENGINE_KEY)) {
|
|
||||||
QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString();
|
|
||||||
GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
m_settings = new QSettings(MAIN_SETTINGS, QSettings::IniFormat, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用GSetting获取当前窗口应该使用的透明度
|
//使用GSetting获取当前窗口应该使用的透明度
|
||||||
|
@ -509,7 +404,7 @@ void MainWindow::initTimer() {
|
||||||
m_askTimer->stop();
|
m_askTimer->stop();
|
||||||
} else {
|
} else {
|
||||||
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
|
||||||
if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH)
|
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG).toBool() && !m_currentSearchAsked && GlobalSettings::getInstance()->getValue(FILE_INDEX_ENABLE_KEY).toBool() == false)
|
||||||
m_askTimer->start();
|
m_askTimer->start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -539,11 +434,8 @@ bool MainWindow::tryHideMainwindow()
|
||||||
* @brief MainWindow::setSearchMethod 设置搜索模式
|
* @brief MainWindow::setSearchMethod 设置搜索模式
|
||||||
* @param is_index_search true为索引搜索,false为暴力搜索
|
* @param is_index_search true为索引搜索,false为暴力搜索
|
||||||
*/
|
*/
|
||||||
void MainWindow::setSearchMethod(const bool &is_index_search) {
|
void MainWindow::setSearchMethod(const bool isIndexSearch) {
|
||||||
if(is_index_search) {
|
if(!isIndexSearch) {
|
||||||
Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH);
|
|
||||||
} else {
|
|
||||||
Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::DIRECTSEARCH);
|
|
||||||
m_researchTimer->stop();
|
m_researchTimer->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,14 +69,13 @@ public:
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
/**
|
/**
|
||||||
* @brief Load the main window
|
* @brief Load the main window
|
||||||
|
* The position which mainwindow shows follow the ukui-panel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// The position which mainwindow shows follow the ukui-panel.
|
|
||||||
void moveToPanel();
|
void moveToPanel();
|
||||||
|
|
||||||
// The position which mainwindow shows in the center of screen where the cursor in.
|
// The position which mainwindow shows in the center of screen where the cursor in.
|
||||||
void centerToScreen(QWidget* widget);
|
void centerToScreen(QWidget* widget);
|
||||||
void initGsettings();
|
void initSettings();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
|
@ -87,11 +86,6 @@ protected:
|
||||||
public:
|
public:
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void searchMethodChanged(FileUtils::SearchMethod);
|
|
||||||
void webEngineChanged();
|
|
||||||
void setText(QString keyword);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* @brief Monitor screen resolution
|
* @brief Monitor screen resolution
|
||||||
|
@ -103,53 +97,37 @@ public Q_SLOTS:
|
||||||
* @param screen: Primary screen
|
* @param screen: Primary screen
|
||||||
*/
|
*/
|
||||||
void primaryScreenChangedSlot(QScreen *screen);
|
void primaryScreenChangedSlot(QScreen *screen);
|
||||||
|
|
||||||
void bootOptionsFilter(QString opt); // 过滤终端命令
|
void bootOptionsFilter(QString opt); // 过滤终端命令
|
||||||
void clearSearchResult(); //清空搜索结果
|
void clearSearchResult(); //清空搜索结果
|
||||||
void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);
|
void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);
|
||||||
void settingsBtnClickedSlot();
|
|
||||||
void searchKeywordSlot(const QString&);
|
void searchKeywordSlot(const QString&);
|
||||||
void resizeHeight(int height);
|
void resizeHeight(int height);
|
||||||
void tryHide();
|
void tryHide();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void setText(QString keyword);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setSearchMethod(const bool isIndexSearch);
|
||||||
QWidget *m_widget = nullptr; // central widget
|
|
||||||
QFrame * m_titleFrame = nullptr; // Title bar frame
|
|
||||||
QHBoxLayout * m_titleLyt = nullptr; // Title layout
|
|
||||||
QLabel * m_iconLabel = nullptr; // Icon lable
|
|
||||||
QLabel * m_titleLabel = nullptr; // Title lable
|
|
||||||
QPushButton * m_settingsBtn = nullptr; // Menu button
|
|
||||||
// StackedWidget * m_stackedWidget = nullptr; // Stacked widget
|
|
||||||
// SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
|
|
||||||
// SeachBarWidget * m_searchWidget = nullptr; // Search bar
|
|
||||||
SeachBarWidget * m_searchBarWidget;
|
|
||||||
SearchResultPage * m_searchResultPage;
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
|
|
||||||
SettingsWidget * m_settingsWidget = nullptr; // Settings Widget
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QStringList m_dirList;
|
|
||||||
|
|
||||||
QQueue<QString> * m_search_result_file = nullptr;
|
|
||||||
QQueue<QString> * m_search_result_dir = nullptr;
|
|
||||||
QQueue<QPair<QString, QStringList>> * m_search_result_content = nullptr;
|
|
||||||
|
|
||||||
QSystemTrayIcon * m_sys_tray_icon = nullptr;
|
|
||||||
CreateIndexAskDialog * m_askDialog = nullptr;
|
|
||||||
bool m_isAskDialogVisible = false;
|
|
||||||
|
|
||||||
QTimer * m_askTimer = nullptr; //询问是否创建索引弹窗弹出的计时器
|
|
||||||
QTimer * m_researchTimer = nullptr; //创建索引后重新执行一次搜索的计时器
|
|
||||||
bool m_currentSearchAsked = false; //本次搜索是否已经询问过是否创建索引了
|
|
||||||
QGSettings * m_search_gsettings = nullptr;
|
|
||||||
AppWidgetPlugin *m_appWidgetPlugin = nullptr;
|
|
||||||
|
|
||||||
void setSearchMethod(const bool&);
|
|
||||||
double getTransparentData();
|
double getTransparentData();
|
||||||
void initTimer();
|
void initTimer();
|
||||||
bool tryHideMainwindow();
|
bool tryHideMainwindow();
|
||||||
void setSearchMethodConfig(const bool&, const bool&);
|
void setSearchMethodConfig(const bool& createIndex, const bool& noLongerAsk);
|
||||||
|
|
||||||
|
SeachBarWidget *m_searchBarWidget;
|
||||||
|
SearchResultPage *m_searchResultPage;
|
||||||
|
|
||||||
|
QSystemTrayIcon *m_sys_tray_icon = nullptr;
|
||||||
|
CreateIndexAskDialog *m_askDialog = nullptr;
|
||||||
|
bool m_isAskDialogVisible = false;
|
||||||
|
|
||||||
|
QTimer *m_askTimer = nullptr; //询问是否创建索引弹窗弹出的计时器
|
||||||
|
QTimer *m_researchTimer = nullptr; //创建索引后重新执行一次搜索的计时器
|
||||||
|
bool m_currentSearchAsked = false; //本次搜索是否已经询问过是否创建索引了
|
||||||
|
QGSettings *m_searchGsettings = nullptr;
|
||||||
|
QSettings *m_settings = nullptr;
|
||||||
|
AppWidgetPlugin *m_appWidgetPlugin = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
size_t FileUtils::maxIndexCount = 0;
|
size_t FileUtils::maxIndexCount = 0;
|
||||||
unsigned short FileUtils::indexStatus = 0;
|
unsigned short FileUtils::indexStatus = 0;
|
||||||
FileUtils::SearchMethod FileUtils::searchMethod = FileUtils::SearchMethod::DIRECTSEARCH;
|
|
||||||
QMap<QString, QStringList> FileUtils::map_chinese2pinyin = QMap<QString, QStringList>();
|
QMap<QString, QStringList> FileUtils::map_chinese2pinyin = QMap<QString, QStringList>();
|
||||||
static QMutex iconMutex;
|
static QMutex iconMutex;
|
||||||
|
|
||||||
|
|
|
@ -113,9 +113,6 @@ public:
|
||||||
static size_t maxIndexCount;
|
static size_t maxIndexCount;
|
||||||
static unsigned short indexStatus;
|
static unsigned short indexStatus;
|
||||||
|
|
||||||
enum class SearchMethod { DIRECTSEARCH = 0, INDEXSEARCH = 1};
|
|
||||||
static SearchMethod searchMethod;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void findNodes(const QDomElement &elem, QQueue<QString> &names, QList<QDomElement> &nodes);
|
static void findNodes(const QDomElement &elem, QQueue<QString> &names, QList<QDomElement> &nodes);
|
||||||
static inline void findNodesByAttr(const QDomElement&, QQueue<QString>&, QList<QDomElement>&, const QString &, const QStringList&);
|
static inline void findNodesByAttr(const QDomElement&, QQueue<QString>&, QList<QDomElement>&, const QString &, const QStringList&);
|
||||||
|
|
|
@ -23,32 +23,33 @@
|
||||||
#include "global-settings.h"
|
#include "global-settings.h"
|
||||||
|
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
static GlobalSettings *global_instance_of_global_settings = nullptr;
|
static GlobalSettings *globalInstance = nullptr;
|
||||||
|
|
||||||
GlobalSettings *GlobalSettings::getInstance() {
|
GlobalSettings *GlobalSettings::getInstance() {
|
||||||
if(!global_instance_of_global_settings) {
|
if(!globalInstance) {
|
||||||
global_instance_of_global_settings = new GlobalSettings;
|
globalInstance = new GlobalSettings;
|
||||||
}
|
}
|
||||||
return global_instance_of_global_settings;
|
return globalInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) {
|
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
||||||
m_settings = new QSettings(MAIN_SETTINGS, QSettings::IniFormat, this);
|
{
|
||||||
// m_settings->setAtomicSyncRequired(false);
|
//搜索黑名单过滤
|
||||||
m_block_dirs_settings = new QSettings(BLOCK_DIRS, QSettings::IniFormat, this);
|
m_blockDirsSettings = new QSettings(BLOCK_DIRS, QSettings::IniFormat, this);
|
||||||
m_block_dirs_settings->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
m_blockDirsSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
m_block_dirs_settings->setValue("These_are_block_dirs_conf_for_ukui_search","0");
|
m_blockDirsSettings->setValue("These_are_block_dirs_conf_for_ukui_search","0");
|
||||||
m_block_dirs_settings->sync();
|
m_blockDirsSettings->sync();
|
||||||
|
|
||||||
m_confWatcher = new QFileSystemWatcher(this);
|
m_confWatcher = new QFileSystemWatcher(this);
|
||||||
m_confWatcher->addPath(BLOCK_DIRS);
|
m_confWatcher->addPath(BLOCK_DIRS);
|
||||||
connect(m_confWatcher, &QFileSystemWatcher::fileChanged, this, [ & ]() {
|
connect(m_confWatcher, &QFileSystemWatcher::fileChanged, this, [ & ]() {
|
||||||
m_block_dirs_settings->sync();
|
m_blockDirsSettings->sync();
|
||||||
m_confWatcher->addPath(BLOCK_DIRS);
|
m_confWatcher->addPath(BLOCK_DIRS);
|
||||||
});
|
});
|
||||||
|
//搜索历史记录
|
||||||
m_search_record_settings = new QSettings(SEARCH_HISTORY, QSettings::IniFormat, this);
|
m_searchRecordSettings = new QSettings(SEARCH_HISTORY, QSettings::IniFormat, this);
|
||||||
m_search_record_settings->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
m_searchRecordSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
for(QString i : m_search_record_settings->allKeys()) {
|
for(QString i : m_searchRecordSettings->allKeys()) {
|
||||||
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
|
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
|
||||||
}
|
}
|
||||||
if(!QDBusConnection::sessionBus().connect("org.kylinssoclient.dbus",
|
if(!QDBusConnection::sessionBus().connect("org.kylinssoclient.dbus",
|
||||||
|
@ -56,86 +57,90 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) {
|
||||||
"org.freedesktop.kylinssoclient.interface",
|
"org.freedesktop.kylinssoclient.interface",
|
||||||
"keyChanged",
|
"keyChanged",
|
||||||
this, SLOT(updateSearchHistory(QString))))
|
this, SLOT(updateSearchHistory(QString))))
|
||||||
|
|
||||||
qWarning() << "Kylinssoclient Dbus connect fail!";
|
qWarning() << "Kylinssoclient Dbus connect fail!";
|
||||||
|
|
||||||
this->forceSync();
|
//全局页面透明度
|
||||||
//the default number of transparency in mainwindow is 0.7
|
//the default number of transparency for mainwindow is 0.7
|
||||||
//if someone changes the num in mainwindow, here should be modified too
|
setValue(TRANSPARENCY_KEY, 0.7);
|
||||||
m_cache.insert(TRANSPARENCY_KEY, 0.7);
|
|
||||||
if(QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) {
|
if(QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) {
|
||||||
m_trans_gsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this);
|
m_transGsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this);
|
||||||
connect(m_trans_gsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
connect(m_transGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
||||||
if(key == TRANSPARENCY_KEY) {
|
if(key == TRANSPARENCY_KEY) {
|
||||||
m_cache.remove(TRANSPARENCY_KEY);
|
setValue(TRANSPARENCY_KEY, m_transGsettings->get(TRANSPARENCY_KEY).toDouble());
|
||||||
m_cache.insert(TRANSPARENCY_KEY, m_trans_gsettings->get(TRANSPARENCY_KEY).toDouble());
|
|
||||||
qApp->paletteChanged(qApp->palette());
|
qApp->paletteChanged(qApp->palette());
|
||||||
Q_EMIT this->transparencyChanged(m_trans_gsettings->get(TRANSPARENCY_KEY).toDouble());
|
Q_EMIT this->transparencyChanged(m_transGsettings->get(TRANSPARENCY_KEY).toDouble());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_cache.remove(TRANSPARENCY_KEY);
|
if(m_transGsettings->keys().contains(TRANSPARENCY_KEY)) {
|
||||||
m_cache.insert(TRANSPARENCY_KEY, m_trans_gsettings->get(TRANSPARENCY_KEY).toDouble());
|
setValue(TRANSPARENCY_KEY, m_transGsettings->get(TRANSPARENCY_KEY).toDouble());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cache.insert(STYLE_NAME_KEY, "ukui-light");
|
//主题,字体大小
|
||||||
m_cache.insert(FONT_SIZE_KEY, 11);
|
setValue(STYLE_NAME_KEY, "ukui-light");
|
||||||
|
setValue(FONT_SIZE_KEY, 11);
|
||||||
if(QGSettings::isSchemaInstalled(THEME_GSETTINGS_ID)) {
|
if(QGSettings::isSchemaInstalled(THEME_GSETTINGS_ID)) {
|
||||||
m_theme_gsettings = new QGSettings(THEME_GSETTINGS_ID, QByteArray(), this);
|
m_themeGsettings = new QGSettings(THEME_GSETTINGS_ID, QByteArray(), this);
|
||||||
connect(m_theme_gsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
connect(m_themeGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
||||||
if(key == STYLE_NAME_KEY) {
|
if(key == STYLE_NAME_KEY) {
|
||||||
//当前主题改变时也发出paletteChanged信号,通知主界面刷新
|
//当前主题改变时也发出paletteChanged信号,通知主界面刷新
|
||||||
m_cache.remove(STYLE_NAME_KEY);
|
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
||||||
m_cache.insert(STYLE_NAME_KEY, m_theme_gsettings->get(STYLE_NAME_KEY).toString());
|
|
||||||
qApp->paletteChanged(qApp->palette());
|
qApp->paletteChanged(qApp->palette());
|
||||||
Q_EMIT this->styleChanged(m_theme_gsettings->get(STYLE_NAME_KEY).toString());
|
Q_EMIT this->styleChanged(m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
||||||
} else if(key == FONT_SIZE_KEY) {
|
} else if(key == FONT_SIZE_KEY) {
|
||||||
m_cache.remove(FONT_SIZE_KEY);
|
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble());
|
||||||
m_cache.insert(FONT_SIZE_KEY, m_theme_gsettings->get(FONT_SIZE_KEY).toDouble());
|
|
||||||
qApp->paletteChanged(qApp->palette());
|
qApp->paletteChanged(qApp->palette());
|
||||||
} else if (key == ICON_THEME_KEY) {
|
} else if (key == ICON_THEME_KEY) {
|
||||||
qApp->paletteChanged(qApp->palette());
|
qApp->paletteChanged(qApp->palette());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_cache.remove(STYLE_NAME_KEY);
|
if(m_themeGsettings->keys().contains(STYLE_NAME_KEY)) {
|
||||||
m_cache.insert(STYLE_NAME_KEY, m_theme_gsettings->get(STYLE_NAME_KEY).toString());
|
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
|
||||||
m_cache.remove(FONT_SIZE_KEY);
|
}
|
||||||
m_cache.insert(FONT_SIZE_KEY, m_theme_gsettings->get(FONT_SIZE_KEY).toDouble());
|
if(m_themeGsettings->keys().contains(FONT_SIZE_KEY)) {
|
||||||
|
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//文件索引与搜索插件相关设置
|
||||||
|
setValue(FILE_INDEX_ENABLE_KEY, false);
|
||||||
|
setValue(WEB_ENGINE_KEY, "baidu");
|
||||||
|
setValue(CONTENT_FUZZY_SEARCH_KEY, false);
|
||||||
|
if(QGSettings::isSchemaInstalled(UKUI_SEARCH_SCHEMAS)) {
|
||||||
|
m_searchGsettings = new QGSettings(UKUI_SEARCH_SCHEMAS, QByteArray(), this);
|
||||||
|
connect(m_searchGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
|
||||||
|
if(key == FILE_INDEX_ENABLE_KEY) {
|
||||||
|
bool fileSearchEnable = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
||||||
|
setValue(FILE_INDEX_ENABLE_KEY, fileSearchEnable);
|
||||||
|
Q_EMIT fileSearchEnableChanged(fileSearchEnable);
|
||||||
|
} else if(key == WEB_ENGINE_KEY) {
|
||||||
|
QString webSearchEngine = m_searchGsettings->get(WEB_ENGINE_KEY).toString();
|
||||||
|
setValue(WEB_ENGINE_KEY, webSearchEngine);
|
||||||
|
Q_EMIT webSearchEngineChanged(webSearchEngine);
|
||||||
|
} else if (key == CONTENT_FUZZY_SEARCH_KEY) {
|
||||||
|
bool contentFuzzySearch = m_searchGsettings->get(CONTENT_FUZZY_SEARCH_KEY).toBool();
|
||||||
|
setValue(CONTENT_FUZZY_SEARCH_KEY, contentFuzzySearch);
|
||||||
|
Q_EMIT contentFuzzySearchEnableChanged(contentFuzzySearch);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(m_searchGsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
||||||
|
setValue(FILE_INDEX_ENABLE_KEY, m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool());
|
||||||
|
}
|
||||||
|
if(m_searchGsettings->keys().contains(WEB_ENGINE_KEY)) {
|
||||||
|
setValue(WEB_ENGINE_KEY, m_searchGsettings->get(WEB_ENGINE_KEY).toBool());
|
||||||
|
}
|
||||||
|
if(m_searchGsettings->keys().contains(CONTENT_FUZZY_SEARCH_KEY)) {
|
||||||
|
setValue(CONTENT_FUZZY_SEARCH_KEY, m_searchGsettings->get(CONTENT_FUZZY_SEARCH_KEY).toBool());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant GlobalSettings::getValue(const QString &key) {
|
const QVariant GlobalSettings::getValue(const QString &key) {
|
||||||
return m_cache.value(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GlobalSettings::isExist(const QString &key) {
|
m_mutex.lock();
|
||||||
return !m_cache.value(key).isNull();
|
QVariant value = m_cache.value(key);
|
||||||
}
|
m_mutex.unlock();
|
||||||
|
return value;
|
||||||
void GlobalSettings::reset(const QString &key) {
|
|
||||||
m_cache.remove(key);
|
|
||||||
QtConcurrent::run([ = ]() {
|
|
||||||
// if (m_mutex.tryLock(1000)) {
|
|
||||||
m_settings->remove(key);
|
|
||||||
m_settings->sync();
|
|
||||||
// m_mutex.unlock();
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
Q_EMIT this->valueChanged(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalSettings::resetAll() {
|
|
||||||
QStringList tmp = m_cache.keys();
|
|
||||||
m_cache.clear();
|
|
||||||
for(auto key : tmp) {
|
|
||||||
Q_EMIT this->valueChanged(key);
|
|
||||||
}
|
|
||||||
QtConcurrent::run([ = ]() {
|
|
||||||
if(m_mutex.tryLock(1000)) {
|
|
||||||
m_settings->clear();
|
|
||||||
m_settings->sync();
|
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove) {
|
bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove) {
|
||||||
|
@ -145,14 +150,9 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_block_dirs_settings->remove(path);
|
m_blockDirsSettings->remove(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if(!path.startsWith("/home")) {
|
|
||||||
// returnCode = QString(tr("I can only search your user directory, it doesn't make any sense if you block an directory which is not in user directory!"));
|
|
||||||
// returnCode = PATH_NOT_IN_HOME;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//why QSetting's key can't start with "/"??
|
//why QSetting's key can't start with "/"??
|
||||||
QString pathKey = path.right(path.length() - 1);
|
QString pathKey = path.right(path.length() - 1);
|
||||||
|
@ -161,7 +161,7 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
|
||||||
pathKey = pathKey.mid(0, pathKey.length() - 1);
|
pathKey = pathKey.mid(0, pathKey.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList blockDirs = m_block_dirs_settings->allKeys();
|
QStringList blockDirs = m_blockDirsSettings->allKeys();
|
||||||
for(QString i : blockDirs) {
|
for(QString i : blockDirs) {
|
||||||
if(FileUtils::isOrUnder(pathKey, i)) {
|
if(FileUtils::isOrUnder(pathKey, i)) {
|
||||||
// returnCode = QString(tr("My parent folder has been blocked!"));
|
// returnCode = QString(tr("My parent folder has been blocked!"));
|
||||||
|
@ -170,43 +170,23 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FileUtils::isOrUnder(i, pathKey))
|
if(FileUtils::isOrUnder(i, pathKey))
|
||||||
m_block_dirs_settings->remove(i);
|
m_blockDirsSettings->remove(i);
|
||||||
}
|
}
|
||||||
m_block_dirs_settings->setValue(pathKey, "0");
|
m_blockDirsSettings->setValue(pathKey, "0");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList GlobalSettings::getBlockDirs() {
|
QStringList GlobalSettings::getBlockDirs() {
|
||||||
return m_block_dirs_settings->allKeys();
|
return m_blockDirsSettings->allKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void GlobalSettings::appendCloudData(const QString &key, const QString &value)
|
|
||||||
//{
|
|
||||||
// QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat);
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// QStringList values = m_qSettings->value(key).toStringList();
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if (values.contains(value)) {
|
|
||||||
// values.removeOne(value);
|
|
||||||
// }
|
|
||||||
// values.insert(0,value);
|
|
||||||
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// m_qSettings->setValue(key, values);
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if (m_qSettings) {
|
|
||||||
// delete m_qSettings;
|
|
||||||
// m_qSettings = NULL;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time) {
|
void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time) {
|
||||||
QStringList keys = m_search_record_settings->allKeys();
|
QStringList keys = m_searchRecordSettings->allKeys();
|
||||||
if(keys.contains(QString(QUrl::toPercentEncoding(word))))
|
if(keys.contains(QString(QUrl::toPercentEncoding(word))))
|
||||||
m_history.removeOne(word);
|
m_history.removeOne(word);
|
||||||
m_search_record_settings->setValue(QString(QUrl::toPercentEncoding(word)), time.toString("yyyy-MM-dd hh:mm:ss"));
|
m_searchRecordSettings->setValue(QString(QUrl::toPercentEncoding(word)), time.toString("yyyy-MM-dd hh:mm:ss"));
|
||||||
if(keys.size() >= 20)
|
if(keys.size() >= 20)
|
||||||
m_search_record_settings->remove(QString(QUrl::toPercentEncoding(m_history.takeFirst())));
|
m_searchRecordSettings->remove(QString(QUrl::toPercentEncoding(m_history.takeFirst())));
|
||||||
m_history.append(word);
|
m_history.append(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,83 +194,18 @@ QStringList GlobalSettings::getSearchRecord() {
|
||||||
return m_history;
|
return m_history;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool GlobalSettings::removeOneCloudData(const QString &key, const QString &value)
|
|
||||||
//{
|
|
||||||
// if (!QFileInfo(CLOUD_FILE).isFile()) return false;
|
|
||||||
// QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat);
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// QStringList values = m_qSettings->value(key).toStringList();
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if (values.contains(value)) {
|
|
||||||
// values.removeOne(value);
|
|
||||||
// } else return false;
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// m_qSettings->setValue(key, values);
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if (m_qSettings) {
|
|
||||||
// delete m_qSettings;
|
|
||||||
// m_qSettings = NULL;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//bool GlobalSettings::removeAllCloudData(const QString &key)
|
|
||||||
//{
|
|
||||||
// if (!QFileInfo(CLOUD_FILE).isFile()) return false;
|
|
||||||
// QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat);
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// m_qSettings->setValue(key, QStringList());
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if (m_qSettings) {
|
|
||||||
// delete m_qSettings;
|
|
||||||
// m_qSettings = NULL;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//QStringList GlobalSettings::getCloudData(const QString &key)
|
|
||||||
//{
|
|
||||||
// if (!QFileInfo(CLOUD_FILE).isFile()) return QStringList();
|
|
||||||
// QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat);
|
|
||||||
// m_qSettings->beginGroup(key);
|
|
||||||
// QStringList values = m_qSettings->value(key).toStringList();
|
|
||||||
// m_qSettings->endGroup();
|
|
||||||
// if(m_qSettings)
|
|
||||||
// delete m_qSettings;
|
|
||||||
// return values;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//this method is designed for main process settings only!!
|
//this method is designed for main process settings only!!
|
||||||
void GlobalSettings::setValue(const QString &key, const QVariant &value) {
|
void GlobalSettings::setValue(const QString &key, const QVariant &value) {
|
||||||
|
m_mutex.lock();
|
||||||
m_cache.insert(key, value);
|
m_cache.insert(key, value);
|
||||||
QtConcurrent::run([ = ]() {
|
m_mutex.unlock();
|
||||||
if (m_mutex.tryLock(1000)) {
|
|
||||||
m_settings->setValue(key, value);
|
|
||||||
m_settings->sync();
|
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalSettings::forceSync(const QString &key) {
|
|
||||||
m_settings->sync();
|
|
||||||
if(key.isNull()) {
|
|
||||||
m_cache.clear();
|
|
||||||
for(auto key : m_settings->allKeys()) {
|
|
||||||
m_cache.insert(key, m_settings->value(key));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_cache.remove(key);
|
|
||||||
m_cache.insert(key, m_settings->value(key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalSettings::updateSearchHistory(QString key) {
|
void GlobalSettings::updateSearchHistory(QString key) {
|
||||||
if(key == "search") {
|
if(key == "search") {
|
||||||
m_search_record_settings->sync();
|
m_searchRecordSettings->sync();
|
||||||
m_history.clear();
|
m_history.clear();
|
||||||
for(QString i : m_search_record_settings->allKeys()) {
|
for(QString i : m_searchRecordSettings->allKeys()) {
|
||||||
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
|
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,35 +45,32 @@
|
||||||
#define FONT_SIZE_KEY "systemFontSize"
|
#define FONT_SIZE_KEY "systemFontSize"
|
||||||
#define ICON_THEME_KEY "iconThemeName"
|
#define ICON_THEME_KEY "iconThemeName"
|
||||||
|
|
||||||
#define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog"
|
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
|
||||||
|
#define FILE_INDEX_ENABLE_KEY "fileIndexEnable"
|
||||||
|
#define WEB_ENGINE_KEY "webEngine"
|
||||||
|
#define CONTENT_FUZZY_SEARCH_KEY "contentFuzzySearch"
|
||||||
|
|
||||||
#define WEB_ENGINE "web_engine"
|
#define WEB_ENGINE "web_engine"
|
||||||
#define PATH_EMPTY 1;
|
#define PATH_EMPTY 1;
|
||||||
#define PATH_NOT_IN_HOME 2;
|
#define PATH_NOT_IN_HOME 2;
|
||||||
#define PATH_PARENT_BLOCKED 3;
|
#define PATH_PARENT_BLOCKED 3;
|
||||||
|
|
||||||
#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf"
|
|
||||||
#define BLOCK_DIRS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf"
|
#define BLOCK_DIRS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf"
|
||||||
#define SEARCH_HISTORY QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-history.conf"
|
#define SEARCH_HISTORY QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-history.conf"
|
||||||
//#define CLOUD_HISTORY "history"
|
//#define CLOUD_HISTORY "history"
|
||||||
//#define CLOUD_APPLICATIONS "applications"
|
//#define CLOUD_APPLICATIONS "applications"
|
||||||
|
|
||||||
namespace UkuiSearch {
|
namespace UkuiSearch {
|
||||||
|
/**
|
||||||
|
* @brief The GlobalSettings class
|
||||||
|
* 用于同步搜索应用的全局设置
|
||||||
|
* 不要作为文件索引或应用数据等服务设置使用
|
||||||
|
*/
|
||||||
class LIBSEARCH_EXPORT GlobalSettings : public QObject {
|
class LIBSEARCH_EXPORT GlobalSettings : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static GlobalSettings *getInstance();
|
static GlobalSettings *getInstance();
|
||||||
const QVariant getValue(const QString&);
|
const QVariant getValue(const QString&);
|
||||||
bool isExist(const QString&);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void valueChanged(const QString&);
|
|
||||||
void transparencyChanged(const double&);
|
|
||||||
void styleChanged(const QString&);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void setValue(const QString&, const QVariant&);
|
|
||||||
void reset(const QString&);
|
|
||||||
void resetAll();
|
|
||||||
/**
|
/**
|
||||||
* @brief setBlockDirs
|
* @brief setBlockDirs
|
||||||
* set path for blacklist,return true if success,otherwise return false.
|
* set path for blacklist,return true if success,otherwise return false.
|
||||||
|
@ -84,25 +81,28 @@ public Q_SLOTS:
|
||||||
*/
|
*/
|
||||||
bool setBlockDirs(const QString& path, int &returnCode, bool remove = false);
|
bool setBlockDirs(const QString& path, int &returnCode, bool remove = false);
|
||||||
QStringList getBlockDirs();
|
QStringList getBlockDirs();
|
||||||
// void appendCloudData(const QString& key, const QString& value);
|
|
||||||
void setSearchRecord(const QString &word, const QDateTime &time);
|
void setSearchRecord(const QString &word, const QDateTime &time);
|
||||||
QStringList getSearchRecord();
|
QStringList getSearchRecord();
|
||||||
// bool removeOneCloudData(const QString& key, const QString& value);
|
|
||||||
// bool removeAllCloudData(const QString& key);
|
|
||||||
// QStringList getCloudData(const QString& key);
|
|
||||||
|
|
||||||
void forceSync(const QString& = nullptr);
|
|
||||||
void updateSearchHistory(QString key);
|
void updateSearchHistory(QString key);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged(const QString&);
|
||||||
|
void transparencyChanged(const double&);
|
||||||
|
void styleChanged(const QString&);
|
||||||
|
void fileSearchEnableChanged(bool);
|
||||||
|
void webSearchEngineChanged(const QString&);
|
||||||
|
void contentFuzzySearchEnableChanged(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GlobalSettings(QObject *parent = nullptr);
|
explicit GlobalSettings(QObject *parent = nullptr);
|
||||||
~GlobalSettings() = default;
|
~GlobalSettings() = default;
|
||||||
|
void setValue(const QString&, const QVariant&);
|
||||||
|
|
||||||
QSettings* m_settings;
|
QGSettings *m_transGsettings;
|
||||||
QGSettings* m_trans_gsettings;
|
QGSettings *m_themeGsettings;
|
||||||
QGSettings* m_theme_gsettings;
|
QGSettings *m_searchGsettings;
|
||||||
QSettings *m_block_dirs_settings;
|
QSettings *m_blockDirsSettings;
|
||||||
QSettings *m_search_record_settings;
|
QSettings *m_searchRecordSettings;
|
||||||
QMap<QString, QVariant> m_cache;
|
QMap<QString, QVariant> m_cache;
|
||||||
QStringList m_history;
|
QStringList m_history;
|
||||||
QFileSystemWatcher *m_confWatcher;
|
QFileSystemWatcher *m_confWatcher;
|
||||||
|
|
|
@ -18,17 +18,17 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "file-search-plugin.h"
|
#include "file-search-plugin.h"
|
||||||
#include "search-manager.h"
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include "search-manager.h"
|
||||||
|
|
||||||
#define OCR_ICONLABLE_WITH 352
|
#define OCR_ICONLABLE_WITH 352
|
||||||
#define OCR_ICONLABLE_HEIGHT 247
|
#define OCR_ICONLABLE_HEIGHT 247
|
||||||
using namespace UkuiSearch;
|
using namespace UkuiSearch;
|
||||||
|
|
||||||
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
|
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent),m_settings(GlobalSettings::getInstance())
|
||||||
{
|
{
|
||||||
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
||||||
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
||||||
|
@ -60,14 +60,14 @@ void UkuiSearch::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resu
|
||||||
++SearchManager::uniqueSymbolFile;
|
++SearchManager::uniqueSymbolFile;
|
||||||
SearchManager::m_mutexFile.unlock();
|
SearchManager::m_mutexFile.unlock();
|
||||||
|
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) {
|
||||||
DirectSearch *directSearch;
|
|
||||||
directSearch = new DirectSearch(keyword, searchResult, FILE_SEARCH_VALUE, SearchManager::uniqueSymbolFile);
|
|
||||||
m_pool.start(directSearch);
|
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
|
||||||
FileSearch *filesearch;
|
FileSearch *filesearch;
|
||||||
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolFile, keyword, FILE_SEARCH_VALUE, 1, 0, 5);
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolFile, keyword, FILE_SEARCH_VALUE, 1, 0, 5);
|
||||||
m_pool.start(filesearch);
|
m_pool.start(filesearch);
|
||||||
|
} else{
|
||||||
|
DirectSearch *directSearch;
|
||||||
|
directSearch = new DirectSearch(keyword, searchResult, FILE_SEARCH_VALUE, SearchManager::uniqueSymbolFile);
|
||||||
|
m_pool.start(directSearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void FileSearchPlugin::initDetailPage()
|
||||||
// return previewPage;
|
// return previewPage;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent)
|
DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent),m_settings(GlobalSettings::getInstance())
|
||||||
{
|
{
|
||||||
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
||||||
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
||||||
|
@ -270,14 +270,14 @@ void UkuiSearch::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resul
|
||||||
++SearchManager::uniqueSymbolDir;
|
++SearchManager::uniqueSymbolDir;
|
||||||
SearchManager::m_mutexDir.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
|
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) {
|
||||||
DirectSearch *directSearch;
|
|
||||||
directSearch = new DirectSearch(keyword, searchResult, DIR_SEARCH_VALUE, SearchManager::uniqueSymbolDir);
|
|
||||||
m_pool.start(directSearch);
|
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
|
||||||
FileSearch *filesearch;
|
FileSearch *filesearch;
|
||||||
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolDir, keyword, DIR_SEARCH_VALUE, 1, 0, 5);
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolDir, keyword, DIR_SEARCH_VALUE, 1, 0, 5);
|
||||||
m_pool.start(filesearch);
|
m_pool.start(filesearch);
|
||||||
|
} else {
|
||||||
|
DirectSearch *directSearch;
|
||||||
|
directSearch = new DirectSearch(keyword, searchResult, DIR_SEARCH_VALUE, SearchManager::uniqueSymbolDir);
|
||||||
|
m_pool.start(directSearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ void DirSearchPlugin::initDetailPage()
|
||||||
// return nullptr;
|
// return nullptr;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(parent)
|
FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(parent),m_settings(GlobalSettings::getInstance())
|
||||||
{
|
{
|
||||||
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
||||||
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
SearchPluginIface::Actioninfo Openpath { 1, tr("Open path")};
|
||||||
|
@ -454,11 +454,9 @@ void UkuiSearch::FileContengSearchPlugin::KeywordSearch(QString keyword, DataQue
|
||||||
SearchManager::m_mutexContent.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
|
|
||||||
m_keyWord = keyword;
|
m_keyWord = keyword;
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) {
|
||||||
return;
|
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
|
||||||
FileContentSearch *fileContentSearch;
|
FileContentSearch *fileContentSearch;
|
||||||
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, 0, 5);
|
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, m_settings->getValue(CONTENT_FUZZY_SEARCH_KEY).toBool(), 0, 5);
|
||||||
m_pool.start(fileContentSearch);
|
m_pool.start(fileContentSearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,12 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
#include "libsearch_global.h"
|
|
||||||
#include "search-plugin-iface.h"
|
#include "search-plugin-iface.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "action-label.h"
|
#include "action-label.h"
|
||||||
#include "separation-line.h"
|
#include "separation-line.h"
|
||||||
|
#include "global-settings.h"
|
||||||
|
|
||||||
namespace UkuiSearch {
|
namespace UkuiSearch {
|
||||||
//internal plugin
|
//internal plugin
|
||||||
class LIBSEARCH_EXPORT FileSearchPlugin : public QObject, public SearchPluginIface
|
class LIBSEARCH_EXPORT FileSearchPlugin : public QObject, public SearchPluginIface
|
||||||
|
@ -89,6 +90,7 @@ private:
|
||||||
bool m_enable = true;
|
bool m_enable = true;
|
||||||
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
||||||
QThreadPool m_pool;
|
QThreadPool m_pool;
|
||||||
|
GlobalSettings *m_settings = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBSEARCH_EXPORT DirSearchPlugin : public QObject, public SearchPluginIface
|
class LIBSEARCH_EXPORT DirSearchPlugin : public QObject, public SearchPluginIface
|
||||||
|
@ -143,6 +145,7 @@ private:
|
||||||
bool m_enable = true;
|
bool m_enable = true;
|
||||||
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
||||||
QThreadPool m_pool;
|
QThreadPool m_pool;
|
||||||
|
GlobalSettings *m_settings = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBSEARCH_EXPORT FileContengSearchPlugin : public QObject, public SearchPluginIface
|
class LIBSEARCH_EXPORT FileContengSearchPlugin : public QObject, public SearchPluginIface
|
||||||
|
@ -200,6 +203,7 @@ private:
|
||||||
bool m_enable = true;
|
bool m_enable = true;
|
||||||
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
QList<SearchPluginIface::Actioninfo> m_actionInfo;
|
||||||
QThreadPool m_pool;
|
QThreadPool m_pool;
|
||||||
|
GlobalSettings *m_settings = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,13 +225,15 @@ int FileSearch::getResult(Xapian::MSet &result) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContentSearch::FileContentSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, int begin, int num) {
|
FileContentSearch::FileContentSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, bool fuzzy, int begin, int num)
|
||||||
|
:m_search_result(searchResult),
|
||||||
|
m_uniqueSymbol(uniqueSymbol),
|
||||||
|
m_keyword(keyword),
|
||||||
|
m_fuzzy(fuzzy),
|
||||||
|
m_begin(begin),
|
||||||
|
m_num(num)
|
||||||
|
{
|
||||||
this->setAutoDelete(true);
|
this->setAutoDelete(true);
|
||||||
m_search_result = searchResult;
|
|
||||||
m_uniqueSymbol = uniqueSymbol;
|
|
||||||
m_keyword = keyword;
|
|
||||||
m_begin = begin;
|
|
||||||
m_num = num;
|
|
||||||
m_matchDecider = new FileContentMatchDecider();
|
m_matchDecider = new FileContentMatchDecider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,18 +277,23 @@ int FileContentSearch::keywordSearchContent() {
|
||||||
std::vector<KeyWord> sKeyWord = ChineseSegmentation::getInstance()->callSegment(m_keyword.toStdString());
|
std::vector<KeyWord> sKeyWord = ChineseSegmentation::getInstance()->callSegment(m_keyword.toStdString());
|
||||||
//Creat a query
|
//Creat a query
|
||||||
std::string words;
|
std::string words;
|
||||||
for(int i = 0; i < sKeyWord.size(); i++) {
|
for(size_t i = 0; i < sKeyWord.size(); i++) {
|
||||||
words.append(sKeyWord.at(i).word).append(" ");
|
words.append(sKeyWord.at(i).word).append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Xapian::Query query = qp.parse_query(words);
|
// Xapian::Query query = qp.parse_query(words);
|
||||||
|
|
||||||
std::vector<Xapian::Query> v;
|
std::vector<Xapian::Query> v;
|
||||||
for(int i=0; i<sKeyWord.size(); i++) {
|
for(size_t i = 0; i < sKeyWord.size(); i++) {
|
||||||
v.push_back(Xapian::Query(sKeyWord.at(i).word));
|
v.push_back(Xapian::Query(sKeyWord.at(i).word));
|
||||||
qDebug() << QString::fromStdString(sKeyWord.at(i).word);
|
// qDebug() << QString::fromStdString(sKeyWord.at(i).word);
|
||||||
|
}
|
||||||
|
Xapian::Query query;
|
||||||
|
if(m_fuzzy) {
|
||||||
|
query = Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
|
||||||
|
} else {
|
||||||
|
query = Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end());
|
||||||
}
|
}
|
||||||
Xapian::Query query = Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end());
|
|
||||||
|
|
||||||
qDebug() << "keywordSearchContent:" << QString::fromStdString(query.get_description());
|
qDebug() << "keywordSearchContent:" << QString::fromStdString(query.get_description());
|
||||||
|
|
||||||
|
@ -316,88 +323,45 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) {
|
||||||
for(auto it = result.begin(); it != result.end(); ++it) {
|
for(auto it = result.begin(); it != result.end(); ++it) {
|
||||||
Xapian::Document doc = it.get_document();
|
Xapian::Document doc = it.get_document();
|
||||||
std::string data = doc.get_data();
|
std::string data = doc.get_data();
|
||||||
double docScoreWeight = it.get_weight();
|
// double docScoreWeight = it.get_weight();
|
||||||
Xapian::percent docScorePercent = it.get_percent();
|
// Xapian::percent docScorePercent = it.get_percent();
|
||||||
QString path = QString::fromStdString(doc.get_value(1));
|
QString path = QString::fromStdString(doc.get_value(1));
|
||||||
QString suffix = QString::fromStdString(doc.get_value(2));
|
// QString suffix = QString::fromStdString(doc.get_value(2));
|
||||||
|
|
||||||
SearchPluginIface::ResultInfo ri;
|
SearchPluginIface::ResultInfo ri;
|
||||||
if(!SearchManager::creatResultInfo(ri, path)) {
|
if(!SearchManager::creatResultInfo(ri, path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Construct snippets containing keyword.
|
// Construct snippets containing keyword.
|
||||||
// QStringList snippets;
|
auto termIterator = doc.termlist_begin();
|
||||||
// snippets.append(QString::fromStdString( result.snippet(doc.get_data(),400)));
|
QStringList words = QString::fromStdString(keyWord).split(" ", QString::SkipEmptyParts);
|
||||||
// qWarning()<<QString::fromStdString(s);
|
|
||||||
auto term = doc.termlist_begin();
|
|
||||||
std::string wordTobeFound = QString::fromStdString(keyWord).section(" ", 0, 0).toStdString();
|
|
||||||
// int size = wordTobeFound.length();
|
|
||||||
term.skip_to(wordTobeFound);
|
|
||||||
// int count = 0;
|
|
||||||
// for(auto pos = term.positionlist_begin(); pos != term.positionlist_end() && count < 6; ++pos) {
|
|
||||||
// std::string s = data.substr((*pos < 60) ? 0 : (*pos - 60), size + 120);
|
|
||||||
// QString snippet = QString::fromStdString(s);
|
|
||||||
// if(snippet.size() > 6 + QString::fromStdString(keyWord).size()) {
|
|
||||||
// snippet.replace(0, 3, "...").replace(snippet.size() - 3, 3, "...");
|
|
||||||
// } else {
|
|
||||||
// snippet.append("...").prepend("...");
|
|
||||||
// }
|
|
||||||
// ri.description.prepend(SearchPluginIface::DescriptionInfo{"",snippet});
|
|
||||||
//// snippets.append(snippet);
|
|
||||||
// QString().swap(snippet);
|
|
||||||
// std::string().swap(s);
|
|
||||||
// ++count;
|
|
||||||
// }
|
|
||||||
//fix me: make a snippet without cut cjk char.
|
|
||||||
auto pos = term.positionlist_begin();
|
|
||||||
QString snippet = FileUtils::chineseSubString(data,*pos,120);
|
|
||||||
|
|
||||||
// if(data.length() - *pos < 120) {
|
for(const QString& wordTobeFound : words) {
|
||||||
// std::string s = data.substr((data.length() < 120) ? 0 : (data.length() - 120), 120);
|
std::string term = wordTobeFound.toStdString();
|
||||||
// snippet = QString::fromStdString(s);
|
termIterator.skip_to(term);
|
||||||
// } else {
|
if(term == *termIterator) {
|
||||||
// std::string s = data.substr(*pos, 120);
|
break;
|
||||||
// snippet = QString::fromStdString(s);
|
} else {
|
||||||
// }
|
termIterator = doc.termlist_begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto pos = termIterator.positionlist_begin();
|
||||||
|
QString snippet = FileUtils::chineseSubString(data,*pos,120);
|
||||||
|
|
||||||
ri.description.prepend(SearchPluginIface::DescriptionInfo{"",snippet});
|
ri.description.prepend(SearchPluginIface::DescriptionInfo{"",snippet});
|
||||||
QString().swap(snippet);
|
QString().swap(snippet);
|
||||||
// std::string().swap(s);
|
|
||||||
std::string().swap(data);
|
std::string().swap(data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// for(QString i : QString::fromStdString(keyWord).split(" ",QString::SkipEmptyParts))
|
|
||||||
// {
|
|
||||||
// std::string word = i.toStdString();
|
|
||||||
// term.skip_to(word);
|
|
||||||
// int size = word.size();
|
|
||||||
// auto pos = term.positionlist_begin();
|
|
||||||
// std::string s = data.substr((*pos < 60)? 0: (*pos - 60) , size + 120);
|
|
||||||
// QString snippet = QString::fromStdString(s);
|
|
||||||
// snippet.replace(0,3,"...").replace(snippet.size()-3,3,"...");
|
|
||||||
// snippets.append(snippet);
|
|
||||||
// std::string().swap(word);
|
|
||||||
// std::string().swap(s);
|
|
||||||
// QString().swap(snippet);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
SearchManager::m_mutexContent.lock();
|
SearchManager::m_mutexContent.lock();
|
||||||
if(m_uniqueSymbol == SearchManager::uniqueSymbolContent) {
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolContent) {
|
||||||
m_search_result->enqueue(ri);
|
m_search_result->enqueue(ri);
|
||||||
SearchManager::m_mutexContent.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
// snippets.clear();
|
|
||||||
// QStringList().swap(snippets);
|
|
||||||
} else {
|
} else {
|
||||||
SearchManager::m_mutexContent.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// searchResult.insert(path,snippets);
|
|
||||||
//qDebug() << "path=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
|
//qDebug() << "path=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
|
||||||
}
|
}
|
||||||
// // if(!pathTobeDelete->isEmpty())
|
|
||||||
// // deleteAllIndex(pathTobeDelete)
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ private:
|
||||||
|
|
||||||
class FileContentSearch : public QRunnable {
|
class FileContentSearch : public QRunnable {
|
||||||
public:
|
public:
|
||||||
explicit FileContentSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, int begin = 0, int num = 20);
|
explicit FileContentSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, bool fuzzy,int begin = 0, int num = 20);
|
||||||
~FileContentSearch();
|
~FileContentSearch();
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
@ -132,6 +132,7 @@ private:
|
||||||
FileContentMatchDecider *m_matchDecider;
|
FileContentMatchDecider *m_matchDecider;
|
||||||
size_t m_uniqueSymbol;
|
size_t m_uniqueSymbol;
|
||||||
QString m_keyword;
|
QString m_keyword;
|
||||||
|
bool m_fuzzy;
|
||||||
int m_begin = 0;
|
int m_begin = 0;
|
||||||
int m_num = 20;
|
int m_num = 20;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue