This refactors the free space notifier module to use a critical (i.e. persistent and always on top) notification for warning of low disk space.
The, albeit blinking, tray icon is easy to miss, especially when you're running a full screen terminal, which I typically do while compiling stuff.
It now also monitors the Root folder, if it's on a separate partition from the user's home. Furthermore, Filelight is offered to explore the drive (if installed).
The overall warning logic remains pretty much the same:
* Once the drive goes below the configured threshold a warning notification is shown, it stays on screen until dismissed by the user or
when free space is above warning threshold again.
* The notification is emitted again when free space drops below half the previous threshold, for added sense of urgency should the drive
be rapidly filled up
* The notification is also emitted again if free space remains below the threshold for more than one hour
(It will only emit again when it was closed, obviously, so you won't end up with a tonne of popups after a few hours ;)
I don't think this needs to be separately configurable for Home and Root, since the default threshold is like 200 MiB (it's not a configured
percentage), so the absolute free space it warns about will be the same, even if your Home is giant compared to Root.
BUG: 340582
FIXED-IN: 5.20.0
Differential Revision: https://phabricator.kde.org/D29770
if(m_lastAvail<0||avail<m_lastAvail/2){// always warn the first time or when available dropped to a half of previous one, warn again
m_lastAvail=avail;
warn=true;
}elseif(avail>m_lastAvail){// the user freed some space
m_lastAvail=avail;// so warn if it goes low again
if(m_sni){
// keep the SNI active, but don't blink
m_sni->setStatus(KStatusNotifierItem::Active);
m_sni->setToolTip(QStringLiteral("drive-harddisk"),i18n("Low Disk Space"),i18n("Remaining space in your Home folder: %1 MiB",QLocale::system().toString(avail)));
}
if(avail>=limit){
if(m_notification){
m_notification->close();
}
// do not change lastAvail otherwise, to handle free space slowly going down
m_sni->setToolTip(QStringLiteral("drive-harddisk"),i18n("Low Disk Space"),i18n("Remaining space in your Home folder: %1 MiB",QLocale::system().toString(avail)));
m_notification->setText(i18nc("Warns the user that the system is running low on space on his home folder, indicating the percentage and absolute MiB size remaining",
"Your Home folder is running out of disk space, you have %1 MiB remaining (%2%)",QLocale::system().toString(avail),availpct));
autofilelight=filelightService();
if(filelight){
actions.prepend(i18n("Open in Filelight"));
}else{
// Do we really want the user opening Root in a file manager?