// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "notificationinterface_adaptor.h" #include "notificationmanager.h" #include "application.h" #include "nativeruntime.h" // This is the AppMan specific notification interface that runs on the P2P bus between an app and // the application manager. It closely resembles the org.freedesktop.Notifications interface. //NOTE: The header for this class is autogenerated from the XML interface definition. // We are NOT using the generated cpp, but instead implement the adaptor manually. QT_USE_NAMESPACE_AM static inline NativeRuntime *nativeRuntimeFor(NotificationInterfaceAdaptor *adaptor) { return (adaptor && adaptor->parent()) ? qobject_cast(adaptor->parent()->parent()) : nullptr; } NotificationInterfaceAdaptor::NotificationInterfaceAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { connect(&NotificationManager::instance()->internalSignals, &NotificationManagerInternalSignals::notificationClosed, this, &NotificationInterfaceAdaptor::closed); connect(&NotificationManager::instance()->internalSignals, &NotificationManagerInternalSignals::actionInvoked, this, &NotificationInterfaceAdaptor::actionInvoked); } NotificationInterfaceAdaptor::~NotificationInterfaceAdaptor() { } void NotificationInterfaceAdaptor::close(uint id) { NotificationManager::instance()->closeNotification(id); } uint NotificationInterfaceAdaptor::show(uint replacesId, const QString &appIcon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout) { auto *nr = nativeRuntimeFor(this); Q_ASSERT(nr); if (nr->application()) { return NotificationManager::instance()->showNotification(nr->application()->id(), replacesId, appIcon, summary, body, actions, hints, timeout); } else { return 0; } }