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