blob: f25860c3b12b27608e4d22911a1147aa28a386df (
plain)
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
|
import QtQuick 2.0
import QtQuick.Controls 2.4
import Qt.labs.platform 1.0 as Labs
Labs.SystemTrayIcon {
visible: systrayVisible
property alias statusItem: statusItem
menu: Labs.Menu {
id: systrayMenu
Labs.MenuItem {
id: statusItem
text: qsTr("Checking status…")
enabled: false
}
Labs.MenuItem {
id: vpnSystrayToggle
text: getConnectionText()
enabled: isConnectionTextEnabled()
onTriggered: {
if (ctx.status == "off") {
backend.switchOn()
} else if (ctx.status == "on") {
backend.switchOff()
}
}
}
Labs.MenuSeparator {}
Labs.MenuItem {
text: qsTr("Donate")
onTriggered: Qt.openUrlExternally(ctx.donateURL)
}
Labs.MenuSeparator {}
Labs.MenuItem {
id: showAppItem
//: Part of the systray menu; show or hide the main app window
text: isVisible() ? qsTr("Hide") : qsTr("Show")
onTriggered: {
if (isVisible()) {
root.hide()
} else {
root.bringToFront()
}
}
}
Labs.MenuItem {
//: Part of the systray menu; quits que application
text: qsTr("Quit")
onTriggered: backend.quit()
}
}
function isVisible() {
return root.visibility != 0 && root.visibility != 3
}
function getConnectionText() {
if (!ctx) {
return ""
} else if (ctx.status == "off") {
// Not Turn on, because we will can later append "to <Location>"
if (ctx.locations && ctx.bestLocation) {
return qsTr("Connect to") + " " + getCanonicalLocation(ctx.bestLocation)
} else {
return qsTr("Connect")
}
} else if (ctx.status == "on") {
return qsTr("Disconnect")
}
return ""
}
function isConnectionTextEnabled() {
if (!ctx) {
return false
}
return ctx.status == "off" || ctx.status == "on"
}
// returns the composite of Location, CC
function getCanonicalLocation(label) {
try {
let loc = ctx.locationLabels[label]
return loc[0] + ", " + loc[1]
} catch(e) {
return "unknown"
}
}
}
|