增加了一个用于调试的索引状态监控页面,可通过'ukui-search-service -m'打开.

This commit is contained in:
iaom 2022-12-09 16:30:58 +08:00
parent 8611cf74b6
commit 3af1582eb1
13 changed files with 505 additions and 41 deletions

View File

@ -28,7 +28,7 @@
#include "file-content-indexer.h" #include "file-content-indexer.h"
#include "writable-database.h" #include "writable-database.h"
using namespace UkuiSearch; using namespace UkuiSearch;
FirstRunIndexer::FirstRunIndexer(const QStringList &folders, const QStringList &blackList, QAtomicInt& stop, WorkModes mode, Targets target) FirstRunIndexer::FirstRunIndexer(const QStringList &folders, const QStringList &blackList, QAtomicInt& stop, WorkMode mode, Targets target)
: m_folders(folders), : m_folders(folders),
m_blackList(blackList), m_blackList(blackList),
m_stop(&stop), m_stop(&stop),
@ -58,7 +58,7 @@ void FirstRunIndexer::run()
m_cache.clear(); m_cache.clear();
malloc_trim(0); malloc_trim(0);
qDebug() << "FirstRunIndexer: time :" << t.elapsed(); qDebug() << "FirstRunIndexer: time :" << t.elapsed();
Q_EMIT done(); Q_EMIT done(m_mode);
} }
void FirstRunIndexer::fetch() void FirstRunIndexer::fetch()

View File

