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 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 __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())