optimize global-settings;

Fix the problem that the search window cannot show because it was hidden by something while create-index-dialog is showing.
This commit is contained in:
JunjieBai 2023-05-31 17:59:20 +08:00
parent 5157a6be6c
commit 3b8c35c2c2
22 changed files with 164 additions and 563 deletions

View File

@ -20,6 +20,7 @@
*/ */
#include "search-line-edit.h" #include "search-line-edit.h"
#include <KWindowEffects> #include <KWindowEffects>
#include <QApplication>
#include <QPainterPath> #include <QPainterPath>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -91,7 +92,7 @@ void SearchLineEdit::paintEvent(QPaintEvent *e)
QPainter p(this); QPainter p(this);
p.setRenderHint(QPainter::Antialiasing); // 反锯齿; p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
p.setBrush(palette().base()); p.setBrush(palette().base());
p.setOpacity(GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble()); p.setOpacity(GlobalSettings::getInstance().getValue(TRANSPARENCY_KEY).toDouble());
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawRoundedRect(this->rect(), 12, 12); p.drawRoundedRect(this->rect(), 12, 12);
return QLineEdit::paintEvent(e); return QLineEdit::paintEvent(e);

View File

@ -28,7 +28,6 @@
#include "result-view.h" #include "result-view.h"
#include "search-plugin-iface.h" #include "search-plugin-iface.h"
#include "best-list-view.h" #include "best-list-view.h"
#include "web-search-view.h"
namespace UkuiSearch { namespace UkuiSearch {
class ResultScrollBar : public QScrollBar class ResultScrollBar : public QScrollBar

View File

@ -19,6 +19,7 @@
* *
*/ */
#include "search-result-page.h" #include "search-result-page.h"
#include "global-settings.h"
#include <QPainterPath> #include <QPainterPath>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
@ -128,7 +129,7 @@ void SearchResultPage::paintEvent(QPaintEvent *event)
QPainter p(this); QPainter p(this);
p.setRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::Antialiasing);
p.setBrush(palette().base()); p.setBrush(palette().base());
p.setOpacity(GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble()); p.setOpacity(GlobalSettings::getInstance().getValue(TRANSPARENCY_KEY).toDouble());
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawRoundedRect(this->rect().adjusted(10,10,-10,-10), 12, 12); p.drawRoundedRect(this->rect().adjusted(10,10,-10,-10), 12, 12);

View File

@ -50,7 +50,7 @@
#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf" #define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf"
#define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog" #define ENABLE_CREATE_INDEX_ASK_DIALOG "enable_create_index_ask_dialog"
const static QString FILE_INDEX_ENABLE_KEY = "fileIndexEnable";
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);
@ -164,8 +164,8 @@ void MainWindow::bootOptionsFilter(QString opt) {
clearSearchResult(); clearSearchResult();
centerToScreen(this); centerToScreen(this);
this->m_searchBarWidget->setFocus(); this->m_searchBarWidget->setFocus();
this->activateWindow();
} }
this->activateWindow();
} }
} }
@ -236,7 +236,7 @@ void MainWindow::searchKeywordSlot(const QString &keyword)
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索 //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG).toBool() if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG).toBool()
&& !m_currentSearchAsked && !m_currentSearchAsked
&& GlobalSettings::getInstance()->getValue(FILE_INDEX_ENABLE_KEY).toBool() == false) { && !m_isIndexSearch) {
m_askTimer->start(); m_askTimer->start();
} }
Q_EMIT m_searchResultPage->startSearch(keyword); Q_EMIT m_searchResultPage->startSearch(keyword);
@ -294,10 +294,13 @@ void MainWindow::initSettings() {
const QByteArray id(UKUI_SEARCH_SCHEMAS); const QByteArray id(UKUI_SEARCH_SCHEMAS);
if(QGSettings::isSchemaInstalled(id)) { if(QGSettings::isSchemaInstalled(id)) {
m_searchGsettings = new QGSettings(id); m_searchGsettings = new QGSettings(id);
if (m_searchGsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
m_isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
}
connect(m_searchGsettings, &QGSettings::changed, this, [ = ](const QString & key) { connect(m_searchGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
if(key == FILE_INDEX_ENABLE_KEY) { if(key == FILE_INDEX_ENABLE_KEY) {
bool isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool(); m_isIndexSearch = m_searchGsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
if(m_researchTimer->isActive() && !isIndexSearch) { if(m_researchTimer->isActive() && !m_isIndexSearch) {
m_researchTimer->stop(); m_researchTimer->stop();
} }
} }
@ -308,7 +311,7 @@ void MainWindow::initSettings() {
//使用GSetting获取当前窗口应该使用的透明度 //使用GSetting获取当前窗口应该使用的透明度
double MainWindow::getTransparentData() { double MainWindow::getTransparentData() {
return GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble(); return GlobalSettings::getInstance().getValue(TRANSPARENCY_KEY).toDouble();
} }
void MainWindow::initTimer() { void MainWindow::initTimer() {
@ -325,7 +328,7 @@ void MainWindow::initTimer() {
}, Qt::UniqueConnection); }, Qt::UniqueConnection);
return; return;
} }
if(this->isVisible()) { if(this->isVisible() && !m_isIndexSearch) {
m_isAskDialogVisible = true; m_isAskDialogVisible = true;
kdk::UkuiStyleHelper::self()->removeHeader(m_askDialog); kdk::UkuiStyleHelper::self()->removeHeader(m_askDialog);
m_askDialog->show(); m_askDialog->show();
@ -350,9 +353,10 @@ void MainWindow::initTimer() {
m_askTimer->stop(); m_askTimer->stop();
} else { } else {
//允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索 //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG, true).toBool() && !m_currentSearchAsked && GlobalSettings::getInstance()->getValue(FILE_INDEX_ENABLE_KEY).toBool() == false) if(m_settings->value(ENABLE_CREATE_INDEX_ASK_DIALOG, true).toBool() && !m_currentSearchAsked && !m_isIndexSearch) {
m_askTimer->start(); m_askTimer->start();
} }
}
}); });
} }

