From a71d7e65570740cb93ddbf76f11a448b9b2b8a5f Mon Sep 17 00:00:00 2001 From: tristanleboss Date: Sat, 8 Oct 2022 05:43:52 +0200 Subject: [PATCH] Add infohash and download path columns PR #17799. --- src/base/bittorrent/infohash.h | 3 +++ src/gui/transferlistmodel.cpp | 19 +++++++++++++++++++ src/gui/transferlistmodel.h | 3 +++ src/gui/transferlistsortmodel.cpp | 7 +++++++ src/gui/transferlistwidget.cpp | 3 +++ 5 files changed, 35 insertions(+) diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index ffaff0c25..0c69e37d4 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -40,6 +40,9 @@ using SHA1Hash = Digest32<160>; using SHA256Hash = Digest32<256>; +Q_DECLARE_METATYPE(SHA1Hash) +Q_DECLARE_METATYPE(SHA256Hash) + namespace BitTorrent { class InfoHash; diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index c4b842fc3..96ef1c44a 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -34,6 +34,7 @@ #include #include +#include "base/bittorrent/infohash.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrent.h" #include "base/global.h" @@ -224,12 +225,15 @@ QVariant TransferListModel::headerData(const int section, const Qt::Orientation case TR_AMOUNT_LEFT: return tr("Remaining", "Amount of data left to download (e.g. in MB)"); case TR_TIME_ELAPSED: return tr("Time Active", "Time (duration) the torrent is active (not paused)"); case TR_SAVE_PATH: return tr("Save path", "Torrent save path"); + case TR_DOWNLOAD_PATH: return tr("Incomplete Save Path", "Torrent incomplete save path"); case TR_COMPLETED: return tr("Completed", "Amount of data completed (e.g. in MB)"); case TR_RATIO_LIMIT: return tr("Ratio Limit", "Upload share ratio limit"); case TR_SEEN_COMPLETE_DATE: return tr("Last Seen Complete", "Indicates the time when the torrent was last seen complete/whole"); case TR_LAST_ACTIVITY: return tr("Last Activity", "Time passed since a chunk was downloaded/uploaded"); case TR_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data"); case TR_AVAILABILITY: return tr("Availability", "The number of distributed copies of the torrent"); + case TR_INFOHASH_V1: return tr("Info Hash v1", "i.e: torrent info hash v1"); + case TR_INFOHASH_V2: return tr("Info Hash v2", "i.e: torrent info hash v2"); default: return {}; } } @@ -424,6 +428,8 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons return timeElapsedString(torrent->activeTime(), torrent->finishedTime()); case TR_SAVE_PATH: return torrent->savePath().toString(); + case TR_DOWNLOAD_PATH: + return torrent->downloadPath().toString(); case TR_COMPLETED: return unitString(torrent->completedSize()); case TR_SEEN_COMPLETE_DATE: @@ -434,6 +440,10 @@ QString TransferListModel::displayValue(const BitTorrent::Torrent *torrent, cons return availabilityString(torrent->distributedCopies()); case TR_TOTAL_SIZE: return unitString(torrent->totalSize()); + case TR_INFOHASH_V1: + return torrent->infoHash().v1().toString(); + case TR_INFOHASH_V2: + return torrent->infoHash().v2().toString(); } return {}; @@ -491,6 +501,8 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co return torrent->remainingSize(); case TR_TIME_ELAPSED: return !alt ? torrent->activeTime() : torrent->finishedTime(); + case TR_DOWNLOAD_PATH: + return torrent->downloadPath().data(); case TR_SAVE_PATH: return torrent->savePath().toString(); case TR_COMPLETED: @@ -505,6 +517,10 @@ QVariant TransferListModel::internalValue(const BitTorrent::Torrent *torrent, co return torrent->distributedCopies(); case TR_TOTAL_SIZE: return torrent->totalSize(); + case TR_INFOHASH_V1: + return QVariant::fromValue(torrent->infoHash().v1()); + case TR_INFOHASH_V2: + return QVariant::fromValue(torrent->infoHash().v2()); } return {}; @@ -540,6 +556,9 @@ QVariant TransferListModel::data(const QModelIndex &index, const int role) const case TR_TAGS: case TR_TRACKER: case TR_SAVE_PATH: + case TR_DOWNLOAD_PATH: + case TR_INFOHASH_V1: + case TR_INFOHASH_V2: return displayValue(torrent, index.column()); } break; diff --git a/src/gui/transferlistmodel.h b/src/gui/transferlistmodel.h index dbe8e32e8..d177e2001 100644 --- a/src/gui/transferlistmodel.h +++ b/src/gui/transferlistmodel.h @@ -81,6 +81,9 @@ public: TR_SEEN_COMPLETE_DATE, TR_LAST_ACTIVITY, TR_AVAILABILITY, + TR_DOWNLOAD_PATH, + TR_INFOHASH_V1, + TR_INFOHASH_V2, NB_COLUMNS }; diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index b33912de1..bbc6856a9 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -163,11 +163,18 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r switch (compareColumn) { case TransferListModel::TR_CATEGORY: + case TransferListModel::TR_DOWNLOAD_PATH: case TransferListModel::TR_NAME: case TransferListModel::TR_SAVE_PATH: case TransferListModel::TR_TRACKER: return m_naturalCompare(leftValue.toString(), rightValue.toString()); + case TransferListModel::TR_INFOHASH_V1: + return threeWayCompare(leftValue.value(), rightValue.value()); + + case TransferListModel::TR_INFOHASH_V2: + return threeWayCompare(leftValue.value(), rightValue.value()); + case TransferListModel::TR_TAGS: return customCompare(leftValue.value(), rightValue.value(), m_naturalCompare); diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 21e2b05d0..93e8906b7 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -171,6 +171,9 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) setColumnHidden(TransferListModel::TR_AMOUNT_LEFT, true); setColumnHidden(TransferListModel::TR_TIME_ELAPSED, true); setColumnHidden(TransferListModel::TR_SAVE_PATH, true); + setColumnHidden(TransferListModel::TR_DOWNLOAD_PATH, true); + setColumnHidden(TransferListModel::TR_INFOHASH_V1, true); + setColumnHidden(TransferListModel::TR_INFOHASH_V2, true); setColumnHidden(TransferListModel::TR_COMPLETED, true); setColumnHidden(TransferListModel::TR_RATIO_LIMIT, true); setColumnHidden(TransferListModel::TR_SEEN_COMPLETE_DATE, true);