def on_genre_view_selection_changed(self, view):
        '''
        action when user selects a row in the list of genres
        '''
        model, genre_iter = view.get_selected()
        if genre_iter:
            self.genre_entry.set_text(model[genre_iter][0])
            index = model[genre_iter][2]
            if index != '':
                self.genre_combobox.set_active_iter(self._iters[(index, self.GENRE_POPUP)])
                self.amend_mode = True
                self.current_genre = rb3compat.unicodestr(model[genre_iter][0], 'utf-8')
        else:
            self.genre_entry.set_text('')
            self.genre_combobox.set_active_iter(None)
            self.amend_mode = False

        if self.blank_iter and self.amend_mode:
            try:
                index = model[self.blank_iter][0]
                if index == '':
                    model.remove(self.blank_iter)
                    self.blank_iter = None
            except:
                self.blank_iter = None
    def amend_genre_info(self, current_genre, new_genre, icon_name):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        if current_genre != "":
            for elem in root.xpath(base):
                if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                    found = True
                    del self.genre_alternate[GenreType(
                        name=elem.text, genre_type=self.GENRE_USER)]
                    break

        else:
            elem = ET.SubElement(
                root.xpath(self._sprite_name + '/alt')[0], "alt")
            if elem != None:
                found = True

        if found:
            elem.text = rb3compat.unicodestr(new_genre, 'utf-8')
            elem.attrib['genre'] = icon_name

            tree = ET.ElementTree(root)
            tree.write(self._user_popups,
                       pretty_print=True,
                       xml_declaration=True)
            self.genre_alternate[GenreType(
                name=elem.text, genre_type=self.GENRE_USER)] = icon_name
            return GenreType(name=elem.text, genre_type=self.GENRE_USER)
        else:
            print("nothing found to amend")
            return None
    def playlist_fillmenu(self, popup_menu, menubar, section_name,
        actiongroup, func, favourite=False):
        print("CoverArtBrowser DEBUG - playlist_fillmenu")

        playlist_manager = self.shell.props.playlist_manager
        playlists_entries = playlist_manager.get_playlists()

        # tidy up old playlists menu items before recreating the list
        actiongroup.remove_actions()
        popup_menu.remove_menu_items(menubar, section_name)

        if playlists_entries:
            for playlist in playlists_entries:
                if playlist.props.is_local and \
                    isinstance(playlist, RB.StaticPlaylistSource):

                    args=(playlist, favourite)
                    
                    # take the name of the playlist, strip out non-english characters and reduce the string
                    # to just a-to-z characters i.e. this will make the action_name valid in RB3
                    
                    ascii_name = unicodedata.normalize('NFKD', \
                        rb3compat.unicodestr(playlist.props.name, 'utf-8')).encode('ascii','ignore')
                    ascii_name = ascii_name.decode(encoding='UTF-8')
                    ascii_name = re.sub(r'[^a-zA-Z]', '', ascii_name)
                    action = actiongroup.add_action(func=func,
                        action_name=ascii_name,
                        playlist=playlist,favourite=favourite,
                        label=playlist.props.name)
                        
                    popup_menu.add_menu_item( menubar, section_name,
                        action )
    def amend_genre_info(self, current_genre, new_genre, icon_name):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        if current_genre != "":
            for elem in root.xpath(base):
                if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                    found = True
                    del self.genre_alternate[GenreType(name=elem.text, genre_type=self.GENRE_USER)]
                    break

        else:
            elem = ET.SubElement(root.xpath(self._sprite_name + '/alt')[0], "alt")
            if elem != None:
                found = True

        if found:
            elem.text = rb3compat.unicodestr(new_genre, 'utf-8')
            elem.attrib['genre'] = icon_name

            tree = ET.ElementTree(root)
            tree.write(self._user_popups, pretty_print=True, xml_declaration=True)
            self.genre_alternate[GenreType(name=elem.text, genre_type=self.GENRE_USER)] = icon_name
            return GenreType(name=elem.text, genre_type=self.GENRE_USER)
        else:
            print("nothing found to amend")
            return None
Example #5
0
    def set_save_sensitivity(self, _):
        '''
        action to toggle the state of the save button depending
        upon the values entered in the genre edit fields
        '''
        entry_value = self.genre_entry.get_text()
        treeiter = self.genre_combobox.get_active_iter()

        entry_value = rb3compat.unicodestr(entry_value, 'utf-8')
        enable = False
        try:
            test = self._iters[(entry_value, self.GENRE_LIST)]
            if RB.search_fold(
                    self.current_genre) == RB.search_fold(entry_value):
                # if the current entry is the same then could save
                enable = True
        except:
            # reach here if this is a brand new entry
            enable = True

        if treeiter == None or entry_value == None or entry_value == "":
            # no icon chosen, or no entry value then nothing to save
            enable = False

        self.save_button.set_sensitive(enable)
