2022-06-18 10:46:14 +08:00
|
|
|
#include <QDebug>
|
2022-10-26 18:01:40 +08:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QQmlContext>
|
2022-06-18 10:46:14 +08:00
|
|
|
#include "ukui-search-service.h"
|
|
|
|
#include "dir-watcher.h"
|
2022-10-26 18:01:40 +08:00
|
|
|
#include "file-utils.h"
|
|
|
|
#include "file-indexer-config.h"
|
2022-10-21 11:21:35 +08:00
|
|
|
|
2022-06-18 10:46:14 +08:00
|
|
|
using namespace UkuiSearch;
|
2022-10-26 18:01:40 +08:00
|
|
|
UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &applicationName)
|
|
|
|
: QtSingleApplication (applicationName, argc, argv)
|
2022-06-18 10:46:14 +08:00
|
|
|
{
|
|
|
|
qDebug()<<"ukui search service constructor start";
|
|
|
|
setApplicationVersion(QString("v%1").arg(VERSION));
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if (!this->isRunning()) {
|
|
|
|
connect(this, &QtSingleApplication::messageReceived, [=](QString msg) {
|
|
|
|
this->parseCmd(msg, true);
|
|
|
|
});
|
2022-10-26 18:01:40 +08:00
|
|
|
qRegisterMetaType<IndexType>("IndexType");
|
|
|
|
m_indexScheduler = new IndexScheduler(this);
|
|
|
|
DirWatcher::getDirWatcher()->initDbusService();
|
2022-06-18 10:46:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//parse cmd
|
|
|
|
qDebug()<<"parse cmd";
|
|
|
|
auto message = this->arguments().join(' ').toUtf8();
|
|
|
|
parseCmd(message, !isRunning());
|
|
|
|
|
|
|
|
qDebug()<<"ukui search service constructor end";
|
|
|
|
}
|
|
|
|
|
2022-10-26 18:01:40 +08:00
|
|
|
UkuiSearchService::~UkuiSearchService()
|
|
|
|
{
|
|
|
|
if(m_quickView) {
|
|
|
|
delete m_quickView;
|
|
|
|
m_quickView = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 10:46:14 +08:00
|
|
|
void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
|
|
|
QCommandLineOption quitOption(QStringList()<<"q"<<"quit", tr("Stop service"));
|
|
|
|
parser.addOption(quitOption);
|
|
|
|
|
|
|
|
QCommandLineOption startOption(QStringList()<<"i"<<"index", tr("start or stop file index"), "option");
|
|
|
|
parser.addOption(startOption);
|
|
|
|
|
2022-10-26 18:01:40 +08:00
|
|
|
QCommandLineOption monitorWindow(QStringList()<<"m"<<"monitor", tr("Show index monitor window"));
|
|
|
|
parser.addOption(monitorWindow);
|
|
|
|
|
2022-06-18 10:46:14 +08:00
|
|
|
// QCommandLineOption statusOption(QStringList()<<"s"<<"status", tr("show status of file index service"));
|
|
|
|
// parser.addOption(statusOption);
|
|
|
|
|
|
|
|
if (isPrimary) {
|
|
|
|
const QStringList args = QString(msg).split(' ');
|
|
|
|
parser.process(args);
|
|
|
|
if(parser.isSet(startOption)) {
|
|
|
|
qDebug() << "options!!!!" << parser.value(startOption);
|
|
|
|
if(parser.value(startOption) == "start") {
|
2022-10-26 18:01:40 +08:00
|
|
|
m_indexScheduler->scheduleIndexing();
|
2022-06-18 10:46:14 +08:00
|
|
|
} else if (parser.value(startOption) == "stop") {
|
2022-10-26 18:01:40 +08:00
|
|
|
m_indexScheduler->stop();
|
2022-06-18 10:46:14 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-26 18:01:40 +08:00
|
|
|
|
|
|
|
if (parser.isSet(monitorWindow)) {
|
|
|
|
loadMonitorWindow();
|
|
|
|
m_quickView->show();
|
|
|
|
return;
|
|
|
|
}
|
2022-06-18 10:46:14 +08:00
|
|
|
if (parser.isSet(quitOption)) {
|
|
|
|
qApp->quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (arguments().count() < 2) {
|
|
|
|
parser.showHelp();
|
|
|
|
}
|
|
|
|
parser.process(arguments());
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 18:01:40 +08:00
|
|
|
void UkuiSearchService::loadMonitorWindow()
|
2022-06-18 10:46:14 +08:00
|
|
|
{
|
2022-10-26 18:01:40 +08:00
|
|
|
if(!m_quickView) {
|
|
|
|
m_quickView = new QQuickView();
|
|
|
|
m_quickView->rootContext()->setContextProperty("monitor", m_monitor);
|
|
|
|
m_quickView->setSource(m_qmlPath);
|
2022-06-18 10:46:14 +08:00
|
|
|
}
|
|
|
|
}
|