mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Implement #352
This commit is contained in:
parent
0128e830c5
commit
cedbe608ec
@ -107,7 +107,7 @@ class BooksModel(QAbstractTableModel):
|
||||
def __init__(self, parent):
|
||||
QAbstractTableModel.__init__(self, parent)
|
||||
self.db = None
|
||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher']
|
||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher', 'series']
|
||||
self.sorted_on = (3, Qt.AscendingOrder)
|
||||
self.last_search = '' # The last search performed on this model
|
||||
|
||||
@ -301,6 +301,10 @@ class BooksModel(QAbstractTableModel):
|
||||
pub = self.db.publisher(row)
|
||||
if pub:
|
||||
return QVariant(BooksView.wrap(pub, 20))
|
||||
elif col == 6:
|
||||
series = self.db.series(row)
|
||||
if series:
|
||||
return QVariant(series)
|
||||
return NONE
|
||||
elif role == Qt.TextAlignmentRole and index.column() in [2, 3, 4]:
|
||||
return QVariant(Qt.AlignRight | Qt.AlignVCenter)
|
||||
@ -320,6 +324,7 @@ class BooksModel(QAbstractTableModel):
|
||||
elif section == 3: text = _("Date")
|
||||
elif section == 4: text = _("Rating")
|
||||
elif section == 5: text = _("Publisher")
|
||||
elif section == 6: text = _("Series")
|
||||
return QVariant(text)
|
||||
else:
|
||||
return QVariant(section+1)
|
||||
|
@ -668,7 +668,32 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
''')
|
||||
conn.execute('pragma user_version=3')
|
||||
conn.commit()
|
||||
|
||||
@staticmethod
|
||||
def upgrade_version3(conn):
|
||||
conn.executescript(
|
||||
'''
|
||||
/***** Add series_index column to meta view ******/
|
||||
DROP VIEW meta;
|
||||
CREATE VIEW meta AS
|
||||
SELECT id, title,
|
||||
(SELECT concat(name) FROM authors WHERE authors.id IN (SELECT author from books_authors_link WHERE book=books.id)) authors,
|
||||
(SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
|
||||
(SELECT rating FROM ratings WHERE ratings.id IN (SELECT rating from books_ratings_link WHERE book=books.id)) rating,
|
||||
timestamp,
|
||||
(SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size,
|
||||
(SELECT concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags,
|
||||
(SELECT text FROM comments WHERE book=books.id) comments,
|
||||
(SELECT name FROM series WHERE series.id IN (SELECT series FROM books_series_link WHERE book=books.id)) series,
|
||||
series_index,
|
||||
sort,
|
||||
author_sort
|
||||
FROM books;
|
||||
''')
|
||||
conn.execute('pragma user_version=4')
|
||||
conn.commit()
|
||||
|
||||
|
||||
def __del__(self):
|
||||
global _lock_file
|
||||
import os
|
||||
@ -686,6 +711,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
LibraryDatabase.upgrade_version1(self.conn)
|
||||
if self.user_version == 2: # Upgrade to 3
|
||||
LibraryDatabase.upgrade_version2(self.conn)
|
||||
if self.user_version == 3: # Upgrade to 4
|
||||
LibraryDatabase.upgrade_version3(self.conn)
|
||||
|
||||
@apply
|
||||
def user_version():
|
||||
@ -706,16 +733,19 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
'publisher': 'publisher',
|
||||
'size': 'size',
|
||||
'date': 'timestamp',
|
||||
'rating': 'rating'
|
||||
'rating': 'rating',
|
||||
'series': 'series',
|
||||
}
|
||||
field = FIELDS[sort_field]
|
||||
order = 'ASC'
|
||||
if not ascending:
|
||||
order = 'DESC'
|
||||
sort = field + ' ' + order
|
||||
if field == 'series':
|
||||
sort += ',series_index '+order
|
||||
|
||||
|
||||
self.cache = self.conn.execute('SELECT * from meta ORDER BY '+field+' '
|
||||
+order).fetchall()
|
||||
self.cache = self.conn.execute('SELECT * from meta ORDER BY '+sort).fetchall()
|
||||
self.data = self.cache
|
||||
self.conn.commit()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user