Browse Source

Merge pull request #10954 from Chocobo1/column

Add availability column
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
f121e67aba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/gui/transferlistdelegate.cpp
  2. 7
      src/gui/transferlistmodel.cpp
  3. 1
      src/gui/transferlistmodel.h
  4. 1
      src/webui/api/serialize/serialize_torrent.cpp
  5. 1
      src/webui/api/serialize/serialize_torrent.h
  6. 19
      src/webui/www/private/scripts/dynamicTable.js
  7. 6
      src/webui/www/private/scripts/misc.js

12
src/gui/transferlistdelegate.cpp

@ -192,6 +192,18 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString); QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString);
} }
break; break;
case TransferListModel::TR_AVAILABILITY: {
const qreal availability = index.data().toReal();
if (hideValues && (availability <= 0))
break;
const QString availabilityStr = Utils::String::fromDouble(availability, 3);
opt.displayAlignment = (Qt::AlignRight | Qt::AlignVCenter);
QItemDelegate::drawDisplay(painter, opt, option.rect, availabilityStr);
}
break;
default: default:
QItemDelegate::paint(painter, option, index); QItemDelegate::paint(painter, option, index);
} }

7
src/gui/transferlistmodel.cpp

@ -124,8 +124,8 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_SEEN_COMPLETE_DATE: return tr("Last Seen Complete", "Indicates the time when the torrent was last seen complete/whole"); 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_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_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data");
default: case TR_AVAILABILITY: return tr("Availability", "The number of distributed copies of the torrent");
return {}; default: return {};
} }
} }
else if (role == Qt::TextAlignmentRole) { else if (role == Qt::TextAlignmentRole) {
@ -149,6 +149,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_RATIO: case TR_RATIO:
case TR_QUEUE_POSITION: case TR_QUEUE_POSITION:
case TR_LAST_ACTIVITY: case TR_LAST_ACTIVITY:
case TR_AVAILABILITY:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default: default:
return QAbstractListModel::headerData(section, orientation, role); return QAbstractListModel::headerData(section, orientation, role);
@ -239,6 +240,8 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
if (torrent->isPaused() || torrent->isChecking()) if (torrent->isPaused() || torrent->isChecking())
return -1; return -1;
return torrent->timeSinceActivity(); return torrent->timeSinceActivity();
case TR_AVAILABILITY:
return torrent->distributedCopies();
case TR_TOTAL_SIZE: case TR_TOTAL_SIZE:
return torrent->totalSize(); return torrent->totalSize();
} }

1
src/gui/transferlistmodel.h

@ -77,6 +77,7 @@ public:
TR_RATIO_LIMIT, TR_RATIO_LIMIT,
TR_SEEN_COMPLETE_DATE, TR_SEEN_COMPLETE_DATE,
TR_LAST_ACTIVITY, TR_LAST_ACTIVITY,
TR_AVAILABILITY,
NB_COLUMNS NB_COLUMNS
}; };

1
src/webui/api/serialize/serialize_torrent.cpp

@ -125,6 +125,7 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent)
ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent.lastSeenComplete().toTime_t(); ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent.lastSeenComplete().toTime_t();
ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent.isAutoTMMEnabled(); ret[KEY_TORRENT_AUTO_TORRENT_MANAGEMENT] = torrent.isAutoTMMEnabled();
ret[KEY_TORRENT_TIME_ACTIVE] = torrent.activeTime(); ret[KEY_TORRENT_TIME_ACTIVE] = torrent.activeTime();
ret[KEY_TORRENT_AVAILABILITY] = torrent.distributedCopies();
if (torrent.isPaused() || torrent.isChecking()) { if (torrent.isPaused() || torrent.isChecking()) {
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0; ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;

1
src/webui/api/serialize/serialize_torrent.h

@ -78,5 +78,6 @@ const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity";
const char KEY_TORRENT_TOTAL_SIZE[] = "total_size"; const char KEY_TORRENT_TOTAL_SIZE[] = "total_size";
const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm"; const char KEY_TORRENT_AUTO_TORRENT_MANAGEMENT[] = "auto_tmm";
const char KEY_TORRENT_TIME_ACTIVE[] = "time_active"; const char KEY_TORRENT_TIME_ACTIVE[] = "time_active";
const char KEY_TORRENT_AVAILABILITY[] = "availability";
QVariantMap serialize(const BitTorrent::TorrentHandle &torrent); QVariantMap serialize(const BitTorrent::TorrentHandle &torrent);

19
src/webui/www/private/scripts/dynamicTable.js

@ -828,12 +828,12 @@ const TorrentsTable = new Class({
this.newColumn('max_ratio', '', 'QBT_TR(Ratio Limit)QBT_TR[CONTEXT=TransferListModel]', 100, false); this.newColumn('max_ratio', '', 'QBT_TR(Ratio Limit)QBT_TR[CONTEXT=TransferListModel]', 100, false);
this.newColumn('seen_complete', '', 'QBT_TR(Last Seen Complete)QBT_TR[CONTEXT=TransferListModel]', 100, false); this.newColumn('seen_complete', '', 'QBT_TR(Last Seen Complete)QBT_TR[CONTEXT=TransferListModel]', 100, false);
this.newColumn('last_activity', '', 'QBT_TR(Last Activity)QBT_TR[CONTEXT=TransferListModel]', 100, false); this.newColumn('last_activity', '', 'QBT_TR(Last Activity)QBT_TR[CONTEXT=TransferListModel]', 100, false);
this.newColumn('availability', '', 'QBT_TR(Availability)QBT_TR[CONTEXT=TransferListModel]', 100, false);
this.columns['state_icon'].onclick = ''; this.columns['state_icon'].onclick = '';
this.columns['state_icon'].dataProperties[0] = 'state'; this.columns['state_icon'].dataProperties[0] = 'state';
this.columns['num_seeds'].dataProperties.push('num_complete'); this.columns['num_seeds'].dataProperties.push('num_complete');
this.columns['num_leechs'].dataProperties.push('num_incomplete'); this.columns['num_leechs'].dataProperties.push('num_incomplete');
this.initColumnsFunctions(); this.initColumnsFunctions();
@ -1092,13 +1092,9 @@ const TorrentsTable = new Class({
// ratio // ratio
this.columns['ratio'].updateTd = function(td, row) { this.columns['ratio'].updateTd = function(td, row) {
const ratio = this.getRowValue(row); const ratio = this.getRowValue(row);
let html = null; const string = (ratio === -1) ? '∞' : toFixedPointString(ratio, 2);
if (ratio == -1) td.set('html', string);
html = '∞'; td.set('title', string);
else
html = (Math.floor(100 * ratio) / 100).toFixed(2); //Don't round up
td.set('html', html);
td.set('title', html);
}; };
// tags // tags
@ -1181,6 +1177,13 @@ const TorrentsTable = new Class({
td.set('html', time); td.set('html', time);
td.set('title', time); td.set('title', time);
}; };
// availability
this.columns['availability'].updateTd = function(td, row) {
const value = toFixedPointString(this.getRowValue(row), 3);
td.set('html', value);
td.set('title', value);
};
}, },
applyFilter: function(row, filterName, categoryHash, tagHash, filterTerms) { applyFilter: function(row, filterName, categoryHash, tagHash, filterTerms) {

6
src/webui/www/private/scripts/misc.js

@ -161,3 +161,9 @@ function safeTrim(value) {
throw e; throw e;
} }
} }
function toFixedPointString(number, digits) {
// Do not round up number
const power = Math.pow(10, digits);
return (Math.floor(power * number) / power).toFixed(digits);
}

Loading…
Cancel
Save