2023-05-18 18:59:10 -04:00
|
|
|
#include "localdocs.h"
|
2023-06-28 20:42:40 -04:00
|
|
|
#include "mysettings.h"
|
2023-05-18 18:59:10 -04:00
|
|
|
|
|
|
|
class MyLocalDocs: public LocalDocs { };
|
|
|
|
Q_GLOBAL_STATIC(MyLocalDocs, localDocsInstance)
|
|
|
|
LocalDocs *LocalDocs::globalInstance()
|
|
|
|
{
|
|
|
|
return localDocsInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalDocs::LocalDocs()
|
|
|
|
: QObject(nullptr)
|
2023-05-22 22:13:42 -04:00
|
|
|
, m_localDocsModel(new LocalDocsModel(this))
|
2023-05-23 20:26:31 -04:00
|
|
|
, m_database(nullptr)
|
2023-05-18 18:59:10 -04:00
|
|
|
{
|
2023-06-28 20:42:40 -04:00
|
|
|
connect(MySettings::globalInstance(), &MySettings::localDocsChunkSizeChanged, this, &LocalDocs::handleChunkSizeChanged);
|
2023-05-23 20:26:31 -04:00
|
|
|
|
|
|
|
// Create the DB with the chunk size from settings
|
2023-06-28 20:42:40 -04:00
|
|
|
m_database = new Database(MySettings::globalInstance()->localDocsChunkSize());
|
2023-05-23 20:26:31 -04:00
|
|
|
|
2023-05-18 18:59:10 -04:00
|
|
|
connect(this, &LocalDocs::requestAddFolder, m_database,
|
|
|
|
&Database::addFolder, Qt::QueuedConnection);
|
|
|
|
connect(this, &LocalDocs::requestRemoveFolder, m_database,
|
|
|
|
&Database::removeFolder, Qt::QueuedConnection);
|
2023-05-23 20:26:31 -04:00
|
|
|
connect(this, &LocalDocs::requestChunkSizeChange, m_database,
|
|
|
|
&Database::changeChunkSize, Qt::QueuedConnection);
|
2023-10-24 12:13:32 -04:00
|
|
|
|
|
|
|
// Connections for modifying the model and keeping it updated with the database
|
|
|
|
connect(m_database, &Database::updateInstalled,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateInstalled, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::updateIndexing,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateIndexing, Qt::QueuedConnection);
|
2024-01-22 12:36:01 -05:00
|
|
|
connect(m_database, &Database::updateError,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateError, Qt::QueuedConnection);
|
2023-10-24 12:13:32 -04:00
|
|
|
connect(m_database, &Database::updateCurrentDocsToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateCurrentDocsToIndex, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::updateTotalDocsToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateTotalDocsToIndex, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::subtractCurrentBytesToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::subtractCurrentBytesToIndex, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::updateCurrentBytesToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateCurrentBytesToIndex, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::updateTotalBytesToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateTotalBytesToIndex, Qt::QueuedConnection);
|
2024-01-22 12:36:01 -05:00
|
|
|
connect(m_database, &Database::updateCurrentEmbeddingsToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateCurrentEmbeddingsToIndex, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::updateTotalEmbeddingsToIndex,
|
|
|
|
m_localDocsModel, &LocalDocsModel::updateTotalEmbeddingsToIndex, Qt::QueuedConnection);
|
2023-10-24 12:13:32 -04:00
|
|
|
connect(m_database, &Database::addCollectionItem,
|
|
|
|
m_localDocsModel, &LocalDocsModel::addCollectionItem, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::removeFolderById,
|
|
|
|
m_localDocsModel, &LocalDocsModel::removeFolderById, Qt::QueuedConnection);
|
|
|
|
connect(m_database, &Database::removeCollectionItem,
|
|
|
|
m_localDocsModel, &LocalDocsModel::removeCollectionItem, Qt::QueuedConnection);
|
2023-05-22 22:13:42 -04:00
|
|
|
connect(m_database, &Database::collectionListUpdated,
|
2023-10-24 12:13:32 -04:00
|
|
|
m_localDocsModel, &LocalDocsModel::collectionListUpdated, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
connect(qApp, &QCoreApplication::aboutToQuit, this, &LocalDocs::aboutToQuit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::aboutToQuit()
|
|
|
|
{
|
|
|
|
delete m_database;
|
|
|
|
m_database = nullptr;
|
2023-05-18 18:59:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::addFolder(const QString &collection, const QString &path)
|
|
|
|
{
|
2023-05-22 22:13:42 -04:00
|
|
|
const QUrl url(path);
|
2023-06-03 10:08:59 -04:00
|
|
|
const QString localPath = url.isLocalFile() ? url.toLocalFile() : path;
|
|
|
|
emit requestAddFolder(collection, localPath);
|
2023-05-18 18:59:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::removeFolder(const QString &collection, const QString &path)
|
|
|
|
{
|
2023-10-24 12:13:32 -04:00
|
|
|
m_localDocsModel->removeCollectionPath(collection, path);
|
2023-05-18 18:59:10 -04:00
|
|
|
emit requestRemoveFolder(collection, path);
|
|
|
|
}
|
|
|
|
|
2023-06-28 20:42:40 -04:00
|
|
|
void LocalDocs::handleChunkSizeChanged()
|
2023-05-23 20:26:31 -04:00
|
|
|
{
|
2023-06-28 20:42:40 -04:00
|
|
|
emit requestChunkSizeChange(MySettings::globalInstance()->localDocsChunkSize());
|
2023-05-18 18:59:10 -04:00
|
|
|
}
|