Fix #1251 (Edit Meta Information page problem) and various minor bug fixes

This commit is contained in:
Kovid Goyal 2008-11-11 18:46:49 -08:00
parent 96d3777d40
commit d7b7110358
5 changed files with 35 additions and 21 deletions

View File

@ -110,19 +110,20 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
else: else:
old_extensions.add(ext) old_extensions.add(ext)
for ext in new_extensions: for ext in new_extensions:
self.db.add_format(self.row, ext, open(paths[ext], 'rb')) self.db.add_format(self.row, ext, open(paths[ext], 'rb'), notify=False)
db_extensions = set([f.lower() for f in self.db.formats(self.row).split(',')]) db_extensions = set([f.lower() for f in self.db.formats(self.row).split(',')])
extensions = new_extensions.union(old_extensions) extensions = new_extensions.union(old_extensions)
for ext in db_extensions: for ext in db_extensions:
if ext not in extensions: if ext not in extensions:
self.db.remove_format(self.row, ext) self.db.remove_format(self.row, ext, notify=False)
def __init__(self, window, row, db): def __init__(self, window, row, db, accepted_callback=None):
QDialog.__init__(self, window) QDialog.__init__(self, window)
Ui_MetadataSingleDialog.__init__(self) Ui_MetadataSingleDialog.__init__(self)
self.setupUi(self) self.setupUi(self)
self.splitter.setStretchFactor(100, 1) self.splitter.setStretchFactor(100, 1)
self.db = db self.db = db
self.accepted_callback = accepted_callback
self.id = db.id(row) self.id = db.id(row)
self.row = row self.row = row
self.cover_data = None self.cover_data = None
@ -334,20 +335,22 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
if self.formats_changed: if self.formats_changed:
self.sync_formats() self.sync_formats()
title = qstring_to_unicode(self.title.text()) title = qstring_to_unicode(self.title.text())
self.db.set_title(self.id, title) self.db.set_title(self.id, title, notify=False)
au = unicode(self.authors.text()) au = unicode(self.authors.text())
if au: if au:
self.db.set_authors(self.id, string_to_authors(au)) self.db.set_authors(self.id, string_to_authors(au), notify=False)
aus = qstring_to_unicode(self.author_sort.text()) aus = qstring_to_unicode(self.author_sort.text())
if aus: if aus:
self.db.set_author_sort(self.id, aus) self.db.set_author_sort(self.id, aus, notify=False)
self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text())) self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text()), notify=False)
self.db.set_rating(self.id, 2*self.rating.value()) self.db.set_rating(self.id, 2*self.rating.value(), notify=False)
self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.text())) self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.text()), notify=False)
self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(',')) self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','), notify=False)
self.db.set_series(self.id, qstring_to_unicode(self.series.currentText())) self.db.set_series(self.id, qstring_to_unicode(self.series.currentText()), notify=False)
self.db.set_series_index(self.id, self.series_index.value()) self.db.set_series_index(self.id, self.series_index.value(), notify=False)
self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText())) self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()), notify=False)
if self.cover_changed: if self.cover_changed:
self.db.set_cover(self.id, pixmap_to_data(self.cover.pixmap())) self.db.set_cover(self.id, pixmap_to_data(self.cover.pixmap()))
QDialog.accept(self) QDialog.accept(self)
if callable(self.accepted_callback):
self.accepted_callback(self.id)

View File

@ -139,6 +139,9 @@ class BooksModel(QAbstractTableModel):
def refresh_ids(self, ids, current_row=-1): def refresh_ids(self, ids, current_row=-1):
rows = self.db.refresh_ids(ids) rows = self.db.refresh_ids(ids)
self.refresh_rows(rows, current_row=current_row)
def refresh_rows(self, rows, current_row=-1):
for row in rows: for row in rows:
if self.cover_cache: if self.cover_cache:
id = self.db.id(row) id = self.db.id(row)
@ -147,7 +150,7 @@ class BooksModel(QAbstractTableModel):
self.emit(SIGNAL('new_bookdisplay_data(PyQt_PyObject)'), self.emit(SIGNAL('new_bookdisplay_data(PyQt_PyObject)'),
self.get_book_display_info(row)) self.get_book_display_info(row))
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'),
self.index(row, 0), self.index(row, self.columnCount(None)-1)) self.index(row, 0), self.index(row, self.columnCount(QModelIndex())-1))
def close(self): def close(self):
self.db.close() self.db.close()

