File indexing completed on 2024-05-12 16:23:41
0001 // SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im> 0002 // SPDX-FileCopyrightText: 2020 Rinigus <rinigus.git@gmail.com> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #ifndef DBMANAGER_H 0007 #define DBMANAGER_H 0008 0009 #include <QObject> 0010 #include <QString> 0011 #include <QSqlDatabase> 0012 0013 #include <ThreadedDatabase> 0014 0015 #include <QCoro/QCoroTask> 0016 0017 class QQmlEngine; 0018 0019 /** 0020 * @class DBManager 0021 * @short Class for database initialization and applying changes in its records 0022 */ 0023 class DBManager : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit DBManager(QObject *parent = nullptr); 0028 0029 Q_SIGNALS: 0030 // emitted with the name of the table that has been changed 0031 void databaseTableChanged(QString table); 0032 0033 public: 0034 QCoro::Task<> addBookmark(const QVariantMap bookmarkdata); 0035 QCoro::Task<> removeBookmark(const QString url); 0036 QCoro::Task<bool> isBookmarked(const QString url) const; 0037 0038 QCoro::Task<> addToHistory(const QVariantMap pagedata); 0039 QCoro::Task<> removeFromHistory(const QString url); 0040 QCoro::Task<> clearHistory(); 0041 0042 QCoro::Task<> updateIcon(QQmlEngine *engine, const QString url, const QString iconSource); 0043 QCoro::Task<> updateLastVisited(const QString url); 0044 0045 inline std::shared_ptr<ThreadedDatabase> database() { 0046 return m_database; 0047 } 0048 0049 private: 0050 // limit the size of history table 0051 QCoro::Task<> trimHistory(); 0052 // drop unused icons 0053 QCoro::Task<> trimIcons(); 0054 0055 // execute SQL statement 0056 QCoro::Task<> execute(const QString command); 0057 0058 // methods for manipulation of bookmarks or history tables 0059 QCoro::Task<> addRecord(const QString table, const QVariantMap pagedata); 0060 QCoro::Task<> removeRecord(const QString table, const QString url); 0061 QCoro::Task<> removeAllRecords(const QString table); 0062 QCoro::Task<> updateIconRecord(const QString table, const QString url, const QString iconSource); 0063 QCoro::Task<> setLastVisitedRecord(const QString table, const QString url); 0064 QCoro::Task<bool> hasRecord(const QString table, const QString url) const; 0065 0066 std::shared_ptr<ThreadedDatabase> m_database; 0067 }; 0068 0069 #endif // DBMANAGER_H