Massive clean up of loading torrents.

This commit is contained in:
Alex Dedul 2007-07-16 03:23:36 +00:00
commit ac81d240bd
8 changed files with 78 additions and 129 deletions

View file

@ -267,7 +267,7 @@ class plugin_RSS:
def torrents_view_row_activated(self, widget, spare1, spare2): def torrents_view_row_activated(self, widget, spare1, spare2):
selection = widget.get_selection() selection = widget.get_selection()
model, selection_iter = selection.get_selected() model, selection_iter = selection.get_selected()
self.interface.add_torrent_url(widget.get_model().get_value(selection_iter, 2)) self.interface.interactive_add_torrent_url(widget.get_model().get_value(selection_iter, 2))
def chkfeeds_clicked(self, args): def chkfeeds_clicked(self, args):
@ -342,7 +342,7 @@ class plugin_RSS:
#print "contains" + checkfilterexp #print "contains" + checkfilterexp
for enclosure in entry.enclosures: for enclosure in entry.enclosures:
print enclosure.href print enclosure.href
self.interface.external_add_url(enclosure.href) self.interface.interactive_add_torrent_url(enclosure.href)
#self.feeds_config.set(feedname, "lastchecked", asctime(entry.date_parsed)) #self.feeds_config.set(feedname, "lastchecked", asctime(entry.date_parsed))
else: else:
if avail[checkfilterfeed]: if avail[checkfilterfeed]:
@ -363,7 +363,7 @@ class plugin_RSS:
#print "contains" + checkfilterexp #print "contains" + checkfilterexp
for enclosure in entry.enclosures: for enclosure in entry.enclosures:
print enclosure.href print enclosure.href
self.interface.external_add_url(enclosure.href) self.interface.interactive_add_torrent_url(enclosure.href)
#self.feeds_config.set(checkfilterfeed, "lastchecked", asctime(entry.date_parsed)) #self.feeds_config.set(checkfilterfeed, "lastchecked", asctime(entry.date_parsed))
for name in avail.keys(): for name in avail.keys():

View file

@ -151,7 +151,7 @@ class TorrentCreator:
# Torrent was created successfully # Torrent was created successfully
if add_torrent: if add_torrent:
# We need to add this torrent to the queue # We need to add this torrent to the queue
self.interface.external_add_torrent(torrent) self.interface.interactive_add_torrent(torrent)
return True return True
else: else:
return False return False

View file

@ -105,25 +105,17 @@ or failures in startup. You may wish to remove it manually. (%s)
Continuing...""" % pstate_file_path Continuing...""" % pstate_file_path
print >> sys.stderr, "The error was: %s." % oopsie print >> sys.stderr, "The error was: %s." % oopsie
def get_cmd_line_torrents():
return [os.path.abspath(x) for x in args]
def start_deluge(): def start_deluge():
print "Starting new Deluge session..." print "Starting new Deluge session..."
upgrade_old_persistent_state() upgrade_old_persistent_state()
interface = deluge.interface.DelugeGTK() interface = deluge.interface.DelugeGTK()
add_args(interface)
interface.start(options.tray)
def add_args(interface): interface.start(options.tray, get_cmd_line_torrents(), options.url)
if options.url:
interface.external_add_url(options.url)
else:
for arg in args:
apath = os.path.abspath(arg)
if apath.endswith(".torrent"):
interface.external_add_torrent(apath)
else:
print "Error,", arg, " does not seem to be a .torrent file"
if dbus_imported: if dbus_imported:
bus = dbus.SessionBus() bus = dbus.SessionBus()
@ -143,7 +135,11 @@ if dbus_imported:
deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.Deluge') deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.Deluge')
print "send to iface" print "send to iface"
add_args(deluge_iface) for filename in get_cmd_line_torrents():
deluge_iface.interactive_add_torrent(filename)
if options.url:
deluge_iface.interactive_add_torrent_url(options.url)
else: else:
print "no existing Deluge session" print "no existing Deluge session"

View file

