Author: andar
Revision: 5381
Log:
Show a progress window when downloading torrents from URL
Add ErrorDialogs when trying to add bad torrents and when downloading of
torrent fails
Diff:
Modified: trunk/deluge/ui/gtkui/addtorrentdialog.py
===================================================================
--- trunk/deluge/ui/gtkui/addtorrentdialog.py 2009-06-10 22:23:49 UTC (rev
5380)
+++ trunk/deluge/ui/gtkui/addtorrentdialog.py 2009-06-10 22:35:47 UTC (rev
5381)
@@ -51,6 +51,7 @@
from deluge.log import LOG as log
import deluge.common
import deluge.ui.common
+import dialogs
class AddTorrentDialog(component.Component):
def __init__(self):
@@ -194,10 +195,12 @@
info = deluge.ui.common.TorrentInfo(filename)
except Exception, e:
log.debug("Unable to open torrent file: %s", e)
+ dialogs.ErrorDialog(_("Invalid File"), e, self.dialog).run()
continue
if info.info_hash in self.files:
log.debug("Trying to add a duplicate torrent!")
+ dialogs.ErrorDialog(_("Duplicate Torrent"), _("You cannot add
the same torrent twice."), self.dialog).run()
continue
name = "%s (%s)" % (info.name, os.path.split(filename)[-1])
@@ -465,8 +468,7 @@
# Check to see if we can change file priorities
(model, row) = self.listview_torrents.get_selection().get_selected()
if self.options[model[row][0]]["compact_allocation"]:
- import dialogs
- dialogs.InformationDialog(_("Unable to set file priority!"),
_("File prioritization is unavailable when using Compact allocation.")).run()
+ dialogs.InformationDialog(_("Unable to set file priority!"),
_("File prioritization is unavailable when using Compact allocation."),
self.dialog).run()
return
(model, paths) =
self.listview_files.get_selection().get_selected_rows()
if len(paths) > 1:
@@ -582,21 +584,63 @@
else:
url = None
+ entry.set_text("")
+ dialog.hide()
+
# This is where we need to fetch the .torrent file from the URL and
# add it to the list.
log.debug("url: %s", url)
- if url != None:
+ if url:
if deluge.common.is_url(url):
self.add_from_url(url)
elif deluge.common.is_magnet(url):
self.add_from_magnets([url])
+ else:
+ dialogs.ErrorDialog(_("Invalid URL"), _("%s is not a valid
URL." % url), self.dialog).run()
- entry.set_text("")
- dialog.hide()
-
def add_from_url(self, url):
- gobject.idle_add(self._download_from_url, url)
+ dialog = gtk.Dialog(
+ _("Downloading.."),
+ flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT |
gtk.DIALOG_NO_SEPARATOR,
+ parent=self.dialog)
+ dialog.set_transient_for(self.dialog)
+ pb = gtk.ProgressBar()
+ dialog.vbox.pack_start(pb, True, True)
+ dialog.show_all()
+
+ # Create a tmp file path
+ import tempfile
+ import os.path
+ tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1])
+
+ def on_part(data, current_length, total_length):
+ if total_length:
+ percent = float(current_length) / float(total_length)
+ pb.set_fraction(percent)
+ pb.set_text("%.2f%% (%s / %s)" % (
+ percent * 100,
+ deluge.common.fsize(current_length),
+ deluge.common.fsize(total_length)))
+ else:
+ pb.pulse()
+ pb.set_text("%s" % deluge.common.fsize(current_length))
+
+ def on_download_success(result):
+ log.debug("Download success!")
+ self.add_from_files([tmp_file])
+ dialog.destroy()
+
+ def on_download_fail(result):
+ log.debug("Download failed: %s", result)
+ dialog.destroy()
+ dialogs.ErrorDialog(_("Download Failed"), _("Failed to download :
%s" % url), details=result.getErrorMessage(), parent=self.dialog).run()
+
+ import deluge.httpdownloader
+ d = deluge.httpdownloader.download_file(url, tmp_file, on_part)
+ d.addCallback(on_download_success)
+ d.addErrback(on_download_fail)
+
def _download_from_url(self, url):
import urllib
import tempfile
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---