2023-01-31 17:39:14 +08:00
|
|
|
//
|
|
|
|
// 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);
|
2023-02-01 18:08:11 +08:00
|
|
|
QDBusConnection conn = QDBusConnection::sessionBus();
|
|
|
|
auto registration = conn.interface()->registerService(notificationServiceName(),
|
|
|
|
QDBusConnectionInterface::ReplaceExistingService,
|
|
|
|
QDBusConnectionInterface::DontAllowReplacement);
|
2023-01-31 17:39:14 +08:00
|
|
|
if (registration.value() != QDBusConnectionInterface::ServiceRegistered) {
|
|
|
|
qWarning() << "Failed to register Notification service on DBus!";
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-01 18:08:11 +08:00
|
|
|
if(!conn.registerObject(notificationServicePath(), this)) {
|
|
|
|
qWarning() << "Failed to register Notification DBus object!" << conn.lastError();
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-31 17:39:14 +08:00
|
|
|
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
|