gpt4all/gpt4all-chat/localdocs.h

105 lines
2.9 KiB
C
Raw Normal View History

2023-05-18 22:59:10 +00:00
#ifndef LOCALDOCS_H
#define LOCALDOCS_H
#include <QObject>
#include <QtSql>
#include <QQueue>
#include <QFileInfo>
#include <QThread>
#include <QFileSystemWatcher>
struct DocumentInfo
{
int folder;
QFileInfo doc;
};
2023-05-21 19:13:28 +00:00
struct CollectionInfo {
Q_GADGET
Q_PROPERTY(QString name MEMBER name)
public:
QString name;
QList<QString> folders;
};
Q_DECLARE_METATYPE(CollectionInfo)
2023-05-18 22:59:10 +00:00
class Database : public QObject
{
Q_OBJECT
public:
Database();
public Q_SLOTS:
void scanQueue();
void scanDocuments(int folder_id, const QString &folder_path);
void addFolder(const QString &collection, const QString &path);
void removeFolder(const QString &collection, const QString &path);
void retrieveFromDB(const QList<QString> &collections, const QString &text);
void cleanDB();
2023-05-18 22:59:10 +00:00
Q_SIGNALS:
void docsToScanChanged();
void retrieveResult(const QList<QString> &result);
2023-05-21 19:13:28 +00:00
void collectionListUpdated(const QList<CollectionInfo> &collectionList);
2023-05-18 22:59:10 +00:00
private Q_SLOTS:
void start();
void directoryChanged(const QString &path);
bool addFolderToWatch(const QString &path);
bool removeFolderFromWatch(const QString &path);
2023-05-21 19:13:28 +00:00
void addCurrentFolders();
void updateCollectionList();
2023-05-18 22:59:10 +00:00
private:
void removeFolderInternal(const QString &collection, int folder_id, const QString &path);
2023-05-18 22:59:10 +00:00
void chunkStream(QTextStream &stream, int document_id);
void handleDocumentErrorAndScheduleNext(const QString &errorMessage,
int document_id, const QString &document_path, const QSqlError &error);
private:
QQueue<DocumentInfo> m_docsToScan;
QList<QString> m_retrieve;
QThread m_dbThread;
QFileSystemWatcher *m_watcher;
};
class LocalDocs : public QObject
{
Q_OBJECT
2023-05-21 19:13:28 +00:00
Q_PROPERTY(QList<CollectionInfo> collectionList READ collectionList NOTIFY collectionListChanged)
2023-05-18 22:59:10 +00:00
public:
static LocalDocs *globalInstance();
2023-05-21 19:13:28 +00:00
QList<CollectionInfo> collectionList() const { return m_collectionList; }
2023-05-18 22:59:10 +00:00
void addFolder(const QString &collection, const QString &path);
void removeFolder(const QString &collection, const QString &path);
QList<QString> result() const { return m_retrieveResult; }
void requestRetrieve(const QList<QString> &collections, const QString &text);
Q_SIGNALS:
void requestAddFolder(const QString &collection, const QString &path);
void requestRemoveFolder(const QString &collection, const QString &path);
void requestRetrieveFromDB(const QList<QString> &collections, const QString &text);
void receivedResult();
2023-05-21 19:13:28 +00:00
void collectionListChanged();
2023-05-18 22:59:10 +00:00
private Q_SLOTS:
2023-05-21 19:13:28 +00:00
void handleRetrieveResult(const QList<QString> &result);
void handleCollectionListUpdated(const QList<CollectionInfo> &collectionList);
2023-05-18 22:59:10 +00:00
private:
Database *m_database;
QList<QString> m_retrieveResult;
2023-05-21 19:13:28 +00:00
QList<CollectionInfo> m_collectionList;
2023-05-18 22:59:10 +00:00
private:
explicit LocalDocs();
~LocalDocs() {}
friend class MyLocalDocs;
};
#endif // LOCALDOCS_H