ukui-search/libsearch/dirwatcher/dir-watcher.cpp

106 lines
3.0 KiB
C++
Raw Normal View History

2022-03-01 10:37:03 +08:00
#include "dir-watcher.h"
#include <QDebug>
#include <QThread>
static std::once_flag flag;
static DirWatcher *global_intance = nullptr;
DirWatcher::DirWatcher(QObject *parent) : QObject(parent)
{
m_dbusInterface = new QDBusInterface("com.ukui.search.fileindex.service",
"/org/ukui/search/privateDirWatcher",
"org.ukui.search.fileindex");
if (!m_dbusInterface->isValid()) {
qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError();
return;
}
2022-03-01 10:37:03 +08:00
}
DirWatcher *DirWatcher::getDirWatcher()
{
std::call_once(flag, [ & ] {
global_intance = new DirWatcher();
});
return global_intance;
}
2022-04-14 11:16:26 +08:00
void DirWatcher::initDbusService()
{
QDBusReply<void> reply = m_dbusInterface->call("initDbusService");
if (!reply.isValid()) {
qCritical() << "initDbusService call filed!";
2022-04-14 11:16:26 +08:00
}
2022-03-01 10:37:03 +08:00
}
QStringList DirWatcher::currentIndexableDir()
2022-03-01 10:37:03 +08:00
{
QDBusReply<QStringList> reply = m_dbusInterface->call("currentIndexableDir");
if (!reply.isValid()) {
qCritical() << "currentIndexableDir call filed!";
return QStringList();
}
return reply.value();
}
QStringList DirWatcher::currentBlackListOfIndex()
{
QDBusReply<QStringList> reply = m_dbusInterface->call("currentBlackListOfIndex");
if (!reply.isValid()) {
qCritical() << "currentBlackListOfIndex call filed!";
return QStringList();
}
return reply.value();
}
2022-03-01 10:37:03 +08:00
/**
* @brief DirWatcher::blackListOfDir
* @param dirPath
*/
QStringList DirWatcher::blackListOfDir(const QString &dirPath)
{
QDBusReply<QStringList> reply = m_dbusInterface->call("blackListOfDir", dirPath);
if (!reply.isValid()) {
qCritical() << "blackListOfDir call filed!";
return QStringList();
2022-03-01 10:37:03 +08:00
}
return reply.value();
}
QStringList DirWatcher::currentSearchableDir()
{
QDBusReply<QStringList> reply = m_dbusInterface->call("currentSearchableDir");
if (!reply.isValid()) {
qCritical() << "currentSearchableDir call filed!";
return QStringList();
}
return reply.value();
}
QStringList DirWatcher::searchableDirForSearchApplication()
{
QDBusReply<QStringList> reply = m_dbusInterface->call("searchableDirForSearchApplication");
if (!reply.isValid()) {
qCritical() << "searchableDirForSearchApplication call filed!";
return QStringList();
2022-03-01 10:37:03 +08:00
}
return reply.value();
2022-03-01 10:37:03 +08:00
}
void DirWatcher::appendIndexableListItem(const QString &path)
{
QDBusReply<void> reply = m_dbusInterface->call("appendIndexableListItem", path);
if (!reply.isValid()) {
qCritical() << "appendIndexableListItem call filed!";
}
}
void DirWatcher::removeIndexableListItem(const QString &path)
{
QDBusReply<void> reply = m_dbusInterface->call("removeIndexableListItem", path);
if (!reply.isValid()) {
qCritical() << "removeIndexableListItem call filed!";
2022-03-01 10:37:03 +08:00
}
}