-
Notifications
You must be signed in to change notification settings - Fork 0
/
trayicon.cpp
114 lines (99 loc) · 2.61 KB
/
trayicon.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "trayicon.h"
TrayIcon::TrayIcon(QObject *parent) :
QObject(parent)
{
this->icon = new QSystemTrayIcon(this);
icon->setContextMenu(this->makeMenu());
icon->setIcon(QIcon(":/icons/2safe@22x22.png"));
icon->show();
}
void TrayIcon::setAccount(QString a)
{
this->m_account = a;
QAction *action = icon->contextMenu()->actions().at(0);
if(a.isEmpty()) {
action->setText("Unauthorized");
//action->setVisible(false);
} else {
action->setText(a);
//action->setVisible(true);
}
}
void TrayIcon::setUsage(QString u)
{
this->m_usage = u;
QAction *action = icon->contextMenu()->actions().at(1);
if(u.isEmpty()) {
action->setText("No info");
action->setVisible(false);
} else {
action->setText(u);
action->setVisible(true);
}
}
void TrayIcon::setAction(QString a)
{
this->m_action = a;
QAction *action = icon->contextMenu()->actions().at(2);
if(a.isEmpty()) {
action->setText("No info");
action->setVisible(false);
} else {
action->setText(a);
action->setVisible(true);
}
}
QMenu* TrayIcon::makeMenu()
{
QMenu *menu = new QMenu();
QAction *a;
a = new QAction("Unauthorized", menu);
a->setEnabled(false);
menu->addAction(a);
a = new QAction("No info", menu);
a->setEnabled(false);
a->setVisible(false);
menu->addAction(a);
a = new QAction("No info", menu);
a->setEnabled(false);
a->setVisible(false);
menu->addAction(a);
menu->addSeparator();
// a = new QAction("Open folder", menu);
// menu->addAction(a);
a = new QAction("Open website", menu);
connect(a, &QAction::triggered, [](){
QDesktopServices::openUrl(QUrl("https://www.2safe.com/web/"));
});
menu->addAction(a);
menu->addSeparator();
a = new QAction("Switch user", menu);
connect(a, &QAction::triggered, [&](){
emit logout();
});
menu->addAction(a);
a = new QAction("Change folder", menu);
connect(a, &QAction::triggered, [&](){
emit chdir();
});
menu->addAction(a);
menu->addSeparator();
a = new QAction("Exit", menu);
connect(a, &QAction::triggered, [&](){
emit quit();
});
menu->addAction(a);
return menu;
}
QHash<QString, QAction *> TrayIcon::initActions(QList<QString> labels)
{
QHash<QString, QAction*> hash;
foreach (auto l, labels) {
hash.insert(l, new QAction(l, this));
}
return hash;
}
void TrayIcon::showMessage(QString title, QString text)
{
icon->showMessage(title, text, QSystemTrayIcon::Information, 2000);
}