mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Automatic fixes
This commit is contained in:
parent
cb07d093e2
commit
e09ecee421
@ -13,19 +13,19 @@ class DeleteAction(object):
|
||||
|
||||
def _get_selected_formats(self, msg):
|
||||
from calibre.gui2.dialogs.select_formats import SelectFormats
|
||||
fmts = self.library_view.model().db.all_formats()
|
||||
fmts = self.gui.library_view.model().db.all_formats()
|
||||
d = SelectFormats([x.lower() for x in fmts], msg, parent=self)
|
||||
if d.exec_() != d.Accepted:
|
||||
return None
|
||||
return d.selected_formats
|
||||
|
||||
def _get_selected_ids(self, err_title=_('Cannot delete')):
|
||||
rows = self.library_view.selectionModel().selectedRows()
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, err_title, _('No book selected'))
|
||||
d.exec_()
|
||||
return set([])
|
||||
return set(map(self.library_view.model().id, rows))
|
||||
return set(map(self.gui.library_view.model().id, rows))
|
||||
|
||||
def delete_selected_formats(self, *args):
|
||||
ids = self._get_selected_ids()
|
||||
@ -37,11 +37,11 @@ class DeleteAction(object):
|
||||
return
|
||||
for id in ids:
|
||||
for fmt in fmts:
|
||||
self.library_view.model().db.remove_format(id, fmt,
|
||||
self.gui.library_view.model().db.remove_format(id, fmt,
|
||||
index_is_id=True, notify=False)
|
||||
self.library_view.model().refresh_ids(ids)
|
||||
self.library_view.model().current_changed(self.library_view.currentIndex(),
|
||||
self.library_view.currentIndex())
|
||||
self.gui.library_view.model().refresh_ids(ids)
|
||||
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||
self.gui.library_view.currentIndex())
|
||||
if ids:
|
||||
self.tags_view.recount()
|
||||
|
||||
@ -54,17 +54,17 @@ class DeleteAction(object):
|
||||
if fmts is None:
|
||||
return
|
||||
for id in ids:
|
||||
bfmts = self.library_view.model().db.formats(id, index_is_id=True)
|
||||
bfmts = self.gui.library_view.model().db.formats(id, index_is_id=True)
|
||||
if bfmts is None:
|
||||
continue
|
||||
bfmts = set([x.lower() for x in bfmts.split(',')])
|
||||
rfmts = bfmts - set(fmts)
|
||||
for fmt in rfmts:
|
||||
self.library_view.model().db.remove_format(id, fmt,
|
||||
self.gui.library_view.model().db.remove_format(id, fmt,
|
||||
index_is_id=True, notify=False)
|
||||
self.library_view.model().refresh_ids(ids)
|
||||
self.library_view.model().current_changed(self.library_view.currentIndex(),
|
||||
self.library_view.currentIndex())
|
||||
self.gui.library_view.model().refresh_ids(ids)
|
||||
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||
self.gui.library_view.currentIndex())
|
||||
if ids:
|
||||
self.tags_view.recount()
|
||||
|
||||
@ -113,16 +113,16 @@ class DeleteAction(object):
|
||||
if not ids:
|
||||
return
|
||||
for id in ids:
|
||||
self.library_view.model().db.remove_cover(id)
|
||||
self.library_view.model().refresh_ids(ids)
|
||||
self.library_view.model().current_changed(self.library_view.currentIndex(),
|
||||
self.library_view.currentIndex())
|
||||
self.gui.library_view.model().db.remove_cover(id)
|
||||
self.gui.library_view.model().refresh_ids(ids)
|
||||
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||
self.gui.library_view.currentIndex())
|
||||
|
||||
def delete_books(self, *args):
|
||||
'''
|
||||
Delete selected books from device or library.
|
||||
'''
|
||||
view = self.current_view()
|
||||
view = self.gui.current_view()
|
||||
rows = view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
return
|
||||
|
@ -19,13 +19,13 @@ class EditMetadataAction(object):
|
||||
|
||||
def download_metadata(self, checked, covers=True, set_metadata=True,
|
||||
set_social_metadata=None):
|
||||
rows = self.library_view.selectionModel().selectedRows()
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot download metadata'),
|
||||
_('No books selected'))
|
||||
d.exec_()
|
||||
return
|
||||
db = self.library_view.model().db
|
||||
db = self.gui.library_view.model().db
|
||||
ids = [db.id(row.row()) for row in rows]
|
||||
self.do_download_metadata(ids, covers=covers,
|
||||
set_metadata=set_metadata,
|
||||
@ -33,7 +33,7 @@ class EditMetadataAction(object):
|
||||
|
||||
def do_download_metadata(self, ids, covers=True, set_metadata=True,
|
||||
set_social_metadata=None):
|
||||
db = self.library_view.model().db
|
||||
db = self.gui.library_view.model().db
|
||||
if set_social_metadata is None:
|
||||
get_social_metadata = config['get_social_metadata']
|
||||
else:
|
||||
@ -59,11 +59,11 @@ class EditMetadataAction(object):
|
||||
return
|
||||
self._book_metadata_download_check.stop()
|
||||
self.progress_indicator.stop()
|
||||
cr = self.library_view.currentIndex().row()
|
||||
cr = self.gui.library_view.currentIndex().row()
|
||||
x = self._download_book_metadata
|
||||
self._download_book_metadata = None
|
||||
if x.exception is None:
|
||||
self.library_view.model().refresh_ids(
|
||||
self.gui.library_view.model().refresh_ids(
|
||||
x.updated, cr)
|
||||
if self.cover_flow:
|
||||
self.cover_flow.dataChanged()
|
||||
@ -83,8 +83,8 @@ class EditMetadataAction(object):
|
||||
'''
|
||||
Edit metadata of selected books in library.
|
||||
'''
|
||||
rows = self.library_view.selectionModel().selectedRows()
|
||||
previous = self.library_view.currentIndex()
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
previous = self.gui.library_view.currentIndex()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot edit metadata'),
|
||||
_('No books selected'))
|
||||
@ -95,12 +95,12 @@ class EditMetadataAction(object):
|
||||
return self.edit_bulk_metadata(checked)
|
||||
|
||||
def accepted(id):
|
||||
self.library_view.model().refresh_ids([id])
|
||||
self.gui.library_view.model().refresh_ids([id])
|
||||
|
||||
for row in rows:
|
||||
self._metadata_view_id = self.library_view.model().db.id(row.row())
|
||||
self._metadata_view_id = self.gui.library_view.model().db.id(row.row())
|
||||
d = MetadataSingleDialog(self, row.row(),
|
||||
self.library_view.model().db,
|
||||
self.gui.library_view.model().db,
|
||||
accepted_callback=accepted,
|
||||
cancel_all=rows.index(row) < len(rows)-1)
|
||||
d.view_format.connect(self.metadata_view_format)
|
||||
@ -108,8 +108,8 @@ class EditMetadataAction(object):
|
||||
if d.cancel_all:
|
||||
break
|
||||
if rows:
|
||||
current = self.library_view.currentIndex()
|
||||
m = self.library_view.model()
|
||||
current = self.gui.library_view.currentIndex()
|
||||
m = self.gui.library_view.model()
|
||||
if self.cover_flow:
|
||||
self.cover_flow.dataChanged()
|
||||
m.current_changed(current, previous)
|
||||
@ -120,16 +120,16 @@ class EditMetadataAction(object):
|
||||
Edit metadata of selected books in library in bulk.
|
||||
'''
|
||||
rows = [r.row() for r in \
|
||||
self.library_view.selectionModel().selectedRows()]
|
||||
self.gui.library_view.selectionModel().selectedRows()]
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot edit metadata'),
|
||||
_('No books selected'))
|
||||
d.exec_()
|
||||
return
|
||||
if MetadataBulkDialog(self, rows,
|
||||
self.library_view.model().db).changed:
|
||||
self.library_view.model().resort(reset=False)
|
||||
self.library_view.model().research()
|
||||
self.gui.library_view.model().db).changed:
|
||||
self.gui.library_view.model().resort(reset=False)
|
||||
self.gui.library_view.model().research()
|
||||
self.tags_view.recount()
|
||||
if self.cover_flow:
|
||||
self.cover_flow.dataChanged()
|
||||
@ -141,7 +141,7 @@ class EditMetadataAction(object):
|
||||
'''
|
||||
if self.stack.currentIndex() != 0:
|
||||
return
|
||||
rows = self.library_view.selectionModel().selectedRows()
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
return error_dialog(self, _('Cannot merge books'),
|
||||
_('No books selected'), show=True)
|
||||
@ -186,22 +186,22 @@ class EditMetadataAction(object):
|
||||
for row in rows:
|
||||
if row.row() < rows[0].row():
|
||||
dest_row -= 1
|
||||
ci = self.library_view.model().index(dest_row, 0)
|
||||
ci = self.gui.library_view.model().index(dest_row, 0)
|
||||
if ci.isValid():
|
||||
self.library_view.setCurrentIndex(ci)
|
||||
self.gui.library_view.setCurrentIndex(ci)
|
||||
|
||||
def add_formats(self, dest_id, src_books, replace=False):
|
||||
for src_book in src_books:
|
||||
if src_book:
|
||||
fmt = os.path.splitext(src_book)[-1].replace('.', '').upper()
|
||||
with open(src_book, 'rb') as f:
|
||||
self.library_view.model().db.add_format(dest_id, fmt, f, index_is_id=True,
|
||||
self.gui.library_view.model().db.add_format(dest_id, fmt, f, index_is_id=True,
|
||||
notify=False, replace=replace)
|
||||
|
||||
def books_to_merge(self, rows):
|
||||
src_books = []
|
||||
src_ids = []
|
||||
m = self.library_view.model()
|
||||
m = self.gui.library_view.model()
|
||||
for i, row in enumerate(rows):
|
||||
id_ = m.id(row)
|
||||
if i == 0:
|
||||
@ -216,10 +216,10 @@ class EditMetadataAction(object):
|
||||
return [dest_id, src_books, src_ids]
|
||||
|
||||
def delete_books_after_merge(self, ids_to_delete):
|
||||
self.library_view.model().delete_books_by_id(ids_to_delete)
|
||||
self.gui.library_view.model().delete_books_by_id(ids_to_delete)
|
||||
|
||||
def merge_metadata(self, dest_id, src_ids):
|
||||
db = self.library_view.model().db
|
||||
db = self.gui.library_view.model().db
|
||||
dest_mi = db.get_metadata(dest_id, index_is_id=True, get_cover=True)
|
||||
orig_dest_comments = dest_mi.comments
|
||||
for src_id in src_ids:
|
||||
|
@ -29,8 +29,8 @@ class FetchNewsAction(object):
|
||||
if job.failed:
|
||||
self.scheduler.recipe_download_failed(arg)
|
||||
return self.job_exception(job)
|
||||
id = self.library_view.model().add_news(pt.name, arg)
|
||||
self.library_view.model().reset()
|
||||
id = self.gui.library_view.model().add_news(pt.name, arg)
|
||||
self.gui.library_view.model().reset()
|
||||
sync = dynamic.get('news_to_be_synced', set([]))
|
||||
sync.add(id)
|
||||
dynamic.set('news_to_be_synced', sync)
|
||||
|
@ -28,7 +28,7 @@ class SaveToDiskAction(object):
|
||||
single_format=prefs['output_format'])
|
||||
|
||||
def save_to_disk(self, checked, single_dir=False, single_format=None):
|
||||
rows = self.current_view().selectionModel().selectedRows()
|
||||
rows = self.gui.current_view().selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
return error_dialog(self, _('Cannot save to disk'),
|
||||
_('No books selected'), show=True)
|
||||
@ -37,7 +37,7 @@ class SaveToDiskAction(object):
|
||||
if not path:
|
||||
return
|
||||
dpath = os.path.abspath(path).replace('/', os.sep)
|
||||
lpath = self.library_view.model().db.library_path.replace('/', os.sep)
|
||||
lpath = self.gui.library_view.model().db.library_path.replace('/', os.sep)
|
||||
if dpath.startswith(lpath):
|
||||
return error_dialog(self, _('Not allowed'),
|
||||
_('You are trying to save files into the calibre '
|
||||
@ -45,7 +45,7 @@ class SaveToDiskAction(object):
|
||||
'library. Save to disk is meant to export '
|
||||
'files from your calibre library elsewhere.'), show=True)
|
||||
|
||||
if self.current_view() is self.library_view:
|
||||
if self.gui.current_view() is self.gui.library_view:
|
||||
from calibre.gui2.add import Saver
|
||||
from calibre.library.save_to_disk import config
|
||||
opts = config().parse()
|
||||
@ -61,12 +61,12 @@ class SaveToDiskAction(object):
|
||||
opts.template = opts.template.split('/')[-1].strip()
|
||||
if not opts.template:
|
||||
opts.template = '{title} - {authors}'
|
||||
self._saver = Saver(self, self.library_view.model().db,
|
||||
self._saver = Saver(self, self.gui.library_view.model().db,
|
||||
Dispatcher(self._books_saved), rows, path, opts,
|
||||
spare_server=self.spare_server)
|
||||
|
||||
else:
|
||||
paths = self.current_view().model().paths(rows)
|
||||
paths = self.gui.current_view().model().paths(rows)
|
||||
self.device_manager.save_books(
|
||||
Dispatcher(self.books_saved), paths, path)
|
||||
|
||||
|
@ -19,18 +19,18 @@ from calibre.ptempfile import PersistentTemporaryFile
|
||||
class ViewAction(object):
|
||||
|
||||
def view_format(self, row, format):
|
||||
fmt_path = self.library_view.model().db.format_abspath(row, format)
|
||||
fmt_path = self.gui.library_view.model().db.format_abspath(row, format)
|
||||
if fmt_path:
|
||||
self._view_file(fmt_path)
|
||||
|
||||
def view_format_by_id(self, id_, format):
|
||||
fmt_path = self.library_view.model().db.format_abspath(id_, format,
|
||||
fmt_path = self.gui.library_view.model().db.format_abspath(id_, format,
|
||||
index_is_id=True)
|
||||
if fmt_path:
|
||||
self._view_file(fmt_path)
|
||||
|
||||
def metadata_view_format(self, fmt):
|
||||
fmt_path = self.library_view.model().db.\
|
||||
fmt_path = self.gui.library_view.model().db.\
|
||||
format_abspath(self._metadata_view_id,
|
||||
fmt, index_is_id=True)
|
||||
if fmt_path:
|
||||
@ -67,14 +67,14 @@ class ViewAction(object):
|
||||
self._launch_viewer(name, viewer, internal)
|
||||
|
||||
def view_specific_format(self, triggered):
|
||||
rows = self.library_view.selectionModel().selectedRows()
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot view'), _('No book selected'))
|
||||
d.exec_()
|
||||
return
|
||||
|
||||
row = rows[0].row()
|
||||
formats = self.library_view.model().db.formats(row).upper().split(',')
|
||||
formats = self.gui.library_view.model().db.formats(row).upper().split(',')
|
||||
d = ChooseFormatDialog(self, _('Choose the format to view'), formats)
|
||||
if d.exec_() == d.Accepted:
|
||||
format = d.format()
|
||||
@ -91,7 +91,7 @@ class ViewAction(object):
|
||||
) % num)
|
||||
|
||||
def view_folder(self, *args):
|
||||
rows = self.current_view().selectionModel().selectedRows()
|
||||
rows = self.gui.current_view().selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot open folder'),
|
||||
_('No book selected'))
|
||||
@ -100,15 +100,15 @@ class ViewAction(object):
|
||||
if not self._view_check(len(rows)):
|
||||
return
|
||||
for row in rows:
|
||||
path = self.library_view.model().db.abspath(row.row())
|
||||
path = self.gui.library_view.model().db.abspath(row.row())
|
||||
open_local_file(path)
|
||||
|
||||
def view_folder_for_id(self, id_):
|
||||
path = self.library_view.model().db.abspath(id_, index_is_id=True)
|
||||
path = self.gui.library_view.model().db.abspath(id_, index_is_id=True)
|
||||
open_local_file(path)
|
||||
|
||||
def view_book(self, triggered):
|
||||
rows = self.current_view().selectionModel().selectedRows()
|
||||
rows = self.gui.current_view().selectionModel().selectedRows()
|
||||
self._view_books(rows)
|
||||
|
||||
def view_specific_book(self, index):
|
||||
@ -122,13 +122,13 @@ class ViewAction(object):
|
||||
if not self._view_check(len(rows)):
|
||||
return
|
||||
|
||||
if self.current_view() is self.library_view:
|
||||
if self.gui.current_view() is self.gui.library_view:
|
||||
for row in rows:
|
||||
if hasattr(row, 'row'):
|
||||
row = row.row()
|
||||
|
||||
formats = self.library_view.model().db.formats(row)
|
||||
title = self.library_view.model().db.title(row)
|
||||
formats = self.gui.library_view.model().db.formats(row)
|
||||
title = self.gui.library_view.model().db.title(row)
|
||||
if not formats:
|
||||
error_dialog(self, _('Cannot view'),
|
||||
_('%s has no available formats.')%(title,), show=True)
|
||||
@ -146,7 +146,7 @@ class ViewAction(object):
|
||||
if not in_prefs:
|
||||
self.view_format(row, formats[0])
|
||||
else:
|
||||
paths = self.current_view().model().paths(rows)
|
||||
paths = self.gui.current_view().model().paths(rows)
|
||||
for path in paths:
|
||||
pt = PersistentTemporaryFile('_viewer_'+\
|
||||
os.path.splitext(path)[1])
|
||||
|
Loading…
x
Reference in New Issue
Block a user