2006-12-08 19:06:49 +00:00
|
|
|
#!/usr/bin/env python
|
2006-11-28 22:28:37 +00:00
|
|
|
#
|
2006-12-08 18:10:47 +00:00
|
|
|
# delugegtk.py
|
|
|
|
#
|
|
|
|
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
|
2007-01-08 19:38:19 +00:00
|
|
|
#
|
|
|
|
# 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)
|
2006-12-08 18:10:47 +00:00
|
|
|
# any later version.
|
|
|
|
#
|
2007-01-08 19:38:19 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
2006-12-08 18:10:47 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-01-08 19:38:19 +00:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2006-12-08 18:10:47 +00:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-01-08 19:38:19 +00:00
|
|
|
# along with this program. If not, write to:
|
2006-12-08 18:10:47 +00:00
|
|
|
# The Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor
|
|
|
|
# Boston, MA 02110-1301, USA.
|
2006-11-28 22:28:37 +00:00
|
|
|
|
2007-03-05 22:30:54 +00:00
|
|
|
import sys, os, os.path, urllib
|
2007-03-26 01:03:00 +00:00
|
|
|
import deluge, dcommon, dgtk, ipc_manager, dialogs
|
2007-02-21 01:18:37 +00:00
|
|
|
import delugeplugins, pref
|
2006-11-28 22:28:37 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
2007-01-11 21:53:25 +00:00
|
|
|
import gtk, gtk.glade, gobject
|
2007-01-11 00:58:23 +00:00
|
|
|
import xdg, xdg.BaseDirectory
|
2007-03-05 22:30:54 +00:00
|
|
|
import gettext, locale
|
2007-02-21 01:58:35 +00:00
|
|
|
|
2007-03-26 01:19:08 +00:00
|
|
|
DEFAULT_PREFS = {
|
|
|
|
"auto_end_seeding" : False,
|
|
|
|
"close_to_tray" : False,
|
|
|
|
"default_download_path" : "",
|
|
|
|
"enable_system_tray" : True,
|
|
|
|
"enabled_plugins" : "",
|
|
|
|
"end_seed_ratio" : 0.0,
|
|
|
|
"max_download_rate" : -1.0,
|
|
|
|
"max_number_downloads" : -1.0,
|
|
|
|
"max_number_uploads" : -1.0,
|
|
|
|
"max_upload_rate" : -1.0,
|
|
|
|
"show_dl" : True,
|
|
|
|
"show_eta" : True,
|
|
|
|
"show_infopane" : True,
|
|
|
|
"show_peers" : True,
|
|
|
|
"show_seeders" : True,
|
|
|
|
"show_share" : True,
|
|
|
|
"show_size" : True,
|
|
|
|
"show_status" : True,
|
|
|
|
"show_toolbar" : True,
|
|
|
|
"show_ul" : True,
|
|
|
|
"tcp_port_range_lower" : 6881,
|
|
|
|
"tcp_port_range_upper" : 6889,
|
|
|
|
"use_compact_storage" : False,
|
|
|
|
"use_default_dir" : False,
|
|
|
|
"window_height" : 480,
|
|
|
|
"window_width" : 640,
|
|
|
|
"window_x_pos" : 0,
|
|
|
|
"window_y_pos" : 0,
|
|
|
|
}
|
|
|
|
|
2007-02-21 01:58:35 +00:00
|
|
|
class DelugeGTK:
|
|
|
|
def __init__(self):
|
2007-03-05 22:30:54 +00:00
|
|
|
APP = 'deluge'
|
|
|
|
DIR = os.path.join(dcommon.INSTALL_PREFIX, 'share', 'locale')
|
2007-03-06 01:40:46 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, '')
|
2007-03-05 23:38:14 +00:00
|
|
|
locale.bindtextdomain(APP, DIR)
|
|
|
|
locale.textdomain(APP)
|
2007-03-05 22:30:54 +00:00
|
|
|
gettext.bindtextdomain(APP, DIR)
|
|
|
|
gettext.textdomain(APP)
|
|
|
|
gettext.install(APP, DIR)
|
|
|
|
|
2007-01-12 20:07:55 +00:00
|
|
|
self.is_running = False
|
2007-02-22 20:51:22 +00:00
|
|
|
self.ipc_manager = ipc_manager.Manager(self)
|
2007-01-12 20:07:55 +00:00
|
|
|
self.torrent_file_queue = []
|
2007-02-07 23:49:31 +00:00
|
|
|
#Load up a config file:
|
2007-03-22 21:52:56 +00:00
|
|
|
self.conf_file = os.path.join(dcommon.CONFIG_DIR, 'deluge.conf')
|
2007-02-07 23:49:31 +00:00
|
|
|
if os.path.isdir(self.conf_file):
|
|
|
|
print 'Weird, the file I was trying to write to, %s, is an existing directory'%(self.conf_file)
|
|
|
|
sys.exit(0)
|
|
|
|
if not os.path.isfile(self.conf_file):
|
|
|
|
f = open(self.conf_file, mode='w')
|
|
|
|
f.flush()
|
|
|
|
f.close()
|
2007-02-15 21:54:55 +00:00
|
|
|
#Start the Deluge Manager:
|
2007-03-01 22:43:25 +00:00
|
|
|
p = "DE"
|
2007-03-05 22:38:22 +00:00
|
|
|
v = "0500"
|
2007-03-02 00:33:15 +00:00
|
|
|
s = "%s %s"%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION)
|
2007-03-22 18:04:15 +00:00
|
|
|
#try:
|
|
|
|
# self.manager = deluge.Manager(p, v, s, dcommon.CONFIG_DIR)
|
|
|
|
#except:
|
|
|
|
# # If something goes wrong while restoring the session, then load
|
|
|
|
# # a blank state rather than crash and exit
|
|
|
|
# self.manager = deluge.Manager(p, v, s, dcommon.CONFIG_DIR, blank_slate=True)
|
|
|
|
# self.something_screwed_up = True
|
|
|
|
self.manager = deluge.Manager(p, v, s, dcommon.CONFIG_DIR)
|
|
|
|
self.something_screwed_up = False
|
|
|
|
#else: self.something_screwed_up = False
|
2007-02-15 21:54:55 +00:00
|
|
|
self.plugins = delugeplugins.PluginManager(self.manager, self)
|
|
|
|
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
|
2007-03-22 21:52:56 +00:00
|
|
|
if os.path.isdir(os.path.join(dcommon.CONFIG_DIR , 'plugins')):
|
|
|
|
self.plugins.add_plugin_dir(os.path.join(dcommon.CONFIG_DIR, 'plugins'))
|
2007-02-15 21:54:55 +00:00
|
|
|
self.plugins.scan_for_plugins()
|
2007-03-26 01:19:08 +00:00
|
|
|
self.config = pref.Preferences(self.conf_file, DEFAULT_PREFS)
|
2007-01-11 00:58:23 +00:00
|
|
|
#Set up the interface:
|
2007-03-05 22:30:54 +00:00
|
|
|
self.wtree = gtk.glade.XML(dcommon.get_glade_file("delugegtk.glade"), domain=APP)
|
2006-11-28 22:28:37 +00:00
|
|
|
self.window = self.wtree.get_widget("main_window")
|
2007-01-12 20:07:55 +00:00
|
|
|
self.window.hide()
|
2006-12-22 23:24:42 +00:00
|
|
|
self.toolbar = self.wtree.get_widget("tb_middle")
|
2007-02-16 02:03:16 +00:00
|
|
|
self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL,[('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY)
|
2007-02-16 18:38:14 +00:00
|
|
|
self.window.connect("delete_event", self.close)
|
2007-02-16 02:03:16 +00:00
|
|
|
self.window.connect("drag_data_received", self.on_drag_data)
|
2007-03-07 01:04:14 +00:00
|
|
|
self.window.set_title(dcommon.PROGRAM_NAME)
|
2006-11-28 22:28:37 +00:00
|
|
|
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
|
2007-03-01 21:02:40 +00:00
|
|
|
self.notebook = self.wtree.get_widget("torrent_info")
|
2007-02-21 02:43:09 +00:00
|
|
|
self.statusbar = self.wtree.get_widget("statusbar")
|
2007-02-15 21:54:55 +00:00
|
|
|
|
2007-03-05 22:30:54 +00:00
|
|
|
|
|
|
|
|
2007-02-14 22:43:48 +00:00
|
|
|
|
2007-02-08 22:40:55 +00:00
|
|
|
## Construct the Interface
|
2007-03-01 19:30:06 +00:00
|
|
|
try:
|
|
|
|
self.build_tray_icon()
|
|
|
|
except AttributeError:
|
|
|
|
#python-pygtk is < 2.9
|
|
|
|
self.tray_icon = dgtk.StupidTray()
|
|
|
|
self.has_tray = False
|
|
|
|
else:
|
|
|
|
self.has_tray = True
|
|
|
|
|
2007-03-26 01:03:00 +00:00
|
|
|
self.preferences_dialog = dialogs.PreferencesDlg(self, self.config)
|
|
|
|
self.plugin_dialog = dialogs.PluginDlg(self, self.plugins)
|
2007-02-08 22:40:55 +00:00
|
|
|
self.build_torrent_table()
|
|
|
|
self.build_summary_tab()
|
|
|
|
self.build_file_tab()
|
|
|
|
self.build_peer_tab()
|
2006-12-08 19:02:22 +00:00
|
|
|
|
2007-02-08 22:40:55 +00:00
|
|
|
self.connect_signals()
|
2006-12-08 19:02:22 +00:00
|
|
|
|
2007-02-15 22:41:53 +00:00
|
|
|
try:
|
|
|
|
self.load_window_settings()
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2007-02-21 21:21:42 +00:00
|
|
|
enable_plugins = self.config.get('enabled_plugins', str, default="").split(':')
|
2007-02-15 21:54:55 +00:00
|
|
|
print enable_plugins
|
|
|
|
for plugin in enable_plugins:
|
|
|
|
try:
|
|
|
|
self.plugins.enable_plugin(plugin)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2007-02-16 04:30:49 +00:00
|
|
|
self.apply_prefs()
|
2007-02-27 23:49:29 +00:00
|
|
|
self.load_window_geometry()
|
2007-02-22 20:51:22 +00:00
|
|
|
|
|
|
|
def external_add_torrent(self, torrent_file):
|
|
|
|
print "Ding!"
|
|
|
|
print "Got torrent externally:", os.path.basename(torrent_file)
|
|
|
|
print "Here's the raw data:", torrent_file
|
|
|
|
print "\tNow, what to do with it?"
|
|
|
|
if self.is_running:
|
|
|
|
print "\t\tthe client seems to already be running, i'll try and add the torrent"
|
|
|
|
uid = self.interactive_add_torrent(torrent_file)
|
|
|
|
else:
|
|
|
|
print "\t\tthe client hasn't started yet, I'll queue the torrent"
|
|
|
|
self.torrent_file_queue.append(torrent_file)
|
2007-02-08 22:40:55 +00:00
|
|
|
|
|
|
|
def connect_signals(self):
|
2007-01-12 20:07:55 +00:00
|
|
|
self.wtree.signal_autoconnect({
|
2006-11-28 22:28:37 +00:00
|
|
|
## File Menu
|
2007-01-12 20:07:55 +00:00
|
|
|
"add_torrent": self.add_torrent_clicked,
|
2007-02-12 18:14:15 +00:00
|
|
|
"add_torrent_url": self.add_torrent_url_clicked,
|
2007-01-12 20:07:55 +00:00
|
|
|
"remove_torrent" : self.remove_torrent_clicked,
|
2007-02-16 18:38:14 +00:00
|
|
|
"menu_quit": self.quit,
|
2006-12-21 07:28:55 +00:00
|
|
|
## Edit Menu
|
2007-02-08 22:40:55 +00:00
|
|
|
"pref_clicked": self.show_pref_dialog,
|
|
|
|
"plugins_clicked": self.show_plugin_dialog,
|
2007-01-11 21:53:25 +00:00
|
|
|
## View Menu
|
2007-02-21 05:29:47 +00:00
|
|
|
"toolbar_toggle": self.toolbar_toggle,
|
2007-01-12 20:40:56 +00:00
|
|
|
"infopane_toggle": self.infopane_toggle,
|
2007-01-11 21:53:25 +00:00
|
|
|
"size_toggle": self.size_toggle,
|
|
|
|
"status_toggle": self.status_toggle,
|
|
|
|
"seeders_toggle": self.seeders_toggle,
|
|
|
|
"peers_toggle": self.peers_toggle,
|
|
|
|
"dl_toggle": self.dl_toggle,
|
|
|
|
"ul_toggle": self.ul_toggle,
|
|
|
|
"eta_toggle": self.eta_toggle,
|
|
|
|
"share_toggle": self.share_toggle,
|
2006-11-28 22:28:37 +00:00
|
|
|
## Help Menu
|
2007-02-08 22:40:55 +00:00
|
|
|
"show_about_dialog": self.show_about_dialog,
|
2007-01-12 20:07:55 +00:00
|
|
|
## Toolbar
|
2007-02-27 00:47:22 +00:00
|
|
|
"start_pause": self.start_pause,
|
2007-01-12 20:07:55 +00:00
|
|
|
"update_tracker": self.update_tracker,
|
2007-02-07 23:49:31 +00:00
|
|
|
"clear_finished": self.clear_finished,
|
|
|
|
"queue_up": self.q_torrent_up,
|
|
|
|
"queue_down": self.q_torrent_down,
|
2007-02-21 05:38:02 +00:00
|
|
|
"queue_bottom": self.q_to_bottom,
|
2007-01-12 20:07:55 +00:00
|
|
|
})
|
2007-02-08 22:40:55 +00:00
|
|
|
|
2007-02-14 18:08:33 +00:00
|
|
|
def build_tray_icon(self):
|
2007-02-27 20:47:46 +00:00
|
|
|
self.tray_icon = gtk.status_icon_new_from_file(dcommon.get_pixmap("deluge32.png"))
|
|
|
|
self.tray_menu = gtk.Menu()
|
|
|
|
|
|
|
|
item_show = gtk.MenuItem(_("Show / Hide Window"))
|
|
|
|
item_add = gtk.ImageMenuItem(_("Add Torrent"))
|
|
|
|
item_clear = gtk.ImageMenuItem(_("Clear Finished"))
|
|
|
|
item_pref = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
|
|
|
|
item_plug = gtk.ImageMenuItem(_("Plugins"))
|
|
|
|
item_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
|
|
|
|
|
|
|
|
item_add.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_MENU))
|
|
|
|
item_clear.set_image(gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU))
|
2007-03-01 19:37:38 +00:00
|
|
|
item_plug.set_image(gtk.image_new_from_stock(gtk.STOCK_DISCONNECT, gtk.ICON_SIZE_MENU))
|
2007-02-27 20:47:46 +00:00
|
|
|
|
|
|
|
item_show.connect("activate", self.force_show_hide)
|
|
|
|
item_add.connect("activate", self.add_torrent_clicked)
|
|
|
|
item_clear.connect("activate", self.clear_finished)
|
|
|
|
item_pref.connect("activate", self.show_pref_dialog)
|
|
|
|
item_plug.connect("activate", self.show_plugin_dialog)
|
|
|
|
item_quit.connect("activate", self.quit)
|
|
|
|
|
|
|
|
self.tray_menu.append(item_show)
|
|
|
|
self.tray_menu.append(item_add)
|
|
|
|
self.tray_menu.append(item_clear)
|
2007-03-01 19:37:38 +00:00
|
|
|
self.tray_menu.append(gtk.SeparatorMenuItem())
|
2007-02-27 20:47:46 +00:00
|
|
|
self.tray_menu.append(item_pref)
|
|
|
|
self.tray_menu.append(item_plug)
|
2007-02-27 21:52:52 +00:00
|
|
|
self.tray_menu.append(gtk.SeparatorMenuItem())
|
2007-02-27 20:47:46 +00:00
|
|
|
self.tray_menu.append(item_quit)
|
|
|
|
|
|
|
|
self.tray_menu.show_all()
|
|
|
|
|
|
|
|
self.tray_icon.connect("activate", self.tray_clicked)
|
|
|
|
self.tray_icon.connect("popup-menu", self.tray_popup)
|
|
|
|
|
|
|
|
def tray_popup(self, status_icon, button, activate_time):
|
|
|
|
self.tray_menu.popup(None, None, gtk.status_icon_position_menu,
|
|
|
|
button, activate_time, status_icon)
|
2007-02-14 18:08:33 +00:00
|
|
|
|
2007-02-27 20:47:46 +00:00
|
|
|
def tray_clicked(self, status_icon):
|
2007-02-14 18:08:33 +00:00
|
|
|
if self.window.get_property("visible"):
|
|
|
|
if self.window.is_active():
|
|
|
|
self.window.hide()
|
|
|
|
else:
|
|
|
|
self.window.present()
|
|
|
|
else:
|
|
|
|
self.window.show()
|
|
|
|
|
|
|
|
def force_show_hide(self, arg=None):
|
|
|
|
if self.window.get_property("visible"):
|
|
|
|
self.window.hide()
|
|
|
|
else:
|
|
|
|
self.window.show()
|
2007-02-08 22:40:55 +00:00
|
|
|
|
|
|
|
def build_torrent_table(self):
|
2006-12-08 18:10:47 +00:00
|
|
|
## Create the torrent listview
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_view = self.wtree.get_widget("torrent_view")
|
2007-03-05 22:30:54 +00:00
|
|
|
self.torrent_glade = gtk.glade.XML(dcommon.get_glade_file("torrent_menu.glade"), domain='deluge')
|
2007-02-27 00:28:18 +00:00
|
|
|
self.torrent_menu = self.torrent_glade.get_widget("torrent_menu")
|
|
|
|
self.torrent_glade.signal_autoconnect({"update_tracker": self.update_tracker,
|
|
|
|
"clear_finished": self.clear_finished,
|
|
|
|
"queue_up": self.q_torrent_up,
|
|
|
|
"queue_down": self.q_torrent_down,
|
|
|
|
"queue_bottom": self.q_to_bottom,
|
|
|
|
})
|
2006-12-22 23:24:42 +00:00
|
|
|
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
|
2007-03-01 19:12:06 +00:00
|
|
|
self.torrent_model = gtk.ListStore(int, int, str, str, float, str, int, int, int, int, int, int, str, float)
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_view.set_model(self.torrent_model)
|
|
|
|
self.torrent_view.set_rules_hint(True)
|
|
|
|
self.torrent_view.set_reorderable(True)
|
2007-02-28 01:51:52 +00:00
|
|
|
|
|
|
|
def size(column, cell, model, iter, data):
|
|
|
|
size = long(model.get_value(iter, data))
|
|
|
|
size_str = dcommon.fsize(size)
|
|
|
|
cell.set_property('text', size_str)
|
|
|
|
|
|
|
|
def rate(column, cell, model, iter, data):
|
|
|
|
rate = int(model.get_value(iter, data))
|
|
|
|
rate_str = dcommon.frate(rate)
|
|
|
|
cell.set_property('text', rate_str)
|
|
|
|
|
|
|
|
def peer(column, cell, model, iter, data):
|
|
|
|
c1, c2 = data
|
|
|
|
a = int(model.get_value(iter, c1))
|
|
|
|
b = int(model.get_value(iter, c2))
|
|
|
|
cell.set_property('text', '%d (%d)'%(a, b))
|
|
|
|
|
|
|
|
def time(column, cell, model, iter, data):
|
|
|
|
time = int(model.get_value(iter, data))
|
2007-03-06 20:38:02 +00:00
|
|
|
if time < 0:
|
|
|
|
time_str = _("Infinity")
|
|
|
|
elif time == 0:
|
|
|
|
time_str = "-"
|
|
|
|
else:
|
|
|
|
time_str = dcommon.ftime(time)
|
2007-02-28 01:51:52 +00:00
|
|
|
cell.set_property('text', time_str)
|
|
|
|
|
2007-03-06 21:17:41 +00:00
|
|
|
def ratio(column, cell, model, iter, data):
|
|
|
|
ratio = float(model.get_value(iter, data))
|
|
|
|
if ratio == -1:
|
|
|
|
ratio_str = _("Unknown")
|
|
|
|
else:
|
|
|
|
ratio_str = "%.2f"%ratio
|
|
|
|
cell.set_property('text', ratio_str)
|
|
|
|
|
2006-12-08 19:02:22 +00:00
|
|
|
|
2006-12-24 04:08:34 +00:00
|
|
|
## Initializes the columns for the torrent_view
|
2007-02-21 01:18:37 +00:00
|
|
|
self.queue_column = dgtk.add_text_column(self.torrent_view, "#", 1)
|
|
|
|
self.name_column = dgtk.add_text_column(self.torrent_view, _("Name"), 2)
|
2007-02-28 01:51:52 +00:00
|
|
|
self.size_column = dgtk.add_func_column(self.torrent_view, _("Size"), size, 3)
|
2007-02-21 01:18:37 +00:00
|
|
|
self.status_column = dgtk.add_progress_column(self.torrent_view, _("Status"), 4, 5)
|
2007-02-28 01:51:52 +00:00
|
|
|
self.seed_column = dgtk.add_func_column(self.torrent_view, _("Seeders"), peer, (6, 7))
|
|
|
|
self.peer_column = dgtk.add_func_column(self.torrent_view, _("Peers"), peer, (8, 9))
|
|
|
|
self.dl_column = dgtk.add_func_column(self.torrent_view, _("Download"), rate, 10)
|
|
|
|
self.ul_column = dgtk.add_func_column(self.torrent_view, _("Upload"), rate, 11)
|
|
|
|
self.eta_column = dgtk.add_func_column(self.torrent_view, _("Time Remaining"), time, 12)
|
2007-03-06 21:17:41 +00:00
|
|
|
self.share_column = dgtk.add_func_column(self.torrent_view, _("Ratio"), ratio, 13)
|
2006-11-28 22:28:37 +00:00
|
|
|
|
2006-12-24 04:08:34 +00:00
|
|
|
self.status_column.set_expand(True)
|
2007-03-01 19:12:06 +00:00
|
|
|
self.seed_column.set_sort_column_id(6)
|
|
|
|
self.peer_column.set_sort_column_id(8)
|
2007-02-17 18:39:59 +00:00
|
|
|
|
2007-03-01 22:04:22 +00:00
|
|
|
def long_sort(model, iter1, iter2, data):
|
|
|
|
value1 = long(model.get_value(iter1, data))
|
|
|
|
value2 = long(model.get_value(iter2, data))
|
|
|
|
if value1 < value2:
|
|
|
|
return -1
|
|
|
|
elif value1 > value2:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
self.torrent_model.set_sort_func(3, long_sort, 3)
|
|
|
|
self.torrent_model.set_sort_func(12, long_sort, 12)
|
2007-03-02 19:14:50 +00:00
|
|
|
try:
|
|
|
|
self.torrent_view.get_selection().set_select_function(self.torrent_clicked, full=True)
|
|
|
|
except TypeError:
|
|
|
|
self.torrent_view.get_selection().set_select_function(self.old_t_click)
|
2007-02-27 00:28:18 +00:00
|
|
|
self.torrent_view.connect("button-press-event", self.torrent_view_clicked)
|
2007-03-02 19:14:50 +00:00
|
|
|
|
|
|
|
def old_t_click(self, path):
|
|
|
|
return self.torrent_clicked(self.torrent_view.get_selection(), self.torrent_model, path, False)
|
2007-02-27 00:28:18 +00:00
|
|
|
|
2007-02-17 18:39:59 +00:00
|
|
|
def torrent_clicked(self, selection, model, path, is_selected):
|
|
|
|
if is_selected:
|
|
|
|
# Torrent is already selected, we don't need to do anything
|
|
|
|
return True
|
|
|
|
unique_id = model.get_value(model.get_iter(path), 0)
|
|
|
|
state = self.manager.get_torrent_state(unique_id)
|
|
|
|
# A new torrent has been selected, need to update parts of interface
|
|
|
|
self.text_summary_total_size.set_text(dcommon.fsize(state["total_size"]))
|
|
|
|
self.text_summary_pieces.set_text(str(state["pieces"]))
|
|
|
|
self.text_summary_tracker.set_text(str(state["tracker"]))
|
|
|
|
#self.text_summary_compact_allocation.set_text(str(state[""]))
|
|
|
|
# Now for the File tab
|
|
|
|
self.file_store.clear()
|
|
|
|
all_files = self.manager.get_torrent_file_info(unique_id)
|
2007-02-21 03:26:48 +00:00
|
|
|
file_filter = self.manager.get_file_filter(unique_id)
|
|
|
|
if file_filter is None:
|
2007-02-22 21:47:21 +00:00
|
|
|
file_filter = [False] * len(all_files)
|
2007-02-21 03:26:48 +00:00
|
|
|
assert(len(all_files) == len(file_filter))
|
|
|
|
i=0
|
2007-02-17 18:39:59 +00:00
|
|
|
for f in all_files:
|
2007-02-22 21:47:21 +00:00
|
|
|
self.file_store.append([not file_filter[i], f['path'], dcommon.fsize(f['size']),
|
2007-02-21 03:26:48 +00:00
|
|
|
f['offset'], '%.2f%%'%f['progress']])
|
|
|
|
i=i+1
|
2007-02-17 18:39:59 +00:00
|
|
|
|
|
|
|
return True
|
2007-02-27 00:28:18 +00:00
|
|
|
|
|
|
|
def torrent_view_clicked(self, widget, event):
|
|
|
|
print widget
|
|
|
|
print event
|
|
|
|
if event.button == 3:
|
|
|
|
x = int(event.x)
|
|
|
|
y = int(event.y)
|
|
|
|
data = self.torrent_view.get_path_at_pos(x, y)
|
|
|
|
if data is None:
|
|
|
|
return True
|
|
|
|
path, col, cellx, celly = data
|
|
|
|
self.torrent_view.grab_focus()
|
|
|
|
self.torrent_view.set_cursor(path, col, 0)
|
|
|
|
unique_id = self.get_selected_torrent()
|
|
|
|
|
|
|
|
self.torrent_menu.popup(None, None, None, event.button, event.time)
|
|
|
|
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2007-02-08 22:40:55 +00:00
|
|
|
|
2007-02-27 00:47:22 +00:00
|
|
|
def start_pause(self, widget):
|
|
|
|
print "Pause btn clicked"
|
|
|
|
unique_id = self.get_selected_torrent()
|
2007-03-01 22:11:35 +00:00
|
|
|
try:
|
|
|
|
self.manager.set_user_pause(unique_id, not self.manager.is_user_paused(unique_id))
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2007-02-27 00:47:22 +00:00
|
|
|
|
2007-02-08 22:40:55 +00:00
|
|
|
def build_summary_tab(self):
|
2007-01-11 23:15:22 +00:00
|
|
|
#Torrent Summary tab
|
2007-01-12 20:07:55 +00:00
|
|
|
# Look into glade's widget prefix function
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_title = self.wtree.get_widget("summary_title")
|
|
|
|
self.text_summary_total_size = self.wtree.get_widget("summary_total_size")
|
|
|
|
self.text_summary_pieces = self.wtree.get_widget("summary_pieces")
|
|
|
|
self.text_summary_total_downloaded = self.wtree.get_widget("summary_total_downloaded")
|
|
|
|
self.text_summary_total_uploaded = self.wtree.get_widget("summary_total_uploaded")
|
|
|
|
self.text_summary_download_rate = self.wtree.get_widget("summary_download_rate")
|
|
|
|
self.text_summary_upload_rate = self.wtree.get_widget("summary_upload_rate")
|
2007-02-06 21:21:09 +00:00
|
|
|
self.text_summary_seeders = self.wtree.get_widget("summary_seeders")
|
|
|
|
self.text_summary_peers = self.wtree.get_widget("summary_peers")
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_percentage_done = self.wtree.get_widget("summary_percentage_done")
|
|
|
|
self.text_summary_share_ratio = self.wtree.get_widget("summary_share_ratio")
|
|
|
|
self.text_summary_downloaded_this_session = self.wtree.get_widget("summary_downloaded_this_session")
|
2007-02-22 21:15:56 +00:00
|
|
|
self.text_summary_uploaded_this_session = self.wtree.get_widget("summary_uploaded_this_session")
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_tracker = self.wtree.get_widget("summary_tracker")
|
|
|
|
self.text_summary_tracker_response = self.wtree.get_widget("summary_tracker_response")
|
2007-02-06 21:21:09 +00:00
|
|
|
self.text_summary_tracker_status = self.wtree.get_widget("summary_tracker_status")
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_next_announce = self.wtree.get_widget("summary_next_announce")
|
|
|
|
self.text_summary_compact_allocation = self.wtree.get_widget("summary_compact_allocation")
|
|
|
|
self.text_summary_eta = self.wtree.get_widget("summary_eta")
|
2007-02-08 22:40:55 +00:00
|
|
|
|
|
|
|
def build_peer_tab(self):
|
|
|
|
self.peer_view = self.wtree.get_widget("peer_view")
|
|
|
|
self.peer_store = gtk.ListStore(str, str, str, str, str)
|
|
|
|
self.peer_view.set_model(self.peer_store)
|
|
|
|
|
2007-02-16 02:21:36 +00:00
|
|
|
self.peer_ip_column = dgtk.add_text_column(self.peer_view, _("IP Address"), 0)
|
|
|
|
self.peer_client_column = dgtk.add_text_column(self.peer_view, _("Client"), 1)
|
|
|
|
self.peer_complete_column = dgtk.add_text_column(self.peer_view, _("Percent Complete"), 2)
|
|
|
|
self.peer_download_column = dgtk.add_text_column(self.peer_view, _("Download Rate"), 3)
|
|
|
|
self.peer_upload_column = dgtk.add_text_column(self.peer_view, _("Upload Rate"), 4)
|
2007-02-08 22:40:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build_file_tab(self):
|
|
|
|
self.file_view = self.wtree.get_widget("file_view")
|
2007-02-21 03:26:48 +00:00
|
|
|
self.file_store = gtk.ListStore(bool, str, str, str, str)
|
2007-02-08 22:40:55 +00:00
|
|
|
self.file_view.set_model(self.file_store)
|
2007-01-11 23:15:22 +00:00
|
|
|
|
2007-02-21 03:26:48 +00:00
|
|
|
dgtk.add_toggle_column(self.file_view, _("Download"), 0, toggled_signal=self.file_toggled)
|
|
|
|
dgtk.add_text_column(self.file_view, _("Filename"), 1).set_expand(True)
|
|
|
|
dgtk.add_text_column(self.file_view, _("Size"), 2)
|
|
|
|
dgtk.add_text_column(self.file_view, _("Offset"), 3)
|
2007-03-26 01:03:00 +00:00
|
|
|
dgtk.add_text_column(self.file_view, _("Progress"), 4)
|
2007-02-21 03:26:48 +00:00
|
|
|
|
2007-02-19 21:19:23 +00:00
|
|
|
|
|
|
|
def file_toggled(self, renderer, path):
|
|
|
|
file_iter = self.file_store.get_iter_from_string(path)
|
|
|
|
value = not renderer.get_active()
|
2007-02-21 03:26:48 +00:00
|
|
|
self.file_store.set_value(file_iter, 0, value)
|
2007-02-19 21:19:23 +00:00
|
|
|
file_filter = []
|
|
|
|
itr = self.file_store.get_iter_first()
|
|
|
|
while itr is not None:
|
2007-02-22 21:15:56 +00:00
|
|
|
file_filter.append(not self.file_store.get_value(itr, 0))
|
2007-02-19 21:19:23 +00:00
|
|
|
itr = self.file_store.iter_next(itr)
|
2007-02-21 03:26:48 +00:00
|
|
|
print file_filter
|
2007-02-19 21:19:23 +00:00
|
|
|
self.manager.set_file_filter(self.get_selected_torrent(), file_filter)
|
|
|
|
|
2007-02-08 22:40:55 +00:00
|
|
|
def show_about_dialog(self, arg=None):
|
2007-03-26 01:03:00 +00:00
|
|
|
dialogs.show_about_dialog()
|
2007-02-08 22:40:55 +00:00
|
|
|
|
|
|
|
def show_pref_dialog(self, arg=None):
|
2007-03-26 01:03:00 +00:00
|
|
|
self.preferences_dialog.show()
|
2007-02-07 23:49:31 +00:00
|
|
|
self.apply_prefs()
|
2007-03-26 01:03:00 +00:00
|
|
|
self.config.save_to_file()
|
2007-01-12 20:07:55 +00:00
|
|
|
|
2007-02-08 22:40:55 +00:00
|
|
|
def show_plugin_dialog(self, arg=None):
|
2007-03-26 01:03:00 +00:00
|
|
|
self.plugin_dialog.show()
|
2007-02-08 22:40:55 +00:00
|
|
|
|
2007-02-14 22:43:48 +00:00
|
|
|
def apply_prefs(self):
|
2007-02-21 21:05:23 +00:00
|
|
|
ulrate = self.config.get("max_upload_rate", int, default=-1)
|
|
|
|
dlrate = self.config.get("max_download_rate", int, default=-1)
|
|
|
|
if not (ulrate == -1):
|
|
|
|
ulrate *= 1024
|
|
|
|
if not (dlrate == -1):
|
2007-03-01 23:08:28 +00:00
|
|
|
dlrate *= 1024
|
2007-02-21 21:21:42 +00:00
|
|
|
ports = [self.config.get("tcp_port_range_lower", int, default=6881),
|
|
|
|
self.config.get("tcp_port_range_upper", int, default=6889)]
|
2007-03-01 23:28:42 +00:00
|
|
|
if self.config.get("auto_end_seeding", bool, default=False):
|
|
|
|
auto_seed_ratio = self.config.get("end_seed_ratio", float, default=1.0)
|
|
|
|
else:
|
|
|
|
auto_seed_ratio = -1
|
2007-02-27 20:47:46 +00:00
|
|
|
self.tray_icon.set_visible(self.config.get("enable_system_tray", bool, default=True))
|
2007-02-21 21:21:42 +00:00
|
|
|
self.manager.set_pref("listen_on", ports)
|
2007-02-21 21:05:23 +00:00
|
|
|
self.manager.set_pref("max_upload_rate", ulrate)
|
|
|
|
self.manager.set_pref("max_download_rate", dlrate)
|
2007-02-21 21:21:42 +00:00
|
|
|
self.manager.set_pref("max_uploads", self.config.get("max_number_uploads", int, default=-1))
|
|
|
|
self.manager.set_pref("max_connections", self.config.get("max_number_downloads", int, default=-1))
|
2007-03-01 23:28:42 +00:00
|
|
|
self.manager.set_pref("auto_seed_ratio", auto_seed_ratio)
|
2007-03-06 20:57:49 +00:00
|
|
|
|
|
|
|
# '%s %d%%'%(deluge.STATE_MESSAGES[state['state']], int(state['progress'] * 100))
|
|
|
|
def get_message_from_state(self, torrent_state):
|
|
|
|
state = torrent_state['state']
|
|
|
|
is_paused = torrent_state['is_paused']
|
|
|
|
progress = torrent_state['progress']
|
|
|
|
progress = '%d%%'%int(progress * 100)
|
|
|
|
if is_paused:
|
|
|
|
message = 'Paused %s'%progress
|
|
|
|
else:
|
2007-03-08 06:49:53 +00:00
|
|
|
try:
|
|
|
|
message = deluge.STATE_MESSAGES[state]
|
|
|
|
if state in (1, 3, 4, 7):
|
|
|
|
message = '%s %s'%(message, progress)
|
|
|
|
except IndexError:
|
|
|
|
message = ''
|
2007-03-06 20:57:49 +00:00
|
|
|
return message
|
2007-02-08 22:40:55 +00:00
|
|
|
|
2007-02-14 22:43:48 +00:00
|
|
|
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
|
|
|
|
def get_list_from_unique_id(self, unique_id):
|
|
|
|
state = self.manager.get_torrent_state(unique_id)
|
2007-02-28 01:51:52 +00:00
|
|
|
|
2007-02-14 22:43:48 +00:00
|
|
|
queue = int(state['queue_pos']) + 1
|
|
|
|
name = state['name']
|
2007-02-28 01:51:52 +00:00
|
|
|
size = long(state['total_size'])
|
2007-02-14 22:43:48 +00:00
|
|
|
progress = float(state['progress'] * 100)
|
2007-03-06 20:57:49 +00:00
|
|
|
message = self.get_message_from_state(state)
|
2007-02-28 01:51:52 +00:00
|
|
|
seeds = int(state['num_seeds'])
|
|
|
|
seeds_t = int(state['total_seeds'])
|
|
|
|
peers = int(state['num_peers'])
|
|
|
|
peers_t = int(state['total_peers'])
|
|
|
|
dlrate = int(state['download_rate'])
|
|
|
|
ulrate = int(state['upload_rate'])
|
|
|
|
try:
|
2007-03-06 20:38:02 +00:00
|
|
|
eta = dcommon.get_eta(state["total_size"], state["total_done"], state["download_rate"])
|
2007-02-28 01:51:52 +00:00
|
|
|
except ZeroDivisionError:
|
|
|
|
eta = -1
|
|
|
|
share = float(self.calc_share_ratio(unique_id, state))
|
|
|
|
rlist = [int(unique_id), int(queue), str(name), long(size), float(progress), str(message),
|
|
|
|
int(seeds), int(seeds_t), int(peers), int(peers_t), int(dlrate), int(ulrate), int(eta), float(share)]
|
|
|
|
|
|
|
|
return rlist
|
2007-02-14 22:43:48 +00:00
|
|
|
|
|
|
|
|
2007-01-11 00:58:23 +00:00
|
|
|
## Start the timer that updates the interface
|
2007-01-12 20:07:55 +00:00
|
|
|
def start(self, hidden=False):
|
|
|
|
if not hidden:
|
|
|
|
self.window.show()
|
|
|
|
# go through torrent files to add
|
|
|
|
#dummy preferences values:
|
|
|
|
use_default_download_location = True
|
|
|
|
default_download_location = "."
|
|
|
|
for torrent_file in self.torrent_file_queue:
|
|
|
|
print "adding torrent", torrent_file
|
|
|
|
try:
|
2007-02-16 18:57:58 +00:00
|
|
|
self.interactive_add_torrent(torrent_file, append=False)
|
2007-01-12 20:07:55 +00:00
|
|
|
except deluge.DelugeError:
|
|
|
|
print "duplicate torrent found, ignoring", torrent_file
|
|
|
|
## add torrents in manager to interface
|
2007-02-28 01:51:52 +00:00
|
|
|
# self.torrent_model.append([0, 1, "Hello, World", 2048, 50.0, "Hi", 1, 2, 1, 2, 2048, 2048, 120, 1.0])
|
2007-01-12 20:07:55 +00:00
|
|
|
for uid in self.manager.get_unique_IDs():
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_model.append(self.get_list_from_unique_id(uid))
|
2007-01-11 00:58:23 +00:00
|
|
|
gobject.timeout_add(1000, self.update)
|
2007-01-12 20:07:55 +00:00
|
|
|
try:
|
|
|
|
self.is_running = True
|
|
|
|
gtk.main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.manager.quit()
|
2007-02-21 02:43:09 +00:00
|
|
|
|
2007-01-11 00:58:23 +00:00
|
|
|
## Call via a timer to update the interface
|
|
|
|
def update(self):
|
2007-01-11 21:53:25 +00:00
|
|
|
# Make sure that the interface still exists
|
|
|
|
try:
|
2007-01-11 05:01:11 +00:00
|
|
|
tab = self.wtree.get_widget("torrent_info").get_current_page()
|
2007-01-11 21:53:25 +00:00
|
|
|
except AttributeError:
|
|
|
|
return False
|
2007-02-21 02:43:09 +00:00
|
|
|
|
2007-03-01 22:43:25 +00:00
|
|
|
if self.something_screwed_up:
|
2007-03-26 01:03:00 +00:00
|
|
|
dialogs.show_popup_warning(self.window,
|
2007-03-06 20:29:40 +00:00
|
|
|
_("For some reason, the previous state could not be loaded, so a blank state has been loaded for you."))
|
2007-03-26 01:03:00 +00:00
|
|
|
restore_torrents = dialogs.show_popup_question(self.window,
|
2007-03-06 20:29:40 +00:00
|
|
|
_("Would you like to attempt to reload the previous session's downloads?"))
|
|
|
|
if restore_torrents:
|
2007-03-22 21:52:56 +00:00
|
|
|
torrent_subdir = os.path.join(self.manager.base_dir, deluge.TORRENTS_SUBDIR)
|
2007-03-06 20:29:40 +00:00
|
|
|
for torrent in os.listdir(torrent_subdir):
|
|
|
|
if torrent.endswith('.torrent'):
|
2007-03-08 22:49:03 +00:00
|
|
|
self.interactive_add_torrent(torrent)
|
2007-03-01 22:43:25 +00:00
|
|
|
self.something_screwed_up = False
|
|
|
|
|
2007-02-21 02:43:09 +00:00
|
|
|
# Update Statusbar and Tray Tips
|
|
|
|
core_state = self.manager.get_state()
|
|
|
|
connections = core_state['num_peers']
|
|
|
|
dlrate = dcommon.frate(core_state['download_rate'])
|
|
|
|
ulrate = dcommon.frate(core_state['upload_rate'])
|
|
|
|
|
|
|
|
self.statusbar_temp_msg = '%s: %s %s: %s %s: %s'%(
|
|
|
|
_('Connections'), connections, _('Download'),
|
|
|
|
dlrate, _('Upload'), ulrate)
|
|
|
|
|
|
|
|
if 'DHT_nodes' in core_state.keys():
|
|
|
|
dht_peers = core_state['DHT_nodes']
|
|
|
|
if dht_peers == -1:
|
|
|
|
dht_peers = '?'
|
|
|
|
else:
|
|
|
|
dht_peers = str(dht_peers)
|
|
|
|
self.statusbar_temp_msg = self.statusbar_temp_msg + ' [DHT: %s]'%(dht_peers)
|
|
|
|
|
2007-02-21 02:56:55 +00:00
|
|
|
msg = _("Deluge Bittorrent Client") + "\n" + \
|
|
|
|
_("Connections") + ": " + str(connections) + "\n" + _("Download") + ": " + \
|
|
|
|
dlrate + "\n" + _("Upload") + ": " + ulrate
|
2007-02-21 02:43:09 +00:00
|
|
|
|
2007-02-27 20:47:46 +00:00
|
|
|
self.tray_icon.set_tooltip(msg)
|
2007-02-21 02:43:09 +00:00
|
|
|
|
|
|
|
#Update any active plugins
|
2007-02-14 22:43:48 +00:00
|
|
|
self.plugins.update_active_plugins()
|
2007-02-21 02:43:09 +00:00
|
|
|
|
|
|
|
# Put the generated message into the statusbar
|
|
|
|
# This gives plugins a chance to write to the
|
|
|
|
# statusbar if they want
|
|
|
|
self.statusbar.pop(1)
|
|
|
|
self.statusbar.push(1, self.statusbar_temp_msg)
|
2007-02-14 22:43:48 +00:00
|
|
|
|
2007-01-11 23:15:22 +00:00
|
|
|
# If no torrent is selected, select the first torrent:
|
2007-02-21 01:18:37 +00:00
|
|
|
(temp, selection) = self.torrent_view.get_selection().get_selected()
|
2007-01-11 23:15:22 +00:00
|
|
|
if selection is None:
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_view.get_selection().select_path("0")
|
2007-01-12 20:40:56 +00:00
|
|
|
#Torrent List
|
2007-02-21 01:18:37 +00:00
|
|
|
itr = self.torrent_model.get_iter_first()
|
2007-01-12 20:40:56 +00:00
|
|
|
if itr is None:
|
|
|
|
return True
|
2007-02-14 22:43:48 +00:00
|
|
|
|
2007-01-12 20:40:56 +00:00
|
|
|
while itr is not None:
|
2007-02-21 01:18:37 +00:00
|
|
|
uid = self.torrent_model.get_value(itr, 0)
|
2007-01-12 20:40:56 +00:00
|
|
|
try:
|
|
|
|
state = self.manager.get_torrent_state(uid)
|
|
|
|
tlist = self.get_list_from_unique_id(uid)
|
2007-02-28 01:51:52 +00:00
|
|
|
for i in range(len(tlist)):
|
|
|
|
try:
|
|
|
|
self.torrent_model.set_value(itr, i, tlist[i])
|
|
|
|
except:
|
2007-03-01 19:12:06 +00:00
|
|
|
print "ERR", i, type(tlist[i]), tlist[i]
|
2007-02-21 01:18:37 +00:00
|
|
|
itr = self.torrent_model.iter_next(itr)
|
2007-01-12 20:40:56 +00:00
|
|
|
except deluge.InvalidUniqueIDError:
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_model.remove(itr)
|
|
|
|
if not self.torrent_model.iter_is_valid(itr):
|
2007-01-12 20:40:56 +00:00
|
|
|
itr = None
|
2007-02-27 19:38:55 +00:00
|
|
|
try:
|
|
|
|
if self.manager.is_user_paused(self.get_selected_torrent()):
|
|
|
|
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PLAY)
|
|
|
|
else:
|
|
|
|
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PAUSE)
|
|
|
|
except KeyError:
|
2007-03-02 06:40:14 +00:00
|
|
|
pass
|
2007-02-12 20:41:06 +00:00
|
|
|
|
2007-03-05 18:49:13 +00:00
|
|
|
try:
|
|
|
|
state = self.manager.get_torrent_state(self.get_selected_torrent())
|
|
|
|
except deluge.InvalidUniqueIDError:
|
|
|
|
return True
|
2007-02-14 22:43:48 +00:00
|
|
|
|
|
|
|
|
2007-02-09 21:41:58 +00:00
|
|
|
if tab == 0: #Details Pane
|
2007-03-23 00:27:21 +00:00
|
|
|
self.wtree.get_widget("summary_name").set_text(state['name'])
|
2007-02-06 21:21:09 +00:00
|
|
|
self.text_summary_total_size.set_text(dcommon.fsize(state["total_size"]))
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_pieces.set_text(str(state["pieces"]))
|
2007-02-22 21:15:56 +00:00
|
|
|
self.text_summary_total_downloaded.set_text(dcommon.fsize(state["total_done"]))
|
|
|
|
#self.text_summary_total_uploaded.set_text()
|
2007-02-06 21:21:09 +00:00
|
|
|
self.text_summary_download_rate.set_text(dcommon.frate(state["download_rate"]))
|
|
|
|
self.text_summary_upload_rate.set_text(dcommon.frate(state["upload_rate"]))
|
|
|
|
self.text_summary_seeders.set_text(dcommon.fseed(state))
|
|
|
|
self.text_summary_peers.set_text(dcommon.fpeer(state))
|
2007-02-12 23:12:08 +00:00
|
|
|
self.wtree.get_widget("progressbar").set_fraction(float(state['progress']))
|
2007-03-23 00:27:21 +00:00
|
|
|
self.wtree.get_widget("progressbar").set_text(dcommon.fpcnt(state["progress"]))
|
2007-02-28 01:51:52 +00:00
|
|
|
self.text_summary_share_ratio.set_text(str(self.calc_share_ratio(self.get_selected_torrent(), state)))
|
2007-02-22 21:15:56 +00:00
|
|
|
self.text_summary_downloaded_this_session.set_text(dcommon.fsize(state["total_download"]))
|
|
|
|
self.text_summary_uploaded_this_session.set_text(dcommon.fsize(state["total_upload"]))
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_tracker.set_text(str(state["tracker"]))
|
|
|
|
#self.text_summary_tracker_response.set_text(str(state[""]))
|
2007-02-06 21:21:09 +00:00
|
|
|
self.text_summary_tracker_status.set_text(str(state["tracker_ok"]))
|
2007-01-11 23:15:22 +00:00
|
|
|
self.text_summary_next_announce.set_text(str(state["next_announce"]))
|
|
|
|
#self.text_summary_compact_allocation.set_text(str(state[""]))
|
2007-02-12 19:36:16 +00:00
|
|
|
self.text_summary_eta.set_text(dcommon.estimate_eta(state))
|
2007-01-12 20:40:56 +00:00
|
|
|
elif tab == 1: #Peers List
|
2007-02-19 20:39:23 +00:00
|
|
|
def biographer(model, path, iter, dictionary):
|
|
|
|
assert(model.get_value(iter, 0) not in dictionary.keys())
|
|
|
|
dictionary[model.get_value(iter, 0)] = model.get_string_from_iter(iter)
|
|
|
|
|
|
|
|
class remover_data:
|
|
|
|
def __init__(self, new_ips):
|
|
|
|
self.new_ips = new_ips
|
|
|
|
self.removed = False
|
|
|
|
|
|
|
|
def remover(model, path, iter, data):
|
|
|
|
if model.get_value(iter, 0) not in data.new_ips:
|
|
|
|
model.remove(iter)
|
|
|
|
data.removed = True
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2007-02-12 20:41:06 +00:00
|
|
|
unique_id = self.get_selected_torrent()
|
|
|
|
|
2007-03-02 06:40:14 +00:00
|
|
|
new_peer_info = self.manager.get_torrent_peer_info(unique_id)
|
2007-02-12 20:41:06 +00:00
|
|
|
|
|
|
|
new_ips = {}
|
|
|
|
|
|
|
|
for index in range(len(new_peer_info)):
|
|
|
|
if not new_peer_info[index]['client'] == "":
|
|
|
|
assert(new_peer_info[index]['ip'] not in new_ips.keys())
|
|
|
|
new_ips[new_peer_info[index]['ip']] = index
|
2007-02-19 20:39:23 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
data = remover_data(new_ips.keys())
|
|
|
|
self.peer_store.foreach(remover, data)
|
|
|
|
if not data.removed:
|
|
|
|
break
|
|
|
|
|
|
|
|
curr_ips = {}
|
|
|
|
|
|
|
|
self.peer_store.foreach(biographer, curr_ips)
|
|
|
|
|
|
|
|
assert(self.peer_store.iter_n_children(None) == len(curr_ips.keys()))
|
|
|
|
|
|
|
|
for peer in new_peer_info:
|
|
|
|
if peer['ip'] in curr_ips.keys():
|
|
|
|
self.peer_store.set(self.peer_store.get_iter_from_string(curr_ips[peer['ip']]),
|
|
|
|
1, unicode(peer['client'], 'Latin-1'),
|
2007-02-22 00:28:38 +00:00
|
|
|
2, '%.2f%%'%peer["peer_has"],
|
|
|
|
3, dcommon.frate(peer["download_speed"]),
|
|
|
|
4, dcommon.frate(peer["upload_speed"]))
|
2007-02-19 20:39:23 +00:00
|
|
|
for peer in new_peer_info:
|
|
|
|
if peer['ip'] not in curr_ips.keys() and peer['client'] is not "":
|
2007-02-22 00:28:38 +00:00
|
|
|
self.peer_store.append([peer["ip"],
|
|
|
|
unicode(peer["client"], 'Latin-1'),
|
|
|
|
'%.2f%%'%peer["peer_has"],
|
|
|
|
dcommon.frate(peer["download_speed"]),
|
|
|
|
dcommon.frate(peer["upload_speed"])])
|
2007-03-02 06:40:14 +00:00
|
|
|
#print new_ips
|
|
|
|
#print curr_ips
|
|
|
|
#print new_peer_info
|
|
|
|
del new_peer_info
|
|
|
|
del new_ips
|
|
|
|
del curr_ips
|
|
|
|
|
|
|
|
|
2007-02-12 20:41:06 +00:00
|
|
|
|
2007-01-12 20:40:56 +00:00
|
|
|
elif tab == 2: #File List
|
2007-01-11 21:53:25 +00:00
|
|
|
pass
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2007-01-11 00:58:23 +00:00
|
|
|
return True
|
|
|
|
|
2007-02-07 23:49:31 +00:00
|
|
|
def calc_share_ratio(self, unique_id, torrent_state):
|
2007-02-28 01:51:52 +00:00
|
|
|
r = float(self.manager.calc_ratio(unique_id, torrent_state))
|
|
|
|
return r
|
2007-01-11 23:15:22 +00:00
|
|
|
|
2007-01-11 05:01:11 +00:00
|
|
|
def get_selected_torrent(self):
|
2007-02-07 23:49:31 +00:00
|
|
|
try:
|
2007-02-21 01:18:37 +00:00
|
|
|
return self.torrent_model.get_value(self.torrent_view.get_selection().get_selected()[1], 0)
|
2007-02-07 23:49:31 +00:00
|
|
|
except TypeError:
|
|
|
|
return None
|
2007-02-16 02:03:16 +00:00
|
|
|
|
|
|
|
def on_drag_data(self, widget, drag_context, x, y, selection_data, info, timestamp):
|
|
|
|
uri_split = selection_data.data.strip().split()
|
|
|
|
for uri in uri_split:
|
|
|
|
path = urllib.url2pathname(uri).strip('\r\n\x00')
|
|
|
|
if path.startswith('file:\\\\\\'):
|
|
|
|
path = path[8:]
|
|
|
|
elif path.startswith('file://'):
|
|
|
|
path = path[7:]
|
|
|
|
elif path.startswith('file:'):
|
|
|
|
path = path[5:]
|
|
|
|
if path.endswith('.torrent'):
|
|
|
|
self.interactive_add_torrent(path)
|
|
|
|
|
2007-02-07 23:49:31 +00:00
|
|
|
|
2006-12-22 23:24:42 +00:00
|
|
|
|
2007-02-16 18:57:58 +00:00
|
|
|
def interactive_add_torrent(self, torrent, append=True):
|
2007-02-21 21:21:42 +00:00
|
|
|
if self.config.get('use_default_dir', bool, default=False):
|
|
|
|
path = self.config.get('default_download_path', default=os.path.expandvars('$HOME'))
|
2007-02-12 19:09:56 +00:00
|
|
|
else:
|
2007-03-26 01:03:00 +00:00
|
|
|
path = dialogs.show_directory_chooser_dialog(self.window)
|
2007-02-12 19:09:56 +00:00
|
|
|
if path is None:
|
|
|
|
return
|
2007-03-23 01:28:53 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage', bool, default=False))
|
|
|
|
except deluge.InsufficientFreeSpaceError, err:
|
|
|
|
nice_need = dcommon.fsize(err.needed_space)
|
|
|
|
nice_free = dcommon.fsize(err.free_space)
|
|
|
|
|
2007-03-08 22:14:40 +00:00
|
|
|
|
2007-02-16 18:57:58 +00:00
|
|
|
if append:
|
2007-02-21 01:18:37 +00:00
|
|
|
self.torrent_model.append(self.get_list_from_unique_id(unique_id))
|
2007-02-12 19:09:56 +00:00
|
|
|
|
|
|
|
|
2006-11-28 22:28:37 +00:00
|
|
|
|
2007-01-12 20:07:55 +00:00
|
|
|
def add_torrent_clicked(self, obj=None):
|
2007-03-26 01:03:00 +00:00
|
|
|
torrent = dialogs.show_file_open_dialog()
|
2007-01-11 00:58:23 +00:00
|
|
|
if torrent is not None:
|
2007-02-12 19:09:56 +00:00
|
|
|
self.interactive_add_torrent(torrent)
|
2007-01-11 05:01:11 +00:00
|
|
|
|
2007-02-12 18:14:15 +00:00
|
|
|
def add_torrent_url_clicked(self, obj=None):
|
2007-02-16 02:21:36 +00:00
|
|
|
dlg = gtk.Dialog(title=_("Add torrent from URL"), parent=self.window,
|
2007-02-12 19:09:56 +00:00
|
|
|
buttons=(gtk.STOCK_CANCEL, 0, gtk.STOCK_OK, 1))
|
|
|
|
dlg.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
|
|
|
|
|
2007-02-16 02:21:36 +00:00
|
|
|
label = gtk.Label(_("Enter the URL of the .torrent to download"))
|
2007-02-12 19:09:56 +00:00
|
|
|
entry = gtk.Entry()
|
|
|
|
dlg.vbox.pack_start(label)
|
|
|
|
dlg.vbox.pack_start(entry)
|
|
|
|
dlg.show_all()
|
|
|
|
result = dlg.run()
|
|
|
|
url = entry.get_text()
|
|
|
|
dlg.destroy()
|
|
|
|
|
|
|
|
if result == 1:
|
|
|
|
opener = urllib.URLopener()
|
|
|
|
filename, headers = opener.retrieve(url)
|
|
|
|
if filename.endswith(".torrent") or headers["content-type"]=="application/x=bittorrent":
|
|
|
|
self.interactive_add_torrent(filename)
|
|
|
|
|
2007-02-12 18:14:15 +00:00
|
|
|
|
2007-01-12 20:07:55 +00:00
|
|
|
def remove_torrent_clicked(self, obj=None):
|
2007-02-07 23:49:31 +00:00
|
|
|
torrent = self.get_selected_torrent()
|
|
|
|
if torrent is not None:
|
2007-03-05 22:30:54 +00:00
|
|
|
glade = gtk.glade.XML(dcommon.get_glade_file("dgtkpopups.glade"), domain='deluge')
|
2007-02-12 18:14:15 +00:00
|
|
|
asker = glade.get_widget("remove_torrent_dlg")
|
2007-02-21 01:37:21 +00:00
|
|
|
|
|
|
|
asker.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
|
2007-02-12 18:14:15 +00:00
|
|
|
|
|
|
|
warning = glade.get_widget("warning")
|
|
|
|
warning.set_text(" ")
|
|
|
|
|
|
|
|
data_also = glade.get_widget("data_also")
|
|
|
|
data_also.connect("toggled", self.remove_toggle_warning, warning)
|
|
|
|
|
|
|
|
response = asker.run()
|
|
|
|
asker.destroy()
|
|
|
|
if response == 1:
|
|
|
|
self.manager.remove_torrent(torrent, data_also.get_active())
|
2007-02-23 05:10:46 +00:00
|
|
|
self.clear_details_pane()
|
|
|
|
|
|
|
|
def clear_details_pane(self):
|
|
|
|
self.wtree.get_widget("progressbar").set_text("")
|
|
|
|
self.text_summary_total_size.set_text("")
|
|
|
|
self.text_summary_pieces.set_text("")
|
|
|
|
self.text_summary_total_downloaded.set_text("")
|
|
|
|
self.text_summary_total_uploaded.set_text("")
|
|
|
|
self.text_summary_download_rate.set_text("")
|
|
|
|
self.text_summary_upload_rate.set_text("")
|
|
|
|
self.text_summary_seeders.set_text("")
|
|
|
|
self.text_summary_peers.set_text("")
|
|
|
|
self.wtree.get_widget("progressbar").set_fraction(0.0)
|
|
|
|
self.text_summary_share_ratio.set_text("")
|
|
|
|
self.text_summary_downloaded_this_session.set_text("")
|
|
|
|
self.text_summary_uploaded_this_session.set_text("")
|
|
|
|
self.text_summary_tracker.set_text("")
|
|
|
|
self.text_summary_tracker_response.set_text("")
|
|
|
|
self.text_summary_tracker_status.set_text("")
|
|
|
|
self.text_summary_next_announce.set_text("")
|
|
|
|
self.text_summary_compact_allocation.set_text("")
|
|
|
|
self.text_summary_eta.set_text("")
|
|
|
|
self.peer_store.clear()
|
|
|
|
self.file_store.clear()
|
2007-02-12 18:14:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def remove_toggle_warning(self, args, warning):
|
|
|
|
if not args.get_active():
|
|
|
|
warning.set_text(" ")
|
|
|
|
else:
|
2007-02-16 02:21:36 +00:00
|
|
|
warning.set_markup("<i>" + _("Warning - all downloaded files for this torrent will be deleted!") + "</i>")
|
2007-02-12 18:14:15 +00:00
|
|
|
return False
|
2007-02-07 23:49:31 +00:00
|
|
|
|
2007-01-12 20:07:55 +00:00
|
|
|
def update_tracker(self, obj=None):
|
2007-02-07 23:49:31 +00:00
|
|
|
torrent = self.get_selected_torrent()
|
|
|
|
if torrent is not None:
|
|
|
|
self.manager.update_tracker(torrent)
|
|
|
|
|
|
|
|
def clear_finished(self, obj=None):
|
2007-02-27 20:47:46 +00:00
|
|
|
print "Clearing Completed Torrents"
|
2007-02-07 23:49:31 +00:00
|
|
|
self.manager.clear_completed()
|
|
|
|
|
|
|
|
def q_torrent_up(self, obj=None):
|
|
|
|
torrent = self.get_selected_torrent()
|
|
|
|
if torrent is not None:
|
|
|
|
self.manager.queue_up(torrent)
|
2007-02-23 05:10:46 +00:00
|
|
|
|
2007-02-07 23:49:31 +00:00
|
|
|
def q_torrent_down(self, obj=None):
|
|
|
|
torrent = self.get_selected_torrent()
|
|
|
|
if torrent is not None:
|
2007-02-23 03:46:01 +00:00
|
|
|
self.manager.queue_down(torrent)
|
2007-02-21 05:38:02 +00:00
|
|
|
|
|
|
|
def q_to_bottom(self, widget):
|
|
|
|
torrent = self.get_selected_torrent()
|
|
|
|
if torrent is not None:
|
|
|
|
self.manager.queue_bottom(torrent)
|
2007-02-23 05:10:46 +00:00
|
|
|
|
2007-02-21 05:29:47 +00:00
|
|
|
def toolbar_toggle(self, widget):
|
|
|
|
if widget.get_active():
|
|
|
|
self.wtree.get_widget("tb_left").show()
|
|
|
|
self.wtree.get_widget("tb_middle").show()
|
|
|
|
self.wtree.get_widget("tb_right").show()
|
|
|
|
else:
|
|
|
|
self.wtree.get_widget("tb_left").hide()
|
|
|
|
self.wtree.get_widget("tb_middle").hide()
|
|
|
|
self.wtree.get_widget("tb_right").hide()
|
|
|
|
|
2007-01-12 20:40:56 +00:00
|
|
|
def infopane_toggle(self, widget):
|
|
|
|
if widget.get_active():
|
|
|
|
self.wtree.get_widget("torrent_info").show()
|
|
|
|
else:
|
2007-02-28 06:20:12 +00:00
|
|
|
self.wtree.get_widget("torrent_info").hide()
|
2007-01-11 21:53:25 +00:00
|
|
|
|
|
|
|
def size_toggle(self, obj):
|
|
|
|
self.size_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
|
|
|
|
def status_toggle(self, obj):
|
|
|
|
self.status_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def seeders_toggle(self, obj):
|
|
|
|
self.seed_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def peers_toggle(self, obj):
|
|
|
|
self.peer_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def dl_toggle(self, obj):
|
|
|
|
self.dl_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def ul_toggle(self, obj):
|
|
|
|
self.ul_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def eta_toggle(self, obj):
|
|
|
|
self.eta_column.set_visible(obj.get_active())
|
|
|
|
|
|
|
|
def share_toggle(self, obj):
|
|
|
|
self.share_column.set_visible(obj.get_active())
|
|
|
|
|
2007-02-15 22:41:53 +00:00
|
|
|
def load_window_settings(self):
|
2007-02-21 21:21:42 +00:00
|
|
|
self.wtree.get_widget("chk_infopane").set_active(self.config.get("show_infopane", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_toolbar").set_active(self.config.get("show_toolbar", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_size").set_active(self.config.get("show_size", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_status").set_active(self.config.get("show_status", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_seed").set_active(self.config.get("show_seeders", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_peer").set_active(self.config.get("show_peers", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_download").set_active(self.config.get("show_dl", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_upload").set_active(self.config.get("show_ul", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_eta").set_active(self.config.get("show_eta", bool, default=True))
|
|
|
|
self.wtree.get_widget("chk_ratio").set_active(self.config.get("show_share", bool, default=True))
|
2007-02-15 22:41:53 +00:00
|
|
|
|
|
|
|
def save_window_settings(self):
|
2007-02-21 01:18:37 +00:00
|
|
|
self.config.set("show_infopane", self.wtree.get_widget("chk_infopane").get_active())
|
2007-02-21 05:29:47 +00:00
|
|
|
self.config.set("show_toolbar", self.wtree.get_widget("chk_toolbar").get_active())
|
2007-02-21 01:18:37 +00:00
|
|
|
self.config.set("show_size", self.size_column.get_visible())
|
|
|
|
self.config.set("show_status", self.status_column.get_visible())
|
|
|
|
self.config.set("show_seeders", self.seed_column.get_visible())
|
|
|
|
self.config.set("show_peers", self.peer_column.get_visible())
|
|
|
|
self.config.set("show_dl", self.dl_column.get_visible())
|
|
|
|
self.config.set("show_ul", self.ul_column.get_visible())
|
|
|
|
self.config.set("show_eta", self.eta_column.get_visible())
|
|
|
|
self.config.set("show_share", self.share_column.get_visible())
|
2007-02-27 23:49:29 +00:00
|
|
|
|
|
|
|
def save_window_geometry(self):
|
|
|
|
x, y = self.window.get_position()
|
|
|
|
w, h = self.window.get_size()
|
|
|
|
self.config.set('window_x_pos', x)
|
|
|
|
self.config.set('window_y_pos', y)
|
|
|
|
self.config.set('window_width', w)
|
|
|
|
self.config.set('window_height',h)
|
|
|
|
|
|
|
|
def load_window_geometry(self):
|
|
|
|
x = self.config.get('window_x_pos', int, default=0)
|
|
|
|
y = self.config.get('window_y_pos', int, default=0)
|
|
|
|
w = self.config.get('window_width', int, default=640)
|
|
|
|
h = self.config.get('window_height',int, default=480)
|
|
|
|
self.window.move(x, y)
|
|
|
|
self.window.resize(w, h)
|
|
|
|
|
2007-02-16 18:38:14 +00:00
|
|
|
|
|
|
|
def close(self, widget, event):
|
2007-03-01 19:30:06 +00:00
|
|
|
if self.config.get("close_to_tray", bool, default=False) and self.config.get("enable_system_tray", bool, default=True) and self.has_tray:
|
2007-02-27 23:49:29 +00:00
|
|
|
self.save_window_geometry()
|
2007-02-16 18:38:14 +00:00
|
|
|
self.window.hide()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
self.quit()
|
|
|
|
|
|
|
|
def quit(self, widget=None):
|
2007-02-27 23:49:29 +00:00
|
|
|
self.save_window_geometry()
|
2007-02-22 21:15:56 +00:00
|
|
|
self.window.hide()
|
2007-02-16 18:38:14 +00:00
|
|
|
self.shutdown()
|
2007-02-15 21:30:17 +00:00
|
|
|
|
|
|
|
def shutdown(self):
|
2007-02-17 18:39:59 +00:00
|
|
|
enabled_plugins = ':'.join(self.plugins.get_enabled_plugins())
|
2007-02-21 01:18:37 +00:00
|
|
|
self.config.set('enabled_plugins', enabled_plugins)
|
2007-02-15 22:41:53 +00:00
|
|
|
self.save_window_settings()
|
2007-02-21 01:18:37 +00:00
|
|
|
self.config.save_to_file(self.conf_file)
|
2007-02-15 21:30:17 +00:00
|
|
|
self.plugins.shutdown_all_plugins()
|
2007-01-11 00:58:23 +00:00
|
|
|
self.manager.quit()
|
2007-01-11 21:53:25 +00:00
|
|
|
gtk.main_quit()
|
2006-12-22 23:24:42 +00:00
|
|
|
|
2007-01-11 00:58:23 +00:00
|
|
|
|
2006-12-04 23:59:45 +00:00
|
|
|
|
|
|
|
|
2006-12-08 20:26:35 +00:00
|
|
|
## For testing purposes, create a copy of the interface
|
2006-11-28 22:28:37 +00:00
|
|
|
if __name__ == "__main__":
|
2007-01-11 00:58:23 +00:00
|
|
|
interface = DelugeGTK()
|
2007-02-06 21:21:09 +00:00
|
|
|
interface.start()
|