Example #1
0
    def __init__(self, b):
        self.book = b
        self.ui = cozy.ui.main_view.CozyUI()

        self.ONLINE_TOOLTIP_TEXT = _("Open book overview")
        self.OFFLINE_TOOLTIP_TEXT = _("Currently offline")

        super().__init__()
        self.event_box = Gtk.EventBox()
        self.add_events(Gdk.EventMask.KEY_PRESS_MASK)
        self.box = Gtk.Box()
        self.box.set_orientation(Gtk.Orientation.VERTICAL)
        self.box.set_spacing(7)
        self.box.set_halign(Gtk.Align.CENTER)
        self.box.set_valign(Gtk.Align.START)
        self.box.set_margin_top(10)

        # label contains the book name and is limited to x chars
        title_label = Gtk.Label.new("")
        title = tools.shorten_string(self.book.name, MAX_BOOK_LENGTH)
        title_label.set_markup("<b>" + title + "</b>")
        title_label.set_xalign(0.5)
        title_label.set_line_wrap(Pango.WrapMode.WORD_CHAR)
        title_label.props.max_width_chars = 30
        title_label.props.justify = Gtk.Justification.CENTER

        author_label = Gtk.Label.new(
            tools.shorten_string(self.book.author, MAX_BOOK_LENGTH))
        author_label.set_xalign(0.5)
        author_label.set_line_wrap(Pango.WrapMode.WORD_CHAR)
        author_label.props.max_width_chars = 30
        author_label.props.justify = Gtk.Justification.CENTER
        author_label.get_style_context().add_class("dim-label")

        self.art = AlbumElement(self.book,
                                180,
                                self.ui.window.get_scale_factor(),
                                bordered=True,
                                square=False)

        if db.is_external(
                self.book) and not self.book.offline and not FilesystemMonitor(
                ).is_book_online(self.book):
            super().set_sensitive(False)
            self.box.set_tooltip_text(self.OFFLINE_TOOLTIP_TEXT)
        else:
            self.box.set_tooltip_text(self.ONLINE_TOOLTIP_TEXT)

        # assemble finished element
        self.box.add(self.art)
        self.box.add(title_label)
        self.box.add(author_label)
        self.event_box.add(self.box)
        self.add(self.event_box)

        self.event_box.connect("button-press-event",
                               self.__on_button_press_event)
        self.connect("key-press-event", self.__on_key_press_event)
        FilesystemMonitor().add_listener(self.__on_storage_changed)
        Settings().add_listener(self.__on_storage_changed)
Example #2
0
 def __player_changed(self, event, message):
     """
     Listen to and handle all gst player messages that are important for the ui.
     """
     if event == "stop":
         if self.__inhibit_cookie:
             self.app.uninhibit(self.__inhibit_cookie)
         self.is_playing = False
         self.stop()
         self.titlebar.stop()
         self.sleep_timer.stop()
     elif event == "play":
         self.is_playing = True
         self.play()
         self.titlebar.play()
         self.sleep_timer.start()
         self.book_overview.select_track(None, True)
         self.refresh_recent()
         self.__inhibit_cookie = self.app.inhibit(
             self.window, Gtk.ApplicationInhibitFlags.SUSPEND, "Playback of audiobook")
     elif event == "pause":
         if self.__inhibit_cookie:
             self.app.uninhibit(self.__inhibit_cookie)
         self.is_playing = False
         self.pause()
         self.titlebar.pause()
         self.sleep_timer.stop()
         self.book_overview.select_track(None, False)
     elif event == "track-changed":
         self.track_changed()
         if self.sort_stack.props.visible_child_name == "recent":
             self.book_box.invalidate_filter()
             self.book_box.invalidate_sort()
     elif event == "error":
         if self.dialog_open:
             return
         if "Resource not found" in str(message):
             current_track = player.get_current_track()
             if db.is_external(current_track.book):
                 player.stop()
                 player.unload()
                 player.emit_event("stop")
             else:
                 self.dialog_open = True
                 dialog = FileNotFoundDialog(
                     current_track.file)
                 dialog.show()
Example #3
0
    def update_offline_status(self):
        """
        Hide/Show download elements depending on whether the book is on an external storage.
        """
        self.book = Book.get(Book.id == self.book.id)
        if self.switch_signal:
            self.download_switch.disconnect(self.switch_signal)
        if is_external(self.book):
            self.download_box.set_visible(True)
            self.download_switch.set_visible(True)
            self.download_switch.set_active(self.book.offline)
        else:
            self.download_box.set_visible(False)
            self.download_switch.set_visible(False)
        self.switch_signal = self.download_switch.connect("notify::active", self.__on_download_switch_changed)

        self._set_book_download_status(self.book.downloaded)