From d28f38b1a03a98de2a79ce750672255cacde36fa Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 14:45:21 -0700 Subject: [PATCH 01/17] Add locale to Settings, and make it default to the system locale, or English --- onionshare/settings.py | 17 ++++++++++++++++- tests/test_onionshare_settings.py | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index adcfc7a3..d231a976 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -21,6 +21,7 @@ along with this program. If not, see . import json import os import platform +import locale from . import strings @@ -47,6 +48,12 @@ class Settings(object): else: self.common.log('Settings', '__init__', 'Supplied config does not exist or is unreadable. Falling back to default location') + # Available languages in this version of OnionShare + self.available_locales = [ + 'cs', 'da', 'de', 'en', 'eo', 'es', 'fi', + 'fr', 'it', 'nl', 'no', 'pt', 'ru', 'tr' + ] + # These are the default settings. They will get overwritten when loading from disk self.default_settings = { 'version': self.common.version, @@ -74,7 +81,8 @@ class Settings(object): 'slug': '', 'hidservauth_string': '', 'downloads_dir': self.build_default_downloads_dir(), - 'receive_allow_receiver_shutdown': True + 'receive_allow_receiver_shutdown': True, + 'locale': None # this gets defined in fill_in_defaults() } self._settings = {} self.fill_in_defaults() @@ -88,6 +96,13 @@ class Settings(object): if key not in self._settings: self._settings[key] = self.default_settings[key] + # Choose the default locale based on the OS preference, and fall-back to English + if self._settings['locale'] is None: + default_locale = locale.getdefaultlocale()[0][:2] + if default_locale not in self.available_locales: + default_locale = 'en' + self._settings['locale'] = default_locale + def build_filename(self): """ Returns the path of the settings file. diff --git a/tests/test_onionshare_settings.py b/tests/test_onionshare_settings.py index 1f1ef528..371b2d27 100644 --- a/tests/test_onionshare_settings.py +++ b/tests/test_onionshare_settings.py @@ -40,7 +40,7 @@ def settings_obj(sys_onionshare_dev_mode, platform_linux): class TestSettings: def test_init(self, settings_obj): - assert settings_obj._settings == settings_obj.default_settings == { + expected_settings = { 'version': 'DUMMY_VERSION_1.2.3', 'connection_type': 'bundled', 'control_port_address': '127.0.0.1', @@ -68,6 +68,11 @@ class TestSettings: 'receive_allow_receiver_shutdown': True, 'public_mode': False } + for key in settings_obj._settings: + # Skip locale, it will not always default to the same thing + if key != 'locale': + assert settings_obj._settings[key] == settings_obj.default_settings[key] + assert settings_obj._settings[key] == expected_settings[key] def test_fill_in_defaults(self, settings_obj): del settings_obj._settings['version'] From 64a44284654badbba5296451cf91bff8e050ad94 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 15:01:02 -0700 Subject: [PATCH 02/17] Make Settings.available_locales be a dictionary mapping locale codes to language names in that language --- onionshare/settings.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index d231a976..d3788739 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -48,11 +48,25 @@ class Settings(object): else: self.common.log('Settings', '__init__', 'Supplied config does not exist or is unreadable. Falling back to default location') - # Available languages in this version of OnionShare - self.available_locales = [ - 'cs', 'da', 'de', 'en', 'eo', 'es', 'fi', - 'fr', 'it', 'nl', 'no', 'pt', 'ru', 'tr' - ] + # Dictionary of available languages in this version of OnionShare, + # mapped to the language name, in that language. + # TODO: Update language names to not be in English + self.available_locales = { + 'cs': 'Croatian', + 'da': 'Danish', + 'de': 'German', + 'en': 'English', + 'eo': 'Esperanto', + 'es': 'Spanish', + 'fi': 'Finnish', + 'fr': 'French', + 'it': 'Italian', + 'nl': 'Dutch', + 'no': 'Norweigan', + 'pt': 'Portuguese', + 'ru': 'Russian', + 'tr': 'Turkish' + } # These are the default settings. They will get overwritten when loading from disk self.default_settings = { From 9a19a7aecd41e266ea917cbd039dc11162841c24 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 16:14:14 -0700 Subject: [PATCH 03/17] Allow switching locales from the settings dialog --- onionshare_gui/settings_dialog.py | 27 +++++++++++++++++++++++++++ share/locale/en.json | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 3cd25d31..5966b954 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -227,6 +227,22 @@ class SettingsDialog(QtWidgets.QDialog): if self.system != 'Windows' and self.system != 'Darwin': autoupdate_group.hide() + # Language settings + + # Populate the dropdown with all of OnionShare's available languages + self.language_combobox = QtWidgets.QComboBox() + language_names_to_locales = {v: k for k, v in self.common.settings.available_locales.items()} + language_names = list(language_names_to_locales) + language_names.sort() + for language_name in language_names: + locale = language_names_to_locales[language_name] + self.language_combobox.addItem(language_name, QtCore.QVariant(locale)) + + language_layout = QtWidgets.QVBoxLayout() + language_layout.addWidget(self.language_combobox) + language_group = QtWidgets.QGroupBox(strings._("gui_settings_language_label", True)) + language_group.setLayout(language_layout) + # Connection type: either automatic, control port, or socket file # Bundled Tor @@ -431,6 +447,7 @@ class SettingsDialog(QtWidgets.QDialog): left_col_layout.addWidget(sharing_group) left_col_layout.addWidget(receiving_group) left_col_layout.addWidget(autoupdate_group) + left_col_layout.addWidget(language_group) left_col_layout.addStretch() right_col_layout = QtWidgets.QVBoxLayout() @@ -524,6 +541,10 @@ class SettingsDialog(QtWidgets.QDialog): autoupdate_timestamp = self.old_settings.get('autoupdate_timestamp') self._update_autoupdate_timestamp(autoupdate_timestamp) + locale = self.old_settings.get('locale') + locale_index = self.language_combobox.findData(QtCore.QVariant(locale)) + self.language_combobox.setCurrentIndex(locale_index) + connection_type = self.old_settings.get('connection_type') if connection_type == 'bundled': if self.connection_type_bundled_radio.isEnabled(): @@ -936,6 +957,12 @@ class SettingsDialog(QtWidgets.QDialog): if not self.stealth_checkbox.isChecked(): settings.set('hidservauth_string', '') + # Language + locale_index = self.language_combobox.currentIndex() + locale = self.language_combobox.itemData(locale_index) + settings.set('locale', locale) + + # Tor connection if self.connection_type_bundled_radio.isChecked(): settings.set('connection_type', 'bundled') if self.connection_type_automatic_radio.isChecked(): diff --git a/share/locale/en.json b/share/locale/en.json index 0f0f0cf4..903f8945 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -180,5 +180,6 @@ "gui_upload_in_progress": "Upload Started {}", "gui_upload_finished_range": "Uploaded {} to {}", "gui_upload_finished": "Uploaded {}", - "gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}" + "gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}", + "gui_settings_language_label": "Select language" } From 9d5f9d18edcc082e24b9d59783b088d16e5dfc37 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 16:18:40 -0700 Subject: [PATCH 04/17] Translate language names to their own language --- onionshare/settings.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index d3788739..1fbda807 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -49,23 +49,22 @@ class Settings(object): self.common.log('Settings', '__init__', 'Supplied config does not exist or is unreadable. Falling back to default location') # Dictionary of available languages in this version of OnionShare, - # mapped to the language name, in that language. - # TODO: Update language names to not be in English + # mapped to the language name, in that language self.available_locales = { - 'cs': 'Croatian', - 'da': 'Danish', - 'de': 'German', - 'en': 'English', - 'eo': 'Esperanto', - 'es': 'Spanish', - 'fi': 'Finnish', - 'fr': 'French', - 'it': 'Italian', - 'nl': 'Dutch', - 'no': 'Norweigan', - 'pt': 'Portuguese', - 'ru': 'Russian', - 'tr': 'Turkish' + 'cs': 'Hrvatski', # Croatian + 'da': 'Dansk', # Danish + 'de': 'Deutsch', # German + 'en': 'English', # English + 'eo': 'Esperanto', # Esperanto + 'es': 'Español', # Spanish + 'fi': 'Suomi', # Finnish + 'fr': 'Français', # French + 'it': 'Italiano', # Italian + 'nl': 'Nederlands', # Dutch + 'no': 'Norsk', # Norweigan + 'pt': 'Português', # Portuguese + 'ru': 'Русский', # Russian + 'tr': 'Türkçe' # Turkish } # These are the default settings. They will get overwritten when loading from disk From 23c55bc95b2c99a6efad03f0c6c0fda91c18cf26 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 16:23:46 -0700 Subject: [PATCH 05/17] Change how language selection setting looks --- onionshare_gui/settings_dialog.py | 13 ++++++------- share/locale/en.json | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 5966b954..709ab059 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -228,20 +228,19 @@ class SettingsDialog(QtWidgets.QDialog): autoupdate_group.hide() # Language settings - - # Populate the dropdown with all of OnionShare's available languages + language_label = QtWidgets.QLabel(strings._("gui_settings_language_label", True)) self.language_combobox = QtWidgets.QComboBox() + # Populate the dropdown with all of OnionShare's available languages language_names_to_locales = {v: k for k, v in self.common.settings.available_locales.items()} language_names = list(language_names_to_locales) language_names.sort() for language_name in language_names: locale = language_names_to_locales[language_name] self.language_combobox.addItem(language_name, QtCore.QVariant(locale)) - - language_layout = QtWidgets.QVBoxLayout() + language_layout = QtWidgets.QHBoxLayout() + language_layout.addWidget(language_label) language_layout.addWidget(self.language_combobox) - language_group = QtWidgets.QGroupBox(strings._("gui_settings_language_label", True)) - language_group.setLayout(language_layout) + language_layout.addStretch() # Connection type: either automatic, control port, or socket file @@ -447,7 +446,7 @@ class SettingsDialog(QtWidgets.QDialog): left_col_layout.addWidget(sharing_group) left_col_layout.addWidget(receiving_group) left_col_layout.addWidget(autoupdate_group) - left_col_layout.addWidget(language_group) + left_col_layout.addLayout(language_layout) left_col_layout.addStretch() right_col_layout = QtWidgets.QVBoxLayout() diff --git a/share/locale/en.json b/share/locale/en.json index 903f8945..05830e62 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -181,5 +181,5 @@ "gui_upload_finished_range": "Uploaded {} to {}", "gui_upload_finished": "Uploaded {}", "gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}", - "gui_settings_language_label": "Select language" + "gui_settings_language_label": "Preferred language" } From c4f776c42ada8b6a8c2c8326dc91d3aa87670675 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 17:06:29 -0700 Subject: [PATCH 06/17] Set OnionShare language based on the locale stored in settings, and prompt user to restart OnionShare after changing their language --- onionshare/__init__.py | 9 +++++-- onionshare/strings.py | 39 ++++++++++++++----------------- onionshare_gui/__init__.py | 4 ++++ onionshare_gui/onionshare_gui.py | 5 ++-- onionshare_gui/settings_dialog.py | 30 +++++++++++++++++------- share/locale/en.json | 3 ++- 6 files changed, 55 insertions(+), 35 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 715c5571..2f0ef14c 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -33,7 +33,11 @@ def main(cwd=None): """ common = Common() + # Load settings right away, in order to get locale setting for strings + common.load_settings(config) strings.load_strings(common) + + # Display OnionShare banner print(strings._('version_string').format(common.version)) # OnionShare CLI in OSX needs to change current working directory (#132) @@ -88,8 +92,9 @@ def main(cwd=None): if not valid: sys.exit() - # Load settings - common.load_settings(config) + # Re-load settings, if a custom config was passed in + if config: + common.load_settings(config) # Debug mode? common.debug = debug diff --git a/onionshare/strings.py b/onionshare/strings.py index 3e9df56d..edae7849 100644 --- a/onionshare/strings.py +++ b/onionshare/strings.py @@ -22,36 +22,33 @@ import locale import os strings = {} +translations = {} -def load_strings(common, default="en"): +def load_strings(common): """ Loads translated strings and fallback to English if the translation does not exist. """ - global strings + global strings, translations - # find locale dir - locale_dir = common.get_resource_path('locale') - - # load all translations + # Load all translations translations = {} - for filename in os.listdir(locale_dir): - abs_filename = os.path.join(locale_dir, filename) - lang, ext = os.path.splitext(filename) - if ext == '.json': - with open(abs_filename, encoding='utf-8') as f: - translations[lang] = json.load(f) + for locale in common.settings.available_locales: + locale_dir = common.get_resource_path('locale') + filename = os.path.join(locale_dir, "{}.json".format(locale)) + with open(filename, encoding='utf-8') as f: + translations[locale] = json.load(f) - strings = translations[default] - lc, enc = locale.getdefaultlocale() - if lc: - lang = lc[:2] - if lang in translations: - # if a string doesn't exist, fallback to English - for key in translations[default]: - if key in translations[lang]: - strings[key] = translations[lang][key] + # Build strings + default_locale = 'en' + current_locale = common.settings.get('locale') + strings = {} + for s in translations[default_locale]: + if s in translations[current_locale]: + strings[s] = translations[current_locale][s] + else: + strings[s] = translations[default_locale][s] def translated(k, gui=False): diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 99db635a..51565cb6 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -59,7 +59,11 @@ def main(): common = Common() common.define_css() + # Load settings right away, in order to get locale setting for strings + common.load_settings() strings.load_strings(common) + + # Display OnionShare banner print(strings._('version_string').format(common.version)) # Allow Ctrl-C to smoothly quit the program instead of throwing an exception diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 83f3a7e0..b3d6afef 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -57,9 +57,10 @@ class OnionShareGui(QtWidgets.QMainWindow): self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png'))) self.setMinimumWidth(850) - # Load settings + # Load settings, if a custom config was passed in self.config = config - self.common.load_settings(self.config) + if self.config: + self.common.load_settings(self.config) # System tray menu = QtWidgets.QMenu() diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 709ab059..7aff85a5 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -830,8 +830,29 @@ class SettingsDialog(QtWidgets.QDialog): """ self.common.log('SettingsDialog', 'save_clicked') + def changed(s1, s2, keys): + """ + Compare the Settings objects s1 and s2 and return true if any values + have changed for the given keys. + """ + for key in keys: + if s1.get(key) != s2.get(key): + return True + return False + settings = self.settings_from_fields() if settings: + # If language changed, inform user they need to restart OnionShare + if changed(settings, self.old_settings, ['locale']): + # Look up error message in different locale + new_locale = settings.get('locale') + if new_locale in strings.translations and 'gui_settings_language_changed_notice' in strings.translations[new_locale]: + notice = strings.translations[new_locale]['gui_settings_language_changed_notice'] + else: + notice = strings._('gui_settings_language_changed_notice') + Alert(self.common, notice, QtWidgets.QMessageBox.Information) + + # Save the new settings settings.save() # If Tor isn't connected, or if Tor settings have changed, Reinitialize @@ -840,15 +861,6 @@ class SettingsDialog(QtWidgets.QDialog): if not self.local_only: if self.onion.is_authenticated(): self.common.log('SettingsDialog', 'save_clicked', 'Connected to Tor') - def changed(s1, s2, keys): - """ - Compare the Settings objects s1 and s2 and return true if any values - have changed for the given keys. - """ - for key in keys: - if s1.get(key) != s2.get(key): - return True - return False if changed(settings, self.old_settings, [ 'connection_type', 'control_port_address', diff --git a/share/locale/en.json b/share/locale/en.json index 05830e62..02577f0d 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -181,5 +181,6 @@ "gui_upload_finished_range": "Uploaded {} to {}", "gui_upload_finished": "Uploaded {}", "gui_open_folder_error_nautilus": "Cannot open folder because nautilus is not available. The file is here: {}", - "gui_settings_language_label": "Preferred language" + "gui_settings_language_label": "Preferred language", + "gui_settings_language_changed_notice": "Restart OnionShare for your change in language to take effect." } From 60afaaf338d2c49ffd93a605a90bb645cf37955a Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 17:18:56 -0700 Subject: [PATCH 07/17] Make printing the settings filename as debug statement instead of print --- onionshare/settings.py | 2 +- share/locale/en.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index 1fbda807..811ad032 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -164,7 +164,7 @@ class Settings(object): except: pass open(self.filename, 'w').write(json.dumps(self._settings)) - print(strings._('settings_saved').format(self.filename)) + self.common.log('Settings', 'save', 'Settings saved in {}'.format(self.filename)) def get(self, key): return self._settings[key] diff --git a/share/locale/en.json b/share/locale/en.json index 02577f0d..f5d887b5 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -106,7 +106,6 @@ "gui_settings_button_help": "Help", "gui_settings_shutdown_timeout_checkbox": "Use auto-stop timer", "gui_settings_shutdown_timeout": "Stop the share at:", - "settings_saved": "Settings saved in {}", "settings_error_unknown": "Can't connect to Tor controller because your settings don't make sense.", "settings_error_automatic": "Could not connect to the Tor controller. Is Tor Browser (available from torproject.org) running in the background?", "settings_error_socket_port": "Can't connect to the Tor controller at {}:{}.", From c572ab996a54d41c26d3e5ce99d5b38ebc406323 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 17:35:58 -0700 Subject: [PATCH 08/17] Fix tests --- onionshare/settings.py | 9 +++++++-- tests/conftest.py | 7 +++++-- tests/test_onionshare_strings.py | 12 ++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/onionshare/settings.py b/onionshare/settings.py index 811ad032..ed827cbd 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -122,8 +122,13 @@ class Settings(object): """ p = platform.system() if p == 'Windows': - appdata = os.environ['APPDATA'] - return '{}\\OnionShare\\onionshare.json'.format(appdata) + try: + appdata = os.environ['APPDATA'] + return '{}\\OnionShare\\onionshare.json'.format(appdata) + except: + # If for some reason we don't have the 'APPDATA' environment variable + # (like running tests in Linux while pretending to be in Windows) + return os.path.expanduser('~/.config/onionshare/onionshare.json') elif p == 'Darwin': return os.path.expanduser('~/Library/Application Support/OnionShare/onionshare.json') else: diff --git a/tests/conftest.py b/tests/conftest.py index 8ac7efb8..3ae6fd52 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ import tempfile import pytest -from onionshare import common, web, settings +from onionshare import common, web, settings, strings @pytest.fixture def temp_dir_1024(): @@ -151,7 +151,10 @@ def time_strftime(monkeypatch): @pytest.fixture def common_obj(): - return common.Common() + _common = common.Common() + _common.settings = settings.Settings(_common) + strings.load_strings(_common) + return _common @pytest.fixture def settings_obj(sys_onionshare_dev_mode, platform_linux): diff --git a/tests/test_onionshare_strings.py b/tests/test_onionshare_strings.py index d3d40c8f..6d39598c 100644 --- a/tests/test_onionshare_strings.py +++ b/tests/test_onionshare_strings.py @@ -32,12 +32,6 @@ from onionshare import strings # return path # common.get_resource_path = get_resource_path - -def test_starts_with_empty_strings(): - """ Creates an empty strings dict by default """ - assert strings.strings == {} - - def test_underscore_is_function(): assert callable(strings._) and isinstance(strings._, types.FunctionType) @@ -53,11 +47,13 @@ class TestLoadStrings: def test_load_strings_loads_other_languages( self, common_obj, locale_fr, sys_onionshare_dev_mode): """ load_strings() loads other languages in different locales """ - strings.load_strings(common_obj, "fr") + common_obj.settings.set('locale', 'fr') + strings.load_strings(common_obj) assert strings._('preparing_files') == "Préparation des fichiers à partager." def test_load_invalid_locale( self, common_obj, locale_invalid, sys_onionshare_dev_mode): """ load_strings() raises a KeyError for an invalid locale """ with pytest.raises(KeyError): - strings.load_strings(common_obj, 'XX') + common_obj.settings.set('locale', 'XX') + strings.load_strings(common_obj) From a1f5b5964a71b2c815347bc5c88c2849e8aac675 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 17:47:10 -0700 Subject: [PATCH 09/17] Remove the useless gui=True arg getting passed intro strings._ all over the place --- onionshare/onion.py | 2 +- onionshare/strings.py | 2 +- onionshare_gui/__init__.py | 4 +- onionshare_gui/onionshare_gui.py | 50 ++++---- onionshare_gui/receive_mode/__init__.py | 14 +- onionshare_gui/receive_mode/uploads.py | 16 +-- onionshare_gui/server_status.py | 30 ++--- onionshare_gui/settings_dialog.py | 134 ++++++++++---------- onionshare_gui/share_mode/__init__.py | 26 ++-- onionshare_gui/share_mode/downloads.py | 8 +- onionshare_gui/share_mode/file_selection.py | 12 +- onionshare_gui/tor_connection_dialog.py | 6 +- 12 files changed, 152 insertions(+), 152 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index c45ae72e..cb73e976 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -247,7 +247,7 @@ class Onion(object): self.c = Controller.from_socket_file(path=self.tor_control_socket) self.c.authenticate() except Exception as e: - raise BundledTorBroken(strings._('settings_error_bundled_tor_broken', True).format(e.args[0])) + raise BundledTorBroken(strings._('settings_error_bundled_tor_broken').format(e.args[0])) while True: try: diff --git a/onionshare/strings.py b/onionshare/strings.py index edae7849..b730933d 100644 --- a/onionshare/strings.py +++ b/onionshare/strings.py @@ -51,7 +51,7 @@ def load_strings(common): strings[s] = translations[default_locale][s] -def translated(k, gui=False): +def translated(k): """ Returns a translated string. """ diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 51565cb6..b5520071 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -100,10 +100,10 @@ def main(): valid = True for filename in filenames: if not os.path.isfile(filename) and not os.path.isdir(filename): - Alert(common, strings._("not_a_file", True).format(filename)) + Alert(common, strings._("not_a_file").format(filename)) valid = False if not os.access(filename, os.R_OK): - Alert(common, strings._("not_a_readable_file", True).format(filename)) + Alert(common, strings._("not_a_readable_file").format(filename)) valid = False if not valid: sys.exit() diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index b3d6afef..1b3a62a2 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -64,11 +64,11 @@ class OnionShareGui(QtWidgets.QMainWindow): # System tray menu = QtWidgets.QMenu() - self.settings_action = menu.addAction(strings._('gui_settings_window_title', True)) + self.settings_action = menu.addAction(strings._('gui_settings_window_title')) self.settings_action.triggered.connect(self.open_settings) - help_action = menu.addAction(strings._('gui_settings_button_help', True)) + help_action = menu.addAction(strings._('gui_settings_button_help')) help_action.triggered.connect(SettingsDialog.help_clicked) - exit_action = menu.addAction(strings._('systray_menu_exit', True)) + exit_action = menu.addAction(strings._('systray_menu_exit')) exit_action.triggered.connect(self.close) self.system_tray = QtWidgets.QSystemTrayIcon(self) @@ -81,10 +81,10 @@ class OnionShareGui(QtWidgets.QMainWindow): self.system_tray.show() # Mode switcher, to switch between share files and receive files - self.share_mode_button = QtWidgets.QPushButton(strings._('gui_mode_share_button', True)); + self.share_mode_button = QtWidgets.QPushButton(strings._('gui_mode_share_button')); self.share_mode_button.setFixedHeight(50) self.share_mode_button.clicked.connect(self.share_mode_clicked) - self.receive_mode_button = QtWidgets.QPushButton(strings._('gui_mode_receive_button', True)); + self.receive_mode_button = QtWidgets.QPushButton(strings._('gui_mode_receive_button')); self.receive_mode_button.setFixedHeight(50) self.receive_mode_button.clicked.connect(self.receive_mode_clicked) self.settings_button = QtWidgets.QPushButton() @@ -224,24 +224,24 @@ class OnionShareGui(QtWidgets.QMainWindow): # Share mode if self.share_mode.server_status.status == ServerStatus.STATUS_STOPPED: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped)) - self.server_status_label.setText(strings._('gui_status_indicator_share_stopped', True)) + self.server_status_label.setText(strings._('gui_status_indicator_share_stopped')) elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working)) - self.server_status_label.setText(strings._('gui_status_indicator_share_working', True)) + self.server_status_label.setText(strings._('gui_status_indicator_share_working')) elif self.share_mode.server_status.status == ServerStatus.STATUS_STARTED: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started)) - self.server_status_label.setText(strings._('gui_status_indicator_share_started', True)) + self.server_status_label.setText(strings._('gui_status_indicator_share_started')) else: # Receive mode if self.receive_mode.server_status.status == ServerStatus.STATUS_STOPPED: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_stopped)) - self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped', True)) + self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped')) elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working)) - self.server_status_label.setText(strings._('gui_status_indicator_receive_working', True)) + self.server_status_label.setText(strings._('gui_status_indicator_receive_working')) elif self.receive_mode.server_status.status == ServerStatus.STATUS_STARTED: self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_started)) - self.server_status_label.setText(strings._('gui_status_indicator_receive_started', True)) + self.server_status_label.setText(strings._('gui_status_indicator_receive_started')) def stop_server_finished(self): # When the server stopped, cleanup the ephemeral onion service @@ -255,9 +255,9 @@ class OnionShareGui(QtWidgets.QMainWindow): self.common.log('OnionShareGui', '_tor_connection_canceled') def ask(): - a = Alert(self.common, strings._('gui_tor_connection_ask', True), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False) - settings_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_open_settings', True)) - quit_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_quit', True)) + a = Alert(self.common, strings._('gui_tor_connection_ask'), QtWidgets.QMessageBox.Question, buttons=QtWidgets.QMessageBox.NoButton, autostart=False) + settings_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_open_settings')) + quit_button = QtWidgets.QPushButton(strings._('gui_tor_connection_ask_quit')) a.addButton(settings_button, QtWidgets.QMessageBox.AcceptRole) a.addButton(quit_button, QtWidgets.QMessageBox.RejectRole) a.setDefaultButton(settings_button) @@ -328,7 +328,7 @@ class OnionShareGui(QtWidgets.QMainWindow): if self.common.platform == 'Windows' or self.common.platform == 'Darwin': if self.common.settings.get('use_autoupdate'): def update_available(update_url, installed_version, latest_version): - Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version)) + Alert(self.common, strings._("update_available").format(update_url, installed_version, latest_version)) self.update_thread = UpdateThread(self.common, self.onion, self.config) self.update_thread.update_available.connect(update_available) @@ -345,8 +345,8 @@ class OnionShareGui(QtWidgets.QMainWindow): # Have we lost connection to Tor somehow? if not self.onion.is_authenticated(): self.timer.stop() - self.status_bar.showMessage(strings._('gui_tor_connection_lost', True)) - self.system_tray.showMessage(strings._('gui_tor_connection_lost', True), strings._('gui_tor_connection_error_settings', True)) + self.status_bar.showMessage(strings._('gui_tor_connection_lost')) + self.system_tray.showMessage(strings._('gui_tor_connection_lost'), strings._('gui_tor_connection_error_settings')) self.share_mode.handle_tor_broke() self.receive_mode.handle_tor_broke() @@ -400,7 +400,7 @@ class OnionShareGui(QtWidgets.QMainWindow): if event["type"] == Web.REQUEST_OTHER: if event["path"] != '/favicon.ico' and event["path"] != "/{}/shutdown".format(mode.web.shutdown_slug): - self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.error404_count, strings._('other_page_loaded', True), event["path"])) + self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(mode.web.error404_count, strings._('other_page_loaded'), event["path"])) mode.timer_callback() @@ -409,14 +409,14 @@ class OnionShareGui(QtWidgets.QMainWindow): When the URL gets copied to the clipboard, display this in the status bar. """ self.common.log('OnionShareGui', 'copy_url') - self.system_tray.showMessage(strings._('gui_copied_url_title', True), strings._('gui_copied_url', True)) + self.system_tray.showMessage(strings._('gui_copied_url_title'), strings._('gui_copied_url')) def copy_hidservauth(self): """ When the stealth onion service HidServAuth gets copied to the clipboard, display this in the status bar. """ self.common.log('OnionShareGui', 'copy_hidservauth') - self.system_tray.showMessage(strings._('gui_copied_hidservauth_title', True), strings._('gui_copied_hidservauth', True)) + self.system_tray.showMessage(strings._('gui_copied_hidservauth_title'), strings._('gui_copied_hidservauth')) def clear_message(self): """ @@ -454,14 +454,14 @@ class OnionShareGui(QtWidgets.QMainWindow): if server_status.status != server_status.STATUS_STOPPED: self.common.log('OnionShareGui', 'closeEvent, opening warning dialog') dialog = QtWidgets.QMessageBox() - dialog.setWindowTitle(strings._('gui_quit_title', True)) + dialog.setWindowTitle(strings._('gui_quit_title')) if self.mode == OnionShareGui.MODE_SHARE: - dialog.setText(strings._('gui_share_quit_warning', True)) + dialog.setText(strings._('gui_share_quit_warning')) else: - dialog.setText(strings._('gui_receive_quit_warning', True)) + dialog.setText(strings._('gui_receive_quit_warning')) dialog.setIcon(QtWidgets.QMessageBox.Critical) - quit_button = dialog.addButton(strings._('gui_quit_warning_quit', True), QtWidgets.QMessageBox.YesRole) - dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit', True), QtWidgets.QMessageBox.NoRole) + quit_button = dialog.addButton(strings._('gui_quit_warning_quit'), QtWidgets.QMessageBox.YesRole) + dont_quit_button = dialog.addButton(strings._('gui_quit_warning_dont_quit'), QtWidgets.QMessageBox.NoRole) dialog.setDefaultButton(dont_quit_button) reply = dialog.exec_() diff --git a/onionshare_gui/receive_mode/__init__.py b/onionshare_gui/receive_mode/__init__.py index 590dec65..1207a0f3 100644 --- a/onionshare_gui/receive_mode/__init__.py +++ b/onionshare_gui/receive_mode/__init__.py @@ -72,7 +72,7 @@ class ReceiveMode(Mode): self.info_widget.hide() # Receive mode info - self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True)) + self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning')) self.receive_info.setMinimumHeight(80) self.receive_info.setWordWrap(True) @@ -86,7 +86,7 @@ class ReceiveMode(Mode): """ Return the string to put on the stop server button, if there's a shutdown timeout """ - return strings._('gui_receive_stop_server_shutdown_timeout', True) + return strings._('gui_receive_stop_server_shutdown_timeout') def timeout_finished_should_stop_server(self): """ @@ -125,7 +125,7 @@ class ReceiveMode(Mode): """ Handle REQUEST_LOAD event. """ - self.system_tray.showMessage(strings._('systray_page_loaded_title', True), strings._('systray_upload_page_loaded_message', True)) + self.system_tray.showMessage(strings._('systray_page_loaded_title'), strings._('systray_upload_page_loaded_message')) def handle_request_started(self, event): """ @@ -135,7 +135,7 @@ class ReceiveMode(Mode): self.uploads_in_progress += 1 self.update_uploads_in_progress() - self.system_tray.showMessage(strings._('systray_upload_started_title', True), strings._('systray_upload_started_message', True)) + self.system_tray.showMessage(strings._('systray_upload_started_title'), strings._('systray_upload_started_message')) def handle_request_progress(self, event): """ @@ -148,7 +148,7 @@ class ReceiveMode(Mode): Handle REQUEST_CLOSE_SERVER event. """ self.stop_server() - self.system_tray.showMessage(strings._('systray_close_server_title', True), strings._('systray_close_server_message', True)) + self.system_tray.showMessage(strings._('systray_close_server_title'), strings._('systray_close_server_message')) def handle_request_upload_file_renamed(self, event): """ @@ -194,7 +194,7 @@ class ReceiveMode(Mode): else: image = self.common.get_resource_path('images/share_completed.png') self.info_completed_uploads_count.setText(' {1:d}'.format(image, self.uploads_completed)) - self.info_completed_uploads_count.setToolTip(strings._('info_completed_uploads_tooltip', True).format(self.uploads_completed)) + self.info_completed_uploads_count.setToolTip(strings._('info_completed_uploads_tooltip').format(self.uploads_completed)) def update_uploads_in_progress(self): """ @@ -205,7 +205,7 @@ class ReceiveMode(Mode): else: image = self.common.get_resource_path('images/share_in_progress.png') self.info_in_progress_uploads_count.setText(' {1:d}'.format(image, self.uploads_in_progress)) - self.info_in_progress_uploads_count.setToolTip(strings._('info_in_progress_uploads_tooltip', True).format(self.uploads_in_progress)) + self.info_in_progress_uploads_count.setToolTip(strings._('info_in_progress_uploads_tooltip').format(self.uploads_in_progress)) def update_primary_action(self): self.common.log('ReceiveMode', 'update_primary_action') diff --git a/onionshare_gui/receive_mode/uploads.py b/onionshare_gui/receive_mode/uploads.py index 48574cc7..33d993b3 100644 --- a/onionshare_gui/receive_mode/uploads.py +++ b/onionshare_gui/receive_mode/uploads.py @@ -113,7 +113,7 @@ class Upload(QtWidgets.QWidget): self.started = datetime.now() # Label - self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress', True).format(self.started.strftime("%b %d, %I:%M%p"))) + self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress').format(self.started.strftime("%b %d, %I:%M%p"))) # Progress bar self.progress_bar = QtWidgets.QProgressBar() @@ -190,16 +190,16 @@ class Upload(QtWidgets.QWidget): self.ended = self.started = datetime.now() if self.started.year == self.ended.year and self.started.month == self.ended.month and self.started.day == self.ended.day: if self.started.hour == self.ended.hour and self.started.minute == self.ended.minute: - text = strings._('gui_upload_finished', True).format( + text = strings._('gui_upload_finished').format( self.started.strftime("%b %d, %I:%M%p") ) else: - text = strings._('gui_upload_finished_range', True).format( + text = strings._('gui_upload_finished_range').format( self.started.strftime("%b %d, %I:%M%p"), self.ended.strftime("%I:%M%p") ) else: - text = strings._('gui_upload_finished_range', True).format( + text = strings._('gui_upload_finished_range').format( self.started.strftime("%b %d, %I:%M%p"), self.ended.strftime("%b %d, %I:%M%p") ) @@ -220,7 +220,7 @@ class Uploads(QtWidgets.QScrollArea): self.uploads = {} - self.setWindowTitle(strings._('gui_uploads', True)) + self.setWindowTitle(strings._('gui_uploads')) self.setWidgetResizable(True) self.setMinimumHeight(150) self.setMinimumWidth(350) @@ -229,10 +229,10 @@ class Uploads(QtWidgets.QScrollArea): self.vbar = self.verticalScrollBar() self.vbar.rangeChanged.connect(self.resizeScroll) - uploads_label = QtWidgets.QLabel(strings._('gui_uploads', True)) + uploads_label = QtWidgets.QLabel(strings._('gui_uploads')) uploads_label.setStyleSheet(self.common.css['downloads_uploads_label']) - self.no_uploads_label = QtWidgets.QLabel(strings._('gui_no_uploads', True)) - self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history', True)) + self.no_uploads_label = QtWidgets.QLabel(strings._('gui_no_uploads')) + self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history')) self.clear_history_button.clicked.connect(self.reset) self.clear_history_button.hide() diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 32135ca4..f1ffe995 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -61,7 +61,7 @@ class ServerStatus(QtWidgets.QWidget): self.resizeEvent(None) # Shutdown timeout layout - self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True)) + self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout')) self.shutdown_timeout = QtWidgets.QDateTimeEdit() self.shutdown_timeout.setDisplayFormat("hh:mm A MMM d, yy") if self.local_only: @@ -101,11 +101,11 @@ class ServerStatus(QtWidgets.QWidget): self.url.setMinimumSize(self.url.sizeHint()) self.url.setStyleSheet(self.common.css['server_status_url']) - self.copy_url_button = QtWidgets.QPushButton(strings._('gui_copy_url', True)) + self.copy_url_button = QtWidgets.QPushButton(strings._('gui_copy_url')) self.copy_url_button.setFlat(True) self.copy_url_button.setStyleSheet(self.common.css['server_status_url_buttons']) self.copy_url_button.clicked.connect(self.copy_url) - self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True)) + self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth')) self.copy_hidservauth_button.setFlat(True) self.copy_hidservauth_button.setStyleSheet(self.common.css['server_status_url_buttons']) self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth) @@ -174,21 +174,21 @@ class ServerStatus(QtWidgets.QWidget): info_image = self.common.get_resource_path('images/info.png') if self.mode == ServerStatus.MODE_SHARE: - self.url_description.setText(strings._('gui_share_url_description', True).format(info_image)) + self.url_description.setText(strings._('gui_share_url_description').format(info_image)) else: - self.url_description.setText(strings._('gui_receive_url_description', True).format(info_image)) + self.url_description.setText(strings._('gui_receive_url_description').format(info_image)) # Show a Tool Tip explaining the lifecycle of this URL if self.common.settings.get('save_private_key'): if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get('close_after_first_download'): - self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent', True)) + self.url_description.setToolTip(strings._('gui_url_label_onetime_and_persistent')) else: - self.url_description.setToolTip(strings._('gui_url_label_persistent', True)) + self.url_description.setToolTip(strings._('gui_url_label_persistent')) else: if self.mode == ServerStatus.MODE_SHARE and self.common.settings.get('close_after_first_download'): - self.url_description.setToolTip(strings._('gui_url_label_onetime', True)) + self.url_description.setToolTip(strings._('gui_url_label_onetime')) else: - self.url_description.setToolTip(strings._('gui_url_label_stay_open', True)) + self.url_description.setToolTip(strings._('gui_url_label_stay_open')) self.url.setText(self.get_url()) self.url.show() @@ -223,9 +223,9 @@ class ServerStatus(QtWidgets.QWidget): self.server_button.setStyleSheet(self.common.css['server_status_button_stopped']) self.server_button.setEnabled(True) if self.mode == ServerStatus.MODE_SHARE: - self.server_button.setText(strings._('gui_share_start_server', True)) + self.server_button.setText(strings._('gui_share_start_server')) else: - self.server_button.setText(strings._('gui_receive_start_server', True)) + self.server_button.setText(strings._('gui_receive_start_server')) self.server_button.setToolTip('') if self.common.settings.get('shutdown_timeout'): self.shutdown_timeout_container.show() @@ -233,15 +233,15 @@ class ServerStatus(QtWidgets.QWidget): self.server_button.setStyleSheet(self.common.css['server_status_button_started']) self.server_button.setEnabled(True) if self.mode == ServerStatus.MODE_SHARE: - self.server_button.setText(strings._('gui_share_stop_server', True)) + self.server_button.setText(strings._('gui_share_stop_server')) else: - self.server_button.setText(strings._('gui_receive_stop_server', True)) + self.server_button.setText(strings._('gui_receive_stop_server')) if self.common.settings.get('shutdown_timeout'): self.shutdown_timeout_container.hide() if self.mode == ServerStatus.MODE_SHARE: - self.server_button.setToolTip(strings._('gui_share_stop_server_shutdown_timeout_tooltip', True).format(self.timeout)) + self.server_button.setToolTip(strings._('gui_share_stop_server_shutdown_timeout_tooltip').format(self.timeout)) else: - self.server_button.setToolTip(strings._('gui_receive_stop_server_shutdown_timeout_tooltip', True).format(self.timeout)) + self.server_button.setToolTip(strings._('gui_receive_stop_server_shutdown_timeout_tooltip').format(self.timeout)) elif self.status == self.STATUS_WORKING: self.server_button.setStyleSheet(self.common.css['server_status_button_working']) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 7aff85a5..b9e0453a 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -47,7 +47,7 @@ class SettingsDialog(QtWidgets.QDialog): self.local_only = local_only self.setModal(True) - self.setWindowTitle(strings._('gui_settings_window_title', True)) + self.setWindowTitle(strings._('gui_settings_window_title')) self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png'))) self.system = platform.system() @@ -57,8 +57,8 @@ class SettingsDialog(QtWidgets.QDialog): # Use a slug or not ('public mode') self.public_mode_checkbox = QtWidgets.QCheckBox() self.public_mode_checkbox.setCheckState(QtCore.Qt.Unchecked) - self.public_mode_checkbox.setText(strings._("gui_settings_public_mode_checkbox", True)) - public_mode_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Public-Mode")) + self.public_mode_checkbox.setText(strings._("gui_settings_public_mode_checkbox")) + public_mode_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Public-Mode")) public_mode_label.setStyleSheet(self.common.css['settings_whats_this']) public_mode_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) public_mode_label.setOpenExternalLinks(True) @@ -74,8 +74,8 @@ class SettingsDialog(QtWidgets.QDialog): # Whether or not to use a shutdown ('auto-stop') timer self.shutdown_timeout_checkbox = QtWidgets.QCheckBox() self.shutdown_timeout_checkbox.setCheckState(QtCore.Qt.Checked) - self.shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_checkbox", True)) - shutdown_timeout_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Using-the-Auto-Stop-Timer")) + self.shutdown_timeout_checkbox.setText(strings._("gui_settings_shutdown_timeout_checkbox")) + shutdown_timeout_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Auto-Stop-Timer")) shutdown_timeout_label.setStyleSheet(self.common.css['settings_whats_this']) shutdown_timeout_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) shutdown_timeout_label.setOpenExternalLinks(True) @@ -91,9 +91,9 @@ class SettingsDialog(QtWidgets.QDialog): # Whether or not to use legacy v2 onions self.use_legacy_v2_onions_checkbox = QtWidgets.QCheckBox() self.use_legacy_v2_onions_checkbox.setCheckState(QtCore.Qt.Unchecked) - self.use_legacy_v2_onions_checkbox.setText(strings._("gui_use_legacy_v2_onions_checkbox", True)) + self.use_legacy_v2_onions_checkbox.setText(strings._("gui_use_legacy_v2_onions_checkbox")) self.use_legacy_v2_onions_checkbox.clicked.connect(self.use_legacy_v2_onions_checkbox_clicked) - use_legacy_v2_onions_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Legacy-Addresses")) + use_legacy_v2_onions_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Legacy-Addresses")) use_legacy_v2_onions_label.setStyleSheet(self.common.css['settings_whats_this']) use_legacy_v2_onions_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) use_legacy_v2_onions_label.setOpenExternalLinks(True) @@ -108,9 +108,9 @@ class SettingsDialog(QtWidgets.QDialog): # Whether or not to save the Onion private key for reuse (persistent URL mode) self.save_private_key_checkbox = QtWidgets.QCheckBox() self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked) - self.save_private_key_checkbox.setText(strings._("gui_save_private_key_checkbox", True)) + self.save_private_key_checkbox.setText(strings._("gui_save_private_key_checkbox")) self.save_private_key_checkbox.clicked.connect(self.save_private_key_checkbox_clicked) - save_private_key_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Using-a-Persistent-URL")) + save_private_key_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-a-Persistent-URL")) save_private_key_label.setStyleSheet(self.common.css['settings_whats_this']) save_private_key_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) save_private_key_label.setOpenExternalLinks(True) @@ -125,9 +125,9 @@ class SettingsDialog(QtWidgets.QDialog): # Stealth self.stealth_checkbox = QtWidgets.QCheckBox() self.stealth_checkbox.setCheckState(QtCore.Qt.Unchecked) - self.stealth_checkbox.setText(strings._("gui_settings_stealth_option", True)) + self.stealth_checkbox.setText(strings._("gui_settings_stealth_option")) self.stealth_checkbox.clicked.connect(self.stealth_checkbox_clicked_connect) - use_stealth_label = QtWidgets.QLabel(strings._("gui_settings_whats_this", True).format("https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services")) + use_stealth_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Stealth-Onion-Services")) use_stealth_label.setStyleSheet(self.common.css['settings_whats_this']) use_stealth_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) use_stealth_label.setOpenExternalLinks(True) @@ -140,12 +140,12 @@ class SettingsDialog(QtWidgets.QDialog): self.use_stealth_widget = QtWidgets.QWidget() self.use_stealth_widget.setLayout(use_stealth_layout) - hidservauth_details = QtWidgets.QLabel(strings._('gui_settings_stealth_hidservauth_string', True)) + hidservauth_details = QtWidgets.QLabel(strings._('gui_settings_stealth_hidservauth_string')) hidservauth_details.setWordWrap(True) hidservauth_details.setMinimumSize(hidservauth_details.sizeHint()) hidservauth_details.hide() - self.hidservauth_copy_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True)) + self.hidservauth_copy_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth')) self.hidservauth_copy_button.clicked.connect(self.hidservauth_copy_button_clicked) self.hidservauth_copy_button.hide() @@ -159,7 +159,7 @@ class SettingsDialog(QtWidgets.QDialog): general_group_layout.addWidget(hidservauth_details) general_group_layout.addWidget(self.hidservauth_copy_button) - general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label", True)) + general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label")) general_group.setLayout(general_group_layout) # Sharing options @@ -167,19 +167,19 @@ class SettingsDialog(QtWidgets.QDialog): # Close after first download self.close_after_first_download_checkbox = QtWidgets.QCheckBox() self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Checked) - self.close_after_first_download_checkbox.setText(strings._("gui_settings_close_after_first_download_option", True)) + self.close_after_first_download_checkbox.setText(strings._("gui_settings_close_after_first_download_option")) # Sharing options layout sharing_group_layout = QtWidgets.QVBoxLayout() sharing_group_layout.addWidget(self.close_after_first_download_checkbox) - sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label", True)) + sharing_group = QtWidgets.QGroupBox(strings._("gui_settings_sharing_label")) sharing_group.setLayout(sharing_group_layout) # Downloads dir - downloads_label = QtWidgets.QLabel(strings._('gui_settings_downloads_label', True)); + downloads_label = QtWidgets.QLabel(strings._('gui_settings_downloads_label')); self.downloads_dir_lineedit = QtWidgets.QLineEdit() self.downloads_dir_lineedit.setReadOnly(True) - downloads_button = QtWidgets.QPushButton(strings._('gui_settings_downloads_button', True)) + downloads_button = QtWidgets.QPushButton(strings._('gui_settings_downloads_button')) downloads_button.clicked.connect(self.downloads_button_clicked) downloads_layout = QtWidgets.QHBoxLayout() downloads_layout.addWidget(downloads_label) @@ -189,13 +189,13 @@ class SettingsDialog(QtWidgets.QDialog): # Allow the receiver to shutdown the server self.receive_allow_receiver_shutdown_checkbox = QtWidgets.QCheckBox() self.receive_allow_receiver_shutdown_checkbox.setCheckState(QtCore.Qt.Checked) - self.receive_allow_receiver_shutdown_checkbox.setText(strings._("gui_settings_receive_allow_receiver_shutdown_checkbox", True)) + self.receive_allow_receiver_shutdown_checkbox.setText(strings._("gui_settings_receive_allow_receiver_shutdown_checkbox")) # Receiving options layout receiving_group_layout = QtWidgets.QVBoxLayout() receiving_group_layout.addLayout(downloads_layout) receiving_group_layout.addWidget(self.receive_allow_receiver_shutdown_checkbox) - receiving_group = QtWidgets.QGroupBox(strings._("gui_settings_receiving_label", True)) + receiving_group = QtWidgets.QGroupBox(strings._("gui_settings_receiving_label")) receiving_group.setLayout(receiving_group_layout) # Automatic updates options @@ -203,13 +203,13 @@ class SettingsDialog(QtWidgets.QDialog): # Autoupdate self.autoupdate_checkbox = QtWidgets.QCheckBox() self.autoupdate_checkbox.setCheckState(QtCore.Qt.Unchecked) - self.autoupdate_checkbox.setText(strings._("gui_settings_autoupdate_option", True)) + self.autoupdate_checkbox.setText(strings._("gui_settings_autoupdate_option")) # Last update time self.autoupdate_timestamp = QtWidgets.QLabel() # Check for updates button - self.check_for_updates_button = QtWidgets.QPushButton(strings._('gui_settings_autoupdate_check_button', True)) + self.check_for_updates_button = QtWidgets.QPushButton(strings._('gui_settings_autoupdate_check_button')) self.check_for_updates_button.clicked.connect(self.check_for_updates) # We can't check for updates if not connected to Tor if not self.onion.connected_to_tor: @@ -220,7 +220,7 @@ class SettingsDialog(QtWidgets.QDialog): autoupdate_group_layout.addWidget(self.autoupdate_checkbox) autoupdate_group_layout.addWidget(self.autoupdate_timestamp) autoupdate_group_layout.addWidget(self.check_for_updates_button) - autoupdate_group = QtWidgets.QGroupBox(strings._("gui_settings_autoupdate_label", True)) + autoupdate_group = QtWidgets.QGroupBox(strings._("gui_settings_autoupdate_label")) autoupdate_group.setLayout(autoupdate_group_layout) # Autoupdate is only available for Windows and Mac (Linux updates using package manager) @@ -228,7 +228,7 @@ class SettingsDialog(QtWidgets.QDialog): autoupdate_group.hide() # Language settings - language_label = QtWidgets.QLabel(strings._("gui_settings_language_label", True)) + language_label = QtWidgets.QLabel(strings._("gui_settings_language_label")) self.language_combobox = QtWidgets.QComboBox() # Populate the dropdown with all of OnionShare's available languages language_names_to_locales = {v: k for k, v in self.common.settings.available_locales.items()} @@ -245,7 +245,7 @@ class SettingsDialog(QtWidgets.QDialog): # Connection type: either automatic, control port, or socket file # Bundled Tor - self.connection_type_bundled_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_bundled_option', True)) + self.connection_type_bundled_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_bundled_option')) self.connection_type_bundled_radio.toggled.connect(self.connection_type_bundled_toggled) # Bundled Tor doesn't work on dev mode in Windows or Mac @@ -255,27 +255,27 @@ class SettingsDialog(QtWidgets.QDialog): # Bridge options for bundled tor # No bridges option radio - self.tor_bridges_no_bridges_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_no_bridges_radio_option', True)) + self.tor_bridges_no_bridges_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_no_bridges_radio_option')) self.tor_bridges_no_bridges_radio.toggled.connect(self.tor_bridges_no_bridges_radio_toggled) # obfs4 option radio # if the obfs4proxy binary is missing, we can't use obfs4 transports (self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = self.common.get_tor_paths() if not os.path.isfile(self.obfs4proxy_file_path): - self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option_no_obfs4proxy', True)) + self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option_no_obfs4proxy')) self.tor_bridges_use_obfs4_radio.setEnabled(False) else: - self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option', True)) + self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option')) self.tor_bridges_use_obfs4_radio.toggled.connect(self.tor_bridges_use_obfs4_radio_toggled) # meek_lite-azure option radio # if the obfs4proxy binary is missing, we can't use meek_lite-azure transports (self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = self.common.get_tor_paths() if not os.path.isfile(self.obfs4proxy_file_path): - self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy', True)) + self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option_no_obfs4proxy')) self.tor_bridges_use_meek_lite_azure_radio.setEnabled(False) else: - self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option', True)) + self.tor_bridges_use_meek_lite_azure_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_meek_lite_azure_radio_option')) self.tor_bridges_use_meek_lite_azure_radio.toggled.connect(self.tor_bridges_use_meek_lite_azure_radio_toggled) # meek_lite currently not supported on the version of obfs4proxy bundled with TorBrowser @@ -283,10 +283,10 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_bridges_use_meek_lite_azure_radio.hide() # Custom bridges radio and textbox - self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option', True)) + self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option')) 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_label = QtWidgets.QLabel(strings._('gui_settings_tor_bridges_custom_label')) self.tor_bridges_use_custom_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) self.tor_bridges_use_custom_label.setOpenExternalLinks(True) self.tor_bridges_use_custom_textbox = QtWidgets.QPlainTextEdit() @@ -313,14 +313,14 @@ class SettingsDialog(QtWidgets.QDialog): self.bridges.setLayout(bridges_layout) # Automatic - self.connection_type_automatic_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_automatic_option', True)) + self.connection_type_automatic_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_automatic_option')) self.connection_type_automatic_radio.toggled.connect(self.connection_type_automatic_toggled) # Control port - self.connection_type_control_port_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_control_port_option', True)) + self.connection_type_control_port_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_control_port_option')) self.connection_type_control_port_radio.toggled.connect(self.connection_type_control_port_toggled) - connection_type_control_port_extras_label = QtWidgets.QLabel(strings._('gui_settings_control_port_label', True)) + connection_type_control_port_extras_label = QtWidgets.QLabel(strings._('gui_settings_control_port_label')) self.connection_type_control_port_extras_address = QtWidgets.QLineEdit() self.connection_type_control_port_extras_port = QtWidgets.QLineEdit() connection_type_control_port_extras_layout = QtWidgets.QHBoxLayout() @@ -333,10 +333,10 @@ class SettingsDialog(QtWidgets.QDialog): self.connection_type_control_port_extras.hide() # Socket file - self.connection_type_socket_file_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_socket_file_option', True)) + self.connection_type_socket_file_radio = QtWidgets.QRadioButton(strings._('gui_settings_connection_type_socket_file_option')) self.connection_type_socket_file_radio.toggled.connect(self.connection_type_socket_file_toggled) - connection_type_socket_file_extras_label = QtWidgets.QLabel(strings._('gui_settings_socket_file_label', True)) + connection_type_socket_file_extras_label = QtWidgets.QLabel(strings._('gui_settings_socket_file_label')) self.connection_type_socket_file_extras_path = QtWidgets.QLineEdit() connection_type_socket_file_extras_layout = QtWidgets.QHBoxLayout() connection_type_socket_file_extras_layout.addWidget(connection_type_socket_file_extras_label) @@ -347,7 +347,7 @@ class SettingsDialog(QtWidgets.QDialog): self.connection_type_socket_file_extras.hide() # Tor SOCKS address and port - gui_settings_socks_label = QtWidgets.QLabel(strings._('gui_settings_socks_label', True)) + gui_settings_socks_label = QtWidgets.QLabel(strings._('gui_settings_socks_label')) self.connection_type_socks_address = QtWidgets.QLineEdit() self.connection_type_socks_port = QtWidgets.QLineEdit() connection_type_socks_layout = QtWidgets.QHBoxLayout() @@ -362,14 +362,14 @@ class SettingsDialog(QtWidgets.QDialog): # Authentication options # No authentication - self.authenticate_no_auth_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_no_auth_option', True)) + self.authenticate_no_auth_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_no_auth_option')) self.authenticate_no_auth_radio.toggled.connect(self.authenticate_no_auth_toggled) # Password - self.authenticate_password_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_password_option', True)) + self.authenticate_password_radio = QtWidgets.QRadioButton(strings._('gui_settings_authenticate_password_option')) self.authenticate_password_radio.toggled.connect(self.authenticate_password_toggled) - authenticate_password_extras_label = QtWidgets.QLabel(strings._('gui_settings_password_label', True)) + authenticate_password_extras_label = QtWidgets.QLabel(strings._('gui_settings_password_label')) self.authenticate_password_extras_password = QtWidgets.QLineEdit('') authenticate_password_extras_layout = QtWidgets.QHBoxLayout() authenticate_password_extras_layout.addWidget(authenticate_password_extras_label) @@ -384,7 +384,7 @@ class SettingsDialog(QtWidgets.QDialog): authenticate_group_layout.addWidget(self.authenticate_no_auth_radio) authenticate_group_layout.addWidget(self.authenticate_password_radio) authenticate_group_layout.addWidget(self.authenticate_password_extras) - self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label", True)) + self.authenticate_group = QtWidgets.QGroupBox(strings._("gui_settings_authenticate_label")) self.authenticate_group.setLayout(authenticate_group_layout) # Put the radios into their own group so they are exclusive @@ -393,18 +393,18 @@ class SettingsDialog(QtWidgets.QDialog): connection_type_radio_group_layout.addWidget(self.connection_type_automatic_radio) connection_type_radio_group_layout.addWidget(self.connection_type_control_port_radio) connection_type_radio_group_layout.addWidget(self.connection_type_socket_file_radio) - connection_type_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label", True)) + connection_type_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_connection_type_label")) connection_type_radio_group.setLayout(connection_type_radio_group_layout) # The Bridges options are not exclusive (enabling Bridges offers obfs4 or custom bridges) connection_type_bridges_radio_group_layout = QtWidgets.QVBoxLayout() connection_type_bridges_radio_group_layout.addWidget(self.bridges) - self.connection_type_bridges_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_tor_bridges", True)) + self.connection_type_bridges_radio_group = QtWidgets.QGroupBox(strings._("gui_settings_tor_bridges")) self.connection_type_bridges_radio_group.setLayout(connection_type_bridges_radio_group_layout) self.connection_type_bridges_radio_group.hide() # Test tor settings button - self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button', True)) + self.connection_type_test_button = QtWidgets.QPushButton(strings._('gui_settings_connection_type_test_button')) 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) @@ -420,13 +420,13 @@ class SettingsDialog(QtWidgets.QDialog): connection_type_layout.addLayout(connection_type_test_button_layout) # Buttons - self.save_button = QtWidgets.QPushButton(strings._('gui_settings_button_save', True)) + self.save_button = QtWidgets.QPushButton(strings._('gui_settings_button_save')) self.save_button.clicked.connect(self.save_clicked) - self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel', True)) + self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel')) self.cancel_button.clicked.connect(self.cancel_clicked) version_label = QtWidgets.QLabel('OnionShare {0:s}'.format(self.common.version)) version_label.setStyleSheet(self.common.css['settings_version']) - self.help_button = QtWidgets.QPushButton(strings._('gui_settings_button_help', True)) + self.help_button = QtWidgets.QPushButton(strings._('gui_settings_button_help')) self.help_button.clicked.connect(self.help_clicked) buttons_layout = QtWidgets.QHBoxLayout() buttons_layout.addWidget(version_label) @@ -623,7 +623,7 @@ class SettingsDialog(QtWidgets.QDialog): self.tor_bridges_use_custom_textbox_options.hide() # Alert the user about meek's costliness if it looks like they're turning it on if not self.old_settings.get('tor_bridges_use_meek_lite_azure'): - Alert(self.common, strings._('gui_settings_meek_lite_expensive_warning', True), QtWidgets.QMessageBox.Warning) + Alert(self.common, strings._('gui_settings_meek_lite_expensive_warning'), QtWidgets.QMessageBox.Warning) def tor_bridges_use_custom_radio_toggled(self, checked): """ @@ -736,7 +736,7 @@ class SettingsDialog(QtWidgets.QDialog): """ downloads_dir = self.downloads_dir_lineedit.text() selected_dir = QtWidgets.QFileDialog.getExistingDirectory(self, - strings._('gui_settings_downloads_label', True), downloads_dir) + strings._('gui_settings_downloads_label'), downloads_dir) if selected_dir: self.common.log('SettingsDialog', 'downloads_button_clicked', 'selected dir: {}'.format(selected_dir)) @@ -766,7 +766,7 @@ class SettingsDialog(QtWidgets.QDialog): onion.connect(custom_settings=settings, config=self.config, tor_status_update_func=tor_status_update_func) # If an exception hasn't been raised yet, the Tor settings work - Alert(self.common, strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth, onion.supports_next_gen_onions)) + Alert(self.common, strings._('settings_test_success').format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth, onion.supports_next_gen_onions)) # Clean up onion.cleanup() @@ -802,19 +802,19 @@ class SettingsDialog(QtWidgets.QDialog): # Check for updates def update_available(update_url, installed_version, latest_version): - Alert(self.common, strings._("update_available", True).format(update_url, installed_version, latest_version)) + Alert(self.common, strings._("update_available").format(update_url, installed_version, latest_version)) close_forced_update_thread() def update_not_available(): - Alert(self.common, strings._('update_not_available', True)) + Alert(self.common, strings._('update_not_available')) close_forced_update_thread() def update_error(): - Alert(self.common, strings._('update_error_check_error', True), QtWidgets.QMessageBox.Warning) + Alert(self.common, strings._('update_error_check_error'), QtWidgets.QMessageBox.Warning) close_forced_update_thread() def update_invalid_version(latest_version): - Alert(self.common, strings._('update_error_invalid_latest_version', True).format(latest_version), QtWidgets.QMessageBox.Warning) + Alert(self.common, strings._('update_error_invalid_latest_version').format(latest_version), QtWidgets.QMessageBox.Warning) close_forced_update_thread() forced_update_thread = UpdateThread(self.common, self.onion, self.config, force=True) @@ -905,7 +905,7 @@ class SettingsDialog(QtWidgets.QDialog): """ self.common.log('SettingsDialog', 'cancel_clicked') if not self.local_only and not self.onion.is_authenticated(): - Alert(self.common, strings._('gui_tor_connection_canceled', True), QtWidgets.QMessageBox.Warning) + Alert(self.common, strings._('gui_tor_connection_canceled'), QtWidgets.QMessageBox.Warning) sys.exit() else: self.close() @@ -938,7 +938,7 @@ class SettingsDialog(QtWidgets.QDialog): if self.save_private_key_checkbox.isChecked(): # force the legacy mode on use_legacy_v2_onions = True - settings.set('save_private_key', True) + settings.set('save_private_key') settings.set('private_key', self.old_settings.get('private_key')) settings.set('slug', self.old_settings.get('slug')) settings.set('hidservauth_string', self.old_settings.get('hidservauth_string')) @@ -950,7 +950,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('hidservauth_string', '') if use_legacy_v2_onions: - settings.set('use_legacy_v2_onions', True) + settings.set('use_legacy_v2_onions') else: settings.set('use_legacy_v2_onions', False) # If we are not using legacy mode, but we previously had persistence turned on, force it off! @@ -984,7 +984,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('connection_type', 'socket_file') if self.autoupdate_checkbox.isChecked(): - settings.set('use_autoupdate', True) + settings.set('use_autoupdate') else: settings.set('use_autoupdate', False) @@ -1004,19 +1004,19 @@ class SettingsDialog(QtWidgets.QDialog): # Whether we use bridges if self.tor_bridges_no_bridges_radio.isChecked(): - settings.set('no_bridges', True) + settings.set('no_bridges') settings.set('tor_bridges_use_obfs4', False) settings.set('tor_bridges_use_meek_lite_azure', False) settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_obfs4_radio.isChecked(): settings.set('no_bridges', False) - settings.set('tor_bridges_use_obfs4', True) + settings.set('tor_bridges_use_obfs4') settings.set('tor_bridges_use_meek_lite_azure', False) settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_meek_lite_azure_radio.isChecked(): settings.set('no_bridges', False) settings.set('tor_bridges_use_obfs4', False) - settings.set('tor_bridges_use_meek_lite_azure', True) + settings.set('tor_bridges_use_meek_lite_azure') settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_custom_radio.isChecked(): settings.set('no_bridges', False) @@ -1047,8 +1047,8 @@ class SettingsDialog(QtWidgets.QDialog): new_bridges = ''.join(new_bridges) settings.set('tor_bridges_use_custom_bridges', new_bridges) else: - Alert(self.common, strings._('gui_settings_tor_bridges_invalid', True)) - settings.set('no_bridges', True) + Alert(self.common, strings._('gui_settings_tor_bridges_invalid')) + settings.set('no_bridges') return False return settings @@ -1071,11 +1071,11 @@ class SettingsDialog(QtWidgets.QDialog): dt = datetime.datetime.fromtimestamp(autoupdate_timestamp) last_checked = dt.strftime('%B %d, %Y %H:%M') else: - last_checked = strings._('gui_settings_autoupdate_timestamp_never', True) - self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp', True).format(last_checked)) + last_checked = strings._('gui_settings_autoupdate_timestamp_never') + self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp').format(last_checked)) def _tor_status_update(self, progress, summary): - self.tor_status.setText('{}
{}% {}'.format(strings._('connecting_to_tor', True), progress, summary)) + self.tor_status.setText('{}
{}% {}'.format(strings._('connecting_to_tor'), progress, summary)) self.qtapp.processEvents() if 'Done' in summary: self.tor_status.hide() diff --git a/onionshare_gui/share_mode/__init__.py b/onionshare_gui/share_mode/__init__.py index 90fce49a..feb3b86b 100644 --- a/onionshare_gui/share_mode/__init__.py +++ b/onionshare_gui/share_mode/__init__.py @@ -118,7 +118,7 @@ class ShareMode(Mode): """ Return the string to put on the stop server button, if there's a shutdown timeout """ - return strings._('gui_share_stop_server_shutdown_timeout', True) + return strings._('gui_share_stop_server_shutdown_timeout') def timeout_finished_should_stop_server(self): """ @@ -127,11 +127,11 @@ class ShareMode(Mode): # If there were no attempts to download the share, or all downloads are done, we can stop if self.web.share_mode.download_count == 0 or self.web.done: self.server_status.stop_server() - self.server_status_label.setText(strings._('close_on_timeout', True)) + self.server_status_label.setText(strings._('close_on_timeout')) return True # A download is probably still running - hold off on stopping the share else: - self.server_status_label.setText(strings._('timeout_download_still_running', True)) + self.server_status_label.setText(strings._('timeout_download_still_running')) return False def start_server_custom(self): @@ -178,7 +178,7 @@ class ShareMode(Mode): # Warn about sending large files over Tor if self.web.share_mode.download_filesize >= 157286400: # 150mb - self.filesize_warning.setText(strings._("large_filesize", True)) + self.filesize_warning.setText(strings._("large_filesize")) self.filesize_warning.show() def start_server_error_custom(self): @@ -223,7 +223,7 @@ class ShareMode(Mode): """ Handle REQUEST_LOAD event. """ - self.system_tray.showMessage(strings._('systray_page_loaded_title', True), strings._('systray_download_page_loaded_message', True)) + self.system_tray.showMessage(strings._('systray_page_loaded_title'), strings._('systray_download_page_loaded_message')) def handle_request_started(self, event): """ @@ -237,7 +237,7 @@ class ShareMode(Mode): self.downloads_in_progress += 1 self.update_downloads_in_progress() - self.system_tray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True)) + self.system_tray.showMessage(strings._('systray_download_started_title'), strings._('systray_download_started_message')) def handle_request_progress(self, event): """ @@ -247,7 +247,7 @@ class ShareMode(Mode): # Is the download complete? if event["data"]["bytes"] == self.web.share_mode.filesize: - self.system_tray.showMessage(strings._('systray_download_completed_title', True), strings._('systray_download_completed_message', True)) + self.system_tray.showMessage(strings._('systray_download_completed_title'), strings._('systray_download_completed_message')) # Update the total 'completed downloads' info self.downloads_completed += 1 @@ -260,7 +260,7 @@ class ShareMode(Mode): if self.common.settings.get('close_after_first_download'): self.server_status.stop_server() self.status_bar.clearMessage() - self.server_status_label.setText(strings._('closing_automatically', True)) + self.server_status_label.setText(strings._('closing_automatically')) else: if self.server_status.status == self.server_status.STATUS_STOPPED: self.downloads.cancel(event["data"]["id"]) @@ -276,7 +276,7 @@ class ShareMode(Mode): # Update the 'in progress downloads' info self.downloads_in_progress -= 1 self.update_downloads_in_progress() - self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True)) + self.system_tray.showMessage(strings._('systray_download_canceled_title'), strings._('systray_download_canceled_message')) def on_reload_settings(self): """ @@ -302,9 +302,9 @@ class ShareMode(Mode): total_size_readable = self.common.human_readable_filesize(total_size_bytes) if file_count > 1: - self.info_label.setText(strings._('gui_file_info', True).format(file_count, total_size_readable)) + self.info_label.setText(strings._('gui_file_info').format(file_count, total_size_readable)) else: - self.info_label.setText(strings._('gui_file_info_single', True).format(file_count, total_size_readable)) + self.info_label.setText(strings._('gui_file_info_single').format(file_count, total_size_readable)) else: self.primary_action.hide() @@ -332,7 +332,7 @@ class ShareMode(Mode): else: image = self.common.get_resource_path('images/share_completed.png') self.info_completed_downloads_count.setText(' {1:d}'.format(image, self.downloads_completed)) - self.info_completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.downloads_completed)) + self.info_completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip').format(self.downloads_completed)) def update_downloads_in_progress(self): """ @@ -343,7 +343,7 @@ class ShareMode(Mode): else: image = self.common.get_resource_path('images/share_in_progress.png') self.info_in_progress_downloads_count.setText(' {1:d}'.format(image, self.downloads_in_progress)) - self.info_in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.downloads_in_progress)) + self.info_in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip').format(self.downloads_in_progress)) @staticmethod def _compute_total_size(filenames): diff --git a/onionshare_gui/share_mode/downloads.py b/onionshare_gui/share_mode/downloads.py index a34796f1..fe1e91b8 100644 --- a/onionshare_gui/share_mode/downloads.py +++ b/onionshare_gui/share_mode/downloads.py @@ -89,7 +89,7 @@ class Downloads(QtWidgets.QScrollArea): self.downloads = {} - self.setWindowTitle(strings._('gui_downloads', True)) + self.setWindowTitle(strings._('gui_downloads')) self.setWidgetResizable(True) self.setMinimumHeight(150) self.setMinimumWidth(350) @@ -98,10 +98,10 @@ class Downloads(QtWidgets.QScrollArea): self.vbar = self.verticalScrollBar() self.vbar.rangeChanged.connect(self.resizeScroll) - downloads_label = QtWidgets.QLabel(strings._('gui_downloads', True)) + downloads_label = QtWidgets.QLabel(strings._('gui_downloads')) downloads_label.setStyleSheet(self.common.css['downloads_uploads_label']) - self.no_downloads_label = QtWidgets.QLabel(strings._('gui_no_downloads', True)) - self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history', True)) + self.no_downloads_label = QtWidgets.QLabel(strings._('gui_no_downloads')) + self.clear_history_button = QtWidgets.QPushButton(strings._('gui_clear_history')) self.clear_history_button.clicked.connect(self.reset) self.clear_history_button.hide() diff --git a/onionshare_gui/share_mode/file_selection.py b/onionshare_gui/share_mode/file_selection.py index 628ad5ef..f6f54469 100644 --- a/onionshare_gui/share_mode/file_selection.py +++ b/onionshare_gui/share_mode/file_selection.py @@ -41,7 +41,7 @@ class DropHereLabel(QtWidgets.QLabel): if image: self.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/logo_transparent.png')))) else: - self.setText(strings._('gui_drag_and_drop', True)) + self.setText(strings._('gui_drag_and_drop')) self.setStyleSheet(self.common.css['share_file_selection_drop_here_label']) self.hide() @@ -65,7 +65,7 @@ class DropCountLabel(QtWidgets.QLabel): self.setAcceptDrops(True) self.setAlignment(QtCore.Qt.AlignCenter) - self.setText(strings._('gui_drag_and_drop', True)) + self.setText(strings._('gui_drag_and_drop')) self.setStyleSheet(self.common.css['share_file_selection_drop_count_label']) self.hide() @@ -216,7 +216,7 @@ class FileList(QtWidgets.QListWidget): if filename not in filenames: if not os.access(filename, os.R_OK): - Alert(self.common, strings._("not_a_readable_file", True).format(filename)) + Alert(self.common, strings._("not_a_readable_file").format(filename)) return fileinfo = QtCore.QFileInfo(filename) @@ -301,9 +301,9 @@ class FileSelection(QtWidgets.QVBoxLayout): self.file_list.files_updated.connect(self.update) # Buttons - self.add_button = QtWidgets.QPushButton(strings._('gui_add', True)) + self.add_button = QtWidgets.QPushButton(strings._('gui_add')) self.add_button.clicked.connect(self.add) - self.delete_button = QtWidgets.QPushButton(strings._('gui_delete', True)) + self.delete_button = QtWidgets.QPushButton(strings._('gui_delete')) self.delete_button.clicked.connect(self.delete) button_layout = QtWidgets.QHBoxLayout() button_layout.addStretch() @@ -340,7 +340,7 @@ class FileSelection(QtWidgets.QVBoxLayout): """ Add button clicked. """ - file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items', True)) + file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items')) if file_dialog.exec_() == QtWidgets.QDialog.Accepted: for filename in file_dialog.selectedFiles(): self.file_list.add_file(filename) diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py index b3bd1fe5..2bcbf1a6 100644 --- a/onionshare_gui/tor_connection_dialog.py +++ b/onionshare_gui/tor_connection_dialog.py @@ -51,7 +51,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): self.setFixedSize(400, 150) # Label - self.setLabelText(strings._('connecting_to_tor', True)) + self.setLabelText(strings._('connecting_to_tor')) # Progress bar ticks from 0 to 100 self.setRange(0, 100) @@ -81,7 +81,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def _tor_status_update(self, progress, summary): self.setValue(int(progress)) - self.setLabelText("{}
{}".format(strings._('connecting_to_tor', True), summary)) + self.setLabelText("{}
{}".format(strings._('connecting_to_tor'), summary)) def _connected_to_tor(self): self.common.log('TorConnectionDialog', '_connected_to_tor') @@ -104,7 +104,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog): def alert_and_open_settings(): # Display the exception in an alert box - Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings', True)), QtWidgets.QMessageBox.Warning) + Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings')), QtWidgets.QMessageBox.Warning) # Open settings self.open_settings.emit() From c10500148b415aaadb889c7a48bb87ad3f55b6da Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 18:19:25 -0700 Subject: [PATCH 10/17] Fix tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py tests --- tests_gui_local/commontests.py | 66 ++++++++++++++++--- ...re_receive_mode_upload_test_public_mode.py | 57 ++-------------- tests_gui_tor/commontests.py | 20 +++--- tests_gui_tor/conftest.py | 5 +- 4 files changed, 75 insertions(+), 73 deletions(-) diff --git a/tests_gui_local/commontests.py b/tests_gui_local/commontests.py index de1ad9ab..d3f8a100 100644 --- a/tests_gui_local/commontests.py +++ b/tests_gui_local/commontests.py @@ -3,11 +3,60 @@ import requests import socket import socks import zipfile +import json +import shutil from PyQt5 import QtCore, QtTest + from onionshare import strings +from onionshare.common import Common +from onionshare.settings import Settings +from onionshare.onion import Onion +from onionshare.web import Web +from onionshare_gui import Application, OnionShare, OnionShareGui + class CommonTests(object): + @staticmethod + def set_up(test_settings): + '''Create GUI with given settings''' + # Create our test file + testfile = open('/tmp/test.txt', 'w') + testfile.write('onionshare') + testfile.close() + + common = Common() + common.settings = Settings(common) + common.define_css() + strings.load_strings(common) + + # Get all of the settings in test_settings + test_settings['downloads_dir'] = '/tmp/OnionShare' + for key, val in common.settings.default_settings.items(): + if key not in test_settings: + test_settings[key] = val + + # Start the Onion + testonion = Onion(common) + global qtapp + qtapp = Application(common) + app = OnionShare(common, testonion, True, 0) + + web = Web(common, False, True) + settings_filename = '/tmp/testsettings.json' + open(settings_filename, 'w').write(json.dumps(test_settings)) + + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True) + return gui + + @staticmethod + def tear_down(): + try: + os.remove('/tmp/test.txt') + shutil.rmtree('/tmp/OnionShare') + except: + pass + def test_gui_loaded(self): '''Test that the GUI actually is shown''' self.assertTrue(self.gui.show) @@ -32,7 +81,7 @@ class CommonTests(object): self.assertFalse(self.gui.share_mode.info_widget.isVisible()) def test_info_widget_is_visible(self, mode): - '''Test that the info widget along top of screen is shown''' + '''Test that the info widget along top of screen is shown''' if mode == 'receive': self.assertTrue(self.gui.receive_mode.info_widget.isVisible()) if mode == 'share': @@ -69,9 +118,9 @@ class CommonTests(object): def test_server_status_indicator_says_starting(self, mode): '''Test that the Server Status indicator shows we are Starting''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) if mode == 'share': - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) def test_settings_button_is_hidden(self): '''Test that the settings button is hidden when the server starts''' @@ -123,9 +172,9 @@ class CommonTests(object): def test_server_status_indicator_says_started(self, mode): '''Test that the Server Status indicator shows we are started''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) if mode == 'share': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) def test_web_page(self, mode, string, public_mode): '''Test that the web page contains a string''' @@ -195,12 +244,12 @@ class CommonTests(object): def test_server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) if mode == 'share': if stay_open: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) else: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) # Auto-stop timer tests def test_set_timeout(self, mode, timeout): @@ -304,4 +353,3 @@ class CommonTests(object): def test_add_button_visible(self): '''Test that the add button should be visible''' self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) - diff --git a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py index 30a290e7..7b1cfe79 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py @@ -8,6 +8,7 @@ import json from PyQt5 import QtWidgets from onionshare.common import Common +from onionshare.settings import Settings from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * @@ -18,65 +19,15 @@ class OnionShareGuiTest(unittest.TestCase): '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "receive_allow_receiver_shutdown": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - os.remove('/tmp/OnionShare/test.txt') - os.remove('/tmp/OnionShare/test-2.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_tor/commontests.py b/tests_gui_tor/commontests.py index a0d9bf5f..cb23cca9 100644 --- a/tests_gui_tor/commontests.py +++ b/tests_gui_tor/commontests.py @@ -32,7 +32,7 @@ class CommonTests(object): self.assertFalse(self.gui.share_mode.info_widget.isVisible()) def test_info_widget_is_visible(self, mode): - '''Test that the info widget along top of screen is shown''' + '''Test that the info widget along top of screen is shown''' if mode == 'receive': self.assertTrue(self.gui.receive_mode.info_widget.isVisible()) if mode == 'share': @@ -69,9 +69,9 @@ class CommonTests(object): def test_server_status_indicator_says_starting(self, mode): '''Test that the Server Status indicator shows we are Starting''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) if mode == 'share': - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) def test_settings_button_is_hidden(self): '''Test that the settings button is hidden when the server starts''' @@ -126,9 +126,9 @@ class CommonTests(object): def test_server_status_indicator_says_started(self, mode): '''Test that the Server Status indicator shows we are started''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) if mode == 'share': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) def test_web_page(self, mode, string, public_mode): '''Test that the web page contains a string''' @@ -201,12 +201,12 @@ class CommonTests(object): def test_server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if mode == 'receive': - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) if mode == 'share': if stay_open: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) else: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True)) + self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) def test_cancel_the_share(self, mode): '''Test that we can cancel this share before it's started up ''' @@ -354,6 +354,6 @@ class CommonTests(object): self.gui.app.onion.cleanup(stop_tor=True) QtTest.QTest.qWait(2500) if mode == 'share': - self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost', True)) + self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) if mode == 'receive': - self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost', True)) + self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) diff --git a/tests_gui_tor/conftest.py b/tests_gui_tor/conftest.py index 8ac7efb8..23079e8d 100644 --- a/tests_gui_tor/conftest.py +++ b/tests_gui_tor/conftest.py @@ -151,7 +151,10 @@ def time_strftime(monkeypatch): @pytest.fixture def common_obj(): - return common.Common() + _common = common.Common() + _common.settings = settings.Settings(_common) + strings.load_strings(_common) + return _common @pytest.fixture def settings_obj(sys_onionshare_dev_mode, platform_linux): From d18b77e85453ae269f2c634e549a2e46ffc2472d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 18:32:18 -0700 Subject: [PATCH 11/17] Fix the rest of the local GUI tests --- .../onionshare_receive_mode_upload_test.py | 57 +------------------ ...re_receive_mode_upload_test_public_mode.py | 1 - .../onionshare_share_mode_download_test.py | 55 +----------------- ...re_share_mode_download_test_public_mode.py | 56 +----------------- ...hare_share_mode_download_test_stay_open.py | 55 +----------------- .../onionshare_slug_persistent_test.py | 56 +----------------- tests_gui_local/onionshare_timer_test.py | 55 +----------------- 7 files changed, 18 insertions(+), 317 deletions(-) diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py index 2aa2ed94..cf439950 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -15,68 +15,17 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "receive_allow_receiver_shutdown": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - os.remove('/tmp/OnionShare/test.txt') - os.remove('/tmp/OnionShare/test-2.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py index 7b1cfe79..f89da51a 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py @@ -16,7 +16,6 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): test_settings = { diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests_gui_local/onionshare_share_mode_download_test.py index c546fb61..1800150f 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -15,66 +15,17 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "close_after_first_download": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py index 764b5885..37c593f9 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py +++ b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py @@ -15,66 +15,16 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "public_mode": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py index b92ff097..57ea8424 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py +++ b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py @@ -15,66 +15,17 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": False, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "close_after_first_download": False } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_local/onionshare_slug_persistent_test.py b/tests_gui_local/onionshare_slug_persistent_test.py index 1e5614dc..54652eeb 100644 --- a/tests_gui_local/onionshare_slug_persistent_test.py +++ b/tests_gui_local/onionshare_slug_persistent_test.py @@ -15,68 +15,18 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - slug = '' - @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": True, - "shutdown_timeout": False, "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "save_private_key": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): diff --git a/tests_gui_local/onionshare_timer_test.py b/tests_gui_local/onionshare_timer_test.py index 1a5134e2..26eb4560 100644 --- a/tests_gui_local/onionshare_timer_test.py +++ b/tests_gui_local/onionshare_timer_test.py @@ -15,66 +15,17 @@ from onionshare_gui import * from .commontests import CommonTests class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' @classmethod def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, True, 0) - - web = Web(common, False, True) - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": True, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" + "shutdown_timeout": True } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True) + cls.gui = CommonTests.set_up(test_settings) @classmethod def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') + CommonTests.tear_down() @pytest.mark.run(order=1) def test_gui_loaded(self): From 907503952f8d49a57f6fc3e793b7104fcf6295f2 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 30 Sep 2018 18:40:47 -0700 Subject: [PATCH 12/17] Oops, import strings into tor GUI tests --- tests_gui_tor/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests_gui_tor/conftest.py b/tests_gui_tor/conftest.py index 23079e8d..3ae6fd52 100644 --- a/tests_gui_tor/conftest.py +++ b/tests_gui_tor/conftest.py @@ -8,7 +8,7 @@ import tempfile import pytest -from onionshare import common, web, settings +from onionshare import common, web, settings, strings @pytest.fixture def temp_dir_1024(): From c43d882a65109f3e070bae6cd8c91fc140526fc0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 1 Oct 2018 12:53:10 +1000 Subject: [PATCH 13/17] Explicitly set true/false values for settings that need it --- onionshare_gui/settings_dialog.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index b9e0453a..794bd79c 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -938,7 +938,7 @@ class SettingsDialog(QtWidgets.QDialog): if self.save_private_key_checkbox.isChecked(): # force the legacy mode on use_legacy_v2_onions = True - settings.set('save_private_key') + settings.set('save_private_key', True) settings.set('private_key', self.old_settings.get('private_key')) settings.set('slug', self.old_settings.get('slug')) settings.set('hidservauth_string', self.old_settings.get('hidservauth_string')) @@ -950,7 +950,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('hidservauth_string', '') if use_legacy_v2_onions: - settings.set('use_legacy_v2_onions') + settings.set('use_legacy_v2_onions', True) else: settings.set('use_legacy_v2_onions', False) # If we are not using legacy mode, but we previously had persistence turned on, force it off! @@ -984,7 +984,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('connection_type', 'socket_file') if self.autoupdate_checkbox.isChecked(): - settings.set('use_autoupdate') + settings.set('use_autoupdate', True) else: settings.set('use_autoupdate', False) @@ -1004,19 +1004,19 @@ class SettingsDialog(QtWidgets.QDialog): # Whether we use bridges if self.tor_bridges_no_bridges_radio.isChecked(): - settings.set('no_bridges') + settings.set('no_bridges', True) settings.set('tor_bridges_use_obfs4', False) settings.set('tor_bridges_use_meek_lite_azure', False) settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_obfs4_radio.isChecked(): settings.set('no_bridges', False) - settings.set('tor_bridges_use_obfs4') + settings.set('tor_bridges_use_obfs4', True) settings.set('tor_bridges_use_meek_lite_azure', False) settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_meek_lite_azure_radio.isChecked(): settings.set('no_bridges', False) settings.set('tor_bridges_use_obfs4', False) - settings.set('tor_bridges_use_meek_lite_azure') + settings.set('tor_bridges_use_meek_lite_azure', True) settings.set('tor_bridges_use_custom_bridges', '') if self.tor_bridges_use_custom_radio.isChecked(): settings.set('no_bridges', False) @@ -1048,7 +1048,7 @@ class SettingsDialog(QtWidgets.QDialog): settings.set('tor_bridges_use_custom_bridges', new_bridges) else: Alert(self.common, strings._('gui_settings_tor_bridges_invalid')) - settings.set('no_bridges') + settings.set('no_bridges', True) return False return settings From 29b1b97282b0167f275ca36eba2a69ca46f21663 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 1 Oct 2018 12:53:23 +1000 Subject: [PATCH 14/17] Add French translation for restarting OnionShare to see change in language take effect --- share/locale/fr.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/locale/fr.json b/share/locale/fr.json index 967e456e..ee206662 100644 --- a/share/locale/fr.json +++ b/share/locale/fr.json @@ -29,5 +29,6 @@ "gui_please_wait": "Attendez-vous...", "gui_quit_warning_quit": "Quitter", "gui_quit_warning_dont_quit": "Ne quitter pas", - "gui_settings_autoupdate_timestamp_never": "Jamais" + "gui_settings_autoupdate_timestamp_never": "Jamais", + "gui_settings_language_changed_notice": "Redémarrez OnionShare pour que votre changement de langue prenne effet" } From 9aa9dc39a1d83992665746f722f3d279046ac1fd Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 1 Oct 2018 13:32:09 +1000 Subject: [PATCH 15/17] Move Alert dialog about restart into the conditional that fires only if locale was changed --- onionshare_gui/settings_dialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 794bd79c..5a81282a 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -850,7 +850,7 @@ class SettingsDialog(QtWidgets.QDialog): notice = strings.translations[new_locale]['gui_settings_language_changed_notice'] else: notice = strings._('gui_settings_language_changed_notice') - Alert(self.common, notice, QtWidgets.QMessageBox.Information) + Alert(self.common, notice, QtWidgets.QMessageBox.Information) # Save the new settings settings.save() From 7e8a76be8ae716d49c3c1f4a996b175361afcd97 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 1 Oct 2018 15:32:53 +1000 Subject: [PATCH 16/17] Load default settings before parsing for any alternate config. Reload strings if an alternate config was passed in after --- onionshare/__init__.py | 10 ++++++++-- onionshare_gui/__init__.py | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 2f0ef14c..069559c5 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -33,8 +33,12 @@ def main(cwd=None): """ common = Common() - # Load settings right away, in order to get locale setting for strings - common.load_settings(config) + # Load the default settings and strings early, for the sake of being able to parse options. + # These won't be in the user's chosen locale necessarily, but we need to parse them + # early in order to even display the option to pass alternate settings (which might + # contain a preferred locale). + # If an alternate --config is passed, we'll reload strings later. + common.load_settings() strings.load_strings(common) # Display OnionShare banner @@ -95,6 +99,8 @@ def main(cwd=None): # Re-load settings, if a custom config was passed in if config: common.load_settings(config) + # Re-load the strings, in case the provided config has changed locale + strings.load_strings(common) # Debug mode? common.debug = debug diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index b5520071..675bb52d 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -59,7 +59,11 @@ def main(): common = Common() common.define_css() - # Load settings right away, in order to get locale setting for strings + # Load the default settings and strings early, for the sake of being able to parse options. + # These won't be in the user's chosen locale necessarily, but we need to parse them + # early in order to even display the option to pass alternate settings (which might + # contain a preferred locale). + # If an alternate --config is passed, we'll reload strings later. common.load_settings() strings.load_strings(common) @@ -88,6 +92,10 @@ def main(): filenames[i] = os.path.abspath(filenames[i]) config = args.config + if config: + # Re-load the strings, in case the provided config has changed locale + common.load_settings(config) + strings.load_strings(common) local_only = bool(args.local_only) debug = bool(args.debug) From 235fb84dfc42c441b10e8d4da86165e15556e83c Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 10 Oct 2018 18:45:55 -0700 Subject: [PATCH 17/17] Fix various bugs so local GUI tests pass again after merges --- onionshare_gui/mode/history.py | 12 ++++++------ onionshare_gui/mode/receive_mode/__init__.py | 2 +- tests_gui_local/commontests.py | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index 8cfa0ed5..b446b9fb 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -196,7 +196,7 @@ class UploadHistoryItem(HistoryItem): self.started = datetime.now() # Label - self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress', True).format(self.started.strftime("%b %d, %I:%M%p"))) + self.label = QtWidgets.QLabel(strings._('gui_upload_in_progress').format(self.started.strftime("%b %d, %I:%M%p"))) # Progress bar self.progress_bar = QtWidgets.QProgressBar() @@ -274,16 +274,16 @@ class UploadHistoryItem(HistoryItem): self.ended = self.started = datetime.now() if self.started.year == self.ended.year and self.started.month == self.ended.month and self.started.day == self.ended.day: if self.started.hour == self.ended.hour and self.started.minute == self.ended.minute: - text = strings._('gui_upload_finished', True).format( + text = strings._('gui_upload_finished').format( self.started.strftime("%b %d, %I:%M%p") ) else: - text = strings._('gui_upload_finished_range', True).format( + text = strings._('gui_upload_finished_range').format( self.started.strftime("%b %d, %I:%M%p"), self.ended.strftime("%I:%M%p") ) else: - text = strings._('gui_upload_finished_range', True).format( + text = strings._('gui_upload_finished_range').format( self.started.strftime("%b %d, %I:%M%p"), self.ended.strftime("%b %d, %I:%M%p") ) @@ -380,7 +380,7 @@ class History(QtWidgets.QWidget): # Header self.header_label = QtWidgets.QLabel(header_text) self.header_label.setStyleSheet(self.common.css['downloads_uploads_label']) - clear_button = QtWidgets.QPushButton(strings._('gui_clear_history', True)) + clear_button = QtWidgets.QPushButton(strings._('gui_clear_history')) clear_button.setStyleSheet(self.common.css['downloads_uploads_clear']) clear_button.setFlat(True) clear_button.clicked.connect(self.reset) @@ -486,7 +486,7 @@ class History(QtWidgets.QWidget): else: image = self.common.get_resource_path('images/share_in_progress.png') self.in_progress_label.setText(' {1:d}'.format(image, self.in_progress_count)) - self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip', True).format(self.in_progress_count)) + self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip').format(self.in_progress_count)) class ToggleHistory(QtWidgets.QPushButton): diff --git a/onionshare_gui/mode/receive_mode/__init__.py b/onionshare_gui/mode/receive_mode/__init__.py index d22dd149..f070f963 100644 --- a/onionshare_gui/mode/receive_mode/__init__.py +++ b/onionshare_gui/mode/receive_mode/__init__.py @@ -63,7 +63,7 @@ class ReceiveMode(Mode): ) # Receive mode warning - receive_warning = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True)) + receive_warning = QtWidgets.QLabel(strings._('gui_receive_mode_warning')) receive_warning.setMinimumHeight(80) receive_warning.setWordWrap(True) diff --git a/tests_gui_local/commontests.py b/tests_gui_local/commontests.py index c057386d..27e406c1 100644 --- a/tests_gui_local/commontests.py +++ b/tests_gui_local/commontests.py @@ -14,6 +14,8 @@ from onionshare.settings import Settings from onionshare.onion import Onion from onionshare.web import Web from onionshare_gui import Application, OnionShare, OnionShareGui +from onionshare_gui.mode.share_mode import ShareMode +from onionshare_gui.mode.receive_mode import ReceiveMode class CommonTests(object): @@ -236,7 +238,7 @@ class CommonTests(object): def test_server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if type(mode) == ReceiveMode: - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped', True)) + self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) if type(mode) == ShareMode: if stay_open: self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped'))