@ -41,7 +41,7 @@ public:
Add = 1, Add = 1,
Rebuild Rebuild
}; };
Q_DECLARE_FLAGS(WorkModes, WorkMode) Q_ENUM(WorkMode)
/** /**
* @brief The Target enum * @brief The Target enum
* *
@ -57,7 +57,7 @@ public:
}; };
Q_DECLARE_FLAGS(Targets, Target) Q_DECLARE_FLAGS(Targets, Target)
FirstRunIndexer(const QStringList& folders, const QStringList& blackList, QAtomicInt& stop, WorkModes mode = WorkMode::Update, Targets target = Target::All); FirstRunIndexer(const QStringList& folders, const QStringList& blackList, QAtomicInt& stop, WorkMode mode = WorkMode::Update, Targets target = Target::All);
~FirstRunIndexer(); ~FirstRunIndexer();
void run() override; void run() override;
@ -65,14 +65,14 @@ Q_SIGNALS:
void progress(IndexType type, uint all, uint finished); void progress(IndexType type, uint all, uint finished);
void basicIndexDone(int size); void basicIndexDone(int size);
void contentIndexDone(int size); void contentIndexDone(int size);
void done(); void done(WorkMode);
private: private:
void fetch(); void fetch();
void basicIndex(); void basicIndex();
void contentIndex(); void contentIndex();
WorkModes m_mode; WorkMode m_mode;
Targets m_target; Targets m_target;
QStringList m_folders; QStringList m_folders;
QStringList m_blackList; QStringList m_blackList;

View File

@ -29,6 +29,7 @@ IndexScheduler::IndexScheduler(QObject *parent) :
m_stop(0) m_stop(0)
{ {
qRegisterMetaType<IndexerState>("IndexerState"); qRegisterMetaType<IndexerState>("IndexerState");
qRegisterMetaType<FirstRunIndexer::WorkMode>("FirstRunIndexer::WorkMode");
m_threadPool.setMaxThreadCount(1); m_threadPool.setMaxThreadCount(1);
connect(&m_fileWatcher, &FileWatcher::filesUpdate, this, &IndexScheduler::updateIndex); connect(&m_fileWatcher, &FileWatcher::filesUpdate, this, &IndexScheduler::updateIndex);
connect(m_config, &FileIndexerConfig::fileIndexEnableStatusChanged, this, &IndexScheduler::fileIndexEnable); connect(m_config, &FileIndexerConfig::fileIndexEnableStatusChanged, this, &IndexScheduler::fileIndexEnable);
@ -50,6 +51,7 @@ void IndexScheduler::addNewPath(const QString &folders, const QStringList &black
} }
m_isAddNewPathFinished = false; m_isAddNewPathFinished = false;
m_state = Running; m_state = Running;
Q_EMIT stateChange(m_state);
FirstRunIndexer::Targets target = FirstRunIndexer::Target::None; FirstRunIndexer::Targets target = FirstRunIndexer::Target::None;
if(m_config->isFileIndexEnable()) { if(m_config->isFileIndexEnable()) {
target |= FirstRunIndexer::Target::Basic; target |= FirstRunIndexer::Target::Basic;
@ -57,10 +59,9 @@ void IndexScheduler::addNewPath(const QString &folders, const QStringList &black
if(m_config->isContentIndexEnable()) { if(m_config->isContentIndexEnable()) {
target |= FirstRunIndexer::Target::Content; target |= FirstRunIndexer::Target::Content;
} }
FirstRunIndexer::WorkMode mode = FirstRunIndexer::WorkMode::Add;
startIndexJob(QStringList() << folders, blackList, mode, target);
if(FirstRunIndexer::Target::None != target) { if(FirstRunIndexer::Target::None != target) {
FirstRunIndexer *indexer = new FirstRunIndexer(QStringList(folders), blackList, m_stop, FirstRunIndexer::WorkMode::Add, target);
connect(indexer, &FirstRunIndexer::done, this, &IndexScheduler::addNewPathFinished, Qt::QueuedConnection);
m_threadPool.start(indexer);
m_fileWatcher.addWatch(folders, blackList); m_fileWatcher.addWatch(folders, blackList);
} }
} }
@ -96,7 +97,7 @@ void IndexScheduler::scheduleIndexing()
Q_EMIT stateChange(m_state); Q_EMIT stateChange(m_state);
FirstRunIndexer::Targets rebuiltTarget = checkAndRebuild(); FirstRunIndexer::Targets rebuiltTarget = checkAndRebuild();
FirstRunIndexer::WorkModes mode = FirstRunIndexer::WorkMode::Update; FirstRunIndexer::WorkMode mode = FirstRunIndexer::WorkMode::Update;
FirstRunIndexer::Targets target = FirstRunIndexer::Target::None; FirstRunIndexer::Targets target = FirstRunIndexer::Target::None;
//如果数据库被执行过重建,那么跳过增量更新步骤。 //如果数据库被执行过重建,那么跳过增量更新步骤。
@ -108,7 +109,7 @@ void IndexScheduler::scheduleIndexing()
target |= FirstRunIndexer::Target::Content; target |= FirstRunIndexer::Target::Content;
m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Updating); m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Updating);
} }
startIndexJob(mode, target); startIndexJob(m_config->currentIndexableDir(), m_config->currentBlackListOfIndex(), mode, target);
//启动监听 //启动监听
m_fileWatcher.installWatches(); m_fileWatcher.installWatches();
@ -121,7 +122,7 @@ IndexScheduler::IndexerState IndexScheduler::getIndexState()
FirstRunIndexer::Targets IndexScheduler::checkAndRebuild() FirstRunIndexer::Targets IndexScheduler::checkAndRebuild()
{ {
FirstRunIndexer::WorkModes mode = FirstRunIndexer::WorkMode::Rebuild; FirstRunIndexer::WorkMode mode = FirstRunIndexer::WorkMode::Rebuild;
FirstRunIndexer::Targets target = FirstRunIndexer::Target::None; FirstRunIndexer::Targets target = FirstRunIndexer::Target::None;
if((m_statusRecorder->getStatus(INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Error || !m_statusRecorder->versionCheck(INDEX_DATABASE_VERSION_KEY, INDEX_DATABASE_VERSION)) if((m_statusRecorder->getStatus(INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Error || !m_statusRecorder->versionCheck(INDEX_DATABASE_VERSION_KEY, INDEX_DATABASE_VERSION))
&& m_config->isFileIndexEnable()) { && m_config->isFileIndexEnable()) {
@ -136,14 +137,14 @@ FirstRunIndexer::Targets IndexScheduler::checkAndRebuild()
target |= FirstRunIndexer::Target::Content; target |= FirstRunIndexer::Target::Content;
m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing); m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing);
} }
startIndexJob(mode, target); startIndexJob(m_config->currentIndexableDir(), m_config->currentBlackListOfIndex(), mode, target);
return target; return target;
} }
void IndexScheduler::startIndexJob(FirstRunIndexer::WorkModes &mode, FirstRunIndexer::Targets &target) void IndexScheduler::startIndexJob(const QStringList& folders,const QStringList& blackList, FirstRunIndexer::WorkMode mode, FirstRunIndexer::Targets target)
{ {
if(FirstRunIndexer::Target::None != target) { if(FirstRunIndexer::Target::None != target) {
FirstRunIndexer *indexer = new FirstRunIndexer(m_config->currentIndexableDir(), m_config->currentBlackListOfIndex(), m_stop, mode, target); FirstRunIndexer *indexer = new FirstRunIndexer(folders, blackList, m_stop, mode, target);
connect(indexer, &FirstRunIndexer::done, this, &IndexScheduler::firstRunFinished, Qt::QueuedConnection); connect(indexer, &FirstRunIndexer::done, this, &IndexScheduler::firstRunFinished, Qt::QueuedConnection);
connect(indexer, &FirstRunIndexer::progress, this, &IndexScheduler::process); connect(indexer, &FirstRunIndexer::progress, this, &IndexScheduler::process);
@ -188,13 +189,25 @@ void IndexScheduler::updateIndex(const QVector<PendingFile> &files)
m_threadPool.start(updateJob); m_threadPool.start(updateJob);
} }
void IndexScheduler::firstRunFinished() void IndexScheduler::firstRunFinished(FirstRunIndexer::WorkMode mode)
{ {
if((m_statusRecorder->getStatus(INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Ready) if((m_statusRecorder->getStatus(INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Ready)
&& m_statusRecorder->getStatus(CONTENT_INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Ready) { && m_statusRecorder->getStatus(CONTENT_INDEX_DATABASE_STATE_KEY).toInt() == IndexStatusRecorder::State::Ready) {
m_isFirstRunFinished = true; switch (mode) {
case FirstRunIndexer::WorkMode::Add:
m_isAddNewPathFinished = true;
break;
case FirstRunIndexer::WorkMode::Rebuild:
m_isRebuildFinished = true;
break;
case FirstRunIndexer::WorkMode::Update:
m_isFirstRunFinished = true;
break;
default:
break;
}
} }
if(m_isFirstRunFinished && m_isAddNewPathFinished && m_isUpdateFinished) { if(isIdle()) {
m_state = Idle; m_state = Idle;
Q_EMIT stateChange(m_state); Q_EMIT stateChange(m_state);
} }
@ -203,18 +216,13 @@ void IndexScheduler::firstRunFinished()
void IndexScheduler::updateFinished() void IndexScheduler::updateFinished()
{ {
m_isUpdateFinished = true; m_isUpdateFinished = true;
if(m_isFirstRunFinished && m_isAddNewPathFinished) { if(isIdle()) {
m_state = Idle; m_state = Idle;
Q_EMIT stateChange(m_state); Q_EMIT stateChange(m_state);
} }
} }
void IndexScheduler::addNewPathFinished() bool IndexScheduler::isIdle()
{ {
m_isAddNewPathFinished = true; return m_isFirstRunFinished && m_isAddNewPathFinished && m_isUpdateFinished && m_isRebuildFinished;
if(m_isFirstRunFinished && m_isUpdateFinished) {
m_state = Idle;
Q_EMIT stateChange(m_state);
}
} }

View File

@ -68,9 +68,9 @@ Q_SIGNALS:
private Q_SLOTS: private Q_SLOTS:
void fileIndexEnable(bool enable); void fileIndexEnable(bool enable);
void updateIndex(const QVector<PendingFile>& files); void updateIndex(const QVector<PendingFile>& files);
void firstRunFinished(); void firstRunFinished(FirstRunIndexer::WorkMode mode);
void updateFinished(); void updateFinished();
void addNewPathFinished(); bool isIdle();
private: private:
/** /**
@ -79,7 +79,7 @@ private:
* @return * @return
*/ */
FirstRunIndexer::Targets checkAndRebuild(); FirstRunIndexer::Targets checkAndRebuild();
void startIndexJob(FirstRunIndexer::WorkModes &mode, FirstRunIndexer::Targets &target); void startIndexJob(const QStringList &folders, const QStringList &blackList, FirstRunIndexer::WorkMode mode, FirstRunIndexer::Targets target);
FileWatcher m_fileWatcher; FileWatcher m_fileWatcher;
IndexStatusRecorder *m_statusRecorder = nullptr; IndexStatusRecorder *m_statusRecorder = nullptr;
FileIndexerConfig *m_config = nullptr; FileIndexerConfig *m_config = nullptr;
@ -88,6 +88,7 @@ private:
QThreadPool m_threadPool; QThreadPool m_threadPool;
bool m_isFirstRunFinished = true; bool m_isFirstRunFinished = true;
bool m_isRebuildFinished = true;
bool m_isUpdateFinished = true; bool m_isUpdateFinished = true;
bool m_isAddNewPathFinished = true; bool m_isAddNewPathFinished = true;
}; };

