ukui-notification/notification-server/notification-server-applica...

55 lines
1.5 KiB
C++

//
// Created by zpf on 23-2-1.
//
#include <QCommandLineParser>
#include <QDebug>
#include "notification-server-application.h"
#include "notification-server-config.h"
#include "server.h"
using namespace NotificationServer;
NotificationServerApplication::NotificationServerApplication(int &argc, char **argv, const QString &applicationName)
: QtSingleCoreApplication(applicationName, argc, argv)
{
setApplicationVersion(NOTIFICATION_SERVER_VERSION);
qApp->setProperty("IS_UKUI_NOTIFICATION_SERVICE", true);
if (!this->isRunning()) {
connect(this, &QtSingleCoreApplication::messageReceived, [=](QString msg) {
this->parseCmd(msg, true);
});
Server::self().init();
}
parseCmd(this->arguments().join(" ").toUtf8(), !isRunning());
}
NotificationServerApplication::~NotificationServerApplication()
{
}
void NotificationServerApplication::parseCmd(QString msg, bool isPrimary)
{
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption quitOption(QStringList()<<"q"<<"quit", tr("Quit notification server"));
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);
}
}