mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1251 (Edit Meta Information page problem) and various minor bug fixes
This commit is contained in:
parent
96d3777d40
commit
d7b7110358
@ -110,19 +110,20 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
else:
|
||||
old_extensions.add(ext)
|
||||
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(',')])
|
||||
extensions = new_extensions.union(old_extensions)
|
||||
for ext in db_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)
|
||||
Ui_MetadataSingleDialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
self.splitter.setStretchFactor(100, 1)
|
||||
self.db = db
|
||||
self.accepted_callback = accepted_callback
|
||||
self.id = db.id(row)
|
||||
self.row = row
|
||||
self.cover_data = None
|
||||
@ -334,20 +335,22 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
if self.formats_changed:
|
||||
self.sync_formats()
|
||||
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())
|
||||
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())
|
||||
if aus:
|
||||
self.db.set_author_sort(self.id, aus)
|
||||
self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text()))
|
||||
self.db.set_rating(self.id, 2*self.rating.value())
|
||||
self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.text()))
|
||||
self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','))
|
||||
self.db.set_series(self.id, qstring_to_unicode(self.series.currentText()))
|
||||
self.db.set_series_index(self.id, self.series_index.value())
|
||||
self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()))
|
||||
self.db.set_author_sort(self.id, aus, notify=False)
|
||||
self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text()), notify=False)
|
||||
self.db.set_rating(self.id, 2*self.rating.value(), notify=False)
|
||||
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(','), notify=False)
|
||||
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(), notify=False)
|
||||
self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()), notify=False)
|
||||
if self.cover_changed:
|
||||
self.db.set_cover(self.id, pixmap_to_data(self.cover.pixmap()))
|
||||
QDialog.accept(self)
|
||||
if callable(self.accepted_callback):
|
||||
self.accepted_callback(self.id)
|
||||
|
@ -139,6 +139,9 @@ class BooksModel(QAbstractTableModel):
|
||||
|
||||
def refresh_ids(self, ids, current_row=-1):
|
||||
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:
|
||||
if self.cover_cache:
|
||||
id = self.db.id(row)
|
||||
@ -147,7 +150,7 @@ class BooksModel(QAbstractTableModel):
|
||||
self.emit(SIGNAL('new_bookdisplay_data(PyQt_PyObject)'),
|
||||
self.get_book_display_info(row))
|
||||
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):
|
||||
self.db.close()
|
||||
|
@ -663,9 +663,13 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
if bulk or (bulk is None and len(rows) > 1):
|
||||
return self.edit_bulk_metadata(checked)
|
||||
|
||||
def accepted(id):
|
||||
self.library_view.model().refresh_ids([id])
|
||||
|
||||
for row in rows:
|
||||
d = MetadataSingleDialog(self, row.row(),
|
||||
self.library_view.model().db)
|
||||
MetadataSingleDialog(self, row.row(),
|
||||
self.library_view.model().db,
|
||||
accepted_callback=accepted)
|
||||
|
||||
def edit_bulk_metadata(self, checked):
|
||||
'''
|
||||
|
@ -645,7 +645,7 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
if self.has_format(index, format, index_is_id):
|
||||
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)
|
||||
if path is None:
|
||||
path = os.path.join(self.library_path, self.path(id, index_is_id=True))
|
||||
@ -670,7 +670,8 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
except AttributeError:
|
||||
fmts = []
|
||||
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):
|
||||
'''
|
||||
@ -689,7 +690,7 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
self.data.books_deleted([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)
|
||||
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)
|
||||
@ -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.remove(format.upper())
|
||||
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):
|
||||
'''
|
||||
|
@ -559,6 +559,8 @@ class BasicNewsRecipe(object, LoggingInterface):
|
||||
|
||||
@classmethod
|
||||
def description_limiter(cls, src):
|
||||
if not src:
|
||||
return ''
|
||||
pos = cls.summary_length
|
||||
fuzz = 50
|
||||
si = src.find(';', pos)
|
||||
@ -572,7 +574,7 @@ class BasicNewsRecipe(object, LoggingInterface):
|
||||
npos = pos
|
||||
ans = src[:npos+1]
|
||||
if isinstance(ans, unicode):
|
||||
return
|
||||
return ans
|
||||
return ans+u'\u2026' if isinstance(ans, unicode) else ans + '...'
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user