From 5632fffc5fabc8d0139e9ed42fcd0a8d9db47bc2 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 28 Sep 2018 19:54:46 -0700 Subject: [PATCH] Added an indicator count for share mode --- onionshare/common.py | 10 ++++++++++ onionshare_gui/share_mode/__init__.py | 1 + onionshare_gui/share_mode/info.py | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/onionshare/common.py b/onionshare/common.py index 6662ca4e..43a6ac43 100644 --- a/onionshare/common.py +++ b/onionshare/common.py @@ -279,6 +279,16 @@ class Common(object): } """, + 'download_uploads_indicator': """ + QLabel { + color: #ffffff; + background-color: #f44449; + font-weight: bold; + padding: 5px; + border-radius: 5px; + font-size: 10px; + }""", + 'downloads_uploads_progress_bar': """ QProgressBar { border: 1px solid #4e064f; diff --git a/onionshare_gui/share_mode/__init__.py b/onionshare_gui/share_mode/__init__.py index 0504b529..58801c45 100644 --- a/onionshare_gui/share_mode/__init__.py +++ b/onionshare_gui/share_mode/__init__.py @@ -224,6 +224,7 @@ class ShareMode(Mode): else: filesize = self.web.share_mode.download_filesize self.downloads.add(event["data"]["id"], filesize) + self.info.update_indicator(True) self.downloads_in_progress += 1 self.info.update_downloads_in_progress() diff --git a/onionshare_gui/share_mode/info.py b/onionshare_gui/share_mode/info.py index 3ee12a95..a191933d 100644 --- a/onionshare_gui/share_mode/info.py +++ b/onionshare_gui/share_mode/info.py @@ -51,12 +51,19 @@ class ShareModeInfo(QtWidgets.QWidget): self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle.png')) ) self.toggle_button.clicked.connect(self.toggle_downloads) + # 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() + # Info layout layout = QtWidgets.QHBoxLayout() layout.addWidget(self.label) layout.addStretch() layout.addWidget(self.in_progress_downloads_count) layout.addWidget(self.completed_downloads_count) + layout.addWidget(self.indicator_label) layout.addWidget(self.toggle_button) self.setLayout(layout) @@ -70,6 +77,21 @@ class ShareModeInfo(QtWidgets.QWidget): self.label_text = s self.label.setText(self.label_text) + 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() + def update_downloads_completed(self): """ Update the 'Downloads completed' info widget. @@ -107,6 +129,10 @@ class ShareModeInfo(QtWidgets.QWidget): self.toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) ) self.toggle_button.setFlat(False) + # Reset the indicator count + self.indicator_count = 0 + self.update_indicator() + self.share_mode.resize_window() def show_less(self):