2023-05-18 22:59:10 +00:00
|
|
|
#include "localdocs.h"
|
|
|
|
|
|
|
|
class MyLocalDocs: public LocalDocs { };
|
|
|
|
Q_GLOBAL_STATIC(MyLocalDocs, localDocsInstance)
|
|
|
|
LocalDocs *LocalDocs::globalInstance()
|
|
|
|
{
|
|
|
|
return localDocsInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalDocs::LocalDocs()
|
|
|
|
: QObject(nullptr)
|
2023-05-23 02:13:42 +00:00
|
|
|
, m_localDocsModel(new LocalDocsModel(this))
|
2023-05-24 00:26:31 +00:00
|
|
|
, m_database(nullptr)
|
2023-05-18 22:59:10 +00:00
|
|
|
{
|
2023-05-24 00:26:31 +00:00
|
|
|
QSettings settings;
|
|
|
|
settings.sync();
|
|
|
|
m_chunkSize = settings.value("localdocs/chunkSize", 256).toInt();
|
|
|
|
m_retrievalSize = settings.value("localdocs/retrievalSize", 3).toInt();
|
|
|
|
|
|
|
|
// Create the DB with the chunk size from settings
|
|
|
|
m_database = new Database(m_chunkSize);
|
|
|
|
|
2023-05-18 22:59:10 +00:00
|
|
|
connect(this, &LocalDocs::requestAddFolder, m_database,
|
|
|
|
&Database::addFolder, Qt::QueuedConnection);
|
|
|
|
connect(this, &LocalDocs::requestRemoveFolder, m_database,
|
|
|
|
&Database::removeFolder, Qt::QueuedConnection);
|
|
|
|
connect(this, &LocalDocs::requestRetrieveFromDB, m_database,
|
|
|
|
&Database::retrieveFromDB, Qt::QueuedConnection);
|
2023-05-24 00:26:31 +00:00
|
|
|
connect(this, &LocalDocs::requestChunkSizeChange, m_database,
|
|
|
|
&Database::changeChunkSize, Qt::QueuedConnection);
|
2023-05-18 22:59:10 +00:00
|
|
|
connect(m_database, &Database::retrieveResult, this,
|
2023-05-24 18:49:43 +00:00
|
|
|
&LocalDocs::receivedResult, Qt::QueuedConnection);
|
2023-05-23 02:13:42 +00:00
|
|
|
connect(m_database, &Database::collectionListUpdated,
|
|
|
|
m_localDocsModel, &LocalDocsModel::handleCollectionListUpdated, Qt::QueuedConnection);
|
2023-05-18 22:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::addFolder(const QString &collection, const QString &path)
|
|
|
|
{
|
2023-05-23 02:13:42 +00:00
|
|
|
const QUrl url(path);
|
|
|
|
if (url.isLocalFile()) {
|
|
|
|
emit requestAddFolder(collection, url.toLocalFile());
|
|
|
|
} else {
|
|
|
|
emit requestAddFolder(collection, path);
|
|
|
|
}
|
2023-05-18 22:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::removeFolder(const QString &collection, const QString &path)
|
|
|
|
{
|
|
|
|
emit requestRemoveFolder(collection, path);
|
|
|
|
}
|
|
|
|
|
2023-05-24 18:49:43 +00:00
|
|
|
void LocalDocs::requestRetrieve(const QString &uid, const QList<QString> &collections, const QString &text)
|
2023-05-18 22:59:10 +00:00
|
|
|
{
|
2023-05-24 18:49:43 +00:00
|
|
|
emit requestRetrieveFromDB(uid, collections, text, m_retrievalSize);
|
2023-05-24 00:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int LocalDocs::chunkSize() const
|
|
|
|
{
|
|
|
|
return m_chunkSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::setChunkSize(int chunkSize)
|
|
|
|
{
|
|
|
|
if (m_chunkSize == chunkSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_chunkSize = chunkSize;
|
|
|
|
emit chunkSizeChanged();
|
|
|
|
emit requestChunkSizeChange(chunkSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
int LocalDocs::retrievalSize() const
|
|
|
|
{
|
|
|
|
return m_retrievalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::setRetrievalSize(int retrievalSize)
|
|
|
|
{
|
|
|
|
if (m_retrievalSize == retrievalSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_retrievalSize = retrievalSize;
|
|
|
|
emit retrievalSizeChanged();
|
2023-05-18 22:59:10 +00:00
|
|
|
}
|