View File

@ -114,7 +114,7 @@ private:
QGSettings *m_searchGsettings = nullptr; QGSettings *m_searchGsettings = nullptr;
QSettings *m_settings = nullptr; QSettings *m_settings = nullptr;
AppWidgetPlugin *m_appWidgetPlugin = nullptr; AppWidgetPlugin *m_appWidgetPlugin = nullptr;
bool m_isIndexSearch = false;
}; };
} }

View File

@ -19,6 +19,7 @@
*/ */
#include "result-view-delegate.h" #include "result-view-delegate.h"
#include <QPainterPath> #include <QPainterPath>
#include <QApplication>
using namespace UkuiSearch; using namespace UkuiSearch;
static ResultItemStyle *global_instance_of_item_style = nullptr; static ResultItemStyle *global_instance_of_item_style = nullptr;

View File

@ -30,7 +30,6 @@
#include <QSyntaxHighlighter> #include <QSyntaxHighlighter>
#include <QTextCharFormat> #include <QTextCharFormat>
#include <QRegExp> #include <QRegExp>
#include "global-settings.h"
namespace UkuiSearch { namespace UkuiSearch {
class HightLightEffectHelper : public QSyntaxHighlighter class HightLightEffectHelper : public QSyntaxHighlighter

View File

@ -3,11 +3,9 @@ INCLUDEPATH += $$PWD
HEADERS += \ HEADERS += \
$$PWD/best-list-view.h \ $$PWD/best-list-view.h \
$$PWD/result-view-delegate.h \ $$PWD/result-view-delegate.h \
$$PWD/result-view.h \ $$PWD/result-view.h
$$PWD/web-search-view.h
SOURCES += \ SOURCES += \
$$PWD/best-list-view.cpp \ $$PWD/best-list-view.cpp \
$$PWD/result-view-delegate.cpp \ $$PWD/result-view-delegate.cpp \
$$PWD/result-view.cpp \ $$PWD/result-view.cpp
$$PWD/web-search-view.cpp

View File

@ -1,196 +0,0 @@
/*
*
* Copyright (C) 2021, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: jixiaoxu <jixiaoxu@kylinos.cn>
*
*/
#include <QDBusReply>
#include <QDesktopServices>
#include "web-search-view.h"
#define MAIN_MARGINS 0,0,0,0
#define MAIN_SPACING 0
#define TITLE_HEIGHT 30
#define VIEW_ICON_SIZE 24
using namespace UkuiSearch;
WebSearchView::WebSearchView(QWidget *parent) : QTreeView(parent)
{
setStyle(ResultItemStyle::getStyle());
this->setFrameShape(QFrame::NoFrame);
this->viewport()->setAutoFillBackground(false);
this->setRootIsDecorated(false);
this->setIconSize(QSize(VIEW_ICON_SIZE, VIEW_ICON_SIZE));
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setSelectionBehavior(QAbstractItemView::SelectRows);
this->setSelectionMode(QAbstractItemView::SingleSelection);
this->setHeaderHidden(true);
m_model = new WebSearchModel(this);
this->setModel(m_model);
m_styleDelegate = new ResultViewDelegate(this);
this->setItemDelegate(m_styleDelegate);
}
bool WebSearchView::isSelected()
{
return m_is_selected;
}
int WebSearchView::showHeight()
{
return this->rowHeight(this->model()->index(0, 0, QModelIndex()));
}
QModelIndex WebSearchView::getModlIndex(int row, int column)
{
return this->m_model->index(row, column);
}
void WebSearchView::clearSelectedRow()
{
if (!m_is_selected) {
this->blockSignals(true);
//this->clearSelection();
this->setCurrentIndex(QModelIndex());
this->blockSignals(false);
}
}
void WebSearchView::startSearch(const QString & keyword)
{
this->m_styleDelegate->setSearchKeyword(keyword);
this->m_model->startSearch(keyword);
m_keyWord = keyword;
}
void WebSearchView::mouseReleaseEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
this->clearSelection();
}
return QTreeView::mouseReleaseEvent(event);
}
void WebSearchView::LaunchBrowser()
{
QString address;
QString engine = GlobalSettings::getInstance()->getValue("web_engine").toString();
if(!engine.isEmpty()) {
if(engine == "360") {
address = "https://so.com/s?q=" + m_keyWord; //360
} else if(engine == "sougou") {
address = "https://www.sogou.com/web?query=" + m_keyWord; //搜狗
} else {
address = "http://baidu.com/s?word=" + m_keyWord; //百度
}
} else { //默认值
address = "http://baidu.com/s?word=" + m_keyWord ; //百度
}
bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
"/com/kylin/AppManager",
"com.kylin.AppManager",
QDBusConnection::sessionBus());
if(!appLaunchInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
res = false;
} else {
appLaunchInterface->setTimeout(10000);
QDBusReply<bool> reply = appLaunchInterface->call("LaunchDefaultAppWithUrl", address);
if(reply.isValid()) {
res = reply;
} else {
qWarning() << "SoftWareCenter dbus called failed!";
res = false;
}
}
if(appLaunchInterface) {
delete appLaunchInterface;
}
appLaunchInterface = NULL;
if (res)
return;
QDesktopServices::openUrl(address);
}
void WebSearchView::initConnections()
{
}
WebSearchWidget::WebSearchWidget(QWidget *parent) : QWidget(parent)
{
this->initUi();
initConnections();
}
QString WebSearchWidget::getWidgetName()
{
return m_titleLabel->text();
}
void WebSearchWidget::setEnabled(const bool &enabled)
{
m_enabled = enabled;
}
void WebSearchWidget::clearResultSelection()
{
this->m_webSearchView->setCurrentIndex(QModelIndex());
}
QModelIndex WebSearchWidget::getModlIndex(int row, int column)
{
return this->m_webSearchView->getModlIndex(row, column);
}
void WebSearchWidget::setResultSelection(const QModelIndex &index)
{
this->m_webSearchView->setCurrentIndex(index);
}
void WebSearchWidget::LaunchBrowser()
{
this->m_webSearchView->LaunchBrowser();
}
void WebSearchWidget::initUi()
{
m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt);
m_mainLyt->setContentsMargins(MAIN_MARGINS);
m_mainLyt->setSpacing(MAIN_SPACING);
m_titleLabel = new TitleLabel(this);
m_titleLabel->setText(tr("Web Page"));
m_titleLabel->setFixedHeight(TITLE_HEIGHT);
m_webSearchView = new WebSearchView(this);
m_mainLyt->addWidget(m_titleLabel);
m_mainLyt->addWidget(m_webSearchView);
this->setFixedHeight(m_webSearchView->height() + TITLE_HEIGHT);
this->setFixedWidth(656);
}
void WebSearchWidget::initConnections()
{
connect(this, &WebSearchWidget::startSearch, m_webSearchView, &WebSearchView::startSearch);
connect(m_webSearchView, &WebSearchView::clicked, this, [=] () {
this->LaunchBrowser();
});
}

