diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 9f3f4a4d4..63b15375e 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -131,64 +131,6 @@ AddTorrentData::AddTorrentData(const AddTorrentParams ¶ms) savePath = Session::instance()->defaultSavePath(); } -// TorrentState - -TorrentState::TorrentState(int value) - : m_value(value) -{ -} - -QString TorrentState::toString() const -{ - switch (m_value) { - case Error: - return QLatin1String("error"); - case MissingFiles: - return QLatin1String("missingFiles"); - case Uploading: - return QLatin1String("uploading"); - case PausedUploading: - return QLatin1String("pausedUP"); - case QueuedUploading: - return QLatin1String("queuedUP"); - case StalledUploading: - return QLatin1String("stalledUP"); - case CheckingUploading: - return QLatin1String("checkingUP"); - case ForcedUploading: - return QLatin1String("forcedUP"); - case Allocating: - return QLatin1String("allocating"); - case Downloading: - return QLatin1String("downloading"); - case DownloadingMetadata: - return QLatin1String("metaDL"); - case PausedDownloading: - return QLatin1String("pausedDL"); - case QueuedDownloading: - return QLatin1String("queuedDL"); - case StalledDownloading: - return QLatin1String("stalledDL"); - case CheckingDownloading: - return QLatin1String("checkingDL"); - case ForcedDownloading: - return QLatin1String("forcedDL"); -#if LIBTORRENT_VERSION_NUM < 10100 - case QueuedForChecking: - return QLatin1String("queuedForChecking"); -#endif - case CheckingResumeData: - return QLatin1String("checkingResumeData"); - default: - return QLatin1String("unknown"); - } -} - -TorrentState::operator int() const -{ - return m_value; -} - // TorrentHandle const qreal TorrentHandle::USE_GLOBAL_RATIO = -2.; diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 167fec71d..1199f863c 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -120,48 +120,35 @@ namespace BitTorrent quint32 numPeers = 0; }; - class TorrentState + enum class TorrentState { - public: - enum - { - Unknown = -1, - - ForcedDownloading, - Downloading, - DownloadingMetadata, - Allocating, - StalledDownloading, - - ForcedUploading, - Uploading, - StalledUploading, + Unknown = -1, - QueuedDownloading, - QueuedUploading, + ForcedDownloading, + Downloading, + DownloadingMetadata, + Allocating, + StalledDownloading, - CheckingUploading, - CheckingDownloading, + ForcedUploading, + Uploading, + StalledUploading, #if LIBTORRENT_VERSION_NUM < 10100 - QueuedForChecking, + QueuedForChecking, #endif - CheckingResumeData, + CheckingResumeData, + QueuedDownloading, + QueuedUploading, - PausedDownloading, - PausedUploading, + CheckingUploading, + CheckingDownloading, - MissingFiles, - Error - }; + PausedDownloading, + PausedUploading, - TorrentState(int value); - - operator int() const; - QString toString() const; - - private: - int m_value; + MissingFiles, + Error }; class TorrentHandle : public QObject @@ -474,4 +461,6 @@ namespace BitTorrent }; } +Q_DECLARE_METATYPE(BitTorrent::TorrentState) + #endif // BITTORRENT_TORRENTHANDLE_H diff --git a/src/base/torrentfilter.h b/src/base/torrentfilter.h index 55b848e14..335ec1868 100644 --- a/src/base/torrentfilter.h +++ b/src/base/torrentfilter.h @@ -37,7 +37,6 @@ typedef QSet QStringSet; namespace BitTorrent { class TorrentHandle; - class TorrentState; } class TorrentFilter diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 36382b329..3b917acd7 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -58,7 +58,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem bool isHideState = true; if (Preferences::instance()->getHideZeroComboValues() == 1) { // paused torrents only QModelIndex stateIndex = index.sibling(index.row(), TorrentModel::TR_STATUS); - if (stateIndex.data().toInt() != BitTorrent::TorrentState::PausedDownloading) + if (stateIndex.data().value() != BitTorrent::TorrentState::PausedDownloading) isHideState = false; } const bool hideValues = Preferences::instance()->getHideZeroValues() & isHideState; @@ -98,7 +98,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem break; } case TorrentModel::TR_STATUS: { - const int state = index.data().toInt(); + const auto state = index.data().value(); QString display = getStatusString(state); QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; @@ -223,7 +223,7 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const return size; } -QString TransferListDelegate::getStatusString(const int state) const +QString TransferListDelegate::getStatusString(const BitTorrent::TorrentState state) const { QString str; diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index 577dd1b32..d67c49af0 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -39,6 +39,10 @@ class QStyleOptionViewItem; class QModelIndex; QT_END_NAMESPACE +namespace BitTorrent +{ + enum class TorrentState; +} // Defines for download list list columns class TransferListDelegate: public QItemDelegate @@ -52,7 +56,7 @@ public: QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; private: - QString getStatusString(const int state) const; + QString getStatusString(const BitTorrent::TorrentState state) const; }; #endif // TRANSFERLISTDELEGATE_H diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index dc9028b76..56a09d3f3 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include "base/bittorrent/cachestatus.h" #include "base/bittorrent/session.h" #include "base/bittorrent/sessionstatus.h" @@ -227,6 +229,52 @@ static const char KEY_LOG_PEER_REASON[] = "reason"; namespace { + QString torrentStateToString(const BitTorrent::TorrentState state) + { + switch (state) { + case BitTorrent::TorrentState::Error: + return QLatin1String("error"); + case BitTorrent::TorrentState::MissingFiles: + return QLatin1String("missingFiles"); + case BitTorrent::TorrentState::Uploading: + return QLatin1String("uploading"); + case BitTorrent::TorrentState::PausedUploading: + return QLatin1String("pausedUP"); + case BitTorrent::TorrentState::QueuedUploading: + return QLatin1String("queuedUP"); + case BitTorrent::TorrentState::StalledUploading: + return QLatin1String("stalledUP"); + case BitTorrent::TorrentState::CheckingUploading: + return QLatin1String("checkingUP"); + case BitTorrent::TorrentState::ForcedUploading: + return QLatin1String("forcedUP"); + case BitTorrent::TorrentState::Allocating: + return QLatin1String("allocating"); + case BitTorrent::TorrentState::Downloading: + return QLatin1String("downloading"); + case BitTorrent::TorrentState::DownloadingMetadata: + return QLatin1String("metaDL"); + case BitTorrent::TorrentState::PausedDownloading: + return QLatin1String("pausedDL"); + case BitTorrent::TorrentState::QueuedDownloading: + return QLatin1String("queuedDL"); + case BitTorrent::TorrentState::StalledDownloading: + return QLatin1String("stalledDL"); + case BitTorrent::TorrentState::CheckingDownloading: + return QLatin1String("checkingDL"); + case BitTorrent::TorrentState::ForcedDownloading: + return QLatin1String("forcedDL"); +#if LIBTORRENT_VERSION_NUM < 10100 + case BitTorrent::TorrentState::QueuedForChecking: + return QLatin1String("queuedForChecking"); +#endif + case BitTorrent::TorrentState::CheckingResumeData: + return QLatin1String("checkingResumeData"); + default: + return QLatin1String("unknown"); + } + } + class QTorrentCompare { public: @@ -315,7 +363,7 @@ namespace ret[KEY_TORRENT_NUM_INCOMPLETE] = torrent->totalLeechersCount(); const qreal ratio = torrent->realRatio(); ret[KEY_TORRENT_RATIO] = (ratio > BitTorrent::TorrentHandle::MAX_RATIO) ? -1 : ratio; - ret[KEY_TORRENT_STATE] = torrent->state().toString(); + ret[KEY_TORRENT_STATE] = torrentStateToString(torrent->state()); ret[KEY_TORRENT_ETA] = torrent->eta(); ret[KEY_TORRENT_SEQUENTIAL_DOWNLOAD] = torrent->isSequentialDownload(); if (torrent->hasMetadata())