View File

@ -1,4 +1,24 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#include "monitor.h" #include "monitor.h"
#include <QMetaEnum>
#include "file-indexer-config.h" #include "file-indexer-config.h"
using namespace UkuiSearch; using namespace UkuiSearch;
Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) Monitor::Monitor(IndexScheduler *scheduler, QObject *parent)
@ -7,9 +27,10 @@ Monitor::Monitor(IndexScheduler *scheduler, QObject *parent)
m_basicDatabase(DataBaseType::Basic), m_basicDatabase(DataBaseType::Basic),
m_contentDatabase(DataBaseType::Content) m_contentDatabase(DataBaseType::Content)
{ {
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::indexStateChanged);
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged); connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged);
connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate); connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate);
connect(scheduler, &IndexScheduler::basicIndexDone, this, &Monitor::basicIndexDone);
connect(scheduler, &IndexScheduler::contentIndexDone, this, &Monitor::contentIndexDone);
} }
QStringList Monitor::getCurrentIndexPaths() QStringList Monitor::getCurrentIndexPaths()
@ -17,9 +38,10 @@ QStringList Monitor::getCurrentIndexPaths()
return FileIndexerConfig::getInstance()->currentIndexableDir(); return FileIndexerConfig::getInstance()->currentIndexableDir();
} }
IndexScheduler::IndexerState Monitor::getIndexState() QString Monitor::getIndexState()
{ {
return m_scheduler->getIndexState(); QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
return QString::fromLocal8Bit(metaEnum.valueToKey(m_scheduler->getIndexState()));
} }
uint Monitor::getBasicIndexSize() uint Monitor::getBasicIndexSize()
@ -68,6 +90,8 @@ void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state)
Q_EMIT basicIndexDocNumUpdate(m_basicDatabase.getIndexDocCount()); Q_EMIT basicIndexDocNumUpdate(m_basicDatabase.getIndexDocCount());
Q_EMIT contentIndexDocNumUpdate(m_contentDatabase.getIndexDocCount()); Q_EMIT contentIndexDocNumUpdate(m_contentDatabase.getIndexDocCount());
} }
QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state)));
} }
void Monitor::processUpdate(IndexType type, uint all, uint finished) void Monitor::processUpdate(IndexType type, uint all, uint finished)

View File

@ -1,3 +1,22 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#ifndef MONITOR_H #ifndef MONITOR_H
#define MONITOR_H #define MONITOR_H
@ -14,7 +33,7 @@ class Monitor : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QStringList currentIndexPaths READ getCurrentIndexPaths) Q_PROPERTY(QStringList currentIndexPaths READ getCurrentIndexPaths)
Q_PROPERTY(IndexScheduler::IndexerState indexState READ getIndexState NOTIFY indexStateChanged) Q_PROPERTY(QString indexState READ getIndexState NOTIFY indexStateChanged)
Q_PROPERTY(uint basicIndexSize READ getBasicIndexSize NOTIFY basicIndexSizeChange) Q_PROPERTY(uint basicIndexSize READ getBasicIndexSize NOTIFY basicIndexSizeChange)
Q_PROPERTY(uint contentIndexSize READ getContentIndexSize NOTIFY contentIndexSizeChange) Q_PROPERTY(uint contentIndexSize READ getContentIndexSize NOTIFY contentIndexSizeChange)
Q_PROPERTY(uint ocrIndexSize READ getOCRIndexSize NOTIFY ocrIndexSizeChange) Q_PROPERTY(uint ocrIndexSize READ getOCRIndexSize NOTIFY ocrIndexSizeChange)
@ -26,28 +45,114 @@ class Monitor : public QObject
public: public:
explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr); explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr);
/**
* @brief getCurrentIndexPaths
* @return
*/
QStringList getCurrentIndexPaths(); QStringList getCurrentIndexPaths();
IndexScheduler::IndexerState getIndexState(); /**
* @brief getIndexState
* @return
*/
QString getIndexState();
/**
* @brief getBasicIndexSize
* @return
*/
uint getBasicIndexSize(); uint getBasicIndexSize();
/**
* @brief getContentIndexSize
* @return
*/
uint getContentIndexSize(); uint getContentIndexSize();
/**
* @brief getOCRIndexSize
* @return OCR索引数量
*/
uint getOCRIndexSize(); uint getOCRIndexSize();
/**
* @brief getBasicIndexProgress
* @return
*/
uint getBasicIndexProgress(); uint getBasicIndexProgress();
/**
* @brief getContentIndexProgress
* @return
*/
uint getContentIndexProgress(); uint getContentIndexProgress();
/**
* @brief getOCRIndexProgress
* @return ocr索引进度
*/
uint getOCRIndexProgress(); uint getOCRIndexProgress();
/**
* @brief getBasicIndexDocNum
* @return
*/
uint getBasicIndexDocNum(); uint getBasicIndexDocNum();
/**
* @brief getContentIndexDocNum
* @return
*/
uint getContentIndexDocNum(); uint getContentIndexDocNum();
Q_SIGNALS: Q_SIGNALS:
void indexStateChanged(IndexScheduler::IndexerState); /**
* @brief indexStateChanged
*
*/
void indexStateChanged(QString);
/**
* @brief basicIndexSizeChange
*
*/
void basicIndexSizeChange(uint); void basicIndexSizeChange(uint);
/**
* @brief contentIndexSizeChange
* OCR索引
*/
void contentIndexSizeChange(uint); void contentIndexSizeChange(uint);
/**
* @brief ocrIndexSizeChange
* OCR索引总量
*/
void ocrIndexSizeChange(uint); void ocrIndexSizeChange(uint);
/**
* @brief basicIndexProgressUpdate
*
*/
void basicIndexProgressUpdate(uint); void basicIndexProgressUpdate(uint);
/**
* @brief contentIndexProgressUpdate
* OCR索引
*/
void contentIndexProgressUpdate(uint); void contentIndexProgressUpdate(uint);
/**
* @brief ocrIndexProgressUpdate
* OCR索引进度
*/
void ocrIndexProgressUpdate(uint); void ocrIndexProgressUpdate(uint);
/**
* @brief basicIndexDocNumUpdate
*
*/
void basicIndexDocNumUpdate(uint); void basicIndexDocNumUpdate(uint);
/**
* @brief contentIndexDocNumUpdate
*
*/
void contentIndexDocNumUpdate(uint); void contentIndexDocNumUpdate(uint);
/**
* @brief basicIndexDone
*
*/
void basicIndexDone();
/**
* @brief contentIndexDone
*
*/
void contentIndexDone();
private Q_SLOTS: private Q_SLOTS:
void onIndexStateChanged(IndexScheduler::IndexerState); void onIndexStateChanged(IndexScheduler::IndexerState);

View File

@ -1,3 +1,22 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QTime> #include <QTime>

View File

@ -1,6 +1,137 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Window 2.12 import QtQuick.Layouts 1.12
Window { Rectangle {
height: 180
width: 320
Column {
visible: true
width: parent.width
height: childrenRect.height
StatusKeyValue {
id: basicIndexDocumentNum
keyText: qsTr("Basic index document number")
valueText: "--"
}
StatusKeyValue {
id: contentIndexDocumentNum
keyText: qsTr("Content index document number")
valueText: "--"
}
StatusKeyValue {
id: indexState
keyText: qsTr("Index state")
valueText: "--"
}
IndexProgressBar {
id: basicIndexProgress
width: parent.width;
name: "Basic index progress"
from: 0
visible: false
}
IndexProgressBar {
id: contentIndexProgress
width: parent.width;
name: "Content index progress"
from: 0
visible: false
}
IndexProgressBar {
id: ocrIndexProgress
name: "OCR index progress"
width: parent.width;
from: 0
visible: false
}
Component.onCompleted: {
basicIndexDocumentNum.valueText = monitor.basicIndexDocNum
contentIndexDocumentNum.valueText = monitor.contentIndexDocNum
indexState.valueText = monitor.indexState
monitor.basicIndexDocNumUpdate.connect(onBasicIndexDocNumUpdate);
monitor.contentIndexDocNumUpdate.connect(onContentIndexDocumentNum);
monitor.indexStateChanged.connect(onIndexStateChanged);
monitor.basicIndexSizeChange.connect(onBasicIndexSizeChange);
monitor.basicIndexProgressUpdate.connect(onBasicIndexProgressUpdate);
monitor.contentIndexSizeChange.connect(onContentIndexSizeChange);
monitor.contentIndexProgressUpdate.connect(onContentIndexProgressUpdate);
monitor.ocrIndexSizeChange.connect(onOcrIndexSizeChange);
monitor.onOcrIndexProgressUpdate.connect(onOcrIndexProgressUpdate);
monitor.basicIndexDone.connect(onBasicIndexDone);
monitor.contentIndexDone.connect(onContentIndexDone);
}
function onBasicIndexDocNumUpdate(num) {
var numStr = "%1";
basicIndexDocumentNum.valueText = numStr.arg(num);
}
function onContentIndexDocumentNum(num) {
var numStr = "%1";
contentIndexDocumentNum.valueText = numStr.arg(num);
}
function onIndexStateChanged(state) {
indexState.valueText = state;
}
function onBasicIndexSizeChange(num) {
if(!basicIndexProgress.visible) {
basicIndexProgress.visible = true;
}
basicIndexProgress.to = num;
}
function onBasicIndexProgressUpdate(num) {
basicIndexProgress.value = num;
basicIndexProgress.state = "Running"
}
function onContentIndexSizeChange(num) {
if(!contentIndexProgress.visible) {
contentIndexProgress.visible = true;
}
contentIndexProgress.to = num;
}
function onContentIndexProgressUpdate(num) {
contentIndexProgress.value = num;
contentIndexProgress.state = "Running"
}
function onOcrIndexSizeChange(num) {
if(!ocrIndexProgress.visible) {
ocrIndexProgress.visible = true;
}
ocrIndexProgress.to = num;
}
function onOcrIndexProgressUpdate(num) {
ocrIndexProgress.value = num;
ocrIndexProgress.state = "Running"
}
function onBasicIndexDone() {
basicIndexProgress.state = "Done"
}
function onContentIndexDone() {
contentIndexProgress.state = "Done"
ocrIndexProgress.state = "Done"
}
}
} }

