- // Use a timer to update the space information. Polling is useful
- // here, as files can be deleted/added outside the scope of Dolphin.
- m_timer = new QTimer(this);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh()));
+StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget *parent)
+ : QWidget(parent)
+ , m_observer(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);
+ m_textInfoButton->setPopupMode(QToolButton::InstantPopup);
+ auto menu = new DiskSpaceUsageMenu{this};
+ connect(menu, &DiskSpaceUsageMenu::showMessage, this, &StatusBarSpaceInfo::showMessage);
+ connect(menu, &DiskSpaceUsageMenu::showInstallationProgress, this, &StatusBarSpaceInfo::showInstallationProgress);
+ m_textInfoButton->setMenu(menu);
+
+ auto layout = new QHBoxLayout(this);
+ // We reduce the outside margin of the flat button so it visually has the same margin as the status bar text label on the other end of the bar.
+ layout->setContentsMargins(2, -1, 0, -1); // "-1" makes it so the fixed height won't be ignored.
+ layout->addWidget(m_capacityBar);
+ layout->addWidget(m_textInfoButton);