Example #6
0
    def on_genre_view_selection_changed(self, view):
        '''
        action when user selects a row in the list of genres
        '''
        model, genre_iter = view.get_selected()
        if genre_iter:
            self.genre_entry.set_text(model[genre_iter][0])
            index = model[genre_iter][2]
            if index != '':
                self.genre_combobox.set_active_iter(
                    self._iters[(index, self.GENRE_POPUP)])
                self.amend_mode = True
                self.current_genre = rb3compat.unicodestr(
                    model[genre_iter][0], 'utf-8')
        else:
            self.genre_entry.set_text('')
            self.genre_combobox.set_active_iter(None)
            self.amend_mode = False

        if self.blank_iter and self.amend_mode:
            try:
                index = model[self.blank_iter][0]
                if index == '':
                    model.remove(self.blank_iter)
                    self.blank_iter = None
            except:
                self.blank_iter = None
Example #7
0
    def do_search(self, coverobject, callback):
        '''
        When this method is called, the webview gets refreshed with the info
        of the album or artist passed.
        
        '''
        print("coverart-search do_search")
        if coverobject is self.current_searchobject:
            return

        self.current_searchobject = coverobject
        self.callback = callback

        if isinstance(coverobject, Album):
            artist = coverobject.artist
            album_name = coverobject.name

            if album_name.upper() == "UNKNOWN":
                album_name = ""

            if artist.upper() == "UNKNOWN":
                artist = ""

            if not (album_name == "" and artist == ""):
                artist = rb3compat.unicodestr(artist.replace('&', '&'),
                                              'utf-8')
                album_name = rb3compat.unicodestr(
                    album_name.replace('&', '&'), 'utf-8')
                self.render_album_art_search(artist, album_name)
        else:
            artist_name = coverobject.name

            if artist_name.upper() == "UNKNOWN":
                artist_name = ""

            if not (artist_name == ""):
                artist = rb3compat.unicodestr(
                    artist_name.replace('&', '&'), 'utf-8')
                self.render_artist_art_search(artist)
    def do_search(self, coverobject, callback):
        '''
        When this method is called, the webview gets refreshed with the info
        of the album or artist passed.
        
        '''
        print ("coverart-search do_search")
        if coverobject is self.current_searchobject:
            return

        self.current_searchobject = coverobject
        self.callback = callback
        
        if isinstance(coverobject, Album):
            artist = coverobject.artist
            album_name = coverobject.name

            if album_name.upper() == "UNKNOWN":
                album_name = ""

            if artist.upper() == "UNKNOWN":
                artist = ""

            if not(album_name == "" and artist == ""):
                artist = rb3compat.unicodestr(artist.replace('&', '&'),
                    'utf-8')
                album_name = rb3compat.unicodestr(album_name.replace('&', '&'), 'utf-8')
                self.render_album_art_search(artist, album_name)
        else:
            artist_name = coverobject.name

            if artist_name.upper() == "UNKNOWN":
                artist_name = ""

            if not(artist_name == ""):
                artist = rb3compat.unicodestr(artist_name.replace('&', '&'),
                    'utf-8')
                self.render_artist_art_search(artist)
    def do_search(self, album):
        '''
        When this method is called, the webview gets refreshed with the info
        of the album passed.
        '''
        if album is self.current_album:
            return

        self.current_album = album

        artist = album.artist
        album_name = album.name

        if album_name.upper() == "UNKNOWN":
            album_name = ""

        if artist.upper() == "UNKNOWN":
            artist = ""

        if not(album_name == "" and artist == ""):
            artist = rb3compat.unicodestr(artist.replace('&', '&'),
                'utf-8')
            album_name = rb3compat.unicodestr(album_name.replace('&', '&'), 'utf-8')
            self.render_album_art_search(artist, album_name)
    def on_delete_button_clicked(self, button):
        '''
        action when a genre is to be deleted
        '''
        selection = self.genre_view.get_selection()

        model, genre_iter = selection.get_selected()
        if genre_iter:
            index = rb3compat.unicodestr(model[genre_iter][0], 'utf-8')
            model.remove(genre_iter)

            if index:
                del self._iters[(index, self.GENRE_LIST)]
                self._sheet.delete_genre(index)

                self._toggle_new_genre_state()
Example #11
0
    def on_delete_button_clicked(self, button):
        '''
        action when a genre is to be deleted
        '''
        selection = self.genre_view.get_selection()

        model, genre_iter = selection.get_selected()
        if genre_iter:
            index = rb3compat.unicodestr(model[genre_iter][0], 'utf-8')
            model.remove(genre_iter)

            if index:
                del self._iters[(index, self.GENRE_LIST)]
                self._sheet.delete_genre(index)

                self._toggle_new_genre_state()
