Support for socksproxytype plugins in Settings dialog

This commit is contained in:
Dmitri Bogomolov 2019-10-03 18:34:27 +03:00
parent 5160a68c28
commit e3ccc3c7c8
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 35 additions and 33 deletions

View File

@ -1,3 +1,4 @@
import ConfigParser
import os import os
import sys import sys
@ -16,6 +17,7 @@ import tempfile
import widgets import widgets
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlStoredProcedure from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network.asyncore_pollchoose import set_rates from network.asyncore_pollchoose import set_rates
from tr import _translate from tr import _translate
@ -32,6 +34,16 @@ class SettingsDialog(QtGui.QDialog):
self.net_restart_needed = False self.net_restart_needed = False
self.timer = QtCore.QTimer() self.timer = QtCore.QTimer()
try:
import pkg_resources
except ImportError:
pass
else:
# Append proxy types defined in plugins
for ep in pkg_resources.iter_entry_points(
'bitmessage.proxyconfig'):
self.comboBoxProxyType.addItem(ep.name)
self.lineEditMaxOutboundConnections.setValidator( self.lineEditMaxOutboundConnections.setValidator(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections)) QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
@ -117,21 +129,16 @@ class SettingsDialog(QtGui.QDialog):
self.checkBoxOnionOnly.setChecked( self.checkBoxOnionOnly.setChecked(
config.safeGetBoolean('bitmessagesettings', 'onionservicesonly')) config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
proxy_type = config.safeGet( try:
'bitmessagesettings', 'socksproxytype', 'none') # Get real value, not temporary
if proxy_type == 'none': self._proxy_type = ConfigParser.SafeConfigParser.get(
self.comboBoxProxyType.setCurrentIndex(0) config, 'bitmessagesettings', 'socksproxytype')
self.lineEditSocksHostname.setEnabled(False) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
self.lineEditSocksPort.setEnabled(False) self._proxy_type = 'none'
self.lineEditSocksUsername.setEnabled(False) self.comboBoxProxyType.setCurrentIndex(
self.lineEditSocksPassword.setEnabled(False) 0 if self._proxy_type == 'none'
self.checkBoxAuthentication.setEnabled(False) else self.comboBoxProxyType.findText(self._proxy_type))
self.checkBoxSocksListen.setEnabled(False) self.comboBoxProxyTypeChanged(self.comboBoxProxyType.currentIndex())
self.checkBoxOnionOnly.setEnabled(False)
elif proxy_type == 'SOCKS4a':
self.comboBoxProxyType.setCurrentIndex(1)
elif proxy_type == 'SOCKS5':
self.comboBoxProxyType.setCurrentIndex(2)
self.lineEditSocksHostname.setText( self.lineEditSocksHostname.setText(
config.get('bitmessagesettings', 'sockshostname')) config.get('bitmessagesettings', 'sockshostname'))
@ -219,7 +226,7 @@ class SettingsDialog(QtGui.QDialog):
self.checkBoxAuthentication.setEnabled(False) self.checkBoxAuthentication.setEnabled(False)
self.checkBoxSocksListen.setEnabled(False) self.checkBoxSocksListen.setEnabled(False)
self.checkBoxOnionOnly.setEnabled(False) self.checkBoxOnionOnly.setEnabled(False)
elif comboBoxIndex in (1, 2): else:
self.lineEditSocksHostname.setEnabled(True) self.lineEditSocksHostname.setEnabled(True)
self.lineEditSocksPort.setEnabled(True) self.lineEditSocksPort.setEnabled(True)
self.checkBoxAuthentication.setEnabled(True) self.checkBoxAuthentication.setEnabled(True)
@ -321,27 +328,22 @@ class SettingsDialog(QtGui.QDialog):
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
upnpThread.start() upnpThread.start()
proxy_type = self.config.safeGet( proxytype_index = self.comboBoxProxyType.currentIndex()
'bitmessagesettings', 'socksproxytype', 'none') if proxytype_index == 0:
if ( if self._proxy_type != 'none' and shared.statusIconColor != 'red':
proxy_type == 'none' and
self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' and
shared.statusIconColor != 'red'
):
self.net_restart_needed = True self.net_restart_needed = True
if ( elif self.comboBoxProxyType.currentText() != self._proxy_type:
proxy_type[0:5] == 'SOCKS' and
self.comboBoxProxyType.currentText()[0:5] != 'SOCKS'
):
self.net_restart_needed = True self.net_restart_needed = True
self.parent.statusbar.clearMessage() self.parent.statusbar.clearMessage()
self.config.set( self.config.set(
'bitmessagesettings', 'socksproxytype', 'bitmessagesettings', 'socksproxytype',
str(self.comboBoxProxyType.currentText()) 'none' if self.comboBoxProxyType.currentIndex() == 0
if self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' else str(self.comboBoxProxyType.currentText())
else 'none'
) )
if proxytype_index > 2: # last literal proxytype in ui
start_proxyconfig()
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(

View File

@ -419,12 +419,12 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>SOCKS4a</string> <string notr="true">SOCKS4a</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>SOCKS5</string> <string notr="true">SOCKS5</string>
</property> </property>
</item> </item>
</widget> </widget>