File: kdedksysguard.cpp

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (63 lines) | stat: -rw-r--r-- 1,959 bytes parent folder | download
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
/*
    SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
    SPDX-FileCopyrightText: 2006 Aaron Seigo <aseigo@kde.org>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#include "kdedksysguard.h"

#include <QAction>
#include <QProcess>
#include <QStandardPaths>
#include <QTimer>

#include <KLocalizedString>
#include <KPluginFactory>

#include <KActionCollection>
#include <KGlobalAccel>
#include <QDBusConnection>
#include <QDBusConnectionInterface>

K_PLUGIN_CLASS_WITH_JSON(KDEDKSysGuard, "ksysguard.json")

KDEDKSysGuard::KDEDKSysGuard(QObject *parent, const QVariantList &)
    : KDEDModule(parent)
{
    QTimer::singleShot(0, this, &KDEDKSysGuard::init);
}

KDEDKSysGuard::~KDEDKSysGuard()
{
}

void KDEDKSysGuard::init()
{
    KActionCollection *actionCollection = new KActionCollection(this);

    QAction *action = actionCollection->addAction(QStringLiteral("Show System Activity"));
    action->setText(i18n("Show System Activity"));
    connect(action, &QAction::triggered, this, &KDEDKSysGuard::showTaskManager);

    KGlobalAccel::self()->setGlobalShortcut(action, QKeySequence(Qt::CTRL | Qt::Key_Escape));
}

void KDEDKSysGuard::showTaskManager()
{
    QDBusConnection con = QDBusConnection::sessionBus();
    QDBusConnectionInterface *interface = con.interface();
    if (interface->isServiceRegistered(QStringLiteral("org.kde.systemmonitor"))) {
        QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.systemmonitor"),
                                                          QStringLiteral("/"),
                                                          QStringLiteral("org.qtproject.Qt.QWidget"),
                                                          QStringLiteral("close"));

        con.asyncCall(msg);
    } else {
        const QString exe = QStandardPaths::findExecutable(QStringLiteral("systemmonitor"));
        QProcess::startDetached(exe, QStringList());
    }
}

#include "kdedksysguard.moc"