From 0c6dbe4c8a08c3372fa1707a4afc2611e2bdd535 Mon Sep 17 00:00:00 2001 From: hiro Date: Tue, 23 Apr 2019 16:03:50 +0200 Subject: [PATCH] Clean ui, add strings, fix web listing logic --- onionshare/web/website_mode.py | 13 +++-- onionshare_gui/mode/history.py | 21 ++++++++ onionshare_gui/mode/website_mode/__init__.py | 57 +++----------------- share/locale/en.json | 2 + 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/onionshare/web/website_mode.py b/onionshare/web/website_mode.py index 51137183..65e486e6 100644 --- a/onionshare/web/website_mode.py +++ b/onionshare/web/website_mode.py @@ -81,24 +81,27 @@ class WebsiteModeWeb(object): self.web.add_request(self.web.REQUEST_LOAD, request.path) + print(self.file_info) + + filelist = [] if self.file_info['files']: self.website_folder = os.path.dirname(self.file_info['files'][0]['filename']) + filelist = [v['basename'] for v in self.file_info['files']] elif self.file_info['dirs']: self.website_folder = self.file_info['dirs'][0]['filename'] + filelist = os.listdir(self.website_folder) else: return self.web.error404() - if any((fname == 'index.html') for fname in os.listdir(self.website_folder)): + if any((fname == 'index.html') for fname in filelist): self.web.app.static_url_path = self.website_folder self.web.app.static_folder = self.website_folder if not os.path.isfile(os.path.join(self.website_folder, page_path)): page_path = os.path.join(page_path, 'index.html') - return send_from_directory(self.website_folder, page_path) - - elif any(os.path.isfile(os.path.join(self.website_folder, i)) for i in os.listdir(self.website_folder)): + elif any(os.path.isfile(os.path.join(self.website_folder, i)) for i in filelist): filenames = [] - for i in os.listdir(self.website_folder): + for i in filelist: filenames.append(os.path.join(self.website_folder, i)) self.set_file_info(filenames) diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index 1546cb68..34cd8306 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -341,6 +341,27 @@ class ReceiveHistoryItem(HistoryItem): self.label.setText(self.get_canceled_label_text(self.started)) +class VisitHistoryItem(HistoryItem): + """ + Download history item, for share mode + """ + def __init__(self, common, id, total_bytes): + super(VisitHistoryItem, self).__init__() + self.common = common + + self.id = id + self.visited = time.time() + 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"))) + + # Layout + layout = QtWidgets.QVBoxLayout() + layout.addWidget(self.label) + self.setLayout(layout) + + class HistoryItemList(QtWidgets.QScrollArea): """ List of items diff --git a/onionshare_gui/mode/website_mode/__init__.py b/onionshare_gui/mode/website_mode/__init__.py index e10da8b9..e2c5bd72 100644 --- a/onionshare_gui/mode/website_mode/__init__.py +++ b/onionshare_gui/mode/website_mode/__init__.py @@ -27,7 +27,7 @@ from onionshare.web import Web from ..file_selection import FileSelection from .. import Mode -from ..history import History, ToggleHistory, DownloadHistoryItem +from ..history import History, ToggleHistory, VisitHistoryItem from ...widgets import Alert class WebsiteMode(Mode): @@ -130,7 +130,7 @@ class WebsiteMode(Mode): The shutdown 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.download_count == 0 or self.web.done: + 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 @@ -144,7 +144,7 @@ class WebsiteMode(Mode): Starting the server. """ # Reset web counters - self.web.website_mode.download_count = 0 + self.web.website_mode.visit_count = 0 self.web.error404_count = 0 # Hide and reset the downloads if we have previously shared @@ -201,11 +201,10 @@ class WebsiteMode(Mode): def cancel_server_custom(self): """ - Stop the compression thread on cancel + Log that the server has been cancelled """ - if self.compress_thread: - self.common.log('WebsiteMode', 'cancel_server: quitting compress thread') - self.compress_thread.quit() + self.common.log('WebsiteMode', 'cancel_server') + def handle_tor_broke_custom(self): """ @@ -217,7 +216,7 @@ class WebsiteMode(Mode): """ Handle REQUEST_LOAD event. """ - self.system_tray.showMessage(strings._('systray_page_loaded_title'), strings._('systray_download_page_loaded_message')) + self.system_tray.showMessage(strings._('systray_site_loaded_title'), strings._('systray_site_page_loaded_message')) def handle_request_started(self, event): """ @@ -226,52 +225,12 @@ class WebsiteMode(Mode): filesize = self.web.website_mode.download_filesize - item = DownloadHistoryItem(self.common, event["data"]["id"], filesize) + 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() - self.system_tray.showMessage(strings._('systray_download_started_title'), strings._('systray_download_started_message')) - - def handle_request_progress(self, event): - """ - Handle REQUEST_PROGRESS event. - """ - self.history.update(event["data"]["id"], event["data"]["bytes"]) - - # Is the download complete? - if event["data"]["bytes"] == self.web.website_mode.filesize: - self.system_tray.showMessage(strings._('systray_download_completed_title'), strings._('systray_download_completed_message')) - - # Update completed and in progress labels - self.history.completed_count += 1 - self.history.in_progress_count -= 1 - self.history.update_completed() - self.history.update_in_progress() - - # Close on finish? - if self.common.settings.get('close_after_first_download'): - self.server_status.stop_server() - self.status_bar.clearMessage() - self.server_status_label.setText(strings._('closing_automatically')) - else: - if self.server_status.status == self.server_status.STATUS_STOPPED: - self.history.cancel(event["data"]["id"]) - self.history.in_progress_count = 0 - self.history.update_in_progress() - - def handle_request_canceled(self, event): - """ - Handle REQUEST_CANCELED event. - """ - self.history.cancel(event["data"]["id"]) - - # Update in progress count - self.history.in_progress_count -= 1 - self.history.update_in_progress() - self.system_tray.showMessage(strings._('systray_download_canceled_title'), strings._('systray_download_canceled_message')) - def on_reload_settings(self): """ If there were some files listed for sharing, we should be ok to re-enable diff --git a/share/locale/en.json b/share/locale/en.json index 926f6f43..dafd20d1 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -114,6 +114,7 @@ "gui_use_legacy_v2_onions_checkbox": "Use legacy addresses", "gui_save_private_key_checkbox": "Use a persistent address", "gui_share_url_description": "Anyone with this OnionShare address can download your files using the Tor Browser: ", + "gui_website_url_description": "Anyone with this OnionShare address can visit your website using the Tor Browser: ", "gui_receive_url_description": "Anyone with this OnionShare address can upload files to your computer using the Tor Browser: ", "gui_url_label_persistent": "This share will not auto-stop.

Every subsequent share reuses the address. (To use one-time addresses, turn off \"Use persistent address\" in the settings.)", "gui_url_label_stay_open": "This share will not auto-stop.", @@ -168,6 +169,7 @@ "gui_share_mode_autostop_timer_waiting": "Waiting to finish sending", "gui_receive_mode_no_files": "No Files Received Yet", "gui_receive_mode_autostop_timer_waiting": "Waiting to finish receiving", + "gui_visit_started": "Someone has visited your website {}", "receive_mode_upload_starting": "Upload of total size {} is starting", "days_first_letter": "d", "hours_first_letter": "h",