unified progress labels into label, making progress indeterminate in the initial stage of article sync

This commit is contained in:
Martin Rotter 2021-08-02 09:32:15 +02:00
parent f522cf972e
commit 546f166a90
10 changed files with 86 additions and 60 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.9.2" date="2021-07-30"/>
<release version="3.9.2" date="2021-08-02"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

@ -1 +1 @@
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9

View File

@ -403,7 +403,7 @@ void FormMain::onFeedUpdatesFinished(const FeedDownloadResults& results) {
void FormMain::onFeedUpdatesStarted() {
m_ui->m_actionStopRunningItemsUpdate->setEnabled(true);
statusBar()->showProgressFeeds(0, tr("Feed update started"));
statusBar()->showProgressFeeds(-1, tr("Fetching common data"));
}
void FormMain::onFeedUpdatesProgress(const Feed* feed, int current, int total) {

View File

@ -0,0 +1,31 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "gui/reusable/progressbarwithtext.h"
#include "definitions/definitions.h"
#include "miscellaneous/application.h"
ProgressBarWithText::ProgressBarWithText(QWidget* parent) : QProgressBar(parent) {}
QString ProgressBarWithText::text() const {
qint64 totalSteps = qint64(maximum()) - minimum();
QString result = format();
QLocale locale;
locale.setNumberOptions(locale.numberOptions() | QLocale::OmitGroupSeparator);
result.replace(QLatin1String("%m"), locale.toString(totalSteps));
result.replace(QLatin1String("%v"), locale.toString(value()));
// If max and min are equal and we get this far, it means that the
// progress bar has one step and that we are on that step. Return
// 100% here in order to avoid division by zero further down.
if (totalSteps == 0) {
result.replace(QLatin1String("%p"), locale.toString(100));
return result;
}
const auto progress = static_cast<int>((qint64(value()) - minimum()) * 100.0 / totalSteps);
result.replace(QLatin1String("%p"), locale.toString(progress));
return result;
}

View File

@ -0,0 +1,15 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef PROGRESSBARWITHTEXT_H
#define PROGRESSBARWITHTEXT_H
#include <QProgressBar>
class ProgressBarWithText : public QProgressBar {
public:
explicit ProgressBarWithText(QWidget* parent = nullptr);
virtual QString text() const;
};
#endif // PROGRESSBARWITHTEXT_H

View File

@ -4,54 +4,36 @@
#include "gui/dialogs/formmain.h"
#include "gui/reusable/plaintoolbutton.h"
#include "gui/reusable/progressbarwithtext.h"
#include "gui/tabwidget.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include <QLabel>
#include <QProgressBar>
#include <QToolButton>
StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent) {
setSizeGripEnabled(false);
setContentsMargins(2, 0, 2, 2);
m_barProgressFeeds = new QProgressBar(this);
m_barProgressFeeds->setTextVisible(false);
m_barProgressFeeds->setFixedWidth(100);
m_barProgressFeeds = new ProgressBarWithText(this);
m_barProgressFeeds->setTextVisible(true);
m_barProgressFeeds->setFixedWidth(200);
m_barProgressFeeds->setVisible(false);
m_barProgressFeeds->setObjectName(QSL("m_barProgressFeeds"));
m_barProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update progress bar"), this);
m_barProgressFeedsAction->setObjectName(QSL("m_barProgressFeedsAction"));
m_lblProgressFeeds = new QLabel(this);
m_lblProgressFeeds->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressFeeds->setVisible(false);
m_lblProgressFeeds->setObjectName(QSL("m_lblProgressFeeds"));
m_lblProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update label"), this);
m_lblProgressFeedsAction->setObjectName(QSL("m_lblProgressFeedsAction"));
m_barProgressDownload = new QProgressBar(this);
m_barProgressDownload = new ProgressBarWithText(this);
m_barProgressDownload->setTextVisible(true);
m_barProgressDownload->setFixedWidth(100);
m_barProgressDownload->setFixedWidth(200);
m_barProgressDownload->setVisible(false);
m_barProgressDownload->setObjectName(QSL("m_barProgressDownload"));
m_barProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), tr("File download progress bar"), this);
m_barProgressDownloadAction->setObjectName(QSL("m_barProgressDownloadAction"));
m_lblProgressDownload = new QLabel(this);
m_lblProgressDownload->setText("Downloading files in background");
m_lblProgressDownload->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressDownload->setVisible(false);
m_lblProgressDownload->setObjectName(QSL("m_lblProgressDownload"));
m_lblProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), tr("File download label"), this);
m_lblProgressDownloadAction->setObjectName(QSL("m_lblProgressDownloadAction"));
m_lblProgressDownload->installEventFilter(this);
m_barProgressDownload->installEventFilter(this);
}
@ -64,8 +46,8 @@ QList<QAction*> StatusBar::availableActions() const {
QList<QAction*> actions = qApp->userActions();
// Now, add placeholder actions for custom stuff.
actions << m_barProgressDownloadAction << m_barProgressFeedsAction
<< m_lblProgressDownloadAction << m_lblProgressFeedsAction;
actions << m_barProgressDownloadAction
<< m_barProgressFeedsAction;
return actions;
}
@ -99,9 +81,7 @@ QStringList StatusBar::savedActions() const {
}
QList<QAction*> StatusBar::convertActions(const QStringList& actions) {
bool progress_visible = this->actions().contains(m_barProgressFeedsAction) &&
m_lblProgressFeeds->isVisible() &&
m_barProgressFeeds->isVisible();
bool progress_visible = this->actions().contains(m_barProgressFeedsAction) && m_barProgressFeeds->isVisible();
QList<QAction*> available_actions = availableActions();
QList<QAction*> spec_actions;
@ -122,16 +102,6 @@ QList<QAction*> StatusBar::convertActions(const QStringList& actions) {
action_to_add = m_barProgressFeedsAction;
widget_to_add->setVisible(progress_visible);
}
else if (matching_action == m_lblProgressDownloadAction) {
widget_to_add = m_lblProgressDownload;
action_to_add = m_lblProgressDownloadAction;
widget_to_add->setVisible(false);
}
else if (matching_action == m_lblProgressFeedsAction) {
widget_to_add = m_lblProgressFeeds;
action_to_add = m_lblProgressFeedsAction;
widget_to_add->setVisible(progress_visible);
}
else {
if (action_name == SEPARATOR_ACTION_NAME) {
QLabel* lbl = new QLabel(QString::fromUtf8(""), this);
@ -192,7 +162,7 @@ void StatusBar::loadSpecificActions(const QList<QAction*>& actions, bool initial
}
bool StatusBar::eventFilter(QObject* watched, QEvent* event) {
if (watched == m_lblProgressDownload || watched == m_barProgressDownload) {
if (watched == m_barProgressDownload) {
if (event->type() == QEvent::Type::MouseButtonPress) {
qApp->mainForm()->tabWidget()->showDownloadManager();
}
@ -219,30 +189,40 @@ void StatusBar::clear() {
void StatusBar::showProgressFeeds(int progress, const QString& label) {
if (actions().contains(m_barProgressFeedsAction)) {
m_lblProgressFeeds->setVisible(true);
m_barProgressFeeds->setVisible(true);
m_lblProgressFeeds->setText(label);
m_barProgressFeeds->setValue(progress);
m_barProgressFeeds->setFormat(label);
if (progress < 0) {
m_barProgressFeeds->setRange(0, 0);
}
else {
m_barProgressFeeds->setRange(0, 100);
m_barProgressFeeds->setValue(progress);
}
}
}
void StatusBar::clearProgressFeeds() {
m_lblProgressFeeds->setVisible(false);
m_barProgressFeeds->setVisible(false);
}
void StatusBar::showProgressDownload(int progress, const QString& tooltip) {
if (actions().contains(m_barProgressDownloadAction)) {
m_lblProgressDownload->setVisible(true);
m_barProgressDownload->setVisible(true);
m_barProgressDownload->setValue(progress);
m_barProgressDownload->setFormat(tooltip);
m_barProgressDownload->setToolTip(tooltip);
m_lblProgressDownload->setToolTip(tooltip);
if (progress < 0) {
m_barProgressDownload->setRange(0, 0);
}
else {
m_barProgressDownload->setRange(0, 100);
m_barProgressDownload->setValue(progress);
}
}
}
void StatusBar::clearProgressDownload() {
m_lblProgressDownload->setVisible(false);
m_barProgressDownload->setVisible(false);
m_barProgressDownload->setValue(0);
}

View File

@ -7,7 +7,7 @@
#include "gui/toolbars/basetoolbar.h"
class QProgressBar;
class ProgressBarWithText;
class QLabel;
class PlainToolButton;
@ -39,14 +39,10 @@ class StatusBar : public QStatusBar, public BaseBar {
private:
void clear();
QProgressBar* m_barProgressFeeds;
ProgressBarWithText* m_barProgressFeeds;
QAction* m_barProgressFeedsAction;
QLabel* m_lblProgressFeeds;
QAction* m_lblProgressFeedsAction;
QProgressBar* m_barProgressDownload;
ProgressBarWithText* m_barProgressDownload;
QAction* m_barProgressDownloadAction;
QLabel* m_lblProgressDownload;
QAction* m_lblProgressDownloadAction;
};
#endif // STATUSBAR_H

View File

@ -64,6 +64,7 @@ HEADERS += core/feeddownloader.h \
gui/notifications/notificationseditor.h \
gui/notifications/singlenotificationeditor.h \
gui/reusable/baselineedit.h \
gui/reusable/progressbarwithtext.h \
gui/settings/settingsnotifications.h \
gui/toolbars/basetoolbar.h \
gui/reusable/comboboxwithstatus.h \
@ -249,6 +250,7 @@ SOURCES += core/feeddownloader.cpp \
gui/notifications/notificationseditor.cpp \
gui/notifications/singlenotificationeditor.cpp \
gui/reusable/baselineedit.cpp \
gui/reusable/progressbarwithtext.cpp \
gui/settings/settingsnotifications.cpp \
gui/toolbars/basetoolbar.cpp \
gui/reusable/comboboxwithstatus.cpp \

View File

@ -143,7 +143,7 @@ DVALUE(char*) GUI::FeedsToolbarActionsDef = "m_actionUpdateAllItems,m_actionStop
DKEY GUI::StatusbarActions = "status_bar";
DVALUE(char*) GUI::StatusbarActionsDef =
"m_lblProgressFeedsAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_actionFullscreen,m_actionQuit";
"m_barProgressDownloadAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_actionFullscreen,m_actionQuit";
DKEY GUI::MainWindowInitialSize = "window_size";
DKEY GUI::MainWindowInitialPosition = "window_position";

View File

@ -388,7 +388,9 @@ void DownloadItem::updateDownloadInfoLabel() {
}
bool DownloadItem::downloading() const {
return (m_ui->m_progressDownload->isVisible());
return !m_finishedDownloading;
//return (m_ui->m_progressDownload->isVisible());
}
bool DownloadItem::downloadedSuccessfully() const {