diff --git a/libsearch/CMakeLists.txt b/libsearch/CMakeLists.txt index e285378..bd51e9d 100644 --- a/libsearch/CMakeLists.txt +++ b/libsearch/CMakeLists.txt @@ -111,7 +111,7 @@ set(LIBUKUI_SEARCH_SRC icon-loader.cpp icon-loader.h data-collecter.cpp data-collecter.h - + remote-file-event-helper.cpp ) qt5_generate_repc(LIBUKUI_SEARCH_SRC index/monitor.rep REPLICA) set(QRC_FILES resource1.qrc) @@ -119,6 +119,8 @@ file(GLOB TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../translations/libukui-search/*. set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/libsearch/.qm) qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES}) +qt5_generate_repc(LIBUKUI_SEARCH_SRC fileeventhandler.rep REPLICA) + add_library(${PROJECT_NAME} SHARED ${LIBUKUI_SEARCH_SRC} ${QRC_FILES} @@ -231,4 +233,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-search-config.cmake DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}) if(BUILD_TEST) add_subdirectory(test) -endif () \ No newline at end of file +endif () diff --git a/libsearch/fileeventhandler.rep b/libsearch/fileeventhandler.rep new file mode 100644 index 0000000..98aad46 --- /dev/null +++ b/libsearch/fileeventhandler.rep @@ -0,0 +1,6 @@ +#include + +class FileEventHandler +{ + SLOT(void handleFileEvent(int eventType, QString arg1, QString arg2)) +} diff --git a/libsearch/index/index-updater.cpp b/libsearch/index/index-updater.cpp index 2aca5f4..6b63d68 100644 --- a/libsearch/index/index-updater.cpp +++ b/libsearch/index/index-updater.cpp @@ -29,6 +29,7 @@ #include "compatible-define.h" #include "index-status-recorder.h" #include "ai-indexer.h" +#include "pending-file-queue.h" using namespace UkuiSearch; IndexUpdater::IndexUpdater(const QVector& files, QAtomicInt& indexstop, @@ -41,6 +42,7 @@ IndexUpdater::IndexUpdater(const QVector& files, m_contentIndexOcrStop(&contentIndexOcrStop), m_aiIndexStop(&aiIndexStop) { + connect(this, &IndexUpdater::indexUpdated, PendingFileQueue::getInstance(), &PendingFileQueue::signalFileEvent); } void IndexUpdater::updateIndex() { @@ -55,6 +57,11 @@ void IndexUpdater::updateIndex() } qDebug() << "===update basic index==="; for(const PendingFile& file : m_cache) { + // notify ukui-idm + if (file.isCreated()) { + Q_EMIT indexUpdated(1, file.path(), nullptr); + } + if(file.shouldRemoveIndex()) { qDebug() << "| remove:" < #include "index-status-recorder.h" +#include "remote-file-event-helper.h" + using namespace UkuiSearch; static PendingFileQueue *global_instance_pending_file_queue = nullptr; PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent) @@ -38,6 +40,9 @@ PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent) m_cacheTimer->moveToThread(this); m_minProcessTimer->moveToThread(this); + m_fileEventHelper = new RemoteFileEventHelper; + m_fileEventHelper->moveToThread(this); + // connect(this, &PendingFileQueue::cacheTimerStart, m_cacheTimer, f, Qt::DirectConnection); // connect(this, &PendingFileQueue::minProcessTimerStart, m_minProcessTimer, f,Qt::DirectConnection); connect(this, SIGNAL(cacheTimerStart()), m_cacheTimer, SLOT(start())); @@ -47,6 +52,8 @@ PendingFileQueue::PendingFileQueue(QObject *parent) : QThread(parent) connect(m_cacheTimer, &QTimer::timeout, this, &PendingFileQueue::processCache, Qt::DirectConnection); connect(m_minProcessTimer, &QTimer::timeout, this, &PendingFileQueue::processCache, Qt::DirectConnection); + + connect(this, &PendingFileQueue::signalFileEvent, m_fileEventHelper, &RemoteFileEventHelper::handleFileEventRequest); } PendingFileQueue *PendingFileQueue::getInstance(QObject *parent) @@ -67,6 +74,11 @@ PendingFileQueue::~PendingFileQueue() delete m_minProcessTimer; m_minProcessTimer = nullptr; } + if(m_fileEventHelper) { + delete m_fileEventHelper; + m_fileEventHelper = nullptr; + } + global_instance_pending_file_queue = nullptr; } diff --git a/libsearch/index/pending-file-queue.h b/libsearch/index/pending-file-queue.h index ef3bda3..022a9fa 100644 --- a/libsearch/index/pending-file-queue.h +++ b/libsearch/index/pending-file-queue.h @@ -27,6 +27,8 @@ #include #include "pending-file.h" +class RemoteFileEventHelper; + namespace UkuiSearch { class PendingFileQueue : public QThread { @@ -51,6 +53,8 @@ Q_SIGNALS: void timerStop(); void filesUpdate(const QVector&); + + void signalFileEvent(int eventType, const QString &arg1, const QString &arg2); private: void processCache(); explicit PendingFileQueue(QObject *parent = nullptr); @@ -61,6 +65,7 @@ private: QThread *m_timerThread = nullptr; int m_enqueuetimes = 0; + RemoteFileEventHelper *m_fileEventHelper = nullptr; }; } #endif // PENDINGFILEQUEUE_H diff --git a/libsearch/remote-file-event-helper.cpp b/libsearch/remote-file-event-helper.cpp new file mode 100644 index 0000000..4c8f175 --- /dev/null +++ b/libsearch/remote-file-event-helper.cpp @@ -0,0 +1,48 @@ +#include "remote-file-event-helper.h" +#include "rep_fileeventhandler_replica.h" + +#include +#include + +RemoteFileEventHelper::RemoteFileEventHelper(QObject *parent) : QObject(parent) +{ + setupConnections(); +} + +RemoteFileEventHelper::~RemoteFileEventHelper() +{ + delete m_fileEventHandlerIface; + delete m_remoteNode; +} + +void RemoteFileEventHelper::setupConnections() +{ + m_remoteNode = new QRemoteObjectNode; + m_remoteNode->connectToNode(nodeUrl()); + m_fileEventHandlerIface = m_remoteNode->acquire(); + qDebug() << "connect handle" << m_fileEventHandlerIface; + connect(m_fileEventHandlerIface, &QRemoteObjectReplica::initialized, this, [=]{ + qDebug() << "initilized" << m_fileEventHandlerIface; + }); + connect(m_fileEventHandlerIface, &QRemoteObjectReplica::stateChanged, this, [=](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState){ + qDebug() << "state changed" << state << oldState << m_fileEventHandlerIface; + if (state == QRemoteObjectReplica::Suspect) { + qDebug() << "try reconnect"; + m_fileEventHandlerIface->deleteLater(); + m_remoteNode->deleteLater(); + setupConnections(); + } + }); + connect(this, &RemoteFileEventHelper::handleFileEventRequest, m_fileEventHandlerIface, [=](int type, const QString &arg1, const QString &arg2){ + qDebug() << type << arg1 << arg2 << m_fileEventHandlerIface; + if (m_fileEventHandlerIface->state() == QRemoteObjectReplica::Valid) + m_fileEventHandlerIface->handleFileEvent(type, arg1, arg2); + }); +} + +QUrl RemoteFileEventHelper::nodeUrl() +{ + QString displayEnv = (qgetenv("XDG_SESSION_TYPE") == "wayland") ? QLatin1String("WAYLAND_DISPLAY") : QLatin1String("DISPLAY"); + QString display(qgetenv(displayEnv.toUtf8().data())); + return QUrl(QStringLiteral("local:ukui-idm-") + QString(qgetenv("USER")) + display); +} diff --git a/libsearch/remote-file-event-helper.h b/libsearch/remote-file-event-helper.h new file mode 100644 index 0000000..e8dae0c --- /dev/null +++ b/libsearch/remote-file-event-helper.h @@ -0,0 +1,28 @@ +#ifndef REMOTEFILEEVENTHELPER_H +#define REMOTEFILEEVENTHELPER_H + +#include +#include + +class QRemoteObjectNode; +class FileEventHandlerReplica; + +class RemoteFileEventHelper : public QObject +{ + Q_OBJECT +public: + explicit RemoteFileEventHelper(QObject *parent = nullptr); + ~RemoteFileEventHelper(); + +Q_SIGNALS: + void handleFileEventRequest(int type, const QString &arg1, const QString &arg2); + +private: + void setupConnections(); + static QUrl nodeUrl(); + + QRemoteObjectNode *m_remoteNode = nullptr; + FileEventHandlerReplica *m_fileEventHandlerIface = nullptr; +}; + +#endif // REMOTEFILEEVENTHELPER_H