aboutsummaryrefslogtreecommitdiffstats
path: root/exec.hpp
blob: e26d482d0b62d01a51d448dd24f7979fc9b43a55 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: GPL-3.0+
// Copyright (C) 2021 AISIN CORPORATION

#ifndef EXEC_HPP
#define EXEC_HPP

#include <QProcess>
#include <QVariant>

class AppExec : public QProcess {
    Q_OBJECT

public:
    AppExec(QObject *parent = 0) : QProcess(parent) { }

    Q_INVOKABLE void start(const QString &program, const QVariantList &arguments) {
        QStringList args;

        // convert QVariantList from QML to QStringList for QProcess 

        for (int i = 0; i < arguments.length(); i++)
            args << arguments[i].toString();

        QProcess::start(program, args);
    }

    Q_INVOKABLE void runMominavi() {
        QString program("systemctl");
        QStringList mominavi = {"start","mominavi"};
        QStringList momiplay = {"stop","momiplay"};
        QStringList momiradio = {"stop","momiradio"};
        QStringList momisetting = {"stop","momisetting"};

        QProcess::start(program, mominavi);
        QProcess::waitForFinished();
        QProcess::start(program, momiplay);
        QProcess::waitForFinished();
        QProcess::start(program, momiradio);
        QProcess::waitForFinished();
        QProcess::start(program, momisetting);
        QProcess::waitForFinished();
    }

    Q_INVOKABLE void runMomiplay() {
        QString program("systemctl");
        QStringList mominavi = {"stop","mominavi"};
        QStringList momiplay = {"start","momiplay"};
        QStringList momiradio = {"stop","momiradio"};
        QStringList momisetting = {"stop","momisetting"};

        QProcess::start(program, mominavi);
        QProcess::waitForFinished();
        QProcess::start(program, momiplay);
        QProcess::waitForFinished();
        QProcess::start(program, momiradio);
        QProcess::waitForFinished();
        QProcess::start(program, momisetting);
        QProcess::waitForFinished();
    }
    
    Q_INVOKABLE void runMomiradio() {
        QString program("systemctl");
        QStringList mominavi = {"stop","mominavi"};
        QStringList momiplay = {"stop","momiplay"};
        QStringList momiradio = {"start","momiradio"};
        QStringList momisetting = {"stop","momisetting"};

        QProcess::start(program, mominavi);
        QProcess::waitForFinished();
        QProcess::start(program, momiplay);
        QProcess::waitForFinished();
        QProcess::start(program, momiradio);
        QProcess::waitForFinished();
        QProcess::start(program, momisetting);
        QProcess::waitForFinished();
    }
    
    Q_INVOKABLE void runMomisetting() {
        QString program("systemctl");
        QStringList mominavi = {"stop","mominavi"};
        QStringList momiplay = {"stop","momiplay"};
        QStringList momiradio = {"stop","momiradio"};
        QStringList momisetting = {"start","momisetting"};

        QProcess::start(program, mominavi);
        QProcess::waitForFinished();
        QProcess::start(program, momiplay);
        QProcess::waitForFinished();
        QProcess::start(program, momiradio);
        QProcess::waitForFinished();
        QProcess::start(program, momisetting);
        QProcess::waitForFinished();
    }


    Q_INVOKABLE QByteArray readAll() {
        return QProcess::readAll();
    }
};
#endif // EXEC_HPP