-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cpp
More file actions
75 lines (61 loc) · 1.91 KB
/
app.cpp
File metadata and controls
75 lines (61 loc) · 1.91 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
#include "app.h"
#include <QIcon>
#include <QCoreApplication>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
#ifdef Q_OS_LINUX
#include <QtDBus/QDBusReply>
#endif
app::app(QWidget *parent) : QMainWindow(parent)
{
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
#endif
#ifdef Q_OS_MAC
CFStringRef reasonForActivity = CFSTR("App is performing a critical task");
IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
reasonForActivity,
&assertionID);
#endif
#ifdef Q_OS_LINUX
dbusInterface = new QDBusInterface("org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
QDBusConnection::sessionBus(),
this);
if (dbusInterface->isValid()) {
QDBusReply<uint> reply = dbusInterface->call("Inhibit", "MyQtApp", "Active Task");
if (reply.isValid()) {
linuxCookie = reply.value();
}
}
#endif
setupTrayIcon();
this->hide();
}
void app::setupTrayIcon() {
trayMenu = new QMenu(this);
QAction *quitAction = new QAction("Deactivate!", this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
trayMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayMenu);
trayIcon->setIcon(QIcon(":/Awake.png"));
trayIcon->show();
}
app::~app()
{
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS);
#endif
#ifdef Q_OS_MAC
IOPMAssertionRelease(assertionID);
#endif
#ifdef Q_OS_LINUX
if (linuxCookie > 0 && dbusInterface && dbusInterface->isValid()) {
dbusInterface->call("UnInhibit", linuxCookie);
}
#endif
}