diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 2591c5549..ff002d019 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -73,6 +73,8 @@ class AddTorrentDialog(component.Component): self.listview_torrents = self.builder.get_object('listview_torrents') self.listview_files = self.builder.get_object('listview_files') + self.prefetching_magnets = [] + render = gtk.CellRendererText() render.connect('edited', self._on_torrent_name_edit) render.set_property('editable', True) @@ -160,6 +162,7 @@ class AddTorrentDialog(component.Component): self.previous_selected_torrent = None self.torrent_liststore.clear() self.files_treestore.clear() + self.prefetching_magnets = [] self.dialog.set_transient_for(component.get('MainWindow').window) def _on_config_values(self, config, show=False, focus=False): @@ -237,15 +240,33 @@ class AddTorrentDialog(component.Component): """Process prefetched metadata to allow file priority selection.""" info_hash, b64_metadata = result log.debug('on_uri_metadata for %s (%s)', uri, info_hash) + if info_hash not in self.prefetching_magnets: + return if b64_metadata: metadata = b64decode(b64_metadata) info = TorrentInfo(metadata=metadata) self.files[info_hash] = info.files self.infos[info_hash] = info.filedata - self.prepare_file_store(info.files) else: log.info('Unable to fetch metadata for magnet: %s', uri) + self.prefetching_magnets.remove(info_hash) + self._on_torrent_changed(self.listview_torrents.get_selection()) + + def prefetch_waiting_message(self, torrent_id, files): + """Show magnet files fetching or failed message above files list.""" + if torrent_id in self.prefetching_magnets: + self.builder.get_object('prefetch_label').set_text( + _('Please wait for files...')) + self.builder.get_object('prefetch_spinner').show() + self.builder.get_object('prefetch_hbox').show() + elif not files: + self.builder.get_object('prefetch_label').set_text( + _('Unable to download files for this magnet')) + self.builder.get_object('prefetch_spinner').hide() + self.builder.get_object('prefetch_hbox').show() + else: + self.builder.get_object('prefetch_hbox').hide() def add_from_magnets(self, uris): """Add a list of magnet uris to torrent_liststore.""" @@ -257,20 +278,25 @@ class AddTorrentDialog(component.Component): log.error('Invalid magnet: %s', uri) continue + torrent_id = magnet['info_hash'] + files = magnet['files_tree'] if not self._add_torrent_liststore( - magnet['info_hash'], - magnet['name'], + torrent_id, magnet['name'], xml_escape(uri), - magnet['files_tree'], + files, None, ): already_added += 1 continue - client.core.prefetch_magnet_metadata(uri).addCallback( - self._on_uri_metadata, uri) + if files: + continue + + d = client.core.prefetch_magnet_metadata(uri) + d.addCallback(self._on_uri_metadata, uri) + self.prefetching_magnets.append(magnet['info_hash']) + self.prefetch_waiting_message(torrent_id, None) - self.update_dialog_title_count() if already_added: self.show_already_added_dialog(already_added) @@ -288,16 +314,19 @@ class AddTorrentDialog(component.Component): # Save the previous torrents options self.save_torrent_options() - # Update files list - files_list = self.files[model.get_value(row, 0)] + torrent_id = model.get_value(row, 0) + # Update files list + files_list = self.files[torrent_id] self.prepare_file_store(files_list) if self.core_config == {}: self.update_core_config() # Update the options frame - self.update_torrent_options(model.get_value(row, 0)) + self.update_torrent_options(torrent_id) + # Update magnet prefetch message + self.prefetch_waiting_message(torrent_id, files_list) self.previous_selected_torrent = row diff --git a/deluge/ui/gtkui/glade/add_torrent_dialog.ui b/deluge/ui/gtkui/glade/add_torrent_dialog.ui index b4d098ab5..4151876b4 100644 --- a/deluge/ui/gtkui/glade/add_torrent_dialog.ui +++ b/deluge/ui/gtkui/glade/add_torrent_dialog.ui @@ -82,7 +82,6 @@ center - False True True True @@ -129,7 +128,6 @@ - False True True True @@ -176,7 +174,6 @@ - False True True True @@ -223,7 +220,6 @@ - False True True True @@ -295,21 +291,79 @@ False 1 - + True - True - 2 - automatic - automatic - in + False - + + True + False + 5 + + + False + 5 + + + True + False + True + + + False + True + 0 + + + + + True + False + 0 + Please wait for files... + + + + + + True + True + 1 + + + + + + + False + True + 5 + 0 + + + + True True - 1 - False - True + 2 + automatic + automatic + in + + + True + True + 1 + False + True + + + + True + True + 1 + @@ -413,7 +467,6 @@ False - False True True False @@ -474,7 +527,6 @@ Add In _Paused State - False True True False @@ -490,7 +542,6 @@ Prioritize First/Last Pieces - False True True False @@ -505,7 +556,6 @@ Sequential Download - False True True False @@ -527,7 +577,6 @@ used sparingly. Skip File Hash Check - False True True False @@ -543,7 +592,6 @@ used sparingly. Preallocate Disk Space - False True True False @@ -610,8 +658,8 @@ used sparingly. 1 2 - - + + @@ -624,7 +672,7 @@ used sparingly. GTK_FILL - + @@ -639,7 +687,7 @@ used sparingly. 1 2 GTK_FILL - + @@ -654,7 +702,7 @@ used sparingly. 2 3 GTK_FILL - + @@ -669,7 +717,7 @@ used sparingly. 3 4 GTK_FILL - + @@ -689,8 +737,8 @@ used sparingly. 2 1 2 - - + + @@ -709,8 +757,8 @@ used sparingly. 2 2 3 - - + + @@ -729,8 +777,8 @@ used sparingly. 2 3 4 - - + + @@ -773,7 +821,6 @@ used sparingly. 5 - False True True True @@ -827,7 +874,6 @@ used sparingly. False - False True True True @@ -944,7 +990,6 @@ used sparingly. gtk-cancel - False True True True @@ -960,7 +1005,6 @@ used sparingly. gtk-add - False True True True