branch: externals/calibre
commit be94be6962bc075230e3f950e7666f4f02cf5bb5
Author: Kjartan Óli Ágústsson <[email protected]>
Commit: Kjartan Óli Ágústsson <[email protected]>

    Add ability to filter by series and format
    
    * calibre-db.el (calibre-db--get-formats): Create
    (calibre--get-filter-items): Assume value is already a string when
    field is format.
    * calibre-search.el (calibre-library-search-series,
    calibre-library-search-format): Create
    (calibre-search): Add bindings for calibre-library-search-series and
    calibre-library-search-format.
    
    It would be pointless to convert the result of
    calibre-search-chose-format to a symbol, just to immediately convert
    it back to a string.
---
 calibre-db.el     | 7 ++++++-
 calibre-search.el | 8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/calibre-db.el b/calibre-db.el
index bef7697574..313d6e18ff 100644
--- a/calibre-db.el
+++ b/calibre-db.el
@@ -107,6 +107,11 @@ WHERE books.id = ?"
   (flatten-list (sqlite-select (calibre--db)
                                "SELECT name FROM publishers;")))
 
+(defun calibre-db--get-formats ()
+  "Return a list of the file formats stored in the active library."
+  (flatten-list (sqlite-select (calibre--db)
+                               "SELECT DISTINCT format FROM data;")))
+
 (defvar calibre--db nil)
 (defun calibre--db ()
   "Return the metadata database."
@@ -179,7 +184,7 @@ WHERE format = ?" `[,format])))
       (tag (calibre-db--get-tag-books value))
       (publisher (calibre-db--get-publisher-books value))
       (series (calibre-db--get-series-books value))
-      (format (calibre-db--get-format-books (upcase (symbol-name value)))))))
+      (format (calibre-db--get-format-books value)))))
 
 (defun calibre-library--filter (filters books)
   "Return those books in BOOKS that match FILTERS.
diff --git a/calibre-search.el b/calibre-search.el
index fad8824fa3..8e2fb187a1 100644
--- a/calibre-search.el
+++ b/calibre-search.el
@@ -48,6 +48,8 @@ will not be appended to the calibre-db--get-FIELD function's 
name."
 (calibre-search--choice-function "author" t)
 (calibre-search--choice-function "publisher")
 (calibre-search--choice-function "tag")
+(calibre-search--choice-function "series" nil t)
+(calibre-search--choice-function "format")
 
 (defun calibre-search--operation (args)
   "Return the appropriate symbol for a filter operation.
@@ -68,7 +70,9 @@ ARGS is the argument list of a transient command."
 
 (calibre-library--search-function "author")
 (calibre-library--search-function "publisher")
+(calibre-library--search-function "series")
 (calibre-library--search-function "tag")
+(calibre-library--search-function "format")
 
 (defun calibre-library-clear-last-search ()
   "Clear the last applied search filter."
@@ -85,7 +89,9 @@ ARGS is the argument list of a transient command."
   ["Search"
    ("a" "Author" calibre-library-search-author)
    ("p" "Publisher" calibre-library-search-publisher)
-   ("t" "Tag" calibre-library-search-tag)]
+   ("t" "Tag" calibre-library-search-tag)
+   ("s" "Series" calibre-library-search-series)
+   ("f" "Format" calibre-library-search-format)]
   ["Misc"
    ("u" "Undo" calibre-library-clear-last-search)
    ("c" "Clear" calibre-library-clear-filters)

Reply via email to