From 7ecc6419a3db2d4e8529b388ae6f3f5fbc6463e9 Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Wed, 27 Oct 2021 11:37:55 +0800 Subject: [PATCH] Add web search detail page; Change selection rules; Fix translation bug; Add web search plugin; Add some resouces; --- frontend/control/list-labels/title-label.cpp | 1 + .../stack-pages/search-page-section.cpp | 111 +++++++----------- .../control/stack-pages/search-page-section.h | 1 - frontend/model/best-list-model.cpp | 9 +- frontend/model/best-list-model.h | 2 +- frontend/model/search-result-model.cpp | 4 +- frontend/view/result-view.cpp | 2 +- libsearch/appsearch/app-search-plugin.cpp | 2 +- libsearch/index/file-search-plugin.cpp | 6 +- libsearch/libsearch.pro | 3 +- libsearch/notesearch/note-search-plugin.cpp | 2 +- .../pluginmanage/search-plugin-manager.cpp | 3 +- libsearch/res/icons/search-web-dark.svg | 15 +++ libsearch/res/icons/search-web-default.svg | 19 +++ libsearch/res/icons/search-web-icon.svg | 46 ++++++++ libsearch/resource1.qrc | 3 + .../settingsearch/settings-search-plugin.cpp | 2 +- libsearch/websearch/web-search-plugin.cpp | 110 +++++++++++++++++ libsearch/websearch/web-search-plugin.h | 52 ++++++++ libsearch/websearch/websearch.pri | 7 ++ .../libukui-search/libukui-search_zh_CN.ts | 41 ++++--- translations/ukui-search/bo.ts | 4 +- translations/ukui-search/tr.ts | 4 +- translations/ukui-search/zh_CN.ts | 4 +- 24 files changed, 348 insertions(+), 105 deletions(-) create mode 100644 libsearch/res/icons/search-web-dark.svg create mode 100644 libsearch/res/icons/search-web-default.svg create mode 100644 libsearch/res/icons/search-web-icon.svg create mode 100644 libsearch/websearch/web-search-plugin.cpp create mode 100644 libsearch/websearch/web-search-plugin.h create mode 100644 libsearch/websearch/websearch.pri diff --git a/frontend/control/list-labels/title-label.cpp b/frontend/control/list-labels/title-label.cpp index e9d4d94..03d404e 100644 --- a/frontend/control/list-labels/title-label.cpp +++ b/frontend/control/list-labels/title-label.cpp @@ -42,6 +42,7 @@ void TitleLabel::initUi() { this->setLayout(m_titleLyt); m_showMoreLabel = new ShowMoreLabel(this); m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT); + m_showMoreLabel->adjustSize(); m_showMoreLabel->hide(); m_titleLyt->addStretch(); m_titleLyt->addWidget(m_showMoreLabel); diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 73e46a7..400852d 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -51,15 +51,12 @@ ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent) void ResultArea::appendWidet(ResultWidget *widget) { - //NEW_TODO - m_mainLyt->removeWidget(m_webSearchWidget); m_mainLyt->addWidget(widget); setupConnectionsForWidget(widget); widget->clearResult(); m_widget_list.append(widget); int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0; m_widget->setFixedHeight(m_widget->height() + widget->height() + spacing_height); - m_mainLyt->addWidget(m_webSearchWidget); } /** @@ -82,8 +79,15 @@ void ResultArea::pressEnter() if (false == m_is_selected) {//未选中时默认选取bestlist第一项 int resultNum = m_bestListWidget->getResultNum(); if (0 == resultNum) {//无搜索结果时默认选中websearch - m_webSearchWidget->LaunchBrowser();//默认已选中websearch - m_is_selected = true; + for (ResultWidget * i : m_widget_list) { + if (m_selectedPluginID == m_widget_list.back()->pluginId()) { + QModelIndex index = i->getModlIndex(0, 0); + i->setResultSelection(index); + m_selectedPluginID = i->pluginId(); + m_is_selected = true; + break; + } + } } else {//选取bestlist第一项 QModelIndex index = m_bestListWidget->getModlIndex(0, 0); m_bestListWidget->setResultSelection(index); @@ -91,32 +95,28 @@ void ResultArea::pressEnter() m_is_selected = true; } } else {//选中状态时默认启动action首项 - if (m_selectedPluginID == m_webSearchWidget->getWidgetName()) {//选中网页搜索则启动搜索 - m_webSearchWidget->LaunchBrowser(); - } else { - //先判断详情页是否打开 - if (m_detail_open_state) { - if (m_selectedPluginID == m_bestListWidget->getWidgetName()) {//最佳匹配 - m_bestListWidget->activateIndex(); - } else { - for (ResultWidget * i : m_widget_list) { - if (m_selectedPluginID == i->pluginId()) { - i->activateIndex(); - break; - } + //先判断详情页是否打开 + if (m_detail_open_state) { + if (m_selectedPluginID == m_bestListWidget->getWidgetName()) {//最佳匹配 + m_bestListWidget->activateIndex(); + } else { + for (ResultWidget * i : m_widget_list) { + if (m_selectedPluginID == i->pluginId()) { + i->activateIndex(); + break; } } - } else {//打开详情页 - m_detail_open_state = true; - sendKeyPressSignal(m_selectedPluginID); } + } else {//打开详情页 + m_detail_open_state = true; + sendKeyPressSignal(m_selectedPluginID); } } } void ResultArea::pressDown() { - if (m_selectedPluginID == m_webSearchWidget->getWidgetName()) {//当前为web search,暂不处理 + if (m_selectedPluginID == m_widget_list.back()->pluginId()) {//当前为web search,暂不处理 return; } else if (m_selectedPluginID == m_bestListWidget->getWidgetName()) { QModelIndex index = m_bestListWidget->getCurrentSelection(); @@ -169,13 +169,6 @@ void ResultArea::pressDown() break; } } - if (indexNum >= m_widget_list.size()) {//下一项是web search - QModelIndex index = m_webSearchWidget->getModlIndex(0, 0); - m_webSearchWidget->setResultSelection(index); - m_selectedPluginID = m_webSearchWidget->getWidgetName(); - m_is_selected = true; - this->ensureWidgetVisible(m_webSearchWidget); - } if (findNextWidget){ break; } @@ -192,29 +185,7 @@ void ResultArea::pressUp() if (!m_is_selected) { return; } - if (m_selectedPluginID == m_webSearchWidget->getWidgetName()) {//当前为web search - if (m_bestListWidget->getResultNum() == 0) { - return; - } - m_webSearchWidget->clearResultSelection(); - for (int i = 0; i < m_widget_list.size(); i++) { - ResultWidget * plugin = m_widget_list[m_widget_list.size() - (i + 1)]; - bool findNextWidget = false; - if (0 != plugin->getResultNum()) { - int maxNum = plugin->getExpandState() ? - plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ? - plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT); - QModelIndex resultIndex = plugin->getModlIndex(maxNum - 1, 0); - plugin->setResultSelection(resultIndex); - m_selectedPluginID = plugin->pluginId(); - findNextWidget = true; - sendKeyPressSignal(m_selectedPluginID); - } - if (findNextWidget) { - break; - } - } - } else if (m_selectedPluginID == m_bestListWidget->getWidgetName()) { + if (m_selectedPluginID == m_bestListWidget->getWidgetName()) { QModelIndex index = m_bestListWidget->getCurrentSelection(); int maxNum = m_bestListWidget->getExpandState() ? m_bestListWidget->getResultNum() : (m_bestListWidget->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ? @@ -329,8 +300,6 @@ void ResultArea::onWidgetSizeChanged() whole_height += widget->height(); } whole_height += m_bestListWidget->height(); - //TODO 网页高度 - whole_height += m_webSearchWidget->height(); int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0; m_widget->setFixedHeight(whole_height + spacing_height * (m_widget_list.length() - 1)); @@ -345,9 +314,6 @@ void ResultArea::setSelectionInfo(QString &pluginID) if (m_selectedPluginID != m_bestListWidget->getWidgetName()) { m_bestListWidget->clearResultSelection(); } - if (m_selectedPluginID != m_webSearchWidget->getWidgetName()) { - m_webSearchWidget->clearResultSelection(); - } } void ResultArea::mousePressEvent(QMouseEvent *event) @@ -422,8 +388,6 @@ void ResultArea::initUi() m_bestListWidget->clearResult(); m_mainLyt->addWidget(m_bestListWidget); - m_webSearchWidget = new WebSearchWidget(this); - m_mainLyt->addWidget(m_webSearchWidget); m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS); this->widget()->setContentsMargins(0,0,0,0); m_mainLyt->setSpacing(0); @@ -435,21 +399,25 @@ void ResultArea::initUi() void ResultArea::initConnections() { connect(this, &ResultArea::startSearch, m_bestListWidget, &BestListWidget::startSearch); - connect(this, &ResultArea::startSearch, m_webSearchWidget, &WebSearchWidget::startSearch); connect(this, &ResultArea::startSearch, this, [=] () { m_detail_open_state = false; m_is_selected = false; - QModelIndex index = m_webSearchWidget->getModlIndex(0, 0);//每次启动搜索则选中web搜索,待bestlist收到结果后清空选中 - m_webSearchWidget->setResultSelection(index); + m_selectedPluginID = ""; }); connect(m_bestListWidget, &BestListWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged); connect(m_bestListWidget, &BestListWidget::sizeChanged, this, [=] () { - if (!m_is_selected) { - m_webSearchWidget->clearResultSelection();//每次启动搜索则选中web搜索,待bestlist收到结果后清空选中 - QModelIndex index = m_bestListWidget->getModlIndex(0, 0); + QModelIndex index = m_bestListWidget->getModlIndex(0, 0); + if (index.isValid()) { m_bestListWidget->setResultSelection(index); m_selectedPluginID = m_bestListWidget->getWidgetName(); m_is_selected = true; + + for (ResultWidget * i : m_widget_list) { + if (i->pluginId() == m_widget_list.back()->pluginId()) { + i->clearResultSelection(); + break; + } + } } }); @@ -458,12 +426,10 @@ void ResultArea::initConnections() m_detail_open_state = true; m_is_selected = true; m_selectedPluginID = m_bestListWidget->getWidgetName(); - m_webSearchWidget->clearResultSelection(); }); connect(this, &ResultArea::clearSelectedRow, m_bestListWidget, &BestListWidget::clearSelectedRow); connect(this, &ResultArea::resizeWidth, this, [=] (const int &size) { m_bestListWidget->setFixedWidth(size); - m_webSearchWidget->setFixedWidth(size); }); connect(m_bestListWidget, &BestListWidget::rowClicked, this, &ResultArea::rowClicked); connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] (int value) {//判断显示和隐藏逻辑 @@ -516,6 +482,16 @@ void ResultArea::setupConnectionsForWidget(ResultWidget *widget) }); connect(this, &ResultArea::stopSearch, widget, &ResultWidget::stopSearch); connect(widget, &ResultWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged); + connect(widget, &ResultWidget::sizeChanged, this, [=] () { + if (widget->pluginId() == m_widget_list.back()->pluginId() and m_selectedPluginID != m_bestListWidget->getWidgetName()) {//每次搜索默认选中websearch,由bestlist取消 + QModelIndex index = widget->getModlIndex(0, 0); + if (index.isValid()) { + widget->setResultSelection(index); + m_is_selected = true; + m_selectedPluginID = widget->pluginId(); + } + } + }); connect(widget, &ResultWidget::showMoreClicked, this, [=] () {//点击展开搜索结果后 显示悬浮窗 this->verticalScrollBar()->setValue(widget->pos().ry() + TITLE_HEIGHT); //置顶当前类型搜索结果 if (widget->height() > FRAME_HEIGHT) {//当前widget高度大于搜索结果界面高度则显示悬浮窗 @@ -649,6 +625,7 @@ void DetailWidget::updateDetailPage(const QString &plugin_name, const SearchPlug m_mainLyt->addWidget(m_detailPage); // m_mainLyt->insertWidget(0, m_detailPage, 0); } + m_currentPluginId = plugin_name; } void DetailWidget::clear() diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 9cd37bd..496a741 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -66,7 +66,6 @@ private: QVBoxLayout * m_mainLyt = nullptr; BestListWidget * m_bestListWidget = nullptr; QList m_widget_list; - WebSearchWidget * m_webSearchWidget = nullptr; TitleLabel * m_titleLable = nullptr; bool m_detail_open_state = false; diff --git a/frontend/model/best-list-model.cpp b/frontend/model/best-list-model.cpp index 20b0c28..d359853 100644 --- a/frontend/model/best-list-model.cpp +++ b/frontend/model/best-list-model.cpp @@ -105,11 +105,11 @@ QString BestListModel::getKey(const QModelIndex &index) void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface::ResultInfo &info) { - if (pluginId == "File Search" && m_fileActionKey_tmp != info.actionKey) {//临时保存文件搜索结果的actionKey - m_fileActionKey_tmp = info.actionKey; - } - if (pluginId == "File Content Search" && info.actionKey == m_fileActionKey_tmp) {//文本搜索判断是否和保存的actionKey相同 + if (m_plugin_action_key_list.contains(info.actionKey)) { + qDebug() << "plugin ID:" << pluginId << "name:" << info.name << "action key:" << info.actionKey << "is same with pre-result!"; return; + } else { + m_plugin_action_key_list.append(info.actionKey); } if (m_plugin_id_list.contains(pluginId)) { if (info.name == m_item->m_result_info_list.at(m_plugin_id_list.lastIndexOf(pluginId)).name) { @@ -148,6 +148,7 @@ void BestListModel::startSearch(const QString &keyword) if (!m_item->m_result_info_list.isEmpty()) { this->beginResetModel(); m_plugin_id_list.clear(); + m_plugin_action_key_list.clear(); m_item->m_result_info_list.clear(); this->endResetModel(); Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); diff --git a/frontend/model/best-list-model.h b/frontend/model/best-list-model.h index 6d44902..dc04d58 100644 --- a/frontend/model/best-list-model.h +++ b/frontend/model/best-list-model.h @@ -43,8 +43,8 @@ private: void initConnections(); SearchResultItem * m_item = nullptr; QVector m_plugin_id_list; + QVector m_plugin_action_key_list; bool m_isExpanded = false; - QString m_fileActionKey_tmp; }; } #endif // BESTLISTMODEL_H diff --git a/frontend/model/search-result-model.cpp b/frontend/model/search-result-model.cpp index 147707d..f6aa0a8 100644 --- a/frontend/model/search-result-model.cpp +++ b/frontend/model/search-result-model.cpp @@ -81,7 +81,9 @@ void SearchResultModel::appendInfo(const SearchPluginIface::ResultInfo &info) m_item->m_result_info_list.append(info); this->endResetModel(); Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); - Q_EMIT this->sendBestListData(m_plugin_id, m_item->m_result_info_list.at(0)); + if (m_plugin_id != "Web Page") { + Q_EMIT this->sendBestListData(m_plugin_id, m_item->m_result_info_list.at(0)); + } } void SearchResultModel::startSearch(const QString &keyword) diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index fbd697c..71c6b90 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -119,7 +119,7 @@ void ResultWidget::initUi() m_mainLyt->setSpacing(MAIN_SPACING); m_titleLabel = new TitleLabel(this); - m_titleLabel->setText(m_plugin_id); + m_titleLabel->setText(SearchPluginManager::getInstance()->getPlugin(m_plugin_id)->getPluginName()); m_titleLabel->setFixedHeight(TITLE_HEIGHT); m_resultView = new ResultView(m_plugin_id, this); diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 67657f1..a31e07a 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -22,7 +22,7 @@ AppSearchPlugin::AppSearchPlugin(QObject *parent) : QObject(parent) const QString AppSearchPlugin::name() { - return tr("Applications Search"); + return "Applications Search"; } const QString AppSearchPlugin::description() diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index 785044b..a41d530 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -19,7 +19,7 @@ FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent) const QString FileSearchPlugin::name() { - return tr("File Search"); + return "File Search"; } const QString FileSearchPlugin::description() @@ -226,7 +226,7 @@ DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent) const QString DirSearchPlugin::name() { - return tr("Dir Search"); + return "Dir Search"; } const QString DirSearchPlugin::description() @@ -406,7 +406,7 @@ FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(pare const QString FileContengSearchPlugin::name() { - return tr("File Content Search"); + return "File Content Search"; } const QString FileContengSearchPlugin::description() diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index c123147..9cea2bf 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -31,6 +31,7 @@ include(parser/parser.pri) include(appsearch/appsearch.pri) include(notesearch/notesearch.pri) include(settingsearch/settingsearch.pri) +include(websearch/websearch.pri) LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation LIBS += -lxapian -lquazip5 -luchardet -lQt5Xdg#-L/usr/local/lib/libjemalloc -ljemalloc @@ -67,7 +68,7 @@ unix { INSTALLS += target header.path = /usr/include/ukui-search - header.files += *.h index/*.h appsearch/*.h settingsearch/*.h plugininterface/*.h + header.files += *.h index/*.h appsearch/*.h settingsearch/*.h plugininterface/*.h websearch/*.h INSTALLS += header } INCLUDEPATH += $$PWD/../libchinese-segmentation diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index dc74dc8..23b1b39 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -18,7 +18,7 @@ NoteSearchPlugin::NoteSearchPlugin(QObject *parent) const QString NoteSearchPlugin::name() { - return tr("Note Search"); + return "Note Search"; } const QString NoteSearchPlugin::description() diff --git a/libsearch/pluginmanage/search-plugin-manager.cpp b/libsearch/pluginmanage/search-plugin-manager.cpp index 0d10bef..aed7e31 100644 --- a/libsearch/pluginmanage/search-plugin-manager.cpp +++ b/libsearch/pluginmanage/search-plugin-manager.cpp @@ -4,6 +4,7 @@ #include "app-search-plugin.h" #include "settings-search-plugin.h" #include "note-search-plugin.h" +#include "web-search-plugin.h" using namespace Zeeker; @@ -16,7 +17,7 @@ SearchPluginManager::SearchPluginManager(QObject *parent) registerPlugin(new DirSearchPlugin(this)); registerPlugin(new FileSearchPlugin(this)); registerPlugin(new FileContengSearchPlugin(this)); - + registerPlugin(new WebSearchPlugin(this)); } bool SearchPluginManager::registerPlugin(Zeeker::SearchPluginIface *plugin) diff --git a/libsearch/res/icons/search-web-dark.svg b/libsearch/res/icons/search-web-dark.svg new file mode 100644 index 0000000..d21e934 --- /dev/null +++ b/libsearch/res/icons/search-web-dark.svg @@ -0,0 +1,15 @@ + + + Search-web-深色模式 + + + + + + + + + + + + \ No newline at end of file diff --git a/libsearch/res/icons/search-web-default.svg b/libsearch/res/icons/search-web-default.svg new file mode 100644 index 0000000..4367d7f --- /dev/null +++ b/libsearch/res/icons/search-web-default.svg @@ -0,0 +1,19 @@ + + + Search-web-浅色模式 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libsearch/res/icons/search-web-icon.svg b/libsearch/res/icons/search-web-icon.svg new file mode 100644 index 0000000..e3d10fc --- /dev/null +++ b/libsearch/res/icons/search-web-icon.svg @@ -0,0 +1,46 @@ + + + 搜索 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libsearch/resource1.qrc b/libsearch/resource1.qrc index cdcb612..9f2227b 100644 --- a/libsearch/resource1.qrc +++ b/libsearch/resource1.qrc @@ -7,5 +7,8 @@ res/icons/edit-find-symbolic.svg res/icons/net-disconnected.svg res/icons/system-search.symbolic.png + res/icons/search-web-icon.svg + res/icons/search-web-dark.svg + res/icons/search-web-default.svg diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index a2a4a0b..d97bdff 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -18,7 +18,7 @@ SettingsSearchPlugin::SettingsSearchPlugin(QObject *parent) : QObject(parent) const QString SettingsSearchPlugin::name() { - return tr("Settings Search"); + return "Settings Search"; } const QString SettingsSearchPlugin::description() diff --git a/libsearch/websearch/web-search-plugin.cpp b/libsearch/websearch/web-search-plugin.cpp new file mode 100644 index 0000000..d3804f8 --- /dev/null +++ b/libsearch/websearch/web-search-plugin.cpp @@ -0,0 +1,110 @@ +#include "web-search-plugin.h" +#include "global-settings.h" + +using namespace Zeeker; +WebSearchPlugin::WebSearchPlugin(QObject *parent) : QObject(parent) +{ + SearchPluginIface::Actioninfo open { 0, tr("Start browser search")}; + m_actionInfo << open; + initDetailPage(); +} + +const QString Zeeker::WebSearchPlugin::name() +{ + return "Web Page"; +} + +const QString Zeeker::WebSearchPlugin::description() +{ + return tr("Web Page"); +} + +QString Zeeker::WebSearchPlugin::getPluginName() +{ + return tr("Web Page"); +} + +void Zeeker::WebSearchPlugin::KeywordSearch(QString keyword, DataQueue *searchResult) +{ + m_keyWord = keyword; + ResultInfo resultInfo; + resultInfo.name = m_keyWord; + resultInfo.type = 0; + resultInfo.icon = QIcon(":/res/icons/search-web-icon.svg"); + resultInfo.actionKey = m_keyWord; + searchResult->enqueue(resultInfo); +} + +QList Zeeker::WebSearchPlugin::getActioninfo(int type) +{ + return m_actionInfo; +} + +void Zeeker::WebSearchPlugin::openAction(int actionkey, QString key, int type) +{ + 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 ; //百度 + } + QDesktopServices::openUrl(address); +} + +QWidget *Zeeker::WebSearchPlugin::detailPage(const Zeeker::SearchPluginIface::ResultInfo &ri) +{ + return m_detailPage; +} + +void Zeeker::WebSearchPlugin::initDetailPage() +{ + m_detailPage = new QWidget(); + m_detailPage->setFixedWidth(360); + m_detailPage->setAttribute(Qt::WA_TranslucentBackground); + m_detailLyt = new QVBoxLayout(m_detailPage); + m_detailLyt->setContentsMargins(8, 0, 16, 0); + m_iconLabel = new QLabel(m_detailPage); + m_iconLabel->setAlignment(Qt::AlignCenter); + QString type = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); + if (type == "ukui-dark") { + m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(100, 96)); + } else { + m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-default.svg").pixmap(100, 96)); + } + connect(qApp, &QApplication::paletteChanged, this, [=] () { + QString type = GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString(); + if (type == "ukui-dark") { + m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-dark.svg").pixmap(100, 96)); + } else { + m_iconLabel->setPixmap(QIcon(":/res/icons/search-web-default.svg").pixmap(100, 96)); + } + }); + + m_actionFrame = new QFrame(m_detailPage); + m_actionFrameLyt = new QVBoxLayout(m_actionFrame); + m_actionFrameLyt->setContentsMargins(0, 0, 0, 0); + m_actionFrameLyt->setAlignment(Qt::AlignCenter); + m_actionLabel1 = new ActionLabel(tr("Start browser search"), m_currentActionKey, m_actionFrame); + m_actionLabel1->adjustSize(); + + m_actionFrameLyt->addWidget(m_actionLabel1);; + m_actionFrame->setLayout(m_actionFrameLyt); + + m_detailLyt->addSpacing(166); + m_detailLyt->addWidget(m_iconLabel); + m_detailLyt->addSpacing(6); + m_detailLyt->addWidget(m_actionFrame); + m_detailPage->setLayout(m_detailLyt); + m_detailLyt->addStretch(); + + connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){ + openAction(0, m_currentActionKey, 0); + }); +} diff --git a/libsearch/websearch/web-search-plugin.h b/libsearch/websearch/web-search-plugin.h new file mode 100644 index 0000000..4f7bc87 --- /dev/null +++ b/libsearch/websearch/web-search-plugin.h @@ -0,0 +1,52 @@ +#ifndef WEBSEARCHPLUGIN_H +#define WEBSEARCHPLUGIN_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "action-label.h" +#include "search-plugin-iface.h" + +namespace Zeeker { +class LIBSEARCH_EXPORT WebSearchPlugin : public QObject, public SearchPluginIface +{ + Q_OBJECT + +public: + explicit WebSearchPlugin(QObject *parent = nullptr); + PluginType pluginType() {return PluginType::SearchPlugin;} + const QString name(); + const QString description(); + const QIcon icon() {return QIcon::fromTheme("folder");} + void setEnable(bool enable) {m_enable = enable;} + bool isEnable() {return m_enable;} + QString getPluginName(); + void KeywordSearch(QString keyword,DataQueue *searchResult); + QList getActioninfo(int type); + void openAction(int actionkey, QString key, int type); + QWidget *detailPage(const ResultInfo &ri); + +private: + void initDetailPage(); + QString m_keyWord; + QString m_currentActionKey; + QWidget *m_detailPage = nullptr; + QVBoxLayout *m_detailLyt = nullptr; + QLabel *m_iconLabel = nullptr; + QFrame *m_actionFrame = nullptr; + QVBoxLayout *m_actionFrameLyt = nullptr; + ActionLabel *m_actionLabel1 = nullptr; + + QVBoxLayout * m_actionLyt = nullptr; + + bool m_enable = true; + QList m_actionInfo; +}; +} +#endif // WEBSEARCHPLUGIN_H diff --git a/libsearch/websearch/websearch.pri b/libsearch/websearch/websearch.pri new file mode 100644 index 0000000..3a3830b --- /dev/null +++ b/libsearch/websearch/websearch.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/web-search-plugin.h + +SOURCES += \ + $$PWD/web-search-plugin.cpp diff --git a/translations/libukui-search/libukui-search_zh_CN.ts b/translations/libukui-search/libukui-search_zh_CN.ts index e4fb3e8..012f661 100644 --- a/translations/libukui-search/libukui-search_zh_CN.ts +++ b/translations/libukui-search/libukui-search_zh_CN.ts @@ -4,7 +4,7 @@ Zeeker::AppMatch - + Application Description: 应用描述: @@ -43,7 +43,6 @@ 安装 - Applications Search @@ -79,7 +78,6 @@ 复制文件路径 - Dir Search 目录搜索 @@ -114,13 +112,13 @@ Zeeker::FileContengSearchPlugin - + Open 打开 - + Open path 打开文件所在路径 @@ -130,9 +128,8 @@ 复制文件路径 - File Content Search - 文本内容搜索 + 文本内容搜索 @@ -150,17 +147,17 @@ 文件 - + Path 路径 - + Last time modified 上次修改时间 - + Copy path 复制路径 @@ -185,7 +182,6 @@ 复制文件路径 - File Search 文件搜索 @@ -205,7 +201,7 @@ Can not get a default application for opening %1. - 没有找到默认打开%1的应用。 + 没有找到默认打开%1的应用。 @@ -247,7 +243,6 @@ 打开 - Note Search @@ -284,12 +279,11 @@ Zeeker::SettingsSearchPlugin - + Open 打开 - Settings Search 设置 @@ -300,9 +294,24 @@ 设置。 - + Settings 设置项 + + Zeeker::WebSearchPlugin + + + + Start browser search + 启动浏览器搜索 + + + + + Web Page + 网页 + + diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 03056e1..2546e0a 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -12,7 +12,7 @@ Zeeker::BestListWidget - + Best Matches @@ -243,7 +243,7 @@ Zeeker::WebSearchWidget - + Web Page diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index f6d15c1..8b1b29f 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -247,7 +247,7 @@ Zeeker::BestListWidget - + Best Matches En İyi Eşleşen @@ -616,7 +616,7 @@ Zeeker::WebSearchWidget - + Web Page diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index 4679561..0633143 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -12,7 +12,7 @@ Zeeker::BestListWidget - + Best Matches 最佳匹配 @@ -397,7 +397,7 @@ Zeeker::WebSearchWidget - + Web Page