mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-04-01 14:52:29 -04:00
Enabled automatic extraction of comments from lrf files when a new book is added.
Fixed rendering of book info in library view. Fixed clicking on first item in list would not show book info. Version bump.
This commit is contained in:
parent
b3faebd2f2
commit
714b4efbd8
@ -37,6 +37,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
|
||||
You may have to adjust the GROUP and the location of the rules file to
|
||||
suit your distribution.
|
||||
"""
|
||||
__version__ = "0.3.0b2"
|
||||
__version__ = "0.3.0b3"
|
||||
__docformat__ = "epytext"
|
||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
|
||||
@ -57,6 +57,7 @@ class LibraryDatabase(object):
|
||||
title, author, publisher, size, cover = os.path.basename(_file), \
|
||||
None, None, os.stat(_file)[ST_SIZE], None
|
||||
ext = title[title.rfind(".")+1:].lower() if title.find(".") > -1 else None
|
||||
comments = None
|
||||
if ext == "lrf":
|
||||
lrf = LRFMetaFile(open(_file, "r+b"))
|
||||
title, author, cover, publisher = lrf.title, lrf.author.strip(), \
|
||||
@ -65,6 +66,9 @@ class LibraryDatabase(object):
|
||||
publisher = None
|
||||
if "unknown" in author.lower():
|
||||
author = None
|
||||
comments = lrf.free_text
|
||||
if not comments:
|
||||
comments = None
|
||||
data = open(_file).read()
|
||||
usize = len(data)
|
||||
data = compress(data)
|
||||
@ -75,7 +79,7 @@ class LibraryDatabase(object):
|
||||
self.con.execute("insert into books_meta (title, authors, publisher, "+\
|
||||
"size, tags, comments, rating) values "+\
|
||||
"(?,?,?,?,?,?,?)", \
|
||||
(title, author, publisher, size, None, None, None))
|
||||
(title, author, publisher, size, None, comments, None))
|
||||
_id = self.con.execute("select max(id) from books_meta").next()[0]
|
||||
self.con.execute("insert into books_data values (?,?,?,?)", \
|
||||
(_id, ext, usize, sqlite.Binary(data)))
|
||||
@ -163,6 +167,9 @@ class LibraryDatabase(object):
|
||||
lrf = LRFMetaFile(s)
|
||||
lrf.author = metadata["authors"]
|
||||
lrf.title = metadata["title"]
|
||||
# Not sure if I want to override the lrf freetext field
|
||||
# with a possibly null value
|
||||
#lrf.free_text = metadata["comments"]
|
||||
except LRFException:
|
||||
pass
|
||||
data = s.getvalue()
|
||||
@ -201,7 +208,7 @@ class LibraryDatabase(object):
|
||||
return None
|
||||
data = {}
|
||||
for field in ("id", "title", "authors", "publisher", "size", "tags",
|
||||
"date"):
|
||||
"date", "comments"):
|
||||
data[field] = row[field]
|
||||
return data
|
||||
|
||||
|
||||
@ -38,10 +38,7 @@ from editbook import EditBookDialog
|
||||
|
||||
|
||||
DEFAULT_BOOK_COVER = None
|
||||
LIBRARY_BOOK_TEMPLATE = QString("<table><tr><td><b>Formats:</b> %1 \
|
||||
</td><td><b>Tags:</b> %2</td></tr> \
|
||||
<tr><td colspan='2'><b>Comments:</b> %3</td>\
|
||||
</tr></table>")
|
||||
LIBRARY_BOOK_TEMPLATE = QString("<b>Formats:</b> %1<br><b>Tags:</b> %2<br>%3")
|
||||
DEVICE_BOOK_TEMPLATE = QString("<table><tr><td><b>Title: </b>%1</td><td> \
|
||||
<b> Size:</b> %2</td></tr>\
|
||||
<tr><td><b>Author: </b>%3</td>\
|
||||
@ -124,12 +121,13 @@ class Main(QObject, Ui_MainWindow):
|
||||
for r in range(topleft.row(), bottomright.row()+1):
|
||||
self.current_view.resizeRowToContents(r)
|
||||
|
||||
def show_book(self, current, previous):
|
||||
if not len(self.current_view.selectedIndexes()):
|
||||
def show_book(self, current, previous):
|
||||
if not current.isValid():
|
||||
return
|
||||
if self.library_view.isVisible():
|
||||
formats, tags, comments, cover = self.library_model\
|
||||
.info(current.row())
|
||||
comments = re.sub('\n', '<br>', comments)
|
||||
data = LIBRARY_BOOK_TEMPLATE.arg(formats).arg(tags).arg(comments)
|
||||
tooltip = "To save the cover, drag it to the desktop.<br>To \
|
||||
change the cover drag the new cover onto this picture"
|
||||
@ -488,7 +486,7 @@ class Main(QObject, Ui_MainWindow):
|
||||
self.df.setText(self.df_template.arg("").arg("").arg(""))
|
||||
window.show()
|
||||
self.library_view.resizeColumnsToContents()
|
||||
self.library_view.resizeRowsToContents()
|
||||
self.library_view.resizeRowsToContents()
|
||||
|
||||
|
||||
def device_removed(self):
|
||||
|
||||
@ -526,7 +526,9 @@ class LibraryBooksModel(QAbstractTableModel):
|
||||
tags = row["tags"]
|
||||
if not tags: tags = ""
|
||||
comments = row["comments"]
|
||||
if not comments: comments = ""
|
||||
if not comments:
|
||||
comments = ""
|
||||
comments = TableView.wrap(comments, width=80)
|
||||
return exts, tags, comments, cover
|
||||
|
||||
def id_from_index(self, index): return self._data[index.row()]["id"]
|
||||
|
||||
@ -114,6 +114,8 @@ class xml_field(object):
|
||||
return ""
|
||||
|
||||
def __set__(self, obj, val):
|
||||
if val == None:
|
||||
val = ""
|
||||
document = dom.parseString(obj.info)
|
||||
def create_elem():
|
||||
elem = document.createElement(self.tag_name)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user