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 <QDebug> | ||||
30 | | ||||
31 | using namespace NotificationManager; | ||||
32 | | ||||
33 | Server::Server(QObject *parent) | ||||
34 | : QObject(parent) | ||||
35 | , d(new ServerPrivate(this)) | ||||
36 | { | ||||
37 | connect(d.data(), &ServerPrivate::inhibitedChanged, this, [this] { | ||||
38 | emit inhibitedChanged(inhibited()); | ||||
39 | }); | ||||
40 | connect(d.data(), &ServerPrivate::inhibitionAdded, this, &Server::inhibitionApplicationsChanged); | ||||
41 | connect(d.data(), &ServerPrivate::inhibitionRemoved, this, &Server::inhibitionApplicationsChanged); | ||||
42 | } | ||||
43 | | ||||
44 | Server::~Server() = default; | ||||
45 | | ||||
46 | Server &Server::self() | ||||
47 | { | ||||
48 | static Server s_self; | ||||
49 | return s_self; | ||||
50 | } | ||||
51 | | ||||
52 | bool Server::init() | ||||
53 | { | ||||
54 | return d->init(); | ||||
55 | } | ||||
56 | | ||||
57 | bool Server::isValid() const | ||||
58 | { | ||||
59 | return d->m_valid; | ||||
60 | } | ||||
61 | | ||||
62 | void Server::closeNotification(uint notificationId, CloseReason reason) | ||||
63 | { | ||||
64 | emit notificationRemoved(notificationId, reason); | ||||
65 | | ||||
66 | emit d->NotificationClosed(notificationId, static_cast<int>(reason)); // tell on DBus | ||||
67 | } | ||||
68 | | ||||
69 | void Server::invokeAction(uint notificationId, const QString &actionName) | ||||
70 | { | ||||
71 | emit d->ActionInvoked(notificationId, actionName); | ||||
72 | } | ||||
73 | | ||||
74 | uint Server::add(const Notification ¬ification) | ||||
75 | { | ||||
76 | return d->add(notification); | ||||
77 | } | ||||
78 | | ||||
79 | bool Server::inhibited() const | ||||
80 | { | ||||
81 | return d->inhibited(); | ||||
82 | } | ||||
83 | | ||||
84 | QStringList Server::inhibitionApplications() const | ||||
85 | { | ||||
86 | QStringList applications; | ||||
87 | const auto inhibitions = d->inhibitions(); | ||||
88 | applications.reserve(inhibitions.count()); | ||||
89 | for (const auto &inhibition : inhibitions) { | ||||
90 | applications.append(!inhibition.applicationName.isEmpty() ? inhibition.applicationName : inhibition.desktopEntry); | ||||
91 | } | ||||
92 | return applications; | ||||
93 | } | ||||
94 | | ||||
95 | QStringList Server::inhibitionReasons() const | ||||
96 | { | ||||
97 | QStringList reasons; | ||||
98 | const auto inhibitions = d->inhibitions(); | ||||
99 | reasons.reserve(inhibitions.count()); | ||||
100 | for (const auto &inhibition : inhibitions) { | ||||
101 | reasons.append(inhibition.reason); | ||||
102 | } | ||||
103 | return reasons; | ||||
104 | } | ||||
105 | | ||||
106 | void Server::clearInhibitions() | ||||
107 | { | ||||
108 | d->clearInhibitions(); | ||||
109 | } |