def _make_context_menu_single(self, item): """Make the context menu for a single item.""" # Format for the menu list: # # Each item is either None or separated into (label, # callback), more or less, kinda. If it's None, it's actually # a separator. Otherwise.... # # The label is one of two things: # - A string, which is used as the label for the menu item # - A tuple of (label_text, icon_path), in case you need icons # # The callback is one of three things: # - None, in which case the menu item is made insensitive # - A list, which means a submenu... should be in the same format # as this normal menu # - A method of some form. In other words, a *real* callback :) menu_sections = [] section = [] def play_externally(): app.widgetapp.open_file(item.filename) messages.MarkItemWatched(item).send_to_backend() # drm items seem to go in misc and are always unplayable. # given that, we check for drm first. if item.has_drm: section.append((_('Play Externally'), play_externally)) section.append((_("Edit Item Details"), app.widgetapp.edit_items)) elif item.is_playable: # Show File in Finder if not item.remote and not item.is_container_item: # most recent conversion last_converter = conversion_manager.get_last_conversion() if last_converter is not None: converter = conversion_manager.lookup_converter( last_converter) if converter: def convert(converter=converter.identifier): app.widgetapp.convert_items(converter) section.append( (_('Convert to %(conversion)s', {"conversion": converter.displayname}), convert)) # Convert menu convert_menu = self._make_convert_menu() section.append((_('Convert to...'), convert_menu)) if not (item.device or item.remote): section.append((_('Set media kind as...'), self._make_edit_metadata_menu())) if not item.remote and not item.device: if item.net_lookup_enabled: label = _("Don't Use Online Lookup Data") callback = app.widgetapp.disable_net_lookup_for_selection else: label = _("Use Online Lookup Data") callback = app.widgetapp.enable_net_lookup_for_selection section.append((label, callback)) if section: menu_sections.append(section) section = [] # Play play_in_miro = app.config.get(prefs.PLAY_IN_MIRO) playing_item = app.playback_manager.get_playing_item() is_paused = app.playback_manager.is_paused if item != playing_item: section.append((_('Play'), app.widgetapp.play_selection)) elif item == playing_item and is_paused: section.append((_('Play'), app.playback_manager.toggle_paused)) else: section.append((_('Pause'), app.playback_manager.pause)) # Resume if play_in_miro and item != playing_item and item.resume_time > 0: resumetime = displaytext.short_time_string(item.resume_time) text = _("Resume at %(resumetime)s", {"resumetime": resumetime}) section.append((text, app.widgetapp.resume_play_selection)) if not (item.device or item.remote): if item.video_watched: section.append( (_('Mark as Unplayed'), messages.MarkItemUnwatched(item).send_to_backend)) else: section.append( (_('Mark as Played'), messages.MarkItemWatched(item).send_to_backend)) # XXX "Play Just This Item" does not work for shared items # and not quite sure why at this moment. if not item.remote and item != playing_item and play_in_miro: section.append( (_('Play Just This Item'), lambda: app.playback_manager.start_with_items([item]))) section.append((_('Play Externally'), play_externally)) if section: menu_sections.append(section) section = [] if not (item.device or item.remote): section.append( (_("Edit Item Details"), app.widgetapp.edit_items)) if not item.is_container_item: section.append( (_('Add to Playlist'), app.widgetapp.add_to_playlist)) elif item.is_download: if not menu_sections: # make sure that the default menu option isn't destructive # (re: #16715) section.append(None) section.append((_('Cancel Download'), messages.CancelDownload(item.id).send_to_backend)) if item.is_paused: section.append( (_('Pause Download'), messages.PauseDownload(item.id).send_to_backend)) else: section.append( (_('Resume Download'), messages.ResumeDownload(item.id).send_to_backend)) else: if not (item.device or item.remote): # Download if not item.downloaded: section.append( (_('Download'), messages.StartDownload(item.id).send_to_backend)) if item.is_failed_download: section.append( (_('Cancel Download'), messages.CancelDownload(item.id).send_to_backend)) else: # Other section.append( (_("Edit Item Details"), app.widgetapp.edit_items)) else: # Play section.append((_('Play'), app.widgetapp.play_selection)) if item.is_seeding: section.append((_('Stop Seeding'), messages.StopUpload(item.id).send_to_backend)) elif not item.is_seeding and item.is_torrent: section.append((_('Resume Seeding'), messages.StartUpload(item.id).send_to_backend)) if item.downloaded and not item.remote: if file_navigator_name: reveal_text = _('Show File in %(progname)s', {"progname": file_navigator_name}) else: reveal_text = _('File on Disk') section.append( (reveal_text, lambda: app.widgetapp.check_then_reveal_file(item.filename))) remove = self._remove_context_menu_item([item]) if remove: section.append(remove) if section: menu_sections.append(section) section = [] # don't add this section if the item is remote or a device OR # if it has nothing to add to the section. that way we don't # end up with just a separator. if ((not (item.device or item.remote) and item.permalink or item.has_shareable_url)): section.append( (_('Copy URL to clipboard'), app.widgetapp.copy_item_url)) if item.permalink: section.append( (_('View Web Page'), lambda: app.widgetapp.open_url(item.permalink))) if item.has_shareable_url: section.append( (_('Share'), lambda: app.widgetapp.share_item(item))) if section: menu_sections.append(section) # put separators between all the menu sections menu = [] for section in menu_sections: menu.extend(section) menu.append(None) # remove the last separator from the menu ... but make sure that we # don't try to do this if we came out of the block without actually # creating any entries in the context menu. try: del menu[-1] except IndexError: pass return menu
def cancel_all(): for item in downloading: messages.CancelDownload(item.id).send_to_backend()