View File

@ -1,91 +0,0 @@
/*
*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*/
#ifndef WEBSEARCHVIEW_H
#define WEBSEARCHVIEW_H
#include <QTreeView>
#include <QListView>
#include <QMouseEvent>
#include "web-search-model.h"
#include "result-view-delegate.h"
#include "title-label.h"
namespace UkuiSearch {
class WebSearchView : public QTreeView
{
Q_OBJECT
public:
WebSearchView(QWidget *parent = nullptr);
~WebSearchView() = default;
bool isSelected();
int showHeight();
QModelIndex getModlIndex(int row, int column);
void LaunchBrowser();
public Q_SLOTS:
void clearSelectedRow();
void startSearch(const QString &);
protected:
void mouseReleaseEvent(QMouseEvent *event);
private:
void initConnections();
WebSearchModel * m_model = nullptr;
bool m_is_selected = false;
ResultViewDelegate * m_styleDelegate = nullptr;
QString m_keyWord;
};
class WebSearchWidget : public QWidget
{
Q_OBJECT
public:
WebSearchWidget(QWidget *parent = nullptr);
~WebSearchWidget() = default;
QString getWidgetName();
void setEnabled(const bool&);
void clearResultSelection();
QModelIndex getModlIndex(int row, int column);
void setResultSelection(const QModelIndex &index);
void LaunchBrowser();
private:
void initUi();
void initConnections();
bool m_enabled = true;
QVBoxLayout * m_mainLyt = nullptr;
QHBoxLayout * m_resultLyt = nullptr;
TitleLabel * m_titleLabel = nullptr;
WebSearchView * m_webSearchView = nullptr;
QLabel * m_queryIcon = nullptr;
Q_SIGNALS:
void startSearch(const QString &);
void clearSelectedRow();
void rowClicked();
};
}
#endif // WEBSEARCHVIEW_H

View File

@ -0,0 +1,32 @@
#ifndef GLOBALSETTINGSPRIVATE_H
#define GLOBALSETTINGSPRIVATE_H
#include "global-settings.h"
#include <QMutex>
#include <QGSettings>
#include <QMap>
namespace UkuiSearch {
class GlobalSettingsPrivate : public QObject
{
Q_OBJECT
public:
explicit GlobalSettingsPrivate(QObject *parent = nullptr);
const QVariant getValue(const QString&);
Q_SIGNALS:
void valueChanged(const QString& key, QVariant value);
private:
void setValue(const QString& key, const QVariant& value);
QMutex m_mutex;
QGSettings *m_transGsettings = nullptr;
QGSettings *m_themeGsettings = nullptr;
QMap<QString, QVariant> m_cache;
};
}
#endif // GLOBALSETTINGSPRIVATE_H

