qBittorrent
TransferListModel Class Referencefinal

#include <transferlistmodel.h>

Inheritance diagram for TransferListModel:
Collaboration diagram for TransferListModel:

Public Types

enum  Column {
  TR_QUEUE_POSITION , TR_NAME , TR_SIZE , TR_TOTAL_SIZE ,
  TR_PROGRESS , TR_STATUS , TR_SEEDS , TR_PEERS ,
  TR_DLSPEED , TR_UPSPEED , TR_ETA , TR_RATIO ,
  TR_CATEGORY , TR_TAGS , TR_ADD_DATE , TR_SEED_DATE ,
  TR_TRACKER , TR_DLLIMIT , TR_UPLIMIT , TR_AMOUNT_DOWNLOADED ,
  TR_AMOUNT_UPLOADED , TR_AMOUNT_DOWNLOADED_SESSION , TR_AMOUNT_UPLOADED_SESSION , TR_AMOUNT_LEFT ,
  TR_TIME_ELAPSED , TR_SAVE_PATH , TR_COMPLETED , TR_RATIO_LIMIT ,
  TR_SEEN_COMPLETE_DATE , TR_LAST_ACTIVITY , TR_AVAILABILITY , NB_COLUMNS
}
 
enum  DataRole { UnderlyingDataRole = Qt::UserRole , AdditionalUnderlyingDataRole }
 

Public Member Functions

 TransferListModel (QObject *parent=nullptr)
 
int rowCount (const QModelIndex &parent={}) const override
 
int columnCount (const QModelIndex &parent={}) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
BitTorrent::TorrenttorrentHandle (const QModelIndex &index) const
 

Private Types

enum class  HideZeroValuesMode { Never , Paused , Always }
 

Private Slots

void addTorrent (BitTorrent::Torrent *const torrent)
 
void handleTorrentAboutToBeRemoved (BitTorrent::Torrent *const torrent)
 
void handleTorrentStatusUpdated (BitTorrent::Torrent *const torrent)
 
void handleTorrentsUpdated (const QVector< BitTorrent::Torrent * > &torrents)
 

Private Member Functions

void configure ()
 
QString displayValue (const BitTorrent::Torrent *torrent, int column) const
 
QVariant internalValue (const BitTorrent::Torrent *torrent, int column, bool alt) const
 

Private Attributes

QList< BitTorrent::Torrent * > m_torrentList
 
QHash< BitTorrent::Torrent *, int > m_torrentMap
 
const QHash< BitTorrent::TorrentState, QString > m_statusStrings
 
const QHash< BitTorrent::TorrentState, QColor > m_stateThemeColors
 
HideZeroValuesMode m_hideZeroValuesMode = HideZeroValuesMode::Never
 

Detailed Description

Definition at line 44 of file transferlistmodel.h.

Member Enumeration Documentation

◆ Column

Enumerator
TR_QUEUE_POSITION 
TR_NAME 
TR_SIZE 
TR_TOTAL_SIZE 
TR_PROGRESS 
TR_STATUS 
TR_SEEDS 
TR_PEERS 
TR_DLSPEED 
TR_UPSPEED 
TR_ETA 
TR_RATIO 
TR_CATEGORY 
TR_TAGS 
TR_ADD_DATE 
TR_SEED_DATE 
TR_TRACKER 
TR_DLLIMIT 
TR_UPLIMIT 
TR_AMOUNT_DOWNLOADED 
TR_AMOUNT_UPLOADED 
TR_AMOUNT_DOWNLOADED_SESSION 
TR_AMOUNT_UPLOADED_SESSION 
TR_AMOUNT_LEFT 
TR_TIME_ELAPSED 
TR_SAVE_PATH 
TR_COMPLETED 
TR_RATIO_LIMIT 
TR_SEEN_COMPLETE_DATE 
TR_LAST_ACTIVITY 
TR_AVAILABILITY 
NB_COLUMNS 

Definition at line 50 of file transferlistmodel.h.

51  {
53  TR_NAME,
54  TR_SIZE,
57  TR_STATUS,
58  TR_SEEDS,
59  TR_PEERS,
60  TR_DLSPEED,
61  TR_UPSPEED,
62  TR_ETA,
63  TR_RATIO,
65  TR_TAGS,
68  TR_TRACKER,
69  TR_DLLIMIT,
70  TR_UPLIMIT,
83 
85  };

◆ DataRole

Enumerator
UnderlyingDataRole 
AdditionalUnderlyingDataRole 

Definition at line 87 of file transferlistmodel.h.

88  {
89  UnderlyingDataRole = Qt::UserRole,
91  };

◆ HideZeroValuesMode

Enumerator
Never 
Paused 
Always 

Definition at line 121 of file transferlistmodel.h.

122  {
123  Never,
124  Paused,
125  Always
126  };

Constructor & Destructor Documentation

◆ TransferListModel()

