File: tastenbrett.cpp

package info (click to toggle)
plasma-desktop 4%3A6.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 61,044 kB
  • sloc: cpp: 37,691; ansic: 2,617; python: 1,386; javascript: 1,163; xml: 1,082; sh: 128; makefile: 16
file content (51 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#include "tastenbrett.h"

#include <QCoreApplication>
#include <QDebug>
#include <QProcess>
#include <QStandardPaths>

QString Tastenbrett::path()
{
    static QString path;
    if (!path.isNull()) {
        return path;
    }

    // Find relative to KCM (when run from build dir)
    path = QStandardPaths::findExecutable("tastenbrett", {qEnvironmentVariable("QT_PLUGIN_PATH"), qApp->applicationDirPath()});
    if (!path.isNull()) {
        return path;
    }

    return QStandardPaths::findExecutable("tastenbrett");
}

bool Tastenbrett::exists()
{
    return !path().isNull();
}

void Tastenbrett::launch(const QString &model, const QString &layout, const QString &variant, const QString &options, const QString &title)
{
    if (!exists()) {
        return;
    }

    QProcess p;
    p.setProgram(path());
    QStringList args{"--model", model, "--layout", layout, "--variant", variant, "--options", options};
    if (!title.isEmpty()) {
        args << "-title" << title;
    }
    qDebug() << args;
    p.setArguments(args);
    p.setProcessChannelMode(QProcess::ForwardedChannels);
    p.startDetached();
}