mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
In ShareMode, remove the ShareModeInfo widget and replace with a customized ToggleHistory widget
This commit is contained in:
parent
801d8b965c
commit
5a8cb2ac9d
@ -28,8 +28,9 @@ from onionshare.web import Web
|
||||
from .file_selection import FileSelection
|
||||
from .downloads import Downloads
|
||||
from .threads import CompressThread
|
||||
from .info import ShareModeInfo
|
||||
#from .info import ShareModeInfo
|
||||
from .. import Mode
|
||||
from ..toggle_history import ToggleHistory
|
||||
from ...widgets import Alert
|
||||
|
||||
class ShareMode(Mode):
|
||||
@ -78,7 +79,24 @@ class ShareMode(Mode):
|
||||
self.downloads_completed = 0
|
||||
|
||||
# Information about share, and show downloads button
|
||||
self.info = ShareModeInfo(self.common, self)
|
||||
#self.info = ShareModeInfo(self.common, self)
|
||||
|
||||
# Info label
|
||||
self.info_label = QtWidgets.QLabel()
|
||||
self.info_label.hide()
|
||||
|
||||
# Toggle history
|
||||
self.toggle_history = ToggleHistory(
|
||||
self.common, self, self.downloads,
|
||||
QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')),
|
||||
QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png'))
|
||||
)
|
||||
|
||||
# Top bar
|
||||
top_bar_layout = QtWidgets.QHBoxLayout()
|
||||
top_bar_layout.addWidget(self.info_label)
|
||||
top_bar_layout.addStretch()
|
||||
top_bar_layout.addWidget(self.toggle_history)
|
||||
|
||||
# Primary action layout
|
||||
self.primary_action_layout.addWidget(self.filesize_warning)
|
||||
@ -90,7 +108,7 @@ class ShareMode(Mode):
|
||||
|
||||
# Main layout
|
||||
self.main_layout = QtWidgets.QVBoxLayout()
|
||||
self.main_layout.addWidget(self.info)
|
||||
self.main_layout.addLayout(top_bar_layout)
|
||||
self.main_layout.addLayout(self.file_selection)
|
||||
self.main_layout.addWidget(self.primary_action)
|
||||
self.main_layout.addWidget(self.min_width_widget)
|
||||
@ -191,7 +209,7 @@ class ShareMode(Mode):
|
||||
self.filesize_warning.hide()
|
||||
self.downloads_in_progress = 0
|
||||
self.downloads_completed = 0
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.update_downloads_in_progress()
|
||||
self.file_selection.file_list.adjustSize()
|
||||
|
||||
def cancel_server_custom(self):
|
||||
@ -207,7 +225,7 @@ class ShareMode(Mode):
|
||||
Connection to Tor broke.
|
||||
"""
|
||||
self.primary_action.hide()
|
||||
self.info.show_less()
|
||||
self.info_label.hide()
|
||||
|
||||
def handle_request_load(self, event):
|
||||
"""
|
||||
@ -224,9 +242,9 @@ class ShareMode(Mode):
|
||||
else:
|
||||
filesize = self.web.share_mode.download_filesize
|
||||
self.downloads.add(event["data"]["id"], filesize)
|
||||
self.info.update_indicator(True)
|
||||
self.toggle_history.update_indicator(True)
|
||||
self.downloads_in_progress += 1
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.update_downloads_in_progress()
|
||||
|
||||
self.system_tray.showMessage(strings._('systray_download_started_title', True), strings._('systray_download_started_message', True))
|
||||
|
||||
@ -242,10 +260,10 @@ class ShareMode(Mode):
|
||||
|
||||
# Update the total 'completed downloads' info
|
||||
self.downloads_completed += 1
|
||||
self.info.update_downloads_completed()
|
||||
#self.info.update_downloads_completed()
|
||||
# Update the 'in progress downloads' info
|
||||
self.downloads_in_progress -= 1
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.update_downloads_in_progress()
|
||||
|
||||
# Close on finish?
|
||||
if self.common.settings.get('close_after_first_download'):
|
||||
@ -256,7 +274,7 @@ class ShareMode(Mode):
|
||||
if self.server_status.status == self.server_status.STATUS_STOPPED:
|
||||
self.downloads.cancel(event["data"]["id"])
|
||||
self.downloads_in_progress = 0
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.update_downloads_in_progress()
|
||||
|
||||
def handle_request_canceled(self, event):
|
||||
"""
|
||||
@ -266,7 +284,7 @@ class ShareMode(Mode):
|
||||
|
||||
# Update the 'in progress downloads' info
|
||||
self.downloads_in_progress -= 1
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.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):
|
||||
@ -276,7 +294,7 @@ class ShareMode(Mode):
|
||||
"""
|
||||
if self.server_status.file_selection.get_num_files() > 0:
|
||||
self.primary_action.show()
|
||||
self.info.show_more()
|
||||
self.info_label.show()
|
||||
|
||||
def update_primary_action(self):
|
||||
self.common.log('ShareMode', 'update_primary_action')
|
||||
@ -285,7 +303,7 @@ class ShareMode(Mode):
|
||||
file_count = self.file_selection.file_list.count()
|
||||
if file_count > 0:
|
||||
self.primary_action.show()
|
||||
self.info.show_more()
|
||||
self.info_label.show()
|
||||
|
||||
# Update the file count in the info label
|
||||
total_size_bytes = 0
|
||||
@ -295,13 +313,13 @@ class ShareMode(Mode):
|
||||
total_size_readable = self.common.human_readable_filesize(total_size_bytes)
|
||||
|
||||
if file_count > 1:
|
||||
self.info.update_label(strings._('gui_file_info', True).format(file_count, total_size_readable))
|
||||
self.info_label.setText(strings._('gui_file_info', True).format(file_count, total_size_readable))
|
||||
else:
|
||||
self.info.update_label(strings._('gui_file_info_single', True).format(file_count, total_size_readable))
|
||||
self.info_label.setText(strings._('gui_file_info_single', True).format(file_count, total_size_readable))
|
||||
|
||||
else:
|
||||
self.primary_action.hide()
|
||||
self.info.show_less()
|
||||
self.info_label.hide()
|
||||
|
||||
# Resize window
|
||||
self.resize_window()
|
||||
@ -312,8 +330,8 @@ class ShareMode(Mode):
|
||||
"""
|
||||
self.downloads_completed = 0
|
||||
self.downloads_in_progress = 0
|
||||
self.info.update_downloads_completed()
|
||||
self.info.update_downloads_in_progress()
|
||||
#self.info.update_downloads_completed()
|
||||
#self.info.update_downloads_in_progress()
|
||||
self.downloads.reset()
|
||||
|
||||
def resize_window(self):
|
||||
|
88
onionshare_gui/mode/toggle_history.py
Normal file
88
onionshare_gui/mode/toggle_history.py
Normal file
@ -0,0 +1,88 @@
|
||||
# -*- 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 ToggleHistory(QtWidgets.QPushButton):
|
||||
"""
|
||||
Widget for toggling download/upload history on or off, as well as keeping track
|
||||
of the indicator counter
|
||||
"""
|
||||
def __init__(self, common, current_mode, history_widget, icon, selected_icon):
|
||||
super(ToggleHistory, self).__init__()
|
||||
self.common = common
|
||||
self.current_mode = current_mode
|
||||
self.history_widget = history_widget
|
||||
self.icon = icon
|
||||
self.selected_icon = selected_icon
|
||||
|
||||
# Toggle button
|
||||
self.setDefault(False)
|
||||
self.setFixedWidth(35)
|
||||
self.setFixedHeight(30)
|
||||
self.setFlat(True)
|
||||
self.setIcon(icon)
|
||||
self.clicked.connect(self.toggle_clicked)
|
||||
|
||||
# Keep track of indicator
|
||||
self.indicator_count = 0
|
||||
self.indicator_label = QtWidgets.QLabel(parent=self)
|
||||
self.indicator_label.setStyleSheet(self.common.css['download_uploads_indicator'])
|
||||
self.update_indicator()
|
||||
|
||||
def update_indicator(self, increment=False):
|
||||
"""
|
||||
Update the display of the indicator count. If increment is True, then
|
||||
only increment the counter if Downloads is hidden.
|
||||
"""
|
||||
if increment and not self.history_widget.isVisible():
|
||||
self.indicator_count += 1
|
||||
|
||||
self.indicator_label.setText("{}".format(self.indicator_count))
|
||||
|
||||
if self.indicator_count == 0:
|
||||
self.indicator_label.hide()
|
||||
else:
|
||||
size = self.indicator_label.sizeHint()
|
||||
self.indicator_label.setGeometry(35-size.width(), 0, size.width(), size.height())
|
||||
self.indicator_label.show()
|
||||
|
||||
def toggle_clicked(self):
|
||||
"""
|
||||
Toggle showing and hiding the history widget
|
||||
"""
|
||||
self.common.log('ToggleHistory', 'toggle_clicked')
|
||||
|
||||
if self.history_widget.isVisible():
|
||||
self.history_widget.hide()
|
||||
self.setIcon(self.icon)
|
||||
self.setFlat(True)
|
||||
else:
|
||||
self.history_widget.show()
|
||||
self.setIcon(self.selected_icon)
|
||||
self.setFlat(False)
|
||||
|
||||
# Reset the indicator count
|
||||
self.indicator_count = 0
|
||||
self.update_indicator()
|
||||
|
||||
self.current_mode.resize_window()
|
Loading…
Reference in New Issue
Block a user