TransferListModel::TransferListModel ( QObject *  parent = nullptr)
explicit

Definition at line 108 of file transferlistmodel.cpp.

109  : QAbstractListModel {parent}
111  {
112  {BitTorrent::TorrentState::Downloading, tr("Downloading")},
113  {BitTorrent::TorrentState::StalledDownloading, tr("Stalled", "Torrent is waiting for download to begin")},
114  {BitTorrent::TorrentState::DownloadingMetadata, tr("Downloading metadata", "Used when loading a magnet link")},
115  {BitTorrent::TorrentState::ForcedDownloadingMetadata, tr("[F] Downloading metadata", "Used when forced to load a magnet link. You probably shouldn't translate the F.")},
116  {BitTorrent::TorrentState::ForcedDownloading, tr("[F] Downloading", "Used when the torrent is forced started. You probably shouldn't translate the F.")},
117  {BitTorrent::TorrentState::Uploading, tr("Seeding", "Torrent is complete and in upload-only mode")},
118  {BitTorrent::TorrentState::StalledUploading, tr("Seeding", "Torrent is complete and in upload-only mode")},
119  {BitTorrent::TorrentState::ForcedUploading, tr("[F] Seeding", "Used when the torrent is forced started. You probably shouldn't translate the F.")},
120  {BitTorrent::TorrentState::QueuedDownloading, tr("Queued", "Torrent is queued")},
121  {BitTorrent::TorrentState::QueuedUploading, tr("Queued", "Torrent is queued")},
122  {BitTorrent::TorrentState::CheckingDownloading, tr("Checking", "Torrent local data is being checked")},
123  {BitTorrent::TorrentState::CheckingUploading, tr("Checking", "Torrent local data is being checked")},
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.")},
127  {BitTorrent::TorrentState::Moving, tr("Moving", "Torrent local data are being moved/relocated")},
128  {BitTorrent::TorrentState::MissingFiles, tr("Missing Files")},
129  {BitTorrent::TorrentState::Error, tr("Errored", "Torrent status, the torrent has an error")}
130  }
132 {
133  configure();
135 
136  // Load the torrents
137  using namespace BitTorrent;
138  for (Torrent *const torrent : asConst(Session::instance()->torrents()))
139  addTorrent(torrent);
140 
141  // Listen for torrent changes
142  connect(Session::instance(), &Session::torrentLoaded, this, &TransferListModel::addTorrent);
143  connect(Session::instance(), &Session::torrentAboutToBeRemoved, this, &TransferListModel::handleTorrentAboutToBeRemoved);
144  connect(Session::instance(), &Session::torrentsUpdated, this, &TransferListModel::handleTorrentsUpdated);
145 
146  connect(Session::instance(), &Session::torrentFinished, this, &TransferListModel::handleTorrentStatusUpdated);
147  connect(Session::instance(), &Session::torrentMetadataReceived, this, &TransferListModel::handleTorrentStatusUpdated);
148  connect(Session::instance(), &Session::torrentResumed, this, &TransferListModel::handleTorrentStatusUpdated);
149  connect(Session::instance(), &Session::torrentPaused, this, &TransferListModel::handleTorrentStatusUpdated);
150  connect(Session::instance(), &Session::torrentFinishedChecking, this, &TransferListModel::handleTorrentStatusUpdated);
151 }
static Preferences * instance()
void changed()
void handleTorrentStatusUpdated(BitTorrent::Torrent *const torrent)
const QHash< BitTorrent::TorrentState, QColor > m_stateThemeColors
void addTorrent(BitTorrent::Torrent *const torrent)
const QHash< BitTorrent::TorrentState, QString > m_statusStrings
void handleTorrentsUpdated(const QVector< BitTorrent::Torrent * > &torrents)
void handleTorrentAboutToBeRemoved(BitTorrent::Torrent *const torrent)
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42
QHash< BitTorrent::TorrentState, QColor > torrentStateColorsFromUITheme()

References BitTorrent::CheckingDownloading, BitTorrent::CheckingResumeData, BitTorrent::CheckingUploading, BitTorrent::Downloading, BitTorrent::DownloadingMetadata, BitTorrent::Error, BitTorrent::ForcedDownloading, BitTorrent::ForcedDownloadingMetadata, BitTorrent::ForcedUploading, BitTorrent::MissingFiles, BitTorrent::Moving, BitTorrent::PausedDownloading, BitTorrent::PausedUploading, BitTorrent::QueuedDownloading, BitTorrent::QueuedUploading, BitTorrent::StalledDownloading, BitTorrent::StalledUploading, and BitTorrent::Uploading.

Member Function Documentation

◆ addTorrent

void TransferListModel::addTorrent ( BitTorrent::Torrent *const  torrent)
privateslot

Definition at line 568 of file transferlistmodel.cpp.

