22 #include "ApplicationSettings.h"
23 #include "ApplicationInfo.h"
25 #include <QtCore/qmath.h>
26 #include <QtCore/QUrl>
27 #include <QtCore/QUrlQuery>
28 #include <QtGui/QGuiApplication>
29 #include <QtGui/QScreen>
30 #include <QtCore/QLocale>
33 #include <QStandardPaths>
36 #define GC_DEFAULT_FONT "Andika-R.ttf"
37 #define GC_DEFAULT_FONT_CAPITALIZATION 0 // Font.MixedCase
39 static const QString GENERAL_GROUP_KEY =
"General";
40 static const QString ADMIN_GROUP_KEY =
"Admin";
41 static const QString INTERNAL_GROUP_KEY =
"Internal";
42 static const QString FAVORITE_GROUP_KEY =
"Favorite";
44 static const QString FULLSCREEN_KEY =
"fullscreen";
45 static const QString SHOW_LOCKED_ACTIVITIES_KEY =
"showLockedActivities";
46 static const QString ENABLE_AUDIO_VOICES_KEY =
"enableAudioVoices";
47 static const QString ENABLE_AUDIO_EFFECTS_KEY =
"enableAudioEffects";
48 static const QString VIRTUALKEYBOARD_KEY =
"virtualKeyboard";
49 static const QString LOCALE_KEY =
"locale";
50 static const QString FONT_KEY =
"font";
51 static const QString IS_CURRENT_FONT_EMBEDDED =
"isCurrentFontEmbedded";
52 static const QString ENABLE_AUTOMATIC_DOWNLOADS =
"enableAutomaticDownloads";
54 static const QString DOWNLOAD_SERVER_URL_KEY =
"downloadServerUrl";
56 static const QString EXE_COUNT_KEY =
"exeCount";
58 static const QString FILTER_LEVEL_MIN =
"filterLevelMin";
59 static const QString FILTER_LEVEL_MAX =
"filterLevelMax";
61 static const QString BASE_FONT_SIZE_KEY =
"baseFontSize";
62 static const QString FONT_CAPITALIZATION =
"fontCapitalization";
64 static const QString DEFAULT_CURSOR =
"defaultCursor";
65 static const QString NO_CURSOR =
"noCursor";
66 static const QString DEMO_KEY =
"demo";
67 static const QString KIOSK_KEY =
"kiosk";
68 static const QString SECTION_VISIBLE =
"sectionVisible";
72 ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
73 m_config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) +
74 "/gcompris/" + GCOMPRIS_APPLICATION_NAME +
".conf", QSettings::IniFormat), m_baseFontSizeMin(-7), m_baseFontSizeMax(7)
79 m_config.beginGroup(GENERAL_GROUP_KEY);
80 m_isAudioEffectsEnabled = m_config.value(ENABLE_AUDIO_EFFECTS_KEY,
true).toBool();
81 m_isFullscreen = m_config.value(FULLSCREEN_KEY,
true).toBool();
82 m_isAudioVoicesEnabled = m_config.value(ENABLE_AUDIO_VOICES_KEY,
true).toBool();
83 m_isVirtualKeyboard = m_config.value(VIRTUALKEYBOARD_KEY,
84 ApplicationInfo::getInstance()->
isMobile()).toBool();
85 m_locale = m_config.value(LOCALE_KEY, GC_DEFAULT_LOCALE).toString();
86 m_font = m_config.value(FONT_KEY, GC_DEFAULT_FONT).toString();
87 m_fontCapitalization = m_config.value(FONT_CAPITALIZATION, GC_DEFAULT_FONT_CAPITALIZATION).toUInt();
88 m_isEmbeddedFont = m_config.value(IS_CURRENT_FONT_EMBEDDED,
true).toBool();
91 #if defined(WITH_ACTIVATION_CODE)
92 m_isDemoMode = m_config.value(DEMO_KEY,
true).toBool();
94 m_isDemoMode = m_config.value(DEMO_KEY,
false).toBool();
97 #if defined(WITH_KIOSK_MODE)
98 m_isKioskMode = m_config.value(KIOSK_KEY,
true).toBool();
100 m_isKioskMode = m_config.value(KIOSK_KEY,
false).toBool();
105 m_showLockedActivities = m_config.value(SHOW_LOCKED_ACTIVITIES_KEY, m_isDemoMode).toBool();
106 m_sectionVisible = m_config.value(SECTION_VISIBLE,
true).toBool();
107 m_isAutomaticDownloadsEnabled = m_config.value(ENABLE_AUTOMATIC_DOWNLOADS,
109 m_filterLevelMin = m_config.value(FILTER_LEVEL_MIN, 1).toUInt();
110 m_filterLevelMax = m_config.value(FILTER_LEVEL_MAX, 6).toUInt();
111 m_defaultCursor = m_config.value(DEFAULT_CURSOR,
false).toBool();
112 m_noCursor = m_config.value(NO_CURSOR,
false).toBool();
113 setBaseFontSize(m_config.value(BASE_FONT_SIZE_KEY, 0).toInt());
119 m_config.beginGroup(ADMIN_GROUP_KEY);
120 m_downloadServerUrl = m_config.value(DOWNLOAD_SERVER_URL_KEY,
"http://gcompris.net").toString();
124 m_config.beginGroup(INTERNAL_GROUP_KEY);
125 m_exeCount = m_config.value(EXE_COUNT_KEY, 0).toUInt();
129 m_isBarHidden =
false;
131 connect(
this, SIGNAL(showLockedActivitiesChanged()),
this, SLOT(notifyShowLockedActivitiesChanged()));
132 connect(
this, SIGNAL(audioVoicesEnabledChanged()),
this, SLOT(notifyAudioVoicesEnabledChanged()));
133 connect(
this, SIGNAL(audioEffectsEnabledChanged()),
this, SLOT(notifyAudioEffectsEnabledChanged()));
134 connect(
this, SIGNAL(fullscreenChanged()),
this, SLOT(notifyFullscreenChanged()));
135 connect(
this, SIGNAL(localeChanged()),
this, SLOT(notifyLocaleChanged()));
136 connect(
this, SIGNAL(fontChanged()),
this, SLOT(notifyFontChanged()));
137 connect(
this, SIGNAL(virtualKeyboardChanged()),
this, SLOT(notifyVirtualKeyboardChanged()));
138 connect(
this, SIGNAL(automaticDownloadsEnabledChanged()),
this, SLOT(notifyAutomaticDownloadsEnabledChanged()));
139 connect(
this, SIGNAL(filterLevelMinChanged()),
this, SLOT(notifyFilterLevelMinChanged()));
140 connect(
this, SIGNAL(filterLevelMaxChanged()),
this, SLOT(notifyFilterLevelMaxChanged()));
141 connect(
this, SIGNAL(sectionVisibleChanged()),
this, SLOT(notifySectionVisibleChanged()));
142 connect(
this, SIGNAL(demoModeChanged()),
this, SLOT(notifyDemoModeChanged()));
143 connect(
this, SIGNAL(kioskModeChanged()),
this, SLOT(notifyKioskModeChanged()));
144 connect(
this, SIGNAL(downloadServerUrlChanged()),
this, SLOT(notifyDownloadServerUrlChanged()));
145 connect(
this, SIGNAL(exeCountChanged()),
this, SLOT(notifyExeCountChanged()));
146 connect(
this, SIGNAL(barHiddenChanged()),
this, SLOT(notifyBarHiddenChanged()));
149 ApplicationSettings::~ApplicationSettings()
153 m_config.beginGroup(GENERAL_GROUP_KEY);
154 m_config.setValue(SHOW_LOCKED_ACTIVITIES_KEY, m_showLockedActivities);
155 m_config.setValue(ENABLE_AUDIO_VOICES_KEY, m_isAudioVoicesEnabled);
156 m_config.setValue(LOCALE_KEY, m_locale);
157 m_config.setValue(FONT_KEY, m_font);
158 m_config.setValue(IS_CURRENT_FONT_EMBEDDED, m_isEmbeddedFont);
159 m_config.setValue(FULLSCREEN_KEY, m_isFullscreen);
160 m_config.setValue(VIRTUALKEYBOARD_KEY, m_isVirtualKeyboard);
161 m_config.setValue(ENABLE_AUTOMATIC_DOWNLOADS, m_isAutomaticDownloadsEnabled);
162 m_config.setValue(FILTER_LEVEL_MIN, m_filterLevelMin);
163 m_config.setValue(FILTER_LEVEL_MAX, m_filterLevelMax);
164 m_config.setValue(DEMO_KEY, m_isDemoMode);
165 m_config.setValue(KIOSK_KEY, m_isKioskMode);
166 m_config.setValue(SECTION_VISIBLE, m_sectionVisible);
167 m_config.setValue(DEFAULT_CURSOR, m_defaultCursor);
168 m_config.setValue(NO_CURSOR, m_noCursor);
169 m_config.setValue(BASE_FONT_SIZE_KEY, m_baseFontSize);
170 m_config.setValue(FONT_CAPITALIZATION, m_fontCapitalization);
174 m_config.beginGroup(ADMIN_GROUP_KEY);
175 m_config.setValue(DOWNLOAD_SERVER_URL_KEY, m_downloadServerUrl);
179 m_config.beginGroup(INTERNAL_GROUP_KEY);
180 m_config.setValue(EXE_COUNT_KEY, m_exeCount);
188 void ApplicationSettings::notifyShowLockedActivitiesChanged()
190 updateValueInConfig(GENERAL_GROUP_KEY, SHOW_LOCKED_ACTIVITIES_KEY, m_showLockedActivities);
191 qDebug() <<
"notifyShowLockedActivitiesChanged: " << m_showLockedActivities;
194 void ApplicationSettings::notifyAudioVoicesEnabledChanged()
196 updateValueInConfig(GENERAL_GROUP_KEY, ENABLE_AUDIO_VOICES_KEY, m_isAudioVoicesEnabled);
197 qDebug() <<
"notifyAudioVoices: " << m_isAudioVoicesEnabled;
200 void ApplicationSettings::notifyAudioEffectsEnabledChanged()
202 updateValueInConfig(GENERAL_GROUP_KEY, ENABLE_AUDIO_EFFECTS_KEY, m_isAudioEffectsEnabled);
203 qDebug() <<
"notifyAudioEffects: " << m_isAudioEffectsEnabled;
206 void ApplicationSettings::notifyLocaleChanged()
208 updateValueInConfig(GENERAL_GROUP_KEY, LOCALE_KEY, m_locale);
209 qDebug() <<
"new locale: " << m_locale;
212 void ApplicationSettings::notifyFontChanged()
214 updateValueInConfig(GENERAL_GROUP_KEY, FONT_KEY, m_font);
215 qDebug() <<
"new font: " << m_font;
218 void ApplicationSettings::notifyEmbeddedFontChanged()
220 updateValueInConfig(GENERAL_GROUP_KEY, IS_CURRENT_FONT_EMBEDDED, m_isEmbeddedFont);
221 qDebug() <<
"new font is embedded: " << m_isEmbeddedFont;
224 void ApplicationSettings::notifyFontCapitalizationChanged()
226 updateValueInConfig(GENERAL_GROUP_KEY, FONT_CAPITALIZATION, m_fontCapitalization);
227 qDebug() <<
"new fontCapitalization: " << m_fontCapitalization;
230 void ApplicationSettings::notifyFullscreenChanged()
232 updateValueInConfig(GENERAL_GROUP_KEY, FULLSCREEN_KEY, m_isFullscreen);
233 qDebug() <<
"fullscreen set to: " << m_isFullscreen;
236 void ApplicationSettings::notifyVirtualKeyboardChanged()
238 updateValueInConfig(GENERAL_GROUP_KEY, VIRTUALKEYBOARD_KEY, m_isVirtualKeyboard);
239 qDebug() <<
"virtualkeyboard set to: " << m_isVirtualKeyboard;
245 void ApplicationSettings::setIsAutomaticDownloadsEnabled(
const bool newIsAutomaticDownloadsEnabled) {
247 m_isAutomaticDownloadsEnabled = newIsAutomaticDownloadsEnabled;
248 emit automaticDownloadsEnabledChanged();
252 void ApplicationSettings::notifyAutomaticDownloadsEnabledChanged()
254 updateValueInConfig(GENERAL_GROUP_KEY, ENABLE_AUTOMATIC_DOWNLOADS, m_isAutomaticDownloadsEnabled);
255 qDebug() <<
"enableAutomaticDownloads set to: " << m_isAutomaticDownloadsEnabled;
258 void ApplicationSettings::notifyFilterLevelMinChanged()
260 updateValueInConfig(GENERAL_GROUP_KEY, FILTER_LEVEL_MIN, m_filterLevelMin);
261 qDebug() <<
"filterLevelMin set to: " << m_filterLevelMin;
264 void ApplicationSettings::notifyFilterLevelMaxChanged()
266 updateValueInConfig(GENERAL_GROUP_KEY, FILTER_LEVEL_MAX, m_filterLevelMax);
267 qDebug() <<
"filterLevelMax set to: " << m_filterLevelMax;
270 void ApplicationSettings::notifyDemoModeChanged()
272 updateValueInConfig(GENERAL_GROUP_KEY, DEMO_KEY, m_isDemoMode);
273 qDebug() <<
"notifyDemoMode: " << m_isDemoMode;
276 void ApplicationSettings::notifyKioskModeChanged()
278 updateValueInConfig(GENERAL_GROUP_KEY, KIOSK_KEY, m_isKioskMode);
279 qDebug() <<
"notifyKioskMode: " << m_isKioskMode;
282 void ApplicationSettings::notifySectionVisibleChanged()
284 updateValueInConfig(GENERAL_GROUP_KEY, SECTION_VISIBLE, m_sectionVisible);
285 qDebug() <<
"notifySectionVisible: " << m_sectionVisible;
288 void ApplicationSettings::notifyDownloadServerUrlChanged()
290 updateValueInConfig(ADMIN_GROUP_KEY, DOWNLOAD_SERVER_URL_KEY, m_downloadServerUrl);
291 qDebug() <<
"downloadServerUrl set to: " << m_downloadServerUrl;
294 void ApplicationSettings::notifyExeCountChanged()
296 updateValueInConfig(INTERNAL_GROUP_KEY, EXE_COUNT_KEY, m_exeCount);
297 qDebug() <<
"exeCount set to: " << m_exeCount;
300 void ApplicationSettings::notifyBarHiddenChanged()
302 qDebug() <<
"is bar hidden: " << m_isBarHidden;
305 void ApplicationSettings::saveBaseFontSize()
307 updateValueInConfig(GENERAL_GROUP_KEY, BASE_FONT_SIZE_KEY, m_baseFontSize);
312 qDebug() <<
"save configuration for:" << activity;
313 QMapIterator<QString, QVariant> i(data);
314 while (i.hasNext()) {
316 updateValueInConfig(activity, i.key(), i.value());
322 qDebug() <<
"load configuration for:" << activity;
323 m_config.beginGroup(activity);
324 QStringList keys = m_config.childKeys();
326 foreach(
const QString &key, keys) {
327 data[key] = m_config.value(key);
333 void ApplicationSettings::setFavorite(
const QString &activity,
bool favorite)
335 updateValueInConfig(FAVORITE_GROUP_KEY, activity, favorite);
338 bool ApplicationSettings::isFavorite(
const QString &activity)
340 m_config.beginGroup(FAVORITE_GROUP_KEY);
341 bool favorite = m_config.value(activity,
false).toBool();
346 template<
class T>
void ApplicationSettings::updateValueInConfig(
const QString& group,
347 const QString& key,
const T& value)
349 m_config.beginGroup(group);
350 m_config.setValue(key, value);
355 QObject *ApplicationSettings::systeminfoProvider(QQmlEngine *engine,
356 QJSEngine *scriptEngine)
359 Q_UNUSED(scriptEngine)
367 qmlRegisterSingletonType<ApplicationSettings>(
"GCompris", 1, 0,
368 "ApplicationSettings", systeminfoProvider);
Q_INVOKABLE void saveActivityConfiguration(const QString &activity, const QVariantMap &data)
Stores per-activity configuration data for activity.
Q_INVOKABLE QVariantMap loadActivityConfiguration(const QString &activity)
Loads per-activity configuration data for activity.
bool isDownloadAllowed
Download allowed.
bool isAutomaticDownloadsEnabled
Whether downloads/updates of resource files should be done automatically, without user-interaction...
Singleton that contains GCompris' persistent settings.
bool isMobile
Whether the application is currently running on a mobile platform.