2018-10-07 20:35:15 -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/>.
|
|
|
|
"""
|
|
|
|
import time
|
2018-10-08 00:14:20 -04:00
|
|
|
import subprocess
|
2018-10-08 00:57:45 -04:00
|
|
|
import os
|
2018-10-08 00:14:20 -04:00
|
|
|
from datetime import datetime
|
2018-10-07 20:35:15 -04:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
|
|
|
|
|
|
|
from onionshare import strings
|
2018-10-08 00:57:45 -04:00
|
|
|
from ..widgets import Alert
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
class HistoryItem(QtWidgets.QWidget):
|
|
|
|
"""
|
|
|
|
The base history item
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2019-02-17 01:42:25 -05:00
|
|
|
STATUS_STARTED = 0
|
|
|
|
STATUS_FINISHED = 1
|
|
|
|
STATUS_CANCELED = 2
|
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
def __init__(self):
|
|
|
|
super(HistoryItem, self).__init__()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def cancel(self):
|
|
|
|
pass
|
|
|
|
|
2019-01-19 22:33:36 -05:00
|
|
|
def get_finished_label_text(self, started):
|
2019-01-19 22:00:41 -05:00
|
|
|
"""
|
|
|
|
When an item finishes, returns a string displaying the start/end datetime range.
|
|
|
|
started is a datetime object.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
return self._get_label_text(
|
|
|
|
"gui_all_modes_transfer_finished",
|
|
|
|
"gui_all_modes_transfer_finished_range",
|
|
|
|
started,
|
|
|
|
)
|
2019-01-20 18:49:08 -05:00
|
|
|
|
|
|
|
def get_canceled_label_text(self, started):
|
|
|
|
"""
|
|
|
|
When an item is canceled, returns a string displaying the start/end datetime range.
|
|
|
|
started is a datetime object.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
return self._get_label_text(
|
|
|
|
"gui_all_modes_transfer_canceled",
|
|
|
|
"gui_all_modes_transfer_canceled_range",
|
|
|
|
started,
|
|
|
|
)
|
2019-01-20 18:49:08 -05:00
|
|
|
|
|
|
|
def _get_label_text(self, string_name, string_range_name, started):
|
|
|
|
"""
|
|
|
|
Return a string that contains a date, or date range.
|
|
|
|
"""
|
2019-01-19 22:00:41 -05:00
|
|
|
ended = datetime.now()
|
2019-10-13 00:01:25 -04:00
|
|
|
if (
|
|
|
|
started.year == ended.year
|
|
|
|
and started.month == ended.month
|
|
|
|
and started.day == ended.day
|
|
|
|
):
|
2019-01-19 22:00:41 -05:00
|
|
|
if started.hour == ended.hour and started.minute == ended.minute:
|
2019-10-13 00:01:25 -04:00
|
|
|
text = strings._(string_name).format(started.strftime("%b %d, %I:%M%p"))
|
2019-01-19 22:00:41 -05:00
|
|
|
else:
|
2019-01-20 18:49:08 -05:00
|
|
|
text = strings._(string_range_name).format(
|
2019-10-13 00:01:25 -04:00
|
|
|
started.strftime("%b %d, %I:%M%p"), ended.strftime("%I:%M%p")
|
2019-01-19 22:00:41 -05:00
|
|
|
)
|
|
|
|
else:
|
2019-01-20 18:49:08 -05:00
|
|
|
text = strings._(string_range_name).format(
|
2019-10-13 00:01:25 -04:00
|
|
|
started.strftime("%b %d, %I:%M%p"), ended.strftime("%b %d, %I:%M%p")
|
2019-01-19 22:00:41 -05:00
|
|
|
)
|
|
|
|
return text
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
|
2019-01-19 21:30:13 -05:00
|
|
|
class ShareHistoryItem(HistoryItem):
|
2018-10-07 20:35:15 -04:00
|
|
|
"""
|
|
|
|
Download history item, for share mode
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
def __init__(self, common, id, total_bytes):
|
2019-01-19 21:30:13 -05:00
|
|
|
super(ShareHistoryItem, self).__init__()
|
2018-10-07 20:35:15 -04:00
|
|
|
self.common = common
|
|
|
|
|
|
|
|
self.id = id
|
|
|
|
self.total_bytes = total_bytes
|
|
|
|
self.downloaded_bytes = 0
|
2018-10-10 01:21:03 -04:00
|
|
|
self.started = time.time()
|
|
|
|
self.started_dt = datetime.fromtimestamp(self.started)
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_STARTED
|
2018-10-07 20:35:15 -04:00
|
|
|
|
2018-10-10 01:21:03 -04:00
|
|
|
# Label
|
2019-10-13 00:01:25 -04:00
|
|
|
self.label = QtWidgets.QLabel(
|
|
|
|
strings._("gui_all_modes_transfer_started").format(
|
|
|
|
self.started_dt.strftime("%b %d, %I:%M%p")
|
|
|
|
)
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
# Progress bar
|
|
|
|
self.progress_bar = QtWidgets.QProgressBar()
|
|
|
|
self.progress_bar.setTextVisible(True)
|
|
|
|
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
|
|
|
self.progress_bar.setMinimum(0)
|
|
|
|
self.progress_bar.setMaximum(total_bytes)
|
|
|
|
self.progress_bar.setValue(0)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["downloads_uploads_progress_bar"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
self.progress_bar.total_bytes = total_bytes
|
|
|
|
|
|
|
|
# Layout
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
2018-10-10 01:21:03 -04:00
|
|
|
layout.addWidget(self.label)
|
2018-10-07 20:35:15 -04:00
|
|
|
layout.addWidget(self.progress_bar)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
# Start at 0
|
|
|
|
self.update(0)
|
|
|
|
|
|
|
|
def update(self, downloaded_bytes):
|
|
|
|
self.downloaded_bytes = downloaded_bytes
|
|
|
|
|
|
|
|
self.progress_bar.setValue(downloaded_bytes)
|
|
|
|
if downloaded_bytes == self.progress_bar.total_bytes:
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_complete").format(
|
|
|
|
self.common.format_seconds(time.time() - self.started)
|
|
|
|
)
|
2019-01-19 22:00:41 -05:00
|
|
|
|
|
|
|
# Change the label
|
2019-01-19 22:33:36 -05:00
|
|
|
self.label.setText(self.get_finished_label_text(self.started_dt))
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_FINISHED
|
2019-01-19 22:00:41 -05:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
else:
|
|
|
|
elapsed = time.time() - self.started
|
|
|
|
if elapsed < 10:
|
|
|
|
# Wait a couple of seconds for the download rate to stabilize.
|
|
|
|
# This prevents a "Windows copy dialog"-esque experience at
|
|
|
|
# the beginning of the download.
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_starting").format(
|
|
|
|
self.common.human_readable_filesize(downloaded_bytes)
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_eta").format(
|
2018-10-07 20:35:15 -04:00
|
|
|
self.common.human_readable_filesize(downloaded_bytes),
|
2019-10-13 00:01:25 -04:00
|
|
|
self.estimated_time_remaining,
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
self.progress_bar.setFormat(pb_fmt)
|
|
|
|
|
|
|
|
def cancel(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setFormat(strings._("gui_canceled"))
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_CANCELED
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def estimated_time_remaining(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
return self.common.estimated_time_remaining(
|
|
|
|
self.downloaded_bytes, self.total_bytes, self.started
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
|
2019-01-19 21:30:13 -05:00
|
|
|
class ReceiveHistoryItemFile(QtWidgets.QWidget):
|
2018-10-08 00:14:20 -04:00
|
|
|
def __init__(self, common, filename):
|
2019-01-19 21:30:13 -05:00
|
|
|
super(ReceiveHistoryItemFile, self).__init__()
|
2018-10-08 00:14:20 -04:00
|
|
|
self.common = common
|
|
|
|
|
2019-10-20 13:30:16 -04:00
|
|
|
self.common.log("ReceiveHistoryItemFile", "__init__", f"filename: {filename}")
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
self.filename = filename
|
2018-10-26 00:38:20 -04:00
|
|
|
self.dir = None
|
2018-10-08 00:14:20 -04:00
|
|
|
self.started = datetime.now()
|
|
|
|
|
|
|
|
# Filename label
|
|
|
|
self.filename_label = QtWidgets.QLabel(self.filename)
|
|
|
|
self.filename_label_width = self.filename_label.width()
|
|
|
|
|
|
|
|
# File size label
|
|
|
|
self.filesize_label = QtWidgets.QLabel()
|
2019-10-20 23:01:09 -04:00
|
|
|
self.filesize_label.setStyleSheet(self.common.gui.css["receive_file_size"])
|
2018-10-08 00:14:20 -04:00
|
|
|
self.filesize_label.hide()
|
|
|
|
|
|
|
|
# Folder button
|
2019-10-13 00:01:25 -04:00
|
|
|
folder_pixmap = QtGui.QPixmap.fromImage(
|
|
|
|
QtGui.QImage(self.common.get_resource_path("images/open_folder.png"))
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
folder_icon = QtGui.QIcon(folder_pixmap)
|
|
|
|
self.folder_button = QtWidgets.QPushButton()
|
|
|
|
self.folder_button.clicked.connect(self.open_folder)
|
|
|
|
self.folder_button.setIcon(folder_icon)
|
|
|
|
self.folder_button.setIconSize(folder_pixmap.rect().size())
|
|
|
|
self.folder_button.setFlat(True)
|
|
|
|
self.folder_button.hide()
|
|
|
|
|
|
|
|
# Layouts
|
|
|
|
layout = QtWidgets.QHBoxLayout()
|
|
|
|
layout.addWidget(self.filename_label)
|
|
|
|
layout.addWidget(self.filesize_label)
|
|
|
|
layout.addStretch()
|
|
|
|
layout.addWidget(self.folder_button)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
def update(self, uploaded_bytes, complete):
|
|
|
|
self.filesize_label.setText(self.common.human_readable_filesize(uploaded_bytes))
|
|
|
|
self.filesize_label.show()
|
|
|
|
|
|
|
|
if complete:
|
|
|
|
self.folder_button.show()
|
|
|
|
|
|
|
|
def rename(self, new_filename):
|
|
|
|
self.filename = new_filename
|
|
|
|
self.filename_label.setText(self.filename)
|
|
|
|
|
2018-10-26 00:38:20 -04:00
|
|
|
def set_dir(self, dir):
|
|
|
|
self.dir = dir
|
|
|
|
|
2018-10-08 00:14:20 -04:00
|
|
|
def open_folder(self):
|
|
|
|
"""
|
|
|
|
Open the downloads folder, with the file selected, in a cross-platform manner
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log("ReceiveHistoryItemFile", "open_folder")
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2018-10-26 00:38:20 -04:00
|
|
|
if not self.dir:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log(
|
|
|
|
"ReceiveHistoryItemFile",
|
|
|
|
"open_folder",
|
|
|
|
"dir has not been set yet, can't open folder",
|
|
|
|
)
|
2018-10-26 00:38:20 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
abs_filename = os.path.join(self.dir, self.filename)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Linux
|
2019-10-13 00:01:25 -04:00
|
|
|
if self.common.platform == "Linux" or self.common.platform == "BSD":
|
2018-10-08 00:14:20 -04:00
|
|
|
try:
|
|
|
|
# If nautilus is available, open it
|
2019-10-13 00:01:25 -04:00
|
|
|
subprocess.Popen(["nautilus", abs_filename])
|
2018-10-08 00:14:20 -04:00
|
|
|
except:
|
2019-10-13 00:01:25 -04:00
|
|
|
Alert(
|
|
|
|
self.common,
|
|
|
|
strings._("gui_open_folder_error_nautilus").format(abs_filename),
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# macOS
|
2019-10-13 00:01:25 -04:00
|
|
|
elif self.common.platform == "Darwin":
|
|
|
|
subprocess.call(["open", "-R", abs_filename])
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Windows
|
2019-10-13 00:01:25 -04:00
|
|
|
elif self.common.platform == "Windows":
|
2019-10-20 13:30:16 -04:00
|
|
|
subprocess.Popen(["explorer", f"/select,{abs_filename}"])
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2019-09-08 20:24:18 -04:00
|
|
|
|
2019-01-19 21:30:13 -05:00
|
|
|
class ReceiveHistoryItem(HistoryItem):
|
2018-10-08 00:14:20 -04:00
|
|
|
def __init__(self, common, id, content_length):
|
2019-01-19 21:30:13 -05:00
|
|
|
super(ReceiveHistoryItem, self).__init__()
|
2018-10-08 00:14:20 -04:00
|
|
|
self.common = common
|
|
|
|
self.id = id
|
|
|
|
self.content_length = content_length
|
|
|
|
self.started = datetime.now()
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_STARTED
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Label
|
2019-10-13 00:01:25 -04:00
|
|
|
self.label = QtWidgets.QLabel(
|
|
|
|
strings._("gui_all_modes_transfer_started").format(
|
|
|
|
self.started.strftime("%b %d, %I:%M%p")
|
|
|
|
)
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Progress bar
|
|
|
|
self.progress_bar = QtWidgets.QProgressBar()
|
|
|
|
self.progress_bar.setTextVisible(True)
|
|
|
|
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
|
|
|
self.progress_bar.setMinimum(0)
|
|
|
|
self.progress_bar.setValue(0)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["downloads_uploads_progress_bar"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# This layout contains file widgets
|
|
|
|
self.files_layout = QtWidgets.QVBoxLayout()
|
|
|
|
self.files_layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
files_widget = QtWidgets.QWidget()
|
2019-10-20 23:01:09 -04:00
|
|
|
files_widget.setStyleSheet(self.common.gui.css["receive_file"])
|
2018-10-08 00:14:20 -04:00
|
|
|
files_widget.setLayout(self.files_layout)
|
|
|
|
|
|
|
|
# Layout
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
layout.addWidget(self.label)
|
|
|
|
layout.addWidget(self.progress_bar)
|
|
|
|
layout.addWidget(files_widget)
|
|
|
|
layout.addStretch()
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
# We're also making a dictionary of file widgets, to make them easier to access
|
|
|
|
self.files = {}
|
|
|
|
|
|
|
|
def update(self, data):
|
|
|
|
"""
|
|
|
|
Using the progress from Web, update the progress bar and file size labels
|
|
|
|
for each file
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
if data["action"] == "progress":
|
2018-10-08 00:14:20 -04:00
|
|
|
total_uploaded_bytes = 0
|
2019-10-13 00:01:25 -04:00
|
|
|
for filename in data["progress"]:
|
|
|
|
total_uploaded_bytes += data["progress"][filename]["uploaded_bytes"]
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Update the progress bar
|
|
|
|
self.progress_bar.setMaximum(self.content_length)
|
|
|
|
self.progress_bar.setValue(total_uploaded_bytes)
|
|
|
|
|
|
|
|
elapsed = datetime.now() - self.started
|
|
|
|
if elapsed.seconds < 10:
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_starting").format(
|
|
|
|
self.common.human_readable_filesize(total_uploaded_bytes)
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
else:
|
|
|
|
estimated_time_remaining = self.common.estimated_time_remaining(
|
2019-10-13 00:01:25 -04:00
|
|
|
total_uploaded_bytes, self.content_length, self.started.timestamp()
|
|
|
|
)
|
|
|
|
pb_fmt = strings._("gui_all_modes_progress_eta").format(
|
2018-10-08 00:14:20 -04:00
|
|
|
self.common.human_readable_filesize(total_uploaded_bytes),
|
2019-10-13 00:01:25 -04:00
|
|
|
estimated_time_remaining,
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
|
|
|
# Using list(progress) to avoid "RuntimeError: dictionary changed size during iteration"
|
2019-10-13 00:01:25 -04:00
|
|
|
for filename in list(data["progress"]):
|
2018-10-08 00:14:20 -04:00
|
|
|
# Add a new file if needed
|
|
|
|
if filename not in self.files:
|
2019-01-19 21:30:13 -05:00
|
|
|
self.files[filename] = ReceiveHistoryItemFile(self.common, filename)
|
2018-10-08 00:14:20 -04:00
|
|
|
self.files_layout.addWidget(self.files[filename])
|
|
|
|
|
|
|
|
# Update the file
|
2019-10-13 00:01:25 -04:00
|
|
|
self.files[filename].update(
|
|
|
|
data["progress"][filename]["uploaded_bytes"],
|
|
|
|
data["progress"][filename]["complete"],
|
|
|
|
)
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
elif data["action"] == "rename":
|
|
|
|
self.files[data["old_filename"]].rename(data["new_filename"])
|
|
|
|
self.files[data["new_filename"]] = self.files.pop(data["old_filename"])
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
elif data["action"] == "set_dir":
|
|
|
|
self.files[data["filename"]].set_dir(data["dir"])
|
2018-10-26 00:38:20 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
elif data["action"] == "finished":
|
2019-02-16 22:07:38 -05:00
|
|
|
# Change the status
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_FINISHED
|
2019-02-16 22:07:38 -05:00
|
|
|
|
2018-10-08 00:14:20 -04:00
|
|
|
# Hide the progress bar
|
|
|
|
self.progress_bar.hide()
|
|
|
|
|
|
|
|
# Change the label
|
2019-01-19 22:00:41 -05:00
|
|
|
self.label.setText(self.get_finished_label_text(self.started))
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
elif data["action"] == "canceled":
|
2019-02-16 22:07:38 -05:00
|
|
|
# Change the status
|
2019-02-17 01:42:25 -05:00
|
|
|
self.status = HistoryItem.STATUS_CANCELED
|
2019-02-16 22:07:38 -05:00
|
|
|
|
2019-01-20 18:25:36 -05:00
|
|
|
# Hide the progress bar
|
|
|
|
self.progress_bar.hide()
|
|
|
|
|
|
|
|
# Change the label
|
2019-01-20 18:49:08 -05:00
|
|
|
self.label.setText(self.get_canceled_label_text(self.started))
|
2019-01-20 18:25:36 -05:00
|
|
|
|
2018-10-08 00:14:20 -04:00
|
|
|
|
2019-09-02 04:01:56 -04:00
|
|
|
class IndividualFileHistoryItem(HistoryItem):
|
|
|
|
"""
|
|
|
|
Individual file history item, for share mode viewing of individual files
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
def __init__(self, common, data, path):
|
2019-09-02 04:01:56 -04:00
|
|
|
super(IndividualFileHistoryItem, self).__init__()
|
|
|
|
self.status = HistoryItem.STATUS_STARTED
|
|
|
|
self.common = common
|
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
self.id = id
|
|
|
|
self.path = path
|
2019-09-04 00:59:49 -04:00
|
|
|
self.total_bytes = 0
|
2019-09-04 00:46:32 -04:00
|
|
|
self.downloaded_bytes = 0
|
|
|
|
self.started = time.time()
|
|
|
|
self.started_dt = datetime.fromtimestamp(self.started)
|
|
|
|
self.status = HistoryItem.STATUS_STARTED
|
2019-09-02 04:01:56 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
self.directory_listing = "directory_listing" in data
|
2019-09-04 00:59:49 -04:00
|
|
|
|
2019-09-02 04:01:56 -04:00
|
|
|
# Labels
|
2019-10-13 00:01:25 -04:00
|
|
|
self.timestamp_label = QtWidgets.QLabel(
|
|
|
|
self.started_dt.strftime("%b %d, %I:%M%p")
|
|
|
|
)
|
|
|
|
self.timestamp_label.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["history_individual_file_timestamp_label"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-10-20 13:30:16 -04:00
|
|
|
self.path_label = QtWidgets.QLabel(self.path)
|
2019-09-04 00:59:49 -04:00
|
|
|
self.status_code_label = QtWidgets.QLabel()
|
2019-09-04 00:46:32 -04:00
|
|
|
|
|
|
|
# Progress bar
|
|
|
|
self.progress_bar = QtWidgets.QProgressBar()
|
|
|
|
self.progress_bar.setTextVisible(True)
|
|
|
|
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
|
|
|
self.progress_bar.setValue(0)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["downloads_uploads_progress_bar"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-09-04 00:46:32 -04:00
|
|
|
|
|
|
|
# Text layout
|
|
|
|
labels_layout = QtWidgets.QHBoxLayout()
|
|
|
|
labels_layout.addWidget(self.timestamp_label)
|
2019-09-08 12:35:44 -04:00
|
|
|
labels_layout.addWidget(self.path_label)
|
2019-09-04 00:59:49 -04:00
|
|
|
labels_layout.addWidget(self.status_code_label)
|
|
|
|
labels_layout.addStretch()
|
2019-09-02 04:01:56 -04:00
|
|
|
|
|
|
|
# Layout
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
2019-09-04 00:46:32 -04:00
|
|
|
layout.addLayout(labels_layout)
|
|
|
|
layout.addWidget(self.progress_bar)
|
2019-09-02 04:01:56 -04:00
|
|
|
self.setLayout(layout)
|
|
|
|
|
2019-09-04 01:18:30 -04:00
|
|
|
# Is a status code already sent?
|
2019-10-13 00:01:25 -04:00
|
|
|
if "status_code" in data:
|
2019-10-20 13:30:16 -04:00
|
|
|
self.status_code_label.setText(str(data["status_code"]))
|
2019-10-13 00:01:25 -04:00
|
|
|
if data["status_code"] >= 200 and data["status_code"] < 300:
|
|
|
|
self.status_code_label.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["history_individual_file_status_code_label_2xx"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
if data["status_code"] >= 400 and data["status_code"] < 500:
|
|
|
|
self.status_code_label.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["history_individual_file_status_code_label_4xx"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-09-04 00:59:49 -04:00
|
|
|
self.status = HistoryItem.STATUS_FINISHED
|
2019-09-04 00:46:32 -04:00
|
|
|
self.progress_bar.hide()
|
2019-09-04 00:59:49 -04:00
|
|
|
return
|
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.total_bytes = data["filesize"]
|
2019-09-04 00:59:49 -04:00
|
|
|
self.progress_bar.setMinimum(0)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setMaximum(data["filesize"])
|
|
|
|
self.progress_bar.total_bytes = data["filesize"]
|
2019-09-04 00:59:49 -04:00
|
|
|
|
|
|
|
# Start at 0
|
|
|
|
self.update(0)
|
2019-09-02 04:01:56 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
def update(self, downloaded_bytes):
|
|
|
|
self.downloaded_bytes = downloaded_bytes
|
2019-04-23 10:03:50 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
self.progress_bar.setValue(downloaded_bytes)
|
|
|
|
if downloaded_bytes == self.progress_bar.total_bytes:
|
2019-09-04 01:18:30 -04:00
|
|
|
self.status_code_label.setText("200")
|
2019-10-13 00:01:25 -04:00
|
|
|
self.status_code_label.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["history_individual_file_status_code_label_2xx"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-09-04 00:46:32 -04:00
|
|
|
self.progress_bar.hide()
|
|
|
|
self.status = HistoryItem.STATUS_FINISHED
|
2019-04-23 10:03:50 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
else:
|
|
|
|
elapsed = time.time() - self.started
|
|
|
|
if elapsed < 10:
|
|
|
|
# Wait a couple of seconds for the download rate to stabilize.
|
|
|
|
# This prevents a "Windows copy dialog"-esque experience at
|
|
|
|
# the beginning of the download.
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_starting").format(
|
|
|
|
self.common.human_readable_filesize(downloaded_bytes)
|
|
|
|
)
|
2019-09-04 00:46:32 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
pb_fmt = strings._("gui_all_modes_progress_eta").format(
|
2019-09-04 00:46:32 -04:00
|
|
|
self.common.human_readable_filesize(downloaded_bytes),
|
2019-10-13 00:01:25 -04:00
|
|
|
self.estimated_time_remaining,
|
|
|
|
)
|
2019-04-23 10:03:50 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
self.progress_bar.setFormat(pb_fmt)
|
2019-05-07 18:04:09 -04:00
|
|
|
|
|
|
|
def cancel(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
self.progress_bar.setFormat(strings._("gui_canceled"))
|
2019-05-07 18:04:09 -04:00
|
|
|
self.status = HistoryItem.STATUS_CANCELED
|
2019-04-23 10:03:50 -04:00
|
|
|
|
2019-09-04 00:46:32 -04:00
|
|
|
@property
|
|
|
|
def estimated_time_remaining(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
return self.common.estimated_time_remaining(
|
|
|
|
self.downloaded_bytes, self.total_bytes, self.started
|
|
|
|
)
|
2019-09-04 00:46:32 -04:00
|
|
|
|
2019-09-08 20:24:18 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
class HistoryItemList(QtWidgets.QScrollArea):
|
|
|
|
"""
|
|
|
|
List of items
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
def __init__(self, common):
|
|
|
|
super(HistoryItemList, self).__init__()
|
|
|
|
self.common = common
|
|
|
|
|
|
|
|
self.items = {}
|
|
|
|
|
|
|
|
# The layout that holds all of the items
|
|
|
|
self.items_layout = QtWidgets.QVBoxLayout()
|
|
|
|
self.items_layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.items_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
|
|
|
|
|
|
|
|
# Wrapper layout that also contains a stretch
|
|
|
|
wrapper_layout = QtWidgets.QVBoxLayout()
|
|
|
|
wrapper_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
|
|
|
|
wrapper_layout.addLayout(self.items_layout)
|
|
|
|
wrapper_layout.addStretch()
|
|
|
|
|
|
|
|
# The internal widget of the scroll area
|
|
|
|
widget = QtWidgets.QWidget()
|
|
|
|
widget.setLayout(wrapper_layout)
|
|
|
|
self.setWidget(widget)
|
|
|
|
self.setWidgetResizable(True)
|
|
|
|
|
|
|
|
# Other scroll area settings
|
|
|
|
self.setBackgroundRole(QtGui.QPalette.Light)
|
|
|
|
self.verticalScrollBar().rangeChanged.connect(self.resizeScroll)
|
|
|
|
|
|
|
|
def resizeScroll(self, minimum, maximum):
|
|
|
|
"""
|
|
|
|
Scroll to the bottom of the window when the range changes.
|
|
|
|
"""
|
|
|
|
self.verticalScrollBar().setValue(maximum)
|
|
|
|
|
|
|
|
def add(self, id, item):
|
|
|
|
"""
|
|
|
|
Add a new item. Override this method.
|
|
|
|
"""
|
|
|
|
self.items[id] = item
|
|
|
|
self.items_layout.addWidget(item)
|
|
|
|
|
|
|
|
def update(self, id, data):
|
|
|
|
"""
|
|
|
|
Update an item. Override this method.
|
|
|
|
"""
|
2019-01-20 19:34:56 -05:00
|
|
|
if id in self.items:
|
|
|
|
self.items[id].update(data)
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
def cancel(self, id):
|
|
|
|
"""
|
|
|
|
Cancel an item. Override this method.
|
|
|
|
"""
|
2019-01-20 19:34:56 -05:00
|
|
|
if id in self.items:
|
|
|
|
self.items[id].cancel()
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
"""
|
|
|
|
Reset all items, emptying the list. Override this method.
|
|
|
|
"""
|
2019-02-16 22:07:38 -05:00
|
|
|
for key, item in self.items.copy().items():
|
2019-05-07 18:04:09 -04:00
|
|
|
self.items_layout.removeWidget(item)
|
|
|
|
item.close()
|
|
|
|
del self.items[key]
|
2018-10-07 20:35:15 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
class History(QtWidgets.QWidget):
|
|
|
|
"""
|
|
|
|
A history of what's happened so far in this mode. This contains an internal
|
|
|
|
object full of a scrollable list of items.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
|
|
|
def __init__(self, common, empty_image, empty_text, header_text, mode=""):
|
2018-10-07 20:35:15 -04:00
|
|
|
super(History, self).__init__()
|
|
|
|
self.common = common
|
2019-05-07 18:04:09 -04:00
|
|
|
self.mode = mode
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
self.setMinimumWidth(350)
|
|
|
|
|
2018-10-07 21:09:02 -04:00
|
|
|
# In progress and completed counters
|
|
|
|
self.in_progress_count = 0
|
|
|
|
self.completed_count = 0
|
2019-09-08 20:24:18 -04:00
|
|
|
self.requests_count = 0
|
2018-10-07 21:09:02 -04:00
|
|
|
|
2019-09-08 20:24:18 -04:00
|
|
|
# In progress, completed, and requests labels
|
2018-10-07 21:09:02 -04:00
|
|
|
self.in_progress_label = QtWidgets.QLabel()
|
2019-10-20 23:01:09 -04:00
|
|
|
self.in_progress_label.setStyleSheet(self.common.gui.css["mode_info_label"])
|
2018-10-07 21:09:02 -04:00
|
|
|
self.completed_label = QtWidgets.QLabel()
|
2019-10-20 23:01:09 -04:00
|
|
|
self.completed_label.setStyleSheet(self.common.gui.css["mode_info_label"])
|
2019-09-08 20:24:18 -04:00
|
|
|
self.requests_label = QtWidgets.QLabel()
|
2019-10-20 23:01:09 -04:00
|
|
|
self.requests_label.setStyleSheet(self.common.gui.css["mode_info_label"])
|
2018-10-07 21:09:02 -04:00
|
|
|
|
|
|
|
# Header
|
|
|
|
self.header_label = QtWidgets.QLabel(header_text)
|
2019-10-20 23:01:09 -04:00
|
|
|
self.header_label.setStyleSheet(self.common.gui.css["downloads_uploads_label"])
|
2019-10-13 00:01:25 -04:00
|
|
|
self.clear_button = QtWidgets.QPushButton(
|
|
|
|
strings._("gui_all_modes_clear_history")
|
|
|
|
)
|
2019-10-20 23:01:09 -04:00
|
|
|
self.clear_button.setStyleSheet(self.common.gui.css["downloads_uploads_clear"])
|
2019-09-09 02:35:05 -04:00
|
|
|
self.clear_button.setFlat(True)
|
|
|
|
self.clear_button.clicked.connect(self.reset)
|
2018-10-07 21:09:02 -04:00
|
|
|
header_layout = QtWidgets.QHBoxLayout()
|
|
|
|
header_layout.addWidget(self.header_label)
|
|
|
|
header_layout.addStretch()
|
|
|
|
header_layout.addWidget(self.in_progress_label)
|
|
|
|
header_layout.addWidget(self.completed_label)
|
2019-09-08 20:24:18 -04:00
|
|
|
header_layout.addWidget(self.requests_label)
|
2019-09-09 02:35:05 -04:00
|
|
|
header_layout.addWidget(self.clear_button)
|
2018-10-07 21:09:02 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
# When there are no items
|
|
|
|
self.empty_image = QtWidgets.QLabel()
|
|
|
|
self.empty_image.setAlignment(QtCore.Qt.AlignCenter)
|
|
|
|
self.empty_image.setPixmap(empty_image)
|
|
|
|
self.empty_text = QtWidgets.QLabel(empty_text)
|
|
|
|
self.empty_text.setAlignment(QtCore.Qt.AlignCenter)
|
2019-10-20 23:01:09 -04:00
|
|
|
self.empty_text.setStyleSheet(
|
|
|
|
self.common.gui.css["downloads_uploads_empty_text"]
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
empty_layout = QtWidgets.QVBoxLayout()
|
|
|
|
empty_layout.addStretch()
|
|
|
|
empty_layout.addWidget(self.empty_image)
|
|
|
|
empty_layout.addWidget(self.empty_text)
|
|
|
|
empty_layout.addStretch()
|
|
|
|
self.empty = QtWidgets.QWidget()
|
2019-10-20 23:01:09 -04:00
|
|
|
self.empty.setStyleSheet(self.common.gui.css["downloads_uploads_empty"])
|
2018-10-07 20:35:15 -04:00
|
|
|
self.empty.setLayout(empty_layout)
|
|
|
|
|
|
|
|
# When there are items
|
|
|
|
self.item_list = HistoryItemList(self.common)
|
|
|
|
self.not_empty_layout = QtWidgets.QVBoxLayout()
|
2018-10-07 21:20:13 -04:00
|
|
|
self.not_empty_layout.addLayout(header_layout)
|
2018-10-07 20:35:15 -04:00
|
|
|
self.not_empty_layout.addWidget(self.item_list)
|
|
|
|
self.not_empty = QtWidgets.QWidget()
|
|
|
|
self.not_empty.setLayout(self.not_empty_layout)
|
|
|
|
|
|
|
|
# Layout
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
layout.addWidget(self.empty)
|
|
|
|
layout.addWidget(self.not_empty)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
# Reset once at the beginning
|
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def add(self, id, item):
|
|
|
|
"""
|
|
|
|
Add a new item.
|
|
|
|
"""
|
2019-10-20 13:30:16 -04:00
|
|
|
self.common.log("History", "add", f"id: {id}, item: {item}")
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
# Hide empty, show not empty
|
|
|
|
self.empty.hide()
|
|
|
|
self.not_empty.show()
|
|
|
|
|
|
|
|
# Add it to the list
|
|
|
|
self.item_list.add(id, item)
|
|
|
|
|
|
|
|
def update(self, id, data):
|
|
|
|
"""
|
|
|
|
Update an item.
|
|
|
|
"""
|
|
|
|
self.item_list.update(id, data)
|
|
|
|
|
|
|
|
def cancel(self, id):
|
|
|
|
"""
|
|
|
|
Cancel an item.
|
|
|
|
"""
|
|
|
|
self.item_list.cancel(id)
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
"""
|
|
|
|
Reset all items.
|
|
|
|
"""
|
|
|
|
self.item_list.reset()
|
2019-02-17 00:28:11 -05:00
|
|
|
if len(self.item_list.items) == 0:
|
2019-02-16 22:07:38 -05:00
|
|
|
# Hide not empty, show empty
|
|
|
|
self.not_empty.hide()
|
|
|
|
self.empty.show()
|
|
|
|
# Reset in-progress counter
|
|
|
|
self.in_progress_count = 0
|
|
|
|
self.update_in_progress()
|
2018-10-07 20:35:15 -04:00
|
|
|
|
2019-02-16 22:07:38 -05:00
|
|
|
# Reset completed counter
|
2018-10-07 21:09:02 -04:00
|
|
|
self.completed_count = 0
|
|
|
|
self.update_completed()
|
|
|
|
|
2019-09-08 20:24:18 -04:00
|
|
|
# Reset web requests counter
|
|
|
|
self.requests_count = 0
|
|
|
|
self.update_requests()
|
|
|
|
|
2018-10-07 21:09:02 -04:00
|
|
|
def update_completed(self):
|
|
|
|
"""
|
|
|
|
Update the 'completed' widget.
|
|
|
|
"""
|
|
|
|
if self.completed_count == 0:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_completed_none.png")
|
2018-10-07 21:09:02 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_completed.png")
|
2019-10-20 13:30:16 -04:00
|
|
|
self.completed_label.setText(f'<img src="{image}" /> {self.completed_count}')
|
2019-10-13 00:01:25 -04:00
|
|
|
self.completed_label.setToolTip(
|
|
|
|
strings._("history_completed_tooltip").format(self.completed_count)
|
|
|
|
)
|
2018-10-07 21:09:02 -04:00
|
|
|
|
|
|
|
def update_in_progress(self):
|
|
|
|
"""
|
|
|
|
Update the 'in progress' widget.
|
|
|
|
"""
|
2019-09-08 20:24:18 -04:00
|
|
|
if self.in_progress_count == 0:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_in_progress_none.png")
|
2019-09-08 20:24:18 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_in_progress.png")
|
2019-09-08 20:24:18 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
self.in_progress_label.setText(
|
2019-10-20 13:30:16 -04:00
|
|
|
f'<img src="{image}" /> {self.in_progress_count}'
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
self.in_progress_label.setToolTip(
|
|
|
|
strings._("history_in_progress_tooltip").format(self.in_progress_count)
|
|
|
|
)
|
2019-09-08 20:24:18 -04:00
|
|
|
|
|
|
|
def update_requests(self):
|
|
|
|
"""
|
|
|
|
Update the 'web requests' widget.
|
|
|
|
"""
|
|
|
|
if self.requests_count == 0:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_requests_none.png")
|
2019-09-08 20:24:18 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
image = self.common.get_resource_path("images/history_requests.png")
|
2019-05-07 18:04:09 -04:00
|
|
|
|
2019-10-20 13:30:16 -04:00
|
|
|
self.requests_label.setText(f'<img src="{image}" /> {self.requests_count}')
|
2019-10-13 00:01:25 -04:00
|
|
|
self.requests_label.setToolTip(
|
|
|
|
strings._("history_requests_tooltip").format(self.requests_count)
|
|
|
|
)
|
2018-10-07 21:09:02 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
class ToggleHistory(QtWidgets.QPushButton):
|
|
|
|
"""
|
|
|
|
Widget for toggling showing or hiding the history, as well as keeping track
|
|
|
|
of the indicator counter if it's hidden
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-10-07 20:35:15 -04:00
|
|
|
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)
|
2019-10-13 00:01:25 -04:00
|
|
|
self.indicator_label.setStyleSheet(
|
2019-10-20 23:01:09 -04:00
|
|
|
self.common.gui.css["download_uploads_indicator"]
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
self.update_indicator()
|
|
|
|
|
|
|
|
def update_indicator(self, increment=False):
|
|
|
|
"""
|
|
|
|
Update the display of the indicator count. If increment is True, then
|
2019-09-08 20:39:31 -04:00
|
|
|
only increment the counter if History is hidden.
|
2018-10-07 20:35:15 -04:00
|
|
|
"""
|
|
|
|
if increment and not self.history_widget.isVisible():
|
|
|
|
self.indicator_count += 1
|
|
|
|
|
2019-10-20 13:30:16 -04:00
|
|
|
self.indicator_label.setText(str(self.indicator_count))
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
if self.indicator_count == 0:
|
|
|
|
self.indicator_label.hide()
|
|
|
|
else:
|
|
|
|
size = self.indicator_label.sizeHint()
|
2019-10-13 00:01:25 -04:00
|
|
|
self.indicator_label.setGeometry(
|
|
|
|
35 - size.width(), 0, size.width(), size.height()
|
|
|
|
)
|
2018-10-07 20:35:15 -04:00
|
|
|
self.indicator_label.show()
|
|
|
|
|
|
|
|
def toggle_clicked(self):
|
|
|
|
"""
|
|
|
|
Toggle showing and hiding the history widget
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log("ToggleHistory", "toggle_clicked")
|
2018-10-07 20:35:15 -04:00
|
|
|
|
|
|
|
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()
|