Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
setvisible committed May 10, 2023
2 parents fc73a08 + dba2e2b commit cf88e9b
Show file tree
Hide file tree
Showing 56 changed files with 10,940 additions and 10,503 deletions.
12 changes: 6 additions & 6 deletions src/core/abstractdownloaditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,31 @@ const char* AbstractDownloadItem::state_c_str() const

/******************************************************************************
******************************************************************************/
qint64 AbstractDownloadItem::bytesReceived() const
qsizetype AbstractDownloadItem::bytesReceived() const
{
return m_bytesReceived;
}

void AbstractDownloadItem::setBytesReceived(qint64 bytesReceived)
void AbstractDownloadItem::setBytesReceived(qsizetype bytesReceived)
{
m_bytesReceived = bytesReceived;
}

/******************************************************************************
******************************************************************************/
qint64 AbstractDownloadItem::bytesTotal() const
qsizetype AbstractDownloadItem::bytesTotal() const
{
return m_bytesTotal;
}

void AbstractDownloadItem::setBytesTotal(qint64 bytesTotal)
void AbstractDownloadItem::setBytesTotal(qsizetype bytesTotal)
{
m_bytesTotal = bytesTotal;
}

/******************************************************************************
******************************************************************************/
double AbstractDownloadItem::speed() const
qreal AbstractDownloadItem::speed() const
{
return m_state == Downloading ? m_speed : -1;
}
Expand Down Expand Up @@ -365,7 +365,7 @@ void AbstractDownloadItem::rename(const QString &newName)

/******************************************************************************
******************************************************************************/
void AbstractDownloadItem::updateInfo(qint64 bytesReceived, qint64 bytesTotal)
void AbstractDownloadItem::updateInfo(qsizetype bytesReceived, qsizetype bytesTotal)
{
m_bytesReceived = bytesReceived;
m_bytesTotal = bytesTotal;
Expand Down
16 changes: 8 additions & 8 deletions src/core/abstractdownloaditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class AbstractDownloadItem : public QObject, public IDownloadItem
QString stateToString() const;
const char* state_c_str() const;

qint64 bytesReceived() const Q_DECL_OVERRIDE;
void setBytesReceived(qint64 bytesReceived);
qsizetype bytesReceived() const Q_DECL_OVERRIDE;
void setBytesReceived(qsizetype bytesReceived);

qint64 bytesTotal() const Q_DECL_OVERRIDE;
void setBytesTotal(qint64 bytesTotal);
qsizetype bytesTotal() const Q_DECL_OVERRIDE;
void setBytesTotal(qsizetype bytesTotal);

double speed() const Q_DECL_OVERRIDE;
qreal speed() const Q_DECL_OVERRIDE;
int progress() const Q_DECL_OVERRIDE;

QString errorMessage() const;
Expand Down Expand Up @@ -88,7 +88,7 @@ class AbstractDownloadItem : public QObject, public IDownloadItem
void renamed(QString oldName, QString newName, bool success);

public slots:
void updateInfo(qint64 bytesReceived, qint64 bytesTotal);
void updateInfo(qsizetype bytesReceived, qsizetype bytesTotal);

private slots:
void updateInfo();
Expand All @@ -97,8 +97,8 @@ private slots:
State m_state;

qreal m_speed;
qint64 m_bytesReceived;
qint64 m_bytesTotal;
qsizetype m_bytesReceived;
qsizetype m_bytesTotal;

QString m_errorMessage;

Expand Down
6 changes: 3 additions & 3 deletions src/core/downloadengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ void DownloadEngine::onSpeedTimerTimeout()
emit onChanged();
}

