Do not propose user to restart Bitmessage

if network settings have changed, drop network connections instead
This commit is contained in:
Dmitri Bogomolov 2018-11-20 16:53:25 +02:00
parent 8a3074f3ff
commit 18392017c6
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -1,7 +1,7 @@
import os import os
import sys import sys
from PyQt4 import QtGui from PyQt4 import QtCore, QtGui
import debug import debug
import defaults import defaults
@ -29,6 +29,8 @@ class SettingsDialog(QtGui.QDialog):
self.parent = parent self.parent = parent
self.firstrun = firstrun self.firstrun = firstrun
self.config = BMConfigParser() self.config = BMConfigParser()
self.net_restart_needed = False
self.timer = QtCore.QTimer()
self.lineEditMaxOutboundConnections.setValidator( self.lineEditMaxOutboundConnections.setValidator(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections)) QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
@ -98,7 +100,8 @@ class SettingsDialog(QtGui.QDialog):
self.checkBoxSocksListen.setChecked( self.checkBoxSocksListen.setChecked(
config.getboolean('bitmessagesettings', 'sockslisten')) config.getboolean('bitmessagesettings', 'sockslisten'))
proxy_type = config.get('bitmessagesettings', 'socksproxytype') proxy_type = config.safeGet(
'bitmessagesettings', 'socksproxytype', 'none')
if proxy_type == 'none': if proxy_type == 'none':
self.comboBoxProxyType.setCurrentIndex(0) self.comboBoxProxyType.setCurrentIndex(0)
self.lineEditSocksHostname.setEnabled(False) self.lineEditSocksHostname.setEnabled(False)
@ -283,16 +286,11 @@ class SettingsDialog(QtGui.QDialog):
if int(self.config.get('bitmessagesettings', 'port')) != int( if int(self.config.get('bitmessagesettings', 'port')) != int(
self.lineEditTCPPort.text()): self.lineEditTCPPort.text()):
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Restart"),
_translate(
"MainWindow",
"You must restart Bitmessage for the port number"
" change to take effect.")
)
self.config.set( self.config.set(
'bitmessagesettings', 'port', str(self.lineEditTCPPort.text())) 'bitmessagesettings', 'port', str(self.lineEditTCPPort.text()))
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
self.net_restart_needed = True
if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean( if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean(
'bitmessagesettings', 'upnp'): 'bitmessagesettings', 'upnp'):
self.config.set( self.config.set(
@ -303,32 +301,28 @@ class SettingsDialog(QtGui.QDialog):
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
upnpThread.start() upnpThread.start()
proxy_type = self.config.safeGet(
'bitmessagesettings', 'socksproxytype', 'none')
if ( if (
self.config.get('bitmessagesettings', 'socksproxytype') == proxy_type == 'none' and
'none' and self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' and
self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' shared.statusIconColor != 'red'
): ):
if shared.statusIconColor != 'red': self.net_restart_needed = True
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Restart"),
_translate(
"MainWindow",
"Bitmessage will use your proxy from now on but"
" you may want to manually restart Bitmessage now"
" to close existing connections (if any).")
)
if ( if (
self.config.get('bitmessagesettings', 'socksproxytype')[0:5] == proxy_type[0:5] == 'SOCKS' and
'SOCKS' and self.comboBoxProxyType.currentText()[0:5] != 'SOCKS' self.comboBoxProxyType.currentText()[0:5] != 'SOCKS'
): ):
self.net_restart_needed = True
self.parent.statusbar.clearMessage() self.parent.statusbar.clearMessage()
# just in case we changed something in the network connectivity # just in case we changed something in the network connectivity
state.resetNetworkProtocolAvailability() state.resetNetworkProtocolAvailability()
if self.comboBoxProxyType.currentText()[0:5] == 'SOCKS': self.config.set(
self.config.set('bitmessagesettings', 'socksproxytype', str( 'bitmessagesettings', 'socksproxytype',
self.comboBoxProxyType.currentText())) str(self.comboBoxProxyType.currentText())
else: if self.comboBoxProxyType.currentText()[0:5] == 'SOCKS'
self.config.set('bitmessagesettings', 'socksproxytype', 'none') else 'none'
)
self.config.set('bitmessagesettings', 'socksauthentication', str( self.config.set('bitmessagesettings', 'socksauthentication', str(
self.checkBoxAuthentication.isChecked())) self.checkBoxAuthentication.isChecked()))
self.config.set('bitmessagesettings', 'sockshostname', str( self.config.set('bitmessagesettings', 'sockshostname', str(
@ -495,6 +489,15 @@ class SettingsDialog(QtGui.QDialog):
self.config.save() self.config.save()
if self.net_restart_needed:
self.net_restart_needed = False
self.config.set('bitmessagesettings', 'dontconnect', 'true')
self.timer.singleShot(
5000, lambda:
self.config.remove_option(
'bitmessagesettings', 'dontconnect')
)
self.parent.updateStartOnLogon() self.parent.updateStartOnLogon()
if ( if (