mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-29 08:47:18 -04:00
made it so clicking Start Server actually starts the server, and made the URL fields hide/show appropriately, and the Copy URL button work
This commit is contained in:
parent
349ca67cc9
commit
5325b7b173
4 changed files with 78 additions and 26 deletions
|
@ -34,6 +34,7 @@ class OnionShare(object):
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
elif os.path.isdir(filename):
|
elif os.path.isdir(filename):
|
||||||
shutil.rmtree(filename)
|
shutil.rmtree(filename)
|
||||||
|
self.cleanup_filenames = []
|
||||||
|
|
||||||
def choose_port(self):
|
def choose_port(self):
|
||||||
# let the OS choose a port
|
# let the OS choose a port
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
"filename": "Filename",
|
"filename": "Filename",
|
||||||
"size": "Size",
|
"size": "Size",
|
||||||
"sha1_checksum": "SHA1 checksum",
|
"sha1_checksum": "SHA1 checksum",
|
||||||
"copied_url": "Copied URL to clipboard",
|
|
||||||
"download_page_loaded": "Download page loaded",
|
"download_page_loaded": "Download page loaded",
|
||||||
"download_started": "Download started",
|
"download_started": "Download started",
|
||||||
"download_finished": "Download finished",
|
"download_finished": "Download finished",
|
||||||
|
@ -35,7 +34,8 @@
|
||||||
"gui_start_server": "Start Server",
|
"gui_start_server": "Start Server",
|
||||||
"gui_stop_server": "Stop Server",
|
"gui_stop_server": "Stop Server",
|
||||||
"gui_copy_url": "Copy URL",
|
"gui_copy_url": "Copy URL",
|
||||||
"gui_downloads": "Downloads:"
|
"gui_downloads": "Downloads:",
|
||||||
|
"gui_copied_url": "Copied URL to clipboard"
|
||||||
}, "no": {
|
}, "no": {
|
||||||
"calculating_sha1": "Kalkulerer SHA1 sjekksum.",
|
"calculating_sha1": "Kalkulerer SHA1 sjekksum.",
|
||||||
"connecting_ctrlport": "Kobler til Tors kontroll-port for å sette opp en gjemt tjeneste på port {0}.",
|
"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.",
|
"not_a_file": "{0} er ikke en fil.",
|
||||||
"filesize": "Filstørrelse",
|
"filesize": "Filstørrelse",
|
||||||
"sha1_checksum": "SHA1 sjekksum",
|
"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_page_loaded": "Nedlastingsside lastet",
|
||||||
"download_started": "Nedlasting startet",
|
"download_started": "Nedlasting startet",
|
||||||
"download_finished": "Nedlasting fullført",
|
"download_finished": "Nedlasting fullført",
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
"not_a_file": "{0} no es un archivo.",
|
"not_a_file": "{0} no es un archivo.",
|
||||||
"filesize": "Tamaño del archivo",
|
"filesize": "Tamaño del archivo",
|
||||||
"sha1_checksum": "Suma de verificación SHA1",
|
"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_page_loaded": "Descargar página cargada.",
|
||||||
"download_started": "Descarga comenzó",
|
"download_started": "Descarga comenzó",
|
||||||
"download_finished": "Descarga terminado",
|
"download_finished": "Descarga terminado",
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
"not_a_file": "{0} non è un file.",
|
"not_a_file": "{0} non è un file.",
|
||||||
"filesize": "Grandezza del file",
|
"filesize": "Grandezza del file",
|
||||||
"sha1_checksum": "Firma SHA1",
|
"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_page_loaded": "Pagina di download caricata",
|
||||||
"download_started": "Download iniziato",
|
"download_started": "Download iniziato",
|
||||||
"download_finished": "Download finito",
|
"download_finished": "Download finito",
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
"not_a_file": "{0} is geen bestand.",
|
"not_a_file": "{0} is geen bestand.",
|
||||||
"filesize": "Bestandsgrootte",
|
"filesize": "Bestandsgrootte",
|
||||||
"sha1_checksum": "SHA1 controlecijfer",
|
"sha1_checksum": "SHA1 controlecijfer",
|
||||||
"copied_url": "URL gekopieerd naar klembord",
|
"gui_copied_url": "URL gekopieerd naar klembord",
|
||||||
"download_page_loaded": "Download pagina geladen",
|
"download_page_loaded": "Download pagina geladen",
|
||||||
"download_started": "Download gestart",
|
"download_started": "Download gestart",
|
||||||
"download_finished": "Download voltooid",
|
"download_finished": "Download voltooid",
|
||||||
|
@ -135,7 +135,7 @@
|
||||||
"not_a_file": "{0} não é um arquivo.",
|
"not_a_file": "{0} não é um arquivo.",
|
||||||
"filesize": "Tamanho de arquivo",
|
"filesize": "Tamanho de arquivo",
|
||||||
"sha1_checksum": "Checksum SHA1",
|
"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_page_loaded": "Página de download carregada",
|
||||||
"download_started": "Começou o download",
|
"download_started": "Começou o download",
|
||||||
"download_finished": "Terminou o download",
|
"download_finished": "Terminou o download",
|
||||||
|
@ -153,7 +153,7 @@
|
||||||
"not_a_file": "{0} не является файлом.",
|
"not_a_file": "{0} не является файлом.",
|
||||||
"filesize": "Размер файла",
|
"filesize": "Размер файла",
|
||||||
"sha1_checksum": "SHA1 хешсумма",
|
"sha1_checksum": "SHA1 хешсумма",
|
||||||
"copied_url": "Ссылка скопирована в буфер обмена",
|
"gui_copied_url": "Ссылка скопирована в буфер обмена",
|
||||||
"download_page_loaded": "Страница закачки загружена",
|
"download_page_loaded": "Страница закачки загружена",
|
||||||
"download_started": "Загрузка начата",
|
"download_started": "Загрузка начата",
|
||||||
"download_finished": "Загрузка закончена",
|
"download_finished": "Загрузка закончена",
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
"not_a_file": "{0} ist keine Datei.",
|
"not_a_file": "{0} ist keine Datei.",
|
||||||
"filesize": "Dateigröße",
|
"filesize": "Dateigröße",
|
||||||
"sha1_checksum": "SHA1 Checksumme",
|
"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_page_loaded": "Download-Seite geladen",
|
||||||
"download_started": "Download gestartet",
|
"download_started": "Download gestartet",
|
||||||
"download_finished": "Download abgeschlossen",
|
"download_finished": "Download abgeschlossen",
|
||||||
|
@ -192,7 +192,7 @@
|
||||||
"not_a_file": "{0} dosya değil.",
|
"not_a_file": "{0} dosya değil.",
|
||||||
"filesize": "Dosya boyutu",
|
"filesize": "Dosya boyutu",
|
||||||
"sha1_checksum": "SHA1 özeti",
|
"sha1_checksum": "SHA1 özeti",
|
||||||
"copied_url": "Panoya kopyalanan URL",
|
"gui_copied_url": "Panoya kopyalanan URL",
|
||||||
"download_page_loaded": "İndirme sayfası yüklendi",
|
"download_page_loaded": "İndirme sayfası yüklendi",
|
||||||
"download_started": "İndirme başladı",
|
"download_started": "İndirme başladı",
|
||||||
"download_finished": "İndirme bitti",
|
"download_finished": "İndirme bitti",
|
||||||
|
|
|
@ -24,8 +24,9 @@ class Application(QtGui.QApplication):
|
||||||
QtGui.QApplication.__init__(self, sys.argv)
|
QtGui.QApplication.__init__(self, sys.argv)
|
||||||
|
|
||||||
class OnionShareGui(QtGui.QWidget):
|
class OnionShareGui(QtGui.QWidget):
|
||||||
def __init__(self, app):
|
def __init__(self, qtapp, app):
|
||||||
super(OnionShareGui, self).__init__()
|
super(OnionShareGui, self).__init__()
|
||||||
|
self.qtapp = qtapp
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
self.setWindowTitle('OnionShare')
|
self.setWindowTitle('OnionShare')
|
||||||
|
@ -33,18 +34,18 @@ class OnionShareGui(QtGui.QWidget):
|
||||||
|
|
||||||
def send_files(self, filenames=None):
|
def send_files(self, filenames=None):
|
||||||
# file selection
|
# file selection
|
||||||
file_selection = FileSelection()
|
self.file_selection = FileSelection()
|
||||||
if filenames:
|
if filenames:
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
file_selection.file_list.add_file(filename)
|
self.file_selection.file_list.add_file(filename)
|
||||||
|
|
||||||
# server status
|
# server status
|
||||||
self.server_status = ServerStatus(file_selection)
|
self.server_status = ServerStatus(self.qtapp, self.app, web, self.file_selection)
|
||||||
self.server_status.server_started.connect(file_selection.server_started)
|
self.server_status.server_started.connect(self.file_selection.server_started)
|
||||||
self.server_status.server_started.connect(self.start_server)
|
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)
|
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 = Downloads()
|
downloads = Downloads()
|
||||||
|
@ -54,7 +55,7 @@ class OnionShareGui(QtGui.QWidget):
|
||||||
|
|
||||||
# main layout
|
# main layout
|
||||||
self.layout = QtGui.QVBoxLayout()
|
self.layout = QtGui.QVBoxLayout()
|
||||||
self.layout.addLayout(file_selection)
|
self.layout.addLayout(self.file_selection)
|
||||||
self.layout.addLayout(self.server_status)
|
self.layout.addLayout(self.server_status)
|
||||||
self.layout.addLayout(downloads)
|
self.layout.addLayout(downloads)
|
||||||
self.layout.addLayout(options)
|
self.layout.addLayout(options)
|
||||||
|
@ -79,9 +80,18 @@ class OnionShareGui(QtGui.QWidget):
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
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):
|
def stop_server(self):
|
||||||
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
|
# 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()
|
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):
|
def alert(msg, icon=QtGui.QMessageBox.NoIcon):
|
||||||
dialog = QtGui.QMessageBox()
|
dialog = QtGui.QMessageBox()
|
||||||
|
@ -139,7 +149,7 @@ def main():
|
||||||
qtapp.connect(qtapp, QtCore.SIGNAL("aboutToQuit()"), shutdown)
|
qtapp.connect(qtapp, QtCore.SIGNAL("aboutToQuit()"), shutdown)
|
||||||
|
|
||||||
# launch the gui
|
# launch the gui
|
||||||
gui = OnionShareGui(app)
|
gui = OnionShareGui(qtapp, app)
|
||||||
gui.send_files(filenames)
|
gui.send_files(filenames)
|
||||||
|
|
||||||
# all done
|
# all done
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import platform
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
@ -11,13 +12,19 @@ class ServerStatus(QtGui.QVBoxLayout):
|
||||||
STATUS_WORKING = 1
|
STATUS_WORKING = 1
|
||||||
STATUS_STARTED = 2
|
STATUS_STARTED = 2
|
||||||
|
|
||||||
def __init__(self, file_selection):
|
def __init__(self, qtapp, app, web, file_selection):
|
||||||
super(ServerStatus, self).__init__()
|
super(ServerStatus, self).__init__()
|
||||||
self.status = self.STATUS_STOPPED
|
self.status = self.STATUS_STOPPED
|
||||||
self.addSpacing(10)
|
self.addSpacing(10)
|
||||||
|
|
||||||
|
self.qtapp = qtapp
|
||||||
|
self.app = app
|
||||||
|
self.web = web
|
||||||
self.file_selection = file_selection
|
self.file_selection = file_selection
|
||||||
|
|
||||||
|
# system tray icon (for notifications)
|
||||||
|
self.systray = QtGui.QSystemTrayIcon()
|
||||||
|
|
||||||
# server layout
|
# server layout
|
||||||
self.status_image_stopped = QtGui.QImage('{0}/server_stopped.png'.format(common.onionshare_gui_dir))
|
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))
|
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 = QtGui.QHBoxLayout()
|
||||||
url_layout.addWidget(self.url_label)
|
url_layout.addWidget(self.url_label)
|
||||||
url_layout.addWidget(self.copy_url_button)
|
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
|
# add the widgets
|
||||||
self.addLayout(server_layout)
|
self.addLayout(server_layout)
|
||||||
|
@ -65,6 +69,15 @@ class ServerStatus(QtGui.QVBoxLayout):
|
||||||
elif self.status == self.STATUS_STARTED:
|
elif self.status == self.STATUS_STARTED:
|
||||||
self.status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.status_image_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
|
# buttons enabled
|
||||||
if self.file_selection.get_num_files() == 0:
|
if self.file_selection.get_num_files() == 0:
|
||||||
self.start_server_button.setEnabled(False)
|
self.start_server_button.setEnabled(False)
|
||||||
|
@ -82,11 +95,39 @@ class ServerStatus(QtGui.QVBoxLayout):
|
||||||
self.update()
|
self.update()
|
||||||
self.server_started.emit()
|
self.server_started.emit()
|
||||||
|
|
||||||
|
def start_server_finished(self):
|
||||||
|
self.status = self.STATUS_STARTED
|
||||||
|
self.update()
|
||||||
|
|
||||||
def stop_server(self):
|
def stop_server(self):
|
||||||
self.status = self.STATUS_STOPPED
|
self.status = self.STATUS_WORKING
|
||||||
self.update()
|
self.update()
|
||||||
self.server_stopped.emit()
|
self.server_stopped.emit()
|
||||||
|
|
||||||
def copy_url(self):
|
def stop_server_finished(self):
|
||||||
pass
|
self.status = self.STATUS_STOPPED
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def copy_url(self):
|
||||||
|
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')))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue