117 lines
3.3 KiB
C++
117 lines
3.3 KiB
C++
#include "main_window.h"
|
|
#include <QtWidgets/QApplication>
|
|
#include <QtCore/QTranslator>
|
|
#include <QtCore/QDebug>
|
|
#include <QtCore/QDir>
|
|
#include <QtCore/QStringList>
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
# include <QtCore/QTextCodec>
|
|
#endif
|
|
|
|
#include "config.h"
|
|
#include "logger.h"
|
|
|
|
//==============================================================================
|
|
void configureApplication()
|
|
{
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
|
#endif
|
|
|
|
#if defined (PROG_NAME)
|
|
QApplication::setApplicationName( QString(PROG_NAME) );
|
|
#endif
|
|
|
|
#if defined (SOFT_DEVELOPER)
|
|
QApplication::setOrganizationName( QString(SOFT_DEVELOPER) );
|
|
#endif
|
|
|
|
#if defined (DEVELOPER_DOMAIN)
|
|
QApplication::setOrganizationDomain( QString(DEVELOPER_DOMAIN) );
|
|
#endif
|
|
|
|
#if defined (PROG_VERSION)
|
|
QApplication::setApplicationVersion( QString(PROG_VERSION) );
|
|
#endif
|
|
|
|
#if defined (BUILD_DATE)
|
|
qApp->setProperty( "buildDate", QString(BUILD_DATE) );
|
|
#endif
|
|
}
|
|
//==============================================================================
|
|
QString applicationRootPath()
|
|
{
|
|
QString path { QApplication::applicationDirPath() };
|
|
|
|
if ( path.right(1) != "/" ) {
|
|
|
|
path += "/";
|
|
}
|
|
|
|
if (path.right(5) == "/bin/") {
|
|
|
|
path.remove( path.length() - 4, 4 );
|
|
}
|
|
|
|
return path;
|
|
}
|
|
//==============================================================================
|
|
void installTranslations(const QString &lng = "ru")
|
|
{
|
|
const QString dirName { applicationRootPath() + "translations/" };
|
|
QDir translationsDir { dirName };
|
|
|
|
QStringList filesList = translationsDir.entryList(
|
|
QStringList() << QString("*_%1.qm").arg(lng),
|
|
QDir::Files
|
|
);
|
|
|
|
for (const QString &fileName: std::as_const(filesList)) {
|
|
|
|
QTranslator *translator = new QTranslator(QCoreApplication::instance());
|
|
|
|
if (translator->load( dirName + fileName )) {
|
|
|
|
QCoreApplication::instance()->installTranslator( translator );
|
|
}
|
|
else {
|
|
|
|
delete translator;
|
|
}
|
|
}
|
|
}
|
|
//==============================================================================
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication a(argc, argv);
|
|
|
|
// Предварительная настройка приложения:
|
|
configureApplication();
|
|
// Установка файлов переводов:
|
|
installTranslations();
|
|
|
|
MainWindow w;
|
|
// Запускаем логгер:
|
|
Logger::instance().start();
|
|
|
|
qInfo() << "Запуск приложения:" << QApplication::applicationName();
|
|
qInfo() << "Разработчик:" << QApplication::organizationName();
|
|
qInfo() << "Организация:" << QApplication::organizationDomain();
|
|
qInfo() << "Версия:" << QApplication::applicationVersion();
|
|
qInfo() << "Дата сборки:" << QString(
|
|
a.property("buildDate").isNull()
|
|
? "unknown"
|
|
: a.property("buildDate").toString()
|
|
);
|
|
qDebug() << "Запуск главного окна приложения";
|
|
|
|
w.show();
|
|
a.setQuitOnLastWindowClosed(true);
|
|
|
|
qDebug() << "Запуск основного цикла обработки сообщений";
|
|
return a.exec();
|
|
}
|
|
//==============================================================================
|
|
|