From ffef1d76eed86be394ad937a1a0efbf22aa79b7b Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Tue, 11 Oct 2022 16:10:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=9B=E7=A8=8B=E9=97=B4?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=A1=E5=8F=B7=E9=87=8F=EF=BC=9B=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8F=AF=E7=B4=A2=E5=BC=95=E7=9B=AE=E5=BD=95=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/dirwatcher/dir-watcher.cpp | 9 +++++++-- libsearch/dirwatcher/dir-watcher.h | 4 +++- .../ukui-search-dir-manager-dbus.cpp | 4 +++- .../ukui-search-dir-manager-dbus.h | 3 +++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libsearch/dirwatcher/dir-watcher.cpp b/libsearch/dirwatcher/dir-watcher.cpp index 1e79090..54c8d86 100644 --- a/libsearch/dirwatcher/dir-watcher.cpp +++ b/libsearch/dirwatcher/dir-watcher.cpp @@ -2,15 +2,20 @@ #include #include +#include static std::once_flag flag; static DirWatcher *global_intance = nullptr; -DirWatcher::DirWatcher(QObject *parent) : QObject(parent) +DirWatcher::DirWatcher(QObject *parent) + : QObject(parent), m_semaphore(QStringLiteral("ukui-search-dir-manager-dbus-register-sem"), 0, QSystemSemaphore::AccessMode::Open) { + m_dbusInterface = new QDBusInterface("com.ukui.search.fileindex.service", "/org/ukui/search/privateDirWatcher", "org.ukui.search.fileindex"); + m_semaphore.acquire(); + m_semaphore.release(); if (!m_dbusInterface->isValid()) { qCritical() << "Create privateDirWatcher Interface Failed Because: " << QDBusConnection::sessionBus().lastError(); return; @@ -42,7 +47,7 @@ QStringList DirWatcher::currentIndexableDir() QDBusReply reply = m_dbusInterface->call("currentIndexableDir"); if (!reply.isValid()) { qCritical() << "currentIndexableDir call filed!"; - return QStringList(); + return QStringList() << QString(QDir::homePath()); } return reply.value(); } diff --git a/libsearch/dirwatcher/dir-watcher.h b/libsearch/dirwatcher/dir-watcher.h index 11da431..56ea7e5 100644 --- a/libsearch/dirwatcher/dir-watcher.h +++ b/libsearch/dirwatcher/dir-watcher.h @@ -4,7 +4,7 @@ #include #include #include - +#include class DirWatcher : public QObject { @@ -34,6 +34,8 @@ private: ~DirWatcher() = default; QDBusInterface *m_dbusInterface = nullptr; + + QSystemSemaphore m_semaphore; }; #endif // MOUNTDISKLISTENER_H diff --git a/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.cpp b/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.cpp index ca327e0..868e146 100644 --- a/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.cpp +++ b/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.cpp @@ -5,7 +5,8 @@ #include #include -UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName) : QtSingleApplication (applicationName, argc, argv) +UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName) + : QtSingleApplication (applicationName, argc, argv), m_semaphore(QStringLiteral("ukui-search-dir-manager-dbus-register-sem"), 0, QSystemSemaphore::AccessMode::Create) { setQuitOnLastWindowClosed(false); setApplicationVersion(QString("v%1").arg(VERSION)); @@ -27,6 +28,7 @@ UkuiSearchDirManagerDbus::UkuiSearchDirManagerDbus(int &argc, char *argv[], cons } else { qWarning() << "Ukui search dir manager is running!"; } + m_semaphore.release(); //parse cmd qDebug()<<"parse cmd"; auto message = this->arguments().join(' ').toUtf8(); diff --git a/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.h b/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.h index d8f7f96..ddffe13 100644 --- a/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.h +++ b/ukui-search-service-dir-manager/ukui-search-dir-manager-dbus.h @@ -1,6 +1,7 @@ #ifndef UKUISEARCHDIRWATCHERDBUS_H #define UKUISEARCHDIRWATCHERDBUS_H +#include #include "qtsingleapplication.h" class UkuiSearchDirManagerDbus : public QtSingleApplication @@ -10,6 +11,8 @@ public: UkuiSearchDirManagerDbus(int &argc, char *argv[], const QString &applicationName = "ukui-search-service-dir-manager"); protected Q_SLOTS: void parseCmd(QString msg, bool isPrimary); +private: + QSystemSemaphore m_semaphore; }; #endif // UKUISEARCHDIRWATCHERDBUS_H