summaryrefslogtreecommitdiff
path: root/onionshare_gui
diff options
context:
space:
mode:
authorhiro <hiro@torproject.org>2019-05-08 00:04:09 +0200
committerhiro <hiro@torproject.org>2019-05-08 00:04:09 +0200
commitabc30b315ce77a6a2dd4b8a8d24f7c478a33c7c5 (patch)
tree300f1d0b03b9d750891aee21fa30efbb0e0110b4 /onionshare_gui
parent8f7e52e4eee84d31b1b568ba43db23f6f5f49f1d (diff)
downloadonionshare-abc30b315ce77a6a2dd4b8a8d24f7c478a33c7c5.tar.gz
onionshare-abc30b315ce77a6a2dd4b8a8d24f7c478a33c7c5.zip
Clean code and fix UI bugs
Diffstat (limited to 'onionshare_gui')
-rw-r--r--onionshare_gui/mode/history.py34
-rw-r--r--onionshare_gui/mode/website_mode/__init__.py59
2 files changed, 51 insertions, 42 deletions
diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py
index 34cd8306..51b36f9a 100644
--- a/onionshare_gui/mode/history.py
+++ b/onionshare_gui/mode/history.py
@@ -347,6 +347,7 @@ class VisitHistoryItem(HistoryItem):
"""
def __init__(self, common, id, total_bytes):
super(VisitHistoryItem, self).__init__()
+ self.status = HistoryItem.STATUS_STARTED
self.common = common
self.id = id
@@ -354,13 +355,20 @@ class VisitHistoryItem(HistoryItem):
self.visited_dt = datetime.fromtimestamp(self.visited)
# Label
- self.label = QtWidgets.QLabel(strings._('gui_visit_started').format(self.started_dt.strftime("%b %d, %I:%M%p")))
+ self.label = QtWidgets.QLabel(strings._('gui_visit_started').format(self.visited_dt.strftime("%b %d, %I:%M%p")))
# Layout
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.label)
self.setLayout(layout)
+ def update(self):
+ self.label.setText(self.get_finished_label_text(self.started_dt))
+ self.status = HistoryItem.STATUS_FINISHED
+
+ def cancel(self):
+ self.progress_bar.setFormat(strings._('gui_canceled'))
+ self.status = HistoryItem.STATUS_CANCELED
class HistoryItemList(QtWidgets.QScrollArea):
"""
@@ -425,19 +433,19 @@ class HistoryItemList(QtWidgets.QScrollArea):
Reset all items, emptying the list. Override this method.
"""
for key, item in self.items.copy().items():
- if item.status != HistoryItem.STATUS_STARTED:
- self.items_layout.removeWidget(item)
- item.close()
- del self.items[key]
+ self.items_layout.removeWidget(item)
+ item.close()
+ del self.items[key]
class History(QtWidgets.QWidget):
"""
A history of what's happened so far in this mode. This contains an internal
object full of a scrollable list of items.
"""
- def __init__(self, common, empty_image, empty_text, header_text):
+ def __init__(self, common, empty_image, empty_text, header_text, mode=''):
super(History, self).__init__()
self.common = common
+ self.mode = mode
self.setMinimumWidth(350)
@@ -556,12 +564,14 @@ class History(QtWidgets.QWidget):
"""
Update the 'in progress' widget.
"""
- if self.in_progress_count == 0:
- image = self.common.get_resource_path('images/share_in_progress_none.png')
- else:
- image = self.common.get_resource_path('images/share_in_progress.png')
- self.in_progress_label.setText('<img src="{0:s}" /> {1:d}'.format(image, self.in_progress_count))
- self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip').format(self.in_progress_count))
+ if self.mode != 'website':
+ if self.in_progress_count == 0:
+ image = self.common.get_resource_path('images/share_in_progress_none.png')
+ else:
+ image = self.common.get_resource_path('images/share_in_progress.png')
+
+ self.in_progress_label.setText('<img src="{0:s}" /> {1:d}'.format(image, self.in_progress_count))
+ self.in_progress_label.setToolTip(strings._('history_in_progress_tooltip').format(self.in_progress_count))
class ToggleHistory(QtWidgets.QPushButton):
diff --git a/onionshare_gui/mode/website_mode/__init__.py b/onionshare_gui/mode/website_mode/__init__.py
index 156f578e..06212b02 100644
--- a/onionshare_gui/mode/website_mode/__init__.py
+++ b/onionshare_gui/mode/website_mode/__init__.py
@@ -18,6 +18,10 @@ 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 os
+import secrets
+import random
+import string
+
from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings
@@ -41,9 +45,6 @@ class WebsiteMode(Mode):
"""
Custom initialization for ReceiveMode.
"""
- # Threads start out as None
- self.compress_thread = None
-
# Create the Web object
self.web = Web(self.common, True, 'website')
@@ -76,8 +77,9 @@ class WebsiteMode(Mode):
self.history = History(
self.common,
QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/share_icon_transparent.png'))),
- strings._('gui_share_mode_no_files'),
- strings._('gui_all_modes_history')
+ strings._('gui_website_mode_no_files'),
+ strings._('gui_all_modes_history'),
+ 'website'
)
self.history.hide()
@@ -88,8 +90,8 @@ class WebsiteMode(Mode):
# Toggle history
self.toggle_history = ToggleHistory(
self.common, self, self.history,
- QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')),
- QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png'))
+ QtGui.QIcon(self.common.get_resource_path('images/share_icon_toggle.png')),
+ QtGui.QIcon(self.common.get_resource_path('images/share_icon_toggle_selected.png'))
)
# Top bar
@@ -113,31 +115,27 @@ class WebsiteMode(Mode):
# Wrapper layout
self.wrapper_layout = QtWidgets.QHBoxLayout()
self.wrapper_layout.addLayout(self.main_layout)
- self.wrapper_layout.addWidget(self.history)
+ self.wrapper_layout.addWidget(self.history, stretch=1)
self.setLayout(self.wrapper_layout)
# Always start with focus on file selection
self.file_selection.setFocus()
- def get_stop_server_shutdown_timeout_text(self):
+ def get_stop_server_autostop_timer_text(self):
"""
- Return the string to put on the stop server button, if there's a shutdown timeout
+ Return the string to put on the stop server button, if there's an auto-stop timer
"""
- return strings._('gui_share_stop_server_shutdown_timeout')
+ return strings._('gui_share_stop_server_autostop_timer')
- def timeout_finished_should_stop_server(self):
+ def autostop_timer_finished_should_stop_server(self):
"""
- The shutdown timer expired, should we stop the server? Returns a bool
+ The auto-stop timer expired, should we stop the server? Returns a bool
"""
- # If there were no attempts to download the share, or all downloads are done, we can stop
- if self.web.website_mode.visit_count == 0 or self.web.done:
- self.server_status.stop_server()
- self.server_status_label.setText(strings._('close_on_timeout'))
- return True
- # A download is probably still running - hold off on stopping the share
- else:
- self.server_status_label.setText(strings._('timeout_download_still_running'))
- return False
+
+ self.server_status.stop_server()
+ self.server_status_label.setText(strings._('close_on_autostop_timer'))
+ return True
+
def start_server_custom(self):
"""
@@ -194,9 +192,7 @@ class WebsiteMode(Mode):
"""
self.filesize_warning.hide()
- self.history.in_progress_count = 0
self.history.completed_count = 0
- self.history.update_in_progress()
self.file_selection.file_list.adjustSize()
def cancel_server_custom(self):
@@ -222,14 +218,17 @@ class WebsiteMode(Mode):
"""
Handle REQUEST_STARTED event.
"""
+ if ( (event["path"] == '') or (event["path"].find(".htm") != -1 ) ):
+ filesize = self.web.website_mode.download_filesize
+ item = VisitHistoryItem(self.common, event["data"]["id"], filesize)
+
+ self.history.add(event["data"]["id"], item)
+ self.toggle_history.update_indicator(True)
+ self.history.completed_count += 1
+ self.history.update_completed()
- filesize = self.web.website_mode.download_filesize
+ self.system_tray.showMessage(strings._('systray_website_started_title'), strings._('systray_website_started_message'))
- item = VisitHistoryItem(self.common, event["data"]["id"], filesize)
- self.history.add(event["data"]["id"], item)
- self.toggle_history.update_indicator(True)
- self.history.in_progress_count += 1
- self.history.update_in_progress()
def on_reload_settings(self):
"""