diff --git a/libsearch/CMakeLists.txt b/libsearch/CMakeLists.txt
index 78f0d62..5f9561f 100644
--- a/libsearch/CMakeLists.txt
+++ b/libsearch/CMakeLists.txt
@@ -65,7 +65,6 @@ set(LIBUKUI_SEARCH_SRC
index/index-scheduler.cpp index/index-scheduler.h
index/index-status-recorder.cpp index/index-status-recorder.h
index/index-updater.cpp index/index-updater.h
- index/monitor.cpp index/monitor.h
index/ocrobject.cpp index/ocrobject.h
index/pending-file.cpp index/pending-file.h
index/pending-file-queue.cpp index/pending-file-queue.h
diff --git a/libsearch/index/database.cpp b/libsearch/index/database.cpp
index 901d10e..d80d464 100644
--- a/libsearch/index/database.cpp
+++ b/libsearch/index/database.cpp
@@ -23,14 +23,17 @@ using namespace UkuiSearch;
Database::Database(const DataBaseType &type)
{
switch (type) {
- case DataBaseType::Basic:
- m_database = new Xapian::Database(INDEX_PATH.toStdString());
- break;
- case DataBaseType::Content:
- m_database = new Xapian::Database(CONTENT_INDEX_PATH.toStdString());
- break;
- default:
- break;
+ case DataBaseType::Basic:
+ m_database = new Xapian::Database(INDEX_PATH.toStdString());
+ break;
+ case DataBaseType::Content:
+ m_database = new Xapian::Database(CONTENT_INDEX_PATH.toStdString());
+ break;
+ case DataBaseType::OcrContent:
+ m_database = new Xapian::Database(OCR_CONTENT_INDEX_PATH.toStdString());
+ break;
+ default:
+ break;
}
}
@@ -42,7 +45,7 @@ Database::~Database()
}
}
-uint Database::getIndexDocCount()
+uint Database::getIndexDocCount() const
{
return m_database->get_doccount();
}
diff --git a/libsearch/index/database.h b/libsearch/index/database.h
index 7bbe648..99fe153 100644
--- a/libsearch/index/database.h
+++ b/libsearch/index/database.h
@@ -26,10 +26,10 @@ namespace UkuiSearch {
class Database
{
public:
- Database(const DataBaseType &type);
+ explicit Database(const DataBaseType &type);
~Database();
- uint getIndexDocCount();
+ uint getIndexDocCount() const;
private:
Xapian::Database *m_database;
};
diff --git a/libsearch/index/monitor.h b/libsearch/index/monitor.h
deleted file mode 100644
index 1bcbd84..0000000
--- a/libsearch/index/monitor.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2022, 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 .
- *
- * Authors: iaom
- *
- */
-#ifndef MONITOR_H
-#define MONITOR_H
-
-#include
-#include "index-scheduler.h"
-#include "database.h"
-namespace UkuiSearch {
-/**
- * @brief The Monitor class
- * 用于监控索引状态
- * 为qml
- */
-class Monitor : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QStringList currentIndexPaths READ getCurrentIndexPaths)
- Q_PROPERTY(QString indexState READ getIndexState NOTIFY indexStateChanged)
- Q_PROPERTY(uint basicIndexSize READ getBasicIndexSize NOTIFY basicIndexSizeChange)
- Q_PROPERTY(uint contentIndexSize READ getContentIndexSize NOTIFY contentIndexSizeChange)
- Q_PROPERTY(uint ocrIndexSize READ getOCRIndexSize NOTIFY ocrIndexSizeChange)
- Q_PROPERTY(uint basicIndexProgress READ getBasicIndexProgress NOTIFY basicIndexProgressUpdate)
- Q_PROPERTY(uint contentIndexProgress READ getContentIndexProgress NOTIFY contentIndexProgressUpdate)
- Q_PROPERTY(uint ocrIndexProgress READ getOCRIndexProgress NOTIFY ocrIndexProgressUpdate)
- Q_PROPERTY(uint basicIndexDocNum READ getBasicIndexDocNum NOTIFY basicIndexDocNumUpdate)
- Q_PROPERTY(uint contentIndexDocNum READ getContentIndexDocNum NOTIFY contentIndexDocNumUpdate)
-
-public:
- explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr);
- /**
- * @brief getCurrentIndexPaths
- * @return 当前索引的所有目录
- */
- QStringList getCurrentIndexPaths();
- /**
- * @brief getIndexState
- * @return 当前索引调度器的状态
- */
- QString getIndexState();
- /**
- * @brief getBasicIndexSize
- * @return 当前需要处理的基础索引数量
- */
- uint getBasicIndexSize();
- /**
- * @brief getContentIndexSize
- * @return 当前需要处理的内容索引数量
- */
- uint getContentIndexSize();
- /**
- * @brief getOCRIndexSize
- * @return 当前需要处理的OCR索引数量
- */
- uint getOCRIndexSize();
- /**
- * @brief getBasicIndexProgress
- * @return 基础索引进度
- */
- uint getBasicIndexProgress();
- /**
- * @brief getContentIndexProgress
- * @return 内容索引进度
- */
- uint getContentIndexProgress();
- /**
- * @brief getOCRIndexProgress
- * @return ocr索引进度
- */
- uint getOCRIndexProgress();
- /**
- * @brief getBasicIndexDocNum
- * @return 基础索引完成的总文档数
- */
- uint getBasicIndexDocNum();
- /**
- * @brief getContentIndexDocNum
- * @return 内容索引完成的总文档数
- */
- uint getContentIndexDocNum();
-
-Q_SIGNALS:
- /**
- * @brief indexStateChanged
- * 索引调度器状态
- */
- void indexStateChanged(QString);
- /**
- * @brief basicIndexSizeChange
- * 基础索引进度
- */
- void basicIndexSizeChange(uint);
- /**
- * @brief contentIndexSizeChange
- * 内容索引总量(包括OCR索引)
- */
- void contentIndexSizeChange(uint);
- /**
- * @brief ocrIndexSizeChange
- * OCR索引总量
- */
- void ocrIndexSizeChange(uint);
-
- /**
- * @brief basicIndexProgressUpdate
- * 基础索引进度
- */
- void basicIndexProgressUpdate(uint);
- /**
- * @brief contentIndexProgressUpdate
- * 内容索引进度(包含OCR索引)
- */
- void contentIndexProgressUpdate(uint);
- /**
- * @brief ocrIndexProgressUpdate
- * OCR索引进度
- */
- void ocrIndexProgressUpdate(uint);
- /**
- * @brief basicIndexDocNumUpdate
- * 基础索引完成的总文档数
- */
- void basicIndexDocNumUpdate(uint);
- /**
- * @brief contentIndexDocNumUpdate
- * 内容索引完成的总文档数
- */
- void contentIndexDocNumUpdate(uint);
- /**
- * @brief basicIndexDone
- * 基础索引数据库建立完成或完成增量更新
- */
- void basicIndexDone();
- /**
- * @brief contentIndexDone
- * 内容索引数据库建立完成或完成增量更新
- */
- void contentIndexDone();
-
-private Q_SLOTS:
- void onIndexStateChanged(IndexScheduler::IndexerState);
- void processUpdate(IndexType type, uint all, uint finished);
-
-private:
- IndexScheduler *m_scheduler = nullptr;
- Database m_basicDatabase;
- Database m_contentDatabase;
- uint m_basicIndexSize = 0;
- uint m_contentIndexSize = 0;
- uint m_ocrIndexSize = 0;
- uint m_basicIndexProgress = 0;
- uint m_contentIndexProgress = 0;
- uint m_ocrIndexProgress = 0;
-};
-}
-#endif // MONITOR_H
diff --git a/ukui-search-service/CMakeLists.txt b/ukui-search-service/CMakeLists.txt
index 7d105ea..c4e7528 100644
--- a/ukui-search-service/CMakeLists.txt
+++ b/ukui-search-service/CMakeLists.txt
@@ -11,8 +11,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
-find_package(QT NAMES Qt6 Qt5 COMPONENTS Core DBus Gui Quick Widgets REQUIRED)
-find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Gui Quick Widgets REQUIRED)
+find_package(QT NAMES Qt6 Qt5 COMPONENTS Core DBus Gui Quick Widgets RemoteObjects REQUIRED)
+find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Gui Quick Widgets RemoteObjects REQUIRED)
find_package(PkgConfig REQUIRED)
set(UKUI_SEARCH_SERVICE_EXTERNAL_LIBS "")
set(UKUI_SEARCH_SERVICE_PC_PKGS gsettings-qt)
@@ -27,9 +27,17 @@ foreach(PC_LIB IN ITEMS ${UKUI_SEARCH_SERVICE_PC_PKGS})
endforeach()
set(QRC_FILES qml/qml.qrc)
-add_executable(ukui-search-service
+set(UKUI_SEARCH_SERVICE_SRC
main.cpp
- ukui-search-service.cpp ukui-search-service.h
+ ukui-search-service.cpp
+ ukui-search-service.h
+ monitor.cpp
+ monitor.h
+)
+qt5_generate_repc(UKUI_SEARCH_SERVICE_SRC monitor.rep SOURCE)
+qt5_generate_repc(UKUI_SEARCH_SERVICE_SRC monitor.rep REPLICA)
+add_executable(ukui-search-service
+ ${UKUI_SEARCH_SERVICE_SRC}
${QRC_FILES}
)
target_include_directories(ukui-search-service PRIVATE
@@ -53,6 +61,7 @@ target_link_libraries(ukui-search-service PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Widgets
+ Qt${QT_VERSION_MAJOR}::RemoteObjects
libukui-search
qtsingleapplication
${UKUI_SEARCH_SERVICE_EXTERNAL_LIBS}
diff --git a/ukui-search-service/main.cpp b/ukui-search-service/main.cpp
index 55ef2f9..1c5a72b 100644
--- a/ukui-search-service/main.cpp
+++ b/ukui-search-service/main.cpp
@@ -56,8 +56,6 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
UkuiSearchService ukss(argc, argv, "ukui-search-service");
- if (ukss.isRunning())
- return 0;
- return ukss.exec();
+ return UkuiSearch::UkuiSearchService::exec();
}
diff --git a/libsearch/index/monitor.cpp b/ukui-search-service/monitor.cpp
similarity index 57%
rename from libsearch/index/monitor.cpp
rename to ukui-search-service/monitor.cpp
index 38521dd..6118f5e 100644
--- a/libsearch/index/monitor.cpp
+++ b/ukui-search-service/monitor.cpp
@@ -21,74 +21,85 @@
#include
#include "file-indexer-config.h"
using namespace UkuiSearch;
-Monitor::Monitor(IndexScheduler *scheduler, QObject *parent)
- : QObject(parent),
- m_scheduler(scheduler),
- m_basicDatabase(DataBaseType::Basic),
- m_contentDatabase(DataBaseType::Content)
+Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) : MonitorSource(parent),
+ m_scheduler(scheduler),
+ m_basicDatabase(DataBaseType::Basic),
+ m_contentDatabase(DataBaseType::Content),
+ m_ocrContentDatabase(DataBaseType::OcrContent)
{
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged);
connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate);
connect(scheduler, &IndexScheduler::basicIndexDone, this, &Monitor::basicIndexDone);
connect(scheduler, &IndexScheduler::contentIndexDone, this, &Monitor::contentIndexDone);
+ connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::appendIndexDir, this, [&](){
+ Q_EMIT currentIndexPathsChanged(FileIndexerConfig::getInstance()->currentIndexableDir());
+ });
+ connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::removeIndexDir, this, [&](){
+ Q_EMIT currentIndexPathsChanged(FileIndexerConfig::getInstance()->currentIndexableDir());
+ });
}
-QStringList Monitor::getCurrentIndexPaths()
+QStringList Monitor::currentIndexPaths() const
{
return FileIndexerConfig::getInstance()->currentIndexableDir();
}
-QString Monitor::getIndexState()
+QString Monitor::indexState() const
{
QMetaEnum metaEnum = QMetaEnum::fromType();
return QString::fromLocal8Bit(metaEnum.valueToKey(m_scheduler->getIndexState()));
}
-uint Monitor::getBasicIndexSize()
+uint Monitor::basicIndexSize() const
{
return m_basicIndexSize;
}
-uint Monitor::getContentIndexSize()
+uint Monitor::contentIndexSize() const
{
return m_contentIndexSize;
}
-uint Monitor::getOCRIndexSize()
+uint Monitor::ocrIndexSize() const
{
return m_ocrIndexSize;
}
-uint Monitor::getBasicIndexProgress()
+uint Monitor::basicIndexProgress() const
{
return m_basicIndexProgress;
}
-uint Monitor::getContentIndexProgress()
+uint Monitor::contentIndexProgress() const
{
return m_contentIndexProgress;
}
-uint Monitor::getOCRIndexProgress()
+uint Monitor::ocrIndexProgress() const
{
return m_ocrIndexProgress;
}
-uint Monitor::getBasicIndexDocNum()
+uint Monitor::basicIndexDocNum() const
{
return m_basicDatabase.getIndexDocCount();
}
-uint Monitor::getContentIndexDocNum()
+uint Monitor::contentIndexDocNum() const
{
return m_contentDatabase.getIndexDocCount();
}
+uint Monitor::ocrContentIndexDocNum() const
+{
+ return m_ocrContentDatabase.getIndexDocCount();
+}
+
void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state)
{
if(state == IndexScheduler::IndexerState::Idle) {
- Q_EMIT basicIndexDocNumUpdate(m_basicDatabase.getIndexDocCount());
- Q_EMIT contentIndexDocNumUpdate(m_contentDatabase.getIndexDocCount());
+ Q_EMIT basicIndexDocNumChanged(m_basicDatabase.getIndexDocCount());
+ Q_EMIT contentIndexDocNumChanged(m_contentDatabase.getIndexDocCount());
}
QMetaEnum metaEnum = QMetaEnum::fromType();
Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state)));
@@ -99,21 +110,21 @@ void Monitor::processUpdate(IndexType type, uint all, uint finished)
switch (type) {
case IndexType::Basic:
m_basicIndexSize = all;
- Q_EMIT basicIndexSizeChange(m_basicIndexSize);
+ Q_EMIT basicIndexSizeChanged(m_basicIndexSize);
m_basicIndexProgress = finished;
- Q_EMIT basicIndexProgressUpdate(m_basicIndexProgress);
+ Q_EMIT basicIndexProgressChanged(m_basicIndexProgress);
break;
case IndexType::Contents:
m_contentIndexSize = all;
- Q_EMIT contentIndexSizeChange(m_contentIndexSize);
+ Q_EMIT contentIndexSizeChanged(m_contentIndexSize);
m_contentIndexProgress = finished;
- Q_EMIT contentIndexProgressUpdate(m_contentIndexProgress);
+ Q_EMIT contentIndexProgressChanged(m_contentIndexProgress);
break;
case IndexType::OCR:
m_ocrIndexSize = all;
- Q_EMIT ocrIndexSizeChange(m_ocrIndexSize);
+ Q_EMIT ocrIndexSizeChanged(m_ocrIndexSize);
m_contentIndexProgress = finished;
- Q_EMIT ocrIndexProgressUpdate(m_contentIndexProgress);
+ Q_EMIT ocrIndexProgressChanged(m_contentIndexProgress);
break;
default:
break;
diff --git a/ukui-search-service/monitor.h b/ukui-search-service/monitor.h
new file mode 100644
index 0000000..13d7cd8
--- /dev/null
+++ b/ukui-search-service/monitor.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2022, 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 .
+ *
+ * Authors: iaom
+ *
+ */
+#ifndef MONITOR_H
+#define MONITOR_H
+
+#include
+#include "index-scheduler.h"
+#include "database.h"
+#include "rep_monitor_source.h"
+namespace UkuiSearch {
+/**
+ * @brief The Monitor class
+ * 用于监控索引状态
+ */
+class Monitor : public MonitorSource
+{
+ Q_OBJECT
+
+public:
+ explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr);
+ /**
+ * @brief currentIndexPaths
+ * @return 当前索引的所有目录
+ */
+ QStringList currentIndexPaths() const override;
+ /**
+ * @brief indexState
+ * @return 当前索引调度器的状态
+ */
+ QString indexState() const override;
+ /**
+ * @brief basicIndexSize
+ * @return 当前需要处理的基础索引数量
+ */
+ uint basicIndexSize() const override;
+ /**
+ * @brief contentIndexSize
+ * @return 当前需要处理的内容索引数量
+ */
+ uint contentIndexSize() const override;
+ /**
+ * @brief ocrIndexSize
+ * @return 当前需要处理的OCR索引数量
+ */
+ uint ocrIndexSize() const override;
+ /**
+ * @brief basicIndexProgress
+ * @return 基础索引进度
+ */
+ uint basicIndexProgress() const override;
+ /**
+ * @brief contentIndexProgress
+ * @return 内容索引进度
+ */
+ uint contentIndexProgress() const override;
+ /**
+ * @brief ocrIndexProgress
+ * @return ocr索引进度
+ */
+ uint ocrIndexProgress() const override;
+ /**
+ * @brief basicIndexDocNum
+ * @return 基础索引完成的总文档数
+ */
+ uint basicIndexDocNum() const override;
+ /**
+ * @brief contentIndexDocNum
+ * @return 内容索引完成的总文档数
+ */
+ uint contentIndexDocNum() const override;
+ /**
+ * @brief contentIndexDocNum
+ * @return ocr容索引完成的总文档数
+ */
+ uint ocrContentIndexDocNum() const override;
+
+Q_SIGNALS:
+ /**
+ * @brief basicIndexDone
+ * 基础索引数据库建立完成或完成增量更新
+ */
+ void basicIndexDone();
+ /**
+ * @brief contentIndexDone
+ * 内容索引数据库建立完成或完成增量更新
+ */
+ void contentIndexDone();
+
+private Q_SLOTS:
+ void onIndexStateChanged(IndexScheduler::IndexerState);
+ void processUpdate(UkuiSearch::IndexType type, uint all, uint finished);
+
+private:
+ IndexScheduler *m_scheduler = nullptr;
+ Database m_basicDatabase;
+ Database m_contentDatabase;
+ Database m_ocrContentDatabase;
+ uint m_basicIndexSize = 0;
+ uint m_contentIndexSize = 0;
+ uint m_ocrIndexSize = 0;
+ uint m_basicIndexProgress = 0;
+ uint m_contentIndexProgress = 0;
+ uint m_ocrIndexProgress = 0;
+};
+}
+#endif // MONITOR_H
diff --git a/ukui-search-service/monitor.rep b/ukui-search-service/monitor.rep
new file mode 100644
index 0000000..ccc33b5
--- /dev/null
+++ b/ukui-search-service/monitor.rep
@@ -0,0 +1,15 @@
+#include
+class Monitor
+{
+ PROP(QStringList currentIndexPaths READONLY);
+ PROP(QString indexState READONLY);
+ PROP(uint basicIndexSize READONLY);
+ PROP(uint contentIndexSize READONLY);
+ PROP(uint ocrIndexSize READONLY);
+ PROP(uint basicIndexProgress READONLY);
+ PROP(uint contentIndexProgress READONLY);
+ PROP(uint ocrIndexProgress READONLY);
+ PROP(uint basicIndexDocNum READONLY);
+ PROP(uint contentIndexDocNum READONLY);
+ PROP(uint ocrContentIndexDocNum READONLY);
+};
\ No newline at end of file
diff --git a/ukui-search-service/ukui-search-service.cpp b/ukui-search-service/ukui-search-service.cpp
index fef85ad..6dc167c 100644
--- a/ukui-search-service/ukui-search-service.cpp
+++ b/ukui-search-service/ukui-search-service.cpp
@@ -20,10 +20,14 @@
#include
#include
#include
+#include
+
+#include
#include "ukui-search-service.h"
#include "dir-watcher.h"
#include "file-utils.h"
#include "file-indexer-config.h"
+#include "rep_monitor_replica.h"
using namespace UkuiSearch;
UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &applicationName)
@@ -34,17 +38,20 @@ UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &app
setQuitOnLastWindowClosed(false);
if (!this->isRunning()) {
- connect(this, &QtSingleApplication::messageReceived, [=](QString msg) {
+ connect(this, &QtSingleApplication::messageReceived, [=](const QString& msg) {
this->parseCmd(msg, true);
});
qRegisterMetaType("IndexType");
m_indexScheduler = new IndexScheduler(this);
DirWatcher::getDirWatcher()->initDbusService();
+ m_monitor = new Monitor(m_indexScheduler, this);
+ m_qroHost.setHostUrl(QUrl(QStringLiteral("local:ukui-search-service-monitor")));
+ qDebug() << "Init remote status object:" << m_qroHost.enableRemoting(m_monitor);
}
//parse cmd
qDebug()<<"parse cmd";
- auto message = this->arguments().join(' ').toUtf8();
+ auto message = arguments().join(' ').toUtf8();
parseCmd(message, !isRunning());
qDebug()<<"ukui search service constructor end";
@@ -58,7 +65,7 @@ UkuiSearchService::~UkuiSearchService()
}
}
-void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
+void UkuiSearchService::parseCmd(const QString& msg, bool isPrimary)
{
QCommandLineParser parser;
@@ -71,8 +78,8 @@ void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
QCommandLineOption monitorWindow(QStringList()<<"m"<<"monitor", tr("Show index monitor window"));
parser.addOption(monitorWindow);
-// QCommandLineOption statusOption(QStringList()<<"s"<<"status", tr("show status of file index service"));
-// parser.addOption(statusOption);
+ QCommandLineOption statusOption(QStringList()<<"s"<<"status", tr("show status of file index service"));
+ parser.addOption(statusOption);
if (isPrimary) {
const QStringList args = QString(msg).split(' ');
@@ -86,13 +93,18 @@ void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
qApp->quit();
return;
}
- }
- else {
+ } else {
if (arguments().count() < 2) {
parser.showHelp();
}
parser.process(arguments());
- sendMessage(msg);
+ if(parser.isSet(statusOption)) {
+ showMonitorState();
+ return;
+ } else {
+ sendMessage(msg);
+ ::exit(0);
+ }
}
}
@@ -108,3 +120,29 @@ void UkuiSearchService::loadMonitorWindow()
m_quickView->setSource(m_qmlPath);
}
}
+
+void UkuiSearchService::showMonitorState()
+{
+ m_qroNode.connectToNode(QUrl(QStringLiteral("local:ukui-search-service-monitor")));
+ auto *m = m_qroNode.acquire();
+ connect(m, &QRemoteObjectReplica::initialized, [&, m](){
+ qDebug() << "QRemoteObjectReplica initialized";
+ QString state = m->indexState();
+ QString message = "Current index path: " + m->currentIndexPaths().join(",") + "\n"
+ + "Current index scheduler state: " + m->indexState() + "\n";
+ if(state == "Idle" || state == "Stop") {
+ message += "Basic index size: " + QString::number(m->basicIndexDocNum()) + " \n"
+ + "Content index size: " + QString::number(m->contentIndexDocNum()) + " \n"
+ + "Ocr index size: " + QString::number(m->ocrContentIndexDocNum()) + " \n";
+
+ } else {
+ message += "Basic index progress: " + QString::number(m->basicIndexProgress()) + " of " + QString::number(m->basicIndexSize())+ " finished\n"
+ + "Content index size: " + QString::number(m->contentIndexProgress()) + " of " + QString::number(m->contentIndexSize())+ " finished\n"
+ + "Ocr content index size: " + QString::number(m->ocrIndexProgress()) + " of " + QString::number(m->ocrIndexSize())+ " finished\n";
+ }
+
+ delete m;
+ fputs(qPrintable(message), stdout);
+ qApp->quit();
+ });
+}
diff --git a/ukui-search-service/ukui-search-service.h b/ukui-search-service/ukui-search-service.h
index 3fd274c..edafac4 100644
--- a/ukui-search-service/ukui-search-service.h
+++ b/ukui-search-service/ukui-search-service.h
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
#include "qtsingleapplication.h"
#include "common.h"
#include "index-scheduler.h"
@@ -39,12 +40,15 @@ public:
~UkuiSearchService();
protected Q_SLOTS:
- void parseCmd(QString msg, bool isPrimary);
+ void parseCmd(const QString& msg, bool isPrimary);
private:
void loadMonitorWindow();
+ void showMonitorState();
IndexScheduler *m_indexScheduler = nullptr;
Monitor *m_monitor = nullptr;
+ QRemoteObjectHost m_qroHost;
+ QRemoteObjectNode m_qroNode;
QQuickView *m_quickView = nullptr;
QUrl m_qmlPath = QString("qrc:/qml/IndexMonitor.qml");