2022-06-13 13:38:47 +08:00
|
|
|
#include "ukui-search-app-data-service.h"
|
|
|
|
#include "app-db-manager.h"
|
2022-06-28 11:20:36 +08:00
|
|
|
#include "signal-transformer.h"
|
2022-07-04 17:38:59 +08:00
|
|
|
#include "app-info-dbus-argument.h"
|
2022-06-28 11:20:36 +08:00
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMetaType>
|
|
|
|
#include <QDBusError>
|
|
|
|
#include <QDebug>
|
2022-06-13 13:38:47 +08:00
|
|
|
|
|
|
|
using namespace UkuiSearch;
|
2022-06-23 10:21:22 +08:00
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], const QString &applicationName):
|
|
|
|
QtSingleApplication (applicationName, argc, argv)
|
|
|
|
{
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "ukui search app data service constructor start";
|
2022-06-13 13:38:47 +08:00
|
|
|
setApplicationVersion(QString("v%1").arg(VERSION));
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if (!this->isRunning()) {
|
2022-06-28 11:20:36 +08:00
|
|
|
qDebug() << "First running, I'm in app-db manager dbus rigister.";
|
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
qRegisterMetaType<PropertyMap>("PropertyMap");
|
|
|
|
qDBusRegisterMetaType<PropertyMap>();
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2023-03-10 17:47:04 +08:00
|
|
|
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
|
|
|
|
qDBusRegisterMetaType<ApplicationInfoMap>();
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2022-06-23 10:21:22 +08:00
|
|
|
AppDBManager::getInstance();
|
|
|
|
|
2022-06-28 11:20:36 +08:00
|
|
|
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
|
|
|
if (!sessionBus.registerService("com.ukui.search.appdb.service")) {
|
|
|
|
qCritical() << "QDbus register service failed reason:" << sessionBus.lastError();
|
|
|
|
}
|
2022-07-12 11:26:03 +08:00
|
|
|
|
|
|
|
if(!sessionBus.registerObject("/org/ukui/search/appDataBase/dbManager", AppDBManager::getInstance(), QDBusConnection::ExportAllSlots)) {
|
|
|
|
qCritical() << "ukui-search-app-db-manager dbus register object failed reason:" << sessionBus.lastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!sessionBus.registerObject("/org/ukui/search/appDataBase/signalTransformer", SignalTransformer::getTransformer(), QDBusConnection::ExportAllSignals)) {
|
|
|
|
qCritical() << "ukui-search-signal-transformer dbus register object failed reason:" << sessionBus.lastError();
|
2022-06-28 11:20:36 +08:00
|
|
|
}
|
|
|
|
|
2022-06-23 10:21:22 +08:00
|
|
|
connect(this, &QtSingleApplication::messageReceived, [ & ](QString msg) {
|
2022-06-13 13:38:47 +08:00
|
|
|
this->parseCmd(msg, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//parse cmd
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "parse cmd";
|
2022-06-13 13:38:47 +08:00
|
|
|
auto message = this->arguments().join(' ').toUtf8();
|
|
|
|
parseCmd(message, !isRunning());
|
2022-06-23 10:21:22 +08:00
|
|
|
qDebug() << "ukui search app data service constructor end";
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void UkuiSearchAppDataService::parseCmd(QString msg, bool isPrimary)
|
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
|
|
|
QCommandLineOption quitOption(QStringList()<<"q"<<"quit", tr("Stop service"));
|
|
|
|
parser.addOption(quitOption);
|
|
|
|
|
|
|
|
if (isPrimary) {
|
|
|
|
const QStringList args = QString(msg).split(' ');
|
|
|
|
parser.process(args);
|
|
|
|
|
|
|
|
if (parser.isSet(quitOption)) {
|
|
|
|
qApp->quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (arguments().count() < 2) {
|
|
|
|
parser.showHelp();
|
|
|
|
}
|
|
|
|
parser.process(arguments());
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|