diff --git a/desktop/src/onionshare/connection_tab.py b/desktop/src/onionshare/connection_tab.py index bb5f72a3..88783ec6 100644 --- a/desktop/src/onionshare/connection_tab.py +++ b/desktop/src/onionshare/connection_tab.py @@ -36,6 +36,7 @@ class AutoConnectTab(QtWidgets.QWidget): close_this_tab = QtCore.Signal() tor_is_connected = QtCore.Signal() tor_is_disconnected = QtCore.Signal() + def __init__(self, common, tab_id, status_bar, parent=None): super(AutoConnectTab, self).__init__() self.common = common @@ -67,21 +68,16 @@ class AutoConnectTab(QtWidgets.QWidget): self.image = QtWidgets.QWidget() self.image.setLayout(image_layout) - # Description and checkbox - description_label = QtWidgets.QLabel(strings._("gui_autoconnect_description")) - self.enable_autoconnect_checkbox = ToggleCheckbox( - strings._("gui_enable_autoconnect_checkbox") - ) - self.enable_autoconnect_checkbox.clicked.connect(self.toggle_auto_connect) - self.enable_autoconnect_checkbox.setFixedWidth(400) - self.enable_autoconnect_checkbox.setStyleSheet( - common.gui.css["enable_autoconnect"] - ) - description_layout = QtWidgets.QVBoxLayout() - description_layout.addWidget(description_label) - description_layout.addWidget(self.enable_autoconnect_checkbox) - description_widget = QtWidgets.QWidget() - description_widget.setLayout(description_layout) + # First launch widget + self.first_launch_widget = AutoConnectFirstLaunchWidget(self.common) + self.first_launch_widget.toggle_auto_connect.connect(self.toggle_auto_connect) + self.first_launch_widget.connect_clicked.connect(self.connect_clicked) + self.first_launch_widget.open_tor_settings.connect(self.open_tor_settings) + self.first_launch_widget.show() + + # Use bridge widget + self.use_bridge_widget = AutoConnectUseBridgeWidget(self.common) + self.use_bridge_widget.hide() # Tor connection widget self.tor_con = TorConnectionWidget(self.common, self.status_bar) @@ -89,38 +85,13 @@ class AutoConnectTab(QtWidgets.QWidget): self.tor_con.fail.connect(self.tor_con_fail) self.tor_con.hide() - # Error label - self.error_label = QtWidgets.QLabel() - self.error_label.setStyleSheet(self.common.gui.css["tor_settings_error"]) - self.error_label.setWordWrap(True) - - # CTA buttons - self.connect_button = QtWidgets.QPushButton(strings._("gui_autoconnect_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.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.configure_button) - cta_widget = QtWidgets.QWidget() - cta_widget.setLayout(cta_layout) - - # Layout content_layout = QtWidgets.QVBoxLayout() content_layout.addStretch() content_layout.addWidget(self.image) - content_layout.addWidget(description_widget) + content_layout.addWidget(self.first_launch_widget) + content_layout.addWidget(self.use_bridge_widget) content_layout.addWidget(self.tor_con) - content_layout.addWidget(cta_widget) content_layout.addStretch() content_layout.setAlignment(QtCore.Qt.AlignCenter) content_widget = QtWidgets.QWidget() @@ -138,7 +109,9 @@ class AutoConnectTab(QtWidgets.QWidget): """ self.common.log("AutoConnectTab", "autoconnect_checking") if self.auto_connect_enabled: - self.enable_autoconnect_checkbox.setCheckState(QtCore.Qt.Checked) + self.first_launch_widget.enable_autoconnect_checkbox.setCheckState( + QtCore.Qt.Checked + ) self.connect_clicked() def toggle_auto_connect(self): @@ -147,7 +120,8 @@ class AutoConnectTab(QtWidgets.QWidget): """ self.common.log("AutoConnectTab", "autoconnect_checkbox_clicked") self.curr_settings.set( - "auto_connect", self.enable_autoconnect_checkbox.isChecked() + "auto_connect", + self.first_launch_widget.enable_autoconnect_checkbox.isChecked(), ) self.curr_settings.save() @@ -160,9 +134,9 @@ class AutoConnectTab(QtWidgets.QWidget): """ self.common.log("AutoConnectTab", "connect_clicked") - self.error_label.setText("") - self.connect_button.hide() - self.configure_button.hide() + # If we're on first launch, hide the buttons + if self.first_launch_widget.isVisible(): + self.first_launch_widget.hide_buttons() if not self.common.gui.local_only: self.tor_con.show() @@ -175,12 +149,9 @@ class AutoConnectTab(QtWidgets.QWidget): Finished testing tor connection. """ self.tor_con.hide() - self.connect_button.show() - self.configure_button.show() - if ( - self.common.gui.onion.is_authenticated() - and not self.tor_con.wasCanceled() - ): + self.first_launch_widget.show_buttons() + + if self.common.gui.onion.is_authenticated() and not self.tor_con.wasCanceled(): # Tell the tabs that Tor is connected self.tor_is_connected.emit() # Close the tab @@ -191,6 +162,93 @@ class AutoConnectTab(QtWidgets.QWidget): Finished testing tor connection. """ self.tor_con.hide() + + # If we're on first launch, switch to use bridge + if self.first_launch_widget.isVisible(): + self.first_launch_widget.show_buttons() + self.first_launch_widget.hide() + self.use_bridge_widget.show() + + +class AutoConnectFirstLaunchWidget(QtWidgets.QWidget): + """ + When you first launch OnionShare, this is the widget that is displayed + """ + + toggle_auto_connect = QtCore.Signal() + connect_clicked = QtCore.Signal() + open_tor_settings = QtCore.Signal() + + def __init__(self, common): + super(AutoConnectFirstLaunchWidget, self).__init__() + self.common = common + self.common.log("AutoConnectFirstLaunchWidget", "__init__") + + # Description and checkbox + description_label = QtWidgets.QLabel(strings._("gui_autoconnect_description")) + self.enable_autoconnect_checkbox = ToggleCheckbox( + strings._("gui_enable_autoconnect_checkbox") + ) + self.enable_autoconnect_checkbox.clicked.connect(self._toggle_auto_connect) + self.enable_autoconnect_checkbox.setFixedWidth(400) + self.enable_autoconnect_checkbox.setStyleSheet( + common.gui.css["enable_autoconnect"] + ) + description_layout = QtWidgets.QVBoxLayout() + description_layout.addWidget(description_label) + description_layout.addWidget(self.enable_autoconnect_checkbox) + description_widget = QtWidgets.QWidget() + description_widget.setLayout(description_layout) + + # Buttons + self.connect_button = QtWidgets.QPushButton(strings._("gui_autoconnect_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.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.configure_button) + cta_widget = QtWidgets.QWidget() + cta_widget.setLayout(cta_layout) + + # Layout + layout = QtWidgets.QVBoxLayout() + layout.addWidget(description_widget) + 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() - self.error_label.setText(msg) + + def _toggle_auto_connect(self): + self.toggle_auto_connect.emit() + + def _connect_clicked(self): + self.connect_clicked.emit() + + def _open_tor_settings(self): + self.open_tor_settings.emit() + + +class AutoConnectUseBridgeWidget(QtWidgets.QWidget): + """ + If connecting fails, this is the widget that helps the user bypass censorship + """ + + def __init__(self, common): + super(AutoConnectUseBridgeWidget, self).__init__() + self.common = common + self.common.log("AutoConnectUseBridgeWidget", "__init__")