@ -28,16 +28,11 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
import sys
import os
import os.path import os.path
import threading import threading
import webbrowser import webbrowser
import xdg
import xdg.BaseDirectory import xdg.BaseDirectory
import gettext
PROGRAM_NAME = "Deluge" PROGRAM_NAME = "Deluge"
PROGRAM_VERSION = "0.5.2.90" PROGRAM_VERSION = "0.5.2.90"
@ -112,7 +107,6 @@ def ftime(seconds):
return '%dw %dd'%(weeks, days) return '%dw %dd'%(weeks, days)
return 'unknown' return 'unknown'
def get_glade_file(fname): def get_glade_file(fname):
return os.path.join(GLADE_DIR, fname) return os.path.join(GLADE_DIR, fname)
@ -127,7 +121,18 @@ def open_url_in_browser(dialog, link):
except webbrowser.Error: except webbrowser.Error:
print _("Error: no webbrowser found") print _("Error: no webbrowser found")
LaunchBrowser().start() LaunchBrowser().start()
def fetch_url(url):
import urllib
filename, headers = urllib.urlretrieve(url)
if filename.endswith(".torrent") or \
headers["content-type"]=="application/x-bittorrent":
return filename, headers
else:
print "URL doesn't appear to be a valid torrent file:", url
return None, None
# Encryption States # Encryption States
class EncState: class EncState:
forced, enabled, disabled = range(3) forced, enabled, disabled = range(3)

View file

@ -32,10 +32,6 @@ import common
import dgtk import dgtk
import pref import pref
import gtk import gtk
import gtk.glade
import os
import os.path
import files
PREFS_FILENAME = "prefs.state" PREFS_FILENAME = "prefs.state"
@ -179,19 +175,17 @@ class FilesDlg:
self.dialog = self.glade.get_widget("file_dialog") self.dialog = self.glade.get_widget("file_dialog")
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png")) self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
self.file_view = self.glade.get_widget("file_view") self.file_view = self.glade.get_widget("file_view")
self.files_for_dialog.build_file_view(self.file_view)
def show(self, manager, unique_id): def show(self, manager, unique_id):
self.manager = manager self.manager = manager
self.files_for_dialog.clear_file_store()
self.files_for_dialog.use_unique_id(unique_id) self.files_for_dialog.use_unique_id(unique_id)
self.files_for_dialog.file_view_actions(self.file_view)
self.files_for_dialog.prepare_store() self.files_for_dialog.prepare_store()
#clear private setting #clear private setting
self.glade.get_widget("chk_setpriv").set_active(False) self.glade.get_widget("chk_setpriv").set_active(False)
self.dialog.show() self.dialog.show()
r = self.dialog.run() r = self.dialog.run()
self.dialog.hide() self.dialog.hide()
self.files_for_dialog.remove_columns()
self.files_for_dialog.clear_file_store() self.files_for_dialog.clear_file_store()
if(self.glade.get_widget("chk_setpriv").get_active()): if(self.glade.get_widget("chk_setpriv").get_active()):
self.manager.set_priv(unique_id, True) self.manager.set_priv(unique_id, True)

View file

@ -30,9 +30,6 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
import os
import sys
import imp
import gtk import gtk
import dgtk import dgtk
import common import common
@ -51,20 +48,20 @@ class FilesManager:
"uncheck_selected": self.file_uncheck_selected, "uncheck_selected": self.file_uncheck_selected,
}) })
self.file_unique_id = -1 self.file_unique_id = -1
self.is_file_tab = is_file_tab
# Stores file path -> gtk.TreeIter's iter mapping for quick look up # Stores file path -> gtk.TreeIter's iter mapping for quick look up
# in self.update_torrent_info_widget # in self.update_torrent_info_widget
self.file_store_dict = {} self.file_store_dict = {}
self.file_store = gtk.ListStore(bool, str, gobject.TYPE_UINT64)
self.file_store_sorted = gtk.TreeModelSort(self.file_store)
self.is_file_tab = is_file_tab
if self.is_file_tab: if self.is_file_tab:
self.file_store = gtk.ListStore(bool, str, gobject.TYPE_UINT64, float) self.file_store = gtk.ListStore(bool, str, gobject.TYPE_UINT64, float)
self.file_store_sorted = gtk.TreeModelSort(self.file_store) else:
self.file_store = gtk.ListStore(bool, str, gobject.TYPE_UINT64)
self.file_store_sorted = gtk.TreeModelSort(self.file_store)
def use_unique_id(self, unique_id): def use_unique_id(self, unique_id):
self.file_unique_id = unique_id self.file_unique_id = unique_id
def file_view_actions(self, file_view): def build_file_view(self, file_view):
self.file_view = file_view self.file_view = file_view
def percent(column, cell, model, iter, data): def percent(column, cell, model, iter, data):
percent = float(model.get_value(iter, data)) percent = float(model.get_value(iter, data))
@ -82,11 +79,6 @@ class FilesManager:
self.file_view.get_selection().set_select_function(self.file_clicked) self.file_view.get_selection().set_select_function(self.file_clicked)
self.file_view.connect("button-press-event", self.file_view_clicked) self.file_view.connect("button-press-event", self.file_view_clicked)
def remove_columns(self):
self.file_view.remove_column(self.size_column)
self.file_view.remove_column(self.filename_column)
self.file_view.remove_column(self.toggle_column)
def clear_file_store(self): def clear_file_store(self):
self.file_store.clear() self.file_store.clear()
self.file_store_dict = {} self.file_store_dict = {}

View file

@ -33,7 +33,6 @@
import os.path import os.path
from itertools import izip from itertools import izip
import re import re
import urllib
import gettext import gettext
import gobject import gobject
@ -61,9 +60,7 @@ class DelugeGTK:
gettext.textdomain(APP) gettext.textdomain(APP)
gettext.install(APP, DIR) gettext.install(APP, DIR)
self.is_running = False
self.ipc_manager = ipc_manager.Manager(self) self.ipc_manager = ipc_manager.Manager(self)
self.torrent_file_queue = []
#Start the Deluge Manager: #Start the Deluge Manager:
self.manager = core.Manager(common.CLIENT_CODE, common.CLIENT_VERSION, self.manager = core.Manager(common.CLIENT_CODE, common.CLIENT_VERSION,
'%s %s'%(common.PROGRAM_NAME, common.PROGRAM_VERSION), common.CONFIG_DIR) '%s %s'%(common.PROGRAM_NAME, common.PROGRAM_VERSION), common.CONFIG_DIR)
@ -124,16 +121,6 @@ class DelugeGTK:
self.apply_prefs() self.apply_prefs()
self.load_window_geometry() self.load_window_geometry()
def external_add_torrent(self, torrent_file):
print "Got torrent externally:", os.path.basename(torrent_file)
print "Here's the raw data:", torrent_file
if self.is_running:
print "\t\tClient seems to already be running, we'll try and add the torrent"
uid = self.interactive_add_torrent(torrent_file)
else:
print "\t\tClient isn't running, we'll queue the torrent"
self.torrent_file_queue.append(torrent_file)
def connect_signals(self): def connect_signals(self):
self.wtree.signal_autoconnect({ self.wtree.signal_autoconnect({
@ -662,10 +649,7 @@ class DelugeGTK:
self.peer_store_dict = {} self.peer_store_dict = {}
def build_file_tab(self): def build_file_tab(self):
self.files_for_tab.clear_file_store() self.files_for_tab.build_file_view(self.wtree.get_widget("file_view"))
self.files_for_tab.use_unique_id(self.get_selected_torrent())
self.file_view = self.wtree.get_widget("file_view")
self.files_for_tab.file_view_actions(self.file_view)
def clear_file_store(self): def clear_file_store(self):
self.files_for_tab.clear_file_store() self.files_for_tab.clear_file_store()
@ -782,40 +766,40 @@ class DelugeGTK:
else: else:
status_icon = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("downloading16.png")) status_icon = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("downloading16.png"))
rlist = [int(unique_id), queue, status_icon, name, size, progress, message, rlist = [int(unique_id), queue, status_icon, name, size, progress,
seeds, seeds_t, peers, peers_t, dl_speed, ul_speed, eta, share] message, seeds, seeds_t, peers, peers_t, dl_speed, ul_speed,
eta, share]
return rlist return rlist
## Start the timer that updates the interface ## Start the timer that updates the interface
def start(self, start_in_tray=False): def start(self, start_in_tray=False, cmd_line_torrents=None,
cmd_line_torrent_url=None):
if cmd_line_torrents is None:
cmd_line_torrents = []
if not(start_in_tray and self.config.get("enable_system_tray") and if not(start_in_tray and self.config.get("enable_system_tray") and
self.has_tray) and not self.window.get_property("visible"): self.has_tray) and not self.window.get_property("visible"):
print "Showing window" print "Showing window"
self.window.show() 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:
self.interactive_add_torrent(torrent_file, append=False)
except core.DelugeError:
print "Duplicate torrent found, ignoring the duplicate", torrent_file
## add torrents in manager to interface ## add torrents in manager to interface
for unique_id in self.manager.get_unique_IDs(): for unique_id in self.manager.get_unique_IDs():
self.torrent_model_append(unique_id) self.torrent_model_append(unique_id)
for torrent_file in cmd_line_torrents:
self.interactive_add_torrent(torrent_file)
self.interactive_add_torrent_url(cmd_line_torrent_url)
# Load plugins after we showed main window (if not started in tray) # Load plugins after we showed main window (if not started in tray)
self.load_plugins() self.load_plugins()
# Call update now so everything is up-to-date when the window gains focus on startup # Call update now so everything is up-to-date when the window gains
# focus on startup
self.update() self.update()
gobject.timeout_add(1000, self.update) gobject.timeout_add(1000, self.update)
try: try:
self.is_running = True
gtk.main() gtk.main()
except KeyboardInterrupt: except KeyboardInterrupt:
self.manager.quit() self.manager.quit()
@ -1072,6 +1056,8 @@ class DelugeGTK:
return None return None
def on_drag_data(self, widget, drag_context, x, y, selection_data, info, timestamp): def on_drag_data(self, widget, drag_context, x, y, selection_data, info, timestamp):
import urllib
uri_split = selection_data.data.strip().split() uri_split = selection_data.data.strip().split()
for uri in uri_split: for uri in uri_split:
path = urllib.url2pathname(uri).strip('\r\n\x00') path = urllib.url2pathname(uri).strip('\r\n\x00')
@ -1083,23 +1069,27 @@ class DelugeGTK:
path = path[5:] path = path[5:]
if path.endswith('.torrent'): if path.endswith('.torrent'):
self.interactive_add_torrent(path) self.interactive_add_torrent(path)
def interactive_add_torrent_url(self, url):
if url:
filename, headers = common.fetch_url(url)
if filename:
self.interactive_add_torrent(filename)
def interactive_add_torrent(self, torrent):
if not torrent.endswith(".torrent"):
print "Error,", torrent, " does not seem to be a .torrent file"
return
def interactive_add_torrent(self, torrent, append=True):
if self.config.get('use_default_dir'): if self.config.get('use_default_dir'):
path = self.config.get('default_download_path') path = self.config.get('default_download_path')
else: else:
path = dialogs.show_directory_chooser_dialog(self.window) path = dialogs.show_directory_chooser_dialog(self.window)
if path is None: if path is None:
return return
try: try:
unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage')) unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage'))
if not append and self.config.get('enable_files_dialog'):
self.manager.set_user_pause(unique_id, True)
if self.files_dialog.show(self.manager, unique_id) == 1:
self.manager.set_user_pause(unique_id, False)
else:
self.manager.remove_torrent(unique_id, True, True)
except core.InvalidEncodingError, e: except core.InvalidEncodingError, e:
print "InvalidEncodingError", e print "InvalidEncodingError", e
dialogs.show_popup_warning(self.window, _("An error occured while trying to add the torrent. It's possible your .torrent file is corrupted.")) dialogs.show_popup_warning(self.window, _("An error occured while trying to add the torrent. It's possible your .torrent file is corrupted."))
@ -1112,16 +1102,15 @@ class DelugeGTK:
_("Space Needed:") + " " + nice_need + "\n" + \ _("Space Needed:") + " " + nice_need + "\n" + \
_("Available Space:") + " " + nice_free) _("Available Space:") + " " + nice_free)
else: else:
if append: if self.config.get('enable_files_dialog'):
if self.config.get('enable_files_dialog'): self.manager.set_user_pause(unique_id, True)
self.manager.set_user_pause(unique_id, True) if self.files_dialog.show(self.manager, unique_id) == 1:
if self.files_dialog.show(self.manager, unique_id) == 1: self.manager.set_user_pause(unique_id, False)
self.manager.set_user_pause(unique_id, False)
self.torrent_model_append(unique_id)
else:
self.manager.remove_torrent(unique_id, True, True)
else:
self.torrent_model_append(unique_id) self.torrent_model_append(unique_id)
else:
self.manager.remove_torrent(unique_id, True, True)
else:
self.torrent_model_append(unique_id)
def launchpad(self, obj=None): def launchpad(self, obj=None):
common.open_url_in_browser('self', 'https://translations.launchpad.net/deluge/trunk/+pots/deluge') common.open_url_in_browser('self', 'https://translations.launchpad.net/deluge/trunk/+pots/deluge')
@ -1153,35 +1142,8 @@ class DelugeGTK:
dlg.destroy() dlg.destroy()
if result == 1: if result == 1:
self.add_torrent_url(url) self.interactive_add_torrent_url(url)
def external_add_url(self, url):
print "Got URL externally:", url
if self.is_running:
print "\t\tClient seems to already be running, we'll try and add the URL"
self.add_torrent_url(url)
else:
print "\t\tThe client hasn't yet started, we'll queue the URL torrent file"
self.queue_torrent_url(url)
def add_torrent_url(self, url):
filename, headers = self.fetch_url(url)
if filename:
self.interactive_add_torrent(filename)
def queue_torrent_url(self, url):
filename, headers = self.fetch_url(url)
if filename:
self.torrent_file_queue.append(filename)
def fetch_url(self, url):
filename, headers = urllib.urlretrieve(url)
if filename.endswith(".torrent") or headers["content-type"]=="application/x-bittorrent":
return filename, headers
else:
print "URL doesn't appear to be a valid torrent file:", url
return None, None
def remove_torrent_clicked(self, obj=None): def remove_torrent_clicked(self, obj=None):
glade = gtk.glade.XML(common.get_glade_file("dgtkpopups.glade"), domain='deluge') glade = gtk.glade.XML(common.get_glade_file("dgtkpopups.glade"), domain='deluge')
asker = glade.get_widget("remove_torrent_dlg") asker = glade.get_widget("remove_torrent_dlg")

View file

@ -57,20 +57,20 @@ if dbus_imported:
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus) bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus=self.bus)
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
## external_add_torrent should only be called from outside the class ## interactive_add_torrent should only be called from outside the class
@dbus.service.method('org.deluge_torrent.Deluge') @dbus.service.method('org.deluge_torrent.Deluge')
def external_add_torrent(self, torrent_file): def interactive_add_torrent(self, torrent_file):
self.interface.external_add_torrent(torrent_file) self.interface.interactive_add_torrent(torrent_file)
@dbus.service.method('org.deluge_torrent.Deluge') @dbus.service.method('org.deluge_torrent.Deluge')
def external_add_url(self, url): def interactive_add_torrent_url(self, url):
self.interface.external_add_url(url) self.interface.interactive_add_torrent_url(url)
else: else:
# This is a fallback class in case dbus is not available # This is a fallback class in case dbus is not available
class Manager: class Manager:
def __init__(self, interface, object_path=None): def __init__(self, interface, object_path=None):
self.interface = interface self.interface = interface
def external_add_torrent(self, torrent_file): def interactive_add_torrent(self, torrent_file):
print "I can't do anything with this." print "I can't do anything with this."
def external_add_url(self, url): def interactive_add_torrent_url(self, url):
print "I can't do anything with this." print "I can't do anything with this."