569 {
570  Q_ASSERT(!m_torrentMap.contains(torrent));
571 
572  const int row = m_torrentList.size();
573 
574  beginInsertRows({}, row, row);
575  m_torrentList << torrent;
576  m_torrentMap[torrent] = row;
577  endInsertRows();
578 }
QHash< BitTorrent::Torrent *, int > m_torrentMap
QList< BitTorrent::Torrent * > m_torrentList

References m_torrentList, and m_torrentMap.

◆ columnCount()

int TransferListModel::columnCount ( const QModelIndex &  parent = {}) const
override

Definition at line 158 of file transferlistmodel.cpp.

159 {
160  return NB_COLUMNS;
161 }

References NB_COLUMNS.

Referenced by configure(), TransferListWidget::displayDLHoSMenu(), handleTorrentStatusUpdated(), and handleTorrentsUpdated().

Here is the caller graph for this function:

◆ configure()

void TransferListModel::configure ( )
private

Definition at line 640 of file transferlistmodel.cpp.

641 {
642  const Preferences *pref = Preferences::instance();
643 
644  HideZeroValuesMode hideZeroValuesMode = HideZeroValuesMode::Never;
645  if (pref->getHideZeroValues())
646  {
647  if (pref->getHideZeroComboValues() == 1)
648  hideZeroValuesMode = HideZeroValuesMode::Paused;
649  else
650  hideZeroValuesMode = HideZeroValuesMode::Always;
651  }
652 
653  if (m_hideZeroValuesMode != hideZeroValuesMode)
654  {
655  m_hideZeroValuesMode = hideZeroValuesMode;
656  emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1)));
657  }
658 }
int getHideZeroComboValues() const
bool getHideZeroValues() const
int rowCount(const QModelIndex &parent={}) const override
HideZeroValuesMode m_hideZeroValuesMode
int columnCount(const QModelIndex &parent={}) const override

References Always, columnCount(), Preferences::getHideZeroComboValues(), Preferences::getHideZeroValues(), Preferences::instance(), m_hideZeroValuesMode, Never, Paused, and rowCount().

Here is the call graph for this function:

◆ data()

QVariant TransferListModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 482 of file transferlistmodel.cpp.

483 {
484  if (!index.isValid()) return {};
485 
486  const BitTorrent::Torrent *torrent = m_torrentList.value(index.row());
487  if (!torrent) return {};
488 
489  switch (role)
490  {
491  case Qt::ForegroundRole:
492  return m_stateThemeColors.value(torrent->state(), getDefaultColorByState(torrent->state()));
493  case Qt::DisplayRole:
494  return displayValue(torrent, index.column());
495  case UnderlyingDataRole:
496  return internalValue(torrent, index.column(), false);
498  return internalValue(torrent, index.column(), true);
499  case Qt::DecorationRole:
500  if (index.column() == TR_NAME)
501  return getIconByState(torrent->state());
502  break;
503  case Qt::ToolTipRole:
504  switch (index.column())
505  {
506  case TR_NAME:
507  case TR_STATUS:
508  case TR_CATEGORY:
509  case TR_TAGS:
510  case TR_TRACKER:
511  case TR_SAVE_PATH:
512  return displayValue(torrent, index.column());
513  }
514  break;
515  case Qt::TextAlignmentRole:
516  switch (index.column())
517  {
519  case TR_AMOUNT_UPLOADED:
522  case TR_AMOUNT_LEFT:
523  case TR_COMPLETED:
524  case TR_SIZE:
525  case TR_TOTAL_SIZE:
526  case TR_ETA:
527  case TR_SEEDS:
528  case TR_PEERS:
529  case TR_UPSPEED:
530  case TR_DLSPEED:
531  case TR_UPLIMIT:
532  case TR_DLLIMIT:
533  case TR_RATIO_LIMIT:
534  case TR_RATIO:
535  case TR_QUEUE_POSITION:
536  case TR_LAST_ACTIVITY:
537  case TR_AVAILABILITY:
538  return QVariant {Qt::AlignRight | Qt::AlignVCenter};
539  }
540  }
541 
542  return {};
543 }
virtual TorrentState state() const =0
QString displayValue(const BitTorrent::Torrent *torrent, int column) const
QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt) const
static QIcon getIconByState(BitTorrent::TorrentState state)
static QColor getDefaultColorByState(BitTorrent::TorrentState state)

References AdditionalUnderlyingDataRole, displayValue(), getDefaultColorByState(), getIconByState(), internalValue(), m_stateThemeColors, m_torrentList, BitTorrent::Torrent::state(), TR_AMOUNT_DOWNLOADED, TR_AMOUNT_DOWNLOADED_SESSION, TR_AMOUNT_LEFT, TR_AMOUNT_UPLOADED, TR_AMOUNT_UPLOADED_SESSION, TR_AVAILABILITY, TR_CATEGORY, TR_COMPLETED, TR_DLLIMIT, TR_DLSPEED, TR_ETA, TR_LAST_ACTIVITY, TR_NAME, TR_PEERS, TR_QUEUE_POSITION, TR_RATIO, TR_RATIO_LIMIT, TR_SAVE_PATH, TR_SEEDS, TR_SIZE, TR_STATUS, TR_TAGS, TR_TOTAL_SIZE, TR_TRACKER, TR_UPLIMIT, TR_UPSPEED, and UnderlyingDataRole.

