22 #include <QtGui/QGuiApplication>
23 #include <QtQuick/QQuickWindow>
24 #include <QQmlApplicationEngine>
25 #include <QStandardPaths>
27 #include <QTranslator>
28 #include <QCommandLineParser>
33 #include "ApplicationInfo.h"
34 #include "ActivityInfoTree.h"
36 #include "DownloadManager.h"
38 bool loadAndroidTranslation(QTranslator &translator,
const QString &locale)
40 QFile file(
"assets:/gcompris_" + locale +
".qm");
42 file.open(QIODevice::ReadOnly);
43 QDataStream in(&file);
44 uchar *data = (uchar*)malloc(file.size());
47 qDebug() <<
"file assets:/" << locale <<
".qm exists";
49 in.readRawData((
char*)data, file.size());
51 if(!translator.load(data, file.size())) {
52 qDebug() <<
"Unable to load translation for locale " <<
53 locale <<
", use en_US by default";
62 QString loadTranslation(QSettings &config, QTranslator &translator)
66 if(config.contains(
"General/locale")) {
67 locale = config.value(
"General/locale").toString();
69 locale = GC_DEFAULT_LOCALE;
71 if(locale == GC_DEFAULT_LOCALE)
72 locale = QString(QLocale::system().name() +
".UTF-8");
74 if(locale ==
"C.UTF-8")
75 locale =
"en_US.UTF-8";
79 locale.remove(
".UTF-8");
81 #if defined(Q_OS_ANDROID)
82 if(!loadAndroidTranslation(translator, locale))
86 if(!translator.load(
"gcompris_" + locale, QString(
"%1/%2/translations").arg(QCoreApplication::applicationDirPath(), GCOMPRIS_DATA_FOLDER))) {
87 qDebug() <<
"Unable to load translation for locale " <<
88 locale <<
", use en_US by default";
94 int main(
int argc,
char *argv[])
96 QGuiApplication app(argc, argv);
97 app.setOrganizationName(
"KDE");
98 app.setApplicationName(GCOMPRIS_APPLICATION_NAME);
99 app.setOrganizationDomain(
"kde.org");
103 QSettings config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) +
104 "/gcompris/" + GCOMPRIS_APPLICATION_NAME +
".conf",
105 QSettings::IniFormat);
108 QTranslator translator;
109 QString locale = loadTranslation(config, translator);
111 app.installTranslator(&translator);
113 QCommandLineParser parser;
114 parser.setApplicationDescription(
"GCompris is an educational software for children 2 to 10");
115 parser.addHelpOption();
116 parser.addVersionOption();
117 QCommandLineOption exportActivitiesAsSQL(
"export-activities-as-sql",
"Export activities as SQL");
118 parser.addOption(exportActivitiesAsSQL);
119 QCommandLineOption clDefaultCursor(QStringList() <<
"c" <<
"cursor",
120 QObject::tr(
"Run GCompris with the default system cursor."));
121 parser.addOption(clDefaultCursor);
122 QCommandLineOption clNoCursor(QStringList() <<
"C" <<
"nocursor",
123 QObject::tr(
"Run GCompris without cursor (touch screen mode)."));
124 parser.addOption(clNoCursor);
125 QCommandLineOption clFullscreen(QStringList() <<
"f" <<
"fullscreen",
126 QObject::tr(
"Run GCompris in fullscreen mode."));
127 parser.addOption(clFullscreen);
128 QCommandLineOption clWindow(QStringList() <<
"w" <<
"window",
129 QObject::tr(
"Run GCompris in window mode."));
130 parser.addOption(clWindow);
131 QCommandLineOption clSound(QStringList() <<
"s" <<
"sound",
132 QObject::tr(
"Run GCompris with sound enabled."));
133 parser.addOption(clSound);
134 QCommandLineOption clMute(QStringList() <<
"m" <<
"mute",
135 QObject::tr(
"Run GCompris without sound."));
136 parser.addOption(clMute);
137 QCommandLineOption clWithoutConfig(QStringList() <<
"disable-config",
138 QObject::tr(
"Disable the configuration button."));
139 parser.addOption(clWithoutConfig);
140 QCommandLineOption clWithConfig(QStringList() <<
"enable-config",
141 QObject::tr(
"Enable the configuration button (default)."));
142 parser.addOption(clWithConfig);
147 ActivityInfoTree::init();
148 ApplicationSettings::init();
153 ApplicationInfo::getInstance()->requestAudioFocus();
157 ApplicationSettings::getInstance()->checkPayment();
160 bool isFullscreen =
true;
163 if(config.contains(
"General/fullscreen")) {
164 isFullscreen = config.value(
"General/fullscreen").toBool();
168 bool defaultCursor =
false;
169 if(config.contains(
"General/defaultCursor")) {
170 defaultCursor = config.value(
"General/defaultCursor").toBool();
172 if(!defaultCursor && !parser.isSet(clDefaultCursor))
173 QGuiApplication::setOverrideCursor(
174 QCursor(QPixmap(
":/gcompris/src/core/resource/cursor.svg"),
178 bool noCursor =
false;
179 if(config.contains(
"General/noCursor")) {
180 noCursor = config.value(
"General/noCursor").toBool();
182 if(noCursor || parser.isSet(clNoCursor))
183 QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
187 ApplicationSettings::getInstance()->setExeCount(ApplicationSettings::getInstance()->exeCount() + 1);
191 if(!DownloadManager::getInstance()->areVoicesRegistered())
192 DownloadManager::getInstance()->
updateResource(DownloadManager::getInstance()
193 ->getVoicesResourceForLocale(locale));
195 if(parser.isSet(clFullscreen)) {
198 if(parser.isSet(clWindow)) {
199 isFullscreen =
false;
201 if(parser.isSet(clMute)) {
202 ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(
false);
203 ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(
false);
205 if(parser.isSet(clSound)) {
206 ApplicationSettings::getInstance()->setIsAudioEffectsEnabled(
true);
207 ApplicationSettings::getInstance()->setIsAudioVoicesEnabled(
true);
209 if(parser.isSet(clWithConfig)) {
210 ApplicationSettings::getInstance()->setKioskMode(
false);
212 if(parser.isSet(clWithoutConfig)) {
213 ApplicationSettings::getInstance()->setKioskMode(
true);
216 QQmlApplicationEngine engine(QUrl(
"qrc:/gcompris/src/core/main.qml"));
217 QObject::connect(&engine, SIGNAL(quit()), DownloadManager::getInstance(),
220 if(parser.isSet(exportActivitiesAsSQL)) {
221 ActivityInfoTree *menuTree(qobject_cast<ActivityInfoTree*>(ActivityInfoTree::menuTreeProvider(&engine, NULL)));
222 menuTree->exportAsSQL();
226 QObject *topLevel = engine.rootObjects().value(0);
228 QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
230 qWarning(
"Error: Your root item has to be a Window.");
234 ApplicationInfo::setWindow(window);
236 window->setIcon(QIcon(QPixmap(QString::fromUtf8(
":/gcompris/src/core/resource/gcompris-icon.png"))));
239 window->showFullScreen();
QString GCVersion
GCompris version string (compile time).
Q_INVOKABLE bool updateResource(const QString &path)
Updates a resource path from the upstream server unless prohibited by the settings and registers it i...
QString localeShort
Short (2-letter) locale string of the currently active language.
static void init()
Registers DownloadManager singleton in the QML engine.
GCompris' main QML file defining the top level window.
static void init()
Registers singleton in the QML engine.