Merge branch '0530ukss' into 'ukss-dev'
Add the default indexable dir. See merge request kylin-desktop/ukui-search!322
This commit is contained in:
commit
e94fc38c92
|
@ -14,6 +14,9 @@ DirWatcher::DirWatcher(QObject *parent) : QObject(parent)
|
||||||
if (!m_dbusInterface->isValid()) {
|
if (!m_dbusInterface->isValid()) {
|
||||||
qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError();
|
qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError();
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
connect(m_dbusInterface, SIGNAL(appendIndexItem(QString, QStringList)), this, SLOT(sendAppendSignal(QString, QStringList)));
|
||||||
|
connect(m_dbusInterface, SIGNAL(removeIndexItem(QString)), this, SLOT(sendRemoveSignal(QString)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,3 +106,13 @@ void DirWatcher::removeIndexableListItem(const QString &path)
|
||||||
qCritical() << "removeIndexableListItem call filed!";
|
qCritical() << "removeIndexableListItem call filed!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,11 @@ public Q_SLOTS:
|
||||||
|
|
||||||
void appendIndexableListItem(const QString &path);
|
void appendIndexableListItem(const QString &path);
|
||||||
void removeIndexableListItem(const QString &path);
|
void removeIndexableListItem(const QString &path);
|
||||||
|
void sendAppendSignal(const QString &path, const QStringList &blockList);
|
||||||
|
void sendRemoveSignal(const QString&path);
|
||||||
|
Q_SIGNALS:
|
||||||
|
void appendIndexItem(const QString&, const QStringList&);
|
||||||
|
void removeIndexItem(const QString&);
|
||||||
private:
|
private:
|
||||||
DirWatcher(QObject *parent = nullptr);
|
DirWatcher(QObject *parent = nullptr);
|
||||||
~DirWatcher() = default;
|
~DirWatcher() = default;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#define CURRENT_INDEXABLE_DIR_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-current-indexable-dir.conf"
|
#define CURRENT_INDEXABLE_DIR_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-current-indexable-dir.conf"
|
||||||
#define INDEXABLE_DIR_VALUE "IndexableDir"
|
#define INDEXABLE_DIR_VALUE "IndexableDir"
|
||||||
|
#define DEFAULT_INDEXABLE_DIR QDir::homePath()
|
||||||
|
|
||||||
static std::once_flag flag;
|
static std::once_flag flag;
|
||||||
static DirWatcher *global_intance = nullptr;
|
static DirWatcher *global_intance = nullptr;
|
||||||
|
@ -18,6 +19,14 @@ QMutex DirWatcher::s_mutex;
|
||||||
DirWatcher::DirWatcher(QObject *parent) : QObject(parent)
|
DirWatcher::DirWatcher(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_qSettings = new QSettings(CURRENT_INDEXABLE_DIR_SETTINGS, QSettings::IniFormat);
|
m_qSettings = new QSettings(CURRENT_INDEXABLE_DIR_SETTINGS, QSettings::IniFormat);
|
||||||
|
this->currentIndexableDir();
|
||||||
|
if (m_indexableDirList.isEmpty()) {
|
||||||
|
qDebug() << QString("use the path: %1 as default indexable dir.").arg(DEFAULT_INDEXABLE_DIR);
|
||||||
|
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
|
||||||
|
m_qSettings->setValue(INDEXABLE_DIR_VALUE, DEFAULT_INDEXABLE_DIR);
|
||||||
|
m_qSettings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
initDiskWatcher();
|
initDiskWatcher();
|
||||||
initData();
|
initData();
|
||||||
m_adaptor = new DirWatcherAdaptor(this);
|
m_adaptor = new DirWatcherAdaptor(this);
|
||||||
|
@ -94,6 +103,12 @@ void DirWatcher::handleIndexItemAppend(const QString &path, QStringList &blackLi
|
||||||
|
|
||||||
void DirWatcher::handleIndexItemRemove(const QString &path)
|
void DirWatcher::handleIndexItemRemove(const QString &path)
|
||||||
{
|
{
|
||||||
|
this->currentIndexableDir();
|
||||||
|
QMutexLocker locker(&s_mutex);
|
||||||
|
if (!m_indexableDirList.contains(path)) {
|
||||||
|
qWarning() << QString("The path: %1 is not indexed").arg(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_indexableDirList.removeAll(path);
|
m_indexableDirList.removeAll(path);
|
||||||
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
|
m_qSettings->beginGroup(INDEXABLE_DIR_VALUE);
|
||||||
m_qSettings->setValue(INDEXABLE_DIR_VALUE, m_indexableDirList);
|
m_qSettings->setValue(INDEXABLE_DIR_VALUE, m_indexableDirList);
|
||||||
|
@ -264,15 +279,15 @@ void DirWatcher::appendIndexableListItem(const QString &path)
|
||||||
this->currentIndexableDir();
|
this->currentIndexableDir();
|
||||||
qDebug() << "current indexable dirs:" << m_indexableDirList;
|
qDebug() << "current indexable dirs:" << m_indexableDirList;
|
||||||
|
|
||||||
|
QStringList blackList;
|
||||||
|
QMutexLocker locker(&s_mutex);
|
||||||
|
|
||||||
//根目录特殊处理
|
//根目录特殊处理
|
||||||
if (path == "/") {
|
if (path == "/") {
|
||||||
this->handleIndexItemAppend(path, m_blackListOfIndex);
|
this->handleIndexItemAppend(path, m_blackListOfIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList blackList;
|
|
||||||
QMutexLocker locker(&s_mutex);
|
|
||||||
|
|
||||||
//处理要添加索引的路径与索引黑名单中路径为父子关系的情况
|
//处理要添加索引的路径与索引黑名单中路径为父子关系的情况
|
||||||
for (const QString& blackListPath : m_blackListOfIndex) {
|
for (const QString& blackListPath : m_blackListOfIndex) {
|
||||||
if (path.startsWith(blackListPath + "/") or path == blackListPath) {
|
if (path.startsWith(blackListPath + "/") or path == blackListPath) {
|
||||||
|
@ -389,7 +404,6 @@ void DirWatcher::appendIndexableListItem(const QString &path)
|
||||||
|
|
||||||
void DirWatcher::removeIndexableListItem(const QString &path)
|
void DirWatcher::removeIndexableListItem(const QString &path)
|
||||||
{
|
{
|
||||||
this->currentIndexableDir();
|
|
||||||
this->handleIndexItemRemove(path);
|
this->handleIndexItemRemove(path);
|
||||||
Q_EMIT this->removeIndexItem(path);
|
Q_EMIT this->removeIndexItem(path);
|
||||||
}
|
}
|
||||||
|
@ -442,7 +456,8 @@ void DirWatcher::initData()
|
||||||
|
|
||||||
GList *list = g_volume_monitor_get_volumes(m_volumeMonitor);
|
GList *list = g_volume_monitor_get_volumes(m_volumeMonitor);
|
||||||
if (!list) {
|
if (!list) {
|
||||||
qDebug() << "Error in glist!!!";
|
qDebug() << "Fail to init glist of volume monitor!";
|
||||||
|
handleDisk();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (guint i = 0; i < g_list_length(list); i++) {
|
for (guint i = 0; i < g_list_length(list); i++) {
|
||||||
|
@ -480,6 +495,7 @@ void DirWatcher::initDiskWatcher()
|
||||||
|
|
||||||
m_volumeMonitor = g_volume_monitor_get();
|
m_volumeMonitor = g_volume_monitor_get();
|
||||||
if (!m_volumeMonitor) {
|
if (!m_volumeMonitor) {
|
||||||
|
qDebug() << "Fail to init volume monitor";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_mountAddHandle = g_signal_connect(m_volumeMonitor, "mount-added", G_CALLBACK(mountAddCallback), this);
|
m_mountAddHandle = g_signal_connect(m_volumeMonitor, "mount-added", G_CALLBACK(mountAddCallback), this);
|
||||||
|
|
Loading…
Reference in New Issue