Commit 065ba968 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

[kio_desktop] Implement SlaveBase::GetFileSystemFreeSpace

This enables reporting the actual free space info for desktop:/ in e.g.
the Dolphin status bar.

BUG: 417851

FIXED-IN: 5.19.80
parent 7c7d28ee
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
#include <KDesktopFile> #include <KDesktopFile>
#include <KDirNotify> #include <KDirNotify>
#include <KLocalizedString> #include <KLocalizedString>
#include <KDiskFreeSpaceInfo>
#include <kio/udsentry.h> #include <KIO/StatJob>
#include <KIO/UDSEntry>
#include <QCoreApplication> #include <QCoreApplication>
#include <QFile> #include <QFile>
...@@ -226,3 +227,27 @@ void DesktopProtocol::rename(const QUrl &_src, const QUrl &_dest, KIO::JobFlags ...@@ -226,3 +227,27 @@ void DesktopProtocol::rename(const QUrl &_src, const QUrl &_dest, KIO::JobFlags
} }
} }
void DesktopProtocol::virtual_hook(int id, void *data)
{
switch(id) {
case SlaveBase::GetFileSystemFreeSpace: {
QUrl *url = static_cast<QUrl *>(data);
fileSystemFreeSpace(*url);
} break;
default:
SlaveBase::virtual_hook(id, data);
}
}
void DesktopProtocol::fileSystemFreeSpace(const QUrl &url)
{
const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
const KDiskFreeSpaceInfo spaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(desktopPath);
if (spaceInfo.isValid()) {
setMetaData(QStringLiteral("total"), QString::number(spaceInfo.size()));
setMetaData(QStringLiteral("available"), QString::number(spaceInfo.available()));
finished();
} else {
error(KIO::ERR_CANNOT_STAT, desktopPath);
}
}
...@@ -36,6 +36,11 @@ protected: ...@@ -36,6 +36,11 @@ protected:
void listDir(const QUrl &url) override; void listDir(const QUrl &url) override;
void prepareUDSEntry(KIO::UDSEntry &entry, bool listing=false) const override; void prepareUDSEntry(KIO::UDSEntry &entry, bool listing=false) const override;
void rename(const QUrl &, const QUrl &, KIO::JobFlags flags) override; void rename(const QUrl &, const QUrl &, KIO::JobFlags flags) override;
void virtual_hook(int id, void *data) override;
private:
void fileSystemFreeSpace(const QUrl &url);
}; };
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment