2020-12-09 10:09:29 +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/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-08-27 01:09:22 +08:00
|
|
|
#include <QApplication>
|
2020-09-01 13:36:55 +08:00
|
|
|
#include <QGuiApplication>
|
2020-08-27 12:56:55 +08:00
|
|
|
#include <SingleApplication>
|
2020-09-15 15:55:49 +08:00
|
|
|
#include <QTranslator>
|
|
|
|
|
#include <QLocale>
|
2020-08-27 01:09:22 +08:00
|
|
|
|
2020-09-12 15:38:33 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
2020-08-31 18:32:45 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
2020-09-01 13:36:55 +08:00
|
|
|
|
2021-07-23 16:42:17 +08:00
|
|
|
static int getScreenWidth(void) {
|
2020-09-01 13:36:55 +08:00
|
|
|
Display *display;
|
|
|
|
|
Screen *screen;
|
|
|
|
|
int width = 0;
|
|
|
|
|
|
|
|
|
|
display = XOpenDisplay(NULL);
|
|
|
|
|
if (!display)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
screen = DefaultScreenOfDisplay(display);
|
|
|
|
|
if (!screen)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
width = screen->width;
|
|
|
|
|
out:
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
|
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 18:32:45 +08:00
|
|
|
#endif
|
|
|
|
|
|
2021-07-23 16:42:17 +08:00
|
|
|
void LoadTranlateFile(SingleApplication *app) {
|
2020-09-15 15:55:49 +08:00
|
|
|
QTranslator *translator = new QTranslator;
|
|
|
|
|
|
|
|
|
|
QLocale locale = QLocale::system();
|
|
|
|
|
if (locale.language() == QLocale::Chinese) {
|
2020-09-24 15:42:07 +08:00
|
|
|
if (!translator->load(QString(QM_FILES_INSTALL_PATH)+"/Pastes_zh_CN.qm"))
|
|
|
|
|
translator->load("Pastes_zh_CN.qm");
|
2020-09-15 15:55:49 +08:00
|
|
|
app->installTranslator(translator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 16:42:17 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2020-09-01 13:36:55 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
if (getScreenWidth() > 2560) {
|
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-09-17 00:27:02 +08:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2020-09-01 13:36:55 +08:00
|
|
|
|
2020-08-27 12:56:55 +08:00
|
|
|
SingleApplication a(argc, argv);
|
2020-09-20 19:57:05 +08:00
|
|
|
LoadTranlateFile(&a);
|
2020-08-27 01:09:22 +08:00
|
|
|
|
2020-08-27 09:12:45 +08:00
|
|
|
MainWindow w;
|
2020-08-27 12:56:55 +08:00
|
|
|
QObject::connect(&a, &SingleApplication::instanceStarted, [&w](void) {
|
|
|
|
|
w.hide();
|
|
|
|
|
});
|
2020-08-27 01:09:22 +08:00
|
|
|
|
2020-08-30 17:12:27 +08:00
|
|
|
a.setQuitOnLastWindowClosed(false);
|
2020-08-27 01:09:22 +08:00
|
|
|
return a.exec();
|
|
|
|
|
}
|