1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-06-30 15:36:30 +00:00

Prevent inconsistent status bar progress reporting states

Merge setting title and progress percent into one method. This
makes sure that the method can be called from all over the place
and will still always show a consistent state instead of partially
showing the progress percent for one progress but the label for
a different one.

This is to enable various tasks reporting progress at the same time
in a way that doesn't lead to a confusing mess for users. Usually
multiple tasks do not show progress at the same time, but when it
happens this commit should make sure that the user experience is
at least bearable.

Allow not having a "Stop" button next to the progress report for
tasks that cannot be stopped.
This commit is contained in:
Felix Ernst 2024-06-13 16:38:41 +02:00 committed by Felix Ernst
parent 15eff9f5ad
commit 9108534ce0
4 changed files with 50 additions and 66 deletions

View File

@ -141,8 +141,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinViewContainer::slotDirectoryLoadingCompleted);
connect(m_view, &DolphinView::directoryLoadingCanceled, this, &DolphinViewContainer::slotDirectoryLoadingCanceled);
connect(m_view, &DolphinView::itemCountChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinViewContainer::updateDirectoryLoadingProgress);
connect(m_view, &DolphinView::directorySortingProgress, this, &DolphinViewContainer::updateDirectorySortingProgress);
connect(m_view, &DolphinView::selectionChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::showErrorMessage);
connect(m_view, &DolphinView::urlIsFileError, this, &DolphinViewContainer::slotUrlIsFileError);
@ -162,6 +160,12 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
connect(m_view, &DolphinView::operationCompletedMessage, m_statusBar, &DolphinStatusBar::setText);
connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::setDefaultText);
connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::resetToDefaultText);
connect(m_view, &DolphinView::directoryLoadingProgress, m_statusBar, [this](int percent) {
m_statusBar->showProgress(i18nc("@info:progress", "Loading folder…"), percent);
});
connect(m_view, &DolphinView::directorySortingProgress, m_statusBar, [this](int percent) {
m_statusBar->showProgress(i18nc("@info:progress", "Sorting…"), percent);
});
connect(m_statusBar, &DolphinStatusBar::stopPressed, this, &DolphinViewContainer::stopDirectoryLoading);
connect(m_statusBar, &DolphinStatusBar::zoomLevelChanged, this, &DolphinViewContainer::slotStatusBarZoomLevelChanged);
@ -622,36 +626,18 @@ void DolphinViewContainer::updateStatusBar()
m_view->requestStatusBarText();
}
void DolphinViewContainer::updateDirectoryLoadingProgress(int percent)
{
if (m_statusBar->progressText().isEmpty()) {
m_statusBar->setProgressText(i18nc("@info:progress", "Loading folder…"));
}
m_statusBar->setProgress(percent);
}
void DolphinViewContainer::updateDirectorySortingProgress(int percent)
{
if (m_statusBar->progressText().isEmpty()) {
m_statusBar->setProgressText(i18nc("@info:progress", "Sorting…"));
}
m_statusBar->setProgress(percent);
}
void DolphinViewContainer::slotDirectoryLoadingStarted()
{
if (isSearchUrl(url())) {
// Search KIO-slaves usually don't provide any progress information. Give
// a hint to the user that a searching is done:
updateStatusBar();
m_statusBar->setProgressText(i18nc("@info", "Searching…"));
m_statusBar->setProgress(-1);
m_statusBar->showProgress(i18nc("@info", "Searching…"), -1);
} else {
// Trigger an undetermined progress indication. The progress
// information in percent will be triggered by the percent() signal
// of the directory lister later.
m_statusBar->setProgressText(QString());
updateDirectoryLoadingProgress(-1);
m_statusBar->showProgress(QString(), -1);
}
if (m_urlNavigatorConnected) {
@ -661,10 +647,7 @@ void DolphinViewContainer::slotDirectoryLoadingStarted()
void DolphinViewContainer::slotDirectoryLoadingCompleted()
{
if (!m_statusBar->progressText().isEmpty()) {
m_statusBar->setProgressText(QString());
m_statusBar->setProgress(100);
}
m_statusBar->showProgress(QString(), 100);
if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
// The dir lister has been completed on a Baloo-URI and no items have been found. Instead
@ -681,11 +664,7 @@ void DolphinViewContainer::slotDirectoryLoadingCompleted()
void DolphinViewContainer::slotDirectoryLoadingCanceled()
{
if (!m_statusBar->progressText().isEmpty()) {
m_statusBar->setProgressText(QString());
m_statusBar->setProgress(100);
}
m_statusBar->showProgress(QString(), 100);
m_statusBar->setText(QString());
}
@ -927,7 +906,7 @@ void DolphinViewContainer::closeSearchBox()
void DolphinViewContainer::stopDirectoryLoading()
{
m_view->stopLoading();
m_statusBar->setProgress(100);
m_statusBar->showProgress(QString(), 100);
}
void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)

View File

@ -283,10 +283,6 @@ private Q_SLOTS:
*/
void updateStatusBar();
void updateDirectoryLoadingProgress(int percent);
void updateDirectorySortingProgress(int percent);
/**
* Updates the statusbar to show an undetermined progress with the correct
* context information whether a searching or a directory loading is done.

View File

@ -164,37 +164,42 @@ QString DolphinStatusBar::text() const
return m_text;
}
void DolphinStatusBar::setProgressText(const QString &text)
void DolphinStatusBar::showProgress(const QString &currentlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading)
{
m_progressTextLabel->setText(text);
}
m_cancelLoading = cancelLoading;
QString DolphinStatusBar::progressText() const
{
return m_progressTextLabel->text();
}
void DolphinStatusBar::setProgress(int percent)
{
// Show a busy indicator if a value < 0 is provided:
m_progressBar->setMaximum((percent < 0) ? 0 : 100);
m_progressBar->setMaximum((progressPercent < 0) ? 0 : 100);
percent = qBound(0, percent, 100);
const bool progressRestarted = (percent < 100) && (percent < m_progress);
m_progress = percent;
if (progressRestarted && !m_progressBar->isVisible()) {
progressPercent = qBound(0, progressPercent, 100);
if (!m_progressBar->isVisible()) {
// Show the progress bar delayed: In the case if 100 % are reached within
// a short time, no progress bar will be shown at all.
m_showProgressBarTimer->start();
if (!m_showProgressBarTimer->isActive()) {
m_showProgressBarTimer->start();
} else {
// The timer is already running. Should we restart it or keep it running?
if (m_progressTextLabel->text() != currentlyRunningTaskTitle || (progressPercent < 100 && progressPercent < m_progress)) {
m_showProgressBarTimer->start();
}
}
}
m_progress = progressPercent;
m_progressBar->setValue(m_progress);
if (percent == 100) {
if (progressPercent == 100) {
// The end of the progress has been reached. Assure that the progress bar
// gets hidden and the extensions widgets get visible again.
m_showProgressBarTimer->stop();
updateProgressInfo();
}
m_progressTextLabel->setText(currentlyRunningTaskTitle);
}
QString DolphinStatusBar::progressText() const
{
return m_progressTextLabel->text();
}
int DolphinStatusBar::progress() const
@ -302,7 +307,7 @@ void DolphinStatusBar::updateProgressInfo()
{
if (m_progress < 100) {
// Show the progress information and hide the extensions
m_stopButton->show();
m_stopButton->setVisible(m_cancelLoading == CancelLoading::Allowed);
m_progressTextLabel->show();
m_progressBar->show();
setExtensionsVisible(false);

View File

@ -37,21 +37,23 @@ public:
QString text() const;
enum class CancelLoading { Allowed, Disallowed };
/**
* Sets the text for the progress information.
* DolphinStatusBar::setProgress() should be invoked
* afterwards each time the progress changes.
* Shows progress for a task on the status bar.
*
* Allows us to inform the user about various tasks progressing in the background.
* This method can be called from various places in any order but only the most recent call will be displayed.
* @param currentlyRunningTaskTitle The task that is currently progressing.
* @param progressPercent The percent value shown in a progress bar next to the @p currentlyRunningTaskTitle.
* A negative @p progressPercent value will be interpreted as indeterminate/unknown progress.
* The progress is shown delayed by 500 milliseconds: If the progress does reach 100 % within 500 milliseconds,
* the progress is not shown at all.
* @param cancelLoading Whether a "Stop" button for cancelling the task should be available next to the progress reporting.
*
* @note Make sure you also hide the progress information by calling this with a @p progressPercent equal or greater than 100.
*/
void setProgressText(const QString &text);
void showProgress(const QString &currentlyRunningTaskTitle, int progressPercent, CancelLoading cancelLoading = CancelLoading::Allowed);
QString progressText() const;
/**
* Sets the progress in percent (0 - 100). The
* progress is shown delayed by 500 milliseconds:
* If the progress does reach 100 % within 500 milliseconds,
* the progress is not shown at all.
*/
void setProgress(int percent);
int progress() const;
/**
@ -100,6 +102,7 @@ protected:
private Q_SLOTS:
void showZoomSliderToolTip(int zoomLevel);
void updateProgressInfo();
/**
@ -138,6 +141,7 @@ private:
QSlider *m_zoomSlider;
QLabel *m_progressTextLabel;
CancelLoading m_cancelLoading = CancelLoading::Allowed;
QProgressBar *m_progressBar;
QToolButton *m_stopButton;
int m_progress;