View File

@ -18,52 +18,21 @@
* Modified by: zhangpengfei <zhangpengfei@kylinos.cn> * Modified by: zhangpengfei <zhangpengfei@kylinos.cn>
* *
*/ */
#include <QtConcurrent>
#include <QPalette>
#include "global-settings.h" #include "global-settings.h"
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings" #include "global-settings-private.h"
#include <QPalette>
#include <QApplication>
#include <QDBusReply>
#include <QDebug>
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
#define THEME_GSETTINGS_ID "org.ukui.style"
using namespace UkuiSearch; using namespace UkuiSearch;
static GlobalSettings *globalInstance = nullptr;
GlobalSettings *GlobalSettings::getInstance() { GlobalSettingsPrivate::GlobalSettingsPrivate(QObject *parent) : QObject(parent)
if(!globalInstance) {
globalInstance = new GlobalSettings;
}
return globalInstance;
}
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
{ {
//搜索黑名单过滤
m_blockDirsSettings = new QSettings(BLOCK_DIRS, QSettings::IniFormat, this);
m_blockDirsSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
if (!QFile::exists(BLOCK_DIRS)) {
QFile file(BLOCK_DIRS);
file.open(QIODevice::ReadOnly);
file.close();
}
m_blockDirsSettings->sync();
m_confWatcher = new QFileSystemWatcher(this);
m_confWatcher->addPath(BLOCK_DIRS);
connect(m_confWatcher, &QFileSystemWatcher::fileChanged, this, [ & ]() {
m_blockDirsSettings->sync();
m_confWatcher->addPath(BLOCK_DIRS);
});
//搜索历史记录
m_searchRecordSettings = new QSettings(SEARCH_HISTORY, QSettings::IniFormat, this);
m_searchRecordSettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
for(QString i : m_searchRecordSettings->allKeys()) {
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit()));
}
if(!QDBusConnection::sessionBus().connect("org.kylinssoclient.dbus",
"/org/kylinssoclient/path",
"org.freedesktop.kylinssoclient.interface",
"keyChanged",
this, SLOT(updateSearchHistory(QString))))
qWarning() << "Kylinssoclient Dbus connect fail!";
//全局页面透明度 //全局页面透明度
//the default number of transparency for mainwindow is 0.7 //the default number of transparency for mainwindow is 0.7
setValue(TRANSPARENCY_KEY, 0.7); setValue(TRANSPARENCY_KEY, 0.7);
@ -71,9 +40,10 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
m_transGsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this); m_transGsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this);
connect(m_transGsettings, &QGSettings::changed, this, [ = ](const QString & key) { connect(m_transGsettings, &QGSettings::changed, this, [ = ](const QString & key) {
if(key == TRANSPARENCY_KEY) { if(key == TRANSPARENCY_KEY) {
setValue(TRANSPARENCY_KEY, m_transGsettings->get(TRANSPARENCY_KEY).toDouble()); double transparency = m_transGsettings->get(TRANSPARENCY_KEY).toDouble();
setValue(TRANSPARENCY_KEY, transparency);
qApp->paletteChanged(qApp->palette()); qApp->paletteChanged(qApp->palette());
Q_EMIT this->transparencyChanged(m_transGsettings->get(TRANSPARENCY_KEY).toDouble()); Q_EMIT this->valueChanged(TRANSPARENCY_KEY, transparency);
} }
}); });
if(m_transGsettings->keys().contains(TRANSPARENCY_KEY)) { if(m_transGsettings->keys().contains(TRANSPARENCY_KEY)) {
@ -91,7 +61,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
//当前主题改变时也发出paletteChanged信号通知主界面刷新 //当前主题改变时也发出paletteChanged信号通知主界面刷新
setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString()); setValue(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
qApp->paletteChanged(qApp->palette()); qApp->paletteChanged(qApp->palette());
Q_EMIT this->styleChanged(m_themeGsettings->get(STYLE_NAME_KEY).toString()); Q_EMIT this->valueChanged(STYLE_NAME_KEY, m_themeGsettings->get(STYLE_NAME_KEY).toString());
} else if(key == FONT_SIZE_KEY) { } else if(key == FONT_SIZE_KEY) {
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble()); setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble());
qApp->paletteChanged(qApp->palette()); qApp->paletteChanged(qApp->palette());
@ -106,41 +76,9 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
setValue(FONT_SIZE_KEY, m_themeGsettings->get(FONT_SIZE_KEY).toDouble()); 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).toString());
}
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 GlobalSettingsPrivate::getValue(const QString &key) {
m_mutex.lock(); m_mutex.lock();
QVariant value = m_cache.value(key); QVariant value = m_cache.value(key);
@ -148,81 +86,24 @@ const QVariant GlobalSettings::getValue(const QString &key) {
return value; return value;
} }
bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove) {
if(remove) {
if(path.isEmpty()) {
returnCode = PATH_EMPTY;
return false;
}
m_blockDirsSettings->remove(path);
return true;
}
//why QSetting's key can't start with "/"??
QString pathKey = path.right(path.length() - 1);
if (pathKey.endsWith(QLatin1Char('/'))) {
pathKey = pathKey.mid(0, pathKey.length() - 1);
}
QStringList blockDirs = m_blockDirsSettings->allKeys();
for(QString i : blockDirs) {
if(FileUtils::isOrUnder(pathKey, i)) {
// returnCode = QString(tr("My parent folder has been blocked!"));
returnCode = PATH_PARENT_BLOCKED;
return false;
}
if(FileUtils::isOrUnder(i, pathKey))
m_blockDirsSettings->remove(i);
}
m_blockDirsSettings->setValue(pathKey, "0");
return true;
}
QStringList GlobalSettings::getBlockDirs() {
QStringList blockList;
QStringList tmp = m_blockDirsSettings->allKeys();
for (const QString& blockDir : tmp) {
QString wholePath = "/" + blockDir;
if (QFile::exists(wholePath)) {
blockList.append(wholePath);
} else {
m_blockDirsSettings->remove(blockDir);
m_blockDirsSettings->sync();
}
}
return blockList;
}
void GlobalSettings::setSearchRecord(const QString &word, const QDateTime &time) {
QStringList keys = m_searchRecordSettings->allKeys();
if(keys.contains(QString(QUrl::toPercentEncoding(word))))
m_history.removeOne(word);
m_searchRecordSettings->setValue(QString(QUrl::toPercentEncoding(word)), time.toString("yyyy-MM-dd hh:mm:ss"));
if(keys.size() >= 20)
m_searchRecordSettings->remove(QString(QUrl::toPercentEncoding(m_history.takeFirst())));
m_history.append(word);
}
QStringList GlobalSettings::getSearchRecord() {
return m_history;
}
//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 GlobalSettingsPrivate::setValue(const QString &key, const QVariant &value) {
m_mutex.lock(); m_mutex.lock();
m_cache.insert(key, value); m_cache.insert(key, value);
m_mutex.unlock(); m_mutex.unlock();
} }
void GlobalSettings::updateSearchHistory(QString key) { GlobalSettings &GlobalSettings::getInstance() {
if(key == "search") { static GlobalSettings instance;
m_searchRecordSettings->sync(); return instance;
m_history.clear(); }
for(QString i : m_searchRecordSettings->allKeys()) {
m_history.append(QUrl::fromPercentEncoding(i.toLocal8Bit())); const QVariant GlobalSettings::getValue(const QString& key)
} {
} return d->getValue(key);
}
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent), d(new GlobalSettingsPrivate(this))
{
connect(d, &GlobalSettingsPrivate::valueChanged, this, &GlobalSettings::valueChanged);
} }

