Files
ukui-menu/main.cpp
T
2020-05-06 21:31:03 +08:00

90 lines
2.7 KiB
C++

/*
* 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;.
*
*/
#include "src/MainWindow/mainwindow.h"
#include <QtSingleApplication>
#include <QDesktopWidget>
#include <QFile>
#include <QScreen>
#include <QTranslator>
#include <QLocale>
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QtSingleApplication app("ukui-start-menu",argc,argv);
app.setQuitOnLastWindowClosed(false);
if(app.isRunning())
{
app.sendMessage("raise_window_noop");
return EXIT_SUCCESS;
}
QString locale = QLocale::system().name();
QTranslator translator;
if (locale == "zh_CN"){
if (translator.load(":/ukui_menu_ch.qm"))
app.installTranslator(&translator);
else
qDebug() << "Load translations file" << locale << "failed!";
}
MainWindow w;
int position=0;
int panelSize=0;
if(QGSettings::isSchemaInstalled(QString("org.ukui.panel.settings").toLocal8Bit()))
{
QGSettings* gsetting=new QGSettings(QString("org.ukui.panel.settings").toLocal8Bit());
if(gsetting->keys().contains(QString("panelposition")))
position=gsetting->get("panelposition").toInt();
else
position=0;
if(gsetting->keys().contains(QString("panelsize")))
panelSize=gsetting->get("panelsize").toInt();
else
panelSize=46;
}
else
{
position=0;
panelSize=46;
}
int x=QApplication::primaryScreen()->geometry().x();
int y=QApplication::primaryScreen()->geometry().y();
if(position==0)
w.setGeometry(QRect(x,Style::heightavailable-590,376,590));
else if(position==1)
w.setGeometry(QRect(x,panelSize,376,590));
else if(position==2)
w.setGeometry(QRect(panelSize,y,376,590));
else
w.setGeometry(QRect(Style::widthavailable-376,y,376,590));
app.setActivationWindow(&w);
//注释掉,以保证自启动时不显示界面
w.show();
w.raise();
w.activateWindow();
w.hide();
return app.exec();
}