mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Bug #1902313: Option to mark all books with annotations/bookmarks
Provided a formatter function annotation_count() that returns the number of annotations for a book
This commit is contained in:
parent
3278603c6b
commit
01b8547872
@ -1948,6 +1948,12 @@ class DB(object):
|
|||||||
self.execute('DELETE FROM annotations_dirtied')
|
self.execute('DELETE FROM annotations_dirtied')
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
def annotation_count_for_book(self, book_id):
|
||||||
|
with self.conn:
|
||||||
|
c = self.execute('SELECT count(id) FROM annotations WHERE book=?', (book_id,))
|
||||||
|
r = c.fetchone()[0]
|
||||||
|
return r
|
||||||
|
|
||||||
def conversion_options(self, book_id, fmt):
|
def conversion_options(self, book_id, fmt):
|
||||||
for (data,) in self.conn.get('SELECT data FROM conversion_options WHERE book=? AND format=?', (book_id, fmt.upper())):
|
for (data,) in self.conn.get('SELECT data FROM conversion_options WHERE book=? AND format=?', (book_id, fmt.upper())):
|
||||||
if data:
|
if data:
|
||||||
|
@ -2329,6 +2329,10 @@ class Cache(object):
|
|||||||
def all_annotations_for_book(self, book_id):
|
def all_annotations_for_book(self, book_id):
|
||||||
return tuple(self.backend.all_annotations_for_book(book_id))
|
return tuple(self.backend.all_annotations_for_book(book_id))
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def annotation_count_for_book(self, book_id):
|
||||||
|
return self.backend.annotation_count_for_book(book_id)
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def all_annotation_users(self):
|
def all_annotation_users(self):
|
||||||
return tuple(self.backend.all_annotation_users())
|
return tuple(self.backend.all_annotation_users())
|
||||||
|
@ -1181,6 +1181,26 @@ class BuiltinOndevice(BuiltinFormatterFunction):
|
|||||||
return _('This function can be used only in the GUI')
|
return _('This function can be used only in the GUI')
|
||||||
|
|
||||||
|
|
||||||
|
class BuiltinAnnotationCount(BuiltinFormatterFunction):
|
||||||
|
name = 'annotation_count'
|
||||||
|
arg_count = 0
|
||||||
|
category = 'Get values from metadata'
|
||||||
|
__doc__ = doc = _('annotation_count() -- return the total number of annotations '
|
||||||
|
'of all types attached to the current book. '
|
||||||
|
'This function works only in the GUI.')
|
||||||
|
|
||||||
|
def evaluate(self, formatter, kwargs, mi, locals):
|
||||||
|
if hasattr(mi, '_proxy_metadata'):
|
||||||
|
try:
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
c = get_gui().current_db.new_api.annotation_count_for_book(mi.id)
|
||||||
|
return '' if c == 0 else unicode_type(c)
|
||||||
|
except:
|
||||||
|
return _('Failed to fetch annotation count')
|
||||||
|
return ''
|
||||||
|
return _('This function can be used only in the GUI')
|
||||||
|
|
||||||
|
|
||||||
class BuiltinSeriesSort(BuiltinFormatterFunction):
|
class BuiltinSeriesSort(BuiltinFormatterFunction):
|
||||||
name = 'series_sort'
|
name = 'series_sort'
|
||||||
arg_count = 0
|
arg_count = 0
|
||||||
@ -1808,7 +1828,7 @@ _formatter_builtins = [
|
|||||||
BuiltinSwapAroundComma(), BuiltinSwitch(),
|
BuiltinSwapAroundComma(), BuiltinSwitch(),
|
||||||
BuiltinTemplate(), BuiltinTest(), BuiltinTitlecase(),
|
BuiltinTemplate(), BuiltinTest(), BuiltinTitlecase(),
|
||||||
BuiltinToday(), BuiltinTransliterate(), BuiltinUppercase(),
|
BuiltinToday(), BuiltinTransliterate(), BuiltinUppercase(),
|
||||||
BuiltinUserCategories(), BuiltinVirtualLibraries()
|
BuiltinUserCategories(), BuiltinVirtualLibraries(), BuiltinAnnotationCount()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user