File indexing completed on 2024-05-12 05:39:38

0001 /***************************************************************************
0002  * Copyright (C) 2014 by Renaud Guezennec                                   *
0003  * http://www.rolisteam.org/                                                *
0004  *                                                                          *
0005  *  This file is part of rcse                                               *
0006  *                                                                          *
0007  * rcse is free software; you can redistribute it and/or modify             *
0008  * it under the terms of the GNU General Public License as published by     *
0009  * the Free Software Foundation; either version 2 of the License, or        *
0010  * (at your option) any later version.                                      *
0011  *                                                                          *
0012  * rcse is distributed in the hope that it will be useful,                  *
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
0015  * GNU General Public License for more details.                             *
0016  *                                                                          *
0017  * You should have received a copy of the GNU General Public License        *
0018  * along with this program; if not, write to the                            *
0019  * Free Software Foundation, Inc.,                                          *
0020  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
0021  ***************************************************************************/
0022 #include "mainwindow.h"
0023 #include <QApplication>
0024 
0025 #include <QTranslator>
0026 
0027 #include "qmltypesregister.h"
0028 #include "version.h"
0029 
0030 #include <QCommandLineOption>
0031 #include <QCommandLineParser>
0032 #include <QQuickStyle>
0033 
0034 int main(int argc, char* argv[])
0035 {
0036     QApplication a(argc, argv);
0037 
0038     Q_INIT_RESOURCE(charactersheet);
0039 
0040     a.setAttribute(Qt::AA_DontUseNativeMenuBar, true);
0041     QString appName("RCSE");
0042     a.setApplicationName(appName);
0043 
0044     a.setApplicationVersion(version::version);
0045 
0046     registerQmlTypes();
0047 
0048     // INIT STYLE
0049     QIcon::setThemeSearchPaths({":/rcstyle"});
0050     QQuickStyle::setStyle("Basic");
0051 
0052     QTranslator rolisteamTranslator;
0053     if(!rolisteamTranslator.load(QLocale(), ":/translations/rcse", "_"))
0054         qWarning() << QObject::tr("Load of translation %1 file failed").arg(":/translations/rcse");
0055 
0056     a.installTranslator(&rolisteamTranslator);
0057 
0058     QTranslator qtTranslator;
0059     if(!qtTranslator.load(QLocale(), ":/translations/qt", "_"))
0060         qWarning() << QObject::tr("Load of translation %1 file failed").arg(":/translations/qt");
0061     a.installTranslator(&qtTranslator);
0062 
0063     QCommandLineParser parser;
0064     parser.addHelpOption();
0065     parser.addVersionOption();
0066 
0067     QCommandLineOption translation(QStringList() << "t"
0068                                                  << "translation",
0069                                    QObject::tr("define path to current <translation>"), "translation");
0070     QCommandLineOption file(QStringList() << "f"
0071                                           << "file",
0072                             QObject::tr("open <file>."), "file");
0073 
0074     parser.addOption(translation);
0075     parser.addOption(file);
0076     parser.process(a.arguments());
0077 
0078     if(parser.isSet(translation))
0079     {
0080         QTranslator* cliTranslator= new QTranslator();
0081         if(cliTranslator->load(parser.value(translation)))
0082             qWarning() << QObject::tr("Load of translation %1 file failed").arg(parser.value(translation));
0083         a.installTranslator(cliTranslator);
0084     }
0085 
0086     rcse::MainWindow w;
0087     if(parser.isSet(file))
0088     {
0089         w.loadFile(parser.value(file));
0090     }
0091 
0092     w.show();
0093 
0094     return a.exec();
0095 }