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)
def init(filesystem_monitor: FilesystemMonitor): global __player global __bus if __player: dispose() __player = None __player = Gst.ElementFactory.make("playbin", "player") __scaletempo = Gst.ElementFactory.make("scaletempo", "scaletempo") __scaletempo.sync_state_with_parent() __audiobin = Gst.ElementFactory.make("bin", "audiosink") __audiobin.add(__scaletempo) __audiosink = Gst.ElementFactory.make("autoaudiosink", "audiosink") __audiobin.add(__audiosink) __scaletempo.link(__audiosink) __pad = __scaletempo.get_static_pad("sink") __ghost_pad = Gst.GhostPad.new("sink", __pad) __audiobin.add_pad(__ghost_pad) __player.set_property("audio-sink", __audiobin) __bus = __player.get_bus() __bus.add_signal_watch() __bus.connect("message", __on_gst_message) filesystem_monitor.add_listener(__on_storage_changed)
def configure_inject(self, binder): binder.bind_to_provider(SqliteDatabase, get_db) binder.bind("MainWindow", self.main_window) binder.bind_to_constructor( Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy")) binder.bind_to_constructor(ApplicationSettings, lambda: ApplicationSettings()) binder.bind_to_constructor(Settings, lambda: Settings()) binder.bind_to_constructor("FilesystemMonitor", lambda: FilesystemMonitor()) binder.bind_to_constructor(OfflineCache, lambda: OfflineCache()) binder.bind_to_constructor(Player, lambda: Player()) binder.bind_to_constructor(Library, lambda: Library()) binder.bind_to_constructor(LibraryViewModel, lambda: LibraryViewModel()) binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel()) binder.bind_to_constructor(UISettings, lambda: UISettings()) binder.bind_to_constructor(StorageBlockList, lambda: StorageBlockList()) binder.bind_to_constructor(Files, lambda: Files()) binder.bind_to_constructor(BookDetailViewModel, lambda: BookDetailViewModel()) binder.bind_to_constructor(PlaybackControlViewModel, lambda: PlaybackControlViewModel()) binder.bind_to_constructor(HeaderbarViewModel, lambda: HeaderbarViewModel()) binder.bind_to_constructor(PlaybackSpeedViewModel, lambda: PlaybackSpeedViewModel()) binder.bind_to_constructor(SleepTimerViewModel, lambda: SleepTimerViewModel())
def __on_storage_changed(self, event, message): """ """ if (event == "storage-online" and not super().get_sensitive() ) or event == "external-storage-removed": if message in get_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()): self.refresh_book_object() if message in get_tracks( self.book).first().file and not self.book.offline: super().set_sensitive(False) self.box.set_tooltip_text(self.OFFLINE_TOOLTIP_TEXT) elif event == "external-storage-added": self.refresh_book_object() if FilesystemMonitor().is_book_online(self.book): super().set_sensitive(True) else: super().set_sensitive(False) self.box.set_tooltip_text(self.OFFLINE_TOOLTIP_TEXT) if event == "external-storage-removed": first_track = get_tracks(self.book).first() if first_track and message in first_track.file: self.box.set_tooltip_text(self.ONLINE_TOOLTIP_TEXT)
def load_last_book(filesystem_monitor: FilesystemMonitor): """ Load the last played book into the player. """ global __current_track global __player last_book = Settings.get().last_played_book if last_book and last_book.position != 0: query = Track.select().where(Track.id == last_book.position) if query.exists(): last_track = query.get() if last_track: __player.set_state(Gst.State.NULL) if filesystem_monitor.is_track_online(last_track): path = last_track.file else: path = OfflineCache().get_cached_path(last_track) if not path: return __player.set_property("uri", "file://" + path) __player.set_state(Gst.State.PAUSED) __current_track = last_track Book.update(last_played=int(time.time())).where( Book.id == last_book.id).execute() emit_event("track-changed", last_track)
def load_file(track, filesystem_monitor: FilesystemMonitor): """ Loads a given track into the player. :param track: track to be loaded """ global __current_track global __player if get_gst_player_state() == Gst.State.PLAYING: save_current_track_position() save_current_book_position(__current_track) __current_track = track emit_event("stop") __player.set_state(Gst.State.NULL) init() if filesystem_monitor.is_track_online(track): path = track.file else: path = OfflineCache().get_cached_path(track) if not path: path = track.file __player.set_property("uri", "file://" + path) __player.set_state(Gst.State.PAUSED) save_current_book_position(__current_track) Settings.update(last_played_book=__current_track.book).execute() Book.update(last_played=int(time.time())).where( Book.id == __current_track.book.id).execute() emit_event("track-changed", track)
def __init__(self, model: Library): super().__init__() self._model: Library = model self._fs_monitor: FilesystemMonitor = FilesystemMonitor() self._application_settings: ApplicationSettings = ApplicationSettings() self._search_open: bool = False
def __init__(self): super().__init__() self._model = Library(get_db()) self._fs_monitor: FilesystemMonitor = FilesystemMonitor() self._application_settings: ApplicationSettings = ApplicationSettings() self._importer: Importer = importer_instance self._player: Player = Player() self._library_view_mode: LibraryViewMode = LibraryViewMode.CURRENT self._selected_filter: str = _("All") self._connect()
def remove_invalid_entries(ui=None, refresh=False): """ Remove track entries from db that no longer exist in the filesystem. """ # remove entries from the db that are no longer existent for track in Track.select(): from cozy.control.filesystem_monitor import FilesystemMonitor if not os.path.isfile( track.file) and FilesystemMonitor().is_track_online(track): track.delete_instance() clean_books() if refresh: Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, ui.refresh_content)
def configure_inject(binder): binder.bind_to_provider(SqliteDatabase, get_db) binder.bind_to_constructor( Gio.Settings, lambda: Gio.Settings("com.github.geigi.cozy")) binder.bind_to_constructor(ApplicationSettings, lambda: ApplicationSettings()) binder.bind_to_constructor(Settings, lambda: Settings()) binder.bind_to_constructor("FilesystemMonitor", lambda: FilesystemMonitor()) binder.bind_to_constructor(Library, lambda: Library()) binder.bind_to_constructor(LibraryViewModel, lambda: LibraryViewModel()) binder.bind_to_constructor(SearchViewModel, lambda: SearchViewModel()) binder.bind_to_constructor(UISettings, lambda: UISettings()) binder.bind_to_constructor(StorageBlockList, lambda: StorageBlockList()) binder.bind_to_constructor(Files, lambda: Files())