Optimize code.

This commit is contained in:
zhangjiaping 2021-04-20 20:43:14 +08:00
parent 25d8634ed4
commit 1496662523
4 changed files with 17 additions and 27 deletions

View File

@ -214,6 +214,16 @@ void MainWindow::initUi()
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, [ = ]() {
@ -478,6 +488,7 @@ void MainWindow::initGsettings()
} else if (key == WEB_ENGINE_KEY) {
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)) {

View File

@ -131,6 +131,7 @@ protected:
Q_SIGNALS:
void searchMethodChanged(FileUtils::SearchMethod);
void webEngineChanged();
public Q_SLOTS:
/**

View File

@ -42,16 +42,6 @@ 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());
@ -329,12 +319,7 @@ void SettingsWidget::onBtnDelClicked(const QString& path) {
*/
void SettingsWidget::resetWebEngine()
{
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();
}
QString engine = GlobalSettings::getInstance()->getValue(WEB_ENGINE).toString();
m_engineBtnGroup->blockSignals(true);
if (!engine.isEmpty()) {
if (engine == "360") {
@ -356,11 +341,8 @@ 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);
}
// GlobalSettings::getInstance()->setValue(WEB_ENGINE, engine);
Q_EMIT this->webEngineChanged(engine);
}
/**

View File

@ -35,9 +35,6 @@
#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
@ -48,6 +45,7 @@ public:
void setIndexState(bool);
void setIndexNum(int);
void showWidget();
void resetWebEngine();
private:
void initUi();
@ -57,7 +55,6 @@ private:
void paintEvent(QPaintEvent *);
void resize();
void showWarningDialog(const int&);
void resetWebEngine();
MotifWmHints m_hints;
@ -110,10 +107,9 @@ private:
int m_blockdirs = 0; //黑名单文件夹数量
QGSettings * m_web_engine_gsettings = nullptr;
Q_SIGNALS:
void settingWidgetClosed();
void webEngineChanged(const QString&);
private Q_SLOTS:
// void onBtnConfirmClicked();