-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
66 lines (57 loc) · 2.49 KB
/
main.cpp
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
#include "menuclickedactions.h"
#include "enums.h"
#include <QtWidgets/QApplication>
#include <QtCore/QDebug>
#include <QtGui/QIcon>
#include <QtWidgets/QSystemTrayIcon>
#include <QtWidgets/QMenu>
#include <QActionGroup>
#include <QLoggingCategory>
void addStatusActions(QAction *&action, QMenu &menu, QActionGroup &actionGroup) {
action->setCheckable(true);
actionGroup.addAction(action);
menu.addAction(action);
}
int main(int argc, char *argv[])
{
//qputenv("QT_ASSUME_STDERR_HAS_CONSOLE","1");
QApplication oApp( argc, argv );
//QLoggingCategory::setFilterRules("*.debug=true");
QMenu menu;
QSystemTrayIcon TrayIcon(QIcon(":systemTrayIcon.png"));
auto menuClicked = new menuClickedActions();
TrayIcon.show();
QAction *autoacceptAction=new QAction("Autoaccept", &menu);
QObject::connect(autoacceptAction, SIGNAL(triggered(bool)), menuClicked, SLOT(accept(bool)));
autoacceptAction->setCheckable(true);
menu.addAction(autoacceptAction);
autoacceptAction->trigger();
QMenu statusButtonsMenu("Status", &menu);
QActionGroup statusActionGroup(nullptr);
menu.addMenu(&statusButtonsMenu);
statusActionGroup.setExclusive(true);
QAction *statusAction=new QAction("Online", &statusButtonsMenu); // Online Status
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, ONLINE);
});
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
statusAction=new QAction("Offline", &statusButtonsMenu); // Offline Status
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, OFFLINE);
});
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
statusAction=new QAction("None", &statusButtonsMenu); // Don't try to force a status
addStatusActions(statusAction, statusButtonsMenu, statusActionGroup);
QObject::connect(statusAction, &QAction::triggered, [&menuClicked] (bool checked) {
menuClicked->statusChange(checked, NONE);
});
statusAction->trigger();
QObject::connect(&TrayIcon, &QSystemTrayIcon::activated, [&menu] (QSystemTrayIcon::ActivationReason r) {
if (r==QSystemTrayIcon::ActivationReason::Trigger) menu.popup(QCursor::pos());
});
QAction *exitAction=new QAction("Exit", &menu);
menu.addAction(exitAction);
QObject::connect(exitAction, SIGNAL(triggered()), &oApp, SLOT(quit()));
TrayIcon.setContextMenu(&menu);
return oApp.exec();
}