Here is the call graph for this function:

◆ displayValue()

QString TransferListModel::displayValue ( const BitTorrent::Torrent torrent,
int  column 
) const
private

Definition at line 239 of file transferlistmodel.cpp.

240 {
241  bool hideValues = false;
243  hideValues = true;
245  hideValues = (torrent->state() == BitTorrent::TorrentState::PausedDownloading);
246 
247  const auto availabilityString = [hideValues](const qreal value) -> QString
248  {
249  if (hideValues && (value == 0))
250  return {};
251  return (value >= 0)
253  : tr("N/A");
254  };
255 
256  const auto unitString = [hideValues](const qint64 value, const bool isSpeedUnit = false) -> QString
257  {
258  return (hideValues && (value == 0))
259  ? QString {} : Utils::Misc::friendlyUnit(value, isSpeedUnit);
260  };
261 
262  const auto limitString = [hideValues](const qint64 value) -> QString
263  {
264  if (hideValues && (value <= 0))
265  return {};
266 
267  return (value > 0)
269  : QString::fromUtf8(C_INFINITY);
270  };
271 
272  const auto amountString = [hideValues](const qint64 value, const qint64 total) -> QString
273  {
274  if (hideValues && (value == 0) && (total == 0))
275  return {};
276  return QString::fromLatin1("%1 (%2)").arg(QString::number(value), QString::number(total));
277  };
278 
279  const auto etaString = [hideValues](const qlonglong value) -> QString
280  {
281  if (hideValues && (value >= MAX_ETA))
282  return {};
284  };
285 
286  const auto ratioString = [hideValues](const qreal value) -> QString
287  {
288  if (hideValues && (value <= 0))
289  return {};
290 
291  return ((static_cast<int>(value) == -1) || (value > BitTorrent::Torrent::MAX_RATIO))
292  ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(value, 2);
293  };
294 
295  const auto queuePositionString = [](const qint64 value) -> QString
296  {
297  return (value >= 0) ? QString::number(value + 1) : QLatin1String("*");
298  };
299 
300  const auto lastActivityString = [hideValues](qint64 value) -> QString
301  {
302  if (hideValues && ((value < 0) || (value >= MAX_ETA)))
303  return {};
304 
305  // Show '< 1m ago' when elapsed time is 0
306  if (value == 0)
307  value = 1;
308 
309  return (value >= 0)
310  ? tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(value))
312  };
313 
314  const auto timeElapsedString = [hideValues](const qint64 elapsedTime, const qint64 seedingTime) -> QString
315  {
316  if (seedingTime <= 0)
317  {
318  if (hideValues && (elapsedTime == 0))
319  return {};
320  return Utils::Misc::userFriendlyDuration(elapsedTime);
321  }
322 
323  return tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
324  .arg(Utils::Misc::userFriendlyDuration(elapsedTime)
325  , Utils::Misc::userFriendlyDuration(seedingTime));
326  };
327 
328  const auto progressString = [](const qreal progress) -> QString
329  {
330  return (progress >= 1)
331  ? QString::fromLatin1("100%")
332  : Utils::String::fromDouble((progress * 100), 1) + QLatin1Char('%');
333  };
334 
335  const auto statusString = [this](const BitTorrent::TorrentState state, const QString &errorMessage) -> QString
336  {
337  return (state == BitTorrent::TorrentState::Error)
338  ? m_statusStrings[state] + ": " + errorMessage
339  : m_statusStrings[state];
340  };
341 
342  switch (column)
343  {
344  case TR_NAME:
345  return torrent->name();
346  case TR_QUEUE_POSITION:
347  return queuePositionString(torrent->queuePosition());
348  case TR_SIZE:
349  return unitString(torrent->wantedSize());
350  case TR_PROGRESS:
351  return progressString(torrent->progress());
352  case TR_STATUS:
353  return statusString(torrent->state(), torrent->error());
354  case TR_SEEDS:
355  return amountString(torrent->seedsCount(), torrent->totalSeedsCount());
356  case TR_PEERS:
357  return amountString(torrent->leechsCount(), torrent->totalLeechersCount());
358  case TR_DLSPEED:
359  return unitString(torrent->downloadPayloadRate(), true);
360  case TR_UPSPEED:
361  return unitString(torrent->uploadPayloadRate(), true);
362  case TR_ETA:
363  return etaString(torrent->eta());
364  case TR_RATIO:
365  return ratioString(torrent->realRatio());
366  case TR_RATIO_LIMIT:
367  return ratioString(torrent->maxRatio());
368  case TR_CATEGORY:
369  return torrent->category();
370  case TR_TAGS:
371  return torrent->tags().join(QLatin1String(", "));
372  case TR_ADD_DATE:
373  return QLocale().toString(torrent->addedTime().toLocalTime(), QLocale::ShortFormat);
374  case TR_SEED_DATE:
375  return QLocale().toString(torrent->completedTime().toLocalTime(), QLocale::ShortFormat);
376  case TR_TRACKER:
377  return torrent->currentTracker();
378  case TR_DLLIMIT:
379  return limitString(torrent->downloadLimit());
380  case TR_UPLIMIT:
381  return limitString(torrent->uploadLimit());
383  return unitString(torrent->totalDownload());
384  case TR_AMOUNT_UPLOADED:
385  return unitString(torrent->totalUpload());
387  return unitString(torrent->totalPayloadDownload());
389  return unitString(torrent->totalPayloadUpload());
390  case TR_AMOUNT_LEFT:
391  return unitString(torrent->remainingSize());
392  case TR_TIME_ELAPSED:
393  return timeElapsedString(torrent->activeTime(), torrent->finishedTime());
394  case TR_SAVE_PATH:
395  return Utils::Fs::toNativePath(torrent->savePath());
396  case TR_COMPLETED:
397  return unitString(torrent->completedSize());
399  return QLocale().toString(torrent->lastSeenComplete().toLocalTime(), QLocale::ShortFormat);
400  case TR_LAST_ACTIVITY:
401  return lastActivityString(torrent->timeSinceActivity());
402  case TR_AVAILABILITY:
403  return availabilityString(torrent->distributedCopies());
404  case TR_TOTAL_SIZE:
405  return unitString(torrent->totalSize());
406  }
407 
408  return {};
409 }
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
Definition: torrent.cpp:64
virtual qlonglong completedSize() const =0
virtual int totalSeedsCount() 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 QDateTime addedTime() const =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
Definition: torrent.h:110
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
Definition: orderedset.h:80
TorrentState
Definition: torrent.h:70
QString toNativePath(const QString &path)
Definition: fs.cpp:64
QString unitString(SizeUnit unit, bool isSpeed=false)
Definition: misc.cpp:252
QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap=-1)
Definition: misc.cpp:353
QString friendlyUnit(qint64 bytes, bool isSpeed=false)
Definition: misc.cpp:261
QString fromDouble(double n, int precision)
Definition: string.cpp:44
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64
const qlonglong MAX_ETA
Definition: types.h:33
const char C_INFINITY[]

