From 5769ce558c4527a5a5f5f59db36394be5de55fac Mon Sep 17 00:00:00 2001
From: Kovid Goyal Books with the same title as the following already exist in the database. Add them anyway? Books with the same title as the following already exist in the database. Add them anyway?')
for mi, formats in duplicates:
@@ -634,49 +650,61 @@ class Main(MainWindow, Ui_MainWindow):
def _add_books(self, paths, to_device, on_card=None):
if on_card is None:
on_card = self.stack.currentIndex() == 2
+ if not paths:
+ return
# Get format and metadata information
formats, metadata, names, infos = [], [], [], []
- for book in paths:
- format = os.path.splitext(book)[1]
- format = format[1:] if format else None
- stream = open(book, 'rb')
- try:
- mi = get_metadata(stream, stream_type=format, use_libprs_metadata=True)
- except:
- mi = MetaInformation(None, None)
- if not mi.title:
- mi.title = os.path.splitext(os.path.basename(book))[0]
- if not mi.authors:
- mi.authors = [_('Unknown')]
- formats.append(format)
- metadata.append(mi)
- names.append(os.path.basename(book))
- infos.append({'title':mi.title, 'authors':', '.join(mi.authors),
- 'cover':self.default_thumbnail, 'tags':[]})
-
- if not to_device:
- model = self.library_view.model()
+ progress = QProgressDialog(_('Reading metadata...'), _('Stop'), 0, len(paths), self)
+ progress.setWindowTitle(_('Adding books...'))
+ progress.setWindowModality(Qt.ApplicationModal)
+ progress.setLabelText(_('Reading metadata...'))
+ progress.show()
+ try:
+ for c, book in enumerate(paths):
+ progress.setValue(c)
+ if progress.wasCanceled():
+ return
+ format = os.path.splitext(book)[1]
+ format = format[1:] if format else None
+ stream = open(book, 'rb')
+ try:
+ mi = get_metadata(stream, stream_type=format, use_libprs_metadata=True)
+ except:
+ mi = MetaInformation(None, None)
+ if not mi.title:
+ mi.title = os.path.splitext(os.path.basename(book))[0]
+ if not mi.authors:
+ mi.authors = [_('Unknown')]
+ formats.append(format)
+ metadata.append(mi)
+ names.append(os.path.basename(book))
+ infos.append({'title':mi.title, 'authors':', '.join(mi.authors),
+ 'cover':self.default_thumbnail, 'tags':[]})
+ title = mi.title if isinstance(mi.title, unicode) else mi.title.decode(preferred_encoding, 'replace')
+ progress.setLabelText(_('Read metadata from ')+title)
- paths = list(paths)
- #for i, path in enumerate(paths):
- # npath, fmt = import_format(path)
- # if npath is not None:
- # paths[i] = npath
- # formats[i] = fmt
- duplicates, number_added = model.add_books(paths, formats, metadata)
- if duplicates:
- files = _('
')
- for mi in duplicates[2]:
- files += '
Books with the same title as the following already exist in the database. Add them anyway?