summaryrefslogtreecommitdiffstats
path: root/src/systemui-lib/dbus/notificationinterfaceadaptor_dbus.cpp
blob: 26ca759353f91431abdea7d9273ce97130ba168d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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<NativeRuntime *>(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;
    }
}