double DownloadEngine::totalSpeed()
qreal DownloadEngine::totalSpeed()
{
double speed = 0;
qreal speed = 0;
foreach (auto item, m_items) {
speed += qMax(item->speed(), 0.0);
speed += qMax(item->speed(), qreal(0));
}
if (speed > 0) {
m_previouSpeed = speed;
Expand Down
4 changes: 2 additions & 2 deletions src/core/downloadengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DownloadEngine : public QObject
QList<IDownloadItem *> failedJobs() const;
QList<IDownloadItem *> runningJobs() const;

double totalSpeed();
qreal totalSpeed();

/* Actions */
void resume(IDownloadItem *item);
Expand Down Expand Up @@ -113,7 +113,7 @@ private slots:
private:
QList<IDownloadItem *> m_items;

double m_previouSpeed = 0;
qreal m_previouSpeed = 0;
QTimer m_speedTimer;

// Pool
Expand Down
6 changes: 3 additions & 3 deletions src/core/downloaditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void DownloadItem::resume()

/* Signals/Slots of QNetworkReply */
connect(d->reply, SIGNAL(metaDataChanged()), this, SLOT(onMetaDataChanged()));
connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(onDownloadProgress(qint64,qint64)));
connect(d->reply, SIGNAL(downloadProgress(qsizetype, qsizetype)),
this, SLOT(onDownloadProgress(qsizetype, qsizetype)));
connect(d->reply, SIGNAL(redirected(QUrl)), this, SLOT(onRedirected(QUrl)));
connect(d->reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(onError(QNetworkReply::NetworkError)));
Expand Down Expand Up @@ -181,7 +181,7 @@ void DownloadItem::onMetaDataChanged()
}
}

