2020-02-02 20:13:31 +08:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2019 Tianjin KYLIN Information Technology 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 2 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, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2019-07-05 12:03:56 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
2020-10-22 16:44:46 +08:00
|
|
|
#include <QApplication>
|
2020-06-30 09:07:40 +08:00
|
|
|
#include <QtSingleApplication>
|
2019-07-05 12:03:56 +08:00
|
|
|
#include <QTranslator>
|
2020-03-06 21:33:01 +08:00
|
|
|
#include <QObject>
|
2020-01-17 10:20:22 +08:00
|
|
|
#include <QDebug>
|
2020-06-30 09:07:40 +08:00
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <memory>
|
2020-10-22 16:44:46 +08:00
|
|
|
#include <QCommandLineParser>
|
2021-02-21 11:15:05 +08:00
|
|
|
#include <QQuickWidget>
|
2021-03-09 16:47:00 +08:00
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QTime>
|
2021-05-21 14:43:26 +08:00
|
|
|
#include <KWindowEffects>
|
2020-03-25 21:28:26 +08:00
|
|
|
|
2020-10-24 14:19:42 +08:00
|
|
|
#include <stdlib.h>
|
2021-09-02 14:43:14 +08:00
|
|
|
#include <signal.h>
|
2020-10-24 14:19:42 +08:00
|
|
|
|
2021-04-13 11:41:23 +08:00
|
|
|
#ifdef KYDEBUG
|
|
|
|
|
#include <ukui-log4qt.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-10-22 16:44:46 +08:00
|
|
|
#include "framelessExtended/framelesshandle.h"
|
|
|
|
|
#include "customstyle.h"
|
|
|
|
|
#include "utils/utils.h"
|
2020-11-18 15:52:46 +08:00
|
|
|
#include "utils/xatom-helper.h"
|
2020-03-25 21:28:26 +08:00
|
|
|
|
2021-02-21 11:15:05 +08:00
|
|
|
const QString KLong = "Loongson";
|
|
|
|
|
|
2021-09-02 14:43:14 +08:00
|
|
|
MainWindow *mainWindow = nullptr;
|
|
|
|
|
|
|
|
|
|
void sigExit(int signalNum)
|
|
|
|
|
{
|
|
|
|
|
if (mainWindow != nullptr) {
|
|
|
|
|
mainWindow->close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 12:03:56 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2021-09-02 14:43:14 +08:00
|
|
|
signal(SIGINT,sigExit);
|
2021-04-13 11:41:23 +08:00
|
|
|
#ifdef KYDEBUG
|
2021-05-06 20:20:00 +08:00
|
|
|
#ifndef __sw_64__
|
2021-04-13 11:41:23 +08:00
|
|
|
initUkuiLog4qt("ukui-control-center");
|
2021-05-06 20:20:00 +08:00
|
|
|
#endif
|
2021-04-13 11:41:23 +08:00
|
|
|
#endif
|
2020-08-18 09:03:28 +08:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2020-10-24 14:19:42 +08:00
|
|
|
|
2021-02-21 11:15:05 +08:00
|
|
|
if (Utils::getCpuInfo().startsWith(KLong, Qt::CaseInsensitive)) {
|
|
|
|
|
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 15:19:02 +08:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-10-26 14:50:01 +08:00
|
|
|
QString id = QString("ukui-control-center" + QLatin1String(getenv("DISPLAY")));
|
2020-10-24 14:19:42 +08:00
|
|
|
QtSingleApplication a(id, argc, argv);
|
2020-07-18 11:55:37 +08:00
|
|
|
|
2020-07-23 15:30:33 +08:00
|
|
|
if (a.isRunning()) {
|
2020-04-02 16:32:34 +08:00
|
|
|
a.sendMessage(QApplication::arguments().length() > 1 ? QApplication::arguments().at(1) : a.applicationFilePath());
|
2020-07-23 15:30:33 +08:00
|
|
|
qDebug() << QObject::tr("ukui-control-center is already running!");
|
2020-03-06 21:33:01 +08:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
} else {
|
2020-08-18 09:03:28 +08:00
|
|
|
// 加载国际化文件
|
2020-03-06 21:33:01 +08:00
|
|
|
QTranslator translator;
|
2020-11-30 19:26:40 +08:00
|
|
|
translator.load("/usr/share/ukui-control-center/shell/res/i18n/" + QLocale::system().name());
|
2020-08-04 09:13:56 +08:00
|
|
|
a.installTranslator(&translator);
|
2020-03-06 21:33:01 +08:00
|
|
|
|
2020-10-22 16:44:46 +08:00
|
|
|
// 命令行参数
|
2021-01-28 11:04:41 +08:00
|
|
|
QCoreApplication::setApplicationName(QObject::tr("ukui-control-center"));
|
2020-03-30 21:37:16 +08:00
|
|
|
QCoreApplication::setApplicationVersion("2.0");
|
2020-04-17 14:00:44 +08:00
|
|
|
|
2020-10-22 16:44:46 +08:00
|
|
|
QCommandLineParser parser;
|
|
|
|
|
Utils::setCLIName(parser);
|
2020-10-30 16:59:30 +08:00
|
|
|
parser.process(a);
|
2020-10-22 16:44:46 +08:00
|
|
|
|
2020-11-18 15:52:46 +08:00
|
|
|
MainWindow w;
|
2021-09-02 14:43:14 +08:00
|
|
|
mainWindow = &w;
|
2020-11-18 15:52:46 +08:00
|
|
|
Utils::centerToScreen(&w);
|
2020-03-06 21:33:01 +08:00
|
|
|
|
2021-05-29 10:29:45 +08:00
|
|
|
w.setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
KWindowEffects::enableBlurBehind(w.winId(),true);
|
2021-05-21 14:43:26 +08:00
|
|
|
|
2020-11-18 15:52:46 +08:00
|
|
|
MotifWmHints hints;
|
|
|
|
|
hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
|
|
|
|
|
hints.functions = MWM_FUNC_ALL;
|
|
|
|
|
hints.decorations = MWM_DECOR_BORDER;
|
|
|
|
|
XAtomHelper::getInstance()->setWindowMotifHint(w.winId(), hints);
|
2020-03-06 21:33:01 +08:00
|
|
|
|
2020-11-18 15:52:46 +08:00
|
|
|
a.setActivationWindow(&w);
|
|
|
|
|
QObject::connect(&a, SIGNAL(messageReceived(const QString&)), &w, SLOT(sltMessageReceived(const QString&)));
|
|
|
|
|
w.show();
|
|
|
|
|
|
2020-03-06 21:33:01 +08:00
|
|
|
return a.exec();
|
2020-02-29 15:03:54 +08:00
|
|
|
}
|
2019-07-05 12:03:56 +08:00
|
|
|
}
|
2020-03-25 21:28:26 +08:00
|
|
|
|