mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Auto convert when syncing news.
This commit is contained in:
parent
91b7cbc580
commit
8398d4a7d7
@ -640,12 +640,33 @@ class DeviceGUI(object):
|
|||||||
', '.join(sent_mails), 3000)
|
', '.join(sent_mails), 3000)
|
||||||
|
|
||||||
|
|
||||||
def sync_news(self):
|
def sync_news(self, send_ids=None, do_auto=True):
|
||||||
if self.device_connected:
|
if self.device_connected:
|
||||||
ids = list(dynamic.get('news_to_be_synced', set([])))
|
ids = list(dynamic.get('news_to_be_synced', set([]))) if send_ids is None else send_ids
|
||||||
ids = [id for id in ids if self.library_view.model().db.has_id(id)]
|
ids = [id for id in ids if self.library_view.model().db.has_id(id)]
|
||||||
files, auto = self.library_view.model().get_preferred_formats_from_ids(
|
files, _auto_ids = self.library_view.model().get_preferred_formats_from_ids(
|
||||||
ids, self.device_manager.device_class.settings().format_map)
|
ids, self.device_manager.device_class.settings().format_map,
|
||||||
|
exclude_auto=do_auto)
|
||||||
|
auto = []
|
||||||
|
if _auto_ids:
|
||||||
|
for id in _auto_ids:
|
||||||
|
formats = [f.lower() for f in self.library_view.model().db.formats(id, index_is_id=True).split(',')]
|
||||||
|
formats = formats if formats != None else []
|
||||||
|
if list(set(formats).intersection(available_input_formats())) != [] and list(set(self.device_manager.device_class.settings().format_map).intersection(available_output_formats())) != []:
|
||||||
|
auto.append(id)
|
||||||
|
if auto != []:
|
||||||
|
format = None
|
||||||
|
for fmt in self.device_manager.device_class.settings().format_map:
|
||||||
|
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
||||||
|
format = fmt
|
||||||
|
break
|
||||||
|
if format is not None:
|
||||||
|
autos = [self.library_view.model().db.title(id, index_is_id=True) for id in auto]
|
||||||
|
autos = '\n'.join('%s'%i for i in autos)
|
||||||
|
info_dialog(self, _('No suitable formats'),
|
||||||
|
_('Auto converting the following books before uploading to '
|
||||||
|
'the device:'), det_msg=autos, show=True)
|
||||||
|
self.auto_convert_news(auto, format)
|
||||||
files = [f for f in files if f is not None]
|
files = [f for f in files if f is not None]
|
||||||
if not files:
|
if not files:
|
||||||
dynamic.set('news_to_be_synced', set([]))
|
dynamic.set('news_to_be_synced', set([]))
|
||||||
@ -667,8 +688,10 @@ class DeviceGUI(object):
|
|||||||
if config['upload_news_to_device'] and files:
|
if config['upload_news_to_device'] and files:
|
||||||
remove = ids if \
|
remove = ids if \
|
||||||
config['delete_news_from_library_on_upload'] else []
|
config['delete_news_from_library_on_upload'] else []
|
||||||
on_card = self.location_view.model().free[0] < \
|
space = { self.location_view.model().free[0] : 'main',
|
||||||
self.location_view.model().free[1]
|
self.location_view.model().free[1] : 'carda',
|
||||||
|
self.location_view.model().free[2] : 'cardb' }
|
||||||
|
on_card = space.get(sorted(space.keys(), reverse=True)[0], 'main')
|
||||||
self.upload_books(files, names, metadata,
|
self.upload_books(files, names, metadata,
|
||||||
on_card=on_card,
|
on_card=on_card,
|
||||||
memory=[[f.name for f in files], remove])
|
memory=[[f.name for f in files], remove])
|
||||||
|
@ -1080,6 +1080,24 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
current = self.library_view.currentIndex()
|
current = self.library_view.currentIndex()
|
||||||
self.library_view.model().current_changed(current, previous)
|
self.library_view.model().current_changed(current, previous)
|
||||||
|
|
||||||
|
def auto_convert_news(self, book_ids, format):
|
||||||
|
previous = self.library_view.currentIndex()
|
||||||
|
rows = [x.row() for x in \
|
||||||
|
self.library_view.selectionModel().selectedRows()]
|
||||||
|
jobs, changed, bad = convert_single_ebook(self, self.library_view.model().db, book_ids, True, format)
|
||||||
|
if jobs == []: return
|
||||||
|
for func, args, desc, fmt, id, temp_files in jobs:
|
||||||
|
if id not in bad:
|
||||||
|
job = self.job_manager.run_job(Dispatcher(self.book_auto_converted_news),
|
||||||
|
func, args=args, description=desc)
|
||||||
|
self.conversion_jobs[job] = (temp_files, fmt, id)
|
||||||
|
|
||||||
|
if changed:
|
||||||
|
self.library_view.model().refresh_rows(rows)
|
||||||
|
current = self.library_view.currentIndex()
|
||||||
|
self.library_view.model().current_changed(current, previous)
|
||||||
|
|
||||||
|
|
||||||
def get_books_for_conversion(self):
|
def get_books_for_conversion(self):
|
||||||
rows = [r.row() for r in \
|
rows = [r.row() for r in \
|
||||||
self.library_view.selectionModel().selectedRows()]
|
self.library_view.selectionModel().selectedRows()]
|
||||||
@ -1175,6 +1193,29 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
|
|
||||||
self.send_by_mail(to, fmts, delete_from_library, specific_format=fmt, send_ids=[book_id], do_auto_convert=False)
|
self.send_by_mail(to, fmts, delete_from_library, specific_format=fmt, send_ids=[book_id], do_auto_convert=False)
|
||||||
|
|
||||||
|
def book_auto_converted_news(self, job):
|
||||||
|
temp_files, fmt, book_id = self.conversion_jobs.pop(job)
|
||||||
|
try:
|
||||||
|
if job.failed:
|
||||||
|
return self.job_exception(job)
|
||||||
|
data = open(temp_files[0].name, 'rb')
|
||||||
|
self.library_view.model().db.add_format(book_id, fmt, data, index_is_id=True)
|
||||||
|
data.close()
|
||||||
|
self.status_bar.showMessage(job.description + (' completed'), 2000)
|
||||||
|
finally:
|
||||||
|
for f in temp_files:
|
||||||
|
try:
|
||||||
|
if os.path.exists(f.name):
|
||||||
|
os.remove(f.name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.tags_view.recount()
|
||||||
|
if self.current_view() is self.library_view:
|
||||||
|
current = self.library_view.currentIndex()
|
||||||
|
self.library_view.model().current_changed(current, QModelIndex())
|
||||||
|
|
||||||
|
self.sync_news(send_ids=[book_id], do_auto_convert=False)
|
||||||
|
|
||||||
def book_converted(self, job):
|
def book_converted(self, job):
|
||||||
temp_files, fmt, book_id = self.conversion_jobs.pop(job)
|
temp_files, fmt, book_id = self.conversion_jobs.pop(job)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user