File indexing completed on 2025-01-05 04:24:22
0001 #ifndef DBACTIONS_H 0002 #define DBACTIONS_H 0003 0004 #include <QObject> 0005 #include <QThread> 0006 #include <QDebug> 0007 #include <QCoreApplication> 0008 0009 #include "db/db.h" 0010 0011 struct UrlData 0012 { 0013 QUrl url; 0014 QString title; 0015 0016 QVariantMap toMap() const 0017 { 0018 return {{"url", url.toString()}, {"title", title}}; 0019 } 0020 0021 FMH::MODEL toModel() const 0022 { 0023 return {{FMH::MODEL_KEY::URL, url.toString()}, {FMH::MODEL_KEY::TITLE, title}}; 0024 } 0025 }; 0026 0027 class DBActions : public DB 0028 { 0029 Q_OBJECT 0030 public: 0031 static DBActions *getInstance() 0032 { 0033 qWarning() << "GETTIG TAGGING INSTANCE" << QThread::currentThread() << qApp->thread(); 0034 0035 if (QThread::currentThread() != qApp->thread()) { 0036 qWarning() << "Can not get Tagging instance from a thread different than the mian one " << QThread::currentThread() << qApp->thread(); 0037 return nullptr; 0038 } 0039 0040 if (m_instance) 0041 return m_instance; 0042 0043 m_instance = new DBActions; 0044 return m_instance; 0045 } 0046 0047 void addToHistory(const UrlData &data); 0048 void addBookmark(const UrlData &data); 0049 0050 void urlIcon(const QUrl &url, const QString &icon); 0051 0052 FMH::MODEL_LIST getHistory() const; 0053 FMH::MODEL_LIST getBookmarks() const; 0054 0055 bool isBookmark(const QUrl &url); 0056 0057 private: 0058 static DBActions *m_instance; 0059 0060 explicit DBActions(QObject *parent = nullptr); 0061 DBActions(const DBActions &) = delete; 0062 DBActions &operator=(const DBActions &) = delete; 0063 DBActions(DBActions &&) = delete; 0064 DBActions &operator=(DBActions &&) = delete; 0065 0066 const QVariantList get(const QString &query, std::function<bool(QVariantMap &item)> modifier = nullptr) const; 0067 0068 signals: 0069 void historyUrlInserted(UrlData data); 0070 void bookmarkInserted(UrlData data); 0071 void iconInserted(QUrl url, QString icon); 0072 0073 }; 0074 0075 #endif // DBACTIONS_H