Add country dropdown

This commit is contained in:
Micah Lee 2021-12-06 20:01:28 -08:00
parent 08ed7dab65
commit 09ac74a1be
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
4 changed files with 48 additions and 10 deletions

View file

@ -312,7 +312,6 @@ class Common:
"""
Returns the absolute path of a resource
"""
self.log("Common", "get_resource_path", f"filename={filename}")
path = resource_filename("onionshare_cli", os.path.join("resources", filename))
self.log("Common", "get_resource_path", f"filename={filename}, path={path}")
return path

View file

@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import json
import os
from PySide2 import QtCore, QtWidgets, QtGui
from onionshare_cli.settings import Settings
@ -57,7 +59,9 @@ class AutoConnectTab(QtWidgets.QWidget):
QtGui.QPixmap.fromImage(
QtGui.QImage(
GuiCommon.get_resource_path(
"images/{}_logo_text_bg.png".format(common.gui.color_mode)
os.path.join(
"images", f"{common.gui.color_mode}_logo_text_bg.png"
)
)
)
)
@ -291,7 +295,22 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
detect_layout.addWidget(self.detect_automatic_radio)
detect_layout.addWidget(self.detect_manual_radio)
# World map
# Country list
locale = self.common.settings.get("locale")
if not locale:
locale = "en"
with open(
GuiCommon.get_resource_path(os.path.join("countries", f"{locale}.json"))
) as f:
countries = json.loads(f.read())
self.country_combobox = QtWidgets.QComboBox()
self.country_combobox.setStyleSheet(
common.gui.css["autoconnect_countries_combobox"]
)
for country_code in countries:
self.country_combobox.addItem(countries[country_code], country_code)
# Buttons
self.connect_button = QtWidgets.QPushButton(
@ -326,9 +345,12 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
layout = QtWidgets.QVBoxLayout()
layout.addWidget(description_label)
layout.addLayout(detect_layout)
layout.addWidget(self.country_combobox)
layout.addWidget(cta_widget)
self.setLayout(layout)
self.detect_automatic_radio.setChecked(True)
def hide_buttons(self):
self.connect_button.hide()
self.configure_button.hide()
@ -338,10 +360,12 @@ class AutoConnectUseBridgeWidget(QtWidgets.QWidget):
self.configure_button.show()
def _detect_automatic_toggled(self):
pass
self.country_combobox.setEnabled(False)
self.country_combobox.hide()
def _detect_manual_toggled(self):
pass
self.country_combobox.setEnabled(True)
self.country_combobox.show()
def _connect_clicked(self):
self.connect_clicked.emit()

View file

@ -176,6 +176,15 @@ class GuiCommon:
width: 0;
height: 0;
}""",
"autoconnect_countries_combobox": """
QComboBox {
padding: 10px;
font-size: 16px;
}
QComboBox:disabled {
color: #666666;
}
""",
# Common styles between modes and their child widgets
"mode_settings_toggle_advanced": """
QPushButton {
@ -563,8 +572,12 @@ class ToggleCheckbox(QtWidgets.QCheckBox):
s = self.style()
s.drawControl(QtWidgets.QStyle.CE_CheckBox, opt, painter, self)
rect = QtCore.QRect(s.subElementRect(QtWidgets.QStyle.SE_CheckBoxContents, opt, self))
x = rect.width() - rect.x() - self.w + 20 # 20 is the padding between text and toggle
rect = QtCore.QRect(
s.subElementRect(QtWidgets.QStyle.SE_CheckBoxContents, opt, self)
)
x = (
rect.width() - rect.x() - self.w + 20
) # 20 is the padding between text and toggle
y = self.height() / 2 - self.h / 2 + self.y() / 2
self.toggleRect = QtCore.QRect(x, y, self.w, self.h)
painter.setBrush(QtGui.QColor(self.bg_color))
@ -574,6 +587,8 @@ class ToggleCheckbox(QtWidgets.QCheckBox):
painter.drawEllipse(x, y - 3, self.h + 6, self.h + 6)
else:
painter.setBrush(QtGui.QColor(self.active_color))
painter.drawEllipse(x + self.w - (self.h + 6), y - 3, self.h + 6, self.h + 6)
painter.drawEllipse(
x + self.w - (self.h + 6), y - 3, self.h + 6, self.h + 6
)
painter.end()

View file

@ -44,7 +44,7 @@
"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_description": "<b>Failed connecting to Tor.</b> This could be because your internet is being censored. 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",