Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[aboutsettings] Add diskUsageModel (Contributes to JB#29435)
  • Loading branch information
thp committed Jun 4, 2015
1 parent 244e429 commit 3bd0ae7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/aboutsettings.cpp
Expand Up @@ -41,6 +41,9 @@
#include <QRegularExpression>
#include <QMap>
#include <QTextStream>
#include <QVariant>

#include <mntent.h>


static QMap<QString, QString> parseReleaseFile(const QString &filename)
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/aboutsettings.h
Expand Up @@ -33,6 +33,7 @@
#define ABOUTSETTINGS_H

#include <QObject>
#include <QVariant>

class QStorageInfo;
class QNetworkInfo;
Expand All @@ -52,9 +53,20 @@ class AboutSettings: public QObject
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;
Expand Down

0 comments on commit 3bd0ae7

Please sign in to comment.