View File

@ -662,10 +662,14 @@ class Main(MainWindow, Ui_MainWindow):
if bulk or (bulk is None and len(rows) > 1): if bulk or (bulk is None and len(rows) > 1):
return self.edit_bulk_metadata(checked) return self.edit_bulk_metadata(checked)
def accepted(id):
self.library_view.model().refresh_ids([id])
for row in rows: for row in rows:
d = MetadataSingleDialog(self, row.row(), MetadataSingleDialog(self, row.row(),
self.library_view.model().db) self.library_view.model().db,
accepted_callback=accepted)
def edit_bulk_metadata(self, checked): def edit_bulk_metadata(self, checked):
''' '''

View File

@ -645,7 +645,7 @@ class LibraryDatabase2(LibraryDatabase):
if self.has_format(index, format, index_is_id): if self.has_format(index, format, index_is_id):
self.remove_format(id, format, index_is_id=True) self.remove_format(id, format, index_is_id=True)
def add_format(self, index, format, stream, index_is_id=False, path=None): def add_format(self, index, format, stream, index_is_id=False, path=None, notify=True):
id = index if index_is_id else self.id(index) id = index if index_is_id else self.id(index)
if path is None: if path is None:
path = os.path.join(self.library_path, self.path(id, index_is_id=True)) path = os.path.join(self.library_path, self.path(id, index_is_id=True))
@ -670,7 +670,8 @@ class LibraryDatabase2(LibraryDatabase):
except AttributeError: except AttributeError:
fmts = [] fmts = []
self.data.set(id, FIELD_MAP['formats'], ','.join(fmts+[format.upper()]), row_is_id=True) self.data.set(id, FIELD_MAP['formats'], ','.join(fmts+[format.upper()]), row_is_id=True)
self.notify('metadata', [id]) if notify:
self.notify('metadata', [id])
def delete_book(self, id): def delete_book(self, id):
''' '''
@ -689,7 +690,7 @@ class LibraryDatabase2(LibraryDatabase):
self.data.books_deleted([id]) self.data.books_deleted([id])
self.notify('delete', [id]) self.notify('delete', [id])
def remove_format(self, index, format, index_is_id=False): def remove_format(self, index, format, index_is_id=False, notify=True):
id = index if index_is_id else self.id(index) id = index if index_is_id else self.id(index)
path = os.path.join(self.library_path, self.path(id, index_is_id=True)) path = os.path.join(self.library_path, self.path(id, index_is_id=True))
name = self.conn.get('SELECT name FROM data WHERE book=? AND format=?', (id, format), all=False) name = self.conn.get('SELECT name FROM data WHERE book=? AND format=?', (id, format), all=False)
@ -706,7 +707,8 @@ class LibraryDatabase2(LibraryDatabase):
fmts = [f.strip().upper() for f in self.data[self.data.row(id)][FIELD_MAP['formats']].split(',')] fmts = [f.strip().upper() for f in self.data[self.data.row(id)][FIELD_MAP['formats']].split(',')]
fmts.remove(format.upper()) fmts.remove(format.upper())
self.data.set(id, FIELD_MAP['formats'], ','.join(fmts), row_is_id=True) self.data.set(id, FIELD_MAP['formats'], ','.join(fmts), row_is_id=True)
self.notify('metadata', [id]) if notify:
self.notify('metadata', [id])
def clean(self): def clean(self):
''' '''

View File

@ -559,6 +559,8 @@ class BasicNewsRecipe(object, LoggingInterface):
@classmethod @classmethod
def description_limiter(cls, src): def description_limiter(cls, src):
if not src:
return ''
pos = cls.summary_length pos = cls.summary_length
fuzz = 50 fuzz = 50
si = src.find(';', pos) si = src.find(';', pos)
@ -572,7 +574,7 @@ class BasicNewsRecipe(object, LoggingInterface):
npos = pos npos = pos
ans = src[:npos+1] ans = src[:npos+1]
if isinstance(ans, unicode): if isinstance(ans, unicode):
return return ans
return ans+u'\u2026' if isinstance(ans, unicode) else ans + '...' return ans+u'\u2026' if isinstance(ans, unicode) else ans + '...'