Warning, /education/gcompris/src/activities/missing-letter/ActivityConfig.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - ActivityConfig.qml
0002  *
0003  * SPDX-FileCopyrightText: 2020 Johnny Jazeix <jazeix@gmail.com>
0004  *
0005  * Authors:
0006  *   Johnny Jazeix <jazeix@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 import "../../core"
0014 import "qrc:/gcompris/src/core/core.js" as Core
0015 
0016 Item {
0017     id: activityConfiguration
0018     property Item background
0019     property alias localeBox: localeBox
0020     property string locale: "system"
0021     property string configurationLocale: "system"
0022     width: flick.width
0023     property alias availableLangs: langs.languages
0024     LanguageList {
0025         id: langs
0026     }
0027 
0028     Column {
0029         spacing: 10 * ApplicationInfo.ratio
0030         width: activityConfiguration.width
0031         GCComboBox {
0032             id: localeBox
0033             model: langs.languages
0034             background: activityConfiguration.background
0035             label: qsTr("Select your locale")
0036         }
0037     }
0038 
0039     function setLocale(localeToSet) {
0040         // Store the locale as-is to be displayed in menu
0041         configurationLocale = localeToSet
0042         activityConfiguration.locale = Core.resolveLocale(localeToSet)
0043     }
0044 
0045     property var dataToSave
0046     function setDefaultValues() {
0047         var localeUtf8 = dataToSave.locale;
0048         if(localeUtf8 !== "system") {
0049             localeUtf8 += ".UTF-8";
0050         }
0051 
0052         if(dataToSave.locale) {
0053             setLocale(localeUtf8)
0054         }
0055         else {
0056             activityConfiguration.localeBox.currentIndex = 0
0057             setLocale(activityConfiguration.availableLangs[0].locale)
0058         }
0059 
0060         for(var i = 0 ; i < activityConfiguration.availableLangs.length ; i ++) {
0061             if(activityConfiguration.availableLangs[i].locale === localeUtf8) {
0062                 activityConfiguration.localeBox.currentIndex = i;
0063                 break;
0064             }
0065         }
0066     }
0067 
0068     function saveValues() {
0069         var newLocale = activityConfiguration.availableLangs[activityConfiguration.localeBox.currentIndex].locale;
0070         // Remove .UTF-8
0071         if(newLocale.indexOf('.') != -1) {
0072             newLocale = newLocale.substring(0, newLocale.indexOf('.'))
0073         }
0074 
0075         setLocale(newLocale);
0076         dataToSave = {"locale": newLocale, "activityLocale": activityConfiguration.locale}
0077     }
0078 }