Skip to content

Commit

Permalink
Support pages
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyanming committed Jul 6, 2024
1 parent 8ca1b52 commit 7787299
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 2,269 deletions.
3 changes: 1 addition & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ The following columns will be searched:
If the keyword occurs in any of the columns above, the matched ebook record will
be shown.

1. Live filter searches the results in =calibredb-full-entries= rather than query
the database.
1. Live filter searches the database.
2. Keywords are separated by "Spaces" (AND operation, mainly used to narrow down
the results, the more spaces you insert, the fewer results.)
3. Each keyword supports REGEX.
Expand Down
8 changes: 1 addition & 7 deletions calibredb-consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
(require 'calibredb-search)
(require 'calibredb-utils)

(eval-when-compile (defvar calibredb-search-entries))
(eval-when-compile (defvar calibredb-full-entries))

(defcustom calibredb-consult-ripgrep-all-args
"rga --null --line-buffered --color=never --max-columns=1000 --path-separator /\ --smart-case --no-heading --with-filename --line-number --rga-adapters=pandoc"
Expand All @@ -44,11 +42,7 @@ Can be either a string, or a list of strings or expressions."
"consult read for calibredb."
(interactive "P")
(if (fboundp 'consult--read)
(let ((candidates (if calibredb-search-entries
calibredb-search-entries
(progn
(setq calibredb-search-entries (calibredb-candidates))
(setq calibredb-full-entries calibredb-search-entries)))))
(let ((candidates (calibredb-candidates)))
(if candidates
(calibredb-find-file (consult--read candidates
:prompt "Pick a book: "
Expand Down
87 changes: 47 additions & 40 deletions calibredb-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
(require 'icons-in-terminal))

(eval-when-compile (defvar calibredb-detailed-view))
(eval-when-compile (defvar calibredb-full-entries))
(declare-function calibredb-condense-comments "calibredb-search.el")
(declare-function calibredb-attach-icon-for "calibredb-utils.el")
(declare-function calibredb-get-file-path "calibredb-utils.el")
Expand Down Expand Up @@ -643,49 +642,57 @@ Argument CALIBRE-ITEM-LIST is the calibred item list."
(setq display-alist
(cons (list (calibredb-format-item item) item) display-alist)))))

(defun calibredb-candidates ()
(defun calibredb-candidates (&optional sql count)
"Generate ebooks candidates alist."
(let* ((query-result (calibredb-query (concat calibredb-query-string
(pcase calibredb-sort-by
('id " ORDER BY id")
('title " ORDER BY title")
('author " ORDER BY author_sort")
('format " ORDER BY format")
('date " ORDER BY last_modified")
('pubdate " ORDER BY pubdate")
('tag " ORDER BY tag")
('size " ORDER BY uncompressed_size")
('language " ORDER BY lang_code")
(_ " ORDER BY id"))
(when (eq calibredb-order 'desc)
" DESC"))))
(let* ((sql (format (if count
"SELECT COUNT(id) FROM (SELECT * FROM (%s) %s)"
"SELECT * FROM (%s) %s")
(concat calibredb-query-string
(pcase calibredb-sort-by
('id " ORDER BY id")
('title " ORDER BY title")
('author " ORDER BY author_sort")
('format " ORDER BY format")
('date " ORDER BY last_modified")
('pubdate " ORDER BY pubdate")
('tag " ORDER BY tag")
('size " ORDER BY uncompressed_size")
('language " ORDER BY lang_code")
(_ " ORDER BY id"))
(when (eq calibredb-order 'desc)
" DESC"))
(if sql (concat " WHERE " sql) "")))
(query-result (calibredb-query sql))
(line-list (if (and (functionp 'sqlite-available-p) (sqlite-available-p))
query-result
(split-string (calibredb-chomp query-result) calibredb-sql-newline) )))
(cond ((equal "" query-result) '(""))
((equal nil query-result) '(""))
(t (let (res-list h-list f-list a-list)
(dolist (line line-list)
(if (and (functionp 'sqlite-available-p) (sqlite-available-p))
(push (calibredb-query-to-alist line) res-list)
;; validate if it is right format
(if (string-match-p (concat "^[0-9]\\{1,10\\}" calibredb-sql-separator) line)
;; decode and push to res-list
(push (calibredb-query-to-alist line) res-list))))
;; filter archive/highlight/favorite items
(dolist (item res-list)
(cond ((string-match-p "archive" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq a-list (cons item a-list)))
((string-match-p "favorite" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq f-list (cons item f-list)))
((string-match-p "highlight" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq h-list (cons item h-list)))))
;; merge archive/highlight/favorite/rest items
(setq res-list (nconc a-list res-list h-list f-list))
(calibredb-getbooklist res-list))))))

(if count
(caar query-result)
(cond ((equal "" query-result) '(""))
((equal nil query-result) '(""))
(t (let (res-list h-list f-list a-list)
(dolist (line line-list)
(if (and (functionp 'sqlite-available-p) (sqlite-available-p))
(push (calibredb-query-to-alist line) res-list)
;; validate if it is right format
(if (string-match-p (concat "^[0-9]\\{1,10\\}" calibredb-sql-separator) line)
;; decode and push to res-list
(push (calibredb-query-to-alist line) res-list))))
;; filter archive/highlight/favorite items
(dolist (item res-list)
(cond ((string-match-p "archive" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq a-list (cons item a-list)))
((string-match-p "favorite" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq f-list (cons item f-list)))
((string-match-p "highlight" (calibredb-getattr (list item) :tag))
(setq res-list (remove item res-list))
(setq h-list (cons item h-list)))))
;; merge archive/highlight/favorite/rest items
(setq res-list (nconc a-list res-list h-list f-list))
(calibredb-getbooklist res-list)))) )))

(defun calibredb-candidate(id)
"Generate one ebook candidate alist.
Expand Down
5 changes: 1 addition & 4 deletions calibredb-dired.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

(require 'calibredb-core)

(eval-when-compile (defvar calibredb-search-entries))
(eval-when-compile (defvar calibredb-full-entries))
(declare-function calibredb-search-clear-filter "calibredb-search.el")

(define-obsolete-function-alias #'calibredb-open-dired
Expand Down Expand Up @@ -76,8 +74,7 @@ library."
(format "--library-path %s" (calibredb-root-dir-quote))))
(lambda (p e)
(when (= 0 (process-exit-status p))
(setq calibredb-search-entries (calibredb-candidates))
(setq calibredb-full-entries calibredb-search-entries)
(calibredb-candidates)
(calibredb-search-clear-filter)
(with-current-buffer buffer
(dired-do-delete)))))))
Expand Down
8 changes: 1 addition & 7 deletions calibredb-helm.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

(require 'calibredb-core)

(eval-when-compile (defvar calibredb-search-entries))
(eval-when-compile (defvar calibredb-full-entries))

(declare-function calibredb-set-metadata--tags "calibredb-utils.el")
(declare-function calibredb-set-metadata--comments "calibredb-utils.el")
Expand Down Expand Up @@ -83,11 +81,7 @@
:header-name (lambda (name)
(concat name " in [" calibredb-root-dir "]"))
:candidates (lambda ()
(if calibredb-search-entries
calibredb-search-entries
(progn
(setq calibredb-search-entries (calibredb-candidates))
(setq calibredb-full-entries calibredb-search-entries))))
(calibredb-candidates))
;; :filtered-candidate-transformer 'helm-findutils-transformer
;; :action-transformer 'helm-transform-file-load-el
:persistent-action 'calibredb-view--helm
Expand Down
8 changes: 1 addition & 7 deletions calibredb-ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
(require 'calibredb-faces)
(require 'calibredb-utils)

(eval-when-compile (defvar calibredb-search-entries))
(eval-when-compile (defvar calibredb-full-entries))
(eval-when-compile (defvar counsel-ag-base-command))
(declare-function counsel-ag "counsel")

Expand Down Expand Up @@ -106,11 +104,7 @@ If prefix ARG is non-nil, keep the files after adding without prompt."
(defun calibredb-ivy-read ()
"Ivy read for calibredb."
(if (fboundp 'ivy-read)
(let ((cand (if calibredb-search-entries
calibredb-search-entries
(progn
(setq calibredb-search-entries (calibredb-candidates))
(setq calibredb-full-entries calibredb-search-entries)))))
(let ((cand (calibredb-candidates)))
(if cand
(ivy-read "Pick a book: "
cand
Expand Down
3 changes: 1 addition & 2 deletions calibredb-opds.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ Optional argument PASSWORD."
(let* ((dom (with-temp-buffer
(insert data)
(libxml-parse-xml-region (point-min) (point-max)))))
(setq calibredb-search-entries (calibredb-opds-dom dom))
(setq calibredb-full-entries calibredb-search-entries)
(calibredb-opds-dom dom)
(calibredb)
(setq calibredb-tag-filter-p nil)
(setq calibredb-favorite-filter-p nil)
Expand Down
6 changes: 1 addition & 5 deletions calibredb-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
The optional PREFIX argument is ignored.
Please notice: `calibredb-id-width' must >= the real id lenth."
(ignore prefix)
(let* ((candidates (if calibredb-search-entries
calibredb-search-entries
(progn
(setq calibredb-search-entries (calibredb-candidates))
(setq calibredb-full-entries calibredb-search-entries)))))
(let* ((candidates (calibredb-candidates)))
(if (fboundp 'consult--read)
(if candidates
(let* ((cand (consult--read candidates
Expand Down
Loading

0 comments on commit 7787299

Please sign in to comment.