[Pkg-anonymity-tools] [onionshare] 41/140: made it so clicking Start Server actually starts the server, and made the URL fields hide/show appropriately, and the Copy URL button work
Ulrike Uhlig
u-guest at moszumanska.debian.org
Mon Sep 29 20:33:45 UTC 2014
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch master
in repository onionshare.
commit 5325b7b17305745a21e692f99b019c1b4d88291e
Author: Micah Lee <micah at micahflee.com>
Date: Wed Aug 27 19:07:15 2014 -0700
made it so clicking Start Server actually starts the server, and made the URL fields hide/show appropriately, and the Copy URL button work
---
onionshare/onionshare.py | 1 +
onionshare/strings.json | 20 +++++++--------
onionshare_gui/onionshare_gui.py | 28 ++++++++++++++-------
onionshare_gui/server_status.py | 53 +++++++++++++++++++++++++++++++++++-----
4 files changed, 77 insertions(+), 25 deletions(-)
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 69b4e50..f9367e4 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -34,6 +34,7 @@ class OnionShare(object):
os.remove(filename)
elif os.path.isdir(filename):
shutil.rmtree(filename)
+ self.cleanup_filenames = []
def choose_port(self):
# let the OS choose a port
diff --git a/onionshare/strings.json b/onionshare/strings.json
index 5f69691..8a72506 100644
--- a/onionshare/strings.json
+++ b/onionshare/strings.json
@@ -9,7 +9,6 @@
"filename": "Filename",
"size": "Size",
"sha1_checksum": "SHA1 checksum",
- "copied_url": "Copied URL to clipboard",
"download_page_loaded": "Download page loaded",
"download_started": "Download started",
"download_finished": "Download finished",
@@ -35,7 +34,8 @@
"gui_start_server": "Start Server",
"gui_stop_server": "Stop Server",
"gui_copy_url": "Copy URL",
- "gui_downloads": "Downloads:"
+ "gui_downloads": "Downloads:",
+ "gui_copied_url": "Copied URL to clipboard"
}, "no": {
"calculating_sha1": "Kalkulerer SHA1 sjekksum.",
"connecting_ctrlport": "Kobler til Tors kontroll-port for å sette opp en gjemt tjeneste på port {0}.",
@@ -45,7 +45,7 @@
"not_a_file": "{0} er ikke en fil.",
"filesize": "Filstørrelse",
"sha1_checksum": "SHA1 sjekksum",
- "copied_url": "Kopierte URL-en til utklippstavlen",
+ "gui_copied_url": "Kopierte URL-en til utklippstavlen",
"download_page_loaded": "Nedlastingsside lastet",
"download_started": "Nedlasting startet",
"download_finished": "Nedlasting fullført",
@@ -63,7 +63,7 @@
"not_a_file": "{0} no es un archivo.",
"filesize": "Tamaño del archivo",
"sha1_checksum": "Suma de verificación SHA1",
- "copied_url": "Copiar URL en el portapapeles",
+ "gui_copied_url": "Copiar URL en el portapapeles",
"download_page_loaded": "Descargar página cargada.",
"download_started": "Descarga comenzó",
"download_finished": "Descarga terminado",
@@ -90,7 +90,7 @@
"not_a_file": "{0} non è un file.",
"filesize": "Grandezza del file",
"sha1_checksum": "Firma SHA1",
- "copied_url": "URL copiato negli appunti",
+ "gui_copied_url": "URL copiato negli appunti",
"download_page_loaded": "Pagina di download caricata",
"download_started": "Download iniziato",
"download_finished": "Download finito",
@@ -108,7 +108,7 @@
"not_a_file": "{0} is geen bestand.",
"filesize": "Bestandsgrootte",
"sha1_checksum": "SHA1 controlecijfer",
- "copied_url": "URL gekopieerd naar klembord",
+ "gui_copied_url": "URL gekopieerd naar klembord",
"download_page_loaded": "Download pagina geladen",
"download_started": "Download gestart",
"download_finished": "Download voltooid",
@@ -135,7 +135,7 @@
"not_a_file": "{0} não é um arquivo.",
"filesize": "Tamanho de arquivo",
"sha1_checksum": "Checksum SHA1",
- "copied_url": "URL foi copiado para área de transferência",
+ "gui_copied_url": "URL foi copiado para área de transferência",
"download_page_loaded": "Página de download carregada",
"download_started": "Começou o download",
"download_finished": "Terminou o download",
@@ -153,7 +153,7 @@
"not_a_file": "{0} не является файлом.",
"filesize": "Размер файла",
"sha1_checksum": "SHA1 хешсумма",
- "copied_url": "Ссылка скопирована в буфер обмена",
+ "gui_copied_url": "Ссылка скопирована в буфер обмена",
"download_page_loaded": "Страница закачки загружена",
"download_started": "Загрузка начата",
"download_finished": "Загрузка закончена",
@@ -172,7 +172,7 @@
"not_a_file": "{0} ist keine Datei.",
"filesize": "Dateigröße",
"sha1_checksum": "SHA1 Checksumme",
- "copied_url": "URL in die Zwischenablage kopiert",
+ "gui_copied_url": "URL in die Zwischenablage kopiert",
"download_page_loaded": "Download-Seite geladen",
"download_started": "Download gestartet",
"download_finished": "Download abgeschlossen",
@@ -192,7 +192,7 @@
"not_a_file": "{0} dosya değil.",
"filesize": "Dosya boyutu",
"sha1_checksum": "SHA1 özeti",
- "copied_url": "Panoya kopyalanan URL",
+ "gui_copied_url": "Panoya kopyalanan URL",
"download_page_loaded": "İndirme sayfası yüklendi",
"download_started": "İndirme başladı",
"download_finished": "İndirme bitti",
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index d3b0c1a..d60d95e 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -24,8 +24,9 @@ class Application(QtGui.QApplication):
QtGui.QApplication.__init__(self, sys.argv)
class OnionShareGui(QtGui.QWidget):
- def __init__(self, app):
+ def __init__(self, qtapp, app):
super(OnionShareGui, self).__init__()
+ self.qtapp = qtapp
self.app = app
self.setWindowTitle('OnionShare')
@@ -33,18 +34,18 @@ class OnionShareGui(QtGui.QWidget):
def send_files(self, filenames=None):
# file selection
- file_selection = FileSelection()
+ self.file_selection = FileSelection()
if filenames:
for filename in filenames:
- file_selection.file_list.add_file(filename)
+ self.file_selection.file_list.add_file(filename)
# server status
- self.server_status = ServerStatus(file_selection)
- self.server_status.server_started.connect(file_selection.server_started)
+ self.server_status = ServerStatus(self.qtapp, self.app, web, self.file_selection)
+ self.server_status.server_started.connect(self.file_selection.server_started)
self.server_status.server_started.connect(self.start_server)
- self.server_status.server_stopped.connect(file_selection.server_stopped)
+ self.server_status.server_stopped.connect(self.file_selection.server_stopped)
self.server_status.server_stopped.connect(self.stop_server)
- file_selection.file_list.files_updated.connect(self.server_status.update)
+ self.file_selection.file_list.files_updated.connect(self.server_status.update)
# downloads
downloads = Downloads()
@@ -54,7 +55,7 @@ class OnionShareGui(QtGui.QWidget):
# main layout
self.layout = QtGui.QVBoxLayout()
- self.layout.addLayout(file_selection)
+ self.layout.addLayout(self.file_selection)
self.layout.addLayout(self.server_status)
self.layout.addLayout(downloads)
self.layout.addLayout(options)
@@ -79,9 +80,18 @@ class OnionShareGui(QtGui.QWidget):
t.daemon = True
t.start()
+ # prepare the files for sending
+ web.set_file_info(self.file_selection.file_list.filenames)
+ self.app.cleanup_filenames.append(web.zip_filename)
+
+ self.server_status.start_server_finished()
+
def stop_server(self):
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
urllib2.urlopen('http://127.0.0.1:{0}/{1}/shutdown'.format(self.app.port, web.shutdown_slug)).read()
+ self.app.cleanup()
+
+ self.server_status.stop_server_finished()
def alert(msg, icon=QtGui.QMessageBox.NoIcon):
dialog = QtGui.QMessageBox()
@@ -139,7 +149,7 @@ def main():
qtapp.connect(qtapp, QtCore.SIGNAL("aboutToQuit()"), shutdown)
# launch the gui
- gui = OnionShareGui(app)
+ gui = OnionShareGui(qtapp, app)
gui.send_files(filenames)
# all done
diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py
index 17077d1..df372d6 100644
--- a/onionshare_gui/server_status.py
+++ b/onionshare_gui/server_status.py
@@ -1,3 +1,4 @@
+import platform
from PyQt4 import QtCore, QtGui
import common
@@ -11,13 +12,19 @@ class ServerStatus(QtGui.QVBoxLayout):
STATUS_WORKING = 1
STATUS_STARTED = 2
- def __init__(self, file_selection):
+ def __init__(self, qtapp, app, web, file_selection):
super(ServerStatus, self).__init__()
self.status = self.STATUS_STOPPED
self.addSpacing(10)
+ self.qtapp = qtapp
+ self.app = app
+ self.web = web
self.file_selection = file_selection
+ # system tray icon (for notifications)
+ self.systray = QtGui.QSystemTrayIcon()
+
# server layout
self.status_image_stopped = QtGui.QImage('{0}/server_stopped.png'.format(common.onionshare_gui_dir))
self.status_image_working = QtGui.QImage('{0}/server_working.png'.format(common.onionshare_gui_dir))
@@ -46,9 +53,6 @@ class ServerStatus(QtGui.QVBoxLayout):
url_layout = QtGui.QHBoxLayout()
url_layout.addWidget(self.url_label)
url_layout.addWidget(self.copy_url_button)
- # url fields start hidden, until there's a URL
- self.url_label.hide()
- self.copy_url_button.hide()
# add the widgets
self.addLayout(server_layout)
@@ -65,6 +69,15 @@ class ServerStatus(QtGui.QVBoxLayout):
elif self.status == self.STATUS_STARTED:
self.status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.status_image_started))
+ # set the URL fields
+ if self.status == self.STATUS_STARTED:
+ self.url_label.setText('http://{0}/ {1}'.format(self.app.onion_host, self.web.slug))
+ self.url_label.show()
+ self.copy_url_button.show()
+ else:
+ self.url_label.hide()
+ self.copy_url_button.hide()
+
# buttons enabled
if self.file_selection.get_num_files() == 0:
self.start_server_button.setEnabled(False)
@@ -82,11 +95,39 @@ class ServerStatus(QtGui.QVBoxLayout):
self.update()
self.server_started.emit()
+ def start_server_finished(self):
+ self.status = self.STATUS_STARTED
+ self.update()
+
def stop_server(self):
- self.status = self.STATUS_STOPPED
+ self.status = self.STATUS_WORKING
self.update()
self.server_stopped.emit()
+ def stop_server_finished(self):
+ self.status = self.STATUS_STOPPED
+ self.update()
+
def copy_url(self):
- pass
+ url = 'http://{0}/{1}'.format(self.app.onion_host, self.web.slug)
+
+ if platform.system() == 'Windows':
+ # Qt's QClipboard isn't working in Windows
+ # https://github.com/micahflee/onionshare/issues/46
+ import ctypes
+ GMEM_DDESHARE = 0x2000
+ ctypes.windll.user32.OpenClipboard(None)
+ ctypes.windll.user32.EmptyClipboard()
+ hcd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(url))+1)
+ pch_data = ctypes.windll.kernel32.GlobalLock(hcd)
+ ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pch_data), bytes(url))
+ ctypes.windll.kernel32.GlobalUnlock(hcd)
+ ctypes.windll.user32.SetClipboardData(1, hcd)
+ ctypes.windll.user32.CloseClipboard()
+ else:
+ clipboard = self.qtapp.clipboard()
+ clipboard.setText(url)
+
+ # todo: make this systray popup work
+ self.systray.showMessage(QtCore.QString("OnionShare"), QtCore.QString(strings._('gui_copied_url')))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/onionshare.git
More information about the Pkg-anonymity-tools
mailing list