- const QString mountPointPath = url.toLocalFile();
- qDebug() << "url:" << mountPointPath;
- KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(mountPointPath);
- m_isMountPoint = (mp && mp->mountPoint() == mountPointPath);
- qDebug() << " isMountPoint:" << m_isMountPoint;
- if (m_isMountPoint) {
- const KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mountPointPath);
- m_drawCapacityBar = info.size() != 0;
- m_capacityBarRatio = (qreal)info.used() / (qreal)info.size();
- qDebug() << " capacityBarRatio:" << m_capacityBarRatio << "(" << info.used() << "/" << info.size() << ")";
-
- // update();
- return;
+ if (!m_freeSpaceInfo.job
+ && (
+ !m_freeSpaceInfo.lastUpdated.isValid()
+ || m_freeSpaceInfo.lastUpdated.secsTo(QDateTime::currentDateTimeUtc()) > 60
+ )
+ ) {
+ // qDebug() << "url:" << url;
+ m_freeSpaceInfo.job = KIO::fileSystemFreeSpace(url);
+ connect(
+ m_freeSpaceInfo.job,
+ &KIO::FileSystemFreeSpaceJob::result,
+ this,
+ [this](KIO::Job *job, KIO::filesize_t size, KIO::filesize_t available) {
+ // even if we receive an error we want to refresh lastUpdated to avoid repeatedly querying in this case
+ m_freeSpaceInfo.lastUpdated = QDateTime::currentDateTimeUtc();
+
+ if (job->error()) {
+ return;
+ }
+
+ m_freeSpaceInfo.size = size;
+ m_freeSpaceInfo.used = size - available;
+ m_freeSpaceInfo.usedRatio = (qreal)m_freeSpaceInfo.used / (qreal)m_freeSpaceInfo.size;
+ m_drawCapacityBar = size > 0;
+ // qDebug() << "job.url:" << data().value("url").toUrl();
+ // qDebug() << "job.size:" << m_freeSpaceInfo.size;
+ // qDebug() << "job.used:" << m_freeSpaceInfo.used;
+ // qDebug() << "job.ratio:" << m_freeSpaceInfo.usedRatio;
+ // qDebug() << "job.draw:" << m_drawCapacityBar;
+
+ update();
+ }
+ );
+ } else {
+ // Job running or cache is still valid.