View File

@ -22,44 +22,18 @@
#define GLOBALSETTINGS_H #define GLOBALSETTINGS_H
#include <QObject> #include <QObject>
#include <QSettings> #include <QString>
#include <QMutex> #include <QVariant>
#include <QVector>
#include <QDir>
#include <QFileSystemWatcher>
//#include <QGSettings>
//If use pkg_config, it wont build succes,why?????????
//My demo can build access yet.
//MouseZhangZh
#include <QGSettings/QGSettings>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QApplication>
#include "libsearch_global.h" #include "libsearch_global.h"
#include "file-utils.h"
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
#define TRANSPARENCY_KEY "transparency"
#define THEME_GSETTINGS_ID "org.ukui.style"
#define STYLE_NAME_KEY "styleName"
#define FONT_SIZE_KEY "systemFontSize"
#define ICON_THEME_KEY "iconThemeName"
#define FILE_INDEX_ENABLE_KEY "fileIndexEnable"
#define WEB_ENGINE_KEY "webEngine"
#define CONTENT_FUZZY_SEARCH_KEY "contentFuzzySearch"
#define WEB_ENGINE "web_engine"
#define PATH_EMPTY 1;
#define PATH_NOT_IN_HOME 2;
#define PATH_PARENT_BLOCKED 3;
#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 CLOUD_HISTORY "history"
//#define CLOUD_APPLICATIONS "applications"
namespace UkuiSearch { namespace UkuiSearch {
const static QString TRANSPARENCY_KEY = "transparency";
const static QString STYLE_NAME_KEY = "styleName";
const static QString FONT_SIZE_KEY = "systemFontSize";
const static QString ICON_THEME_KEY = "iconThemeName";
class GlobalSettingsPrivate;
/** /**
* @brief The GlobalSettings class * @brief The GlobalSettings class
* *
@ -68,48 +42,18 @@ namespace UkuiSearch {
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& key);
/**
* @brief setBlockDirs
* set path for blacklist,return true if success,otherwise return false.
* @param path path to be blocked
* @param returnMessage this message will be set when return false.
* @param true to remove blocking,false to set blocking,default set false.
* @return
*/
bool setBlockDirs(const QString& path, int &returnCode, bool remove = false);
QStringList getBlockDirs();
void setSearchRecord(const QString &word, const QDateTime &time);
QStringList getSearchRecord();
void updateSearchHistory(QString key);
Q_SIGNALS: Q_SIGNALS:
void valueChanged(const QString&); void valueChanged(const QString& key, QVariant value);
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(const GlobalSettings&) = delete;
void setValue(const QString&, const QVariant&); GlobalSettings& operator =(const GlobalSettings&) = delete;
QGSettings *m_transGsettings;
QGSettings *m_themeGsettings;
QGSettings *m_searchGsettings;
QSettings *m_blockDirsSettings;
QSettings *m_searchRecordSettings;
QMap<QString, QVariant> m_cache;
QStringList m_history;
QFileSystemWatcher *m_confWatcher;
QMutex m_mutex;
// size_t test = 0;
GlobalSettingsPrivate *d;
}; };
} }

