diff --git a/src/lib/downloads/downloadfilehelper.cpp b/src/lib/downloads/downloadfilehelper.cpp index 2242299da..c2db65e86 100644 --- a/src/lib/downloads/downloadfilehelper.cpp +++ b/src/lib/downloads/downloadfilehelper.cpp @@ -73,7 +73,7 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, const Do m_fileSize = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); if (m_fileSize > 0) { - mimeType.append(QString(" (%1)").arg(DownloadItem::fileSizeToString(m_fileSize))); + mimeType.append(QString(" (%1)").arg(qz_fileSizeToString(m_fileSize))); } // Close Empty Tab diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index b0e86b06c..806437c06 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -24,6 +24,7 @@ #include "downloadmanager.h" #include "iconprovider.h" #include "networkmanager.h" +#include "globalfunctions.h" #include #include @@ -236,27 +237,6 @@ QString DownloadItem::currentSpeedToString(double speed) return QString::number(speed, 'f', 2) + " GB/s"; } -QString DownloadItem::fileSizeToString(qint64 size) -{ - if (size < 0) { - return tr("Unknown size"); - } - - double _size = (double)size; - _size /= 1024; //kB - if (_size < 1000) { - return QString::number(_size, 'f', 0) + " kB"; - } - - _size /= 1024; //MB - if (_size < 1000) { - return QString::number(_size, 'f', 1) + " MB"; - } - - _size /= 1024; //GB - return QString::number(_size, 'f', 2) + " GB"; -} - void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total) { #ifdef DOWNMANAGER_DEBUG @@ -275,8 +255,8 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 QString remTime = remaingTimeToString(time); m_remTime = time; - QString currSize = fileSizeToString(received); - QString fileSize = fileSizeToString(total); + QString currSize = qz_fileSizeToString(received); + QString fileSize = qz_fileSizeToString(total); if (fileSize == tr("Unknown size")) { ui->downloadInfo->setText(tr("%2 - unknown size (%3)").arg(currSize, speed)); diff --git a/src/lib/downloads/downloaditem.h b/src/lib/downloads/downloaditem.h index ed7e2f463..4482904a7 100644 --- a/src/lib/downloads/downloaditem.h +++ b/src/lib/downloads/downloaditem.h @@ -53,7 +53,6 @@ public: static QString remaingTimeToString(QTime time); static QString currentSpeedToString(double speed); - static QString fileSizeToString(qint64 size); signals: void deleteItem(DownloadItem*); diff --git a/src/lib/other/browsinglibrary.cpp b/src/lib/other/browsinglibrary.cpp index 4d5d3ca79..1e9c5b42a 100644 --- a/src/lib/other/browsinglibrary.cpp +++ b/src/lib/other/browsinglibrary.cpp @@ -141,9 +141,9 @@ void BrowsingLibrary::optimizeDatabase() { mApp->setOverrideCursor(Qt::WaitCursor); QString profilePath = mApp->currentProfilePath(); - QString sizeBefore = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); + QString sizeBefore = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); mApp->history()->optimizeHistory(); - QString sizeAfter = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); + QString sizeAfter = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); mApp->restoreOverrideCursor(); QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.

Database Size Before: %1
Database Size After: %2").arg(sizeBefore, sizeAfter)); } diff --git a/src/lib/tools/globalfunctions.cpp b/src/lib/tools/globalfunctions.cpp index 415cf0bc7..fb4421587 100644 --- a/src/lib/tools/globalfunctions.cpp +++ b/src/lib/tools/globalfunctions.cpp @@ -265,6 +265,28 @@ QString qz_alignTextToWidth(const QString &string, const QString &text, const QF return returnString; } +QString qz_fileSizeToString(qint64 size) +{ + if (size < 0) { + return QObject::tr("Unknown size"); + } + + double _size = (double)size; + _size /= 1024; //kB + if (_size < 1000) { + return QString::number(_size > 1 ? _size : 1, 'f', 0) + " KB"; + } + + _size /= 1024; //MB + if (_size < 1000) { + return QString::number(_size, 'f', 1) + " MB"; + } + + _size /= 1024; //GB + return QString::number(_size, 'f', 2) + " GB"; +} + + QPixmap qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url) { const QFontMetrics fontMetrics = QApplication::fontMetrics(); diff --git a/src/lib/tools/globalfunctions.h b/src/lib/tools/globalfunctions.h index f4bebdf71..b60e0526e 100644 --- a/src/lib/tools/globalfunctions.h +++ b/src/lib/tools/globalfunctions.h @@ -49,11 +49,11 @@ QString QT_QUPZILLA_EXPORT qz_getFileNameFromUrl(const QUrl &url); QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name); QString QT_QUPZILLA_EXPORT qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width); +QString QT_QUPZILLA_EXPORT qz_fileSizeToString(qint64 size); QPixmap QT_QUPZILLA_EXPORT qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url); QString QT_QUPZILLA_EXPORT qz_applyDirectionToPage(QString &pageContents); - QString QT_QUPZILLA_EXPORT qz_buildSystem(); template diff --git a/src/lib/webview/siteinfo.cpp b/src/lib/webview/siteinfo.cpp index 4e82bb369..a8f65f9aa 100644 --- a/src/lib/webview/siteinfo.cpp +++ b/src/lib/webview/siteinfo.cpp @@ -68,7 +68,7 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent) //GENERAL ui->heading->setText(QString("%1:").arg(title)); ui->siteAddress->setText(view->url().toString()); - ui->sizeLabel->setText(DownloadItem::fileSizeToString(webPage->totalBytes())); + ui->sizeLabel->setText(qz_fileSizeToString(webPage->totalBytes())); QString encoding; //Meta @@ -202,7 +202,7 @@ void SiteInfo::databaseItemChanged(QListWidgetItem* item) ui->databaseName->setText(QString("%1 (%2)").arg(db.displayName(), db.name())); ui->databasePath->setText(db.fileName()); - ui->databaseSize->setText(DownloadItem::fileSizeToString(db.size())); + ui->databaseSize->setText(qz_fileSizeToString(db.size())); } void SiteInfo::copyActionData()