32 #include <QApplication>
67 struct TorrentStateColorDescriptor
73 const TorrentStateColorDescriptor colorDescriptors[] =
95 QHash<BitTorrent::TorrentState, QColor> colors;
96 for (
const TorrentStateColorDescriptor &colorDescriptor : colorDescriptors)
99 if (themeColor.isValid())
100 colors.insert(colorDescriptor.state, themeColor);
109 : QAbstractListModel {parent}
124 {
BitTorrent::TorrentState::CheckingResumeData, tr(
"Checking resume data",
"Used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents.")},
165 if (orientation == Qt::Horizontal)
167 if (role == Qt::DisplayRole)
172 case TR_NAME:
return tr(
"Name",
"i.e: torrent name");
173 case TR_SIZE:
return tr(
"Size",
"i.e: torrent size");
175 case TR_STATUS:
return tr(
"Status",
"Torrent status (e.g. downloading, seeding, paused)");
176 case TR_SEEDS:
return tr(
"Seeds",
"i.e. full sources (often untranslated)");
177 case TR_PEERS:
return tr(
"Peers",
"i.e. partial sources (often untranslated)");
178 case TR_DLSPEED:
return tr(
"Down Speed",
"i.e: Download speed");
179 case TR_UPSPEED:
return tr(
"Up Speed",
"i.e: Upload speed");
180 case TR_RATIO:
return tr(
"Ratio",
"Share ratio");
181 case TR_ETA:
return tr(
"ETA",
"i.e: Estimated Time of Arrival / Time left");
183 case TR_TAGS:
return tr(
"Tags");
184 case TR_ADD_DATE:
return tr(
"Added On",
"Torrent was added to transfer list on 01/01/2010 08:00");
185 case TR_SEED_DATE:
return tr(
"Completed On",
"Torrent was completed on 01/01/2010 08:00");
187 case TR_DLLIMIT:
return tr(
"Down Limit",
"i.e: Download limit");
188 case TR_UPLIMIT:
return tr(
"Up Limit",
"i.e: Upload limit");
190 case TR_AMOUNT_UPLOADED:
return tr(
"Uploaded",
"Amount of data uploaded (e.g. in MB)");
193 case TR_AMOUNT_LEFT:
return tr(
"Remaining",
"Amount of data left to download (e.g. in MB)");
194 case TR_TIME_ELAPSED:
return tr(
"Time Active",
"Time (duration) the torrent is active (not paused)");
195 case TR_SAVE_PATH:
return tr(
"Save path",
"Torrent save path");
196 case TR_COMPLETED:
return tr(
"Completed",
"Amount of data completed (e.g. in MB)");
197 case TR_RATIO_LIMIT:
return tr(
"Ratio Limit",
"Upload share ratio limit");
198 case TR_SEEN_COMPLETE_DATE:
return tr(
"Last Seen Complete",
"Indicates the time when the torrent was last seen complete/whole");
199 case TR_LAST_ACTIVITY:
return tr(
"Last Activity",
"Time passed since a chunk was downloaded/uploaded");
200 case TR_TOTAL_SIZE:
return tr(
"Total Size",
"i.e. Size including unwanted data");
201 case TR_AVAILABILITY:
return tr(
"Availability",
"The number of distributed copies of the torrent");
205 else if (role == Qt::TextAlignmentRole)
229 return QVariant(Qt::AlignRight | Qt::AlignVCenter);
231 return QAbstractListModel::headerData(section, orientation, role);
241 bool hideValues =
false;
247 const auto availabilityString = [hideValues](
const qreal
value) -> QString
249 if (hideValues && (
value == 0))
256 const auto unitString = [hideValues](
const qint64
value,
const bool isSpeedUnit =
false) -> QString
258 return (hideValues && (
value == 0))
262 const auto limitString = [hideValues](
const qint64
value) -> QString
264 if (hideValues && (
value <= 0))
272 const auto amountString = [hideValues](
const qint64
value,
const qint64 total) -> QString
274 if (hideValues && (
value == 0) && (total == 0))
276 return QString::fromLatin1(
"%1 (%2)").arg(QString::number(
value), QString::number(total));
279 const auto etaString = [hideValues](
const qlonglong
value) -> QString
286 const auto ratioString = [hideValues](
const qreal
value) -> QString
288 if (hideValues && (
value <= 0))
295 const auto queuePositionString = [](
const qint64
value) -> QString
297 return (
value >= 0) ? QString::number(
value + 1) : QLatin1String(
"*");
300 const auto lastActivityString = [hideValues](qint64
value) -> QString
314 const auto timeElapsedString = [hideValues](
const qint64 elapsedTime,
const qint64 seedingTime) -> QString
316 if (seedingTime <= 0)
318 if (hideValues && (elapsedTime == 0))
323 return tr(
"%1 (seeded for %2)",
"e.g. 4m39s (seeded for 3m10s)")
328 const auto progressString = [](
const qreal progress) -> QString
330 return (progress >= 1)
331 ? QString::fromLatin1(
"100%")
345 return torrent->
name();
351 return progressString(torrent->
progress());
353 return statusString(torrent->
state(), torrent->
error());
363 return etaString(torrent->
eta());
365 return ratioString(torrent->
realRatio());
367 return ratioString(torrent->
maxRatio());
371 return torrent->
tags().
join(QLatin1String(
", "));
373 return QLocale().toString(torrent->
addedTime().toLocalTime(), QLocale::ShortFormat);
375 return QLocale().toString(torrent->
completedTime().toLocalTime(), QLocale::ShortFormat);
399 return QLocale().toString(torrent->
lastSeenComplete().toLocalTime(), QLocale::ShortFormat);
416 return torrent->
name();
424 return QVariant::fromValue(torrent->
state());
434 return torrent->
eta();
440 return QVariant::fromValue(torrent->
tags());
484 if (!index.isValid())
return {};
487 if (!torrent)
return {};
491 case Qt::ForegroundRole:
493 case Qt::DisplayRole:
499 case Qt::DecorationRole:
503 case Qt::ToolTipRole:
504 switch (index.column())
515 case Qt::TextAlignmentRole:
516 switch (index.column())
538 return QVariant {Qt::AlignRight | Qt::AlignVCenter};
547 if (!index.isValid() || (role != Qt::DisplayRole))
return false;
550 if (!torrent)
return false;
553 switch (index.column())
574 beginInsertRows({}, row, row);
582 if (!index.isValid())
return Qt::NoItemFlags;
585 return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
590 if (!index.isValid())
return nullptr;
600 beginRemoveRows({}, row, row);
616 emit dataChanged(index(row, 0), index(row,
columnCount() - 1));
630 emit dataChanged(index(row, 0), index(row, columns));
636 emit dataChanged(index(0, 0), index((
rowCount() - 1), columns));
712 return {34, 139, 34};
714 return {50, 205, 50};
720 return {204, 204, 204};
724 return {65, 105, 225};
726 return {99, 184, 255};
728 return {250, 128, 114};
733 return {79, 148, 205};
744 return {0, 128, 128};
746 return {0, 205, 205};
811 const QPalette pal = QApplication::palette();
813 const QColor &color = pal.color(QPalette::Active, QPalette::Base);
814 return (color.lightness() < 127);
void torrentPaused(Torrent *torrent)
static Session * instance()
void torrentAboutToBeRemoved(Torrent *torrent)
void torrentFinishedChecking(Torrent *torrent)
void torrentFinished(Torrent *torrent)
void torrentResumed(Torrent *torrent)
void torrentsUpdated(const QVector< Torrent * > &torrents)
void torrentLoaded(Torrent *torrent)
void torrentMetadataReceived(Torrent *torrent)
virtual qlonglong totalSize() const =0
virtual qreal distributedCopies() const =0
virtual int uploadPayloadRate() const =0
virtual int seedsCount() const =0
virtual int downloadLimit() const =0
virtual TagSet tags() const =0
virtual qlonglong totalUpload() const =0
virtual QString currentTracker() const =0
virtual QString category() const =0
virtual qlonglong activeTime() const =0
virtual qlonglong totalPayloadDownload() const =0
virtual QString error() const =0
virtual qlonglong finishedTime() const =0
virtual int uploadLimit() const =0
qlonglong remainingSize() const
virtual qlonglong completedSize() const =0
virtual int totalSeedsCount() const =0
virtual TorrentState state() const =0
virtual qlonglong totalDownload() const =0
virtual QString savePath() const =0
virtual qreal realRatio() const =0
virtual qreal maxRatio() const =0
virtual int queuePosition() const =0
virtual bool setCategory(const QString &category)=0
virtual QDateTime addedTime() const =0
virtual void setName(const QString &name)=0
virtual qlonglong totalPayloadUpload() const =0
virtual QDateTime completedTime() const =0
virtual QDateTime lastSeenComplete() const =0
virtual int leechsCount() const =0
virtual qreal progress() const =0
virtual qlonglong timeSinceActivity() const =0
virtual qlonglong eta() const =0
static const qreal MAX_RATIO
virtual qlonglong wantedSize() const =0
virtual int downloadPayloadRate() const =0
virtual int totalLeechersCount() const =0
virtual QString name() const =0
QString join(const QString &separator) const
static Preferences * instance()
int getHideZeroComboValues() const
bool getHideZeroValues() const
void handleTorrentStatusUpdated(BitTorrent::Torrent *const torrent)
@ AdditionalUnderlyingDataRole
@ TR_AMOUNT_DOWNLOADED_SESSION
@ TR_AMOUNT_UPLOADED_SESSION
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int rowCount(const QModelIndex &parent={}) const override
QHash< BitTorrent::Torrent *, int > m_torrentMap
const QHash< BitTorrent::TorrentState, QColor > m_stateThemeColors
HideZeroValuesMode m_hideZeroValuesMode
void addTorrent(BitTorrent::Torrent *const torrent)
QList< BitTorrent::Torrent * > m_torrentList
QString displayValue(const BitTorrent::Torrent *torrent, int column) const
const QHash< BitTorrent::TorrentState, QString > m_statusStrings
QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
void handleTorrentsUpdated(const QVector< BitTorrent::Torrent * > &torrents)
BitTorrent::Torrent * torrentHandle(const QModelIndex &index) const
TransferListModel(QObject *parent=nullptr)
int columnCount(const QModelIndex &parent={}) const override
void handleTorrentAboutToBeRemoved(BitTorrent::Torrent *const torrent)
static UIThemeManager * instance()
QColor getColor(const QString &id, const QColor &defaultColor) const
QIcon getIcon(const QString &iconId, const QString &fallback={}) const
constexpr std::add_const_t< T > & asConst(T &t) noexcept
@ ForcedDownloadingMetadata
QString toNativePath(const QString &path)
QString unitString(SizeUnit unit, bool isSpeed=false)
QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap=-1)
QString friendlyUnit(qint64 bytes, bool isSpeed=false)
QString fromDouble(double n, int precision)
T value(const QString &key, const T &defaultValue={})
QHash< BitTorrent::TorrentState, QColor > torrentStateColorsFromUITheme()
static QIcon getStalledDownloadingIcon()
static bool isDarkTheme()
static QIcon getCheckingIcon()
static QIcon getCompletedIcon()
static QIcon getIconByState(BitTorrent::TorrentState state)
static QColor getDefaultColorByState(BitTorrent::TorrentState state)
static QIcon getDownloadingIcon()
static QIcon getStalledUploadingIcon()
static QIcon getPausedIcon()
static QIcon getErrorIcon()
static QIcon getUploadingIcon()
static QIcon getQueuedIcon()