References BitTorrent::Torrent::activeTime(), BitTorrent::Torrent::addedTime(), Always, C_INFINITY, BitTorrent::Torrent::category(), BitTorrent::Torrent::completedSize(), BitTorrent::Torrent::completedTime(), BitTorrent::Torrent::currentTracker(), BitTorrent::Torrent::distributedCopies(), BitTorrent::Torrent::downloadLimit(), BitTorrent::Torrent::downloadPayloadRate(), BitTorrent::Error, BitTorrent::Torrent::error(), BitTorrent::Torrent::eta(), BitTorrent::Torrent::finishedTime(), Utils::Misc::friendlyUnit(), Utils::String::fromDouble(), OrderedSet< T, Compare >::join(), BitTorrent::Torrent::lastSeenComplete(), BitTorrent::Torrent::leechsCount(), m_hideZeroValuesMode, m_statusStrings, MAX_ETA, BitTorrent::Torrent::MAX_RATIO, BitTorrent::Torrent::maxRatio(), BitTorrent::Torrent::name(), Paused, BitTorrent::PausedDownloading, BitTorrent::Torrent::progress(), BitTorrent::Torrent::queuePosition(), BitTorrent::Torrent::realRatio(), BitTorrent::Torrent::remainingSize(), BitTorrent::Torrent::savePath(), BitTorrent::Torrent::seedsCount(), BitTorrent::Torrent::state(), BitTorrent::Torrent::tags(), BitTorrent::Torrent::timeSinceActivity(), Utils::Fs::toNativePath(), BitTorrent::Torrent::totalDownload(), BitTorrent::Torrent::totalLeechersCount(), BitTorrent::Torrent::totalPayloadDownload(), BitTorrent::Torrent::totalPayloadUpload(), BitTorrent::Torrent::totalSeedsCount(), BitTorrent::Torrent::totalSize(), BitTorrent::Torrent::totalUpload(), TR_ADD_DATE, TR_AMOUNT_DOWNLOADED, TR_AMOUNT_DOWNLOADED_SESSION, TR_AMOUNT_LEFT, TR_AMOUNT_UPLOADED, TR_AMOUNT_UPLOADED_SESSION, TR_AVAILABILITY, TR_CATEGORY, TR_COMPLETED, TR_DLLIMIT, TR_DLSPEED, TR_ETA, TR_LAST_ACTIVITY, TR_NAME, TR_PEERS, TR_PROGRESS, TR_QUEUE_POSITION, TR_RATIO, TR_RATIO_LIMIT, TR_SAVE_PATH, TR_SEED_DATE, TR_SEEDS, TR_SEEN_COMPLETE_DATE, TR_SIZE, TR_STATUS, TR_TAGS, TR_TIME_ELAPSED, TR_TOTAL_SIZE, TR_TRACKER, TR_UPLIMIT, TR_UPSPEED, Utils::Misc::unitString(), BitTorrent::Torrent::uploadLimit(), BitTorrent::Torrent::uploadPayloadRate(), Utils::Misc::userFriendlyDuration(), anonymous_namespace{preferences.cpp}::value(), and BitTorrent::Torrent::wantedSize().

