From 3f27b80154226e9356bd545c006f63f437a217f2 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 11 Dec 2017 17:58:53 +1100 Subject: [PATCH] experimenting with adjustSize() which seems to help the widget issue. Also adjust the custom Bridge parsing so that it injects the Bridge prefix automatically (means we can copy/pasta from https://bridges.torproject.org/bridges) --- a | 32 ++++++++++++++++++++ onionshare_gui/settings_dialog.py | 50 +++++++++++++++++++++++++++---- share/locale/en.json | 1 + 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 a diff --git a/a b/a new file mode 100644 index 00000000..f45f6335 --- /dev/null +++ b/a @@ -0,0 +1,32 @@ +Old Settings + + + ++ # Remove the 'Bridge' lines at the start of each bridge. ++ # They are added automatically to provide compatibility with ++ # copying/pasting bridges provided from https://bridges.torproject.org ++ new_bridges = [] ++ bridges = self.old_settings.get('tor_bridges_use_custom_bridges').split('Bridge ') ++ for bridge in bridges: ++ new_bridges.append(bridge) ++ new_bridges = ''.join(new_bridges) ++ self.tor_bridges_use_custom_textbox.setPlainText(new_bridges) + + + + ++ # Insert a 'Bridge' line at the start of each bridge. ++ # This makes it easier to copy/paste a set of bridges ++ # provided from https://bridges.torproject.org ++ new_bridges = [] ++ bridges = self.tor_bridges_use_custom_textbox.toPlainText().split('\n') ++ for bridge in bridges: ++ if bridge != '': ++ new_bridges.append(''.join(['Bridge ', bridge, '\n'])) ++ new_bridges = ''.join(new_bridges) ++ settings.set('tor_bridges_use_custom_bridges', new_bridges) + + + ++ "gui_settings_tor_bridges_custom_label": "You can obtain bridges from https://bridges.torproject.org", + diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 11dc755f..3736f31f 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -202,18 +202,27 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option', True)) self.tor_bridges_use_custom_radio.toggled.connect(self.tor_bridges_use_custom_radio_toggled) + self.tor_bridges_use_custom_label = QtWidgets.QLabel(strings._('gui_settings_tor_bridges_custom_label', True)) self.tor_bridges_use_custom_textbox = QtWidgets.QPlainTextEdit() - self.tor_bridges_use_custom_textbox.setPlaceholderText('Bridge [address:port] [identifier]') - tor_bridges_use_custom_textbox_options_layout = QtWidgets.QHBoxLayout() + self.tor_bridges_use_custom_textbox.setPlaceholderText('[address:port] [identifier]') + self.tor_bridges_use_custom_textbox.adjustSize() + + tor_bridges_use_custom_textbox_options_layout = QtWidgets.QVBoxLayout() + tor_bridges_use_custom_textbox_options_layout.addWidget(self.tor_bridges_use_custom_label) tor_bridges_use_custom_textbox_options_layout.addWidget(self.tor_bridges_use_custom_textbox) + self.tor_bridges_use_custom_textbox_options = QtWidgets.QWidget() self.tor_bridges_use_custom_textbox_options.setLayout(tor_bridges_use_custom_textbox_options_layout) self.tor_bridges_use_custom_textbox_options.hide() - self.tor_bridges_use_custom_textbox_options.adjustSize() # Test tor settings button self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button', True)) self.connection_type_test_button.clicked.connect(self.test_tor_clicked) + connection_type_test_button_layout = QtWidgets.QHBoxLayout() + connection_type_test_button_layout.addWidget(self.connection_type_test_button) + connection_type_test_button_group = QtWidgets.QGroupBox() + connection_type_test_button_group.setLayout(connection_type_test_button_layout) + # Put the radios into their own group so they are exclusive connection_type_radio_group_layout = QtWidgets.QVBoxLayout() @@ -239,7 +248,6 @@ class SettingsDialog(QtWidgets.QDialog): connection_type_bridges_radio_group_layout.addWidget(self.tor_bridges_use_obfs4_radio) connection_type_bridges_radio_group_layout.addWidget(self.tor_bridges_use_custom_radio) connection_type_bridges_radio_group_layout.addWidget(self.tor_bridges_use_custom_textbox_options) - connection_type_bridges_radio_group_layout.addWidget(self.connection_type_test_button) connection_type_bridges_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_tor_bridges", True)) connection_type_bridges_radio_group.setLayout(connection_type_bridges_radio_group_layout) @@ -272,6 +280,7 @@ class SettingsDialog(QtWidgets.QDialog): right_col_layout.addWidget(connection_type_radio_group) right_col_layout.addWidget(connection_type_group) right_col_layout.addWidget(connection_type_bridges_radio_group) + right_col_layout.addWidget(connection_type_test_button_group) right_col_layout.addWidget(self.tor_status) right_col_layout.addStretch() @@ -351,7 +360,15 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_bridges_use_obfs4_radio.setChecked(self.old_settings.get('tor_bridges_use_obfs4')) if self.old_settings.get('tor_bridges_use_custom_bridges'): self.tor_bridges_use_custom_radio.setChecked(True) - self.tor_bridges_use_custom_textbox.setPlainText(self.old_settings.get('tor_bridges_use_custom_bridges')) + # Remove the 'Bridge' lines at the start of each bridge. + # They are added automatically to provide compatibility with + # copying/pasting bridges provided from https://bridges.torproject.org + new_bridges = [] + bridges = self.old_settings.get('tor_bridges_use_custom_bridges').split('Bridge ') + for bridge in bridges: + new_bridges.append(bridge) + new_bridges = ''.join(new_bridges) + self.tor_bridges_use_custom_textbox.setPlainText(new_bridges) def connection_type_bundled_toggled(self, checked): """ @@ -386,6 +403,8 @@ class SettingsDialog(QtWidgets.QDialog): if checked: self.tor_bridges_use_obfs4_radio.setEnabled(False) self.tor_bridges_use_custom_textbox_options.show() + self.tor_bridges_use_custom_textbox_options.adjustSize() + self.adjustSize() def connection_type_automatic_toggled(self, checked): """ @@ -406,6 +425,10 @@ class SettingsDialog(QtWidgets.QDialog): self.authenticate_group.show() self.connection_type_control_port_extras.show() self.connection_type_socks.show() + self.authenticate_group.adjustSize() + self.connection_type_control_port_extras.adjustSize() + self.connection_type_socks.adjustSize() + self.adjustSize() else: self.connection_type_control_port_extras.hide() @@ -420,6 +443,10 @@ class SettingsDialog(QtWidgets.QDialog): self.authenticate_group.show() self.connection_type_socket_file_extras.show() self.connection_type_socks.show() + self.authenticate_group.adjustSize() + self.connection_type_socket_file_extras.adjustSize() + self.connection_type_socks.adjustSize() + self.adjustSize() else: self.connection_type_socket_file_extras.hide() @@ -437,6 +464,8 @@ class SettingsDialog(QtWidgets.QDialog): common.log('SettingsDialog', 'authenticate_password_toggled') if checked: self.authenticate_password_extras.show() + self.authenticate_password_extras.adjustSize() + self.adjustSize() else: self.authenticate_password_extras.hide() @@ -631,7 +660,16 @@ class SettingsDialog(QtWidgets.QDialog): if self.tor_bridges_use_custom_radio.isChecked(): settings.set('no_bridges', False) settings.set('tor_bridges_use_obfs4', False) - settings.set('tor_bridges_use_custom_bridges', self.tor_bridges_use_custom_textbox.toPlainText()) + # Insert a 'Bridge' line at the start of each bridge. + # This makes it easier to copy/paste a set of bridges + # provided from https://bridges.torproject.org + new_bridges = [] + bridges = self.tor_bridges_use_custom_textbox.toPlainText().split('\n') + for bridge in bridges: + if bridge != '': + new_bridges.append(''.join(['Bridge ', bridge, '\n'])) + new_bridges = ''.join(new_bridges) + settings.set('tor_bridges_use_custom_bridges', new_bridges) return settings diff --git a/share/locale/en.json b/share/locale/en.json index f853295c..6e3afe94 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -94,6 +94,7 @@ "gui_settings_tor_bridges_no_bridges_radio_option": "Don't use bridges", "gui_settings_tor_bridges_obfs4_radio_option": "Use obfs4 pluggable transports", "gui_settings_tor_bridges_custom_radio_option": "Use custom bridges", + "gui_settings_tor_bridges_custom_label": "You can obtain bridges from https://bridges.torproject.org", "gui_settings_button_save": "Save", "gui_settings_button_cancel": "Cancel", "gui_settings_button_help": "Help",