[Pkg-privacy-commits] [onionshare] 156/256: Began making a TorConnectionDialog, which handles connecting to the Tor network

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:32 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to branch master
in repository onionshare.

commit 71dc65edee8ad10202b1ed92107d9512450cf71d
Author: Micah Lee <micah at micahflee.com>
Date:   Mon Apr 17 20:26:35 2017 -0700

    Began making a TorConnectionDialog, which handles connecting to the Tor network
---
 onionshare/onion.py                     |  7 ++--
 onionshare_gui/__init__.py              | 12 ++++++
 onionshare_gui/tor_connection_dialog.py | 68 +++++++++++++++++++++++++++++++++
 share/locale/en.json                    |  3 +-
 4 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/onionshare/onion.py b/onionshare/onion.py
index 4fab42b..d81f23d 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -131,7 +131,7 @@ class Onion(object):
         # The tor process
         self.tor_proc = None
 
-    def connect(self, settings=False, bundled_tor_func=None):
+    def connect(self, settings=False, tor_status_update_func=None):
         # Either use settings that are passed in, or load them from disk
         if settings:
             self.settings = settings
@@ -205,9 +205,8 @@ class Onion(object):
                 # "\033[K" clears the rest of the line
                 print("{}: {}% - {}{}".format(strings._('connecting_to_tor'), progress, summary, "\033[K"), end="\r")
 
-                if callable(bundled_tor_func):
-                    status_string = "{}% - {}".format(progress, summary)
-                    bundled_tor_func(status_string)
+                if callable(tor_status_update_func):
+                    tor_status_update_func(progress, summary)
 
                 if summary == 'Done':
                     print("")
diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py
index fec2f10..e59c6cf 100644
--- a/onionshare_gui/__init__.py
+++ b/onionshare_gui/__init__.py
@@ -22,9 +22,12 @@ import os, sys, platform, argparse
 from PyQt5 import QtCore, QtWidgets
 
 from onionshare import strings, helpers, web
+from onionshare.onion import *
 from onionshare.onionshare import OnionShare
+from onionshare.settings import Settings
 
 from .onionshare_gui import OnionShareGui
+from .tor_connection_dialog import TorConnectionDialog
 
 class Application(QtWidgets.QApplication):
     """
@@ -84,12 +87,21 @@ def main():
         if not valid:
             sys.exit()
 
+    # Load settings
+    settings = Settings()
+    settings.load()
+
+    # Start the Onion
+    onion = Onion()
+    tor_con = TorConnectionDialog(settings, onion)
+
     # Start the OnionShare app
     web.set_stay_open(stay_open)
     app = OnionShare(debug, local_only, stay_open)
 
     # Clean up when app quits
     def shutdown():
+        onion.cleanup()
         app.cleanup()
     qtapp.aboutToQuit.connect(shutdown)
 
diff --git a/onionshare_gui/tor_connection_dialog.py b/onionshare_gui/tor_connection_dialog.py
new file mode 100644
index 0000000..734d2f5
--- /dev/null
+++ b/onionshare_gui/tor_connection_dialog.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+"""
+OnionShare | https://onionshare.org/
+
+Copyright (C) 2017 Micah Lee <micah at micahflee.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+from PyQt5 import QtCore, QtWidgets, QtGui
+
+from onionshare import strings, helpers
+
+class TorConnectionDialog(QtWidgets.QProgressDialog):
+    """
+    Connecting to Tor dialog.
+    """
+    def __init__(self, settings, onion):
+        super(TorConnectionDialog, self).__init__(None)
+        self.settings = settings
+
+        self.setWindowTitle("OnionShare")
+        self.setWindowIcon(QtGui.QIcon(helpers.get_resource_path('images/logo.png')))
+        self.setModal(True)
+
+        # Label
+        self.setLabelText(strings._('connecting_to_tor', True))
+        self.setCancelButtonText(strings._('gui_tor_connection_exit', True))
+
+        # Progress bar ticks from 0 to 100
+        self.setRange(0, 100)
+        # Don't show if connection takes less than 200ms (for non-bundled tor)
+        self.setMinimumDuration(200)
+
+        # If bundled tor, prepare to display Tor connection status
+        if settings.get('connection_type') == 'bundled':
+            tor_status_update = self.tor_status_update
+        else:
+            tor_status_update = None
+
+        # Connect to the Onion
+        self.setValue(0)
+        try:
+            onion.connect(self.settings, tor_status_update)
+        except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported, BundledTorTimeout) as e:
+            print(e.args[0])
+            # TODO: Open settings to connect to Tor properly
+            sys.exit()
+
+        self.exec_()
+
+    def tor_status_update(self, progress, summary):
+        if summary == 'Done':
+            # All done
+            self.close()
+        else:
+            self.setValue(int(progress))
+        self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor', True), summary))
diff --git a/share/locale/en.json b/share/locale/en.json
index 618bba1..acb4f73 100644
--- a/share/locale/en.json
+++ b/share/locale/en.json
@@ -100,5 +100,6 @@
     "update_error_tor": "Error checking for updates: Can't connect to Tor.\nCheck your Tor connection settings.",
     "update_error_sockshttp": "Error checking for updates: Connected to Tor, but can't load the update HTTP request.",
     "update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.",
-    "update_not_available": "You are running the latest version of OnionShare."
+    "update_not_available": "You are running the latest version of OnionShare.",
+    "gui_tor_connection_exit": "Exit"
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list