Commit 73d36f25 authored by jpetrell's avatar jpetrell

Merge branch 'jb36373' into 'master'

[storage] Expose partition model as its own role. Contributes to JB#36373

Makes it possible for the delegate to call storageModel.refresh()

See merge request !22
parents 39d7065c c3c6d186
......@@ -229,7 +229,7 @@ void PartitionManagerPrivate::refresh()
const auto removedPartitions = m_partitions.mid(index);
m_partitions.resize(index);
refresh(m_partitions);
refresh(m_partitions, changedPartitions);
for (const auto partition : removedPartitions) {
emit partitionRemoved(Partition(partition));
......@@ -249,12 +249,12 @@ void PartitionManagerPrivate::refresh()
void PartitionManagerPrivate::refresh(PartitionPrivate *partition)
{
refresh(Partitions() << QExplicitlySharedDataPointer<PartitionPrivate>(partition));
refresh(Partitions() << QExplicitlySharedDataPointer<PartitionPrivate>(partition), Partitions() << QExplicitlySharedDataPointer<PartitionPrivate>(partition));
emit partitionChanged(Partition(QExplicitlySharedDataPointer<PartitionPrivate>(partition)));
}
void PartitionManagerPrivate::refresh(const Partitions &partitions)
void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &changedPartitions)
{
for (auto partition : partitions) {
// Reset properties to the unmounted defaults. If the partition is mounted these will be restored
......@@ -311,11 +311,20 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions)
if (partition->status == Partition::Mounted) {
struct statvfs64 stat;
if (::statvfs64(partition->mountPath.toUtf8().constData(), &stat) == 0) {
partition->bytesTotal = stat.f_blocks * stat.f_frsize;
partition->bytesFree = stat.f_bfree * stat.f_frsize;
partition->bytesAvailable = stat.f_bavail * stat.f_frsize;
qint64 bytesFree = stat.f_bfree * stat.f_frsize;
qint64 bytesAvailable = stat.f_bavail * stat.f_frsize;
partition->readOnly = (stat.f_flag & ST_RDONLY) != 0;
if (partition->bytesFree != bytesFree || partition->bytesAvailable != bytesAvailable) {
if (!changedPartitions.contains(partition)) {
changedPartitions.append(partition);
}
}
partition->bytesFree = bytesFree;
partition->bytesAvailable = bytesAvailable;
}
} else if (partition->storageType == Partition::External) {
// Presume the file system can be mounted, unless we can confirm otherwise.
......
......@@ -53,7 +53,7 @@ public:
void refresh();
void refresh(PartitionPrivate *partition);
void refresh(const Partitions &partitions);
void refresh(const Partitions &partitions, Partitions &changedPartitions);
signals:
void partitionChanged(const Partition &partition);
......
......@@ -131,7 +131,8 @@ QHash<int, QByteArray> PartitionModel::roleNames() const
{ MountPathRole, "mountPath" },
{ BytesAvailableRole, "bytesAvailable" },
{ BytesTotalRole, "bytesTotal" },
{ BytesFreeRole, "bytesFree" }
{ BytesFreeRole, "bytesFree" },
{ PartitionModelRole, "partitionModel" }
};
return roleNames;
......@@ -172,6 +173,8 @@ QVariant PartitionModel::data(const QModelIndex &index, int role) const
return partition.bytesTotal();
case BytesFreeRole:
return partition.bytesFree();
case PartitionModelRole:
return QVariant::fromValue(static_cast<QObject*>(const_cast<PartitionModel*>((this))));
default:
return QVariant();
}
......
......@@ -57,6 +57,7 @@ public:
BytesAvailableRole,
BytesTotalRole,
BytesFreeRole,
PartitionModelRole
};
enum Status {
......
......@@ -52,7 +52,7 @@ static QVariantMap g_mocked_apkd_size;
/* Mocked implementations of size calculation functions */
quint64 DiskUsageWorker::calculateSize(QString directory, QString *expandedPath, bool androidHomeExists)
quint64 DiskUsageWorker::calculateSize(QString directory, QString *expandedPath, bool)
{
if (expandedPath) {
*expandedPath = directory;
......
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