2023-04-11 10:19:35 +08:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-03-01 10:37:03 +08:00
|
|
|
|
#include "dir-watcher.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QThread>
|
2022-10-11 16:10:10 +08:00
|
|
|
|
#include <QDir>
|
2022-03-01 10:37:03 +08:00
|
|
|
|
|
|
|
|
|
static std::once_flag flag;
|
|
|
|
|
static DirWatcher *global_intance = nullptr;
|
|
|
|
|
|
2022-10-11 16:10:10 +08:00
|
|
|
|
DirWatcher::DirWatcher(QObject *parent)
|
2023-01-13 15:09:15 +08:00
|
|
|
|
: QObject(parent)
|
2022-03-01 10:37:03 +08:00
|
|
|
|
{
|
2022-10-11 16:10:10 +08:00
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
|
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-05-31 10:48:13 +08:00
|
|
|
|
} else {
|
|
|
|
|
connect(m_dbusInterface, SIGNAL(appendIndexItem(QString, QStringList)), this, SLOT(sendAppendSignal(QString, QStringList)));
|
|
|
|
|
connect(m_dbusInterface, SIGNAL(removeIndexItem(QString)), this, SLOT(sendRemoveSignal(QString)));
|
2022-04-12 14:57:22 +08:00
|
|
|
|
}
|
2022-03-01 10:37:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 17:11:05 +08:00
|
|
|
|
DirWatcher::~DirWatcher()
|
|
|
|
|
{
|
|
|
|
|
if (m_dbusInterface)
|
|
|
|
|
delete m_dbusInterface;
|
|
|
|
|
m_dbusInterface = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QStringList DirWatcher::currentIndexableDir()
|
2022-03-01 10:37:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QDBusReply<QStringList> reply = m_dbusInterface->call("currentIndexableDir");
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "currentIndexableDir call filed!";
|
2022-10-11 16:10:10 +08:00
|
|
|
|
return QStringList() << QString(QDir::homePath());
|
2022-04-15 10:30:01 +08:00
|
|
|
|
}
|
2022-04-25 10:23:20 +08:00
|
|
|
|
return reply.value();
|
2022-04-12 14:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QStringList DirWatcher::currentBlackListOfIndex()
|
2022-04-12 14:57:22 +08:00
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QDBusReply<QStringList> reply = m_dbusInterface->call("currentBlackListOfIndex");
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "currentBlackListOfIndex call filed!";
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
return reply.value();
|
2022-04-12 14:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 10:37:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief DirWatcher::blackListOfDir 根据传入目录返回当前目录下的所有不可搜索目录,没有则返回空列表
|
|
|
|
|
* @param dirPath 要搜索的目录
|
|
|
|
|
*/
|
|
|
|
|
QStringList DirWatcher::blackListOfDir(const QString &dirPath)
|
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
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
|
|
|
|
}
|
2022-04-25 10:23:20 +08:00
|
|
|
|
return reply.value();
|
2022-04-08 11:15:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 09:19:50 +08:00
|
|
|
|
QStringList DirWatcher::getBlockDirsOfUser()
|
|
|
|
|
{
|
|
|
|
|
QDBusReply<QStringList> reply = m_dbusInterface->call("blockDirsForUser");
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "blockDirsForUser call filed!";
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
return reply.value();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 11:15:18 +08:00
|
|
|
|
QStringList DirWatcher::currentSearchableDir()
|
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QDBusReply<QStringList> reply = m_dbusInterface->call("currentSearchableDir");
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "currentSearchableDir call filed!";
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
return reply.value();
|
2022-04-08 11:15:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList DirWatcher::searchableDirForSearchApplication()
|
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QDBusReply<QStringList> reply = m_dbusInterface->call("searchableDirForSearchApplication");
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "searchableDirForSearchApplication call filed!";
|
|
|
|
|
return QStringList();
|
2022-03-01 10:37:03 +08:00
|
|
|
|
}
|
2022-04-25 10:23:20 +08:00
|
|
|
|
return reply.value();
|
2022-03-01 10:37:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 16:54:01 +08:00
|
|
|
|
void DirWatcher::appendSearchDir(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
QDBusReply<int> reply = m_dbusInterface->call("appendSearchDir", path);
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "appendSearchDir call filed!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DirWatcher::removeSearchDir(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
QDBusReply<void> reply = m_dbusInterface->call("removeSearchDir", path);
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "removeSearchDir call filed!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 14:57:22 +08:00
|
|
|
|
void DirWatcher::appendIndexableListItem(const QString &path)
|
|
|
|
|
{
|
2023-04-08 16:54:01 +08:00
|
|
|
|
QDBusReply<int> reply = m_dbusInterface->call("appendIndexableListItem", path);
|
2022-04-25 10:23:20 +08:00
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "appendIndexableListItem call filed!";
|
2022-04-15 10:30:01 +08:00
|
|
|
|
}
|
2022-04-12 14:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DirWatcher::removeIndexableListItem(const QString &path)
|
|
|
|
|
{
|
2022-04-25 10:23:20 +08:00
|
|
|
|
QDBusReply<void> reply = m_dbusInterface->call("removeIndexableListItem", path);
|
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
|
qCritical() << "removeIndexableListItem call filed!";
|
2022-03-01 10:37:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-31 10:48:13 +08:00
|
|
|
|
|
|
|
|
|
void DirWatcher::sendAppendSignal(const QString &path, const QStringList &blockList)
|
|
|
|
|
{
|
|
|
|
|
Q_EMIT this->appendIndexItem(path, blockList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DirWatcher::sendRemoveSignal(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
Q_EMIT this->removeIndexItem(path);
|
|
|
|
|
}
|