def show_replace_bookmark_dialog(self, old_bookmarks, new_page): """ Present a confirmation dialog to replace old bookmarks. @return RESPONSE_YES to create replace bookmarks, RESPONSE_NO to create a new bookmark, RESPONSE_CANCEL to abort creating a new bookmark. """ dialog = message_dialog.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO) dialog.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.set_default_response(gtk.RESPONSE_YES) dialog.set_should_remember_choice('replace-existing-bookmark', (gtk.RESPONSE_YES, gtk.RESPONSE_NO)) pages = map(str, sorted(map(operator.attrgetter('_page'), old_bookmarks))) dialog.set_text( i18n.get_translation().ungettext( 'Replace existing bookmark on page %s?', 'Replace existing bookmarks on pages %s?', len(pages)) % ", ".join(pages), _('The current book already contains marked pages. ' 'Do you want to replace them with a new bookmark on page %d? ') % new_page + '\n\n' + _('Selecting "No" will create a new bookmark without affecting the other bookmarks.' )) return dialog.run()
def show_replace_bookmark_dialog(self, old_bookmarks, new_page): ''' Present a confirmation dialog to replace old bookmarks. @return RESPONSE_YES to create replace bookmarks, RESPONSE_NO to create a new bookmark, RESPONSE_CANCEL to abort creating a new bookmark. ''' dialog = message_dialog.MessageDialog( self._window, flags=Gtk.DialogFlags.MODAL, message_type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.NONE) dialog.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO, Gtk.ResponseType.NO, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) dialog.set_default_response(Gtk.ResponseType.YES) dialog.set_should_remember_choice( 'replace-existing-bookmark', (Gtk.ResponseType.YES, Gtk.ResponseType.NO)) pages = map(str, sorted(map(operator.attrgetter('_page'), old_bookmarks))) dialog.set_text( i18n.get_translation().ngettext( 'Replace existing bookmark on page %s?', 'Replace existing bookmarks on pages %s?', len(list(pages))) % ', '.join(pages), _('The current book already contains marked pages. ' 'Do you want to replace them with a new bookmark on page %d? ') % new_page + '\n\n' + _('Selecting "No" will create a new bookmark without affecting the other bookmarks.' )) return dialog.run()
def show_replace_bookmark_dialog(self, old_bookmarks, new_page): """ Present a confirmation dialog to replace old bookmarks. @return RESPONSE_YES to create replace bookmarks, RESPONSE_NO to create a new bookmark, RESPONSE_CANCEL to abort creating a new bookmark. """ dialog = message_dialog.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO) dialog.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.set_default_response(gtk.RESPONSE_YES) dialog.set_should_remember_choice('replace-existing-bookmark', (gtk.RESPONSE_YES, gtk.RESPONSE_NO)) pages = map(str, sorted(map(operator.attrgetter('_page'), old_bookmarks))) dialog.set_text( i18n.get_translation().ungettext( 'Replace existing bookmark on page %s?', 'Replace existing bookmarks on pages %s?', len(pages) ) % ", ".join(pages), _('The current book already contains marked pages. ' 'Do you want to replace them with a new bookmark on page %d? ') % new_page + '\n\n' + _('Selecting "No" will create a new bookmark without affecting the other bookmarks.')) return dialog.run()
def _should_replace_bookmarks(self, old_bookmarks, new_page): """ Present a confirmation dialog to replace old bookmarks. @return RESPONSE_YES to create replace bookmarks, RESPONSE_NO to create a new bookmark, RESPONSE_CANCEL to abort creating a new bookmark. """ dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE) dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.add_button(gtk.STOCK_NO, constants.RESPONSE_NEW) replace_button = dialog.add_button(gtk.STOCK_YES, constants.RESPONSE_REPLACE) dialog.set_default_response(constants.RESPONSE_REPLACE) pages = map(str, sorted(map(operator.attrgetter('_page'), old_bookmarks))) dialog.set_markup( '<span weight="bold" size="larger">' + i18n.get_translation().ungettext( 'Replace existing bookmark on page %s?', 'Replace existing bookmarks on pages %s?', len(pages)) % ", ".join(pages) + '</span>') dialog.format_secondary_markup( _('The current book already contains marked pages. ' 'Do you want to replace them with a new bookmark on page %d? ') % new_page + '\n\n' + _('Selecting "No" will create a new bookmark without affecting the other bookmarks.' )) checkbox = gtk.CheckButton(_('Do not ask again.')) # FIXME: This really shouldn't depend on MessageDialog's internal layout implementation labels_box = dialog.get_content_area().get_children()[0].get_children( )[1] labels_box.pack_end(checkbox, padding=6) dialog.show_all() replace_button.grab_focus() result = dialog.run() store_choice = checkbox.get_active() dialog.destroy() # Remember the selection if store_choice and result in (constants.RESPONSE_NEW, constants.RESPONSE_REPLACE): prefs['replace bookmark response'] = result return result
def clean_collection(self, collection): ''' Check all books in the collection, removing those that no longer exist. If C{collection} is None, the whole library will be cleaned. ''' removed = self._library.backend.clean_collection(collection) msg = i18n.get_translation().ngettext( 'Removed %d book from the library.', 'Removed %d books from the library.', removed) self._library.set_status_message(msg % removed) if removed > 0: collection = self._library.collection_area.get_current_collection() GLib.idle_add(self._library.book_area.display_covers, collection)
def _remove_books_from_library(self, *args): """Remove the currently selected books from the library, and thus also from the _BookArea. """ selected = self._iconview.get_selected_items() for path in selected: book = self.get_book_at_path(path) self._library.backend.remove_book(book) self.remove_book_at_path(path) msg = i18n.get_translation().ngettext( 'Removed %d book from the library.', 'Removed %d books from the library.', len(selected)) self._library.set_status_message(msg % len(selected))
def clean_collection(self, collection): """ Check all books in the collection, removing those that no longer exist. If C{collection} is None, the whole library will be cleaned. """ removed = self._library.backend.clean_collection(collection) msg = i18n.get_translation().ngettext( 'Removed %d book from the library.', 'Removed %d books from the library.', removed) self._library.set_status_message(msg % removed) if removed > 0: collection = self._library.collection_area.get_current_collection() gobject.idle_add(self._library.book_area.display_covers, collection)
def _should_replace_bookmarks(self, old_bookmarks, new_page): """ Present a confirmation dialog to replace old bookmarks. @return RESPONSE_YES to create replace bookmarks, RESPONSE_NO to create a new bookmark, RESPONSE_CANCEL to abort creating a new bookmark. """ dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE) dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.add_button(gtk.STOCK_NO, constants.RESPONSE_NEW) replace_button = dialog.add_button(gtk.STOCK_YES, constants.RESPONSE_REPLACE) dialog.set_default_response(constants.RESPONSE_REPLACE) pages = map(str, sorted(map(operator.attrgetter('_page'), old_bookmarks))) dialog.set_markup('<span weight="bold" size="larger">' + i18n.get_translation().ungettext( 'Replace existing bookmark on page %s?', 'Replace existing bookmarks on pages %s?', len(pages) ) % ", ".join(pages) + '</span>') dialog.format_secondary_markup( _('The current book already contains marked pages. ' 'Do you want to replace them with a new bookmark on page %d? ') % new_page + '\n\n' + _('Selecting "No" will create a new bookmark without affecting the other bookmarks.') ) checkbox = gtk.CheckButton(_('Do not ask again.')) # FIXME: This really shouldn't depend on MessageDialog's internal layout implementation labels_box = dialog.get_content_area().get_children()[0].get_children()[1] labels_box.pack_end(checkbox, padding=6) dialog.show_all() replace_button.grab_focus() result = dialog.run() store_choice = checkbox.get_active() dialog.destroy() # Remember the selection if store_choice and result in (constants.RESPONSE_NEW, constants.RESPONSE_REPLACE): prefs['replace bookmark response'] = result return result
def _new_files_found(self, filelist, watchentry): """ Called after the scan for new files finished. """ if len(filelist) > 0: if watchentry.collection.id is not None: collection_name = watchentry.collection.name else: collection_name = None self.add_books(filelist, collection_name) message = i18n.get_translation().ngettext( "Added new book '%(bookname)s' from directory '%(directory)s'.", "Added %(count)d new books from directory '%(directory)s'.", len(filelist)) self.set_status_message(message % {'directory': watchentry.directory, 'count': len(filelist), 'bookname': os.path.basename(filelist[0])}) else: self.set_status_message( _("No new books found in directory '%s'.") % watchentry.directory)
def _remove_books_from_collection(self, *args): """Remove the currently selected books from the current collection, and thus also from the _BookArea. """ collection = self._library.collection_area.get_current_collection() if collection == _COLLECTION_ALL: return selected = self._iconview.get_selected_items() self._library.backend.begin_transaction() for path in selected: book = self.get_book_at_path(path) self._library.backend.remove_book_from_collection(book, collection) self.remove_book_at_path(path) self._library.backend.end_transaction() coll_name = self._library.backend.get_collection_name(collection) message = i18n.get_translation().ungettext( "Removed %(num)d book from '%(collection)s'.", "Removed %(num)d books from '%(collection)s'.", len(selected)) self._library.set_status_message( message % {'num': len(selected), 'collection': coll_name})