Merge tag 'upstream/4.0.0.9' into packaging/openkylin/yangtze

4.0.0.9 release
This commit is contained in:
hewenfei 2023-09-12 15:52:57 +08:00
commit adcca09d2e
7 changed files with 208 additions and 19 deletions

View File

@ -121,6 +121,13 @@ set(SOURCE_FILES
src/settings/user-config.cpp src/settings/user-config.h
)
if(COMMAND qt_add_dbus_adaptor)
qt_add_dbus_adaptor(SOURCE_FILES data/org.ukui.menu.xml menu-dbus-service.h UkuiMenu::MenuDbusService)
else()
qt5_add_dbus_adaptor(SOURCE_FILES data/org.ukui.menu.xml menu-dbus-service.h UkuiMenu::MenuDbusService)
endif()
# library sources
set(LIBRARY_SOURCES
src/data-entity.cpp

16
data/org.ukui.menu.xml Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.ukui.menu">
<method name="WinKeyResponse"/>
<method name="ReloadSecurityConfig"/>
<method name="GetSecurityConfigPath">
<arg type="s" direction="out"/>
</method>
<method name="active">
<arg name="display" type="s" direction="in"/>
</method>
<signal name="activeRequest">
<arg name="display" type="s" direction="out"/>
</signal>
</interface>
</node>

View File

@ -6,6 +6,7 @@
#include <QDir>
#include <QDateTime>
#include <QStandardPaths>
#include <KWindowSystem>
#include "qtsingleapplication.h"
#include "ukui-menu-application.h"
@ -138,9 +139,17 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationDomain("ukui.org");
QCoreApplication::setApplicationVersion("0.0.1-alpha");
QString appid = QString("ukui-menu-%1").arg(QLatin1String(getenv("DISPLAY")));
QString display;
if (KWindowSystem::isPlatformWayland()) {
display = QLatin1String(getenv("WAYLAND_DISPLAY"));
} else {
display = QLatin1String(getenv("DISPLAY"));
}
QString appid = QString("ukui-menu-%1").arg(display);
qDebug() << "ukui-menu launch with:" << display << "appid:" << appid;
QtSingleApplication app(appid, argc, argv);
QGuiApplication::instance()->setProperty("display", display);
QTranslator translator;
QString translationFile{(QString(UKUI_MENU_TRANSLATION_DIR) + "/ukui-menu_" + QLocale::system().name() + ".qm")};

View File

@ -16,25 +16,69 @@
*
*/
#include <QDir>
#include "menu-dbus-service.h"
#include "menuadaptor.h"
#include <KWindowSystem>
#include <QDir>
#include <QDebug>
#include <QDBusConnection>
#include <QDBusServiceWatcher>
#include <QDBusConnectionInterface>
#define MENU_CORE_DBUS_SERVICE "org.ukui.menu"
#define MENU_CORE_DBUS_PATH "/org/ukui/menu"
#define MENU_CORE_DBUS_INTERFACE "org.ukui.menu"
using namespace UkuiMenu;
MenuDbusService::MenuDbusService(QObject *parent) : QObject(parent)
QString MenuDbusService::displayFromPid(uint pid)
{
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);
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
if (environFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
const QByteArray DISPLAY = KWindowSystem::isPlatformWayland() ? QByteArrayLiteral("WAYLAND_DISPLAY")
: QByteArrayLiteral("DISPLAY");
const auto lines = environFile.readAll().split('\0');
for (const QByteArray &line : lines) {
const int equalsIdx = line.indexOf('=');
if (equalsIdx <= 0) {
continue;
}
const QByteArray key = line.left(equalsIdx);
if (key == DISPLAY) {
const QByteArray value = line.mid(equalsIdx + 1);
return value;
}
}
}
return {};
}
MenuDbusService::MenuDbusService(const QString &display, QObject *parent) : QObject(parent), m_display(display)
{
bool isServiceRegistered = QDBusConnection::sessionBus().interface()->isServiceRegistered(MENU_CORE_DBUS_SERVICE);
qDebug() << "menu service is registered:" << isServiceRegistered << ", display:" << display;
if (isServiceRegistered) {
initWatcher();
} else {
bool success = registerService();
if (!success) {
initWatcher();
}
qDebug() << "menu service register:" << success;
}
}
void MenuDbusService::WinKeyResponse()
{
Q_EMIT menuActive();
uint callerPid = QDBusConnection::sessionBus().interface()->servicePid(message().service()).value();
QString display = MenuDbusService::displayFromPid(callerPid);
active(display);
}
QString MenuDbusService::GetSecurityConfigPath()
@ -47,3 +91,90 @@ void MenuDbusService::ReloadSecurityConfig()
{
Q_EMIT reloadConfigSignal();
}
void MenuDbusService::active(const QString &display)
{
if (display.isEmpty() || (display == m_display)) {
Q_EMIT menuActive();
return;
}
if (m_menuAdaptor) {
Q_EMIT m_menuAdaptor->activeRequest(display);
}
}
void MenuDbusService::activeMenu(QString display)
{
if (display == m_display) {
Q_EMIT menuActive();
}
}
bool MenuDbusService::registerService()
{
m_menuAdaptor = new MenuAdaptor(this);
QDBusReply<QDBusConnectionInterface::RegisterServiceReply> reply =
QDBusConnection::sessionBus().interface()->registerService(MENU_CORE_DBUS_SERVICE,
QDBusConnectionInterface::ReplaceExistingService,
QDBusConnectionInterface::DontAllowReplacement);
if (reply.value() == QDBusConnectionInterface::ServiceNotRegistered) {
return false;
}
bool res = QDBusConnection::sessionBus().registerObject(MENU_CORE_DBUS_PATH, this);
if (!res) {
QDBusConnection::sessionBus().interface()->unregisterService(MENU_CORE_DBUS_SERVICE);
}
return res;
}
void MenuDbusService::onServiceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)
{
qDebug() << "serviceOwnerChanged:" << service << oldOwner << newOwner;
if (newOwner.isEmpty()) {
bool success = registerService();
if (success) {
disConnectActiveRequest();
delete m_watcher;
m_watcher = nullptr;
}
qDebug() << "try to register service:" << success;
return;
}
uint newOwnerPid = QDBusConnection::sessionBus().interface()->servicePid(newOwner);
qDebug() << "newOwnerPid:" << newOwnerPid << ", myPid:" << QCoreApplication::applicationPid() << ", display:" << m_display;
// if (newOwnerPid == QCoreApplication::applicationPid()) {
// qDebug() << "Becoming a new service";
// }
}
void MenuDbusService::connectToActiveRequest()
{
QDBusConnection::sessionBus().connect(MENU_CORE_DBUS_SERVICE,
MENU_CORE_DBUS_PATH,
MENU_CORE_DBUS_INTERFACE,
"activeRequest",
this,
SLOT(activeMenu(QString)));
}
void MenuDbusService::disConnectActiveRequest()
{
QDBusConnection::sessionBus().disconnect(MENU_CORE_DBUS_SERVICE,
MENU_CORE_DBUS_PATH,
MENU_CORE_DBUS_INTERFACE,
"activeRequest",
this,
SLOT(activeMenu(QString)));
}
void MenuDbusService::initWatcher()
{
m_watcher = new QDBusServiceWatcher(MENU_CORE_DBUS_SERVICE,QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange);
connect(m_watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &MenuDbusService::onServiceOwnerChanged);
connectToActiveRequest();
}

