qml: fix updating network settings
Previously the server parameters were each handled differently, e.g. auto-connect was only applied when updating Network.server and not when Config.autoConnect was updated. Similarly, updating Network.server did not restart the network, leading to >1 connection when Network.oneServer was set to True before updating Network.server. Consolidate server parameter updates into a single call, remove the individual setters, and move Config.autoConnect and Config.autoConnectDefined to Network.
This commit is contained in:
@@ -34,7 +34,6 @@ ElDialog {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatButton {
|
FlatButton {
|
||||||
@@ -42,9 +41,10 @@ ElDialog {
|
|||||||
text: qsTr('Ok')
|
text: qsTr('Ok')
|
||||||
icon.source: '../../icons/confirmed.png'
|
icon.source: '../../icons/confirmed.png'
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Network.oneServer = serverconfig.serverConnectMode == ServerConnectModeComboBox.Mode.Single
|
let auto_connect = serverconfig.serverConnectMode == ServerConnectModeComboBox.Mode.Autoconnect
|
||||||
Config.autoConnect = serverconfig.serverConnectMode == ServerConnectModeComboBox.Mode.Autoconnect
|
let server = serverconfig.address
|
||||||
Network.server = serverconfig.address
|
let one_server = serverconfig.serverConnectMode == ServerConnectModeComboBox.Mode.Single
|
||||||
|
Network.setServerParameters(server, auto_connect, one_server)
|
||||||
rootItem.close()
|
rootItem.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ Wizard {
|
|||||||
} else {
|
} else {
|
||||||
Network.proxy = {'enabled': false}
|
Network.proxy = {'enabled': false}
|
||||||
}
|
}
|
||||||
Config.autoConnect = wizard_data['autoconnect']
|
Network.setServerParameters(wizard_data['server'], wizard_data['autoconnect'], wizard_data['one_server'])
|
||||||
if (!wizard_data['autoconnect']) {
|
|
||||||
Network.server = wizard_data['server']
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ ElComboBox {
|
|||||||
]
|
]
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (!Config.autoConnectDefined) { // initial setup
|
if (!Network.autoConnectDefined) { // initial setup
|
||||||
server_connect_mode_cb.currentIndex = server_connect_mode_cb.indexOfValue(
|
server_connect_mode_cb.currentIndex = server_connect_mode_cb.indexOfValue(
|
||||||
ServerConnectModeComboBox.Mode.Manual)
|
ServerConnectModeComboBox.Mode.Manual)
|
||||||
} else {
|
} else {
|
||||||
server_connect_mode_cb.currentIndex = server_connect_mode_cb.indexOfValue(
|
server_connect_mode_cb.currentIndex = server_connect_mode_cb.indexOfValue(
|
||||||
Config.autoConnect
|
Network.autoConnect
|
||||||
? ServerConnectModeComboBox.Mode.Autoconnect
|
? ServerConnectModeComboBox.Mode.Autoconnect
|
||||||
: Network.oneServer
|
: Network.oneServer
|
||||||
? ServerConnectModeComboBox.Mode.Single
|
? ServerConnectModeComboBox.Mode.Single
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ ApplicationWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
function continueWithServerConnection() {
|
function continueWithServerConnection() {
|
||||||
if (!Config.autoConnectDefined) {
|
if (!Network.autoConnectDefined) {
|
||||||
var dialog = serverConnectWizard.createObject(app)
|
var dialog = serverConnectWizard.createObject(app)
|
||||||
// without completed serverConnectWizard we can't start
|
// without completed serverConnectWizard we can't start
|
||||||
dialog.rejected.connect(function() {
|
dialog.rejected.connect(function() {
|
||||||
|
|||||||
@@ -82,21 +82,6 @@ class QEConfig(AuthMixin, QObject):
|
|||||||
self.config.TERMS_OF_USE_ACCEPTED = 0
|
self.config.TERMS_OF_USE_ACCEPTED = 0
|
||||||
self.termsOfUseChanged.emit()
|
self.termsOfUseChanged.emit()
|
||||||
|
|
||||||
autoConnectChanged = pyqtSignal()
|
|
||||||
@pyqtProperty(bool, notify=autoConnectChanged)
|
|
||||||
def autoConnect(self):
|
|
||||||
return self.config.NETWORK_AUTO_CONNECT
|
|
||||||
|
|
||||||
@autoConnect.setter
|
|
||||||
def autoConnect(self, auto_connect):
|
|
||||||
self.config.NETWORK_AUTO_CONNECT = auto_connect
|
|
||||||
self.autoConnectChanged.emit()
|
|
||||||
|
|
||||||
# auto_connect is actually a tri-state, expose the undefined case
|
|
||||||
@pyqtProperty(bool, notify=autoConnectChanged)
|
|
||||||
def autoConnectDefined(self):
|
|
||||||
return self.config.cv.NETWORK_AUTO_CONNECT.is_set()
|
|
||||||
|
|
||||||
baseUnitChanged = pyqtSignal()
|
baseUnitChanged = pyqtSignal()
|
||||||
@pyqtProperty(str, notify=baseUnitChanged)
|
@pyqtProperty(str, notify=baseUnitChanged)
|
||||||
def baseUnit(self):
|
def baseUnit(self):
|
||||||
|
|||||||
@@ -184,20 +184,39 @@ class QENetwork(QObject, QtEventListener):
|
|||||||
def serverHeight(self):
|
def serverHeight(self):
|
||||||
return self._server_height
|
return self._server_height
|
||||||
|
|
||||||
|
autoConnectChanged = pyqtSignal()
|
||||||
|
@pyqtProperty(bool, notify=autoConnectChanged)
|
||||||
|
def autoConnect(self):
|
||||||
|
return self.network.config.NETWORK_AUTO_CONNECT
|
||||||
|
|
||||||
|
# auto_connect is actually a tri-state, expose the undefined case
|
||||||
|
@pyqtProperty(bool, notify=autoConnectChanged)
|
||||||
|
def autoConnectDefined(self):
|
||||||
|
return self.network.config.cv.NETWORK_AUTO_CONNECT.is_set()
|
||||||
|
|
||||||
@pyqtProperty(str, notify=statusChanged)
|
@pyqtProperty(str, notify=statusChanged)
|
||||||
def server(self):
|
def server(self):
|
||||||
return self._server
|
return self._server
|
||||||
|
|
||||||
@server.setter
|
@pyqtSlot(str, bool, bool)
|
||||||
def server(self, server: str):
|
def setServerParameters(self, server: str, auto_connect: bool, one_server: bool):
|
||||||
net_params = self.network.get_parameters()
|
net_params = self.network.get_parameters()
|
||||||
try:
|
if server == net_params.server and auto_connect == net_params.auto_connect and one_server == net_params.oneserver:
|
||||||
server = ServerAddr.from_str_with_inference(server)
|
|
||||||
if not server:
|
|
||||||
raise Exception('failed to parse')
|
|
||||||
except Exception:
|
|
||||||
return
|
return
|
||||||
net_params = net_params._replace(server=server, auto_connect=QEConfig.instance.autoConnect)
|
if server != str(net_params.server):
|
||||||
|
try:
|
||||||
|
server = ServerAddr.from_str_with_inference(server)
|
||||||
|
if not server:
|
||||||
|
raise Exception('failed to parse')
|
||||||
|
except Exception:
|
||||||
|
if not auto_connect:
|
||||||
|
return
|
||||||
|
server = net_params.server
|
||||||
|
self.statusChanged.emit()
|
||||||
|
if auto_connect != net_params.auto_connect:
|
||||||
|
self.network.config.NETWORK_AUTO_CONNECT = auto_connect
|
||||||
|
self.autoConnectChanged.emit()
|
||||||
|
net_params = net_params._replace(server=server, auto_connect=auto_connect, oneserver=one_server)
|
||||||
self.network.run_from_another_thread(self.network.set_parameters(net_params))
|
self.network.run_from_another_thread(self.network.set_parameters(net_params))
|
||||||
|
|
||||||
@pyqtProperty(str, notify=statusChanged)
|
@pyqtProperty(str, notify=statusChanged)
|
||||||
@@ -258,14 +277,6 @@ class QENetwork(QObject, QtEventListener):
|
|||||||
def oneServer(self):
|
def oneServer(self):
|
||||||
return self.network.oneserver
|
return self.network.oneserver
|
||||||
|
|
||||||
@oneServer.setter
|
|
||||||
def oneServer(self, one_server: bool):
|
|
||||||
if one_server != self.network.oneserver:
|
|
||||||
net_params = self.network.get_parameters()
|
|
||||||
net_params = net_params._replace(oneserver=one_server)
|
|
||||||
self.network.run_from_another_thread(self.network.set_parameters(net_params))
|
|
||||||
self.statusChanged.emit()
|
|
||||||
|
|
||||||
@pyqtProperty('QVariant', notify=feeHistogramUpdated)
|
@pyqtProperty('QVariant', notify=feeHistogramUpdated)
|
||||||
def feeHistogram(self):
|
def feeHistogram(self):
|
||||||
return self._fee_histogram
|
return self._fee_histogram
|
||||||
|
|||||||
Reference in New Issue
Block a user