Example #1
0
def next_track():
    """
    Play the next track of the current book.
    Stops playback if there isn't any.
    """
    global __current_track

    album_tracks = db.tracks(get_current_track().book)
    current = get_current_track()
    index = list(album_tracks).index(current)
    next_track = None
    if index + 1 < len(album_tracks):
        next_track = album_tracks[index + 1]

    play_pause(None)
    save_current_track_position(0)

    if next_track is not None:
        save_current_book_position(next_track)
        play_pause(next_track)
    else:
        stop()
        save_current_book_position(current, 0)
        __player.set_state(Gst.State.NULL)
        __current_track = None
        db.Settings.update(last_played_book=None).execute()
        emit_event("stop")
Example #2
0
def prev_track():
    """
    Play the previous track of the current book.
    Plays the same track again when it is the first of the book.
    """
    global __player
    global __current_track
    album_tracks = db.tracks(get_current_track().book)
    current = get_current_track()
    index = list(album_tracks).index(current)
    previous = None
    if index > -1:
        previous = album_tracks[index - 1]

    save_current_track_position()

    if previous is not None:
        save_current_book_position(previous)
        play_pause(previous)
    else:
        first_track = __current_track
        __player.set_state(Gst.State.NULL)
        __current_track = None
        play_pause(first_track)
        save_current_book_position(current, 0)
Example #3
0
 def __jump_to_folder(self, widget, parameter):
     """
     Opens the folder containing this books files in the default file explorer.
     """
     track = db.tracks(self.book).first()
     path = os.path.dirname(track.file)
     subprocess.Popen(['xdg-open', path])
Example #4
0
def next_track():
    """
    Play the next track of the current book.
    Stops playback if there isn't any.
    """
    global __current_track
    global __play_next

    album_tracks = db.tracks(get_current_track().book)
    current = get_current_track()
    index = list(album_tracks).index(current)
    next_track = None
    if index + 1 < len(album_tracks):
        next_track = album_tracks[index + 1]

    play_pause(None)
    save_current_track_position(0)

    if next_track:
        save_current_book_position(next_track)
        save_current_track_position(0, next_track)
        if __play_next:
            play_pause(next_track)
        else:
            load_file(next_track)
            __play_next = True
    else:
        stop()
        save_current_book_position(current, -1)
        unload()
        db.Settings.update(last_played_book=None).execute()
        emit_event("stop")
Example #5
0
 def __on_storage_changed(self, event, message):
     """
     """
     if (event == "storage-online" and not super().get_sensitive()) or event == "external-storage-removed":
         if message in db.tracks(self.book).first().file:
             super().set_sensitive(True)
             self.box.set_tooltip_text(self.ONLINE_TOOLTIP_TEXT)
     elif (event == "storage-offline" and super().get_sensitive()) or event == "external-storage-added":
         self.refresh_book_object()
         if message in db.tracks(self.book).first().file and not self.book.offline:
             super().set_sensitive(False)
             self.box.set_tooltip_text(self.OFFLINE_TOOLTIP_TEXT)
     if event == "external-storage-removed":
         first_track = db.tracks(self.book).first()
         if first_track and message in first_track.file:
             self.box.set_tooltip_text(self.ONLINE_TOOLTIP_TEXT)
Example #6
0
def prev_track():
    """
    Play the previous track of the current book.
    Plays the same track again when it is the first of the book.
    """
    global __player
    global __current_track
    album_tracks = db.tracks(get_current_track().book)
    current = get_current_track()
    index = list(album_tracks).index(current)
    previous = None
    if index > -1:
        previous = album_tracks[index - 1]

    db.Track.update(position=0).where(db.Track.id == current.id).execute()

    if previous is not None:
        db.Book.update(position=previous.id).where(
            db.Book.id == previous.book.id).execute()
        play_pause(previous)
    else:
        first_track = __current_track
        __player.set_state(Gst.State.NULL)
        __current_track = None
        play_pause(first_track)
        db.Book.update(position=0).where(
            db.Book.id == current.book.id).execute()