Referenced by data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flags()

Qt::ItemFlags TransferListModel::flags ( const QModelIndex &  index) const
override

Definition at line 580 of file transferlistmodel.cpp.

581 {
582  if (!index.isValid()) return Qt::NoItemFlags;
583 
584  // Explicitly mark as editable
585  return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
586 }

◆ handleTorrentAboutToBeRemoved

void TransferListModel::handleTorrentAboutToBeRemoved ( BitTorrent::Torrent *const  torrent)
privateslot

Definition at line 595 of file transferlistmodel.cpp.

596 {
597  const int row = m_torrentMap.value(torrent, -1);
598  Q_ASSERT(row >= 0);
599 
600  beginRemoveRows({}, row, row);
601  m_torrentList.removeAt(row);
602  m_torrentMap.remove(torrent);
603  for (int &value : m_torrentMap)
604  {
605  if (value > row)
606  --value;
607  }
608  endRemoveRows();
609 }

References m_torrentList, m_torrentMap, and anonymous_namespace{preferences.cpp}::value().

Here is the call graph for this function:

◆ handleTorrentStatusUpdated

void TransferListModel::handleTorrentStatusUpdated ( BitTorrent::Torrent *const  torrent)
privateslot

Definition at line 611 of file transferlistmodel.cpp.

612 {
613  const int row = m_torrentMap.value(torrent, -1);
614  Q_ASSERT(row >= 0);
615 
616  emit dataChanged(index(row, 0), index(row, columnCount() - 1));
617 }

References columnCount(), and m_torrentMap.

Here is the call graph for this function:

◆ handleTorrentsUpdated

void TransferListModel::handleTorrentsUpdated ( const QVector< BitTorrent::Torrent * > &  torrents)
privateslot

Definition at line 619 of file transferlistmodel.cpp.

620 {
621  const int columns = (columnCount() - 1);
622 
623  if (torrents.size() <= (m_torrentList.size() * 0.5))
624  {
625  for (BitTorrent::Torrent *const torrent : torrents)
626  {
627  const int row = m_torrentMap.value(torrent, -1);
628  Q_ASSERT(row >= 0);
629 
630  emit dataChanged(index(row, 0), index(row, columns));
631  }
632  }
633  else
634  {
635  // save the overhead when more than half of the torrent list needs update
636  emit dataChanged(index(0, 0), index((rowCount() - 1), columns));
637  }
638 }

References columnCount(), m_torrentList, m_torrentMap, and rowCount().

Here is the call graph for this function:

◆ headerData()

QVariant TransferListModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

Definition at line 163 of file transferlistmodel.cpp.

164 {
165  if (orientation == Qt::Horizontal)
166  {
167  if (role == Qt::DisplayRole)
168  {
169  switch (section)
170  {
171  case TR_QUEUE_POSITION: return QChar('#');
172  case TR_NAME: return tr("Name", "i.e: torrent name");
173  case TR_SIZE: return tr("Size", "i.e: torrent size");
174  case TR_PROGRESS: return tr("Progress", "% Done");
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");
182  case TR_CATEGORY: return tr("Category");
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");
186  case TR_TRACKER: return tr("Tracker");
187  case TR_DLLIMIT: return tr("Down Limit", "i.e: Download limit");
188  case TR_UPLIMIT: return tr("Up Limit", "i.e: Upload limit");
189  case TR_AMOUNT_DOWNLOADED: return tr("Downloaded", "Amount of data downloaded (e.g. in MB)");
190  case TR_AMOUNT_UPLOADED: return tr("Uploaded", "Amount of data uploaded (e.g. in MB)");
191  case TR_AMOUNT_DOWNLOADED_SESSION: return tr("Session Download", "Amount of data downloaded since program open (e.g. in MB)");
192  case TR_AMOUNT_UPLOADED_SESSION: return tr("Session Upload", "Amount of data uploaded since program open (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");
202  default: return {};
203  }
204  }
205  else if (role == Qt::TextAlignmentRole)
206  {
207  switch (section)
208  {
210  case TR_AMOUNT_UPLOADED:
213  case TR_AMOUNT_LEFT:
214  case TR_COMPLETED:
215  case TR_SIZE:
216  case TR_TOTAL_SIZE:
217  case TR_ETA:
218  case TR_SEEDS:
219  case TR_PEERS:
220  case TR_UPSPEED:
221  case TR_DLSPEED:
222  case TR_UPLIMIT:
223  case TR_DLLIMIT:
224  case TR_RATIO_LIMIT:
225  case TR_RATIO:
226  case TR_QUEUE_POSITION:
227  case TR_LAST_ACTIVITY:
228  case TR_AVAILABILITY:
229  return QVariant(Qt::AlignRight | Qt::AlignVCenter);
230  default:
231  return QAbstractListModel::headerData(section, orientation, role);
232  }
233  }
234  }
235 
236  return {};
237 }

