Exemplo n.º 1
0
 def _window_response(self, window, response):
     if response == Gtk.ResponseType.CLOSE:
         self.last_tab = self.prefsnotebook.get_current_page()
         #XXX: These two are probably never triggered
         if self.config.show_lyrics and self.config.lyrics_location != consts.LYRICS_LOCATION_HOME:
             if not os.path.isdir(self.config.musicdir[self.config.profile_num]):
                 ui.show_msg(self.window, _("To save lyrics to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE)
                 # Set music_dir entry focused:
                 self.prefsnotebook.set_current_page(0)
                 self.direntry.grab_focus()
                 return
         if self.config.show_covers and self.config.art_location != consts.ART_LOCATION_HOMECOVERS:
             if not os.path.isdir(self.config.musicdir[self.config.profile_num]):
                 ui.show_msg(self.window, _("To save artwork to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE)
                 # Set music_dir entry focused:
                 self.prefsnotebook.set_current_page(0)
                 self.direntry.grab_focus()
                 return
         if not self.using_mpd_env_vars:
             if self.prev_host != self.config.host[self.config.profile_num] or self.prev_port != self.config.port[self.config.profile_num] or self.prev_password != self.config.password[self.config.profile_num]:
                 # Try to connect if mpd connection info has been updated:
                 ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
                 self.reconnect()
         self.settings_save()
         self.populate_profiles_for_menu()
         ui.change_cursor(None)
     window.destroy()
Exemplo n.º 2
0
 def _window_response(self, window, response):
     if response == Gtk.ResponseType.CLOSE:
         self.last_tab = self.prefsnotebook.get_current_page()
         #XXX: These two are probably never triggered
         if self.config.show_lyrics and self.config.lyrics_location != consts.LYRICS_LOCATION_HOME:
             if not os.path.isdir(misc.file_from_utf8(self.config.musicdir[self.config.profile_num])):
                 ui.show_msg(self.window, _("To save lyrics to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE)
                 # Set music_dir entry focused:
                 self.prefsnotebook.set_current_page(0)
                 self.direntry.grab_focus()
                 return
         if self.config.show_covers and self.config.art_location != consts.ART_LOCATION_HOMECOVERS:
             if not os.path.isdir(misc.file_from_utf8(self.config.musicdir[self.config.profile_num])):
                 ui.show_msg(self.window, _("To save artwork to the music file's directory, you must specify a valid music directory."), _("Music Dir Verification"), 'musicdirVerificationError', Gtk.ButtonsType.CLOSE)
                 # Set music_dir entry focused:
                 self.prefsnotebook.set_current_page(0)
                 self.direntry.grab_focus()
                 return
         if not self.using_mpd_env_vars:
             if self.prev_host != self.config.host[self.config.profile_num] or self.prev_port != self.config.port[self.config.profile_num] or self.prev_password != self.config.password[self.config.profile_num]:
                 # Try to connect if mpd connection info has been updated:
                 ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
                 self.reconnect()
         self.settings_save()
         self.populate_profiles_for_menu()
         ui.change_cursor(None)
     window.destroy()
Exemplo n.º 3
0
    def current_update(self, prevstatus_playlist, new_playlist_length):
        if self.connected():
            self.view.freeze_child_notify()
            self.unbold_boldrow(self.prev_boldrow)

            if not self.update_skip:
                save_model = self.view.get_model()
                self.view.set_model(None)
                if prevstatus_playlist:
                    changed_songs = self.mpd.plchanges(prevstatus_playlist)
                else:
                    changed_songs = self.mpd.plchanges(0)


                newlen = int(new_playlist_length)
                currlen = len(self.store)

                for track in changed_songs:
                    pos = track.pos

                    items = [formatting.parse(part, track, True)
                             for part in self.columnformat]

                    if pos < currlen:
                        # Update attributes for item:
                        i = self.store.get_iter((pos, ))
                        if track.id != self.store.get_value(i, 0).id:
                            self.store.set_value(i, 0, track)
                        for index in range(len(items)):
                            if items[index] != self.store.get_value(i, index+1):
                                self.store.set_value(i, index + 1, items[index])
                    else:
                        # Add new item:
                        self.store.append(
                            [track] + items + [Pango.Weight.NORMAL])

                if newlen == 0:
                    self.store.clear()
                else:
                    # Remove excess songs:
                    for i in range(currlen - newlen):
                        it = self.store.get_iter((currlen - 1 - i,))
                        self.store.remove(it)

                self.view.set_model(save_model)
            self.update_skip = False

            # Update statusbar time:
            self.total_time = sum(item[0].time for item in self.store)

            if 'pos' in self.songinfo():
                currsong = self.songinfo().pos
                self.boldrow(currsong)
                self.prev_boldrow = currsong

            self.view.thaw_child_notify()
            self.header_update_column_indicators()
            self.update_statusbar()
            ui.change_cursor(None)
Exemplo n.º 4
0
    def download_progress(self, dest_filename_curr, i):
        # This populates Main.imagelist for the remote image window
        if os.path.exists(dest_filename_curr):
            pix = GdkPixbuf.Pixbuf.new_from_file(dest_filename_curr)
            pix = pix.scale_simple(148, 148, GdkPixbuf.InterpType.HYPER)
            pix = img.do_style_cover(self.config, pix, 148, 148)
            pix = img.pixbuf_add_border(pix)
            if self.stop_art_update:
                del pix
                return False # don't continue to next image
            self.imagelist_append([i + 1, pix])
            del pix
            self.remotefilelist_append(dest_filename_curr)
            if i == 0:
                self.allow_art_search()

            ui.change_cursor(None)

        return True # continue to next image
Exemplo n.º 5
0
    def download_progress(self, dest_filename_curr, i):
        # This populates Main.imagelist for the remote image window
        if os.path.exists(dest_filename_curr):
            pix = GdkPixbuf.Pixbuf.new_from_file(dest_filename_curr)
            pix = pix.scale_simple(148, 148, GdkPixbuf.InterpType.HYPER)
            pix = img.do_style_cover(self.config, pix, 148, 148)
            pix = img.pixbuf_add_border(pix)
            if self.stop_art_update:
                del pix
                return False  # don't continue to next image
            self.imagelist_append([i + 1, pix])
            del pix
            self.remotefilelist_append(dest_filename_curr)
            if i == 0:
                self.allow_art_search()

            ui.change_cursor(None)

        return True  # continue to next image
Exemplo n.º 6
0
    def current_update(self, prevstatus_playlist, new_playlist_length):
        if self.connected():

            if self.sonata_loaded():
                playlistposition = self.current.get_visible_rect().height

            self.current.freeze_child_notify()

            if not self.current_update_skip:

                if not self.filterbox_visible:
                    self.current.set_model(None)

                if prevstatus_playlist:
                    changed_songs = self.mpd.plchanges(prevstatus_playlist)
                else:
                    changed_songs = self.mpd.plchanges(0)
                    self.current_songs = []

                newlen = int(new_playlist_length)
                currlen = len(self.currentdata)

                for track in changed_songs:
                    pos = track.pos

                    items = [formatting.parse(part, track,
                                  True)
                         for part in self.columnformat]

                    if pos < currlen:
                        # Update attributes for item:
                        i = self.currentdata.get_iter((pos, ))
                        if track.id != self.currentdata.get_value(i, 0):
                            self.currentdata.set_value(i, 0, track.id)
                        for index in range(len(items)):
                            if items[index] != self.currentdata.get_value(i,
                                                                    index + 1):
                                self.currentdata.set_value(i, index + 1,
                                                           items[index])
                        self.current_songs[pos] = track
                    else:
                        # Add new item:
                        self.currentdata.append([track.id] + items +
                                                [Pango.Weight.NORMAL])
                        self.current_songs.append(track)

                if newlen == 0:
                    self.currentdata.clear()
                    self.current_songs = []
                else:
                    # Remove excess songs:
                    for i in range(currlen - newlen):
                        it = self.currentdata.get_iter((currlen - 1 - i,))
                        self.currentdata.remove(it)
                    self.current_songs = self.current_songs[:newlen]

                if not self.filterbox_visible:
                    self.current.set_model(self.currentdata)

            self.current_update_skip = False

            # Update statusbar time:
            self.total_time = sum(t.time for t in self.current_songs)

            if 'pos' in self.songinfo():
                currsong = self.songinfo().pos
                self.boldrow(currsong)
                self.prev_boldrow = currsong

            if self.filterbox_visible:
                # Refresh filtered results:
                # Hacky, but this ensures we retain the
                # self.current position/selection
                self.prevtodo = "RETAIN_POS_AND_SEL"
                self.plpos = playlistposition
                self.searchfilter_feed_loop(self.filterpattern)
            elif self.sonata_loaded():
                self.playlist_retain_view(self.current, playlistposition)
                self.current.thaw_child_notify()

            self.header_update_column_indicators()
            self.update_statusbar()
            ui.change_cursor(None)
Exemplo n.º 7
0
 def on_link_leave(self, _widget, _event):
     ui.change_cursor(None)
Exemplo n.º 8
0
 def on_link_enter(self, widget, _event):
     ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.HAND2))
Exemplo n.º 9
0
    def current_update(self, prevstatus_playlist, new_playlist_length):
        if self.connected():
            self.view.freeze_child_notify()
            self.unbold_boldrow(self.prev_boldrow)

            if not self.update_skip:
                save_model = self.view.get_model()
                self.view.set_model(None)
                if prevstatus_playlist:
                    changed_songs = self.mpd.plchanges(prevstatus_playlist)
                else:
                    changed_songs = self.mpd.plchanges(0)

                newlen = int(new_playlist_length)
                currlen = len(self.store)

                for track in changed_songs:
                    pos = track.pos

                    items = [
                        formatting.parse(part, track, True)
                        for part in self.columnformat
                    ]

                    if pos < currlen:
                        # Update attributes for item:
                        i = self.store.get_iter((pos, ))
                        if track.id != self.store.get_value(i, 0).id:
                            self.store.set_value(i, 0, track)
                        for index in range(len(items)):
                            if items[index] != self.store.get_value(
                                    i, index + 1):
                                self.store.set_value(i, index + 1,
                                                     items[index])
                    else:
                        # Add new item:
                        self.store.append([track] + items +
                                          [Pango.Weight.NORMAL])

                if newlen == 0:
                    self.store.clear()
                else:
                    # Remove excess songs:
                    for i in range(currlen - newlen):
                        it = self.store.get_iter((currlen - 1 - i, ))
                        self.store.remove(it)

                self.view.set_model(save_model)
            self.update_skip = False

            # Update statusbar time:
            self.total_time = sum(item[0].time for item in self.store)

            if 'pos' in self.songinfo():
                currsong = self.songinfo().pos
                self.boldrow(currsong)
                self.prev_boldrow = currsong

            self.view.thaw_child_notify()
            self.header_update_column_indicators()
            self.update_statusbar()
            ui.change_cursor(None)
Exemplo n.º 10
0
 def on_link_leave(self, _widget, _event):
     ui.change_cursor(None)
Exemplo n.º 11
0
 def on_link_enter(self, widget, _event):
     ui.change_cursor(Gdk.Cursor.new(Gdk.CursorType.HAND2))
Exemplo n.º 12
0
    def on_tags_edit(self, files, temp_mpdpaths, music_dir):
        """Display the editing dialog"""
        # Try loading module
        global tagpy
        if tagpy is None:
            try:
                import tagpy
            except ImportError:
                ui.show_msg(
                    self.window,
                    _("Taglib and/or tagpy not found, tag editing support disabled."
                      ),
                    _("Edit Tags"),
                    'editTagsError',
                    Gtk.ButtonsType.CLOSE,
                    response_cb=ui.dialog_destroy)
                ui.change_cursor(None)
                return
            # Set default tag encoding to utf8.. fixes some reported bugs.
            import tagpy.id3v2 as id3v2
            id3v2.FrameFactory.instance().setDefaultTextEncoding(
                tagpy.StringType.UTF8)

        # Make sure tagpy is at least 0.91
        if hasattr(tagpy.Tag.title, '__call__'):
            ui.show_msg(
                self.window,
                _("Tagpy version < 0.91. Please upgrade to a newer version, tag editing support disabled."
                  ),
                _("Edit Tags"),
                'editTagsError',
                Gtk.ButtonsType.CLOSE,
                response_cb=ui.dialog_destroy)
            ui.change_cursor(None)
            return

        if not os.path.isdir(music_dir):
            ui.show_msg(
                self.window,
                _("The path %s does not exist. Please specify a valid music directory in preferences."
                  ) % music_dir,
                _("Edit Tags"),
                'editTagsError',
                Gtk.ButtonsType.CLOSE,
                response_cb=ui.dialog_destroy)
            ui.change_cursor(None)
            return

            # XXX file list was created here

        if len(files) == 0:
            ui.change_cursor(None)
            return

        # Initialize:
        self.tagnum = -1

        self.tags = [{
            'title': '',
            'artist': '',
            'album': '',
            'year': '',
            'track': '',
            'genre': '',
            'comment': '',
            'title-changed': False,
            'artist-changed': False,
            'album-changed': False,
            'year-changed': False,
            'track-changed': False,
            'genre-changed': False,
            'comment-changed': False,
            'fullpath': filename,
            'mpdpath': path,
        } for filename, path in zip(files, temp_mpdpaths)]

        if not os.path.exists(self.tags[0]['fullpath']):
            ui.change_cursor(None)
            ui.show_msg(
                self.window,
                _("File '%s' not found. Please specify a valid music directory in preferences."
                  ) % self.tags[0]['fullpath'],
                _("Edit Tags"),
                'editTagsError',
                Gtk.ButtonsType.CLOSE,
                response_cb=ui.dialog_destroy)
            return
        if not self.tags_next_tag():
            ui.change_cursor(None)
            ui.show_msg(self.window,
                        _("No music files with editable tags found."),
                        _("Edit Tags"),
                        'editTagsError',
                        Gtk.ButtonsType.CLOSE,
                        response_cb=ui.dialog_destroy)
            return
        if not self.edit_window:
            self._init_edit_window()

        saveall_button = self.builder.get_object('tags_saveall_button')
        if len(files) > 1:
            # Only show save all button if more than one song being edited.
            saveall_button.show()
            saveall_button.set_property("visible", True)
        else:
            saveall_button.hide()
            saveall_button.set_property("visible", False)

        self.tags_win_update()
        self.edit_window.show_all()
        SAVE_ALL = -12
        done = False

        while not done:
            # Next file:
            self.tags_win_update()
            response = self.edit_window.run()
            if response == SAVE_ALL:
                self.save_tag()
                while self.tags_next_tag():
                    self.tags_win_update()
                    self.save_tag()
                done = True
            elif response == Gtk.ResponseType.ACCEPT:
                self.save_tag()
                done = not self.tags_next_tag()
                if done:
                    # To ensure we update the last file in tags_mpd_update
                    self.tagnum = self.tagnum + 1
            elif response == Gtk.ResponseType.REJECT:
                done = True

        tag_paths = (tag['mpdpath'] for tag in self.tags[:self.tagnum])
        GLib.idle_add(self.tags_mpd_update, tag_paths)
        self.tags_set_use_mpdpath(self.use_mpdpaths)

        self.tags = None
        ui.change_cursor(None)
        self.edit_window.hide()
Exemplo n.º 13
0
    def on_tags_edit(self, files, temp_mpdpaths, music_dir):
        """Display the editing dialog"""
        # Try loading module
        global tagpy
        if tagpy is None:
            try:
                import tagpy
            except ImportError:
                ui.show_msg(self.window, _("Taglib and/or tagpy not found, tag editing support disabled."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
                ui.change_cursor(None)
                return
            # Set default tag encoding to utf8.. fixes some reported bugs.
            import tagpy.id3v2 as id3v2
            id3v2.FrameFactory.instance().setDefaultTextEncoding(tagpy.StringType.UTF8)

        # Make sure tagpy is at least 0.91
        if hasattr(tagpy.Tag.title, '__call__'):
            ui.show_msg(self.window, _("Tagpy version < 0.91. Please upgrade to a newer version, tag editing support disabled."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
            ui.change_cursor(None)
            return

        if not os.path.isdir(misc.file_from_utf8(music_dir)):
            ui.show_msg(self.window, _("The path %s does not exist. Please specify a valid music directory in preferences.") % music_dir, _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
            ui.change_cursor(None)
            return

                # XXX file list was created here

        if len(files) == 0:
            ui.change_cursor(None)
            return

        # Initialize:
        self.tagnum = -1

        self.tags = [{
             'title': '', 'artist': '', 'album': '', 'year': '', 'track': '',
             'genre': '', 'comment': '', 'title-changed': False,
             'artist-changed': False, 'album-changed': False,
             'year-changed': False, 'track-changed': False,
             'genre-changed': False, 'comment-changed': False,
             'fullpath': misc.file_from_utf8(filename),
             'mpdpath': path,}
            for filename, path in zip(files, temp_mpdpaths)]

        if not os.path.exists(self.tags[0]['fullpath']):
            ui.change_cursor(None)
            ui.show_msg(self.window, _("File '%s' not found. Please specify a valid music directory in preferences.") % self.tags[0]['fullpath'], _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
            return
        if not self.tags_next_tag():
            ui.change_cursor(None)
            ui.show_msg(self.window, _("No music files with editable tags found."), _("Edit Tags"), 'editTagsError', Gtk.ButtonsType.CLOSE, response_cb=ui.dialog_destroy)
            return
        if not self.edit_window:
            self._init_edit_window()

        saveall_button = self.builder.get_object('tags_saveall_button')
        if len(files) > 1:
            # Only show save all button if more than one song being edited.
            saveall_button.show()
            saveall_button.set_property("visible", True)
        else:
            saveall_button.hide()
            saveall_button.set_property("visible", False)

        self.tags_win_update()
        self.edit_window.show_all()
        SAVE_ALL = -12
        done = False

        while not done:
            # Next file:
            self.tags_win_update()
            response = self.edit_window.run()
            if response == SAVE_ALL:
                self.save_tag()
                while self.tags_next_tag():
                    self.tags_win_update()
                    self.save_tag()
                done = True
            elif response == Gtk.ResponseType.ACCEPT:
                self.save_tag()
                done = not self.tags_next_tag()
                if done:
                    # To ensure we update the last file in tags_mpd_update
                    self.tagnum = self.tagnum + 1
            elif response == Gtk.ResponseType.REJECT:
                done = True

        tag_paths = (tag['mpdpath'] for tag in self.tags[:self.tagnum])
        GLib.idle_add(self.tags_mpd_update, tag_paths)
        self.tags_set_use_mpdpath(self.use_mpdpaths)

        self.tags = None
        ui.change_cursor(None)
        self.edit_window.hide()