diff options
| author | Felix Ernst <[email protected]> | 2024-11-10 16:47:19 +0100 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2024-11-12 10:54:25 +0000 |
| commit | 6c73f7912b6fb0327b9fd0ca7a3fff3b2fb4d5e9 (patch) | |
| tree | 7f3cba330209c4e379d0e688cf46573a2b6c2282 /src/statusbar/statusbarspaceinfo.cpp | |
| parent | ed870aa7ed971af4e5b34bd653fb96998e8dd4f3 (diff) | |
Avoid flickering of space info on startup
Prior to this commit, when Dolphin was opening in a directory for
which the free space information cannot be retrieved, the free
space info in the status bar would still briefly be visible before
hiding for good.
This commit avoids this flickering by keeping the space info hidden
until space info has been successfully retrieved. There is no use
showing an empty/wrong space info before that anyway.
I assume the error in the previous code was that it assumed that
one could prevent a widget from being shown by overriding
QWidget::showEvent(). This does not work because this method is
only called to notify QWidgets of their state change.
This commit was primarily written because the brief showing of an
empty space info was messing with automatic tests.
Diffstat (limited to 'src/statusbar/statusbarspaceinfo.cpp')
| -rw-r--r-- | src/statusbar/statusbarspaceinfo.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/statusbar/statusbarspaceinfo.cpp b/src/statusbar/statusbarspaceinfo.cpp index a482bde9c..c25d028d6 100644 --- a/src/statusbar/statusbarspaceinfo.cpp +++ b/src/statusbar/statusbarspaceinfo.cpp @@ -32,7 +32,11 @@ StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget *parent) : QWidget(parent) , m_observer(nullptr) , m_installFilelightWidgetAction{nullptr} + , m_hasSpaceInfo{false} + , m_shown{false} { + hide(); // Only become visible when we have space info to show. @see StatusBarSpaceInfo::setShown(). + m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this); m_textInfoButton = new QToolButton(this); m_textInfoButton->setAutoRaise(true); @@ -57,7 +61,17 @@ void StatusBarSpaceInfo::setShown(bool shown) m_shown = shown; if (!m_shown) { hide(); - m_ready = false; + return; + } + + // We only show() this widget in slotValueChanged() when it m_hasSpaceInfo. + if (m_observer.isNull()) { + m_observer.reset(new SpaceInfoObserver(m_url, this)); + connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged); + } + + if (m_hasSpaceInfo) { + slotValuesChanged(); } } @@ -65,7 +79,7 @@ void StatusBarSpaceInfo::setUrl(const QUrl &url) { if (m_url != url) { m_url = url; - m_ready = false; + m_hasSpaceInfo = false; if (m_observer) { m_observer.reset(new SpaceInfoObserver(m_url, this)); connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged); @@ -87,23 +101,18 @@ void StatusBarSpaceInfo::update() void StatusBarSpaceInfo::showEvent(QShowEvent *event) { - if (m_shown) { - if (m_ready) { - QWidget::showEvent(event); - } - - if (m_observer.isNull()) { - m_observer.reset(new SpaceInfoObserver(m_url, this)); - connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged); - } + if (m_shown && m_observer.isNull()) { + m_observer.reset(new SpaceInfoObserver(m_url, this)); + connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged); } + QWidget::showEvent(event); } void StatusBarSpaceInfo::hideEvent(QHideEvent *event) { - if (m_ready) { + if (m_hasSpaceInfo) { m_observer.reset(); - m_ready = false; + m_hasSpaceInfo = false; } QWidget::hideEvent(event); } @@ -225,7 +234,7 @@ void StatusBarSpaceInfo::slotValuesChanged() return; } - m_ready = true; + m_hasSpaceInfo = true; const quint64 available = m_observer->available(); const quint64 used = size - available; |
