[#2398|GTK] Update prefetching magnet metadata in AddTorrent dialog

The new code automatically attemps to fetch magnet file details from
core while displaying a 'waiting' message.
This commit is contained in:
Calum Lind 2018-09-25 15:16:29 +01:00
parent a09334e116
commit abf4c345f0
2 changed files with 119 additions and 46 deletions

View File

@ -73,6 +73,8 @@ class AddTorrentDialog(component.Component):
self.listview_torrents = self.builder.get_object('listview_torrents') self.listview_torrents = self.builder.get_object('listview_torrents')
self.listview_files = self.builder.get_object('listview_files') self.listview_files = self.builder.get_object('listview_files')
self.prefetching_magnets = []
render = gtk.CellRendererText() render = gtk.CellRendererText()
render.connect('edited', self._on_torrent_name_edit) render.connect('edited', self._on_torrent_name_edit)
render.set_property('editable', True) render.set_property('editable', True)
@ -160,6 +162,7 @@ class AddTorrentDialog(component.Component):
self.previous_selected_torrent = None self.previous_selected_torrent = None
self.torrent_liststore.clear() self.torrent_liststore.clear()
self.files_treestore.clear() self.files_treestore.clear()
self.prefetching_magnets = []
self.dialog.set_transient_for(component.get('MainWindow').window) self.dialog.set_transient_for(component.get('MainWindow').window)
def _on_config_values(self, config, show=False, focus=False): 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.""" """Process prefetched metadata to allow file priority selection."""
info_hash, b64_metadata = result info_hash, b64_metadata = result
log.debug('on_uri_metadata for %s (%s)', uri, info_hash) log.debug('on_uri_metadata for %s (%s)', uri, info_hash)
if info_hash not in self.prefetching_magnets:
return
if b64_metadata: if b64_metadata:
metadata = b64decode(b64_metadata) metadata = b64decode(b64_metadata)
info = TorrentInfo(metadata=metadata) info = TorrentInfo(metadata=metadata)
self.files[info_hash] = info.files self.files[info_hash] = info.files
self.infos[info_hash] = info.filedata self.infos[info_hash] = info.filedata
self.prepare_file_store(info.files)
else: else:
log.info('Unable to fetch metadata for magnet: %s', uri) 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): def add_from_magnets(self, uris):
"""Add a list of magnet uris to torrent_liststore.""" """Add a list of magnet uris to torrent_liststore."""
@ -257,20 +278,25 @@ class AddTorrentDialog(component.Component):
log.error('Invalid magnet: %s', uri) log.error('Invalid magnet: %s', uri)
continue continue
torrent_id = magnet['info_hash']
files = magnet['files_tree']
if not self._add_torrent_liststore( if not self._add_torrent_liststore(
magnet['info_hash'], torrent_id, magnet['name'],
magnet['name'],
xml_escape(uri), xml_escape(uri),
magnet['files_tree'], files,
None, None,
): ):
already_added += 1 already_added += 1
continue continue
client.core.prefetch_magnet_metadata(uri).addCallback( if files:
self._on_uri_metadata, uri) 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: if already_added:
self.show_already_added_dialog(already_added) self.show_already_added_dialog(already_added)
@ -288,16 +314,19 @@ class AddTorrentDialog(component.Component):
# Save the previous torrents options # Save the previous torrents options
self.save_torrent_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) self.prepare_file_store(files_list)
if self.core_config == {}: if self.core_config == {}:
self.update_core_config() self.update_core_config()
# Update the options frame # 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 self.previous_selected_torrent = row

View File

@ -82,7 +82,6 @@
<property name="layout_style">center</property> <property name="layout_style">center</property>
<child> <child>
<object class="GtkButton" id="button_file"> <object class="GtkButton" id="button_file">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -129,7 +128,6 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="button_url"> <object class="GtkButton" id="button_url">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -176,7 +174,6 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="button_hash"> <object class="GtkButton" id="button_hash">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -223,7 +220,6 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="button_remove"> <object class="GtkButton" id="button_remove">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -294,6 +290,57 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="show_border">False</property> <property name="show_border">False</property>
<property name="tab_vborder">1</property> <property name="tab_vborder">1</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkAlignment" id="alignment9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">5</property>
<child>
<object class="GtkHBox" id="prefetch_hbox">
<property name="can_focus">False</property>
<property name="spacing">5</property>
<child>
<object class="GtkSpinner" id="prefetch_spinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="prefetch_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Please wait for files...</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow2"> <object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property> <property name="visible">True</property>
@ -312,6 +359,13 @@
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child> </child>
<child type="tab"> <child type="tab">
<object class="GtkHBox" id="hbox11"> <object class="GtkHBox" id="hbox11">
@ -413,7 +467,6 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkCheckButton" id="chk_move_completed"> <object class="GtkCheckButton" id="chk_move_completed">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -474,7 +527,6 @@
<child> <child>
<object class="GtkCheckButton" id="chk_paused"> <object class="GtkCheckButton" id="chk_paused">
<property name="label" translatable="yes">Add In _Paused State</property> <property name="label" translatable="yes">Add In _Paused State</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -490,7 +542,6 @@
<child> <child>
<object class="GtkCheckButton" id="chk_prioritize"> <object class="GtkCheckButton" id="chk_prioritize">
<property name="label" translatable="yes">Prioritize First/Last Pieces</property> <property name="label" translatable="yes">Prioritize First/Last Pieces</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -505,7 +556,6 @@
<child> <child>
<object class="GtkCheckButton" id="chk_sequential_download"> <object class="GtkCheckButton" id="chk_sequential_download">
<property name="label" translatable="yes">Sequential Download</property> <property name="label" translatable="yes">Sequential Download</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -527,7 +577,6 @@ used sparingly.</property>
<child> <child>
<object class="GtkCheckButton" id="chk_seed_mode"> <object class="GtkCheckButton" id="chk_seed_mode">
<property name="label" translatable="yes">Skip File Hash Check</property> <property name="label" translatable="yes">Skip File Hash Check</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -543,7 +592,6 @@ used sparingly.</property>
<child> <child>
<object class="GtkCheckButton" id="chk_pre_alloc"> <object class="GtkCheckButton" id="chk_pre_alloc">
<property name="label" translatable="yes">Preallocate Disk Space</property> <property name="label" translatable="yes">Preallocate Disk Space</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
@ -610,8 +658,8 @@ used sparingly.</property>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="x_options"></property> <property name="x_options"/>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -624,7 +672,7 @@ used sparingly.</property>
</object> </object>
<packing> <packing>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -639,7 +687,7 @@ used sparingly.</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -654,7 +702,7 @@ used sparingly.</property>
<property name="top_attach">2</property> <property name="top_attach">2</property>
<property name="bottom_attach">3</property> <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -669,7 +717,7 @@ used sparingly.</property>
<property name="top_attach">3</property> <property name="top_attach">3</property>
<property name="bottom_attach">4</property> <property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -689,8 +737,8 @@ used sparingly.</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
<property name="x_options"></property> <property name="x_options"/>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -709,8 +757,8 @@ used sparingly.</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">2</property> <property name="top_attach">2</property>
<property name="bottom_attach">3</property> <property name="bottom_attach">3</property>
<property name="x_options"></property> <property name="x_options"/>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
<child> <child>
@ -729,8 +777,8 @@ used sparingly.</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">3</property> <property name="top_attach">3</property>
<property name="bottom_attach">4</property> <property name="bottom_attach">4</property>
<property name="x_options"></property> <property name="x_options"/>
<property name="y_options"></property> <property name="y_options"/>
</packing> </packing>
</child> </child>
</object> </object>
@ -773,7 +821,6 @@ used sparingly.</property>
<property name="right_padding">5</property> <property name="right_padding">5</property>
<child> <child>
<object class="GtkButton" id="button_apply"> <object class="GtkButton" id="button_apply">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -827,7 +874,6 @@ used sparingly.</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkButton" id="button_revert"> <object class="GtkButton" id="button_revert">
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -944,7 +990,6 @@ used sparingly.</property>
<child> <child>
<object class="GtkButton" id="button_cancel"> <object class="GtkButton" id="button_cancel">
<property name="label">gtk-cancel</property> <property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
@ -960,7 +1005,6 @@ used sparingly.</property>
<child> <child>
<object class="GtkButton" id="button_add"> <object class="GtkButton" id="button_add">
<property name="label">gtk-add</property> <property name="label">gtk-add</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>