Start making UseBridgeWidget, and add json files that list country names for each enabled locale

This commit is contained in:
Micah Lee 2021-12-06 19:39:44 -08:00
parent ce9c35ac9b
commit 339fc9338e
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
21 changed files with 165 additions and 2 deletions

View File

@ -192,7 +192,7 @@ class Onion(object):
custom_settings=None,
config=None,
tor_status_update_func=None,
connect_timeout=120,
connect_timeout=1,
local_only=False,
):
if local_only:

View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import os
import tempfile
import subprocess
import json
import onionshare_cli
def main():
# Clone the country-list repo
tmp_dir = tempfile.TemporaryDirectory()
subprocess.run(
["git", "clone", "https://github.com/umpirsky/country-list.git"],
cwd=tmp_dir.name,
)
repo_dir = os.path.join(tmp_dir.name, "country-list")
# Get the list of enabled languages
common = onionshare_cli.common.Common()
settings = onionshare_cli.settings.Settings(common)
available_locales = list(settings.available_locales)
# Make a dictionary that makes a language's ISO 3166-1 to its name in all enabled languages
os.makedirs(
os.path.join("src", "onionshare", "resources", "countries"), exist_ok=True
)
for locale in available_locales:
with open(os.path.join(repo_dir, "data", locale, "country.json")) as f:
countries = json.loads(f.read())
with open(
os.path.join(
"src", "onionshare", "resources", "countries", f"{locale}.json"
),
"w",
) as f:
f.write(json.dumps(countries))
if __name__ == "__main__":
main()

View File

