Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/server.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "server.h" | ||||
22 | #include "server_p.h" | ||||
23 | | ||||
24 | #include "notification.h" | ||||
25 | #include "notification_p.h" | ||||
26 | | ||||
27 | #include "debug.h" | ||||
28 | | ||||
29 | #include <QDBusConnection> | ||||
30 | | ||||
31 | #include <QDebug> | ||||
32 | | ||||
33 | using namespace NotificationManager; | ||||
34 | | ||||
35 | Server::Server(QObject *parent) | ||||
36 | : QObject(parent) | ||||
37 | , d(new ServerPrivate(this)) | ||||
38 | { | ||||
39 | connect(d.data(), &ServerPrivate::inhibitedChanged, this, [this] { | ||||
40 | emit inhibitedChanged(inhibited()); | ||||
41 | }); | ||||
42 | connect(d.data(), &ServerPrivate::inhibitionAdded, this, &Server::inhibitionApplicationsChanged); | ||||
43 | connect(d.data(), &ServerPrivate::inhibitionRemoved, this, &Server::inhibitionApplicationsChanged); | ||||
44 | } | ||||
45 | | ||||
46 | Server::~Server() = default; | ||||
47 | | ||||
48 | Server &Server::self() | ||||
49 | { | ||||
50 | static Server s_self; | ||||
51 | return s_self; | ||||
52 | } | ||||
53 | | ||||
54 | bool Server::init() | ||||
55 | { | ||||
56 | return d->init(); | ||||
57 | } | ||||
58 | | ||||
59 | bool Server::isValid() const | ||||
60 | { | ||||
61 | return d->m_valid; | ||||
62 | } | ||||
63 | | ||||
64 | void Server::closeNotification(uint notificationId, CloseReason reason) | ||||
65 | { | ||||
66 | emit notificationRemoved(notificationId, reason); | ||||
67 | | ||||
68 | emit d->NotificationClosed(notificationId, static_cast<int>(reason)); // tell on DBus | ||||
69 | } | ||||
70 | | ||||
71 | void Server::invokeAction(uint notificationId, const QString &actionName) | ||||
72 | { | ||||
73 | emit d->ActionInvoked(notificationId, actionName); | ||||
74 | } | ||||
75 | | ||||
76 | uint Server::add(const Notification ¬ification) | ||||
77 | { | ||||
78 | return d->add(notification); | ||||
79 | } | ||||
80 | | ||||
81 | bool Server::inhibited() const | ||||
82 | { | ||||
83 | return d->inhibited(); | ||||
84 | } | ||||
85 | | ||||
86 | QStringList Server::inhibitionApplications() const | ||||
87 | { | ||||
88 | QStringList applications; | ||||
89 | const auto inhibitions = d->inhibitions(); | ||||
90 | applications.reserve(inhibitions.count()); | ||||
91 | for (const auto &inhibition : inhibitions) { | ||||
92 | applications.append(!inhibition.applicationName.isEmpty() ? inhibition.applicationName : inhibition.desktopEntry); | ||||
93 | } | ||||
94 | return applications; | ||||
95 | } | ||||
96 | | ||||
97 | QStringList Server::inhibitionReasons() const | ||||
98 | { | ||||
99 | QStringList reasons; | ||||
100 | const auto inhibitions = d->inhibitions(); | ||||
101 | reasons.reserve(inhibitions.count()); | ||||
102 | for (const auto &inhibition : inhibitions) { | ||||
103 | reasons.append(inhibition.reason); | ||||
104 | } | ||||
105 | return reasons; | ||||
106 | } | ||||
107 | | ||||
108 | void Server::clearInhibitions() | ||||
109 | { | ||||
110 | d->clearInhibitions(); | ||||
111 | } |