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-18 22:59:10 +00:00
|
|
|
, m_database(new Database)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
connect(m_database, &Database::retrieveResult, this,
|
2023-05-21 19:13:28 +00:00
|
|
|
&LocalDocs::handleRetrieveResult, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalDocs::requestRetrieve(const QList<QString> &collections, const QString &text)
|
|
|
|
{
|
|
|
|
m_retrieveResult = QList<QString>();
|
|
|
|
emit requestRetrieveFromDB(collections, text);
|
|
|
|
}
|
|
|
|
|
2023-05-21 19:13:28 +00:00
|
|
|
void LocalDocs::handleRetrieveResult(const QList<QString> &result)
|
2023-05-18 22:59:10 +00:00
|
|
|
{
|
|
|
|
m_retrieveResult = result;
|
|
|
|
emit receivedResult();
|
|
|
|
}
|