References TR_ADD_DATE, TR_AMOUNT_DOWNLOADED, TR_AMOUNT_DOWNLOADED_SESSION, TR_AMOUNT_LEFT, TR_AMOUNT_UPLOADED, TR_AMOUNT_UPLOADED_SESSION, TR_AVAILABILITY, TR_CATEGORY, TR_COMPLETED, TR_DLLIMIT, TR_DLSPEED, TR_ETA, TR_LAST_ACTIVITY, TR_NAME, TR_PEERS, TR_PROGRESS, TR_QUEUE_POSITION, TR_RATIO, TR_RATIO_LIMIT, TR_SAVE_PATH, TR_SEED_DATE, TR_SEEDS, TR_SEEN_COMPLETE_DATE, TR_SIZE, TR_STATUS, TR_TAGS, TR_TIME_ELAPSED, TR_TOTAL_SIZE, TR_TRACKER, TR_UPLIMIT, and TR_UPSPEED.

Referenced by TransferListWidget::displayDLHoSMenu().

Here is the caller graph for this function:

◆ internalValue()

QVariant TransferListModel::internalValue ( const BitTorrent::Torrent torrent,
int  column,
bool  alt 
) const
private

Definition at line 411 of file transferlistmodel.cpp.

412 {
413  switch (column)
414  {
415  case TR_NAME:
416  return torrent->name();
417  case TR_QUEUE_POSITION:
418  return torrent->queuePosition();
419  case TR_SIZE:
420  return torrent->wantedSize();
421  case TR_PROGRESS:
422  return torrent->progress() * 100;
423  case TR_STATUS:
424  return QVariant::fromValue(torrent->state());
425  case TR_SEEDS:
426  return !alt ? torrent->seedsCount() : torrent->totalSeedsCount();
427  case TR_PEERS:
428  return !alt ? torrent->leechsCount() : torrent->totalLeechersCount();
429  case TR_DLSPEED:
430  return torrent->downloadPayloadRate();
431  case TR_UPSPEED:
432  return torrent->uploadPayloadRate();
433  case TR_ETA:
434  return torrent->eta();
435  case TR_RATIO:
436  return torrent->realRatio();
437  case TR_CATEGORY:
438  return torrent->category();
439  case TR_TAGS:
440  return QVariant::fromValue(torrent->tags());
441  case TR_ADD_DATE:
442  return torrent->addedTime();
443  case TR_SEED_DATE:
444  return torrent->completedTime();
445  case TR_TRACKER:
446  return torrent->currentTracker();
447  case TR_DLLIMIT:
448  return torrent->downloadLimit();
449  case TR_UPLIMIT:
450  return torrent->uploadLimit();
452  return torrent->totalDownload();
453  case TR_AMOUNT_UPLOADED:
454  return torrent->totalUpload();
456  return torrent->totalPayloadDownload();
458  return torrent->totalPayloadUpload();
459  case TR_AMOUNT_LEFT:
460  return torrent->remainingSize();
461  case TR_TIME_ELAPSED:
462  return !alt ? torrent->activeTime() : torrent->finishedTime();
463  case TR_SAVE_PATH:
464  return Utils::Fs::toNativePath(torrent->savePath());
465  case TR_COMPLETED:
466  return torrent->completedSize();
467  case TR_RATIO_LIMIT:
468  return torrent->maxRatio();
470  return torrent->lastSeenComplete();
471  case TR_LAST_ACTIVITY:
472  return torrent->timeSinceActivity();
473  case TR_AVAILABILITY:
474  return torrent->distributedCopies();
475  case TR_TOTAL_SIZE:
476  return torrent->totalSize();
477  }
478 
479  return {};
480 }

