2007-08-05 04:07:17 +00:00
|
|
|
# Copyright (C) 2007
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
### Initialization ###
|
|
|
|
|
|
|
|
plugin_name = _("Torrent Peers")
|
|
|
|
plugin_author = "Deluge"
|
|
|
|
plugin_version = "0.2"
|
|
|
|
plugin_description = _("""
|
2007-08-27 06:03:16 +00:00
|
|
|
This shows you the peers associated with each torrent and shows you their ip, \
|
|
|
|
country, client, percent complete and upload and download speeds.
|
2007-08-05 04:07:17 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
def deluge_init(deluge_path):
|
|
|
|
global path
|
|
|
|
path = deluge_path
|
|
|
|
|
|
|
|
def enable(core, interface):
|
|
|
|
global path
|
|
|
|
return TorrentPeers(path, core, interface)
|
|
|
|
|
|
|
|
### The Plugin ###
|
|
|
|
import gtk
|
2007-08-07 17:04:56 +00:00
|
|
|
|
|
|
|
import deluge
|
2007-08-05 04:07:17 +00:00
|
|
|
from TorrentPeers.tab_peers import PeersTabManager
|
|
|
|
|
|
|
|
class TorrentPeers:
|
|
|
|
|
|
|
|
def __init__(self, path, core, interface):
|
|
|
|
print "Loading TorrentPeers plugin..."
|
|
|
|
self.parent = interface
|
2007-08-06 04:02:42 +00:00
|
|
|
self.manager = core
|
2007-08-06 00:40:18 +00:00
|
|
|
self.config_file = deluge.common.CONFIG_DIR + "/peers.conf"
|
2007-09-05 01:29:59 +00:00
|
|
|
self.config = deluge.pref.Preferences(self.config_file, False,
|
|
|
|
defaults={'enable_flags' : True,
|
|
|
|
'size_18' : True})
|
2007-08-06 00:40:18 +00:00
|
|
|
try:
|
|
|
|
self.config.load()
|
|
|
|
except IOError:
|
|
|
|
# File does not exist
|
|
|
|
pass
|
|
|
|
self.dialog_initialize = True
|
|
|
|
self.glade = gtk.glade.XML(path + "/peers_preferences.glade")
|
|
|
|
self.dialog = self.glade.get_widget("dialog")
|
|
|
|
self.glade.signal_autoconnect({
|
|
|
|
'toggle_ui': self.toggle_ui,
|
2007-08-08 02:03:28 +00:00
|
|
|
'on_button_cancel_clicked': self.cancel_clicked,
|
|
|
|
'on_button_ok_clicked': self.ok_clicked
|
2007-08-06 00:40:18 +00:00
|
|
|
})
|
2007-08-06 03:52:16 +00:00
|
|
|
tree_view = gtk.TreeView()
|
|
|
|
scrolled_window = gtk.ScrolledWindow()
|
|
|
|
scrolled_window.add(tree_view)
|
|
|
|
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
self.top_widget = scrolled_window
|
|
|
|
|
|
|
|
self.parent_notebook = self.parent.notebook
|
|
|
|
self.parent_notebook.append_page(self.top_widget,
|
|
|
|
gtk.Label(_("Peers")))
|
|
|
|
|
|
|
|
tree_view.show()
|
|
|
|
scrolled_window.show()
|
|
|
|
|
|
|
|
self.tab_peers = PeersTabManager(tree_view, core)
|
2007-08-05 04:07:17 +00:00
|
|
|
self.tab_peers.build_peers_view()
|
2007-08-07 17:04:56 +00:00
|
|
|
|
|
|
|
self.config_updated()
|
2007-08-05 04:07:17 +00:00
|
|
|
|
|
|
|
def unload(self):
|
|
|
|
self.tab_peers.clear_peer_store()
|
2007-08-06 03:52:16 +00:00
|
|
|
tab_page = self.parent_notebook.page_num(self.top_widget)
|
|
|
|
self.parent_notebook.remove_page(tab_page)
|
2007-08-06 00:40:18 +00:00
|
|
|
self.config.save(self.config_file)
|
|
|
|
|
|
|
|
def configure(self, window):
|
|
|
|
self.dialog_initialize = True
|
2007-09-05 01:43:55 +00:00
|
|
|
if self.config.get("enable_flags"):
|
|
|
|
self.glade.get_widget("chk_flags").set_active(True)
|
|
|
|
self.glade.get_widget("radio_18").set_sensitive(True)
|
|
|
|
self.glade.get_widget("radio_25").set_sensitive(True)
|
|
|
|
if self.config.get("size_18"):
|
|
|
|
self.glade.get_widget("radio_18").set_active(True)
|
|
|
|
self.glade.get_widget("radio_25").set_active(False)
|
2007-08-06 00:40:18 +00:00
|
|
|
else:
|
2007-09-05 01:43:55 +00:00
|
|
|
self.glade.get_widget("radio_18").set_active(False)
|
|
|
|
self.glade.get_widget("radio_25").set_active(True)
|
|
|
|
else:
|
|
|
|
self.glade.get_widget("chk_flags").set_active(False)
|
|
|
|
self.glade.get_widget("radio_18").set_sensitive(False)
|
|
|
|
self.glade.get_widget("radio_25").set_sensitive(False)
|
2007-09-05 01:29:59 +00:00
|
|
|
|
2007-08-06 00:40:18 +00:00
|
|
|
self.dialog_initialize = False
|
|
|
|
self.dialog.set_transient_for(window)
|
|
|
|
self.dialog.show()
|
|
|
|
|
2007-08-07 17:04:56 +00:00
|
|
|
def config_updated(self):
|
2007-08-06 00:40:18 +00:00
|
|
|
if self.config.get("enable_flags"):
|
|
|
|
self.tab_peers.enable_flags()
|
|
|
|
if self.config.get("size_18"):
|
|
|
|
if self.tab_peers.flag_size == "25x15":
|
|
|
|
self.tab_peers.clear_flag_cache()
|
|
|
|
self.tab_peers.set_flag_size("18x12")
|
|
|
|
else:
|
|
|
|
if self.tab_peers.flag_size == "18x12":
|
|
|
|
self.tab_peers.clear_flag_cache()
|
|
|
|
self.tab_peers.set_flag_size("25x15")
|
|
|
|
else:
|
2007-08-07 17:04:56 +00:00
|
|
|
self.tab_peers.clear_flag_cache()
|
2007-08-06 04:37:11 +00:00
|
|
|
self.tab_peers.disable_flags()
|
2007-08-06 00:40:18 +00:00
|
|
|
|
|
|
|
def toggle_ui(self, widget):
|
|
|
|
if not self.dialog_initialize:
|
|
|
|
value = widget.get_active()
|
|
|
|
if widget == self.glade.get_widget("chk_flags"):
|
|
|
|
if value:
|
|
|
|
self.glade.get_widget("radio_18").set_sensitive(True)
|
|
|
|
self.glade.get_widget("radio_25").set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self.glade.get_widget("radio_18").set_sensitive(False)
|
|
|
|
self.glade.get_widget("radio_25").set_sensitive(False)
|
2007-08-05 04:07:17 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
if not self.parent.update_interface:
|
|
|
|
return
|
2007-08-06 03:52:16 +00:00
|
|
|
|
|
|
|
tab_page = self.parent_notebook.page_num(self.top_widget)
|
|
|
|
current_page = self.parent_notebook.get_current_page()
|
|
|
|
|
|
|
|
if tab_page == current_page:
|
|
|
|
unique_id = self.parent.get_selected_torrent()
|
2007-08-06 04:02:42 +00:00
|
|
|
if unique_id is None or \
|
|
|
|
unique_id in self.manager.removed_unique_ids:
|
2007-08-06 03:52:16 +00:00
|
|
|
#if no torrents added or more than one torrent selected
|
|
|
|
self.tab_peers.clear_peer_store()
|
|
|
|
self.tab_peers.set_unique_id(None)
|
|
|
|
return
|
|
|
|
if self.tab_peers.peer_unique_id != unique_id:
|
|
|
|
self.tab_peers.clear_peer_store()
|
|
|
|
self.tab_peers.set_unique_id(unique_id)
|
|
|
|
self.tab_peers.update_peer_store()
|
|
|
|
else:
|
|
|
|
self.tab_peers.update_peer_store()
|
2007-08-06 00:40:18 +00:00
|
|
|
|
2007-08-08 02:03:28 +00:00
|
|
|
def ok_clicked(self, src):
|
2007-08-06 00:40:18 +00:00
|
|
|
self.dialog.hide()
|
2007-08-07 17:04:56 +00:00
|
|
|
|
|
|
|
needs_store_update = False
|
|
|
|
if self.config.get("enable_flags") and not \
|
|
|
|
self.glade.get_widget("chk_flags").get_active():
|
|
|
|
needs_store_update = True
|
|
|
|
|
2007-08-06 04:37:11 +00:00
|
|
|
self.config.set("enable_flags",
|
|
|
|
self.glade.get_widget("chk_flags").get_active())
|
|
|
|
self.config.set("size_18",
|
|
|
|
self.glade.get_widget("radio_18").get_active())
|
2007-08-07 17:04:56 +00:00
|
|
|
self.config_updated()
|
|
|
|
|
|
|
|
if needs_store_update:
|
|
|
|
self.tab_peers.update_peer_store()
|
|
|
|
self.tab_peers.ip_column_queue_resize()
|
2007-08-06 00:40:18 +00:00
|
|
|
|
2007-08-08 02:03:28 +00:00
|
|
|
def cancel_clicked(self, src):
|
2007-08-06 00:40:18 +00:00
|
|
|
self.dialog.hide()
|