Start creating the information widget for receive mode, and refactor for share mode

This commit is contained in:
Micah Lee 2018-05-03 09:29:54 -07:00
parent 65dff32702
commit 07152ad969
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 82 additions and 24 deletions

View File

@ -44,6 +44,38 @@ class ReceiveMode(Mode):
self.server_status.web = self.web
self.server_status.update()
# Downloads
#self.uploads = Uploads(self.common)
self.uploads_in_progress = 0
self.uploads_completed = 0
self.new_upload = False # For scrolling to the bottom of the uploads list
# Information about share, and show uploads button
self.info_show_uploads = QtWidgets.QToolButton()
self.info_show_uploads.setIcon(QtGui.QIcon(self.common.get_resource_path('images/download_window_gray.png')))
self.info_show_uploads.setCheckable(True)
#self.info_show_uploads.toggled.connect(self.downloads_toggled)
self.info_show_uploads.setToolTip(strings._('gui_downloads_window_tooltip', True))
self.info_in_progress_uploads_count = QtWidgets.QLabel()
self.info_in_progress_uploads_count.setStyleSheet('QLabel { font-size: 12px; color: #666666; }')
self.info_completed_uploads_count = QtWidgets.QLabel()
self.info_completed_uploads_count.setStyleSheet('QLabel { font-size: 12px; color: #666666; }')
self.update_uploads_completed()
self.update_uploads_in_progress()
self.info_layout = QtWidgets.QHBoxLayout()
self.info_layout.addStretch()
self.info_layout.addWidget(self.info_in_progress_uploads_count)
self.info_layout.addWidget(self.info_completed_uploads_count)
self.info_layout.addWidget(self.info_show_uploads)
self.info_widget = QtWidgets.QWidget()
self.info_widget.setLayout(self.info_layout)
self.info_widget.hide()
# Receive mode info
self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True))
self.receive_info.setMinimumHeight(80)
@ -51,6 +83,7 @@ class ReceiveMode(Mode):
# Layout
self.layout.insertWidget(0, self.receive_info)
self.layout.insertWidget(0, self.info_widget)
def timer_callback_custom(self):
"""
@ -105,3 +138,26 @@ class ReceiveMode(Mode):
"""
self.stop_server()
self.system_tray.showMessage(strings._('systray_close_server_title', True), strings._('systray_close_server_message', True))
def update_uploads_completed(self):
"""
Update the 'Downloads completed' info widget.
"""
if self.uploads_completed == 0:
image = self.common.get_resource_path('images/download_completed_none.png')
else:
image = self.common.get_resource_path('images/download_completed.png')
self.info_completed_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.uploads_completed))
self.info_completed_uploads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.uploads_completed))
def update_uploads_in_progress(self):
"""
Update the 'Downloads in progress' info widget.
"""
if self.uploads_in_progress == 0:
image = self.common.get_resource_path('images/download_in_progress_none.png')
else:
image = self.common.get_resource_path('images/download_in_progress.png')
self.info_show_uploads.setIcon(QtGui.QIcon(self.common.get_resource_path('images/download_window_green.png')))
self.info_in_progress_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.uploads_in_progress))
self.info_in_progress_uploads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.uploads_in_progress))

View File

