Browse Source

Add some missing columns to dynamic tables

adaptive-webui-19844
buinsky 8 years ago
parent
commit
134e4c1eb9
  1. 2
      src/webui/abstractwebapplication.cpp
  2. 62
      src/webui/btjson.cpp
  3. 135
      src/webui/www/public/scripts/dynamicTable.js

2
src/webui/abstractwebapplication.cpp

@ -244,7 +244,7 @@ void AbstractWebApplication::translateDocument(QString& data) @@ -244,7 +244,7 @@ void AbstractWebApplication::translateDocument(QString& data)
"options_imp", "Preferences", "TrackersAdditionDlg", "ScanFoldersModel",
"PropTabBar", "TorrentModel", "downloadFromURL", "MainWindow", "misc",
"StatusBar", "AboutDlg", "about", "PeerListWidget", "StatusFiltersWidget",
"CategoryFiltersList"
"CategoryFiltersList", "TransferListDelegate"
};
const size_t context_count = sizeof(contexts) / sizeof(contexts[0]);
int i = 0;

62
src/webui/btjson.cpp

@ -109,6 +109,19 @@ static const char KEY_TORRENT_FORCE_START[] = "force_start"; @@ -109,6 +109,19 @@ static const char KEY_TORRENT_FORCE_START[] = "force_start";
static const char KEY_TORRENT_SAVE_PATH[] = "save_path";
static const char KEY_TORRENT_ADDED_ON[] = "added_on";
static const char KEY_TORRENT_COMPLETION_ON[] = "completion_on";
static const char KEY_TORRENT_TRACKER[] = "tracker";
static const char KEY_TORRENT_DL_LIMIT[] = "dl_limit";
static const char KEY_TORRENT_UP_LIMIT[] = "up_limit";
static const char KEY_TORRENT_AMOUNT_DOWNLOADED[] = "downloaded";
static const char KEY_TORRENT_AMOUNT_UPLOADED[] = "uploaded";
static const char KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION[] = "downloaded_session";
static const char KEY_TORRENT_AMOUNT_UPLOADED_SESSION[] = "uploaded_session";
static const char KEY_TORRENT_AMOUNT_LEFT[] = "remaining";
static const char KEY_TORRENT_AMOUNT_COMPLETED[] = "completed";
static const char KEY_TORRENT_RATIO_LIMIT[] = "ratio_limit";
static const char KEY_TORRENT_LAST_SEEN_COMPLETE_TIME[] = "seen_complete";
static const char KEY_TORRENT_LAST_ACTIVITY_TIME[] = "last_activity";
static const char KEY_TORRENT_TOTAL_SIZE[] = "total_size";
// Peer keys
static const char KEY_PEER_IP[] = "ip";
@ -125,6 +138,7 @@ static const char KEY_PEER_CONNECTION_TYPE[] = "connection"; @@ -125,6 +138,7 @@ static const char KEY_PEER_CONNECTION_TYPE[] = "connection";
static const char KEY_PEER_FLAGS[] = "flags";
static const char KEY_PEER_FLAGS_DESCRIPTION[] = "flags_desc";
static const char KEY_PEER_RELEVANCE[] = "relevance";
static const char KEY_PEER_FILES[] = "files";
// Tracker keys
static const char KEY_TRACKER_URL[] = "url";
@ -347,6 +361,21 @@ QByteArray btjson::getTorrents(QString filter, QString category, @@ -347,6 +361,21 @@ QByteArray btjson::getTorrents(QString filter, QString category,
* - "state": Torrent state
* - "seq_dl": Torrent sequential download state
* - "f_l_piece_prio": Torrent first last piece priority state
* - "completion_on": Torrent copletion time
* - "tracker": Torrent tracker
* - "dl_limit": Torrent download limit
* - "up_limit": Torrent upload limit
* - "downloaded": Amount of data downloaded
* - "uploaded": Amount of data uploaded
* - "downloaded_session": Amount of data downloaded since program open
* - "uploaded_session": Amount of data uploaded since program open
* - "amount_left": Amount of data left to download
* - "save_path": Torrent save path
* - "completed": Amount of data completed
* - "ratio_limit": Upload share ratio limit
* - "seen_complete": Indicates the time when the torrent was last seen complete/whole
* - "last_activity": Last time when a chunk was downloaded/uploaded
* - "total_size": Size including unwanted data
* Server state map may contain the following keys:
* - "connection_status": connection status
* - "dht_nodes": DHT nodes count
@ -369,6 +398,16 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData @@ -369,6 +398,16 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData
foreach (BitTorrent::TorrentHandle *const torrent, session->torrents()) {
QVariantMap map = toMap(torrent);
map.remove(KEY_TORRENT_HASH);
// Calculated last activity time can differ from actual value by up to 10 seconds (this is a libtorrent issue).
// So we don't need unnecessary updates of last activity time in response.
if (lastData.contains("torrents") && lastData["torrents"].toHash().contains(torrent->hash()) &&
lastData["torrents"].toHash()[torrent->hash()].toMap().contains(KEY_TORRENT_LAST_ACTIVITY_TIME)) {
uint lastValue = lastData["torrents"].toHash()[torrent->hash()].toMap()[KEY_TORRENT_LAST_ACTIVITY_TIME].toUInt();
if (qAbs((int)(lastValue - map[KEY_TORRENT_LAST_ACTIVITY_TIME].toUInt())) < 15)
map[KEY_TORRENT_LAST_ACTIVITY_TIME] = lastValue;
}
torrents[torrent->hash()] = map;
}
@ -429,6 +468,8 @@ QByteArray btjson::getSyncTorrentPeersData(int acceptedResponseId, QString hash, @@ -429,6 +468,8 @@ QByteArray btjson::getSyncTorrentPeersData(int acceptedResponseId, QString hash,
peer[KEY_PEER_FLAGS] = pi.flags();
peer[KEY_PEER_FLAGS_DESCRIPTION] = pi.flagsDescription();
peer[KEY_PEER_RELEVANCE] = pi.relevance();
peer[KEY_PEER_FILES] = torrent->info().filesForPiece(pi.downloadingPieceIndex()).join(QLatin1String("\n"));
peers[pi.address().ip.toString() + ":" + QString::number(pi.address().port)] = peer;
}
@ -723,6 +764,27 @@ QVariantMap toMap(BitTorrent::TorrentHandle *const torrent) @@ -723,6 +764,27 @@ QVariantMap toMap(BitTorrent::TorrentHandle *const torrent)
ret[KEY_TORRENT_SAVE_PATH] = Utils::Fs::toNativePath(torrent->savePath());
ret[KEY_TORRENT_ADDED_ON] = torrent->addedTime().toTime_t();
ret[KEY_TORRENT_COMPLETION_ON] = torrent->completedTime().toTime_t();
ret[KEY_TORRENT_TRACKER] = torrent->currentTracker();
ret[KEY_TORRENT_DL_LIMIT] = torrent->downloadLimit();
ret[KEY_TORRENT_UP_LIMIT] = torrent->uploadLimit();
ret[KEY_TORRENT_AMOUNT_DOWNLOADED] = torrent->totalDownload();
ret[KEY_TORRENT_AMOUNT_UPLOADED] = torrent->totalUpload();
ret[KEY_TORRENT_AMOUNT_DOWNLOADED_SESSION] = torrent->totalPayloadDownload();
ret[KEY_TORRENT_AMOUNT_UPLOADED_SESSION] = torrent->totalPayloadUpload();
ret[KEY_TORRENT_AMOUNT_LEFT] = torrent->incompletedSize();
ret[KEY_TORRENT_AMOUNT_COMPLETED] = torrent->completedSize();
ret[KEY_TORRENT_RATIO_LIMIT] = torrent->maxRatio();
ret[KEY_TORRENT_LAST_SEEN_COMPLETE_TIME] = torrent->lastSeenComplete().toTime_t();
if (torrent->isPaused() || torrent->isChecking())
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;
else {
QDateTime dt = QDateTime::currentDateTime();
dt = dt.addSecs(-torrent->timeSinceActivity());
ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt.toTime_t();
}
ret[KEY_TORRENT_TOTAL_SIZE] = torrent->totalSize();
return ret;
}

135
src/webui/www/public/scripts/dynamicTable.js

@ -320,10 +320,10 @@ var DynamicTable = new Class({ @@ -320,10 +320,10 @@ var DynamicTable = new Class({
initColumns : function () {},
newColumn : function (name, style, caption, defaultWidth) {
newColumn : function (name, style, caption, defaultWidth, defaultVisible) {
var column = {};
column['name'] = name;
column['visible'] = getLocalStorageItem('column_' + name + '_visible_' + this.dynamicTableDivId, '1');
column['visible'] = getLocalStorageItem('column_' + name + '_visible_' + this.dynamicTableDivId, defaultVisible ? '1' : '0');
column['force_hide'] = false;
column['caption'] = caption;
column['style'] = style;
@ -723,19 +723,34 @@ var TorrentsTable = new Class({ @@ -723,19 +723,34 @@ var TorrentsTable = new Class({
Extends: DynamicTable,
initColumns : function () {
this.newColumn('priority', '', '#', 30);
this.newColumn('state_icon', 'cursor: default', '', 22);
this.newColumn('name', '', 'QBT_TR(Name)QBT_TR', 200);
this.newColumn('size', '', 'QBT_TR(Size)QBT_TR', 100);
this.newColumn('progress', '', 'QBT_TR(Done)QBT_TR', 85);
this.newColumn('num_seeds', '', 'QBT_TR(Seeds)QBT_TR', 100);
this.newColumn('num_leechs', '', 'QBT_TR(Peers)QBT_TR', 100);
this.newColumn('dlspeed', '', 'QBT_TR(Down Speed)QBT_TR', 100);
this.newColumn('upspeed', '', 'QBT_TR(Up Speed)QBT_TR', 100);
this.newColumn('eta', '', 'QBT_TR(ETA)QBT_TR', 100);
this.newColumn('ratio', '', 'QBT_TR(Ratio)QBT_TR', 100);
this.newColumn('category', '', 'QBT_TR(Category)QBT_TR', 100);
this.newColumn('added_on', '', 'QBT_TR(Added On)QBT_TR', 100);
this.newColumn('priority', '', '#', 30, true);
this.newColumn('state_icon', 'cursor: default', '', 22, true);
this.newColumn('name', '', 'QBT_TR(Name)QBT_TR[CONTEXT=TorrentModel]', 200, true);
this.newColumn('size', '', 'QBT_TR(Size)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('progress', '', 'QBT_TR(Done)QBT_TR[CONTEXT=TorrentModel]', 85, true);
this.newColumn('num_seeds', '', 'QBT_TR(Seeds)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('num_leechs', '', 'QBT_TR(Peers)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('dlspeed', '', 'QBT_TR(Down Speed)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('upspeed', '', 'QBT_TR(Up Speed)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('eta', '', 'QBT_TR(ETA)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('ratio', '', 'QBT_TR(Ratio)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('category', '', 'QBT_TR(Category)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('added_on', '', 'QBT_TR(Added On)QBT_TR[CONTEXT=TorrentModel]', 100, true);
this.newColumn('completion_on', '', 'QBT_TR(Completed On)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('tracker', '', 'QBT_TR(Tracker)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('dl_limit', '', 'QBT_TR(Down Limit)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('up_limit', '', 'QBT_TR(Up Limit)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('downloaded', '', 'QBT_TR(Downloaded)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('uploaded', '', 'QBT_TR(Uploaded)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('downloaded_session', '', 'QBT_TR(Session Download)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('uploaded_session', '', 'QBT_TR(Session Upload)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('amount_left', '', 'QBT_TR(Remaining)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('save_path', '', 'QBT_TR(Save path)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('completed', '', 'QBT_TR(Completed)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('ratio_limit', '', 'QBT_TR(Ratio Limit)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('seen_complete', '', 'QBT_TR(Last Seen Complete)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('last_activity', '', 'QBT_TR(Last Activity)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.newColumn('total_size', '', 'QBT_TR(Total Size)QBT_TR[CONTEXT=TorrentModel]', 100, false);
this.columns['state_icon'].onclick = '';
this.columns['state_icon'].dataProperties[0] = 'state';
@ -909,6 +924,64 @@ var TorrentsTable = new Class({ @@ -909,6 +924,64 @@ var TorrentsTable = new Class({
var date = new Date(this.getRowValue(row) * 1000).toLocaleString();
td.set('html', date);
};
// completion_on
this.columns['completion_on'].updateTd = function (td, row) {
var val = this.getRowValue(row);
if (val === 0xffffffff || val < 0)
td.set('html', '');
else {
var date = new Date(this.getRowValue(row) * 1000).toLocaleString();
td.set('html', date);
}
};
// seen_complete
this.columns['seen_complete'].updateTd = this.columns['completion_on'].updateTd;
// dl_limit, up_limit
this.columns['dl_limit'].updateTd = function (td, row) {
var speed = this.getRowValue(row);
if (speed === 0)
td.set('html', '∞')
else
td.set('html', friendlyUnit(speed, true));
};
this.columns['up_limit'].updateTd = this.columns['dl_limit'].updateTd;
// downloaded, uploaded, downloaded_session, uploaded_session, amount_left, completed, total_size
this.columns['downloaded'].updateTd = this.columns['size'].updateTd;
this.columns['uploaded'].updateTd = this.columns['size'].updateTd;
this.columns['downloaded_session'].updateTd = this.columns['size'].updateTd;
this.columns['uploaded_session'].updateTd = this.columns['size'].updateTd;
this.columns['amount_left'].updateTd = this.columns['size'].updateTd;
this.columns['amount_left'].updateTd = this.columns['size'].updateTd;
this.columns['completed'].updateTd = this.columns['size'].updateTd;
this.columns['total_size'].updateTd = this.columns['size'].updateTd;
// save_path, tracker
this.columns['save_path'].updateTd = this.columns['name'].updateTd;
this.columns['tracker'].updateTd = this.columns['name'].updateTd;
// ratio_limit
this.columns['ratio_limit'].updateTd = this.columns['ratio'].updateTd;
// last_activity
this.columns['last_activity'].updateTd = function (td, row) {
var val = this.getRowValue(row);
if (val < 1)
td.set('html', '∞');
else
td.set('html', 'QBT_TR(%1 ago)QBT_TR[CONTEXT=TransferListDelegate]'.replace('%1', friendlyDuration((new Date()) / 1000 - val, true)));
};
},
applyFilter : function (row, filterName, categoryHash) {
@ -1035,18 +1108,19 @@ var TorrentPeersTable = new Class({ @@ -1035,18 +1108,19 @@ var TorrentPeersTable = new Class({
Extends: DynamicTable,
initColumns : function () {
this.newColumn('country', '', 'QBT_TR(Country)QBT_TR', 22);
this.newColumn('ip', '', 'QBT_TR(IP)QBT_TR', 80);
this.newColumn('port', '', 'QBT_TR(Port)QBT_TR', 35);
this.newColumn('client', '', 'QBT_TR(Client)QBT_TR', 140);
this.newColumn('progress', '', 'QBT_TR(Progress)QBT_TR', 50);
this.newColumn('dl_speed', '', 'QBT_TR(Down Speed)QBT_TR', 50);
this.newColumn('up_speed', '', 'QBT_TR(Up Speed)QBT_TR', 50);
this.newColumn('downloaded', '', 'QBT_TR(Downloaded)QBT_TR[CONTEXT=PeerListWidget]', 50);
this.newColumn('uploaded', '', 'QBT_TR(Uploaded)QBT_TR[CONTEXT=PeerListWidget]', 50);
this.newColumn('connection', '', 'QBT_TR(Connection)QBT_TR', 50);
this.newColumn('flags', '', 'QBT_TR(Flags)QBT_TR', 50);
this.newColumn('relevance', '', 'QBT_TR(Relevance)QBT_TR', 30);
this.newColumn('country', '', 'QBT_TR(Country)QBT_TR[CONTEXT=PeerListWidget]', 22, true);
this.newColumn('ip', '', 'QBT_TR(IP)QBT_TR[CONTEXT=PeerListWidget]', 80, true);
this.newColumn('port', '', 'QBT_TR(Port)QBT_TR[CONTEXT=PeerListWidget]', 35, true);
this.newColumn('client', '', 'QBT_TR(Client)QBT_TR[CONTEXT=PeerListWidget]', 140, true);
this.newColumn('progress', '', 'QBT_TR(Progress)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('dl_speed', '', 'QBT_TR(Down Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('up_speed', '', 'QBT_TR(Up Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('downloaded', '', 'QBT_TR(Downloaded)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('uploaded', '', 'QBT_TR(Uploaded)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('connection', '', 'QBT_TR(Connection)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('flags', '', 'QBT_TR(Flags)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('relevance', '', 'QBT_TR(Relevance)QBT_TR[CONTEXT=PeerListWidget]', 30, true);
this.newColumn('files', '', 'QBT_TR(Files)QBT_TR[CONTEXT=PeerListWidget]', 100, true);
this.columns['country'].dataProperties.push('country_code');
this.columns['flags'].dataProperties.push('flags_desc');
@ -1141,6 +1215,13 @@ var TorrentPeersTable = new Class({ @@ -1141,6 +1215,13 @@ var TorrentPeersTable = new Class({
td.title = this.getRowValue(row, 1);
};
// files
this.columns['files'].updateTd = function (td, row) {
td.innerHTML = escapeHtml(this.getRowValue(row, 0).replace('\n', ';'));
td.title = escapeHtml(this.getRowValue(row, 0));
};
}
});

Loading…
Cancel
Save