Files

133 lines
3.9 KiB
C++
Raw Permalink Normal View History

2020-07-30 17:59:34 +08:00
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 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
* 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 <http://www.gnu.org/licenses/>.
*/
2020-03-11 23:13:24 -07:00
#include <stdio.h>
2020-03-04 09:49:45 +08:00
#include <libmate-desktop/mate-gsettings.h>
2020-03-03 11:21:34 +08:00
2020-03-09 15:04:02 +08:00
#include "clib-syslog.h"
2020-03-12 00:39:22 -07:00
#include "plugin-manager.h"
#include "manager-interface.h"
2020-03-03 11:21:34 +08:00
2020-03-11 23:13:24 -07:00
#include <QDebug>
2020-03-15 19:51:57 -07:00
#include <QObject>
2020-03-12 00:39:22 -07:00
#include <QDBusReply>
2020-03-04 11:45:10 +08:00
#include <QApplication>
2020-03-12 00:39:22 -07:00
#include <QDBusConnectionInterface>
2020-03-05 16:31:24 +08:00
2021-03-25 11:29:15 +08:00
#include <sys/types.h>
#include <signal.h>
2020-03-12 20:22:45 -07:00
static void print_help ();
2020-03-11 23:13:24 -07:00
static void parse_args (int argc, char *argv[]);
2020-03-12 00:39:22 -07:00
static void stop_daemon ();
2020-03-04 11:03:01 +08:00
2020-03-11 23:13:24 -07:00
static bool no_daemon = true;
static bool replace = false;
2020-03-04 11:03:01 +08:00
2021-03-25 11:29:15 +08:00
void handler(int no)
{
qDebug()<<"catch SIGTERM signal, with exitcode "<< no;
exit(15);
}
2020-03-04 11:03:01 +08:00
int main (int argc, char* argv[])
2020-03-03 11:21:34 +08:00
{
2020-11-28 17:03:27 +08:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
2020-03-04 11:03:01 +08:00
2021-03-25 11:29:15 +08:00
PluginManager* manager = nullptr;
2020-08-21 15:35:48 +08:00
qDebug( "ukui-settings-daemon starting ...");
2020-03-04 11:10:23 +08:00
QApplication app(argc, argv);
2021-03-25 11:29:15 +08:00
signal(SIGTERM, handler);
QApplication::setQuitOnLastWindowClosed(false);
2020-08-21 15:35:48 +08:00
QTranslator translator;
translator.load("/usr/share/ukui-settings-daemon/daemon/res/i18n/zh_CN.qm");
app.installTranslator(&translator);
2020-03-11 23:13:24 -07:00
parse_args (argc, argv);
2020-03-12 18:21:03 -07:00
2020-03-12 00:39:22 -07:00
if (replace) stop_daemon ();
2020-03-09 15:04:02 +08:00
manager = PluginManager::getInstance();
2021-03-25 11:29:15 +08:00
if (!manager) {
return 0;
2020-03-04 11:03:01 +08:00
}
2021-03-25 11:29:15 +08:00
bool res = manager->managerStart();
if (!res) {
2020-08-21 15:35:48 +08:00
qDebug( "manager start error!");
2021-03-25 11:29:15 +08:00
return 0;
2020-03-04 11:03:01 +08:00
}
2020-03-19 19:57:08 -07:00
CT_SYSLOG(LOG_INFO, "ukui-settings-daemon started!");
2020-03-15 19:51:57 -07:00
app.exec();
2020-03-04 11:03:01 +08:00
2021-03-25 11:29:15 +08:00
if (manager)
delete manager;
2020-03-15 19:51:57 -07:00
return 0;
2020-03-03 11:21:34 +08:00
}
2020-03-04 11:03:01 +08:00
2020-03-11 23:13:24 -07:00
static void parse_args (int argc, char *argv[])
2020-03-04 11:03:01 +08:00
{
2020-03-11 23:13:24 -07:00
if (argc == 1) return;
2020-03-04 11:03:01 +08:00
2020-03-11 23:13:24 -07:00
for (int i = 1; i < argc; ++i) {
if (0 == QString::compare(QString(argv[i]).trimmed(), QString("--replace"))) {
replace = true;
} else if (0 == QString::compare(QString(argv[i]).trimmed(), QString("--daemon"))) {
no_daemon = false;
2020-03-04 11:03:01 +08:00
} else {
2020-03-11 23:13:24 -07:00
if (argc > 1) {
print_help();
CT_SYSLOG(LOG_DEBUG, " Unsupported command line arguments: '%s'", argv[i]);
2020-03-16 01:09:31 -07:00
exit(0);
2020-03-04 14:43:15 +08:00
}
2020-03-04 11:03:01 +08:00
}
}
}
2020-03-11 23:13:24 -07:00
static void print_help()
2020-03-04 11:03:01 +08:00
{
2020-03-12 20:22:45 -07:00
fprintf(stdout, "%s\n%s\n%s\n%s\n\n", \
2020-03-11 23:13:24 -07:00
"Useage: ukui-setting-daemon <option> [...]", \
"options:",\
" --replace Replace the current daemon", \
2020-03-12 20:22:45 -07:00
" --daemon Become a daemon(not support now)");
2020-03-04 11:03:01 +08:00
}
2020-03-12 00:39:22 -07:00
static void stop_daemon ()
{
QString ukuiDaemonBusName = UKUI_SETTINGS_DAEMON_DBUS_NAME;
QString ukuiDaemonBusPath = UKUI_SETTINGS_DAEMON_DBUS_PATH;
bool isStarting = QDBusConnection::sessionBus().interface()->isServiceRegistered(ukuiDaemonBusName);
if (isStarting) {
// close current
PluginManagerDBus pmd(ukuiDaemonBusName, ukuiDaemonBusPath, QDBusConnection::sessionBus());
QDBusPendingReply<> reply = pmd.managerStop();
reply.waitForFinished();
if (reply.isValid()) {
CT_SYSLOG(LOG_DEBUG, "stop current 'ukui-settings-daemon'");
}
}
}