搜索插件接口增加一个反向调用接口,应用搜索增加截图打开时隐藏主页面动作。

This commit is contained in:
iaom 2022-11-02 20:50:30 +08:00
parent 4e37c1d210
commit ceb36981b4
7 changed files with 77 additions and 2 deletions

View File

@ -38,6 +38,7 @@
#include "ukuistylehelper/ukuistylehelper.h" #include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h" #include "windowmanager/windowmanager.h"
#include "global-settings.h" #include "global-settings.h"
#include "action-transmiter.h"
#define MAIN_MARGINS 0, 0, 0, 0 #define MAIN_MARGINS 0, 0, 0, 0
#define TITLE_MARGINS 0,0,0,0 #define TITLE_MARGINS 0,0,0,0
@ -95,6 +96,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->bootOptionsFilter("-s"); this->bootOptionsFilter("-s");
this->setText(keyword); this->setText(keyword);
}); });
connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow);
//NEW_TODO, register plugins //NEW_TODO, register plugins
// SearchPluginManager::getInstance()->registerPlugin(\\); // SearchPluginManager::getInstance()->registerPlugin(\\);
// m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds()); // m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds());

View File

@ -265,6 +265,9 @@ void AppSearchPlugin::initDetailPage()
bool AppSearchPlugin::launch(const QString &path) bool AppSearchPlugin::launch(const QString &path)
{ {
if(QFileInfo(path).fileName() == "kylin-screenshot.desktop") {
invokeActions(InvokableAction::HideUI);
}
bool res(false); bool res(false);
QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager",
"/com/kylin/AppManager", "/com/kylin/AppManager",

View File

@ -0,0 +1,24 @@
#include "action-transmiter.h"
#include <mutex>
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();
}
}

View File

@ -0,0 +1,26 @@
#ifndef ACTIONTRANSMITER_H
#define ACTIONTRANSMITER_H
#include <QObject>
#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

View File

@ -1,6 +1,7 @@
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
HEADERS += \ HEADERS += \
$$PWD/action-transmiter.h \
$$PWD/action-label.h \ $$PWD/action-label.h \
$$PWD/common-defines.h \ $$PWD/common-defines.h \
$$PWD/plugin-iface.h \ $$PWD/plugin-iface.h \
@ -10,6 +11,8 @@ HEADERS += \
$$PWD/separation-line.h $$PWD/separation-line.h
SOURCES += \ SOURCES += \
$$PWD/action-transmiter.cpp \
$$PWD/action-label.cpp \ $$PWD/action-label.cpp \
$$PWD/separation-line.cpp $$PWD/separation-line.cpp \
$$PWD/search-plugin-iface.cpp

View File

@ -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);
}

View File

@ -15,6 +15,13 @@ namespace UkuiSearch {
class SearchPluginIface : public PluginInterface class SearchPluginIface : public PluginInterface
{ {
public: public:
enum InvokableAction
{
None = 1u << 0,
HideUI = 1u << 1
};
Q_DECLARE_FLAGS(InvokableActions, InvokableAction)
struct DescriptionInfo struct DescriptionInfo
{ {
QString key; QString key;
@ -46,9 +53,10 @@ public:
// virtual bool isPreviewEnable(QString key, int type) = 0; // virtual bool isPreviewEnable(QString key, int type) = 0;
// virtual QWidget *previewPage(QString key, int type, QWidget *parent = nullptr) = 0; // virtual QWidget *previewPage(QString key, int type, QWidget *parent = nullptr) = 0;
virtual QWidget *detailPage(const ResultInfo &ri) = 0; virtual QWidget *detailPage(const ResultInfo &ri) = 0;
void invokeActions(InvokableActions actions);
}; };
} }
Q_DECLARE_INTERFACE(UkuiSearch::SearchPluginIface, SearchPluginIface_iid) Q_DECLARE_INTERFACE(UkuiSearch::SearchPluginIface, SearchPluginIface_iid)
#endif // SEARCHPLUGINIFACE_H #endif // SEARCHPLUGINIFACE_H