diff --git a/CMakeLists.txt b/CMakeLists.txt index 851e0cf..3a1acd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ add_compile_definitions(UKUI_MENU_TRANSLATION_DIR="${UKUI_MENU_TRANSLATION_DIR}" set(SOURCE_FILES src/main.cpp src/commons.h + src/menu-dbus-service.cpp src/menu-dbus-service.h src/model/model.cpp src/model/model.h src/settings/settings.cpp src/settings/settings.h src/uiconfig/color-helper.cpp src/uiconfig/color-helper.h diff --git a/src/menu-dbus-service.cpp b/src/menu-dbus-service.cpp new file mode 100644 index 0000000..8202d84 --- /dev/null +++ b/src/menu-dbus-service.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include +#include "menu-dbus-service.h" + +#define MENU_CORE_DBUS_SERVICE "org.ukui.menu" +#define MENU_CORE_DBUS_PATH "/org/ukui/menu" + +using namespace UkuiMenu; + +MenuDbusService::MenuDbusService(QObject *parent) : QObject(parent) +{ + QDBusConnection::sessionBus().unregisterService(MENU_CORE_DBUS_SERVICE); + QDBusConnection::sessionBus().registerService(MENU_CORE_DBUS_SERVICE); + //注册对象路径,导出所有此对象的插槽 ,registerObject参数:路径,interface,对象,options + QDBusConnection::sessionBus().registerObject(MENU_CORE_DBUS_PATH, this, QDBusConnection::ExportAllSlots); +} + +void MenuDbusService::WinKeyResponse() +{ + Q_EMIT menuActive(); +} + +QString MenuDbusService::GetSecurityConfigPath() +{ + QString path = QDir::homePath() + "/.config/ukui-menu-security-config.json"; + return path; +} + +void MenuDbusService::ReloadSecurityConfig() +{ + Q_EMIT reloadConfigSignal(); +} diff --git a/src/menu-dbus-service.h b/src/menu-dbus-service.h new file mode 100644 index 0000000..d2819f5 --- /dev/null +++ b/src/menu-dbus-service.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef MENU_DBUS_SERVICE_H +#define MENU_DBUS_SERVICE_H + +#include +#include +#include + +namespace UkuiMenu { + +class MenuDbusService : public QObject +{ + Q_OBJECT + //申明该类有D-BUS服务接口 + Q_CLASSINFO("D-Bus Interface", "org.ukui.menu") +public: + explicit MenuDbusService(QObject *parent = nullptr); //传入父指针,调用 + +public Q_SLOTS: + void WinKeyResponse(); + QString GetSecurityConfigPath(); + void ReloadSecurityConfig(); + +Q_SIGNALS: + void menuActive(); + void reloadConfigSignal(); +}; + +} + +#endif // MENU_DBUS_SERVICE_H diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index f6bd814..c0356e0 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -30,6 +30,7 @@ UkuiMenuApplication::UkuiMenuApplication(MenuMessageProcessor *processor) : QObj { registerQmlTypes(); startUkuiMenu(); + initDbusService(); connect(processor, &MenuMessageProcessor::request, this, &UkuiMenuApplication::response); } @@ -59,6 +60,11 @@ void UkuiMenuApplication::initQmlEngine() m_applicationEngine->load(url); } +void UkuiMenuApplication::initDbusService() +{ + m_menuDbusService = new MenuDbusService(this); +} + void UkuiMenuApplication::response(MenuMessageProcessor::Command command) { switch (command) { diff --git a/src/ukui-menu-application.h b/src/ukui-menu-application.h index 10c3f7d..63779e1 100644 --- a/src/ukui-menu-application.h +++ b/src/ukui-menu-application.h @@ -19,6 +19,7 @@ #ifndef UKUI_MENU_UKUI_MENU_APPLICATION_H #define UKUI_MENU_UKUI_MENU_APPLICATION_H +#include "menu-dbus-service.h" #include namespace UkuiMenu { @@ -58,8 +59,12 @@ private: void startUkuiMenu(); void initQmlEngine(); + //注册dubs + void initDbusService(); + private: QQmlApplicationEngine *m_applicationEngine{nullptr}; + MenuDbusService *m_menuDbusService = nullptr; };