def _add_default_playlists(self): """ Adds some default smart playlists to the playlist manager """ from xl import playlist # entire playlist entire_lib = playlist.SmartPlaylist( _("Entire Library"), collection=self.collection ) self.smart_playlists.save_playlist(entire_lib, overwrite=True) # random playlists for count in (100, 300, 500): pl = playlist.SmartPlaylist( _("Random %d") % count, collection=self.collection ) pl.set_return_limit(count) pl.set_random_sort(True) self.smart_playlists.save_playlist(pl, overwrite=True) # rating based playlists for item in (3, 4): pl = playlist.SmartPlaylist( _("Rating > %d") % item, collection=self.collection ) pl.add_param('__rating', '>', item) self.smart_playlists.save_playlist(pl, overwrite=True)
def _run_edit_dialog(cls, dialog, collection, smart_manager, parent, orig_pl=None): '''internal helper function''' while True: result = dialog.run() dialog.hide() if result != Gtk.ResponseType.ACCEPT: return name = dialog.get_name() matchany = dialog.get_match_any() limit = dialog.get_limit() state = dialog.get_state() random = dialog.get_random() sort_tags = cls._get_sort_tags(dialog) if not name: dialogs.error( parent, _("You did " "not enter a name for your playlist")) continue if not orig_pl or name != orig_pl.name: try: pl = smart_manager.get_playlist(name) dialogs.error( parent, _("The " "playlist name you entered is already in use.")) continue except ValueError: pass # playlist didn't exist pl = playlist.SmartPlaylist(name, collection) pl.set_or_match(matchany) pl.set_return_limit(limit) pl.set_random_sort(random) pl.set_sort_tags(*sort_tags) for item in state: (field, op) = item[0] value = item[1] pl.add_param(_NMAP[field], _TRANS[op], value) if orig_pl: smart_manager.remove_playlist(pl.name) smart_manager.save_playlist(pl) return pl
def _run_edit_selected_smart_playlist(self, dialog): '''internal helper function''' result = dialog.run() dialog.hide() pl = self.tree.get_selected_page(raw=True) if result == Gtk.ResponseType.ACCEPT: name = dialog.get_name() matchany = dialog.get_match_any() limit = dialog.get_limit() state = dialog.get_state() random = dialog.get_random() if not name: dialogs.error( self.parent, _("You did " "not enter a name for your playlist")) return False if not name == pl.name: try: pl = self.smart_manager.get_playlist(name) dialogs.error( self.parent, _("The " "playlist name you entered is already in use.")) return False except ValueError: pass # playlist didn't exist pl = playlist.SmartPlaylist(name, self.collection) pl.set_or_match(matchany) pl.set_return_limit(limit) pl.set_random_sort(random) for item in state: (field, op) = item[0] value = item[1] pl.add_param(_NMAP[field], _TRANS[op], value) self.smart_manager.remove_playlist(pl.name) self.smart_manager.save_playlist(pl) selection = self.tree.get_selection() (model, iter) = selection.get_selected() model.set_value(iter, 1, name) model.set_value(iter, 2, pl) return True
def _run_add_smart_playlist(self, dialog): '''internal helper function''' result = dialog.run() dialog.hide() if result == gtk.RESPONSE_ACCEPT: name = dialog.get_name() matchany = dialog.get_match_any() limit = dialog.get_limit() state = dialog.get_state() random = dialog.get_random() if not name: dialogs.error(self.parent, _("You did " "not enter a name for your playlist")) return False try: pl = self.smart_manager.get_playlist(name) dialogs.error(self.parent, _("The " "playlist name you entered is already in use.")) return False except ValueError: pass # playlist didn't exist pl = playlist.SmartPlaylist(name, self.collection) pl.set_or_match(matchany) pl.set_return_limit(limit) pl.set_random_sort(random) for item in state: (field, op) = item[0] value = item[1] pl.add_param(_NMAP[field], _TRANS[op], value) self.smart_manager.save_playlist(pl) self.model.append(self.smart, [self.playlist_image, name, pl]) return True