This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbondiQT.c
88 lines (73 loc) · 2.19 KB
/
bondiQT.c
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
#include <QApplication>
#include <QWidget>
#include <QGridLayout>
#include <QPushButton>
#include <QLabel>
#include <QFile>
#include <QTextStream>
#include <QProcess>
#include <QDebug>
#define MAX_APPS 100
#define MAX_NAME_LENGTH 50
#define MAX_COMMAND_LENGTH 100
#define VERSION 8
#define CONFIG_FILE "config.conf"
struct App {
QString name;
QString command;
};
App apps[MAX_APPS];
int numApps = 0;
void readConfigFile() {
QFile file(CONFIG_FILE);
if (!file.open(QIODevice::ReadOnly)) {
qCritical() << "Error opening config file";
exit(EXIT_FAILURE);
}
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
QStringList parts = line.split(':');
if (parts.size() == 2) {
apps[numApps].name = parts[0].trimmed();
apps[numApps].command = parts[1].trimmed();
numApps++;
if (numApps >= MAX_APPS) {
qCritical() << "Too many applications in config file";
break;
}
}
}
file.close();
}
void launchApp(int appIndex) {
QProcess process;
process.startDetached("/bin/sh", QStringList() << "-c" << apps[appIndex].command);
process.waitForFinished(-1);
qDebug() << "Application has exited with status:" << process.exitCode();
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
// Read configuration file
readConfigFile();
// Create a main window
QWidget window;
window.setWindowTitle("Bondi - Big Picture Mode");
window.resize(1280, 720);
// Create a layout
QVBoxLayout *layout = new QVBoxLayout(&window);
// Add title label
QLabel *titleLabel = new QLabel(QString("Bondi CV%1").arg(VERSION));
titleLabel->setStyleSheet("font-size: 24px; color: #FFFFFF;");
layout->addWidget(titleLabel);
// Add buttons
QGridLayout *gridLayout = new QGridLayout();
for (int i = 0; i < numApps; ++i) {
QPushButton *button = new QPushButton(apps[i].name);
connect(button, &QPushButton::clicked, [i]() { launchApp(i); });
gridLayout->addWidget(button, i, 0);
}
layout->addLayout(gridLayout);
window.show();
return app.exec();
}