-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (62 loc) · 2.21 KB
/
main.cpp
File metadata and controls
77 lines (62 loc) · 2.21 KB
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
#include <QApplication>
#include <QScreen>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QProcess>
#include <iostream>
#include <stdlib.h>
class PowerWindow : public QWidget
{
public:
PowerWindow(QWidget *parent = nullptr) : QWidget(parent)
{
setWindowTitle("Power Options");
resize(300, 200);
QVBoxLayout *layout = new QVBoxLayout(this);
QPushButton *rebootButton = new QPushButton("Reboot");
QPushButton *shutdownButton = new QPushButton("Shutdown");
QPushButton *logoutButton = new QPushButton("Logout");
layout->addWidget(rebootButton);
layout->addWidget(shutdownButton);
layout->addWidget(logoutButton);
connect(rebootButton, &QPushButton::clicked, this, [](){
if (QMessageBox::question(nullptr, "Confirm Reboot",
"Are you sure you want to reboot?") == QMessageBox::Yes)
{
// QProcess::startDetached("systemctl reboot");
system("systemctl reboot");
}
});
connect(shutdownButton, &QPushButton::clicked, this, [](){
if (QMessageBox::question(nullptr, "Confirm Shutdown",
"Are you sure you want to shutdown?") == QMessageBox::Yes)
{
// QProcess::startDetached("systemctl poweroff");
system("systemctl poweroff");
}
});
connect(logoutButton, &QPushButton::clicked, this, [](){
if (QMessageBox::question(nullptr, "Confirm Logout",
"Are you sure you want to logout?") == QMessageBox::Yes)
{
// QProcess::startDetached("pkill -KILL -u $USER");
system("pkill -KILL -u $USER");
}
});
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PowerWindow window;
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->availableGeometry();
// Calculate center position
int x = (screenGeometry.width() - window.width()) / 2;
int y = (screenGeometry.height() - window.height()) / 2;
window.move(x, y);
window.show();
return app.exec();
}