dde-application-manager/src/systemdsignaldispatcher.cpp
ComixHe 2fa74e40e5 refact: change implementation of UpdateApplicationInfo
adjust the way of get XDG_DATA_DIRS.

Signed-off-by: ComixHe <heyuming@deepin.org>
Signed-off-by: black-desk <me@black-desk.cn>
2023-08-14 13:39:05 +08:00

53 lines
1.6 KiB
C++

// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "systemdsignaldispatcher.h"
bool SystemdSignalDispatcher::connectToSignals() noexcept
{
auto &con = ApplicationManager1DBus::instance().globalDestBus();
if (!con.connect(SystemdService,
SystemdObjectPath,
SystemdInterfaceName,
"UnitNew",
this,
SLOT(onUnitNew(QString, QDBusObjectPath)))) {
qCritical() << "can't connect to UnitNew signal of systemd service.";
return false;
}
if (!con.connect(SystemdService,
SystemdObjectPath,
SystemdInterfaceName,
"UnitRemoved",
this,
SLOT(onUnitRemoved(QString, QDBusObjectPath)))) {
qCritical() << "can't connect to UnitRemoved signal of systemd service.";
return false;
}
return true;
}
void SystemdSignalDispatcher::onUnitNew(QString unitName, QDBusObjectPath systemdUnitPath)
{
constexpr decltype(auto) appPrefix = u8"app-";
if (!unitName.startsWith(appPrefix)) {
return;
}
emit SystemdUnitNew(unitName.sliced(sizeof(appPrefix) - 1), systemdUnitPath);
}
void SystemdSignalDispatcher::onUnitRemoved(QString unitName, QDBusObjectPath systemdUnitPath)
{
constexpr decltype(auto) appPrefix = u8"app-";
if (!unitName.startsWith(appPrefix)) {
return;
}
emit SystemdUnitRemoved(unitName.sliced(sizeof(appPrefix) - 1), systemdUnitPath);
}