References BitTorrent::Torrent::activeTime(), BitTorrent::Torrent::addedTime(), BitTorrent::Torrent::category(), BitTorrent::Torrent::completedSize(), BitTorrent::Torrent::completedTime(), BitTorrent::Torrent::currentTracker(), BitTorrent::Torrent::distributedCopies(), BitTorrent::Torrent::downloadLimit(), BitTorrent::Torrent::downloadPayloadRate(), BitTorrent::Torrent::eta(), BitTorrent::Torrent::finishedTime(), BitTorrent::Torrent::lastSeenComplete(), BitTorrent::Torrent::leechsCount(), BitTorrent::Torrent::maxRatio(), BitTorrent::Torrent::name(), BitTorrent::Torrent::progress(), BitTorrent::Torrent::queuePosition(), BitTorrent::Torrent::realRatio(), BitTorrent::Torrent::remainingSize(), BitTorrent::Torrent::savePath(), BitTorrent::Torrent::seedsCount(), BitTorrent::Torrent::state(), BitTorrent::Torrent::tags(), BitTorrent::Torrent::timeSinceActivity(), Utils::Fs::toNativePath(), BitTorrent::Torrent::totalDownload(), BitTorrent::Torrent::totalLeechersCount(), BitTorrent::Torrent::totalPayloadDownload(), BitTorrent::Torrent::totalPayloadUpload(), BitTorrent::Torrent::totalSeedsCount(), BitTorrent::Torrent::totalSize(), BitTorrent::Torrent::totalUpload(), TR_ADD_DATE, TR_AMOUNT_DOWNLOADED, TR_AMOUNT_DOWNLOADED_SESSION, TR_AMOUNT_LEFT, TR_AMOUNT_UPLOADED, TR_AMOUNT_UPLOADED_SESSION, TR_AVAILABILITY, TR_CATEGORY, TR_COMPLETED, TR_DLLIMIT, TR_DLSPEED, TR_ETA, TR_LAST_ACTIVITY, TR_NAME, TR_PEERS, TR_PROGRESS, TR_QUEUE_POSITION, TR_RATIO, TR_RATIO_LIMIT, TR_SAVE_PATH, TR_SEED_DATE, TR_SEEDS, TR_SEEN_COMPLETE_DATE, TR_SIZE, TR_STATUS, TR_TAGS, TR_TIME_ELAPSED, TR_TOTAL_SIZE, TR_TRACKER, TR_UPLIMIT, TR_UPSPEED, BitTorrent::Torrent::uploadLimit(), BitTorrent::Torrent::uploadPayloadRate(), and BitTorrent::Torrent::wantedSize().

Referenced by data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rowCount()

int TransferListModel::rowCount ( const QModelIndex &  parent = {}) const
override

Definition at line 153 of file transferlistmodel.cpp.

154 {
155  return m_torrentList.size();
156 }

References m_torrentList.

Referenced by configure(), handleTorrentsUpdated(), and MainWindow::updateNbTorrents().

Here is the caller graph for this function:

◆ setData()

bool TransferListModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
override

Definition at line 545 of file transferlistmodel.cpp.

546 {
547  if (!index.isValid() || (role != Qt::DisplayRole)) return false;
548 
549  BitTorrent::Torrent *const torrent = m_torrentList.value(index.row());
550  if (!torrent) return false;
551 
552  // Category and Name columns can be edited
553  switch (index.column())
554  {
555  case TR_NAME:
556  torrent->setName(value.toString());
557  break;
558  case TR_CATEGORY:
559  torrent->setCategory(value.toString());
560  break;
561  default:
562  return false;
563  }
564 
565  return true;
566 }
virtual bool setCategory(const QString &category)=0
virtual void setName(const QString &name)=0

References m_torrentList, BitTorrent::Torrent::setCategory(), BitTorrent::Torrent::setName(), TR_CATEGORY, TR_NAME, and anonymous_namespace{preferences.cpp}::value().

Referenced by TransferListWidget::renameSelectedTorrent(), and TransferListWidget::setSelectionCategory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ torrentHandle()

BitTorrent::Torrent * TransferListModel::torrentHandle ( const QModelIndex &  index) const

Member Data Documentation

◆ m_hideZeroValuesMode

HideZeroValuesMode TransferListModel::m_hideZeroValuesMode = HideZeroValuesMode::Never
private

Definition at line 128 of file transferlistmodel.h.

Referenced by configure(), and displayValue().

◆ m_stateThemeColors

const QHash<BitTorrent::TorrentState, QColor> TransferListModel::m_stateThemeColors
private

Definition at line 119 of file transferlistmodel.h.

Referenced by data().

◆ m_statusStrings

const QHash<BitTorrent::TorrentState, QString> TransferListModel::m_statusStrings
private

Definition at line 117 of file transferlistmodel.h.

Referenced by displayValue().

◆ m_torrentList

QList<BitTorrent::Torrent *> TransferListModel::m_torrentList
private

◆ m_torrentMap

QHash<BitTorrent::Torrent *, int> TransferListModel::m_torrentMap
private

The documentation for this class was generated from the following files: