Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/globalshortcuts.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 3 of | ||||
7 | * the License or any later version accepted by the membership of | ||||
8 | * KDE e.V. (or its successor approved by the membership of KDE | ||||
9 | * e.V.), which shall act as a proxy defined in Section 14 of | ||||
10 | * version 3 of the license. | ||||
11 | * | ||||
12 | * This program 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 | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "globalshortcuts.h" | ||||
22 | | ||||
23 | #include <QAction> | ||||
24 | #include <QDBusConnection> | ||||
25 | #include <QDBusMessage> | ||||
26 | | ||||
27 | #include <KLocalizedString> | ||||
28 | | ||||
29 | #include <KGlobalAccel> | ||||
30 | | ||||
31 | GlobalShortcuts::GlobalShortcuts(QObject *parent) | ||||
32 | : QObject(parent) | ||||
33 | , m_toggleDoNotDisturbAction(new QAction(this)) | ||||
34 | { | ||||
35 | m_toggleDoNotDisturbAction->setObjectName(QStringLiteral("toggle do not disturb")); | ||||
36 | m_toggleDoNotDisturbAction->setProperty("componentName", QStringLiteral("plasmashell")); | ||||
37 | m_toggleDoNotDisturbAction->setText(i18n("Toggle do not disturb")); | ||||
38 | m_toggleDoNotDisturbAction->setIcon(QIcon::fromTheme(QStringLiteral("notifications-disabled"))); | ||||
39 | m_toggleDoNotDisturbAction->setShortcutContext(Qt::ApplicationShortcut); | ||||
40 | connect(m_toggleDoNotDisturbAction, &QAction::triggered, this, &GlobalShortcuts::toggleDoNotDisturbTriggered); | ||||
41 | | ||||
42 | KGlobalAccel::self()->setGlobalShortcut(m_toggleDoNotDisturbAction, QKeySequence()); | ||||
43 | } | ||||
44 | | ||||
45 | GlobalShortcuts::~GlobalShortcuts() = default; | ||||
46 | | ||||
47 | void GlobalShortcuts::showDoNotDisturbOsd(bool doNotDisturb) const | ||||
48 | { | ||||
49 | QDBusMessage msg = QDBusMessage::createMethodCall( | ||||
50 | QStringLiteral("org.kde.plasmashell"), | ||||
51 | QStringLiteral("/org/kde/osdService"), | ||||
52 | QStringLiteral("org.kde.osdService"), | ||||
53 | QStringLiteral("showText") | ||||
54 | ); | ||||
55 | | ||||
56 | const QString iconName = doNotDisturb ? QStringLiteral("notifications-disabled") : QStringLiteral("notifications"); | ||||
57 | const QString text = doNotDisturb ? i18nc("OSD popup, keep short", "Notifications Off") | ||||
58 | : i18nc("OSD popup, keep short", "Notifications On"); | ||||
59 | | ||||
60 | msg.setArguments({iconName, text}); | ||||
61 | | ||||
62 | QDBusConnection::sessionBus().call(msg, QDBus::NoBlock); | ||||
63 | } |