void DownloadItem::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void DownloadItem::onDownloadProgress(qsizetype bytesReceived, qsizetype bytesTotal)
{
if (d->reply && bytesReceived > 0 && bytesTotal > 0) {
logInfo(QString("Downloaded '%0' (%1 of %2 bytes).")
Expand Down
2 changes: 1 addition & 1 deletion src/core/downloaditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DownloadItem : public AbstractDownloadItem

private slots:
void onMetaDataChanged();
void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void onDownloadProgress(qsizetype bytesReceived, qsizetype bytesTotal);
void onRedirected(const QUrl &url);
void onFinished();
void onError(QNetworkReply::NetworkError error);
Expand Down
4 changes: 2 additions & 2 deletions src/core/downloadstreamitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void DownloadStreamItem::resume()
m_stream->setConfig(resource()->streamConfig());

connect(m_stream, SIGNAL(downloadMetadataChanged()), this, SLOT(onMetaDataChanged()));
connect(m_stream, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
connect(m_stream, SIGNAL(downloadProgress(qsizetype, qsizetype)), this, SLOT(onDownloadProgress(qsizetype, qsizetype)));
connect(m_stream, SIGNAL(downloadError(QString)), this, SLOT(onError(QString)));
connect(m_stream, SIGNAL(downloadFinished()), this, SLOT(onFinished()));

Expand Down Expand Up @@ -110,7 +110,7 @@ void DownloadStreamItem::onMetaDataChanged()
}
}

void DownloadStreamItem::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void DownloadStreamItem::onDownloadProgress(qsizetype bytesReceived, qsizetype bytesTotal)
{
if (bytesReceived > 0 && bytesTotal > 0) {
logInfo(QString("Downloaded '%0' (%1 of %2 bytes).")
Expand Down
2 changes: 1 addition & 1 deletion src/core/downloadstreamitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DownloadStreamItem : public DownloadItem

private slots:
void onMetaDataChanged();
void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void onDownloadProgress(qsizetype bytesReceived, qsizetype bytesTotal);
void onFinished();
void onError(const QString &errorMessage);

Expand Down
34 changes: 22 additions & 12 deletions src/core/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ QString Format::timeToString(qint64 seconds)
/*!
* \brief Returns a string formatting the given size, in bytes.
*/
QString Format::fileSizeToString(qint64 size)
QString Format::fileSizeToString(qsizetype size)
{
if (size < 0 || size >= INT64_MAX) {
if (size < 0 || size >= SIZE_MAX) {
return tr("Unknown");
}
if (size == 0) {
Expand All @@ -82,7 +82,7 @@ QString Format::fileSizeToString(qint64 size)
if (size < 1000) {
return tr("%0 bytes").arg(QString::number(size));
}
double correctSize = size / 1024.0; // KB
qreal correctSize = qreal(size) / 1024; // KB
if (correctSize < 1000) {
return tr("%0 KB").arg(QString::number(correctSize > 0 ? correctSize : 0, 'f', 0));
}
Expand All @@ -105,9 +105,9 @@ QString Format::fileSizeToString(qint64 size)
* fileSizeThousandSeparator(123456789); // returns "123,456,789"
* \endcode
*/
QString Format::fileSizeThousandSeparator(qint64 size)
QString Format::fileSizeThousandSeparator(qsizetype size)
{
auto number = QString::number(size);
QString number = QString::number(size);
int i = number.count();
while (i > 3) {
i -= 3;
Expand Down Expand Up @@ -143,30 +143,34 @@ QString Format::currentSpeedToString(qreal speed, bool showInfiniteSymbol)
return tr("%0 MB/s").arg(QString::number(speed, 'f', 1));
}
speed /= 1024; // GB
return tr("%0 GB/s").arg(QString::number(speed, 'f', 2));
if (speed < 1000) {
return tr("%0 GB/s").arg(QString::number(speed, 'f', 2));
}
speed /= 1024; // TB
return tr("%0 TB/s").arg(QString::number(speed, 'f', 2));
}


/******************************************************************************
******************************************************************************/
static bool parseDouble(const QString &str, double &p)
static bool parseDouble(const QString &str, qreal &p)
{
bool ok = false;
auto val = str.toDouble(&ok);
qreal val = str.toDouble(&ok);
if (ok) {
p = val;
}
return ok;
}

double Format::parsePercentDecimal(const QString &text)
qreal Format::parsePercentDecimal(const QString &text)
{
if (!text.contains('%')) {
return -1.0;
}
QString percentString = text;
percentString.remove('%');
double percent = 0;
qreal percent = 0;
if (!parseDouble(percentString, percent)) {
return -1.0;
}
Expand All @@ -175,7 +179,7 @@ double Format::parsePercentDecimal(const QString &text)

/******************************************************************************
******************************************************************************/
qint64 Format::parseBytes(const QString &text)
qsizetype Format::parseBytes(const QString &text)
{
QString textwithoutTilde = text;
textwithoutTilde.remove(QChar('~'));
Expand Down Expand Up @@ -206,6 +210,9 @@ qint64 Format::parseBytes(const QString &text)
} else if (unitString == QLatin1String("GB")) {
multiple = 1000000000;

} else if (unitString == QLatin1String("TB")) {
multiple = 1000000000000;

} else if (unitString == QLatin1String("KIB")) {
multiple = 1024; // 1 KiB = 2^10 bytes = 1024 bytes

Expand All @@ -215,6 +222,9 @@ qint64 Format::parseBytes(const QString &text)
} else if (unitString == QLatin1String("GIB")) {
multiple = 1073741824; // 1 GiB = 2^30 bytes = 1073741824 bytes

} else if (unitString == QLatin1String("TIB")) {
multiple = 1099511627776; // 1 TiB = 2^40 bytes = 1099511627776 bytes

} else {
return -1;
}
Expand All @@ -231,7 +241,7 @@ qint64 Format::parseBytes(const QString &text)
* => Issue when the filesize is greater than 1.999 GiB...
*/
// qint64 bytes = qCeil(decimal * multiple);
auto bytes = static_cast<qint64>(std::ceil(decimal * multiple));
qsizetype bytes = static_cast<qsizetype>(decimal * multiple);
return bytes;
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class Format : public QObject
static QString timeToString(qint64 seconds);

static QString currentSpeedToString(qreal speed, bool showInfiniteSymbol = false);
static QString fileSizeToString(qint64 size);
static QString fileSizeThousandSeparator(qint64 size);
static QString fileSizeToString(qsizetype size);
static QString fileSizeThousandSeparator(qsizetype size);

static QString yesOrNo(bool yes);

static double parsePercentDecimal(const QString &text);
static qint64 parseBytes(const QString &text);
static qreal parsePercentDecimal(const QString &text);
static qsizetype parseBytes(const QString &text);

static QString toHtmlMark(const QUrl &url, bool wrap = false);
static QString wrapText(const QString &text, int blockLength = 50);
Expand Down
6 changes: 3 additions & 3 deletions src/core/idownloaditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class IDownloadItem

virtual State state() const = 0;

virtual qint64 bytesReceived() const = 0; /*!< in bytes */
virtual qint64 bytesTotal() const = 0; /*!< in bytes */
virtual qsizetype bytesReceived() const = 0; /*!< in bytes */
virtual qsizetype bytesTotal() const = 0; /*!< in bytes */

virtual double speed() const = 0; /*!< Returns the speed in byte per second */
virtual qreal speed() const = 0; /*!< Returns the speed in byte per second */
virtual int progress() const = 0; /*!< Return a value between 0 and 100, or -1 if undefined */

virtual int maxConnectionSegments() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/core/resourceitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ void ResourceItem::setStreamFormatId(const QString &streamFormatId)

/******************************************************************************
******************************************************************************/
qint64 ResourceItem::streamFileSize() const
qsizetype ResourceItem::streamFileSize() const
{
return m_streamFileSize;
}

void ResourceItem::setStreamFileSize(qint64 streamFileSize)
void ResourceItem::setStreamFileSize(qsizetype streamFileSize)
{
m_streamFileSize = streamFileSize;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/resourceitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class ResourceItem
QString streamFormatId() const;
void setStreamFormatId(const QString &streamFormatId);

qint64 streamFileSize() const;
void setStreamFileSize(qint64 streamFileSize);
qsizetype streamFileSize() const;
void setStreamFileSize(qsizetype streamFileSize);

StreamObject::Config streamConfig() const;
void setStreamConfig(const StreamObject::Config &config);
Expand All @@ -102,7 +102,7 @@ class ResourceItem
/* Stream-specific properties */
QString m_streamFileName;
QString m_streamFormatId;
qint64 m_streamFileSize{0};
qsizetype m_streamFileSize{0};

StreamObject::Config m_streamConfig;

Expand Down
12 changes: 6 additions & 6 deletions src/core/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static inline DownloadItem* readJob(const QJsonObject &json, DownloadManager *do

resourceItem->setStreamFileName(json["streamFileName"].toString());
resourceItem->setStreamFormatId(json["streamFormatId"].toString());
resourceItem->setStreamFileSize(json["streamFileSize"].toInt());
resourceItem->setStreamFileSize(static_cast<qsizetype>(json["streamFileSize"].toInteger()));

auto config = readStreamConfig(json["streamConfig"].toObject());
resourceItem->setStreamConfig(config);
Expand All @@ -189,8 +189,8 @@ static inline DownloadItem* readJob(const QJsonObject &json, DownloadManager *do
item->setResource(resourceItem);

item->setState(intToState(json["state"].toInt()));
item->setBytesReceived(json["bytesReceived"].toInt());
item->setBytesTotal(json["bytesTotal"].toInt());
item->setBytesReceived(static_cast<qsizetype>(json["bytesReceived"].toInteger()));
item->setBytesTotal(static_cast<qsizetype>(json["bytesTotal"].toInteger()));
item->setMaxConnectionSegments(json["maxConnectionSegments"].toInt());
item->setMaxConnections(json["maxConnections"].toInt());
item->setLog(json["log"].toString());
Expand All @@ -211,16 +211,16 @@ static inline void writeJob(const DownloadItem *item, QJsonObject &json)

json["streamFileName"] = item->resource()->streamFileName();
json["streamFormatId"] = item->resource()->streamFormatId();
json["streamFileSize"] = item->resource()->streamFileSize();
json["streamFileSize"] = static_cast<qsizetype>(item->resource()->streamFileSize());

auto config = item->resource()->streamConfig();
json["streamConfig"] = writeStreamConfig(config);

json["torrentPreferredFilePriorities"] = item->resource()->torrentPreferredFilePriorities();

json["state"] = stateToInt(item->state());
json["bytesReceived"] = item->bytesReceived();
json["bytesTotal"] = item->bytesTotal();
json["bytesReceived"] = static_cast<qsizetype>(item->bytesReceived());
json["bytesTotal"] = static_cast<qsizetype>(item->bytesTotal());
json["maxConnectionSegments"] = item->maxConnectionSegments();
json["maxConnections"] = item->maxConnections();
json["log"] = item->log();
Expand Down
Loading

0 comments on commit cf88e9b

Please sign in to comment.