2022-04-11 10:22:38 +08:00
|
|
|
#include "file-index-manager.h"
|
2022-04-14 11:16:26 +08:00
|
|
|
#include "dir-watcher.h"
|
|
|
|
#include "common.h"
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2022-04-11 10:22:38 +08:00
|
|
|
static FileIndexManager* global_instance = nullptr;
|
|
|
|
FileIndexManager::FileIndexManager(QObject *parent) : QObject(parent), m_semaphore(INDEX_SEM, 1, QSystemSemaphore::AccessMode::Create)
|
2021-06-10 20:43:57 +08:00
|
|
|
{
|
2022-03-15 13:53:38 +08:00
|
|
|
m_fi = FirstIndex::getInstance();
|
2022-03-04 15:15:07 +08:00
|
|
|
m_iw = InotifyWatch::getInstance();
|
2021-06-10 20:43:57 +08:00
|
|
|
}
|
|
|
|
|
2022-04-11 10:22:38 +08:00
|
|
|
FileIndexManager *FileIndexManager::getInstance()
|
2021-11-22 16:03:31 +08:00
|
|
|
{
|
|
|
|
if(!global_instance) {
|
2022-04-11 10:22:38 +08:00
|
|
|
global_instance = new FileIndexManager();
|
2022-03-15 13:53:38 +08:00
|
|
|
}
|
|
|
|
return global_instance;
|
2021-11-22 16:03:31 +08:00
|
|
|
}
|
|
|
|
|
2022-04-11 10:22:38 +08:00
|
|
|
void FileIndexManager::searchMethod(FileUtils::SearchMethod sm) {
|
2021-04-20 16:24:07 +08:00
|
|
|
qWarning() << "searchMethod start: " << static_cast<int>(sm);
|
2021-04-26 15:06:47 +08:00
|
|
|
if(FileUtils::SearchMethod::INDEXSEARCH == sm || FileUtils::SearchMethod::DIRECTSEARCH == sm) {
|
2021-04-20 16:24:07 +08:00
|
|
|
FileUtils::searchMethod = sm;
|
|
|
|
} else {
|
|
|
|
qWarning("enum class error!!!\n");
|
|
|
|
}
|
2021-11-09 10:07:41 +08:00
|
|
|
if(FileUtils::SearchMethod::INDEXSEARCH == sm && 0 == FileUtils::indexStatus) {
|
2022-03-17 15:40:55 +08:00
|
|
|
qDebug() << "start first index";
|
2022-05-11 18:05:42 +08:00
|
|
|
m_fi->rebuildDatebase();
|
2022-03-17 15:40:55 +08:00
|
|
|
qDebug() << "start inotify index";
|
2021-06-10 20:43:57 +08:00
|
|
|
if(!this->m_iw->isRunning()) {
|
|
|
|
this->m_iw->start();
|
2021-04-20 16:24:07 +08:00
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "Search method has been set to INDEXSEARCH";
|
2021-04-20 16:24:07 +08:00
|
|
|
}
|
2021-06-10 20:43:57 +08:00
|
|
|
if(FileUtils::SearchMethod::DIRECTSEARCH == sm) {
|
|
|
|
m_iw->stopWatch();
|
|
|
|
}
|
2021-04-20 16:24:07 +08:00
|
|
|
qWarning() << "searchMethod end: " << static_cast<int>(FileUtils::searchMethod);
|
|
|
|
}
|
2022-04-14 11:16:26 +08:00
|
|
|
|
|
|
|
void FileIndexManager::initIndexPathSetFunction()
|
|
|
|
{
|
|
|
|
const QByteArray id(UKUI_SEARCH_SCHEMAS);
|
|
|
|
if(QGSettings::isSchemaInstalled(id)) {
|
|
|
|
m_searchSettings = new QGSettings(id);
|
|
|
|
if(!m_searchSettings->keys().contains(SEARCH_METHOD_KEY)) {
|
|
|
|
qWarning() << "Can not find gsettings key:" << UKUI_SEARCH_SCHEMAS << SEARCH_METHOD_KEY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qWarning() << "Can not find gsettings:" << UKUI_SEARCH_SCHEMAS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-02 09:23:53 +08:00
|
|
|
connect(DirWatcher::getDirWatcher(), &DirWatcher::appendIndexItem, this, &FileIndexManager::handleIndexPathAppend, Qt::QueuedConnection);
|
|
|
|
connect(DirWatcher::getDirWatcher(), &DirWatcher::removeIndexItem, this, &FileIndexManager::handleRemovePathAppend, Qt::QueuedConnection);
|
2022-04-25 10:23:20 +08:00
|
|
|
|
2022-04-14 11:16:26 +08:00
|
|
|
|
|
|
|
DirWatcher::getDirWatcher()->initDbusService();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileIndexManager::handleIndexPathAppend(const QString path, const QStringList blockList)
|
|
|
|
{
|
2022-06-02 09:23:53 +08:00
|
|
|
qDebug() << "Add Index path:" << path << " blockList:" << blockList;
|
2022-04-14 11:16:26 +08:00
|
|
|
if(!m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) {
|
|
|
|
m_searchSettings->set(SEARCH_METHOD_KEY, true);
|
|
|
|
} else {
|
|
|
|
m_fi->addIndexPath(path, blockList);
|
|
|
|
m_iw->addIndexPath(path, blockList);
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 09:23:53 +08:00
|
|
|
|
|
|
|
void FileIndexManager::handleRemovePathAppend(const QString path)
|
|
|
|
{
|
|
|
|
qDebug() << "Remove index path:" << path;
|
|
|
|
if(m_searchSettings->get(SEARCH_METHOD_KEY).toBool()) {
|
|
|
|
m_iw->removeIndexPath(path, true);
|
|
|
|
} else {
|
|
|
|
m_iw->removeIndexPath(path, false);
|
|
|
|
}
|
|
|
|
}
|