1.调整主程序执行命令方式,链接dbus接口功能

This commit is contained in:
hewenfei 2022-12-12 15:16:45 +08:00
parent 6139108645
commit 0e321fc17e
2 changed files with 40 additions and 27 deletions

View File

@ -33,7 +33,7 @@ UkuiMenuApplication::UkuiMenuApplication(MenuMessageProcessor *processor) : QObj
registerQmlTypes();
startUkuiMenu();
initDbusService();
connect(processor, &MenuMessageProcessor::request, this, &UkuiMenuApplication::response);
connect(processor, &MenuMessageProcessor::request, this, &UkuiMenuApplication::execCommand);
}
void UkuiMenuApplication::startUkuiMenu()
@ -71,23 +71,36 @@ void UkuiMenuApplication::initQmlEngine()
void UkuiMenuApplication::initDbusService()
{
m_menuDbusService = new MenuDbusService(this);
if (m_menuDbusService) {
connect(m_menuDbusService, &MenuDbusService::menuActive, this, [this] {
execCommand(Active);
});
// connect(m_menuDbusService, &MenuDbusService::reloadConfigSignal, this, [this] {
//// reload ...
// });
}
}
void UkuiMenuApplication::response(MenuMessageProcessor::Command command)
void UkuiMenuApplication::execCommand(Command command)
{
switch (command) {
case MenuMessageProcessor::Show:
// m_applicationEngine;
case Active:
qDebug() << "=Active=>>" << Active;
break;
case MenuMessageProcessor::Quit:
case Show:
qDebug() << "=Show=>>" << Show;
break;
case Quit:
qDebug() << "=Quit=>>" << Quit;
m_applicationEngine->quit();
QCoreApplication::quit();
break;
default:
break;
}
}
// == MenuMessageProcessor == //
MenuMessageProcessor::MenuMessageProcessor() : QObject(nullptr) {}
void MenuMessageProcessor::processMessage(quint32 instanceId, const QByteArray &message)
@ -105,13 +118,12 @@ void MenuMessageProcessor::processMessage(quint32 instanceId, const QByteArray &
parser.parse(options);
if (parser.isSet(showUkuiMenu)) {
Q_EMIT request(Show);
Q_EMIT request(UkuiMenuApplication::Show);
return;
}
if (parser.isSet(quitUkuiMenu)) {
Q_EMIT request(Quit);
QCoreApplication::quit();
Q_EMIT request(UkuiMenuApplication::Quit);
return;
}
}

View File

@ -24,35 +24,24 @@
namespace UkuiMenu {
class MenuMessageProcessor : public QObject
{
Q_OBJECT
public:
enum Command {
Show = 0,
Quit
};
MenuMessageProcessor();
static bool preprocessMessage(const QStringList& message);
public Q_SLOTS:
void processMessage(quint32 instanceId, const QByteArray& message);
Q_SIGNALS:
void request(Command command);
};
class MenuMessageProcessor;
class UkuiMenuApplication : public QObject
{
Q_OBJECT
public:
enum Command {
Active = 0,
Show,
Quit
};
explicit UkuiMenuApplication(MenuMessageProcessor *processor);
UkuiMenuApplication() = delete;
UkuiMenuApplication(const UkuiMenuApplication& obj) = delete;
UkuiMenuApplication(const UkuiMenuApplication&& obj) = delete;
private Q_SLOTS:
void response(MenuMessageProcessor::Command command);
void execCommand(UkuiMenuApplication::Command command);
private:
static void registerQmlTypes();
@ -67,7 +56,19 @@ private:
MenuDbusService *m_menuDbusService = nullptr;
};
class MenuMessageProcessor : public QObject
{
Q_OBJECT
public:
MenuMessageProcessor();
static bool preprocessMessage(const QStringList& message);
public Q_SLOTS:
void processMessage(quint32 instanceId, const QByteArray& message);
Q_SIGNALS:
void request(UkuiMenuApplication::Command command);
};
}