Example #12
0
    def _generate_album_values(self, album):
        tooltip = album.name
        pixbuf = album.cover.pixbuf.scale_simple(48, 48,
                                                 GdkPixbuf.InterpType.BILINEAR)
        show = True

        rating = album.rating
        if int(rating) > 0:
            rating = u'\u2605' * int(rating)
        else:
            rating = ''

        year = ' (' + str(album.real_year) + ')'

        track_count = album.track_count
        if track_count == 1:
            detail = rb3compat.unicodedecode(_(' with 1 track'), 'UTF-8')
        else:
            detail = rb3compat.unicodedecode(
                _(' with %d tracks') % track_count, 'UTF-8')

        duration = album.duration / 60

        if duration == 1:
            detail += rb3compat.unicodedecode(_(' and a duration of 1 minute'),
                                              'UTF-8')
        else:
            detail += rb3compat.unicodedecode(
                _(' and a duration of %d minutes') % duration, 'UTF-8')

        tooltip = rb3compat.unicodestr(tooltip, 'utf-8')
        tooltip = rb3compat.unicodeencode(tooltip, 'utf-8')
        import cgi

        formatted = '<b><i>' + \
                    cgi.escape(rb3compat.unicodedecode(tooltip, 'utf-8')) + \
                    '</i></b>' + \
                    year + \
                    ' ' + rating + \
                    '\n<small>' + \
                    GLib.markup_escape_text(detail) + \
                    '</small>'

        return tooltip, pixbuf, album, show, '', formatted, ''
    def _generate_album_values(self, album):
        tooltip = album.name
        pixbuf = album.cover.pixbuf.scale_simple(48, 48, GdkPixbuf.InterpType.BILINEAR)
        show = True

        rating = album.rating
        if int(rating) > 0:
            rating = u'\u2605' * int(rating)
        else:
            rating = ''

        year = ' (' + str(album.real_year) + ')'

        track_count = album.track_count
        if track_count == 1:
            detail = rb3compat.unicodedecode(_(' with 1 track'), 'UTF-8')
        else:
            detail = rb3compat.unicodedecode(_(' with %d tracks') %
                                             track_count, 'UTF-8')

        duration = album.duration / 60

        if duration == 1:
            detail += rb3compat.unicodedecode(_(' and a duration of 1 minute'), 'UTF-8')
        else:
            detail += rb3compat.unicodedecode(_(' and a duration of %d minutes') %
                                              duration, 'UTF-8')

        tooltip = rb3compat.unicodestr(tooltip, 'utf-8')
        tooltip = rb3compat.unicodeencode(tooltip, 'utf-8')
        import cgi

        formatted = '<b><i>' + \
                    cgi.escape(rb3compat.unicodedecode(tooltip, 'utf-8')) + \
                    '</i></b>' + \
                    year + \
                    ' ' + rating + \
                    '\n<small>' + \
                    GLib.markup_escape_text(detail) + \
                    '</small>'

        return tooltip, pixbuf, album, show, '', formatted, ''
    def playlist_fillmenu(self,
                          popup_menu,
                          menubar,
                          section_name,
                          actiongroup,
                          func,
                          favourite=False):
        print("CoverArtBrowser DEBUG - playlist_fillmenu")

        playlist_manager = self.shell.props.playlist_manager
        playlists_entries = playlist_manager.get_playlists()

        # tidy up old playlists menu items before recreating the list
        actiongroup.remove_actions()
        popup_menu.remove_menu_items(menubar, section_name)

        if playlists_entries:
            for playlist in playlists_entries:
                if playlist.props.is_local and \
                    isinstance(playlist, RB.StaticPlaylistSource):

                    args = (playlist, favourite)

                    # take the name of the playlist, strip out non-english characters and reduce the string
                    # to just a-to-z characters i.e. this will make the action_name valid in RB3

                    ascii_name = unicodedata.normalize('NFKD', \
                        rb3compat.unicodestr(playlist.props.name, 'utf-8')).encode('ascii','ignore')
                    ascii_name = ascii_name.decode(encoding='UTF-8')
                    ascii_name = re.sub(r'[^a-zA-Z]', '', ascii_name)
                    action = actiongroup.add_action(func=func,
                                                    action_name=ascii_name,
                                                    playlist=playlist,
                                                    favourite=favourite,
                                                    label=playlist.props.name)

                    popup_menu.add_menu_item(menubar, section_name, action)
    def set_save_sensitivity(self, _):
        '''
        action to toggle the state of the save button depending
        upon the values entered in the genre edit fields
        '''
        entry_value = self.genre_entry.get_text()
        treeiter = self.genre_combobox.get_active_iter()

        entry_value = rb3compat.unicodestr(entry_value, 'utf-8')
        enable = False
        try:
            test = self._iters[(entry_value, self.GENRE_LIST)]
            if RB.search_fold(self.current_genre) == RB.search_fold(entry_value):
                #if the current entry is the same then could save
                enable = True
        except:
            # reach here if this is a brand new entry
            enable = True

        if treeiter == None or entry_value == None or entry_value == "":
            # no icon chosen, or no entry value then nothing to save
            enable = False

        self.save_button.set_sensitive(enable)