2018-09-28 18:47:49 -04:00
|
|
|
# -*- 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
|
|
|
|
|
|
|
|
|
2018-09-28 19:00:22 -04:00
|
|
|
class ShareModeInfo(QtWidgets.QWidget):
|
2018-09-28 18:47:49 -04:00
|
|
|
"""
|
|
|
|
Share mode information widget
|
|
|
|
"""
|
|
|
|
def __init__(self, common, share_mode):
|
2018-09-28 19:00:22 -04:00
|
|
|
super(ShareModeInfo, self).__init__()
|
2018-09-28 18:47:49 -04:00
|
|
|
self.common = common
|
|
|
|
self.share_mode = share_mode
|
|
|
|
|
|
|
|
# Label
|
2018-09-28 19:00:22 -04:00
|
|
|
self.label_text = ""
|
2018-09-28 18:47:49 -04:00
|
|
|
self.label = QtWidgets.QLabel()
|
|
|
|
self.label.setStyleSheet(self.common.css['mode_info_label'])
|
|
|
|
|
2018-09-28 19:00:22 -04:00
|
|
|
# In progress and completed labels
|
2018-09-28 18:47:49 -04:00
|
|
|
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()
|
|
|
|
self.completed_downloads_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/downloads_toggle.png')) )
|
|
|
|
self.toggle_button.clicked.connect(self.toggle_downloads)
|
|
|
|
|
2018-09-28 22:54:46 -04:00
|
|
|
# Keep track of indicator
|
|
|
|
self.indicator_count = 0
|
|
|
|
self.indicator_label = QtWidgets.QLabel()
|
|
|
|
self.indicator_label.setStyleSheet(self.common.css['download_uploads_indicator'])
|
|
|
|
self.update_indicator()
|
|
|
|
|
2018-09-29 01:03:48 -04:00
|
|
|
# Layout
|
2018-09-28 18:47:49 -04:00
|
|
|
layout = QtWidgets.QHBoxLayout()
|
|
|
|
layout.addWidget(self.label)
|
|
|
|
layout.addStretch()
|
|
|
|
layout.addWidget(self.in_progress_downloads_count)
|
|
|
|
layout.addWidget(self.completed_downloads_count)
|
2018-09-28 22:54:46 -04:00
|
|
|
layout.addWidget(self.indicator_label)
|
2018-09-28 18:47:49 -04:00
|
|
|
layout.addWidget(self.toggle_button)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
self.update_downloads_completed()
|
|
|
|
self.update_downloads_in_progress()
|
|
|
|
|
|
|
|
def update_label(self, s):
|
|
|
|
"""
|
|
|
|
Updates the text of the label.
|
|
|
|
"""
|
2018-09-28 19:00:22 -04:00
|
|
|
self.label_text = s
|
|
|
|
self.label.setText(self.label_text)
|
2018-09-28 18:47:49 -04:00
|
|
|
|
2018-09-28 22:54:46 -04:00
|
|
|
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.share_mode.downloads.isVisible():
|
|
|
|
self.indicator_count += 1
|
|
|
|
|
|
|
|
self.indicator_label.setText("{}".format(self.indicator_count))
|
|
|
|
|
|
|
|
if self.indicator_count == 0:
|
|
|
|
self.indicator_label.hide()
|
|
|
|
else:
|
|
|
|
self.indicator_label.show()
|
|
|
|
|
2018-09-28 18:47:49 -04:00
|
|
|
def update_downloads_completed(self):
|
|
|
|
"""
|
|
|
|
Update the 'Downloads completed' info widget.
|
|
|
|
"""
|
|
|
|
if self.share_mode.downloads_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_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.share_mode.downloads_completed))
|
|
|
|
self.completed_downloads_count.setToolTip(strings._('info_completed_downloads_tooltip', True).format(self.share_mode.downloads_completed))
|
|
|
|
|
|
|
|
def update_downloads_in_progress(self):
|
|
|
|
"""
|
|
|
|
Update the 'Downloads in progress' info widget.
|
|
|
|
"""
|
|
|
|
if self.share_mode.downloads_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_downloads_count.setText('<img src="{0:s}" /> {1:d}'.format(image, self.share_mode.downloads_in_progress))
|
|
|
|
self.in_progress_downloads_count.setToolTip(strings._('info_in_progress_downloads_tooltip', True).format(self.share_mode.downloads_in_progress))
|
|
|
|
|
|
|
|
def toggle_downloads(self):
|
|
|
|
"""
|
|
|
|
Toggle showing and hiding the Downloads widget
|
|
|
|
"""
|
2018-09-28 19:00:22 -04:00
|
|
|
self.common.log('ShareModeInfo', 'toggle_downloads')
|
2018-09-28 18:47:49 -04:00
|
|
|
|
|
|
|
if self.share_mode.downloads.isVisible():
|
|
|
|
self.share_mode.downloads.hide()
|
|
|
|
self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')) )
|
|
|
|
self.toggle_button.setFlat(True)
|
|
|
|
else:
|
|
|
|
self.share_mode.downloads.show()
|
|
|
|
self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) )
|
|
|
|
self.toggle_button.setFlat(False)
|
|
|
|
|
2018-09-28 22:54:46 -04:00
|
|
|
# Reset the indicator count
|
|
|
|
self.indicator_count = 0
|
|
|
|
self.update_indicator()
|
|
|
|
|
2018-09-28 18:47:49 -04:00
|
|
|
self.share_mode.resize_window()
|
|
|
|
|
|
|
|
def show_less(self):
|
|
|
|
"""
|
|
|
|
Remove clutter widgets that aren't necessary.
|
|
|
|
"""
|
2018-09-28 19:00:22 -04:00
|
|
|
self.label.setText("")
|
2018-09-28 18:47:49 -04:00
|
|
|
|
|
|
|
def show_more(self):
|
|
|
|
"""
|
|
|
|
Show all widgets.
|
|
|
|
"""
|
2018-09-28 19:00:22 -04:00
|
|
|
self.label.setText(self.label_text)
|