Commit 3bd0ae74 authored by Thomas Perl's avatar Thomas Perl

[aboutsettings] Add diskUsageModel (Contributes to JB#29435)

parent 244e4298
......@@ -41,6 +41,9 @@
#include <QRegularExpression>
#include <QMap>
#include <QTextStream>
#include <QVariant>
#include <mntent.h>
static QMap<QString, QString> parseReleaseFile(const QString &filename)
......@@ -136,6 +139,47 @@ qlonglong AboutSettings::availableDiskSpace() const
return m_sysinfo->availableDiskSpace("/");
}
QVariant AboutSettings::diskUsageModel() const
{
QVariantList result;
// Optional mountpoints that we want to report disk usage for
QStringList candidates;
candidates << "/home";
// Always report the rootfs
QStringList paths;
paths << "/";
QMap<QString,QString> devices;
FILE *fsd = setmntent(_PATH_MOUNTED, "r");
struct mntent entry;
char buffer[PATH_MAX];
while ((getmntent_r(fsd, &entry, buffer, sizeof(buffer))) != NULL) {
devices[QString::fromLatin1(entry.mnt_dir)] = QString::fromLatin1(entry.mnt_fsname);
}
endmntent(fsd);
foreach (const QString &mountpoint, devices.keys()) {
// Add a reported mountpoint if it's a candidate and if it's not the same as the rootfs
if (candidates.contains(mountpoint) && devices[mountpoint] != devices["/"]) {
paths << mountpoint;
}
}
foreach (const QString &path, paths) {
QVariantMap row;
row["storageType"] = (paths.count() == 1) ? QString("mass") : (path == "/") ? QString("system") : QString("user");
row["path"] = QString(path);
row["available"] = m_sysinfo->availableDiskSpace(path);
row["total"] = m_sysinfo->totalDiskSpace(path);
result << QVariant(row);
}
return result;
}
QString AboutSettings::bluetoothAddress() const
{
return m_netinfo->macAddress(QNetworkInfo::BluetoothMode, 0);
......
......@@ -33,6 +33,7 @@
#define ABOUTSETTINGS_H
#include <QObject>
#include <QVariant>
class QStorageInfo;
class QNetworkInfo;
......@@ -52,9 +53,20 @@ public:
explicit AboutSettings(QObject *parent = 0);
virtual ~AboutSettings();
// Deprecated -- use diskUsageModel() instead
Q_INVOKABLE qlonglong totalDiskSpace() const;
// Deprecated -- use diskUsageModel() instead
Q_INVOKABLE qlonglong availableDiskSpace() const;
/**
* Returns a list of JS objects with the following keys:
* - storageType: one of "mass" (mass storage), "system" (system storage) or "user" (user storage)
* - path: filesystem path (e.g. "/" or "/home/")
* - available: available bytes on the storage
* - total: total bytes on the storage
**/
Q_INVOKABLE QVariant diskUsageModel() const;
QString bluetoothAddress() const;
QString wlanMacAddress() const;
QString imei() const;
......
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