Refactor ReceiveMode and Downloads, to push more download-related logic into Downloads

This commit is contained in:
Micah Lee 2018-05-04 16:06:24 -07:00
parent ed28fdf123
commit 30c9f50d2e
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 20 additions and 25 deletions

View File

@ -71,7 +71,6 @@ class ShareMode(Mode):
self.downloads = Downloads(self.common) self.downloads = Downloads(self.common)
self.downloads_in_progress = 0 self.downloads_in_progress = 0
self.downloads_completed = 0 self.downloads_completed = 0
self.new_download = False # For scrolling to the bottom of the downloads list
# Information about share, and show downloads button # Information about share, and show downloads button
self.info_label = QtWidgets.QLabel() self.info_label = QtWidgets.QLabel()
@ -118,15 +117,6 @@ class ShareMode(Mode):
# Always start with focus on file selection # Always start with focus on file selection
self.file_selection.setFocus() self.file_selection.setFocus()
def timer_callback_custom(self):
"""
This method is called regularly on a timer while share mode is active.
"""
# Scroll to the bottom of the download progress bar log pane if a new download has been added
if self.new_download:
self.downloads.downloads_container.vbar.setValue(self.downloads.downloads_container.vbar.maximum())
self.new_download = False
def get_stop_server_shutdown_timeout_text(self): def get_stop_server_shutdown_timeout_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 a shutdown timeout
@ -156,7 +146,6 @@ class ShareMode(Mode):
self.web.error404_count = 0 self.web.error404_count = 0
# Hide and reset the downloads if we have previously shared # Hide and reset the downloads if we have previously shared
self.downloads.reset_downloads()
self.reset_info_counters() self.reset_info_counters()
def start_server_step2_custom(self): def start_server_step2_custom(self):
@ -250,9 +239,7 @@ class ShareMode(Mode):
""" """
Handle REQUEST_DOWNLOAD event. Handle REQUEST_DOWNLOAD event.
""" """
self.downloads.no_downloads_label.hide()
self.downloads.add_download(event["data"]["id"], self.web.zip_filesize) self.downloads.add_download(event["data"]["id"], self.web.zip_filesize)
self.new_download = True
self.downloads_in_progress += 1 self.downloads_in_progress += 1
self.update_downloads_in_progress() self.update_downloads_in_progress()
@ -351,8 +338,7 @@ class ShareMode(Mode):
self.update_downloads_completed() self.update_downloads_completed()
self.update_downloads_in_progress() self.update_downloads_in_progress()
self.info_show_downloads.setIcon(QtGui.QIcon(self.common.get_resource_path('images/download_window_gray.png'))) self.info_show_downloads.setIcon(QtGui.QIcon(self.common.get_resource_path('images/download_window_gray.png')))
self.downloads.no_downloads_label.show() self.downloads.reset_downloads()
self.downloads.downloads_container.resize(self.downloads.downloads_container.sizeHint())
def update_downloads_completed(self): def update_downloads_completed(self):
""" """

View File

@ -131,11 +131,17 @@ class Downloads(QtWidgets.QWidget):
""" """
Add a new download progress bar. Add a new download progress bar.
""" """
# add it to the list # Hide the no_downloads_label
self.no_downloads_label.hide()
# Add it to the list
download = Download(self.common, download_id, total_bytes) download = Download(self.common, download_id, total_bytes)
self.downloads[download_id] = download self.downloads[download_id] = download
self.downloads_layout.addWidget(download.progress_bar) self.downloads_layout.addWidget(download.progress_bar)
# Scroll to the bottom
self.downloads_container.vbar.setValue(self.downloads_container.vbar.maximum())
def update_download(self, download_id, downloaded_bytes): def update_download(self, download_id, downloaded_bytes):
""" """
Update the progress of a download progress bar. Update the progress of a download progress bar.
@ -156,3 +162,6 @@ class Downloads(QtWidgets.QWidget):
self.downloads_layout.removeWidget(download.progress_bar) self.downloads_layout.removeWidget(download.progress_bar)
download.progress_bar.close() download.progress_bar.close()
self.downloads = {} self.downloads = {}
self.no_downloads_label.show()
self.downloads_container.resize(self.downloads_container.sizeHint())