mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add an entry to the add books drop down menu to easily add formats to an existing book record
This commit is contained in:
parent
25ae86e2cf
commit
c44ad36365
@ -20,9 +20,26 @@ from calibre.ebooks import BOOK_EXTENSIONS
|
|||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.constants import preferred_encoding, filesystem_encoding
|
from calibre.constants import preferred_encoding, filesystem_encoding
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from calibre.gui2 import config
|
from calibre.gui2 import config, question_dialog
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
|
||||||
|
def get_filters():
|
||||||
|
return [
|
||||||
|
(_('Books'), BOOK_EXTENSIONS),
|
||||||
|
(_('EPUB Books'), ['epub']),
|
||||||
|
(_('LRF Books'), ['lrf']),
|
||||||
|
(_('HTML Books'), ['htm', 'html', 'xhtm', 'xhtml']),
|
||||||
|
(_('LIT Books'), ['lit']),
|
||||||
|
(_('MOBI Books'), ['mobi', 'prc', 'azw']),
|
||||||
|
(_('Topaz books'), ['tpz','azw1']),
|
||||||
|
(_('Text books'), ['txt', 'rtf']),
|
||||||
|
(_('PDF Books'), ['pdf']),
|
||||||
|
(_('SNB Books'), ['snb']),
|
||||||
|
(_('Comics'), ['cbz', 'cbr', 'cbc']),
|
||||||
|
(_('Archives'), ['zip', 'rar']),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class AddAction(InterfaceAction):
|
class AddAction(InterfaceAction):
|
||||||
|
|
||||||
name = 'Add Books'
|
name = 'Add Books'
|
||||||
@ -47,6 +64,10 @@ class AddAction(InterfaceAction):
|
|||||||
self.add_menu.addAction(_('Add Empty book. (Book entry with no '
|
self.add_menu.addAction(_('Add Empty book. (Book entry with no '
|
||||||
'formats)'), self.add_empty, _('Shift+Ctrl+E'))
|
'formats)'), self.add_empty, _('Shift+Ctrl+E'))
|
||||||
self.add_menu.addAction(_('Add from ISBN'), self.add_from_isbn)
|
self.add_menu.addAction(_('Add from ISBN'), self.add_from_isbn)
|
||||||
|
self.add_menu.addSeparator()
|
||||||
|
self.add_menu.addAction(_('Add files to selected book records'),
|
||||||
|
self.add_formats, _('Shift+A'))
|
||||||
|
|
||||||
self.qaction.setMenu(self.add_menu)
|
self.qaction.setMenu(self.add_menu)
|
||||||
self.qaction.triggered.connect(self.add_books)
|
self.qaction.triggered.connect(self.add_books)
|
||||||
|
|
||||||
@ -55,6 +76,39 @@ class AddAction(InterfaceAction):
|
|||||||
for action in list(self.add_menu.actions())[1:]:
|
for action in list(self.add_menu.actions())[1:]:
|
||||||
action.setEnabled(enabled)
|
action.setEnabled(enabled)
|
||||||
|
|
||||||
|
def add_formats(self, *args):
|
||||||
|
if self.gui.stack.currentIndex() != 0:
|
||||||
|
return
|
||||||
|
view = self.gui.library_view
|
||||||
|
rows = view.selectionModel().selectedRows()
|
||||||
|
if not rows:
|
||||||
|
return
|
||||||
|
ids = [view.model().id(r) for r in rows]
|
||||||
|
|
||||||
|
if len(ids) > 1 and not question_dialog(self.gui,
|
||||||
|
_('Are you sure'),
|
||||||
|
_('Are you sure you want to add the same'
|
||||||
|
' files to all %d books? If the format'
|
||||||
|
'already exists for a book, it will be replaced.')%len(ids)):
|
||||||
|
return
|
||||||
|
|
||||||
|
books = choose_files(self.gui, 'add formats dialog dir',
|
||||||
|
_('Select book files'), filters=get_filters())
|
||||||
|
if not books:
|
||||||
|
return
|
||||||
|
|
||||||
|
db = view.model().db
|
||||||
|
for id_ in ids:
|
||||||
|
for fpath in books:
|
||||||
|
fmt = os.path.splitext(fpath)[1][1:].upper()
|
||||||
|
if fmt:
|
||||||
|
db.add_format_with_hooks(id_, fmt, fpath, index_is_id=True,
|
||||||
|
notify=True)
|
||||||
|
current_idx = self.gui.library_view.currentIndex()
|
||||||
|
if current_idx.isValid():
|
||||||
|
view.model().current_changed(current_idx, current_idx)
|
||||||
|
|
||||||
|
|
||||||
def add_recursive(self, single):
|
def add_recursive(self, single):
|
||||||
root = choose_dir(self.gui, 'recursive book import root dir dialog',
|
root = choose_dir(self.gui, 'recursive book import root dir dialog',
|
||||||
'Select root folder')
|
'Select root folder')
|
||||||
@ -207,27 +261,14 @@ class AddAction(InterfaceAction):
|
|||||||
'''
|
'''
|
||||||
Add books from the local filesystem to either the library or the device.
|
Add books from the local filesystem to either the library or the device.
|
||||||
'''
|
'''
|
||||||
filters = [
|
filters = get_filters()
|
||||||
(_('Books'), BOOK_EXTENSIONS),
|
|
||||||
(_('EPUB Books'), ['epub']),
|
|
||||||
(_('LRF Books'), ['lrf']),
|
|
||||||
(_('HTML Books'), ['htm', 'html', 'xhtm', 'xhtml']),
|
|
||||||
(_('LIT Books'), ['lit']),
|
|
||||||
(_('MOBI Books'), ['mobi', 'prc', 'azw']),
|
|
||||||
(_('Topaz books'), ['tpz','azw1']),
|
|
||||||
(_('Text books'), ['txt', 'rtf']),
|
|
||||||
(_('PDF Books'), ['pdf']),
|
|
||||||
(_('SNB Books'), ['snb']),
|
|
||||||
(_('Comics'), ['cbz', 'cbr', 'cbc']),
|
|
||||||
(_('Archives'), ['zip', 'rar']),
|
|
||||||
]
|
|
||||||
to_device = self.gui.stack.currentIndex() != 0
|
to_device = self.gui.stack.currentIndex() != 0
|
||||||
if to_device:
|
if to_device:
|
||||||
fmts = self.gui.device_manager.device.settings().format_map
|
fmts = self.gui.device_manager.device.settings().format_map
|
||||||
filters = [(_('Supported books'), fmts)]
|
filters = [(_('Supported books'), fmts)]
|
||||||
|
|
||||||
books = choose_files(self.gui, 'add books dialog dir', 'Select books',
|
books = choose_files(self.gui, 'add books dialog dir',
|
||||||
filters=filters)
|
_('Select books'), filters=filters)
|
||||||
if not books:
|
if not books:
|
||||||
return
|
return
|
||||||
self._add_books(books, to_device)
|
self._add_books(books, to_device)
|
||||||
|
@ -497,6 +497,8 @@ Calibre has several keyboard shortcuts to save you time and mouse movement. Thes
|
|||||||
- Edit the metadata of the currently selected field in the book list.
|
- Edit the metadata of the currently selected field in the book list.
|
||||||
* - :kbd:`A`
|
* - :kbd:`A`
|
||||||
- Add Books
|
- Add Books
|
||||||
|
* - :kbd:`Shift+A`
|
||||||
|
- Add Formats to the selected books
|
||||||
* - :kbd:`C`
|
* - :kbd:`C`
|
||||||
- Convert selected Books
|
- Convert selected Books
|
||||||
* - :kbd:`D`
|
* - :kbd:`D`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user