View File

@ -27,6 +27,7 @@
static const QByteArray UKUI_SEARCH_SCHEMAS = QByteArrayLiteral("org.ukui.search.settings"); static const QByteArray UKUI_SEARCH_SCHEMAS = QByteArrayLiteral("org.ukui.search.settings");
static const QString FILE_INDEX_ENABLE_KEY = QStringLiteral("fileIndexEnable"); static const QString FILE_INDEX_ENABLE_KEY = QStringLiteral("fileIndexEnable");
static const QString CONTENT_INDEX_ENABLE_KEY = QStringLiteral("contentIndexEnable"); static const QString CONTENT_INDEX_ENABLE_KEY = QStringLiteral("contentIndexEnable");
static const QString CONTENT_FUZZY_SEARCH_KEY = QStringLiteral("contentFuzzySearch");
static const QString OCR_ENABLE_KEY = QStringLiteral("ocrEnable"); static const QString OCR_ENABLE_KEY = QStringLiteral("ocrEnable");
static const QString META_DATA_INDEX_ENABLE_KEY = QStringLiteral("metaDataIndexEnable"); static const QString META_DATA_INDEX_ENABLE_KEY = QStringLiteral("metaDataIndexEnable");
@ -98,6 +99,21 @@ bool FileIndexerConfig::isContentIndexEnable()
return m_settings->value(CONTENT_INDEX_ENABLE_KEY, true).toBool(); return m_settings->value(CONTENT_INDEX_ENABLE_KEY, true).toBool();
} }
bool FileIndexerConfig::isFuzzySearchEnable()
{
if(m_gsettings) {
if(m_gsettings->keys().contains(CONTENT_FUZZY_SEARCH_KEY)) {
return m_gsettings->get(CONTENT_FUZZY_SEARCH_KEY).toBool();
} else {
qWarning() << "FileIndexerConfig: Can not find key:" << CONTENT_FUZZY_SEARCH_KEY << "in" << UKUI_SEARCH_SCHEMAS;
return false;
}
} else {
qWarning() << "FileIndexerConfig:" << UKUI_SEARCH_SCHEMAS << " is not found!";
return false;
}
}
bool FileIndexerConfig::isOCREnable() bool FileIndexerConfig::isOCREnable()
{ {
return m_settings->value(OCR_ENABLE_KEY, true).toBool(); return m_settings->value(OCR_ENABLE_KEY, true).toBool();

View File

@ -51,6 +51,11 @@ public:
* @return * @return
*/ */
bool isContentIndexEnable(); bool isContentIndexEnable();
/**
* @brief isFuzzySearchEnable
* @return
*/
bool isFuzzySearchEnable();
/** /**
* @brief isOCREnable * @brief isOCREnable
* @return OCR功能 * @return OCR功能

View File

@ -23,12 +23,13 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMessageBox> #include <QMessageBox>
#include "search-manager.h" #include "search-manager.h"
#include "file-indexer-config.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),m_settings(GlobalSettings::getInstance()) FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
{ {
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,7 +61,7 @@ void UkuiSearch::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resu
++SearchManager::uniqueSymbolFile; ++SearchManager::uniqueSymbolFile;
SearchManager::m_mutexFile.unlock(); SearchManager::m_mutexFile.unlock();
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) { if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
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);
@ -237,7 +238,7 @@ void FileSearchPlugin::initDetailPage()
// return previewPage; // return previewPage;
//} //}
DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent),m_settings(GlobalSettings::getInstance()) DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent)
{ {
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")};
@ -269,7 +270,7 @@ void UkuiSearch::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<Resul
++SearchManager::uniqueSymbolDir; ++SearchManager::uniqueSymbolDir;
SearchManager::m_mutexDir.unlock(); SearchManager::m_mutexDir.unlock();
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) { if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
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);
@ -423,7 +424,7 @@ void DirSearchPlugin::initDetailPage()
// return nullptr; // return nullptr;
//} //}
FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(parent),m_settings(GlobalSettings::getInstance()) FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(parent)
{ {
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")};
@ -456,9 +457,9 @@ void UkuiSearch::FileContengSearchPlugin::KeywordSearch(QString keyword, DataQue
SearchManager::m_mutexContent.unlock(); SearchManager::m_mutexContent.unlock();
m_keyWord = keyword; m_keyWord = keyword;
if(m_settings->getValue(FILE_INDEX_ENABLE_KEY).toBool()) { if(FileIndexerConfig::getInstance()->isFileIndexEnable()) {
FileContentSearch *fileContentSearch; FileContentSearch *fileContentSearch;
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, m_settings->getValue(CONTENT_FUZZY_SEARCH_KEY).toBool(), 0, 5); fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, FileIndexerConfig::getInstance()->isFuzzySearchEnable(), 0, 5);
m_pool.start(fileContentSearch); m_pool.start(fileContentSearch);
} }
} }

View File

@ -90,7 +90,6 @@ 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
@ -145,7 +144,6 @@ 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
@ -203,7 +201,6 @@ 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;
}; };
} }

View File

@ -56,6 +56,7 @@ SOURCES += \
HEADERS += \ HEADERS += \
common.h \ common.h \
file-utils.h \ file-utils.h \
global-settings-private.h \
global-settings.h \ global-settings.h \
gobject-template.h \ gobject-template.h \
libsearch_global.h \ libsearch_global.h \

View File

@ -19,6 +19,7 @@
*/ */
#include "separation-line.h" #include "separation-line.h"
#include "global-settings.h" #include "global-settings.h"
#include <QApplication>
#define NOMORL_LINE_STYLE "QFrame{background: rgba(0,0,0,0.1);}" #define NOMORL_LINE_STYLE "QFrame{background: rgba(0,0,0,0.1);}"
#define DARK_LINE_STYLE "QFrame{background: rgba(255, 255, 255, 0.16);}" #define DARK_LINE_STYLE "QFrame{background: rgba(255, 255, 255, 0.16);}"
@ -34,7 +35,7 @@ SeparationLine::SeparationLine(QWidget *parent) : QFrame(parent)
void SeparationLine::setLineStyle() void SeparationLine::setLineStyle()
{ {
QString type = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); QString type = GlobalSettings::getInstance().getValue(STYLE_NAME_KEY).toString();
if (type == "ukui-dark") { if (type == "ukui-dark") {
this->setStyleSheet(DARK_LINE_STYLE); this->setStyleSheet(DARK_LINE_STYLE);
} else { } else {

View File

@ -28,11 +28,6 @@
#include <QApplication> #include <QApplication>
#include <QVariantMap> #include <QVariantMap>
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
#define TRANSPARENCY_KEY "transparency"
#define THEME_GSETTINGS_ID "org.ukui.style"
#define STYLE_NAME_KEY "styleName"
using namespace UkuiSearch; using namespace UkuiSearch;
AppWidgetPlugin::AppWidgetPlugin(QString providername, QObject *parent) : KAppWidgetProvider(providername, parent) AppWidgetPlugin::AppWidgetPlugin(QString providername, QObject *parent) : KAppWidgetProvider(providername, parent)
@ -49,14 +44,11 @@ AppWidgetPlugin::AppWidgetPlugin(QString providername, QObject *parent) : KAppWi
m_manager = new AppWidget::KAppWidgetManager(this); m_manager = new AppWidget::KAppWidgetManager(this);
connect(GlobalSettings::getInstance(), &GlobalSettings::transparencyChanged, [ & ] { connect(&GlobalSettings::getInstance(), &GlobalSettings::valueChanged, [ & ] (const QString& key, QVariant value) {
qDebug() << "transparency changed"; if (key == TRANSPARENCY_KEY || key == STYLE_NAME_KEY) {
this->appWidgetUpdate();
});
connect(GlobalSettings::getInstance(), &GlobalSettings::styleChanged, [ & ] {
qDebug() << "style changed";
this->appWidgetUpdate(); this->appWidgetUpdate();
qDebug() << key << " has changed to" << value;
}
}); });
} }
@ -76,7 +68,7 @@ void AppWidgetPlugin::appWidgetRecevie(const QString &eventname, const QString &
void AppWidgetPlugin::appWidgetUpdate() void AppWidgetPlugin::appWidgetUpdate()
{ {
QString theme = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); QString theme = GlobalSettings::getInstance().getValue(STYLE_NAME_KEY).toString();
QJsonObject obj; QJsonObject obj;
if (theme == "ukui-dark") { if (theme == "ukui-dark") {
obj.insert("red", QJsonValue(0)); obj.insert("red", QJsonValue(0));
@ -90,7 +82,7 @@ void AppWidgetPlugin::appWidgetUpdate()
obj.insert("placeHolderTextColor", QJsonValue("#72000000")); obj.insert("placeHolderTextColor", QJsonValue("#72000000"));
} }
obj.insert("alpha", QJsonValue(GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble())); obj.insert("alpha", QJsonValue(GlobalSettings::getInstance().getValue(TRANSPARENCY_KEY).toDouble()));
QString jsonData = QString(QJsonDocument(obj).toJson()); QString jsonData = QString(QJsonDocument(obj).toJson());
QVariantMap dataMap; QVariantMap dataMap;

View File

@ -1,15 +1,30 @@
#include <QDBusReply>
#include <QDesktopServices>
#include <QDebug>
#include "web-search-plugin.h" #include "web-search-plugin.h"
#include "global-settings.h" #include "global-settings.h"
#define WEB_ENGINE_KEY "webEngine" #include <QDBusReply>
#include <QDBusInterface>
#include <QDesktopServices>
#include <QDebug>
#include <QApplication>
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define BROWSERTYPE "x-scheme-handler/http" #define BROWSERTYPE "x-scheme-handler/http"
#define DESKTOPPATH "/usr/share/applications/" #define DESKTOPPATH "/usr/share/applications/"
#define WEB_ENGINE_KEY "webEngine"
using namespace UkuiSearch; using namespace UkuiSearch;
WebSearchPlugin::WebSearchPlugin(QObject *parent) : QObject(parent) WebSearchPlugin::WebSearchPlugin(QObject *parent) : QObject(parent)
{ {
if (QGSettings::isSchemaInstalled(UKUI_SEARCH_SCHEMAS)) {
m_settings = new QGSettings(UKUI_SEARCH_SCHEMAS, QByteArray(), this);
if (m_settings->keys().contains(WEB_ENGINE_KEY)) {
m_webEngine = m_settings->get(WEB_ENGINE_KEY).toString();
}
connect(m_settings, &QGSettings::changed, this, [ & ] (const QString& key) {
if (key == WEB_ENGINE_KEY) {
m_webEngine = m_settings->get(WEB_ENGINE_KEY).toString();
}
});
}
SearchPluginIface::Actioninfo open { 0, tr("Start browser search")}; SearchPluginIface::Actioninfo open { 0, tr("Start browser search")};
m_actionInfo << open; m_actionInfo << open;
initDetailPage(); initDetailPage();
@ -37,10 +52,7 @@ void UkuiSearch::WebSearchPlugin::KeywordSearch(QString keyword, DataQueue<UkuiS
resultInfo.name = m_keyWord; resultInfo.name = m_keyWord;
resultInfo.type = 0; resultInfo.type = 0;
QByteArray ba = QString(DESKTOPPATH + getDefaultAppId(BROWSERTYPE)).toUtf8();
QString defaultwebengines(getDefaultAppId(BROWSERTYPE));
QByteArray ba = QString(DESKTOPPATH + defaultwebengines).toUtf8();
GDesktopAppInfo * textinfo = g_desktop_app_info_new_from_filename(ba.constData()); GDesktopAppInfo * textinfo = g_desktop_app_info_new_from_filename(ba.constData());
char *iconname = g_icon_to_string(g_app_info_get_icon(G_APP_INFO(textinfo))); char *iconname = g_icon_to_string(g_app_info_get_icon(G_APP_INFO(textinfo)));
QIcon appicon; QIcon appicon;
@ -71,11 +83,10 @@ void UkuiSearch::WebSearchPlugin::openAction(int actionkey, QString key, int typ
Q_UNUSED(key) Q_UNUSED(key)
Q_UNUSED(type) Q_UNUSED(type)
QString address; QString address;
QString engine = GlobalSettings::getInstance()->getValue("webEngine").toString(); if(!m_webEngine.isEmpty()) {
if(!engine.isEmpty()) { if(m_webEngine == "360") {
if(engine == "360") {
address = "https://so.com/s?q=" + m_keyWord; //360 address = "https://so.com/s?q=" + m_keyWord; //360
} else if(engine == "sougou") { } else if(m_webEngine == "sougou") {
address = "https://www.sogou.com/web?query=" + m_keyWord; //搜狗 address = "https://www.sogou.com/web?query=" + m_keyWord; //搜狗
} else { } else {
address = "http://baidu.com/s?word=" + m_keyWord; //百度 address = "http://baidu.com/s?word=" + m_keyWord; //百度
@ -125,14 +136,14 @@ void UkuiSearch::WebSearchPlugin::initDetailPage()
m_detailLyt->setContentsMargins(8, 0, 16, 0); m_detailLyt->setContentsMargins(8, 0, 16, 0);
m_iconLabel = new QLabel(m_detailPage); m_iconLabel = new QLabel(m_detailPage);
m_iconLabel->setAlignment(Qt::AlignCenter); m_iconLabel->setAlignment(Qt::AlignCenter);
QString type = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); QString type = GlobalSettings::getInstance().getValue(STYLE_NAME_KEY).toString();
if (type == "ukui-dark") { if (type == "ukui-dark") {
m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(128, 128)); m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(128, 128));
} else { } else {
m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-default.svg").pixmap(128, 128)); m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-default.svg").pixmap(128, 128));
} }
connect(qApp, &QApplication::paletteChanged, this, [=] () { connect(qApp, &QApplication::paletteChanged, this, [=] () {
QString type = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); QString type = GlobalSettings::getInstance().getValue(STYLE_NAME_KEY).toString();
if (type == "ukui-dark") { if (type == "ukui-dark") {
m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(128, 128)); m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(128, 128));
} else { } else {

View File

@ -13,6 +13,7 @@
#include "action-label.h" #include "action-label.h"
#include "search-plugin-iface.h" #include "search-plugin-iface.h"
#include <gio/gdesktopappinfo.h> #include <gio/gdesktopappinfo.h>
#include <QGSettings>
namespace UkuiSearch { namespace UkuiSearch {
@ -48,6 +49,9 @@ private:
QVBoxLayout * m_actionLyt = nullptr; QVBoxLayout * m_actionLyt = nullptr;
QGSettings *m_settings = nullptr;
QString m_webEngine;
bool m_enable = true; bool m_enable = true;
QList<WebSearchPlugin::Actioninfo> m_actionInfo; QList<WebSearchPlugin::Actioninfo> m_actionInfo;