@ -73,8 +73,7 @@ class ShareMode(Mode):
self.downloads_completed = 0
self.new_download = False # For scrolling to the bottom of the downloads list
# Info label along top of screen
self.info_layout = QtWidgets.QHBoxLayout()
# Information about share, and show downloads button
self.info_label = QtWidgets.QLabel()
self.info_label.setStyleSheet('QLabel { font-size: 12px; color: #666666; }')
@ -90,9 +89,10 @@ class ShareMode(Mode):
self.info_completed_downloads_count = QtWidgets.QLabel()
self.info_completed_downloads_count.setStyleSheet('QLabel { font-size: 12px; color: #666666; }')
self.update_downloads_completed(self.downloads_in_progress)
self.update_downloads_in_progress(self.downloads_in_progress)
self.update_downloads_completed()
self.update_downloads_in_progress()
self.info_layout = QtWidgets.QHBoxLayout()
self.info_layout.addWidget(self.info_label)
self.info_layout.addStretch()
self.info_layout.addWidget(self.info_in_progress_downloads_count)
@ -230,7 +230,7 @@ class ShareMode(Mode):
self.filesize_warning.hide()
self.downloads_in_progress = 0
self.downloads_completed = 0
self.update_downloads_in_progress(0)
self.update_downloads_in_progress()
self.file_selection.file_list.adjustSize()
def handle_tor_broke_custom(self):
@ -254,7 +254,7 @@ class ShareMode(Mode):
self.downloads.add_download(event["data"]["id"], self.web.zip_filesize)
self.new_download = True
self.downloads_in_progress += 1
self.update_downloads_in_progress(self.downloads_in_progress)
self.update_downloads_in_progress()
self.system_tray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True))
@ -270,10 +270,10 @@ class ShareMode(Mode):
# Update the total 'completed downloads' info
self.downloads_completed += 1
self.update_downloads_completed(self.downloads_completed)
self.update_downloads_completed()
# Update the 'in progress downloads' info
self.downloads_in_progress -= 1
self.update_downloads_in_progress(self.downloads_in_progress)
self.update_downloads_in_progress()
# close on finish?
if not self.web.stay_open:
@ -284,7 +284,7 @@ class ShareMode(Mode):
if self.server_status.status == self.server_status.STATUS_STOPPED:
self.downloads.cancel_download(event["data"]["id"])
self.downloads_in_progress = 0
self.update_downloads_in_progress(self.downloads_in_progress)
self.update_downloads_in_progress()
def handle_request_canceled(self, event):
"""
@ -294,7 +294,7 @@ class ShareMode(Mode):
# Update the 'in progress downloads' info
self.downloads_in_progress -= 1
self.update_downloads_in_progress(self.downloads_in_progress)
self.update_downloads_in_progress()
self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True))
def on_reload_settings(self):
@ -346,34 +346,36 @@ class ShareMode(Mode):
"""
Set the info counters back to zero.
"""
self.update_downloads_completed(0)
self.update_downloads_in_progress(0)
self.downloads_completed = 0
self.downloads_in_progress = 0
self.update_downloads_completed()
self.update_downloads_in_progress()
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.downloads_container.resize(self.downloads.downloads_container.sizeHint())
def update_downloads_completed(self, count):
def update_downloads_completed(self):
"""
Update the 'Downloads completed' info widget.
"""
if count == 0:
self.info_completed_downloads_image = self.common.get_resource_path('images/download_completed_none.png')
if self.downloads_completed == 0:
image = self.common.get_resource_path('images/download_completed_none.png')
else:
self.info_completed_downloads_image = self.common.get_resource_path('images/download_completed.png')
self.info_completed_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(self.info_completed_downloads_image, count))
self.info_completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(count))
image = self.common.get_resource_path('images/download_completed.png')
self.info_completed_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.downloads_completed))
self.info_completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.downloads_completed))
def update_downloads_in_progress(self, count):
def update_downloads_in_progress(self):
"""
Update the 'Downloads in progress' info widget.
"""
if count == 0:
self.info_in_progress_downloads_image = self.common.get_resource_path('images/download_in_progress_none.png')
if self.downloads_in_progress == 0:
image = self.common.get_resource_path('images/download_in_progress_none.png')
else:
self.info_in_progress_downloads_image = self.common.get_resource_path('images/download_in_progress.png')
image = self.common.get_resource_path('images/download_in_progress.png')
self.info_show_downloads.setIcon(QtGui.QIcon(self.common.get_resource_path('images/download_window_green.png')))
self.info_in_progress_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(self.info_in_progress_downloads_image, count))
self.info_in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(count))
self.info_in_progress_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.downloads_in_progress))
self.info_in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.downloads_in_progress))
@staticmethod
def _compute_total_size(filenames):