Only send news to device if the device supports the format the news has been downloaded in

This commit is contained in:
Kovid Goyal 2009-01-14 10:49:06 -08:00
parent ab0c2accef
commit 17df10b5a2
3 changed files with 29 additions and 6 deletions

View File

@ -385,13 +385,35 @@ class BooksModel(QAbstractTableModel):
metadata.append(mi) metadata.append(mi)
return metadata 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): def get_preferred_formats(self, rows, formats, paths=False):
ans = [] ans = []
for row in (row.row() for row in rows): for row in (row.row() for row in rows):
format = None format = None
fmts = self.db.formats(row) fmts = self.db.formats(row)
if not fmts: if not fmts:
return [] fmts = ''
db_formats = set(fmts.lower().split(',')) db_formats = set(fmts.lower().split(','))
available_formats = set([f.lower() for f in formats]) available_formats = set([f.lower() for f in formats])
u = available_formats.intersection(db_formats) u = available_formats.intersection(db_formats)

View File

@ -887,7 +887,8 @@ class Main(MainWindow, Ui_MainWindow):
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([])))
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 = [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] 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([]))