def __filter_books(self, book, data, notify_destroy): """ Filter the books in the book view according to the selected author/reader or "All". """ selected_stack = self.sort_stack.props.visible_child_name if tools.get_glib_settings().get_boolean("hide-offline"): if not self.fs_monitor.is_book_online(book.book): offline_available = Book.get( Book.id == book.book.id).downloaded else: offline_available = True else: offline_available = True if selected_stack == "author": row = self.author_box.get_selected_row() elif selected_stack == "reader": row = self.reader_box.get_selected_row() if selected_stack == "author" or selected_stack == "reader": if row is None: return True and offline_available field = row.data if field is None or field == _("All"): return True and offline_available else: if selected_stack == "author": return True and offline_available if book.book.author == field else False if selected_stack == "reader": return True and offline_available if book.book.reader == field else False elif selected_stack == "recent": return True and offline_available if book.book.last_played > 0 else False
def _mark_current_track(self): """ Mark the current track position. """ book = Book.get(Book.id == self.book.id) if book.position == -1: self.deselect_track_element() self.current_track_element = None return for track_element in self.track_box.get_children(): if isinstance(track_element, DiskElement): continue elif track_element.track.id == book.position: self.current_track_element = track_element track_element.select() else: track_element.deselect() if book.position == 0: self.current_track_element = self.track_box.get_children()[1] self.current_track_element.select() if self.ui.titlebar.current_book and self.ui.titlebar.current_book.id == self.book.id: self.current_track_element.set_playing(player.is_playing())
def refresh_book_object(self): """ Refresh the internal book object from the database. """ try: self.book = Book.get(Book.id == self.book.id) except Exception as e: reporter.exception("book_element", e)
def refresh_book_object(self): """ Refresh the internal book object from the database. """ try: self.book = Book.get(Book.id == self.book.id) except: pass
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)
def _process_queue(self): log.info("Startet processing queue") self.filecopy_cancel = Gio.Cancellable() self._fill_queue_from_db() self.total_batch_count = len(self.queue) self.current_batch_count = 0 if len(self.queue) > 0: self.current_book_processing = self.queue[0].track.book.id while len(self.queue) > 0: log.info("Processing item") self.current_batch_count += 1 item = self.queue[0] if self.thread.stopped(): break new_item = OfflineCacheModel.get(OfflineCacheModel.id == item.id) if self.current_book_processing != new_item.track.book.id: self.update_book_download_status( Book.get(Book.id == self.current_book_processing)) self.current_book_processing = new_item.track.book.id if not new_item.copied and os.path.exists(new_item.track.file): log.info("Copying item") Gdk.threads_add_idle( GLib.PRIORITY_DEFAULT_IDLE, self.ui.switch_to_working, _("Copying") + " " + tools.shorten_string(new_item.track.book.name, 30), False, False) self.current = new_item destination = Gio.File.new_for_path( os.path.join(self.cache_dir, new_item.file)) source = Gio.File.new_for_path(new_item.track.file) flags = Gio.FileCopyFlags.OVERWRITE try: copied = source.copy(destination, flags, self.filecopy_cancel, self.__update_copy_status, None) except Exception as e: if e.code == Gio.IOErrorEnum.CANCELLED: log.info("Download of book was cancelled.") self.thread.stop() break log.error("Could not copy file to offline cache: " + new_item.track.file) log.error(e) self.queue.remove(item) continue if copied: OfflineCacheModel.update(copied=True).where( OfflineCacheModel.id == new_item.id).execute() self.queue.remove(item) if self.current_book_processing: self.update_book_download_status( Book.get(Book.id == self.current_book_processing)) self.current = None Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.ui.switch_to_playing)
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 = Book.get(Book.id == book.id) if player.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 = 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 disk_number = -1 first_disk_element = None disk_count = 0 for track in get_tracks(book): # Insert disk headers if track.disk != disk_number: disc_element = DiskElement(track.disk) self.track_box.add(disc_element) if disk_number == -1: first_disk_element = disc_element if track.disk < 2: first_disk_element.set_hidden(True) else: first_disk_element.show_all() disc_element.show_all() disk_number = track.disk disk_count += 1 track_element = TrackElement(track, self) self.track_box.add(track_element) track_element.show_all() tools.remove_all_children(self.track_list_container) self.track_box.show() self.track_box.set_halign(Gtk.Align.FILL) self.track_list_container.add(self.track_box) self._mark_current_track() self.update_time()