mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-25 10:42:58 -03:00
Clean ui, add strings, fix web listing logic
This commit is contained in:
parent
391c82f2a6
commit
0c6dbe4c8a
4 changed files with 39 additions and 54 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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": "<b>Anyone</b> with this OnionShare address can <b>download</b> your files using the <b>Tor Browser</b>: <img src='{}' />",
|
||||
"gui_website_url_description": "<b>Anyone</b> with this OnionShare address can <b>visit</b> your website using the <b>Tor Browser</b>: <img src='{}' />",
|
||||
"gui_receive_url_description": "<b>Anyone</b> with this OnionShare address can <b>upload</b> files to your computer using the <b>Tor Browser</b>: <img src='{}' />",
|
||||
"gui_url_label_persistent": "This share will not auto-stop.<br><br>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",
|
||||
|
|
Loading…
Add table
Reference in a new issue