View File

@ -20,27 +20,45 @@
#define MENU_DBUS_SERVICE_H
#include <QObject>
#include <QDBusInterface>
#include <QDBusConnection>
#include <QDBusContext>
class MenuAdaptor;
class QDBusServiceWatcher;
namespace UkuiMenu {
class MenuDbusService : public QObject
class MenuDbusService : public QObject, public QDBusContext
{
Q_OBJECT
//申明该类有D-BUS服务接口
Q_CLASSINFO("D-Bus Interface", "org.ukui.menu")
public:
explicit MenuDbusService(QObject *parent = nullptr); //传入父指针,调用
explicit MenuDbusService(const QString& display, QObject *parent = nullptr);
public Q_SLOTS:
void WinKeyResponse();
QString GetSecurityConfigPath();
void ReloadSecurityConfig();
void active(const QString &display);
Q_SIGNALS:
void menuActive();
void reloadConfigSignal();
private Q_SLOTS:
void activeMenu(QString display);
void onServiceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner);
private:
static QString displayFromPid(uint pid);
bool registerService();
void initWatcher();
void connectToActiveRequest();
void disConnectActiveRequest();
private:
QString m_display {};
MenuAdaptor *m_menuAdaptor {nullptr};
QDBusServiceWatcher *m_watcher {nullptr};
};
}

View File

@ -32,7 +32,7 @@
#include "menu-manager.h"
#include "data-provider-manager.h"
#include <QCoreApplication>
#include <QGuiApplication>
#include <QCommandLineParser>
#include <QQmlContext>
#include <QQmlEngine>
@ -127,7 +127,7 @@ void UkuiMenuApplication::loadMenuUI()
void UkuiMenuApplication::initDbusService()
{
m_menuDbusService = new MenuDbusService(this);
m_menuDbusService = new MenuDbusService(QGuiApplication::instance()->property("display").toString(), this);
if (m_menuDbusService) {
connect(m_menuDbusService, &MenuDbusService::menuActive, this, [this] {
execCommand(Active);

View File

@ -16,6 +16,7 @@
*
*/
#include <gio/gio.h>
#include <gio-unix-2.0/gio/gdesktopappinfo.h>
#include "app-manager.h"
#include "app-data-manager.h"
@ -58,10 +59,17 @@ void AppManager::launchApp(const QString &desktopFilePath)
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [desktopFilePath] (QDBusPendingCallWatcher *self) {
QDBusPendingReply<bool> reply = *self;
if (!reply.isValid() || !reply.value()) {
QString cmd = parseDesktopFile(desktopFilePath);
if (!cmd.isEmpty()) {
QProcess::startDetached(cmd, QStringList());
// QString cmd = parseDesktopFile(desktopFilePath);
// if (!cmd.isEmpty()) {
// QProcess::startDetached(cmd, QStringList());
// }
GDesktopAppInfo *desktopAppInfo = g_desktop_app_info_new_from_filename(desktopFilePath.toLocal8Bit().data());
if (desktopAppInfo == nullptr) {
return;
}
bool launched = g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr);
g_object_unref(desktopAppInfo);
qDebug() << "launch with GDesktopAppInfo:" << launched;
}
self->deleteLater();
});