From ac81ac7af25eda2197cd708d0d5e3c567eb6a524 Mon Sep 17 00:00:00 2001 From: iaom Date: Wed, 2 Nov 2022 20:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8F=92=E4=BB=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=8F=8D=E5=90=91?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=A2=9E=E5=8A=A0=E6=88=AA=E5=9B=BE=E6=89=93?= =?UTF-8?q?=E5=BC=80=E6=97=B6=E9=9A=90=E8=97=8F=E4=B8=BB=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/mainwindow.cpp | 2 ++ libsearch/appsearch/app-search-plugin.cpp | 3 +++ .../plugininterface/action-transmiter.cpp | 24 +++++++++++++++++ libsearch/plugininterface/action-transmiter.h | 26 +++++++++++++++++++ .../plugininterface/plugin-interface.pri | 5 +++- .../plugininterface/search-plugin-iface.cpp | 9 +++++++ .../plugininterface/search-plugin-iface.h | 10 ++++++- 7 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 libsearch/plugininterface/action-transmiter.cpp create mode 100644 libsearch/plugininterface/action-transmiter.h create mode 100644 libsearch/plugininterface/search-plugin-iface.cpp diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 2851519..d04e876 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -38,6 +38,7 @@ #include "ukuistylehelper/ukuistylehelper.h" #include "windowmanager/windowmanager.h" #include "global-settings.h" +#include "action-transmiter.h" #define MAIN_MARGINS 0, 0, 0, 0 #define TITLE_MARGINS 0,0,0,0 @@ -95,6 +96,7 @@ MainWindow::MainWindow(QWidget *parent) : this->bootOptionsFilter("-s"); this->setText(keyword); }); + connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow); //NEW_TODO, register plugins // SearchPluginManager::getInstance()->registerPlugin(\\); // m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds()); diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index dc3bfc4..0132767 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -265,6 +265,9 @@ void AppSearchPlugin::initDetailPage() bool AppSearchPlugin::launch(const QString &path) { + if(QFileInfo(path).fileName() == "kylin-screenshot.desktop") { + invokeActions(InvokableAction::HideUI); + } bool res(false); QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", "/com/kylin/AppManager", diff --git a/libsearch/plugininterface/action-transmiter.cpp b/libsearch/plugininterface/action-transmiter.cpp new file mode 100644 index 0000000..80dc758 --- /dev/null +++ b/libsearch/plugininterface/action-transmiter.cpp @@ -0,0 +1,24 @@ +#include "action-transmiter.h" +#include +using namespace UkuiSearch; + +static std::once_flag flag; +static ActionTransmiter *global_intance = nullptr; +ActionTransmiter::ActionTransmiter(QObject *parent) : QObject(parent) +{ +} + +ActionTransmiter *ActionTransmiter::getInstance() +{ + std::call_once(flag, [ & ] { + global_intance = new ActionTransmiter(); + }); + return global_intance; +} + +void ActionTransmiter::invokeActions(SearchPluginIface::InvokableActions actions) +{ + if(SearchPluginIface::InvokableAction::HideUI == actions) { + Q_EMIT hideUIAction(); + } +} diff --git a/libsearch/plugininterface/action-transmiter.h b/libsearch/plugininterface/action-transmiter.h new file mode 100644 index 0000000..94d768c --- /dev/null +++ b/libsearch/plugininterface/action-transmiter.h @@ -0,0 +1,26 @@ +#ifndef ACTIONTRANSMITER_H +#define ACTIONTRANSMITER_H + +#include +#include "search-plugin-iface.h" +namespace UkuiSearch { +/** + * @brief The ActionTransmiter class + * 转发搜索插件的action调用信号 + */ +class ActionTransmiter : public QObject +{ + Q_OBJECT +public: + static ActionTransmiter *getInstance(); + Q_INVOKABLE void invokeActions(SearchPluginIface::InvokableActions actions); + +Q_SIGNALS: + void hideUIAction(); + +private: + ActionTransmiter(QObject *parent = nullptr); +}; + +} +#endif // ACTIONTRANSMITER_H diff --git a/libsearch/plugininterface/plugin-interface.pri b/libsearch/plugininterface/plugin-interface.pri index e4aec47..0c2a73b 100644 --- a/libsearch/plugininterface/plugin-interface.pri +++ b/libsearch/plugininterface/plugin-interface.pri @@ -1,6 +1,7 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/action-transmiter.h \ $$PWD/action-label.h \ $$PWD/common-defines.h \ $$PWD/plugin-iface.h \ @@ -10,6 +11,8 @@ HEADERS += \ $$PWD/separation-line.h SOURCES += \ + $$PWD/action-transmiter.cpp \ $$PWD/action-label.cpp \ - $$PWD/separation-line.cpp + $$PWD/separation-line.cpp \ + $$PWD/search-plugin-iface.cpp diff --git a/libsearch/plugininterface/search-plugin-iface.cpp b/libsearch/plugininterface/search-plugin-iface.cpp new file mode 100644 index 0000000..628f12d --- /dev/null +++ b/libsearch/plugininterface/search-plugin-iface.cpp @@ -0,0 +1,9 @@ +#include "action-transmiter.h" +#include "search-plugin-iface.h" + +using namespace UkuiSearch; + +void SearchPluginIface::invokeActions(InvokableActions actions) +{ + ActionTransmiter::getInstance()->invokeActions(actions); +} diff --git a/libsearch/plugininterface/search-plugin-iface.h b/libsearch/plugininterface/search-plugin-iface.h index a340acd..1eb1a13 100644 --- a/libsearch/plugininterface/search-plugin-iface.h +++ b/libsearch/plugininterface/search-plugin-iface.h @@ -15,6 +15,13 @@ namespace UkuiSearch { class SearchPluginIface : public PluginInterface { public: + enum InvokableAction + { + None = 1u << 0, + HideUI = 1u << 1 + }; + Q_DECLARE_FLAGS(InvokableActions, InvokableAction) + struct DescriptionInfo { QString key; @@ -46,9 +53,10 @@ public: // virtual bool isPreviewEnable(QString key, int type) = 0; // virtual QWidget *previewPage(QString key, int type, QWidget *parent = nullptr) = 0; virtual QWidget *detailPage(const ResultInfo &ri) = 0; + + void invokeActions(InvokableActions actions); }; } - Q_DECLARE_INTERFACE(UkuiSearch::SearchPluginIface, SearchPluginIface_iid) #endif // SEARCHPLUGINIFACE_H