1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Moved fileSizeToString into qz_ function

This commit is contained in:
nowrep 2012-08-23 15:40:10 +02:00
parent 5ca2e2d75f
commit 60ae2c1705
7 changed files with 31 additions and 30 deletions

View File

@ -73,7 +73,7 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, const Do
m_fileSize = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); m_fileSize = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong();
if (m_fileSize > 0) { 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 // Close Empty Tab

View File

@ -24,6 +24,7 @@
#include "downloadmanager.h" #include "downloadmanager.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "globalfunctions.h"
#include <QMenu> #include <QMenu>
#include <QClipboard> #include <QClipboard>
@ -236,27 +237,6 @@ QString DownloadItem::currentSpeedToString(double speed)
return QString::number(speed, 'f', 2) + " GB/s"; 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) void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total)
{ {
#ifdef DOWNMANAGER_DEBUG #ifdef DOWNMANAGER_DEBUG
@ -275,8 +255,8 @@ void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64
QString remTime = remaingTimeToString(time); QString remTime = remaingTimeToString(time);
m_remTime = time; m_remTime = time;
QString currSize = fileSizeToString(received); QString currSize = qz_fileSizeToString(received);
QString fileSize = fileSizeToString(total); QString fileSize = qz_fileSizeToString(total);
if (fileSize == tr("Unknown size")) { if (fileSize == tr("Unknown size")) {
ui->downloadInfo->setText(tr("%2 - unknown size (%3)").arg(currSize, speed)); ui->downloadInfo->setText(tr("%2 - unknown size (%3)").arg(currSize, speed));

View File

@ -53,7 +53,6 @@ public:
static QString remaingTimeToString(QTime time); static QString remaingTimeToString(QTime time);
static QString currentSpeedToString(double speed); static QString currentSpeedToString(double speed);
static QString fileSizeToString(qint64 size);
signals: signals:
void deleteItem(DownloadItem*); void deleteItem(DownloadItem*);

View File

@ -141,9 +141,9 @@ void BrowsingLibrary::optimizeDatabase()
{ {
mApp->setOverrideCursor(Qt::WaitCursor); mApp->setOverrideCursor(Qt::WaitCursor);
QString profilePath = mApp->currentProfilePath(); 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(); mApp->history()->optimizeHistory();
QString sizeAfter = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); QString sizeAfter = qz_fileSizeToString(QFileInfo(profilePath + "browsedata.db").size());
mApp->restoreOverrideCursor(); mApp->restoreOverrideCursor();
QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.<br/><br/><b>Database Size Before: </b>%1<br/><b>Database Size After: </b>%2").arg(sizeBefore, sizeAfter)); QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.<br/><br/><b>Database Size Before: </b>%1<br/><b>Database Size After: </b>%2").arg(sizeBefore, sizeAfter));
} }

View File

@ -265,6 +265,28 @@ QString qz_alignTextToWidth(const QString &string, const QString &text, const QF
return returnString; 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) QPixmap qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)
{ {
const QFontMetrics fontMetrics = QApplication::fontMetrics(); const QFontMetrics fontMetrics = QApplication::fontMetrics();

View File

@ -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_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_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); 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_applyDirectionToPage(QString &pageContents);
QString QT_QUPZILLA_EXPORT qz_buildSystem(); QString QT_QUPZILLA_EXPORT qz_buildSystem();
template <typename T> template <typename T>

View File

@ -68,7 +68,7 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent)
//GENERAL //GENERAL
ui->heading->setText(QString("<b>%1</b>:").arg(title)); ui->heading->setText(QString("<b>%1</b>:").arg(title));
ui->siteAddress->setText(view->url().toString()); ui->siteAddress->setText(view->url().toString());
ui->sizeLabel->setText(DownloadItem::fileSizeToString(webPage->totalBytes())); ui->sizeLabel->setText(qz_fileSizeToString(webPage->totalBytes()));
QString encoding; QString encoding;
//Meta //Meta
@ -202,7 +202,7 @@ void SiteInfo::databaseItemChanged(QListWidgetItem* item)
ui->databaseName->setText(QString("%1 (%2)").arg(db.displayName(), db.name())); ui->databaseName->setText(QString("%1 (%2)").arg(db.displayName(), db.name()));
ui->databasePath->setText(db.fileName()); ui->databasePath->setText(db.fileName());
ui->databaseSize->setText(DownloadItem::fileSizeToString(db.size())); ui->databaseSize->setText(qz_fileSizeToString(db.size()));
} }
void SiteInfo::copyActionData() void SiteInfo::copyActionData()