This repository was archived by the owner on Jun 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
97 lines (82 loc) · 2.87 KB
/
window.cpp
File metadata and controls
97 lines (82 loc) · 2.87 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <QAction>
#include <QCoreApplication>
#include <QCloseEvent>
#include <QMenu>
#include <QVBoxLayout>
#include <QLabel>
#include <QSpacerItem>
#include <QMessageBox>
#include "window.h"
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Window::Window()
: appIcon(QIcon(":/images/nuclear-power.svg"))
{
createActions();
createTrayIcon();
connect(this,&Window::powerManagementEnabled,this, &Window::showTrayMessage);
disable_power_management();
togglePowerManagementAction->setChecked(true);
}
void Window::disable_power_management() {
::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
emit powerManagementEnabled(false);
}
void Window::enable_power_management() {
::SetThreadExecutionState(ES_CONTINUOUS);
emit powerManagementEnabled(true);
}
void Window::showTrayMessage(bool enabled) {
if (enabled)
trayIcon->showMessage("Power Management aktiv","Stromsparfunktionen sind wieder aktiv..");
else
trayIcon->showMessage("Power Management inaktiv","Stromsparfunktionen sind deaktiviert.\nHappy PowerPointing!");
}
void Window::createActions()
{
togglePowerManagementAction = new QAction("Power Management deaktivieren", this);
togglePowerManagementAction->setCheckable(true);
connect(togglePowerManagementAction,&QAction::triggered,this,[this]() {
if (togglePowerManagementAction->isChecked()) {
disable_power_management();
}
else {
enable_power_management();
}
});
aboutAction = new QAction("Über dieses Programm...", this);
connect(aboutAction,&QAction::triggered,this,[this]() {
aboutAction->setDisabled(true);
QString text = "StayAwake\n";
text += "Version " + QString(Window::APPLICATION_VERSION) + "\n\n";
text += "Written by derreisende77.\n";
text += "Licensed under GPLv3.\n";
text += "Source code available on GitHub.com";
QMessageBox::information(nullptr, Window::APPLICATION_NAME, text);
aboutAction->setEnabled(true);
});
aboutQtAction = new QAction("Über Qt...", this);
connect(aboutQtAction, &QAction::triggered, this, [] {
QMessageBox::aboutQt(nullptr);
});
quitAction = new QAction("&Beenden", this);
connect(quitAction,&QAction::triggered, this, []() {
qApp->quit();
});
}
void Window::createTrayIcon()
{
auto trayIconMenu = new QMenu(this);
trayIconMenu->addAction(togglePowerManagementAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(aboutAction);
trayIconMenu->addAction(aboutQtAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setToolTip("StayAwake Power Manager");
trayIcon->setIcon(appIcon);
trayIcon->show();
}