File indexing completed on 2024-05-12 12:03:50
0001 // SPDX-FileCopyrightText: 2017 Dan Leinir Turthra Jensen <admin@leinir.dk> 0002 // SPDX-License-Identifier: LGPL-2.1-only or LGPL-3.0-only or LicenseRef-KDE-Accepted-LGPL 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <memory> 0008 #include <optional> 0009 0010 struct BookEntry; 0011 /** 0012 * \brief A Class to hold a cache of known books to reduce the amount of time spent indexing. 0013 * 0014 * BookDatabase handles holding the conversion between SQL entry and 0015 * BookEntry structs. 0016 * 0017 * The BookEntry struct is defined in CategoryEntriesModel. 0018 */ 0019 class BookDatabase : public QObject 0020 { 0021 Q_OBJECT 0022 public: 0023 static BookDatabase &self() 0024 { 0025 static BookDatabase instance; 0026 return instance; 0027 } 0028 0029 /// @return a list of all known books in the database. 0030 QList<BookEntry> loadEntries(); 0031 0032 /// @return an entry matching the file name if it exists. 0033 std::optional<BookEntry> loadEntry(const QString &fileName); 0034 0035 /// \brief Add a new book to the cache. 0036 /// \param entry The entry to add. 0037 void addEntry(const BookEntry &entry); 0038 0039 /// \brief remove an entry by filename from the cache. 0040 /// \param entry the entry to remove. 0041 void removeEntry(const BookEntry &entry); 0042 0043 /// \brief updateEntry update an entry by filename. 0044 /// \param fileName the filename of the entry to update. 0045 /// \param property the property/fieldname you wish to update. 0046 /// \param value a QVariant with the value. 0047 void updateEntry(const QString &fileName, const QString &property, const QVariant &value); 0048 0049 private: 0050 explicit BookDatabase(QObject *parent = nullptr); 0051 ~BookDatabase() override; 0052 0053 class Private; 0054 std::unique_ptr<Private> d; 0055 };