99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
//
|
|
// Created by zpf on 23-1-31.
|
|
//
|
|
#include <QDBusServiceWatcher>
|
|
#include <QDBusConnection>
|
|
#include "server.h"
|
|
#include "server-private.h"
|
|
#include "notificationsadaptor.h"
|
|
|
|
namespace NotificationServer {
|
|
ServerPrivate::ServerPrivate(QObject *parent) : QObject(parent), m_notificationWatchers(new QDBusServiceWatcher(this))
|
|
{
|
|
m_notificationWatchers->setConnection(QDBusConnection::sessionBus());
|
|
m_notificationWatchers->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
|
|
connect(m_notificationWatchers, &QDBusServiceWatcher::serviceUnregistered, m_notificationWatchers, &QDBusServiceWatcher::removeWatchedService);
|
|
}
|
|
|
|
ServerPrivate::~ServerPrivate() = default;
|
|
|
|
QStringList ServerPrivate::GetCapabilities() const
|
|
{
|
|
return QStringList();
|
|
}
|
|
|
|
uint ServerPrivate::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary,
|
|
const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
QString ServerPrivate::GetServerInformation(QString &vendor, QString &version, QString &specVersion) const
|
|
{
|
|
return QString();
|
|
}
|
|
|
|
void ServerPrivate::CloseNotification(uint id)
|
|
{
|
|
|
|
}
|
|
|
|
bool ServerPrivate::init()
|
|
{
|
|
new NotificationsAdaptor(this);
|
|
if(QDBusConnection::sessionBus().registerObject(notificationServicePath(), this)) {
|
|
qWarning() << "Failed to register Notification DBus object!";
|
|
return false;
|
|
}
|
|
auto registration = QDBusConnection::sessionBus().interface()->registerService(notificationServiceName(),
|
|
QDBusConnectionInterface::ReplaceExistingService,
|
|
QDBusConnectionInterface::DontAllowReplacement);
|
|
if (registration.value() != QDBusConnectionInterface::ServiceRegistered) {
|
|
qWarning() << "Failed to register Notification service on DBus!";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
QString ServerPrivate::notificationServiceName()
|
|
{
|
|
return QStringLiteral("org.freedesktop.Notifications");
|
|
}
|
|
|
|
QString ServerPrivate::notificationServicePath()
|
|
{
|
|
return QStringLiteral("/org/freedesktop/Notifications");
|
|
}
|
|
|
|
QString ServerPrivate::notificationServiceInterface()
|
|
{
|
|
return QStringLiteral("org.freedesktop.Notifications");;
|
|
}
|
|
|
|
void ServerPrivate::RegisterClient()
|
|
{
|
|
m_notificationWatchers->addWatchedService(message().service());
|
|
}
|
|
|
|
void ServerPrivate::UnRegisterClient()
|
|
{
|
|
m_notificationWatchers->removeWatchedService(message().service());
|
|
}
|
|
|
|
Server::Server(QObject *parent): QObject(parent), d(new ServerPrivate(this))
|
|
{
|
|
}
|
|
|
|
Server &Server::self()
|
|
{
|
|
static Server self;
|
|
return self;
|
|
}
|
|
|
|
bool Server::init()
|
|
{
|
|
return d->init();
|
|
}
|
|
|
|
Server::~Server() = default;
|
|
} // NotificationServer
|