View File

@ -1,8 +1,105 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
Item { Column {
ProgressBar { id: progressBar
width: parent.width
property var from: 0
property var to: 0
property var value: 0
property string name: ""
property string state: ""
Row {
Text {
id: progressName
anchors.left: parent.Left
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "stxihei"
font.pixelSize: 14
color: "black"
text: progressBar.name
}
Text {
id: progressState
anchors.left: parent.Right
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "stxihei"
font.pixelSize: 14
color: "blue"
text: progressBar.state
}
}
Row {
width: parent.width
ProgressBar {
width: parent.width * 2 / 3
height: 16
from: progressBar.from
to: progressBar.to
value: progressBar.value
}
Text {
id: progressNum
anchors.left: parent.Right
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "stxihei"
font.pixelSize: 10
color: "blue"
text: "--/--"
}
}
Component.onCompleted: {
updateProgressNum();
} }
onToChanged: {
updateProgressNum();
}
onValueChanged: {
updateProgressNum();
}
onNameChanged: {
progressName.text = progressBar.name;
}
onStateChanged: {
progressState.text = progressBar.state;
}
function updateProgressNum() {
var str = "%1/%2";
progressNum.text = str.arg(progressBar.value).arg(progressBar.to);
}
} }

View File

@ -0,0 +1,55 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
import QtQuick 2.0
Row {
id: kvRow
width: parent.width
height: childrenRect.height
property string keyText : "--"
property string valueText :"--"
Text {
id: keyTextLabel
anchors.left: parent.Left
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "stxihei"
font.pixelSize: 16
color: "black"
text: kvRow.keyText
}
Text {
id: valueTextLabel
anchors.left: parent.Right
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "stxihei"
font.pixelSize: 16
color: "blue"
text: kvRow.valueText
}
onKeyTextChanged: {
keyTextLabel.text = keyText
}
onValueTextChanged: {
valueTextLabel.text = valueText
}
}

