给menu添加dbus接口

This commit is contained in:
gjq 2022-12-12 10:02:44 +08:00 committed by hewenfei
parent 96084f0918
commit a4aaab5d7b
5 changed files with 109 additions and 0 deletions

View File

@ -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

49
src/menu-dbus-service.cpp Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#include <QDir>
#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();
}

48
src/menu-dbus-service.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#ifndef MENU_DBUS_SERVICE_H
#define MENU_DBUS_SERVICE_H
#include <QObject>
#include <QDBusInterface>
#include <QDBusConnection>
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

View File

@ -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) {

View File

@ -19,6 +19,7 @@
#ifndef UKUI_MENU_UKUI_MENU_APPLICATION_H
#define UKUI_MENU_UKUI_MENU_APPLICATION_H
#include "menu-dbus-service.h"
#include <QQmlApplicationEngine>
namespace UkuiMenu {
@ -58,8 +59,12 @@ private:
void startUkuiMenu();
void initQmlEngine();
//注册dubs
void initDbusService();
private:
QQmlApplicationEngine *m_applicationEngine{nullptr};
MenuDbusService *m_menuDbusService = nullptr;
};