Files
ukui-menu/main.cpp
T

110 lines
4.1 KiB
C++
Raw Permalink Normal View History

2020-01-07 20:24:03 +08:00
/*
* 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 3, 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, see <http://www.gnu.org/licenses/&gt;.
*
*/
2022-01-17 10:26:57 +08:00
#include "mainwindow.h"
#include "tabletwindow.h"
#include <QtSingleApplication>
2019-08-24 15:56:39 +08:00
#include <QDesktopWidget>
#include <QFile>
2020-01-16 09:24:34 +08:00
#include <QScreen>
2020-01-19 14:18:35 +08:00
#include <QTranslator>
#include <QLocale>
2020-07-25 17:22:16 +08:00
#include <X11/Xlib.h>
#include <syslog.h>
2022-01-17 10:26:57 +08:00
#include "utility.h"
#include "file-utils.h"
#include <ukuisdk/kylin-com4c.h>
#include <ukuisdk/kylin-com4cxx.h>
#define UKUI_SERVICE "org.gnome.SessionManager"
#define UKUI_PATH "/org/gnome/SessionManager"
#define UKUI_INTERFACE "org.gnome.SessionManager"
2020-07-25 17:22:16 +08:00
#include <ukui-log4qt.h>
2019-08-24 15:56:39 +08:00
int main(int argc, char *argv[])
{
2021-11-19 09:14:55 +08:00
initUkuiLog4qt("ukui-menu");
g_projectCodeName = KDKGetPrjCodeName().c_str();
g_subProjectCodeName = KDKGetOSRelease("SUB_PROJECT_CODENAME").c_str();
2020-05-25 21:49:27 +08:00
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");
2021-04-22 10:07:14 +08:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
2021-11-05 16:04:57 +08:00
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
2021-04-22 10:07:14 +08:00
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
QtSingleApplication app("ukui-menu", argc, argv);
2019-10-28 18:52:43 +08:00
app.setQuitOnLastWindowClosed(false);
2019-12-28 17:39:55 +08:00
2021-11-05 16:04:57 +08:00
if (app.isRunning()) {
app.sendMessage("raise_window_noop");
return EXIT_SUCCESS;
}
2019-08-24 15:56:39 +08:00
2020-01-19 14:18:35 +08:00
QTranslator translator;
2021-11-05 16:04:57 +08:00
if (translator.load(QLocale(), "ukui-menu", "_", QM_FILES_INSTALL_PATH)) {
app.installTranslator(&translator);
} else {
myDebug() << "Load translations file" << QLocale() << "failed!";
}
2022-03-11 13:47:02 +08:00
if (!g_projectCodeName.contains("V10SP1-edu")) {
FileUtils::loadHanziTable(":/src/BackProcess/Search/pinyinWithoutTone.txt");
MainWindow w;
app.setActivationWindow(&w);
2020-11-18 11:34:24 +08:00
if (Style::m_panelPosition == 0) {
w.setGeometry(QRect(Style::m_primaryScreenX + 4, Style::m_primaryScreenY + Style::m_availableScreenHeight - Style::minh - 3,
2021-11-05 16:04:57 +08:00
Style::minw, Style::minh));
} else if (Style::m_panelPosition == 1) {
w.setGeometry(QRect(Style::m_primaryScreenX + 4, Style::m_primaryScreenY + 4, Style::minw, Style::minh));
} else if (Style::m_panelPosition == 2) {
w.setGeometry(QRect(Style::m_primaryScreenX + 4, Style::m_primaryScreenY + 4, Style::minw, Style::minh));
2021-11-05 16:04:57 +08:00
} else {
w.setGeometry(QRect(Style::m_primaryScreenX + Style::m_availableScreenWidth - Style::minw - 4, Style::m_primaryScreenY + 4,
2021-11-05 16:04:57 +08:00
Style::minw, Style::minh));
}
w.show();
w.raise();
w.update();
w.activateWindow();
w.hide();
return app.exec();
2021-11-05 16:04:57 +08:00
} else {
TabletWindow w;
2021-11-05 16:04:57 +08:00
app.setActivationWindow(&w);
centerToScreen(&w);
2021-11-05 16:04:57 +08:00
w.setAttribute(Qt::WA_TranslucentBackground, true);
w.setAttribute(Qt::WA_X11NetWmWindowTypeDesktop, false);
w.setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
w.raise();
w.activateWindow();
//拉起后通知session
QDBusInterface interface(UKUI_SERVICE,
2021-11-05 16:04:57 +08:00
UKUI_PATH,
UKUI_INTERFACE,
QDBusConnection::sessionBus());
interface.call("startupfinished", "ukui-menu", "finish");
return app.exec();
}
2019-08-24 15:56:39 +08:00
}