[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/calibre 6ddfd7048d 14/76: Add ability to have multiple
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/calibre 6ddfd7048d 14/76: Add ability to have multiple libraries |
|
Date: |
Thu, 18 May 2023 09:57:41 -0400 (EDT) |
branch: externals/calibre
commit 6ddfd7048ddc3e559b030acbc2569bfa86553387
Author: Kjartan Óli Ágústsson <kjartanoli@disroot.org>
Commit: Kjartan Óli Ágústsson <kjartanoli@disroot.org>
Add ability to have multiple libraries
* calibre-book.el (calibre-book--file): Use the location of the
current library.
* calibre-db.el (calibre--db): Set calibre--db to nil, and issue a
warning if the appropriate database file does not exist.
(calibre-db--get-books): Return nil if calibre--db returns nil,
instead of attempting to query an invalid database.
* calibre-library.el (calibre-library--execute): Use the location of
the current library
* calibre.el (calibre-library-dir): Deleted
(calibre-libraries): Created
(calibre--library-names): Created
(calibre--library): Created
(calibre-select-library): Created
---
calibre-book.el | 2 +-
calibre-db.el | 21 ++++++++++++++-------
calibre-library.el | 2 +-
calibre.el | 36 ++++++++++++++++++++++++++++++------
4 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/calibre-book.el b/calibre-book.el
index 8d01a5722f..9ac46483f0 100644
--- a/calibre-book.el
+++ b/calibre-book.el
@@ -130,7 +130,7 @@ BOOK is a `calibre-book'."
"Return the path to BOOK in FORMAT."
(with-slots (path file-name) book
(message "%S" file-name)
- (file-name-concat calibre-library-dir
+ (file-name-concat (calibre--library)
path
(message "%s.%s" file-name format))))
diff --git a/calibre-db.el b/calibre-db.el
index 0b41d0ee93..10a00213da 100644
--- a/calibre-db.el
+++ b/calibre-db.el
@@ -28,19 +28,26 @@
(defun calibre--db ()
"Return the metadata database."
(unless calibre--db
- (setf calibre--db
- (sqlite-open
- (file-name-concat calibre-library-dir "metadata.db"))))
+ (let ((file-name (file-name-concat (calibre--library) "metadata.db")))
+ (if (not (file-exists-p file-name))
+ (progn
+ (display-warning 'calibre (format "Metedata database %s does not
exist. Add some books to the library to create it." file-name))
+ (setf calibre--db nil))
+ (setf calibre--db
+ (sqlite-open
+ file-name)))))
calibre--db)
(defun calibre-db--get-books ()
"Return all books in the Calibre library `calibre-library-dir'."
- (mapcar #'calibre-make-book
- (sqlite-select (calibre--db)
- "SELECT books.id, title, series.name, series_index,
timestamp, pubdate, last_modified, path
+ (if (not (calibre--db))
+ nil
+ (mapcar #'calibre-make-book
+ (sqlite-select (calibre--db)
+ "SELECT books.id, title, series.name, series_index,
timestamp, pubdate, last_modified, path
FROM books
LEFT JOIN books_series_link sl ON books.id = sl.book
-LEFT JOIN series ON sl.series = series.id;")))
+LEFT JOIN series ON sl.series = series.id;"))))
(defun calibre-db--get-book-authors (id)
"Return a list of authors for the book identified by ID."
diff --git a/calibre-library.el b/calibre-library.el
index 06db37960b..2c2979880a 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -75,7 +75,7 @@ ARGS should be a list of strings. SENTINEL is a process
sentinel to install."
(error "Could not find calibredb")
(make-process
:name "calibre"
- :command `("calibredb" "--with-library" ,calibre-library-dir ,@args)
+ :command `("calibredb" "--with-library" ,(calibre--library) ,@args)
:sentinel sentinel)))
(defun calibre-library-mark-remove (&optional _num)
diff --git a/calibre.el b/calibre.el
index 6b1b43decc..b1f5b1549a 100644
--- a/calibre.el
+++ b/calibre.el
@@ -64,14 +64,38 @@ column should have."
(integer :tag "Width")))
:package-version '("calibre" . "0.1.0"))
-(defcustom calibre-library-dir "~/Documents/Calibre"
- "The root directory of the Calibre library."
- :type 'directory
- :set (lambda (symbol value)
- (set-default symbol value)
- (setf calibre--db nil))
+(defcustom calibre-libraries nil
+ "An alist mapping library names to directories."
+ :type '(repeat :tag "Libraries" (cons :tag "Library"
+ (string :tag "Name")
+ (directory :tag "Location")))
:package-version '("calibre" . "0.1.0"))
+(defun calibre--library-names ()
+ "Return a list of the names of defined libraries."
+ (mapcar #'car calibre-libraries))
+
+(defvar calibre--library nil
+ "The active library.")
+
+(defun calibre-select-library (&optional library)
+ "Prompt the user to select a library from `calibre-libraries'.
+If LIBRARY is non-nil, select that instead."
+ (interactive)
+ (setf calibre--library (if library
+ library
+ (completing-read "Library: "
(calibre--library-names) nil t))
+ calibre--db nil
+ calibre--books nil)
+ (calibre-library--refresh t))
+
+(defun calibre--library ()
+ "Return the active library.
+If no library is active, prompt the user to select one."
+ (unless calibre--library
+ (calibre-select-library))
+ (alist-get calibre--library calibre-libraries nil nil #'string=))
+
(defcustom calibre-format-preferences '(pdf epub)
"The preference order of file formats."
:type '(repeat symbol :tag "Format")
- [elpa] branch externals/calibre created (now e283a2c928), ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 8f1eab2811 06/76: Allow customisation of the calibredb executable path, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 845bcecde6 13/76: Refresh in memory book list after DB opperations, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 6ddfd7048d 14/76: Add ability to have multiple libraries,
ELPA Syncer <=
- [elpa] externals/calibre b0f8f76723 16/76: Remove references to unimplemented functions, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 06148ea20a 01/76: Initial commit, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre f3a3119322 22/76: Fix calibre customisation group, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 77c8cf66b7 24/76: Remove duplicate defcustom declaration, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 20e5bc41f1 25/76: Fix default value of calibre-calibredb-executable, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre e5d853eb32 34/76: Use the -r flag when adding books, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre aa28fa3ede 37/76: Use let instead of let*, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 6a7a2344c1 41/76: Initialise tabulated list header, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre 5d49526414 42/76: Add support for search and virtual libraries, ELPA Syncer, 2023/05/18
- [elpa] externals/calibre afe5581b7d 43/76: Only prompt to select library if more than one is defined, ELPA Syncer, 2023/05/18