diff --git a/app/inpututils.cpp b/app/inpututils.cpp index 50c23ffa6..5b40e14c0 100644 --- a/app/inpututils.cpp +++ b/app/inpututils.cpp @@ -535,27 +535,7 @@ QString InputUtils::filesToString( QList files ) QString InputUtils::bytesToHumanSize( double bytes ) { - const int precision = 1; - if ( bytes < 1e-5 ) - { - return "0.0"; - } - else if ( bytes < 1024.0 * 1024.0 ) - { - return QString::number( bytes / 1024.0, 'f', precision ) + " KB"; - } - else if ( bytes < 1024.0 * 1024.0 * 1024.0 ) - { - return QString::number( bytes / 1024.0 / 1024.0, 'f', precision ) + " MB"; - } - else if ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 ) - { - return QString::number( bytes / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " GB"; - } - else - { - return QString::number( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " TB"; - } + return CoreUtils::bytesToHumanSize( bytes ); } bool InputUtils::acquireCameraPermission() diff --git a/core/coreutils.cpp b/core/coreutils.cpp index 1b9201f05..834e24c12 100644 --- a/core/coreutils.cpp +++ b/core/coreutils.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "qcoreapplication.h" @@ -283,3 +284,54 @@ QString CoreUtils::nameAbbr( const QString &name, const QString &email ) return email.left( 2 ).toUpper(); } + +QString CoreUtils::getAvailableDeviceStorage() +{ + QString appDir = QCoreApplication::applicationDirPath(); + QStorageInfo storageInfo( appDir ); + + if ( storageInfo.isValid() && storageInfo.isReady() ) + { + return bytesToHumanSize( storageInfo.bytesAvailable() ); + } + + return "N/A"; +} + +QString CoreUtils::getTotalDeviceStorage() +{ + QString appDir = QCoreApplication::applicationDirPath(); + QStorageInfo storageInfo( appDir ); + + if ( storageInfo.isValid() && storageInfo.isReady() ) + { + return bytesToHumanSize( storageInfo.bytesTotal() ); + } + + return "N/A"; +} + +QString CoreUtils::bytesToHumanSize( double bytes ) +{ + const int precision = 1; + if ( bytes < 1e-5 ) + { + return "0.0"; + } + else if ( bytes < 1024.0 * 1024.0 ) + { + return QString::number( bytes / 1024.0, 'f', precision ) + " KB"; + } + else if ( bytes < 1024.0 * 1024.0 * 1024.0 ) + { + return QString::number( bytes / 1024.0 / 1024.0, 'f', precision ) + " MB"; + } + else if ( bytes < 1024.0 * 1024.0 * 1024.0 * 1024.0 ) + { + return QString::number( bytes / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " GB"; + } + else + { + return QString::number( bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0, 'f', precision ) + " TB"; + } +} diff --git a/core/coreutils.h b/core/coreutils.h index fd43a0d53..f39754737 100644 --- a/core/coreutils.h +++ b/core/coreutils.h @@ -109,6 +109,22 @@ class CoreUtils static QString deviceUuid(); static const QString QSETTINGS_APP_GROUP_NAME; + + /** + * Returns available device storage + */ + static QString getAvailableDeviceStorage(); + + /** + * Returns total device storage + */ + static QString getTotalDeviceStorage(); + + /** + * Converts bytes to human readable size (e.g. 1GB, 500MB) + */ + static QString bytesToHumanSize( double bytes ); + private: static QString sLogFile; static int CHECKSUM_CHUNK_SIZE; diff --git a/core/merginapi.cpp b/core/merginapi.cpp index 781c8e990..7967bf484 100644 --- a/core/merginapi.cpp +++ b/core/merginapi.cpp @@ -2415,6 +2415,10 @@ void MerginApi::startProjectPull( const QString &projectFullName ) []( const DownloadQueueItem & a, const DownloadQueueItem & b ) { return a.size > b.size; } ); + CoreUtils::log( "pull " + projectFullName, QStringLiteral( "%1 of available device storage, %2 of total device storage" ) + .arg( CoreUtils::getAvailableDeviceStorage() ) + .arg( CoreUtils::getTotalDeviceStorage() ) ); + CoreUtils::log( "pull " + projectFullName, QStringLiteral( "%1 update tasks, %2 items to download (total size %3 bytes)" ) .arg( transaction.pullTasks.count() ) .arg( transaction.downloadQueue.count() )