Skip to content
Snippets Groups Projects
Commit 0bf00f54 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[bug] fix init crash

parent a7b197e6
No related branches found
No related tags found
No related merge requests found
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4 import QtQuick.Controls 2.12
Dialog { Dialog {
title: qsTr("Login") title: qsTr("Login")
......
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4 import QtQuick.Controls 2.12
Dialog { Dialog {
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
......
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 1.4 import QtQuick.Controls 2.12
StateGroup { StateGroup {
...@@ -26,7 +26,7 @@ StateGroup { ...@@ -26,7 +26,7 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: autoSelectionItem target: autoSelectionItem
text: qsTr("Best") text: qsTr("Best")
} }
PropertyChanges { PropertyChanges {
target: mainStatus target: mainStatus
...@@ -54,14 +54,14 @@ StateGroup { ...@@ -54,14 +54,14 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: autoSelectionItem target: autoSelectionItem
text: { text: {
if (autoSelectionButton.checked) { if (autoSelectionButton.checked) {
//: %1 -> location to which the client is connected to //: %1 -> location to which the client is connected to
qsTr("Best (%1)").arg(locationStr()) qsTr("Best (%1)").arg(locationStr())
} else { } else {
qsTr("Best") qsTr("Best")
} }
} }
} }
PropertyChanges { PropertyChanges {
target: mainStatus target: mainStatus
...@@ -69,7 +69,7 @@ StateGroup { ...@@ -69,7 +69,7 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: mainCurrentGateway target: mainCurrentGateway
//: %1 -> location to which the client is connected to //: %1 -> location to which the client is connected to
text: qsTr("Connected to %1").arg(locationStr()) text: qsTr("Connected to %1").arg(locationStr())
} }
}, },
...@@ -86,14 +86,14 @@ StateGroup { ...@@ -86,14 +86,14 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: autoSelectionItem target: autoSelectionItem
text: { text: {
if (autoSelectionButton.checked) { if (autoSelectionButton.checked) {
//: %1 -> location to which the client is connected to //: %1 -> location to which the client is connected to
qsTr("Best (%1)").arg(locationStr()) qsTr("Best (%1)").arg(locationStr())
} else { } else {
qsTr("Best") qsTr("Best")
} }
} }
} }
PropertyChanges { PropertyChanges {
target: mainStatus target: mainStatus
...@@ -117,7 +117,7 @@ StateGroup { ...@@ -117,7 +117,7 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: autoSelectionItem target: autoSelectionItem
text: qsTr("Best") text: qsTr("Best")
} }
PropertyChanges { PropertyChanges {
target: mainStatus target: mainStatus
...@@ -141,7 +141,7 @@ StateGroup { ...@@ -141,7 +141,7 @@ StateGroup {
} }
PropertyChanges { PropertyChanges {
target: autoSelectionItem target: autoSelectionItem
text: qsTr("Best") text: qsTr("Best")
} }
PropertyChanges { PropertyChanges {
target: mainStatus target: mainStatus
......
...@@ -16,15 +16,12 @@ Window { ...@@ -16,15 +16,12 @@ Window {
maximumHeight: 500 maximumHeight: 500
minimumHeight: 300 minimumHeight: 300
flags: Qt.WindowsStaysOnTopHint
property var ctx property var ctx
property var loginDone property var loginDone
property var allowEmptyPass property var allowEmptyPass
// TODO get a nice background color for this mainwindow. It should be customizable. // TODO get a nice background color for this mainwindow. It should be customizable.
// TODO refactorize all this mess into discrete components. // TODO refactorize all this mess into discrete components.
TabBar { TabBar {
id: bar id: bar
width: parent.width width: parent.width
...@@ -65,7 +62,6 @@ Window { ...@@ -65,7 +62,6 @@ Window {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
SwitchDelegate { SwitchDelegate {
id: vpntoggle id: vpntoggle
...@@ -76,17 +72,19 @@ Window { ...@@ -76,17 +72,19 @@ Window {
Connections { Connections {
function onCheckedChanged() { function onCheckedChanged() {
if (vpntoggle.checked == true && ctx.status == "off") { if (vpntoggle.checked == true
&& ctx.status == "off") {
backend.switchOn() backend.switchOn()
} }
if (vpntoggle.checked === false && ctx.status == "on") { if (vpntoggle.checked === false
&& ctx.status == "on") {
backend.switchOff() backend.switchOff()
} }
} }
} }
contentItem: Text { contentItem: Text {
rightPadding: vpntoggle.indicator.width + control.spacing rightPadding: vpntoggle.indicator.width + vpntoggle.spacing
text: vpntoggle.text text: vpntoggle.text
font: vpntoggle.font font: vpntoggle.font
opacity: enabled ? 1.0 : 0.3 opacity: enabled ? 1.0 : 0.3
...@@ -147,13 +145,13 @@ Window { ...@@ -147,13 +145,13 @@ Window {
id: autoSelectionButton id: autoSelectionButton
checked: !isManualLocation() checked: !isManualLocation()
text: qsTr("Best") text: qsTr("Best")
onClicked: backend.useAutomaticGateway() onClicked: backend.useAutomaticGateway()
} }
RadioButton { RadioButton {
id: manualSelectionButton id: manualSelectionButton
checked: isManualLocation() checked: isManualLocation()
text: qsTr("Manual") text: qsTr("Manual")
onClicked: setGwSelection() onClicked: setGwSelection()
} }
ComboBox { ComboBox {
id: gwSelector id: gwSelector
...@@ -167,41 +165,44 @@ Window { ...@@ -167,41 +165,44 @@ Window {
backend.useLocation(currentText.toString()) backend.useLocation(currentText.toString())
} }
delegate: ItemDelegate { delegate: ItemDelegate {
// TODO: we could use icons // TODO: we could use icons
// https://doc.qt.io/qt-5/qml-qtquick-controls2-abstractbutton.html#icon-prop // https://doc.qt.io/qt-5/qml-qtquick-controls2-abstractbutton.html#icon-prop
background: Rectangle { background: Rectangle {
color: { color: {
const fullness = ctx.locations[modelData] "#ffffff"
if (fullness >= 0 && fullness < 0.4) { // FIXME locations is not defined when we launch
"#83fc5a" /*
} else if (fullness >= 0.4 && fullness < 0.75) { const fullness = ctx.locations[modelData]
"#fcb149" if (fullness >= 0 && fullness < 0.4) {
} else if (fullness >= 0.75) { "#83fc5a"
"#fc5a5d" } else if (fullness >= 0.4 && fullness < 0.75) {
} else { "#fcb149"
"#ffffff" } else if (fullness >= 0.75) {
} "#fc5a5d"
} } else {
} "#ffffff"
contentItem: Text { }
text: modelData */
font: gwSelector.font }
color: "#000000" }
} contentItem: Text {
} text: modelData
font: gwSelector.font
color: "#000000"
}
}
} }
} // end column } // end column
} // end item } // end item
} // end stacklayout } // end stacklayout
Connections { Connections {
target: jsonModel target: jsonModel
function onDataChanged() { function onDataChanged() {
ctx = JSON.parse(jsonModel.getJson()) ctx = JSON.parse(jsonModel.getJson())
// TODO pass QML_DEBUG variable to be hyper-verbose // TODO pass QML_DEBUG variable to be hyper-verbose
//console.debug(jsonModel.getJson()) //console.debug(jsonModel.getJson())
gwSelector.model = Object.keys(ctx.locations) gwSelector.model = Object.keys(ctx.locations)
if (ctx.donateDialog == 'true') { if (ctx.donateDialog == 'true') {
...@@ -275,21 +276,21 @@ Window { ...@@ -275,21 +276,21 @@ Window {
} }
function isManualLocation() { function isManualLocation() {
if (!ctx) { if (!ctx) {
return false return false
} }
return ctx.manualLocation == "true" return ctx.manualLocation == "true"
} }
function setGwSelection() { function setGwSelection() {
if (!ctx.currentLocation) { if (!ctx.currentLocation) {
return return
} }
const location = ctx.currentLocation.toLowerCase() const location = ctx.currentLocation.toLowerCase()
const idx = gwSelector.model.indexOf(location) const idx = gwSelector.model.indexOf(location)
gwSelector.currentIndex = idx gwSelector.currentIndex = idx
backend.useLocation(location) backend.useLocation(location)
} }
Component.onCompleted: { Component.onCompleted: {
...@@ -326,7 +327,7 @@ Window { ...@@ -326,7 +327,7 @@ Window {
} }
function locationStr() { function locationStr() {
return ctx.currentLocation + ", " + ctx.currentCountry return ctx.currentLocation + ", " + ctx.currentCountry
} }
property var icons: { property var icons: {
...@@ -346,12 +347,12 @@ Window { ...@@ -346,12 +347,12 @@ Window {
visible: systrayVisible visible: systrayVisible
onActivated: { onActivated: {
if (reason != SystemTrayIcon.Context) { if (reason != SystemTrayIcon.Context) {
if (app.visible) { if (app.visible) {
app.hide() app.hide()
} else { } else {
app.show() app.show()
} }
} }
} }
...@@ -360,7 +361,6 @@ Window { ...@@ -360,7 +361,6 @@ Window {
* otherwise the ids are not available * otherwise the ids are not available
* from other components * from other components
*/ */
menu: Menu { menu: Menu {
id: systrayMenu id: systrayMenu
...@@ -379,23 +379,21 @@ Window { ...@@ -379,23 +379,21 @@ Window {
checkable: true checkable: true
checked: !isManualLocation() checked: !isManualLocation()
onTriggered: { onTriggered: {
backend.useAutomaticGateway() backend.useAutomaticGateway()
} }
} }
/* a minimal segfault for submenu */ /* a minimal segfault for submenu */
// Menu {} // Menu {}
MenuItem { MenuItem {
id: manualSelectionItem id: manualSelectionItem
text: { text: {
if (isManualLocation()) { if (isManualLocation()) {
locationStr() locationStr()
} else { } else {
qsTr("Pick location…") qsTr("Pick location…")
} }
} }
checkable: true checkable: true
checked: isManualLocation() checked: isManualLocation()
onTriggered: setGwSelection() onTriggered: setGwSelection()
...@@ -403,7 +401,6 @@ Window { ...@@ -403,7 +401,6 @@ Window {
MenuSeparator {} MenuSeparator {}
MenuItem { MenuItem {
text: { text: {
if (vpn.state == "failed") if (vpn.state == "failed")
...@@ -482,7 +479,7 @@ Window { ...@@ -482,7 +479,7 @@ Window {
} }
Component.onCompleted: { Component.onCompleted: {
icon.source = icons["off"] systray.icon.source = icons["off"]
tooltip = qsTr("Checking status…") tooltip = qsTr("Checking status…")
console.debug("systray init completed") console.debug("systray init completed")
hide() hide()
......
...@@ -92,6 +92,9 @@ func (p *gatewayPool) isValidLocation(location string) bool { ...@@ -92,6 +92,9 @@ func (p *gatewayPool) isValidLocation(location string) bool {
func (p *gatewayPool) listLocationFullness(transport string) map[string]float64 { func (p *gatewayPool) listLocationFullness(transport string) map[string]float64 {
locations := p.getLocations() locations := p.getLocations()
cm := make(map[string]float64) cm := make(map[string]float64)
if len(locations) == 0 {
return cm
}
if len(p.recommended) != 0 { if len(p.recommended) != 0 {
for _, gw := range p.recommended { for _, gw := range p.recommended {
if _, ok := cm[gw.gateway.Location]; ok { if _, ok := cm[gw.gateway.Location]; ok {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment