From 0bf00f54b4478192d976c06af07f8183a8052233 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 27 Apr 2021 16:02:42 +0200 Subject: [bug] fix init crash --- gui/qml/LoginDialog.qml | 2 +- gui/qml/LoginOKDialog.qml | 2 +- gui/qml/VpnState.qml | 42 +++++++-------- gui/qml/main.qml | 129 ++++++++++++++++++++++------------------------ 4 files changed, 86 insertions(+), 89 deletions(-) (limited to 'gui') diff --git a/gui/qml/LoginDialog.qml b/gui/qml/LoginDialog.qml index 4d92648..5110b14 100644 --- a/gui/qml/LoginDialog.qml +++ b/gui/qml/LoginDialog.qml @@ -1,6 +1,6 @@ import QtQuick 2.0 import QtQuick.Dialogs 1.2 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.12 Dialog { title: qsTr("Login") diff --git a/gui/qml/LoginOKDialog.qml b/gui/qml/LoginOKDialog.qml index f00a0ab..ba57dbd 100644 --- a/gui/qml/LoginOKDialog.qml +++ b/gui/qml/LoginOKDialog.qml @@ -1,6 +1,6 @@ import QtQuick 2.0 import QtQuick.Dialogs 1.2 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.12 Dialog { standardButtons: StandardButton.Ok diff --git a/gui/qml/VpnState.qml b/gui/qml/VpnState.qml index 7ec6695..e1a183c 100644 --- a/gui/qml/VpnState.qml +++ b/gui/qml/VpnState.qml @@ -1,5 +1,5 @@ import QtQuick 2.0 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.12 StateGroup { @@ -26,7 +26,7 @@ StateGroup { } PropertyChanges { target: autoSelectionItem - text: qsTr("Best") + text: qsTr("Best") } PropertyChanges { target: mainStatus @@ -54,14 +54,14 @@ StateGroup { } PropertyChanges { target: autoSelectionItem - text: { - if (autoSelectionButton.checked) { - //: %1 -> location to which the client is connected to - qsTr("Best (%1)").arg(locationStr()) - } else { - qsTr("Best") - } - } + text: { + if (autoSelectionButton.checked) { + //: %1 -> location to which the client is connected to + qsTr("Best (%1)").arg(locationStr()) + } else { + qsTr("Best") + } + } } PropertyChanges { target: mainStatus @@ -69,7 +69,7 @@ StateGroup { } PropertyChanges { 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()) } }, @@ -86,14 +86,14 @@ StateGroup { } PropertyChanges { target: autoSelectionItem - text: { - if (autoSelectionButton.checked) { - //: %1 -> location to which the client is connected to - qsTr("Best (%1)").arg(locationStr()) - } else { - qsTr("Best") - } - } + text: { + if (autoSelectionButton.checked) { + //: %1 -> location to which the client is connected to + qsTr("Best (%1)").arg(locationStr()) + } else { + qsTr("Best") + } + } } PropertyChanges { target: mainStatus @@ -117,7 +117,7 @@ StateGroup { } PropertyChanges { target: autoSelectionItem - text: qsTr("Best") + text: qsTr("Best") } PropertyChanges { target: mainStatus @@ -141,7 +141,7 @@ StateGroup { } PropertyChanges { target: autoSelectionItem - text: qsTr("Best") + text: qsTr("Best") } PropertyChanges { target: mainStatus diff --git a/gui/qml/main.qml b/gui/qml/main.qml index 3978614..cc984f0 100644 --- a/gui/qml/main.qml +++ b/gui/qml/main.qml @@ -16,15 +16,12 @@ Window { maximumHeight: 500 minimumHeight: 300 - flags: Qt.WindowsStaysOnTopHint - property var ctx property var loginDone property var allowEmptyPass // TODO get a nice background color for this mainwindow. It should be customizable. // TODO refactorize all this mess into discrete components. - TabBar { id: bar width: parent.width @@ -65,7 +62,6 @@ Window { anchors.horizontalCenter: parent.horizontalCenter } - SwitchDelegate { id: vpntoggle @@ -76,17 +72,19 @@ Window { Connections { function onCheckedChanged() { - if (vpntoggle.checked == true && ctx.status == "off") { + if (vpntoggle.checked == true + && ctx.status == "off") { backend.switchOn() } - if (vpntoggle.checked === false && ctx.status == "on") { + if (vpntoggle.checked === false + && ctx.status == "on") { backend.switchOff() } } } contentItem: Text { - rightPadding: vpntoggle.indicator.width + control.spacing + rightPadding: vpntoggle.indicator.width + vpntoggle.spacing text: vpntoggle.text font: vpntoggle.font opacity: enabled ? 1.0 : 0.3 @@ -147,13 +145,13 @@ Window { id: autoSelectionButton checked: !isManualLocation() text: qsTr("Best") - onClicked: backend.useAutomaticGateway() + onClicked: backend.useAutomaticGateway() } RadioButton { id: manualSelectionButton checked: isManualLocation() text: qsTr("Manual") - onClicked: setGwSelection() + onClicked: setGwSelection() } ComboBox { id: gwSelector @@ -167,41 +165,44 @@ Window { backend.useLocation(currentText.toString()) } - delegate: ItemDelegate { - // TODO: we could use icons - // https://doc.qt.io/qt-5/qml-qtquick-controls2-abstractbutton.html#icon-prop - background: Rectangle { - color: { - const fullness = ctx.locations[modelData] - if (fullness >= 0 && fullness < 0.4) { - "#83fc5a" - } else if (fullness >= 0.4 && fullness < 0.75) { - "#fcb149" - } else if (fullness >= 0.75) { - "#fc5a5d" - } else { - "#ffffff" - } - } - } - contentItem: Text { - text: modelData - font: gwSelector.font - color: "#000000" - } - } + delegate: ItemDelegate { + // TODO: we could use icons + // https://doc.qt.io/qt-5/qml-qtquick-controls2-abstractbutton.html#icon-prop + background: Rectangle { + color: { + "#ffffff" + // FIXME locations is not defined when we launch + /* + const fullness = ctx.locations[modelData] + if (fullness >= 0 && fullness < 0.4) { + "#83fc5a" + } else if (fullness >= 0.4 && fullness < 0.75) { + "#fcb149" + } else if (fullness >= 0.75) { + "#fc5a5d" + } else { + "#ffffff" + } + */ + } + } + contentItem: Text { + text: modelData + font: gwSelector.font + color: "#000000" + } + } } } // end column - } // end item + } // end item } // end stacklayout - Connections { target: jsonModel function onDataChanged() { ctx = JSON.parse(jsonModel.getJson()) // TODO pass QML_DEBUG variable to be hyper-verbose - //console.debug(jsonModel.getJson()) + //console.debug(jsonModel.getJson()) gwSelector.model = Object.keys(ctx.locations) if (ctx.donateDialog == 'true') { @@ -275,21 +276,21 @@ Window { } function isManualLocation() { - if (!ctx) { + if (!ctx) { return false - } - return ctx.manualLocation == "true" + } + return ctx.manualLocation == "true" } function setGwSelection() { - if (!ctx.currentLocation) { - return - } - - const location = ctx.currentLocation.toLowerCase() - const idx = gwSelector.model.indexOf(location) - gwSelector.currentIndex = idx - backend.useLocation(location) + if (!ctx.currentLocation) { + return + } + + const location = ctx.currentLocation.toLowerCase() + const idx = gwSelector.model.indexOf(location) + gwSelector.currentIndex = idx + backend.useLocation(location) } Component.onCompleted: { @@ -326,7 +327,7 @@ Window { } function locationStr() { - return ctx.currentLocation + ", " + ctx.currentCountry + return ctx.currentLocation + ", " + ctx.currentCountry } property var icons: { @@ -346,12 +347,12 @@ Window { visible: systrayVisible onActivated: { - if (reason != SystemTrayIcon.Context) { - if (app.visible) { - app.hide() - } else { - app.show() - } + if (reason != SystemTrayIcon.Context) { + if (app.visible) { + app.hide() + } else { + app.show() + } } } @@ -360,7 +361,6 @@ Window { * otherwise the ids are not available * from other components */ - menu: Menu { id: systrayMenu @@ -379,23 +379,21 @@ Window { checkable: true checked: !isManualLocation() onTriggered: { - backend.useAutomaticGateway() + backend.useAutomaticGateway() } } - /* a minimal segfault for submenu */ // Menu {} - MenuItem { id: manualSelectionItem - text: { - if (isManualLocation()) { - locationStr() - } else { - qsTr("Pick location…") - } - } + text: { + if (isManualLocation()) { + locationStr() + } else { + qsTr("Pick location…") + } + } checkable: true checked: isManualLocation() onTriggered: setGwSelection() @@ -403,7 +401,6 @@ Window { MenuSeparator {} - MenuItem { text: { if (vpn.state == "failed") @@ -482,7 +479,7 @@ Window { } Component.onCompleted: { - icon.source = icons["off"] + systray.icon.source = icons["off"] tooltip = qsTr("Checking status…") console.debug("systray init completed") hide() -- cgit v1.2.3