mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Allow exporting all selected files to the computer from the File Browser by right clicking
This commit is contained in:
parent
7ed129d73f
commit
d57943fac2
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import tempfile, shutil, sys, os
|
import tempfile, shutil, sys, os, errno
|
||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
@ -1283,7 +1283,20 @@ class Boss(QObject):
|
|||||||
self.set_modified()
|
self.set_modified()
|
||||||
|
|
||||||
@in_thread_job
|
@in_thread_job
|
||||||
def export_requested(self, name, path):
|
def export_requested(self, name_or_names, path):
|
||||||
|
if isinstance(name_or_names, basestring):
|
||||||
|
return self.export_file(name_or_names, path)
|
||||||
|
for name in name_or_names:
|
||||||
|
dest = os.path.abspath(os.path.join(path, name))
|
||||||
|
if '/' in name or os.sep in name:
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(dest))
|
||||||
|
except EnvironmentError as err:
|
||||||
|
if err.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
self.export_file(name, dest)
|
||||||
|
|
||||||
|
def export_file(self, name, path):
|
||||||
if name in editors and not editors[name].is_synced_to_container:
|
if name in editors and not editors[name].is_synced_to_container:
|
||||||
self.commit_editor_to_container(name)
|
self.commit_editor_to_container(name)
|
||||||
with current_container().open(name, 'rb') as src, open(path, 'wb') as dest:
|
with current_container().open(name, 'rb') as src, open(path, 'wb') as dest:
|
||||||
|
@ -25,7 +25,8 @@ from calibre.ebooks.oeb.polish.cover import (
|
|||||||
)
|
)
|
||||||
from calibre.ebooks.oeb.polish.replace import get_recommended_folders
|
from calibre.ebooks.oeb.polish.replace import get_recommended_folders
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
choose_files, choose_save_file, elided_text, error_dialog, question_dialog
|
choose_dir, choose_files, choose_save_file, elided_text, error_dialog,
|
||||||
|
question_dialog
|
||||||
)
|
)
|
||||||
from calibre.gui2.tweak_book import (
|
from calibre.gui2.tweak_book import (
|
||||||
CONTAINER_DND_MIMETYPE, current_container, editors, tprefs
|
CONTAINER_DND_MIMETYPE, current_container, editors, tprefs
|
||||||
@ -34,7 +35,6 @@ from calibre.gui2.tweak_book.editor import syntax_from_mime
|
|||||||
from calibre.gui2.tweak_book.templates import template_for
|
from calibre.gui2.tweak_book.templates import template_for
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
|
|
||||||
TOP_ICON_SIZE = 24
|
TOP_ICON_SIZE = 24
|
||||||
NAME_ROLE = Qt.UserRole
|
NAME_ROLE = Qt.UserRole
|
||||||
CATEGORY_ROLE = NAME_ROLE + 1
|
CATEGORY_ROLE = NAME_ROLE + 1
|
||||||
@ -482,6 +482,9 @@ class FileList(QTreeWidget):
|
|||||||
m.addAction(QIcon(I('save.png')), _('Export %s') % n, partial(self.export, cn))
|
m.addAction(QIcon(I('save.png')), _('Export %s') % n, partial(self.export, cn))
|
||||||
if cn not in container.names_that_must_not_be_changed and cn not in container.names_that_must_not_be_removed and mt not in OEB_FONTS:
|
if cn not in container.names_that_must_not_be_changed and cn not in container.names_that_must_not_be_removed and mt not in OEB_FONTS:
|
||||||
m.addAction(_('Replace %s with file...') % n, partial(self.replace, cn))
|
m.addAction(_('Replace %s with file...') % n, partial(self.replace, cn))
|
||||||
|
if num > 1:
|
||||||
|
m.addAction(QIcon(I('save.png')), _('Export all %d selected files') % num, self.export_selected)
|
||||||
|
|
||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
|
|
||||||
m.addAction(QIcon(I('modified.png')), _('&Rename %s') % n, self.edit_current_item)
|
m.addAction(QIcon(I('modified.png')), _('&Rename %s') % n, self.edit_current_item)
|
||||||
@ -732,6 +735,14 @@ class FileList(QTreeWidget):
|
|||||||
if path:
|
if path:
|
||||||
self.export_requested.emit(name, path)
|
self.export_requested.emit(name, path)
|
||||||
|
|
||||||
|
def export_selected(self):
|
||||||
|
names = self.selected_names
|
||||||
|
if not names:
|
||||||
|
return
|
||||||
|
path = choose_dir(self, 'tweak_book_export_selected', _('Choose location'))
|
||||||
|
if path:
|
||||||
|
self.export_requested.emit(names, path)
|
||||||
|
|
||||||
def replace(self, name):
|
def replace(self, name):
|
||||||
c = current_container()
|
c = current_container()
|
||||||
mt = c.mime_map[name]
|
mt = c.mime_map[name]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user