summaryrefslogtreecommitdiffstats
path: root/src/main-lib/notificationmanageradaptor_dbus.cpp
blob: 1ad1c39444c60cb95ee404ab1def14da516174d0 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <qplatformdefs.h>
#if defined(Q_OS_UNIX)
#  include <unistd.h>
#endif

#include "notificationmanager.h"
#include "notifications_adaptor.h"

//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.

using namespace Qt::StringLiterals;

QT_USE_NAMESPACE_AM

NotificationsAdaptor::NotificationsAdaptor(QObject *parent)
    : QDBusAbstractAdaptor(parent)
{
    auto nm = NotificationManager::instance();

    connect(&nm->internalSignals, &NotificationManagerInternalSignals::actionInvoked,
            this, &NotificationsAdaptor::ActionInvoked);
    connect(&nm->internalSignals, &NotificationManagerInternalSignals::notificationClosed,
            this, &NotificationsAdaptor::NotificationClosed);
}

NotificationsAdaptor::~NotificationsAdaptor()
{ }

QStringList NotificationsAdaptor::GetCapabilities()
{
    static const QStringList caps {
        u"action-icons"_s,
        u"actions"_s,
        u"body"_s,
        u"body-hyperlinks"_s,
        u"body-images"_s,
        u"body-markup"_s,
        u"icon-static"_s,
        u"persistence"_s,
    };
    return caps;
}

QString NotificationsAdaptor::GetServerInformation(QString &vendor, QString &version, QString &spec_version)
{
    vendor = qApp->organizationName();
    version = u"1.0"_s;
    spec_version = u"1.2"_s;
    return qApp->applicationName();
}

uint NotificationsAdaptor::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 NotificationManager::instance()->showNotification(app_name, replaces_id, app_icon,
                                                             summary, body, actions, hints, timeout);
}

void NotificationsAdaptor::CloseNotification(uint id)
{
    NotificationManager::instance()->closeNotification(id);
}