mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Refactor receive mode into using an info widget too
This commit is contained in:
parent
f056ce576e
commit
35065106ef
@ -452,7 +452,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
Recursively adjust size on all widgets. min_width is the new minimum width
|
||||
of the window.
|
||||
"""
|
||||
self.common.log("OnionShareGui", "adjust_size", "min_width={}".format(min_width))
|
||||
self.setMinimumWidth(min_width)
|
||||
|
||||
# Recursively adjust sizes for the modes
|
||||
|
@ -23,6 +23,7 @@ from onionshare import strings
|
||||
from onionshare.web import Web
|
||||
|
||||
from .uploads import Uploads
|
||||
from .info import ReceiveModeInfo
|
||||
from ..mode import Mode
|
||||
|
||||
class ReceiveMode(Mode):
|
||||
@ -54,32 +55,8 @@ class ReceiveMode(Mode):
|
||||
self.new_upload = False # For scrolling to the bottom of the uploads list
|
||||
|
||||
# Information about share, and show uploads button
|
||||
self.info_in_progress_uploads_count = QtWidgets.QLabel()
|
||||
self.info_in_progress_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
self.info_completed_uploads_count = QtWidgets.QLabel()
|
||||
self.info_completed_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
self.update_uploads_completed()
|
||||
self.update_uploads_in_progress()
|
||||
|
||||
self.info_toggle_button = QtWidgets.QPushButton()
|
||||
self.info_toggle_button.setDefault(False)
|
||||
self.info_toggle_button.setFixedWidth(30)
|
||||
self.info_toggle_button.setFixedHeight(30)
|
||||
self.info_toggle_button.setFlat(True)
|
||||
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) )
|
||||
self.info_toggle_button.clicked.connect(self.toggle_uploads)
|
||||
|
||||
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_toggle_button)
|
||||
|
||||
self.info_widget = QtWidgets.QWidget()
|
||||
self.info_widget.setLayout(self.info_layout)
|
||||
self.info_widget.hide()
|
||||
self.info = ReceiveModeInfo(self.common, self)
|
||||
self.info.show_less()
|
||||
|
||||
# Receive mode info
|
||||
self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True))
|
||||
@ -88,7 +65,7 @@ class ReceiveMode(Mode):
|
||||
|
||||
# Main layout
|
||||
self.main_layout = QtWidgets.QVBoxLayout()
|
||||
self.main_layout.addWidget(self.info_widget)
|
||||
self.main_layout.addWidget(self.info)
|
||||
self.main_layout.addWidget(self.receive_info)
|
||||
self.main_layout.addWidget(self.primary_action)
|
||||
self.main_layout.addStretch()
|
||||
@ -137,7 +114,7 @@ class ReceiveMode(Mode):
|
||||
Connection to Tor broke.
|
||||
"""
|
||||
self.primary_action.hide()
|
||||
self.info_widget.hide()
|
||||
self.info.show_less()
|
||||
|
||||
def handle_request_load(self, event):
|
||||
"""
|
||||
@ -151,7 +128,7 @@ class ReceiveMode(Mode):
|
||||
"""
|
||||
self.uploads.add(event["data"]["id"], event["data"]["content_length"])
|
||||
self.uploads_in_progress += 1
|
||||
self.update_uploads_in_progress()
|
||||
self.info.update_uploads_in_progress()
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_upload_started_title', True), strings._('systray_upload_started_message', True))
|
||||
|
||||
@ -181,17 +158,17 @@ class ReceiveMode(Mode):
|
||||
self.uploads.finished(event["data"]["id"])
|
||||
# Update the total 'completed uploads' info
|
||||
self.uploads_completed += 1
|
||||
self.update_uploads_completed()
|
||||
self.info.update_uploads_completed()
|
||||
# Update the 'in progress uploads' info
|
||||
self.uploads_in_progress -= 1
|
||||
self.update_uploads_in_progress()
|
||||
self.info.update_uploads_in_progress()
|
||||
|
||||
def on_reload_settings(self):
|
||||
"""
|
||||
We should be ok to re-enable the 'Start Receive Mode' button now.
|
||||
"""
|
||||
self.primary_action.show()
|
||||
self.info_widget.show()
|
||||
self.info.show_more()
|
||||
|
||||
def reset_info_counters(self):
|
||||
"""
|
||||
@ -199,61 +176,22 @@ class ReceiveMode(Mode):
|
||||
"""
|
||||
self.uploads_completed = 0
|
||||
self.uploads_in_progress = 0
|
||||
self.update_uploads_completed()
|
||||
self.update_uploads_in_progress()
|
||||
self.info.update_uploads_completed()
|
||||
self.info.update_uploads_in_progress()
|
||||
self.uploads.reset()
|
||||
|
||||
def update_uploads_completed(self):
|
||||
"""
|
||||
Update the 'Uploads completed' info widget.
|
||||
"""
|
||||
if self.uploads_completed == 0:
|
||||
image = self.common.get_resource_path('images/share_completed_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_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_uploads_tooltip', True).format(self.uploads_completed))
|
||||
|
||||
def update_uploads_in_progress(self):
|
||||
"""
|
||||
Update the 'Uploads in progress' info widget.
|
||||
"""
|
||||
if self.uploads_in_progress == 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.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_uploads_tooltip', True).format(self.uploads_in_progress))
|
||||
|
||||
def update_primary_action(self):
|
||||
self.common.log('ReceiveMode', 'update_primary_action')
|
||||
|
||||
# Show the info widget when the server is active
|
||||
if self.server_status.status == self.server_status.STATUS_STARTED:
|
||||
self.info_widget.show()
|
||||
self.info.show_more()
|
||||
else:
|
||||
self.info_widget.hide()
|
||||
self.info.show_less()
|
||||
|
||||
# Resize window
|
||||
self.resize_window()
|
||||
|
||||
def toggle_uploads(self):
|
||||
"""
|
||||
Toggle showing and hiding the Uploads widget
|
||||
"""
|
||||
self.common.log('ReceiveMode', 'toggle_uploads')
|
||||
|
||||
if self.uploads.isVisible():
|
||||
self.uploads.hide()
|
||||
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) )
|
||||
self.info_toggle_button.setFlat(True)
|
||||
else:
|
||||
self.uploads.show()
|
||||
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png')) )
|
||||
self.info_toggle_button.setFlat(False)
|
||||
|
||||
self.resize_window()
|
||||
|
||||
def resize_window(self):
|
||||
min_width = 450
|
||||
if self.uploads.isVisible():
|
||||
|
109
onionshare_gui/receive_mode/info.py
Normal file
109
onionshare_gui/receive_mode/info.py
Normal file
@ -0,0 +1,109 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OnionShare | https://onionshare.org/
|
||||
|
||||
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
|
||||
|
||||
class ReceiveModeInfo(QtWidgets.QWidget):
|
||||
"""
|
||||
Receive mode information widget
|
||||
"""
|
||||
def __init__(self, common, receive_mode):
|
||||
super(ReceiveModeInfo, self).__init__()
|
||||
self.common = common
|
||||
self.receive_mode = receive_mode
|
||||
|
||||
# In progress and completed labels
|
||||
self.in_progress_uploads_count = QtWidgets.QLabel()
|
||||
self.in_progress_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
self.completed_uploads_count = QtWidgets.QLabel()
|
||||
self.completed_uploads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
# Toggle button
|
||||
self.toggle_button = QtWidgets.QPushButton()
|
||||
self.toggle_button.setDefault(False)
|
||||
self.toggle_button.setFixedWidth(30)
|
||||
self.toggle_button.setFixedHeight(30)
|
||||
self.toggle_button.setFlat(True)
|
||||
self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) )
|
||||
self.toggle_button.clicked.connect(self.toggle_uploads)
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QHBoxLayout()
|
||||
layout.addStretch()
|
||||
layout.addWidget(self.in_progress_uploads_count)
|
||||
layout.addWidget(self.completed_uploads_count)
|
||||
layout.addWidget(self.toggle_button)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.update_uploads_completed()
|
||||
self.update_uploads_in_progress()
|
||||
|
||||
def update_uploads_completed(self):
|
||||
"""
|
||||
Update the 'Uploads completed' info widget.
|
||||
"""
|
||||
if self.receive_mode.uploads_completed == 0:
|
||||
image = self.common.get_resource_path('images/share_completed_none.png')
|
||||
else:
|
||||
image = self.common.get_resource_path('images/share_completed.png')
|
||||
self.completed_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.receive_mode.uploads_completed))
|
||||
self.completed_uploads_count.setToolTip(strings._('info_completed_uploads_tooltip', True).format(self.receive_mode.uploads_completed))
|
||||
|
||||
def update_uploads_in_progress(self):
|
||||
"""
|
||||
Update the 'Uploads in progress' info widget.
|
||||
"""
|
||||
if self.receive_mode.uploads_in_progress == 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_uploads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.receive_mode.uploads_in_progress))
|
||||
self.in_progress_uploads_count.setToolTip(strings._('info_in_progress_uploads_tooltip', True).format(self.receive_mode.uploads_in_progress))
|
||||
|
||||
def toggle_uploads(self):
|
||||
"""
|
||||
Toggle showing and hiding the Uploads widget
|
||||
"""
|
||||
self.common.log('ReceiveModeInfo', 'toggle_uploads')
|
||||
|
||||
if self.receive_mode.uploads.isVisible():
|
||||
self.receive_mode.uploads.hide()
|
||||
self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle.png')) )
|
||||
self.toggle_button.setFlat(True)
|
||||
else:
|
||||
self.receive_mode.uploads.show()
|
||||
self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png')) )
|
||||
self.toggle_button.setFlat(False)
|
||||
|
||||
self.receive_mode.resize_window()
|
||||
|
||||
def show_less(self):
|
||||
"""
|
||||
Remove clutter widgets that aren't necessary.
|
||||
"""
|
||||
pass
|
||||
|
||||
def show_more(self):
|
||||
"""
|
||||
Show all widgets.
|
||||
"""
|
||||
pass
|
@ -28,7 +28,7 @@ from onionshare.web import Web
|
||||
from .file_selection import FileSelection
|
||||
from .downloads import Downloads
|
||||
from .threads import CompressThread
|
||||
from .info import Info
|
||||
from .info import ShareModeInfo
|
||||
from ..mode import Mode
|
||||
from ..widgets import Alert
|
||||
|
||||
@ -78,7 +78,7 @@ class ShareMode(Mode):
|
||||
self.downloads_completed = 0
|
||||
|
||||
# Information about share, and show downloads button
|
||||
self.info = Info(self.common, self)
|
||||
self.info = ShareModeInfo(self.common, self)
|
||||
|
||||
# Primary action layout
|
||||
self.primary_action_layout.addWidget(self.filesize_warning)
|
||||
|
@ -22,20 +22,21 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
from onionshare import strings
|
||||
|
||||
|
||||
class Info(QtWidgets.QWidget):
|
||||
class ShareModeInfo(QtWidgets.QWidget):
|
||||
"""
|
||||
Share mode information widget
|
||||
"""
|
||||
def __init__(self, common, share_mode):
|
||||
super(Info, self).__init__()
|
||||
super(ShareModeInfo, self).__init__()
|
||||
self.common = common
|
||||
self.share_mode = share_mode
|
||||
|
||||
# Label
|
||||
self.label_text = ""
|
||||
self.label = QtWidgets.QLabel()
|
||||
self.label.setStyleSheet(self.common.css['mode_info_label'])
|
||||
|
||||
# In prorgess and completed labels
|
||||
# In progress and completed labels
|
||||
self.in_progress_downloads_count = QtWidgets.QLabel()
|
||||
self.in_progress_downloads_count.setStyleSheet(self.common.css['mode_info_label'])
|
||||
self.completed_downloads_count = QtWidgets.QLabel()
|
||||
@ -66,7 +67,8 @@ class Info(QtWidgets.QWidget):
|
||||
"""
|
||||
Updates the text of the label.
|
||||
"""
|
||||
self.label.setText(s)
|
||||
self.label_text = s
|
||||
self.label.setText(self.label_text)
|
||||
|
||||
def update_downloads_completed(self):
|
||||
"""
|
||||
@ -94,7 +96,7 @@ class Info(QtWidgets.QWidget):
|
||||
"""
|
||||
Toggle showing and hiding the Downloads widget
|
||||
"""
|
||||
self.common.log('ShareMode', 'toggle_downloads')
|
||||
self.common.log('ShareModeInfo', 'toggle_downloads')
|
||||
|
||||
if self.share_mode.downloads.isVisible():
|
||||
self.share_mode.downloads.hide()
|
||||
@ -111,10 +113,10 @@ class Info(QtWidgets.QWidget):
|
||||
"""
|
||||
Remove clutter widgets that aren't necessary.
|
||||
"""
|
||||
self.label.hide()
|
||||
self.label.setText("")
|
||||
|
||||
def show_more(self):
|
||||
"""
|
||||
Show all widgets.
|
||||
"""
|
||||
self.label.show()
|
||||
self.label.setText(self.label_text)
|
||||
|
Loading…
Reference in New Issue
Block a user