Skip to content

Instantly share code, notes, and snippets.

@sledgehammer999
Created November 9, 2014 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sledgehammer999/845520068b8884e87122 to your computer and use it in GitHub Desktop.
Save sledgehammer999/845520068b8884e87122 to your computer and use it in GitHub Desktop.
diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp
index 0b77451..ad54ab4 100644
--- a/src/webui/btjson.cpp
+++ b/src/webui/btjson.cpp
@@ -29,7 +29,6 @@
*/
#include "btjson.h"
-#include "misc.h"
#include "fs_utils.h"
#include "qbtsession.h"
#include "torrentpersistentdata.h"
@@ -140,20 +139,20 @@ static QVariantMap toMap(const QTorrentHandle& h)
QVariantMap ret;
ret[KEY_TORRENT_HASH] = h.hash();
ret[KEY_TORRENT_NAME] = h.name();
- ret[KEY_TORRENT_SIZE] = static_cast<qlonglong>(status.total_wanted);
- ret[KEY_TORRENT_PROGRESS] = static_cast<double>(h.progress(status));
- ret[KEY_TORRENT_DLSPEED] = static_cast<int>(status.download_payload_rate);
- ret[KEY_TORRENT_UPSPEED] = static_cast<int>(status.upload_payload_rate);
+ ret[KEY_TORRENT_SIZE] = status.total_wanted;
+ ret[KEY_TORRENT_PROGRESS] = (double)(h.progress(status));
+ ret[KEY_TORRENT_DLSPEED] = status.download_payload_rate;
+ ret[KEY_TORRENT_UPSPEED] = status.upload_payload_rate;
if (QBtSession::instance()->isQueueingEnabled() && h.queue_position(status) >= 0)
- ret[KEY_TORRENT_PRIORITY] = static_cast<int>(h.queue_position(status));
+ ret[KEY_TORRENT_PRIORITY] = h.queue_position(status);
else
ret[KEY_TORRENT_PRIORITY] = -1;
- ret[KEY_TORRENT_SEEDS] = static_cast<int>(status.num_seeds);
- ret[KEY_TORRENT_NUM_COMPLETE] = static_cast<int>(status.num_complete);
- ret[KEY_TORRENT_LEECHS] = static_cast<int>(status.num_peers - status.num_seeds);
- ret[KEY_TORRENT_NUM_INCOMPLETE] = static_cast<int>(status.num_incomplete);
+ ret[KEY_TORRENT_SEEDS] = status.num_seeds;
+ ret[KEY_TORRENT_NUM_COMPLETE] = status.num_complete;
+ ret[KEY_TORRENT_LEECHS] = status.num_peers - status.num_seeds;
+ ret[KEY_TORRENT_NUM_INCOMPLETE] = status.num_incomplete;
const qreal ratio = QBtSession::instance()->getRealRatio(status);
- ret[KEY_TORRENT_RATIO] = (ratio > 100.) ? -1 : static_cast<qreal>(ratio);
+ ret[KEY_TORRENT_RATIO] = (ratio > 100.) ? -1 : ratio;
qulonglong eta = 0;
QString state;
if (h.is_paused(status)) {
@@ -179,7 +178,7 @@ static QVariantMap toMap(const QTorrentHandle& h)
case torrent_status::downloading:
case torrent_status::downloading_metadata:
state = status.download_payload_rate > 0 ? "downloading" : "stalledDL";
- eta = static_cast<qlonglong>(QBtSession::instance()->getETA(h.hash(), status));
+ eta = QBtSession::instance()->getETA(h.hash(), status);
break;
default:
qWarning("Unrecognized torrent status, should not happen!!! status was %d", h.state());
@@ -302,20 +301,20 @@ QByteArray btjson::getPropertiesForTorrent(const QString& hash)
if (save_path.isEmpty())
save_path = fsutils::toNativePath(h.save_path());
data[KEY_PROP_SAVE_PATH] = save_path;
- data[KEY_PROP_CREATION_DATE] = static_cast<int>(h.creation_date_unix());
- data[KEY_PROP_PIECE_SIZE] = static_cast<int>(h.piece_length());
+ data[KEY_PROP_CREATION_DATE] = h.creation_date_unix();
+ data[KEY_PROP_PIECE_SIZE] = h.piece_length();
data[KEY_PROP_COMMENT] = h.comment();
- data[KEY_PROP_WASTED] = static_cast<qlonglong>(status.total_failed_bytes + status.total_redundant_bytes);
- data[KEY_PROP_UPLOADED] = static_cast<qlonglong>(status.all_time_upload);
- data[KEY_PROP_UPLOADED_SESSION] = static_cast<qlonglong>(status.total_payload_upload);
- data[KEY_PROP_DOWNLOADED] = static_cast<qlonglong>(status.all_time_download);
- data[KEY_PROP_DOWNLOADED_SESSION] = static_cast<qlonglong>(status.total_payload_download);
- data[KEY_PROP_UP_LIMIT] = h.upload_limit() <= 0 ? -1 : static_cast<int>(h.upload_limit());
- data[KEY_PROP_DL_LIMIT] = h.download_limit() <= 0 ? -1 : static_cast<int>(h.download_limit());
- data[KEY_PROP_TIME_ELAPSED] = static_cast<int>(status.active_time);
- data[KEY_PROP_SEEDING_TIME] = static_cast<int>(status.seeding_time);
- data[KEY_PROP_CONNECT_COUNT] = static_cast<int>(status.num_connections);
- data[KEY_PROP_CONNECT_COUNT_LIMIT] = static_cast<int>(status.connections_limit);
+ data[KEY_PROP_WASTED] = status.total_failed_bytes + status.total_redundant_bytes;
+ data[KEY_PROP_UPLOADED] = status.all_time_upload;
+ data[KEY_PROP_UPLOADED_SESSION] = status.total_payload_upload;
+ data[KEY_PROP_DOWNLOADED] = status.all_time_download;
+ data[KEY_PROP_DOWNLOADED_SESSION] = status.total_payload_download;
+ data[KEY_PROP_UP_LIMIT] = h.upload_limit() <= 0 ? -1 : h.upload_limit();
+ data[KEY_PROP_DL_LIMIT] = h.download_limit() <= 0 ? -1 : h.download_limit();
+ data[KEY_PROP_TIME_ELAPSED] = status.active_time;
+ data[KEY_PROP_SEEDING_TIME] = status.seeding_time;
+ data[KEY_PROP_CONNECT_COUNT] = status.num_connections;
+ data[KEY_PROP_CONNECT_COUNT_LIMIT] = status.connections_limit;
const qreal ratio = QBtSession::instance()->getRealRatio(status);
data[KEY_PROP_RATIO] = ratio > 100. ? -1 : ratio;
} catch(const std::exception& e) {
@@ -355,7 +354,7 @@ QByteArray btjson::getFilesForTorrent(const QString& hash)
fileName.chop(4);
file_dict[KEY_FILE_NAME] = fsutils::toNativePath(fileName);
const size_type size = h.filesize_at(i);
- file_dict[KEY_FILE_SIZE] = static_cast<qlonglong>(size);
+ file_dict[KEY_FILE_SIZE] = size;
file_dict[KEY_FILE_PROGRESS] = (size > 0) ? (fp[i] / (double) size) : 1.;
file_dict[KEY_FILE_PRIORITY] = priorities[i];
if (i == 0)
@@ -383,9 +382,9 @@ QByteArray btjson::getTransferInfo()
{
CACHED_VARIABLE(QVariantMap, info, CACHE_DURATION_MS);
session_status sessionStatus = QBtSession::instance()->getSessionStatus();
- info[KEY_TRANSFER_DLSPEED] = static_cast<int>(sessionStatus.payload_download_rate);
- info[KEY_TRANSFER_DLDATA] = static_cast<qlonglong>(sessionStatus.total_payload_download);
- info[KEY_TRANSFER_UPSPEED] = static_cast<int>(sessionStatus.payload_upload_rate);
- info[KEY_TRANSFER_UPDATA] = static_cast<qlonglong>(sessionStatus.total_payload_upload);
+ info[KEY_TRANSFER_DLSPEED] = sessionStatus.payload_download_rate;
+ info[KEY_TRANSFER_DLDATA] = sessionStatus.total_payload_download;
+ info[KEY_TRANSFER_UPSPEED] = sessionStatus.payload_upload_rate;
+ info[KEY_TRANSFER_UPDATA] = sessionStatus.total_payload_upload;
return json::toJson(info);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment