Massive clean up of loading torrents.

This commit is contained in:
Alex Dedul 2007-07-16 03:23:36 +00:00
parent c0cb16425b
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):
selection = widget.get_selection()
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):
@ -342,7 +342,7 @@ class plugin_RSS:
#print "contains" + checkfilterexp
for enclosure in entry.enclosures:
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))
else:
if avail[checkfilterfeed]:
@ -363,7 +363,7 @@ class plugin_RSS:
#print "contains" + checkfilterexp
for enclosure in entry.enclosures:
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))
for name in avail.keys():

View File

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

View File

@ -105,25 +105,17 @@ or failures in startup. You may wish to remove it manually. (%s)
Continuing...""" % pstate_file_path
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():
print "Starting new Deluge session..."
upgrade_old_persistent_state()
interface = deluge.interface.DelugeGTK()
add_args(interface)
interface.start(options.tray)
def add_args(interface):
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"
interface.start(options.tray, get_cmd_line_torrents(), options.url)
if dbus_imported:
bus = dbus.SessionBus()
@ -143,7 +135,11 @@ if dbus_imported:
deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.Deluge')
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:
print "no existing Deluge session"

View File

@ -28,16 +28,11 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import sys
import os
import os.path
import threading
import webbrowser
import xdg
import xdg.BaseDirectory
import gettext
PROGRAM_NAME = "Deluge"
PROGRAM_VERSION = "0.5.2.90"
@ -112,7 +107,6 @@ def ftime(seconds):
return '%dw %dd'%(weeks, days)
return 'unknown'
def get_glade_file(fname):
return os.path.join(GLADE_DIR, fname)
@ -127,7 +121,18 @@ def open_url_in_browser(dialog, link):
except webbrowser.Error:
print _("Error: no webbrowser found")
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
class EncState:
forced, enabled, disabled = range(3)

View File

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

View File

@ -30,9 +30,6 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import os
import sys
import imp
import gtk
import dgtk
import common
@ -51,20 +48,20 @@ class FilesManager:
"uncheck_selected": self.file_uncheck_selected,
})
self.file_unique_id = -1
self.is_file_tab = is_file_tab
# Stores file path -> gtk.TreeIter's iter mapping for quick look up
# in self.update_torrent_info_widget
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:
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):
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
def percent(column, cell, model, 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.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):
self.file_store.clear()
self.file_store_dict = {}

View File

@ -33,7 +33,6 @@
import os.path
from itertools import izip
import re
import urllib
import gettext
import gobject
@ -61,9 +60,7 @@ class DelugeGTK:
gettext.textdomain(APP)
gettext.install(APP, DIR)
self.is_running = False
self.ipc_manager = ipc_manager.Manager(self)
self.torrent_file_queue = []
#Start the Deluge Manager:
self.manager = core.Manager(common.CLIENT_CODE, common.CLIENT_VERSION,
'%s %s'%(common.PROGRAM_NAME, common.PROGRAM_VERSION), common.CONFIG_DIR)
@ -124,16 +121,6 @@ class DelugeGTK:
self.apply_prefs()
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):
self.wtree.signal_autoconnect({
@ -662,10 +649,7 @@ class DelugeGTK:
self.peer_store_dict = {}
def build_file_tab(self):
self.files_for_tab.clear_file_store()
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)
self.files_for_tab.build_file_view(self.wtree.get_widget("file_view"))
def clear_file_store(self):
self.files_for_tab.clear_file_store()
@ -782,40 +766,40 @@ class DelugeGTK:
else:
status_icon = gtk.gdk.pixbuf_new_from_file(common.get_pixmap("downloading16.png"))
rlist = [int(unique_id), queue, status_icon, name, size, progress, message,
seeds, seeds_t, peers, peers_t, dl_speed, ul_speed, eta, share]
rlist = [int(unique_id), queue, status_icon, name, size, progress,
message, seeds, seeds_t, peers, peers_t, dl_speed, ul_speed,
eta, share]
return rlist
## 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
self.has_tray) and not self.window.get_property("visible"):
self.has_tray) and not self.window.get_property("visible"):
print "Showing window"
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
for unique_id in self.manager.get_unique_IDs():
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)
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()
gobject.timeout_add(1000, self.update)
try:
self.is_running = True
gtk.main()
except KeyboardInterrupt:
self.manager.quit()
@ -1072,6 +1056,8 @@ class DelugeGTK:
return None
def on_drag_data(self, widget, drag_context, x, y, selection_data, info, timestamp):
import urllib
uri_split = selection_data.data.strip().split()
for uri in uri_split:
path = urllib.url2pathname(uri).strip('\r\n\x00')
@ -1083,23 +1069,27 @@ class DelugeGTK:
path = path[5:]
if path.endswith('.torrent'):
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'):
path = self.config.get('default_download_path')
else:
path = dialogs.show_directory_chooser_dialog(self.window)
if path is None:
return
try:
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:
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."))
@ -1112,16 +1102,15 @@ class DelugeGTK:
_("Space Needed:") + " " + nice_need + "\n" + \
_("Available Space:") + " " + nice_free)
else:
if append:
if 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)
self.torrent_model_append(unique_id)
else:
self.manager.remove_torrent(unique_id, True, True)
else:
if 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)
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):
common.open_url_in_browser('self', 'https://translations.launchpad.net/deluge/trunk/+pots/deluge')
@ -1153,35 +1142,8 @@ class DelugeGTK:
dlg.destroy()
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):
glade = gtk.glade.XML(common.get_glade_file("dgtkpopups.glade"), domain='deluge')
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)
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')
def external_add_torrent(self, torrent_file):
self.interface.external_add_torrent(torrent_file)
def interactive_add_torrent(self, torrent_file):
self.interface.interactive_add_torrent(torrent_file)
@dbus.service.method('org.deluge_torrent.Deluge')
def external_add_url(self, url):
self.interface.external_add_url(url)
def interactive_add_torrent_url(self, url):
self.interface.interactive_add_torrent_url(url)
else:
# This is a fallback class in case dbus is not available
class Manager:
def __init__(self, interface, object_path=None):
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."
def external_add_url(self, url):
def interactive_add_torrent_url(self, url):
print "I can't do anything with this."