def loadAlbums(self, tree, node, fakeChild): """ Initial load of the albums of the given node, assuming it is of type TYPE_ARTIST """ rows = [] path = tree.getItem(node, ROW_FULLPATH) artist = tree.getItem(node, ROW_DATA) allAlbums = pickleLoad(os.path.join(tree.getItem(node, ROW_FULLPATH), 'albums')) # Filter albums if only favorites should be shown if self.showOnlyFavs: allAlbums = [album for album in allAlbums if self.isAlbumInFavorites(artist, album[ALB_NAME])] # Filter artists by genre if needed if self.currGenre is not None: allAlbums = [album for album in allAlbums if album[ALB_NAME] in self.allGenres[self.currGenre][artist]] # The icon depends on whether the album is in the favorites for album in allAlbums: if self.isAlbumInFavorites(artist, album[ALB_NAME]): icon = icons.starDirMenuIcon() else: icon = icons.mediaDirMenuIcon() rows.append((icon, '[%s]' % tools.sec2str(album[ALB_LENGTH], True), '%s' % htmlEscape(album[ALB_NAME]), TYPE_ALBUM, os.path.join(path, album[ALB_INDEX]), album[ALB_NAME])) # Add all the rows, and then add a fake child to each of them tree.appendRows(rows, node) tree.removeRow(fakeChild) for child in tree.iterChildren(node): tree.appendRow(FAKE_CHILD, child)
def switchFavoriteStateOfSelectedItems(self, tree): """ Add to/remove from favorites the selected items """ # Go through selected items and switch their state removed = False for path in tree.getSelectedPaths(): if tree.getItem(path, ROW_TYPE) == TYPE_ALBUM: album = tree.getItem(path, ROW_DATA) artist = tree.getItem(path[:-1], ROW_DATA) if self.isAlbumInFavorites(artist, album): removed = True tree.setItem(path, ROW_PIXBUF, icons.mediaDirMenuIcon()) self.removeFromFavorites(artist, album) else: tree.setItem(path, ROW_PIXBUF, icons.starDirMenuIcon()) self.addToFavorites(artist, album) # If some favorites were removed, we may have to reload the tree if self.showOnlyFavs and removed: self.saveTreeState() self.loadArtists(self.tree, self.currLib) self.restoreTreeState()