mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Status bar: Hide the space free bar when size is unknown
Summary: BUG: 420027 BUG: 422226 FIXED-IN: 20.08 Test Plan: {F8312398} Reviewers: #dolphin, ngraham, broulik, #vdg, elvisangelaccio Reviewed By: #dolphin, ngraham, #vdg, elvisangelaccio Subscribers: elvisangelaccio, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D29213
This commit is contained in:
parent
f7a3318fa5
commit
bf4388c755
|
@ -229,7 +229,9 @@ QString DolphinStatusBar::defaultText() const
|
|||
|
||||
void DolphinStatusBar::setUrl(const QUrl& url)
|
||||
{
|
||||
m_spaceInfo->setUrl(url);
|
||||
if (GeneralSettings::showSpaceInfo()) {
|
||||
m_spaceInfo->setUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
QUrl DolphinStatusBar::url() const
|
||||
|
@ -332,7 +334,7 @@ void DolphinStatusBar::setExtensionsVisible(bool visible)
|
|||
showSpaceInfo = GeneralSettings::showSpaceInfo();
|
||||
showZoomSlider = GeneralSettings::showZoomSlider();
|
||||
}
|
||||
m_spaceInfo->setVisible(showSpaceInfo);
|
||||
m_spaceInfo->setShown(showSpaceInfo);
|
||||
m_zoomSlider->setVisible(showZoomSlider);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
SpaceInfoObserver::SpaceInfoObserver(const QUrl& url, QObject* parent) :
|
||||
QObject(parent),
|
||||
m_mountPointObserver(nullptr),
|
||||
m_hasData(false),
|
||||
m_dataSize(0),
|
||||
m_dataAvailable(0)
|
||||
{
|
||||
|
@ -81,7 +82,8 @@ void SpaceInfoObserver::update()
|
|||
void SpaceInfoObserver::spaceInfoChanged(quint64 size, quint64 available)
|
||||
{
|
||||
// Make sure that the size has actually changed
|
||||
if (m_dataSize != size || m_dataAvailable != available) {
|
||||
if (m_dataSize != size || m_dataAvailable != available || !m_hasData) {
|
||||
m_hasData = true;
|
||||
m_dataSize = size;
|
||||
m_dataAvailable = available;
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ private slots:
|
|||
private:
|
||||
MountPointObserver* m_mountPointObserver;
|
||||
|
||||
bool m_hasData;
|
||||
quint64 m_dataSize;
|
||||
quint64 m_dataAvailable;
|
||||
};
|
||||
|
|
|
@ -38,12 +38,23 @@ StatusBarSpaceInfo::~StatusBarSpaceInfo()
|
|||
{
|
||||
}
|
||||
|
||||
void StatusBarSpaceInfo::setShown(bool shown)
|
||||
{
|
||||
m_shown = shown;
|
||||
if (!m_shown) {
|
||||
hide();
|
||||
m_ready = false;
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBarSpaceInfo::setUrl(const QUrl& url)
|
||||
{
|
||||
if (m_url != url) {
|
||||
m_url = url;
|
||||
m_ready = false;
|
||||
if (m_observer) {
|
||||
m_observer->setUrl(url);
|
||||
m_observer.reset(new SpaceInfoObserver(m_url, this));
|
||||
connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,15 +73,24 @@ void StatusBarSpaceInfo::update()
|
|||
|
||||
void StatusBarSpaceInfo::showEvent(QShowEvent* event)
|
||||
{
|
||||
KCapacityBar::showEvent(event);
|
||||
m_observer.reset(new SpaceInfoObserver(m_url, this));
|
||||
slotValuesChanged();
|
||||
connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged);
|
||||
if (m_shown) {
|
||||
if (m_ready) {
|
||||
KCapacityBar::showEvent(event);
|
||||
}
|
||||
|
||||
if (m_observer.isNull()) {
|
||||
m_observer.reset(new SpaceInfoObserver(m_url, this));
|
||||
connect(m_observer.data(), &SpaceInfoObserver::valuesChanged, this, &StatusBarSpaceInfo::slotValuesChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBarSpaceInfo::hideEvent(QHideEvent* event)
|
||||
{
|
||||
m_observer.reset();
|
||||
if (m_ready) {
|
||||
m_observer.reset();
|
||||
m_ready = false;
|
||||
}
|
||||
KCapacityBar::hideEvent(event);
|
||||
}
|
||||
|
||||
|
@ -95,19 +115,26 @@ void StatusBarSpaceInfo::slotValuesChanged()
|
|||
{
|
||||
Q_ASSERT(m_observer);
|
||||
const quint64 size = m_observer->size();
|
||||
if (size == 0) {
|
||||
setText(i18nc("@info:status", "Unknown size"));
|
||||
setValue(0);
|
||||
update();
|
||||
} else {
|
||||
const quint64 available = m_observer->available();
|
||||
const quint64 used = size - available;
|
||||
const int percentUsed = qRound(100.0 * qreal(used) / qreal(size));
|
||||
|
||||
setText(i18nc("@info:status Free disk space", "%1 free", KIO::convertSize(available)));
|
||||
setUpdatesEnabled(false);
|
||||
setValue(percentUsed);
|
||||
setUpdatesEnabled(true);
|
||||
if (!m_shown || size == 0) {
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
m_ready = true;
|
||||
|
||||
const quint64 available = m_observer->available();
|
||||
const quint64 used = size - available;
|
||||
const int percentUsed = qRound(100.0 * qreal(used) / qreal(size));
|
||||
|
||||
setText(i18nc("@info:status Free disk space", "%1 free", KIO::convertSize(available)));
|
||||
setUpdatesEnabled(false);
|
||||
setValue(percentUsed);
|
||||
setUpdatesEnabled(true);
|
||||
|
||||
if (!isVisible()) {
|
||||
show();
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,10 @@ public:
|
|||
explicit StatusBarSpaceInfo(QWidget* parent = nullptr);
|
||||
~StatusBarSpaceInfo() override;
|
||||
|
||||
/**
|
||||
* Use this to set the widget visibility as it can hide itself
|
||||
*/
|
||||
void setShown(bool);
|
||||
void setUrl(const QUrl& url);
|
||||
QUrl url() const;
|
||||
|
||||
|
@ -58,6 +62,8 @@ private slots:
|
|||
private:
|
||||
QScopedPointer<SpaceInfoObserver> m_observer;
|
||||
QUrl m_url;
|
||||
bool m_ready;
|
||||
bool m_shown;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue