Skip to content

Commit

Permalink
no more Peers Source info
Browse files Browse the repository at this point in the history
** This commit dropped Peers Source info **
** Will be added in later MR **

New commit for later use:
[UI] Add and improve trackers tab

First, added trackers tab to the WebUI.
Second, now we can view all the trackers and view each:
* status
* number of peers
* additional message
Third, moved the private torrent info to the details tab (GTK).

closes: https://dev.deluge-torrent.org/ticket/1015
  • Loading branch information
DjLegolas committed May 7, 2022
1 parent a5a6502 commit 38929ab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 100 deletions.
49 changes: 4 additions & 45 deletions deluge/ui/gtk3/trackers_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self):

# key is url, item is row iter
self.trackers = {}
self.constant_rows = {}

self._can_get_trackers_info = False

Expand Down Expand Up @@ -94,28 +93,13 @@ def __init__(self):

self.torrent_id = None

self._fill_constant_rows()

def _fill_constant_rows(self):
for item in ['DHT', 'PeX', 'LSD']:
row = self.liststore.append(
[
f'*** {item} ***',
'',
0,
'',
]
)

self.constant_rows[item.lower()] = row

def update(self):
if client.is_standalone():
self._can_get_trackers_info = True
else:
self._can_get_trackers_info = (
VersionSplit(client.connection_version()) > VersionSplit('2.0.5')
)
self._can_get_trackers_info = VersionSplit(
client.connection_version()
) > VersionSplit('2.0.5')
self.do_update()

@maybe_coroutine
Expand All @@ -128,14 +112,12 @@ async def do_update(self):
torrent_id = torrent_id[0]
else:
self.liststore.clear()
self._fill_constant_rows()
return

if torrent_id != self.torrent_id:
# We only want to do this if the torrent_id has changed
self.liststore.clear()
self.trackers = {}
self._fill_constant_rows()
self.torrent_id = torrent_id

session = component.get('SessionProxy')
Expand All @@ -152,9 +134,6 @@ async def do_update(self):
'trackers_peers',
]

peers_sources = await session.get_torrent_status(torrent_id, ['peers_source'])
self._on_get_peers_source_status(peers_sources)

status = await session.get_torrent_status(torrent_id, tracker_keys)
self._on_get_torrent_tracker_status(status)

Expand All @@ -164,12 +143,7 @@ def _on_get_torrent_tracker_status(self, status):
return

if not self._can_get_trackers_info:
status['trackers'] = [
{
'url': status['tracker_host'],
'message': ''
}
]
status['trackers'] = [{'url': status['tracker_host'], 'message': ''}]
status['trackers_status'] = {
status['tracker_host']: status['tracker_status']
}
Expand Down Expand Up @@ -212,23 +186,8 @@ def _on_get_torrent_tracker_status(self, status):
self.liststore.remove(self.trackers[tracker])
del self.trackers[tracker]

def _on_get_peers_source_status(self, status):
# Check to see if we got valid data from the core
if not status:
return

for const_values in status['peers_source']:
row = self.constant_rows[const_values['name']]
old_peers_value = self.liststore.get(row, 2)[0]
status = 'Working' if const_values['enabled'] else 'Disabled'
peers_count = const_values['count']
self.liststore.set_value(row, 1, status)
if peers_count != old_peers_value:
self.liststore.set_value(row, 2, peers_count)

def clear(self):
self.liststore.clear()
self._fill_constant_rows()

def _on_button_press_event(self, widget, event):
"""This is a callback for showing the right-click context menu."""
Expand Down
8 changes: 7 additions & 1 deletion deluge/ui/web/js/deluge-all/Keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ Deluge.Keys = {

/**
* Keys used in the trackers tab of the statistics panel.
* <pre>['trackers']</pre>
* <pre>['trackers', 'trackers_status', 'trackers_peers']</pre>
*/
Trackers: ['trackers', 'trackers_status', 'trackers_peers'],

/**
* Keys used in the trackers tab of the statistics panel for Deluge version <2.0.5.
* <pre>['tracker_host', 'tracker_status']</pre>
*/
TrackersRedundant: ['tracker_host', 'tracker_status'],

/**
* Keys used in the details tab of the statistics panel.
*/
Expand Down
7 changes: 7 additions & 0 deletions deluge/ui/web/js/deluge-all/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ deluge.ui = {
deluge.sidebar = new Deluge.Sidebar();
deluge.statusbar = new Deluge.Statusbar();
deluge.toolbar = new Deluge.Toolbar();
deluge.server_version = '';

this.detailsPanel = new Ext.Panel({
id: 'detailsPanel',
Expand Down Expand Up @@ -204,6 +205,11 @@ deluge.ui = {
this.running = setInterval(this.update, 2000);
this.update();
}
deluge.client.daemon.get_version({
success: function (server_version) {
deluge.server_version = server_version;
},
});
deluge.client.web.get_plugins({
success: this.onGotPlugins,
scope: this,
Expand All @@ -215,6 +221,7 @@ deluge.ui = {
* @private
*/
onDisconnect: function () {
deluge.server_version = '';
this.stop();
},

Expand Down
76 changes: 22 additions & 54 deletions deluge/ui/web/js/deluge-all/details/TrackersTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Deluge.details.TrackersTab = Ext.extend(Ext.grid.GridPanel, {
// fast way to figure out if we have a tracker already.
trackers: {},
constantRows: {},
can_get_trackers_info: false,

constructor: function (config) {
config = Ext.apply(
Expand Down Expand Up @@ -67,54 +67,28 @@
this,
config
);
// this.constantRows = {};
this._fillConstantRows();
},

_fillConstantRows: function () {
var constRows = [];
var tmpConstantRows = {};

Ext.each(['DHT', 'PeX', 'LSD'], function (constRowName) {
constRows.push(
new Deluge.data.Tracker(
{
tracker: '*** ' + constRowName + ' ***',
status: '',
peers: 0,
message: '',
},
constRowName.toLowerCase()
)
);
tmpConstantRows[constRowName.toLowerCase()] = true;
});

this.constantRows = tmpConstantRows;
var store = this.getStore();
store.add(constRows);
store.commitChanges();
},

clear: function () {
this.getStore().removeAll();
this._fillConstantRows();
this.trackers = {};
},

update: function (torrentId) {
this.can_get_trackers_info = deluge.server_version > '2.0.5';

var trackers_keys = this.can_get_trackers_info
? Deluge.Keys.Trackers
: Deluge.Keys.TrackersRedundant;

deluge.client.web.get_torrent_status(
torrentId,
Deluge.Keys.Trackers,
trackers_keys,
{
success: this.onTrackersRequestComplete,
scope: this,
}
);
deluge.client.web.get_torrent_status(torrentId, ['peers_source'], {
success: this.onPeersSourceRequestComplete,
scope: this,
});
},

onTrackersRequestComplete: function (status, options) {
Expand All @@ -124,6 +98,20 @@
var newTrackers = [];
var addresses = {};

if (!this.can_get_trackers_info) {
status['trackers'] = [
{
'url': status['tracker_host'],
'message': ''
}
];
var tracker_host = status['tracker_host'];
status['trackers_status'] = {
tracker_host: status['tracker_status']
};
status['trackers_peers'] = {};
};

// Go through the trackers updating and creating tracker records
Ext.each(
status.trackers,
Expand Down Expand Up @@ -175,25 +163,5 @@
if (!sortState) return;
store.sort(sortState.field, sortState.direction);
},

onPeersSourceRequestComplete: function (status, options) {
if (!status) return;

var store = this.getStore();
Ext.each(status.peers_source, function (source) {
var record = store.getById(source.name);
var source_data = {
status: source.enabled ? 'Working' : 'Disabled',
peers: source.count,
};
record.beginEdit();
for (var k in source_data) {
if (record.get(k) != source_data[k]) {
record.set(k, source_data[k]);
}
}
record.endEdit();
});
},
});
})();

0 comments on commit 38929ab

Please sign in to comment.