@ -77,6 +77,9 @@ class AutoConnectTab(QtWidgets.QWidget):
# Use bridge widget
self.use_bridge_widget = AutoConnectUseBridgeWidget(self.common)
self.use_bridge_widget.connect_clicked.connect(self.connect_clicked)
self.use_bridge_widget.back_clicked.connect(self.back_clicked)
self.use_bridge_widget.open_tor_settings.connect(self.open_tor_settings)
self.use_bridge_widget.hide()
# Tor connection widget
@ -134,9 +137,11 @@ class AutoConnectTab(QtWidgets.QWidget):
"""
self.common.log("AutoConnectTab", "connect_clicked")
# If we're on first launch, hide the buttons
# Hide the buttons
if self.first_launch_widget.isVisible():
self.first_launch_widget.hide_buttons()
elif self.use_bridge_widget.isVisible():
self.use_bridge_widget.hide_buttons()
if not self.common.gui.local_only:
self.tor_con.show()
@ -144,12 +149,20 @@ class AutoConnectTab(QtWidgets.QWidget):
else:
self.close_this_tab.emit()
def back_clicked(self):
"""
Switch from use bridge widget back to first launch widget
"""
self.use_bridge_widget.hide()
self.first_launch_widget.show()
def tor_con_success(self):
"""
Finished testing tor connection.
"""
self.tor_con.hide()
self.first_launch_widget.show_buttons()
self.use_bridge_widget.show_buttons()
if self.common.gui.onion.is_authenticated() and not self.tor_con.wasCanceled():
# Tell the tabs that Tor is connected
@ -186,6 +199,7 @@ class AutoConnectFirstLaunchWidget(QtWidgets.QWidget):
# Description and checkbox
description_label = QtWidgets.QLabel(strings._("gui_autoconnect_description"))
description_label.setWordWrap(True)
self.enable_autoconnect_checkbox = ToggleCheckbox(
strings._("gui_enable_autoconnect_checkbox")
)
@ -248,7 +262,92 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
If connecting fails, this is the widget that helps the user bypass censorship
"""
connect_clicked = QtCore.Signal()
back_clicked = QtCore.Signal()
open_tor_settings = QtCore.Signal()
def __init__(self, common):
super(AutoConnectUseBridgeWidget, self).__init__()
self.common = common
self.common.log("AutoConnectUseBridgeWidget", "__init__")
# Description
description_label = QtWidgets.QLabel(
strings._("gui_autoconnect_bridge_description")
)
description_label.setTextFormat(QtCore.Qt.RichText)
description_label.setWordWrap(True)
# Detection preference
self.detect_automatic_radio = QtWidgets.QRadioButton(
strings._("gui_autoconnect_bridge_detect_automatic")
)
self.detect_automatic_radio.toggled.connect(self._detect_automatic_toggled)
self.detect_manual_radio = QtWidgets.QRadioButton(
strings._("gui_autoconnect_bridge_detect_manual")
)
self.detect_manual_radio.toggled.connect(self._detect_manual_toggled)
detect_layout = QtWidgets.QVBoxLayout()
detect_layout.addWidget(self.detect_automatic_radio)
detect_layout.addWidget(self.detect_manual_radio)
# World map
# Buttons
self.connect_button = QtWidgets.QPushButton(
strings._("gui_autoconnect_bridge_start")
)
self.connect_button.clicked.connect(self._connect_clicked)
self.connect_button.setFixedWidth(150)
self.connect_button.setStyleSheet(common.gui.css["autoconnect_start_button"])
self.back_button = QtWidgets.QPushButton(
strings._("gui_autoconnect_bridge_back")
)
self.back_button.clicked.connect(self._back_clicked)
self.back_button.setFlat(True)
self.back_button.setStyleSheet(common.gui.css["autoconnect_configure_button"])
self.configure_button = QtWidgets.QPushButton(
strings._("gui_autoconnect_configure")
)
self.configure_button.clicked.connect(self._open_tor_settings)
self.configure_button.setFlat(True)
self.configure_button.setStyleSheet(
common.gui.css["autoconnect_configure_button"]
)
cta_layout = QtWidgets.QHBoxLayout()
cta_layout.addWidget(self.connect_button)
cta_layout.addWidget(self.back_button)
cta_layout.addWidget(self.configure_button)
cta_layout.addStretch()
cta_widget = QtWidgets.QWidget()
cta_widget.setLayout(cta_layout)
# Layout
layout = QtWidgets.QVBoxLayout()
layout.addWidget(description_label)
layout.addLayout(detect_layout)
layout.addWidget(cta_widget)
self.setLayout(layout)
def hide_buttons(self):
self.connect_button.hide()
self.configure_button.hide()
def show_buttons(self):
self.connect_button.show()
self.configure_button.show()
def _detect_automatic_toggled(self):
pass
def _detect_manual_toggled(self):
pass
def _connect_clicked(self):
self.connect_clicked.emit()
def _back_clicked(self):
self.back_clicked.emit()
def _open_tor_settings(self):
self.open_tor_settings.emit()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"AF": "Afghanistan", "AX": "\u00c5land Islands", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua & Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BA": "Bosnia & Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "BQ": "Caribbean Netherlands", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo - Brazzaville", "CD": "Congo - Kinshasa", "CK": "Cook Islands", "CR": "Costa Rica", "CI": "C\u00f4te d\u2019Ivoire", "HR": "Croatia", "CU": "Cuba", "CW": "Cura\u00e7ao", "CY": "Cyprus", "CZ": "Czechia", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "SZ": "Eswatini", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard & McDonald Islands", "HN": "Honduras", "HK": "Hong Kong SAR China", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao SAR China", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar (Burma)", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MK": "North Macedonia", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PW": "Palau", "PS": "Palestinian Territories", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn Islands", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "R\u00e9union", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "WS": "Samoa", "SM": "San Marino", "ST": "S\u00e3o Tom\u00e9 & Pr\u00edncipe", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SX": "Sint Maarten", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia & South Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "BL": "St. Barth\u00e9lemy", "SH": "St. Helena", "KN": "St. Kitts & Nevis", "LC": "St. Lucia", "MF": "St. Martin", "PM": "St. Pierre & Miquelon", "VC": "St. Vincent & Grenadines", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard & Jan Mayen", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad & Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks & Caicos Islands", "TV": "Tuvalu", "UM": "U.S. Outlying Islands", "VI": "U.S. Virgin Islands", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom", "US": "United States", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican City", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis & Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -44,8 +44,13 @@
"gui_tor_settings_window_title": "Tor Settings",
"gui_autoconnect_description": "OnionShare relies on the Tor Network, run by thousands of volunteers around the world.",
"gui_enable_autoconnect_checkbox": "Enable automatically connecting to Tor",
"gui_autoconnect_bridge_description": "<b>Failed connecting to Tor.</b> This could be because your internet is being censored, and you might be able to bypass this censorship by using a bridge.",
"gui_autoconnect_bridge_detect_automatic": "Automatically determine my location to bypass country-specific censorship",
"gui_autoconnect_bridge_detect_manual": "Manually select my country",
"gui_autoconnect_start": "Connect to Tor",
"gui_autoconnect_configure": "Network Settings",
"gui_autoconnect_bridge_start": "Use a Bridge",
"gui_autoconnect_bridge_back": "Back",
"gui_settings_window_title": "Settings",
"gui_settings_autoupdate_label": "Check for new version",
"gui_settings_autoupdate_option": "Notify me when a new version is available",