View File

@ -4,5 +4,6 @@ RESOURCES += qmlFile
DISTFILES += \ DISTFILES += \
$$PWD/IndexMonitor.qml \ $$PWD/IndexMonitor.qml \
$$PWD/IndexProgressBar.qml $$PWD/IndexProgressBar.qml \
$$PWD/StatusKeyValue.qml

View File

@ -1,3 +1,22 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#include <QDebug> #include <QDebug>
#include <QDBusConnection> #include <QDBusConnection>
#include <QQmlContext> #include <QQmlContext>
@ -91,8 +110,12 @@ void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
void UkuiSearchService::loadMonitorWindow() void UkuiSearchService::loadMonitorWindow()
{ {
if(!m_monitor) {
m_monitor = new Monitor(m_indexScheduler, this);
}
if(!m_quickView) { if(!m_quickView) {
m_quickView = new QQuickView(); m_quickView = new QQuickView();
m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
m_quickView->rootContext()->setContextProperty("monitor", m_monitor); m_quickView->rootContext()->setContextProperty("monitor", m_monitor);
m_quickView->setSource(m_qmlPath); m_quickView->setSource(m_qmlPath);
} }

View File

@ -27,7 +27,7 @@ private:
IndexScheduler *m_indexScheduler = nullptr; IndexScheduler *m_indexScheduler = nullptr;
Monitor *m_monitor = nullptr; Monitor *m_monitor = nullptr;
QQuickView *m_quickView = nullptr; QQuickView *m_quickView = nullptr;
QString m_qmlPath = "qrc:/qml/IndexMonitor.qml"; QUrl m_qmlPath = QString("qrc:/qml/IndexMonitor.qml");
}; };
} }