def loadArtists(self, tree, name): """ Load the given library """ libPath = os.path.join(ROOT_PATH, name) # Make sure the version number is the good one if not os.path.exists(os.path.join(libPath, 'VERSION_%u' % VERSION)): logger.error('[%s] Version number does not match, loading of library "%s" aborted' % (MOD_INFO[modules.MODINFO_NAME], name)) error = _('This library is deprecated, please refresh it.') tree.replaceContent([(icons.errorMenuIcon(), None, error, TYPE_NONE, None, None)]) return rows = [] icon = icons.dirMenuIcon() prevChar = '' allArtists = pickleLoad(os.path.join(libPath, 'artists')) self.allGenres = pickleLoad(os.path.join(libPath, 'genres')) # Filter artists by genre if needed if self.currGenre is not None: allArtists = [artist for artist in allArtists if artist[ART_NAME] in self.allGenres[self.currGenre]] rows.append((icons.infoMenuIcon(), None, '<b>%s</b>' % self.currGenre.capitalize(), TYPE_GENRE_BANNER, None, None)) else: rows.append((icons.infoMenuIcon(), None, '<b>%s</b>' % _('All genres'), TYPE_GENRE_BANNER, None, None)) # Filter artists by favorites if needed if self.showOnlyFavs: allArtists = [artist for artist in allArtists if self.isArtistInFavorites(artist[ART_NAME])] rows.append((icons.starMenuIcon(), None, '<b>%s</b>' % _('My Favorites'), TYPE_FAVORITES_BANNER, None, None)) # Create the rows for artist in allArtists: if len(artist[ART_NAME]) != 0: currChar = unicode(artist[ART_NAME], errors='replace')[0].lower() else: currChar = prevChar if prevChar != currChar and not (prevChar.isdigit() and currChar.isdigit()): prevChar = currChar if currChar.isdigit(): rows.append((None, None, '<b>0 - 9</b>', TYPE_HEADER, None, None)) else: rows.append((None, None, '<b>%s</b>' % currChar.upper(), TYPE_HEADER, None, None)) rows.append((icon, None, htmlEscape(artist[ART_NAME]), TYPE_ARTIST, os.path.join(libPath, artist[ART_INDEX]), artist[ART_NAME])) # Insert all rows, and then add a fake child to each artist tree.replaceContent(rows) for node in tree.iterChildren(None): if tree.getItem(node, ROW_TYPE) == TYPE_ARTIST: tree.appendRow(FAKE_CHILD, node)
def onSearchEnd(self): self._remove_searching_node() if len(self.tree) == 0: if self.music_paths: text = _('No tracks found') else: text = _('No music folders have been added') self.tree.appendRow((icons.infoMenuIcon(), text, TYPE_INFO, ''), None) return
def onSearchStart(self, query): if not self.displaying_results: self.saveTreeState() self.tree.clear() self.displaying_results = True self.searching_text = _('Searching ...') self.searching_text_path = self.tree.appendRow((icons.infoMenuIcon(), self.searching_text, TYPE_INFO, ''), None)
def set_info_text(self): """ Append an item that explains how to add music folders if no music folders are present. Remove the item if music folders are set. """ music_paths = self.get_music_paths_from_tree() last_top_node = self.tree.getChild(None, self.tree.getNbChildren(None) - 1) path = self.tree.getItem(last_top_node, ROW_FULLPATH) typ = self.tree.getItem(last_top_node, ROW_TYPE) last_top_node_info = (typ == TYPE_INFO) and not path if music_paths: for child in reversed(list(self.tree.iterChildren(None))): path = self.tree.getItem(child, ROW_FULLPATH) typ = self.tree.getItem(child, ROW_TYPE) info_node = (typ == TYPE_INFO) and not path if info_node: self.tree.removeRow(child) elif not music_paths and not last_top_node_info: msg = _('Right-click to add music folders') self.tree.appendRow((icons.infoMenuIcon(), msg, TYPE_INFO, ''), None)