mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only send news to device if the device supports the format the news has been downloaded in
This commit is contained in:
parent
ab0c2accef
commit
17df10b5a2
@ -49,13 +49,13 @@ def main(args=sys.argv):
|
||||
input_pdf = PdfFileReader(file(source, "rb"))
|
||||
except:
|
||||
print "Unable to read input"
|
||||
return 2
|
||||
return 2
|
||||
info = input_pdf.getDocumentInfo()
|
||||
title = 'Unknown'
|
||||
author = 'Unknown'
|
||||
if info.title:
|
||||
title = info.title
|
||||
author = info.author
|
||||
title = info.title
|
||||
author = info.author
|
||||
if opts.bounding != None:
|
||||
try:
|
||||
bounding = open( opts.bounding , 'r' )
|
||||
|
@ -385,13 +385,35 @@ class BooksModel(QAbstractTableModel):
|
||||
metadata.append(mi)
|
||||
return metadata
|
||||
|
||||
def get_preferred_formats_from_ids(self, ids, all_formats, mode='r+b'):
|
||||
ans = []
|
||||
for id in ids:
|
||||
format = None
|
||||
fmts = self.db.formats(id, index_is_id=True)
|
||||
if not fmts:
|
||||
fmts = ''
|
||||
available_formats = set(fmts.lower().split(','))
|
||||
for f in all_formats:
|
||||
if f.lower() in available_formats:
|
||||
format = f.lower()
|
||||
break
|
||||
if format is None:
|
||||
ans.append(format)
|
||||
else:
|
||||
f = self.db.format(id, format, index_is_id=True, as_file=True,
|
||||
mode=mode)
|
||||
ans.append(f)
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
def get_preferred_formats(self, rows, formats, paths=False):
|
||||
ans = []
|
||||
for row in (row.row() for row in rows):
|
||||
format = None
|
||||
fmts = self.db.formats(row)
|
||||
if not fmts:
|
||||
return []
|
||||
fmts = ''
|
||||
db_formats = set(fmts.lower().split(','))
|
||||
available_formats = set([f.lower() for f in formats])
|
||||
u = available_formats.intersection(db_formats)
|
||||
|
@ -887,7 +887,8 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
if self.device_connected:
|
||||
ids = list(dynamic.get('news_to_be_synced', set([])))
|
||||
ids = [id for id in ids if self.library_view.model().db.has_id(id)]
|
||||
files = [self.library_view.model().db.format(id, prefs['output_format'], index_is_id=True, as_file=True) for id in ids]
|
||||
files = self.library_view.model().get_preferred_formats_from_ids(
|
||||
ids, self.device_manager.device_class.FORMATS)
|
||||
files = [f for f in files if f is not None]
|
||||
if not files:
|
||||
dynamic.set('news_to_be_synced', set([]))
|
||||
@ -922,7 +923,7 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
if cdata:
|
||||
mi['cover'] = self.cover_to_thumbnail(cdata)
|
||||
metadata = iter(metadata)
|
||||
_files = self.library_view.model().get_preferred_formats(rows,
|
||||
_files = self.library_view.model().get_preferred_formats(rows,
|
||||
self.device_manager.device_class.FORMATS, paths=True)
|
||||
files = [getattr(f, 'name', None) for f in _files]
|
||||
bad, good, gf, names = [], [], [], []
|
||||
|
Loading…
x
Reference in New Issue
Block a user