83 lines
2.9 KiB
C++
83 lines
2.9 KiB
C++
#include "file-index-manager.h"
|
|
#include "dir-watcher.h"
|
|
#include "common.h"
|
|
using namespace UkuiSearch;
|
|
static FileIndexManager* global_instance = nullptr;
|
|
FileIndexManager::FileIndexManager(QObject *parent) : QObject(parent), m_semaphore(INDEX_SEM, 1, QSystemSemaphore::AccessMode::Create)
|
|
{
|
|
m_fi = FirstIndex::getInstance();
|
|
m_iw = InotifyWatch::getInstance();
|
|
}
|
|
|
|
FileIndexManager *FileIndexManager::getInstance()
|
|
{
|
|
if(!global_instance) {
|
|
global_instance = new FileIndexManager();
|
|
}
|
|
return global_instance;
|
|
}
|
|
|
|
void FileIndexManager::searchMethod(FileUtils::SearchMethod sm) {
|
|
qWarning() << "searchMethod start: " << static_cast<int>(sm);
|
|
if(FileUtils::SearchMethod::INDEXSEARCH == sm || FileUtils::SearchMethod::DIRECTSEARCH == sm) {
|
|
FileUtils::searchMethod = sm;
|
|
} else {
|
|
qWarning("enum class error!!!\n");
|
|
}
|
|
if(FileUtils::SearchMethod::INDEXSEARCH == sm && 0 == FileUtils::indexStatus) {
|
|
qDebug() << "start first index";
|
|
m_fi->rebuildDatebase();
|
|
qDebug() << "start inotify index";
|
|
if(!this->m_iw->isRunning()) {
|
|
this->m_iw->start();
|
|
}
|
|
qDebug() << "Search method has been set to INDEXSEARCH";
|
|
}
|
|
if(FileUtils::SearchMethod::DIRECTSEARCH == sm) {
|
|
m_iw->stopWatch();
|
|
}
|
|
qWarning() << "searchMethod end: " << static_cast<int>(FileUtils::searchMethod);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
connect(DirWatcher::getDirWatcher(), &DirWatcher::appendIndexItem, this, &FileIndexManager::handleIndexPathAppend, Qt::QueuedConnection);
|
|
connect(DirWatcher::getDirWatcher(), &DirWatcher::removeIndexItem, this, &FileIndexManager::handleRemovePathAppend, Qt::QueuedConnection);
|
|
|
|
|
|
DirWatcher::getDirWatcher()->initDbusService();
|
|
}
|
|
|
|
void FileIndexManager::handleIndexPathAppend(const QString path, const QStringList blockList)
|
|
{
|
|
qDebug() << "Add Index path:" << path << " blockList:" << blockList;
|
|
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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|