Feature:Add web-engine settings key.

This commit is contained in:
zhangjiaping 2021-04-20 20:12:13 +08:00
parent 53c07dd9c2
commit 25d8634ed4
6 changed files with 41 additions and 6 deletions

View File

@ -5,5 +5,10 @@
<summary>search method</summary>
<description>Is current search-method index-search.</description>
</key>
<key name="web-engine" type="s">
<default>"baidu"</default>
<summary>web engine</summary>
<description>Web engine to search keyword online.</description>
</key>
</schema>
</schemalist>

View File

@ -2,3 +2,4 @@ usr/bin/ukui-search
etc/xdg/autostart/*.desktop
usr/share/applications/*.desktop
src/.qm/*.qm usr/share/ukui-search/translations
usr/share/glib-2.0/schemas/*.xml

View File

@ -475,12 +475,19 @@ void MainWindow::initGsettings()
if (key == SEARCH_METHOD_KEY) {
bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool();
this->setSearchMethod(is_index_search);
} else if (key == WEB_ENGINE_KEY) {
QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString();
GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine);
}
});
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);
}
}
}

View File

@ -54,9 +54,9 @@
#include "xatom-helper.h"
#include "create-index-ask-dialog.h"
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define SEARCH_METHOD_KEY "indexSearch"
#define WEB_ENGINE_KEY "webEngine"
class SearchResult;
class MainWindow : public QMainWindow
@ -99,8 +99,6 @@ private:
SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
SeachBarWidget * m_searchWidget = nullptr; // Search bar
QStringList m_dirList;
QQueue<QString> *m_search_result_file = nullptr;

View File

@ -42,6 +42,16 @@ SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent)
m_hints.decorations = MWM_DECOR_BORDER;
XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
const QByteArray id(UKUI_SEARCH_SCHEMAS);
if (QGSettings::isSchemaInstalled(id)) {
m_web_engine_gsettings = new QGSettings(id);
connect(m_web_engine_gsettings, &QGSettings::changed, this, [ = ](const QString &key) {
if (key == WEB_ENGINE_KEY) {
resetWebEngine();
}
});
}
initUi();
refreshIndexState();
setupBlackList(GlobalSettings::getInstance()->getBlockDirs());
@ -315,11 +325,16 @@ void SettingsWidget::onBtnDelClicked(const QString& path) {
}
/**
* @brief SettingsWidget::resetWebEngine UI控件上
* @brief SettingsWidget::resetWebEngine UI控件上
*/
void SettingsWidget::resetWebEngine()
{
QString engine = GlobalSettings::getInstance()->getValue(WEB_ENGINE).toString();
QString engine;
if (m_web_engine_gsettings && m_web_engine_gsettings->keys().contains(WEB_ENGINE_KEY)) {
engine = m_web_engine_gsettings->get(WEB_ENGINE_KEY).toString();
} else {
engine = GlobalSettings::getInstance()->getValue(WEB_ENGINE).toString();
}
m_engineBtnGroup->blockSignals(true);
if (!engine.isEmpty()) {
if (engine == "360") {
@ -341,8 +356,12 @@ void SettingsWidget::resetWebEngine()
*/
void SettingsWidget::setWebEngine(const QString& engine)
{
if (m_web_engine_gsettings && m_web_engine_gsettings->keys().contains(WEB_ENGINE_KEY)) {
m_web_engine_gsettings->set(WEB_ENGINE_KEY, engine);
} else {
GlobalSettings::getInstance()->setValue(WEB_ENGINE, engine);
}
}
/**
* @brief setIndexState

View File

@ -35,6 +35,9 @@
#include <libsearch.h>
#include "xatom-helper.h"
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define WEB_ENGINE_KEY "webEngine"
class SettingsWidget : public QWidget
{
Q_OBJECT
@ -107,6 +110,8 @@ private:
int m_blockdirs = 0; //黑名单文件夹数量
QGSettings * m_web_engine_gsettings = nullptr;
Q_SIGNALS:
void settingWidgetClosed();