Example #7
0
    def set_book(self, book):
        """
        Display the given book in the book overview.
        """
        if self.book and self.book.id == book.id:
            self.update_time()
            return
        self.book = db.Book.get_by_id(book.id)

        if self.ui.is_playing and self.ui.titlebar.current_book and self.book.id == self.ui.titlebar.current_book.id:
            self.play_book_button.set_image(self.pause_img)
        else:
            self.play_book_button.set_image(self.play_img)

        self.name_label.set_text(book.name)
        self.author_label.set_text(book.author)

        self.update_offline_status()

        pixbuf = artwork_cache.get_cover_pixbuf(
            book, self.ui.window.get_scale_factor(), 250)
        if pixbuf:
            surface = Gdk.cairo_surface_create_from_pixbuf(
                pixbuf, self.ui.window.get_scale_factor(), None)
            self.cover_img.set_from_surface(surface)
        else:
            self.cover_img.set_from_icon_name("book-open-variant-symbolic", Gtk.IconSize.DIALOG)
            self.cover_img.props.pixel_size = 250

        self.duration = db.get_book_duration(book)
        self.speed = self.book.playback_speed
        self.total_label.set_text(
            tools.seconds_to_human_readable(self.duration / self.speed))

        self.last_played_label.set_text(
            tools.past_date_to_human_readable(book.last_played))

        self.published_label.set_visible(False)
        self.published_text.set_visible(False)

        # track list
        # This box contains all track content
        self.track_box = Gtk.Box()
        self.track_box.set_orientation(Gtk.Orientation.VERTICAL)
        self.track_box.set_halign(Gtk.Align.START)
        self.track_box.set_valign(Gtk.Align.START)
        self.track_box.props.margin = 8

        for track in db.tracks(book):
            self.track_box.add(TrackElement(track, self))

        tools.remove_all_children(self.track_list_container)
        self.track_box.show_all()
        self.track_list_container.add(self.track_box)

        self._mark_current_track()
        self.update_time()
Example #8
0
    def __settings_changed(self, event, message):
        """
        React to changes in user settings.
        """
        if not self.book:
            return

        if event == "storage-removed" or event == "external-storage-removed":
            if message in db.tracks(self.book).first().file:
                self.download_box.set_visible(False)
                self.download_switch.set_visible(False)
        elif "external-storage-added" or event == "storage-changed" or event == "storage-added":
            self.update_offline_status()
Example #9
0
    def set_book(self, book):
        if self.book is not None and self.book.id == book.id:
            self.update_time()
            return
        self.book = book

        if self.ui.is_playing and self.ui.titlebar.current_book is not None and self.book.id == self.ui.titlebar.current_book.id:
            self.play_book_button.set_image(self.pause_img)
        else:
            self.play_book_button.set_image(self.play_img)

        self.name_label.set_text(book.name)
        self.author_label.set_text(book.author)

        pixbuf = artwork_cache.get_cover_pixbuf(
            book, self.ui.window.get_scale_factor(), 250)
        surface = Gdk.cairo_surface_create_from_pixbuf(
            pixbuf, self.ui.window.get_scale_factor(), None)
        self.cover_img.set_from_surface(surface)

        self.duration = db.get_book_duration(book)
        self.speed = db.Book.select().where(
            db.Book.id == self.book.id).get().playback_speed
        self.total_label.set_text(
            tools.seconds_to_human_readable(self.duration / self.speed))

        self.last_played_label.set_text(
            tools.past_date_to_human_readable(book.last_played))

        self.published_label.set_visible(False)
        self.published_text.set_visible(False)

        # track list
        # This box contains all track content
        self.track_box = Gtk.Box()
        self.track_box.set_orientation(Gtk.Orientation.VERTICAL)
        self.track_box.set_halign(Gtk.Align.START)
        self.track_box.set_valign(Gtk.Align.START)
        self.track_box.props.margin = 8

        count = 0
        for track in db.tracks(book):
            self.track_box.add(TrackElement(track, self.ui, self))
            count += 1

        tools.remove_all_children(self.track_list_container)
        self.track_box.show_all()
        self.track_list_container.add(self.track_box)

        self._mark_current_track()
        self.update_time()