Commit 851fff53 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

click_on_letter, add configuration for choosing locale

parent 3ad14462
......@@ -45,11 +45,15 @@ ActivityBase {
fillMode: Image.PreserveAspectCrop
focus: true
// system locale by default
property string locale: "system"
signal start
signal stop
signal voiceError
Component.onCompleted: {
dialogActivityConfig.getInitialConfiguration()
activity.start.connect(start)
activity.stop.connect(stop)
}
......@@ -65,6 +69,7 @@ ActivityBase {
property alias repeatItem: repeatItem
property alias score: score
property alias bonus: bonus
property alias locale: background.locale
}
onVoiceError: {
......@@ -76,9 +81,81 @@ ActivityBase {
activity.audioVoices.error.connect(voiceError)
Activity.start(items, mode);
}
onStop: Activity.stop()
DialogActivityConfig {
id: dialogActivityConfig
currentActivity: activity
content: Component {
Item {
property alias localeBox: localeBox
height: column.height
property alias availableLangs: langs.languages
LanguageList {
id: langs
}
Column {
id: column
spacing: 10
width: parent.width
Flow {
spacing: 5
width: dialogActivityConfig.width
GCComboBox {
id: localeBox
model: langs.languages
background: dialogActivityConfig
label: qsTr("Select your locale")
}
}
}
}
}
onClose: home()
onLoadData: {
if(dataToSave && dataToSave["locale"]) {
background.locale = dataToSave["locale"];
}
}
onSaveData: {
var oldLocale = background.locale;
var newLocale =
dialogActivityConfig.configItem.availableLangs[dialogActivityConfig.loader.item.localeBox.currentIndex].locale;
// Remove .UTF-8
if(newLocale.indexOf('.') != -1) {
newLocale = newLocale.substring(0, newLocale.indexOf('.'))
}
dataToSave = {"locale": newLocale }
background.locale = newLocale;
// Restart the activity with new information
if(oldLocale !== newLocale) {
background.stop();
background.start();
}
}
function setDefaultValues() {
var localeUtf8 = background.locale;
if(background.locale != "system") {
localeUtf8 += ".UTF-8";
}
for(var i = 0 ; i < dialogActivityConfig.configItem.availableLangs.length ; i ++) {
if(dialogActivityConfig.configItem.availableLangs[i].locale === localeUtf8) {
dialogActivityConfig.loader.item.localeBox.currentIndex = i;
break;
}
}
}
}
DialogHelp {
id: dialogHelpLeftRight
onClose: home()
......@@ -86,18 +163,22 @@ ActivityBase {
Bar {
id: bar
content: BarEnumContent { value: help | home | level }
content: BarEnumContent { value: help | home | level | config }
onHelpClicked: {
displayDialog(dialogHelpLeftRight)
}
onPreviousLevelClicked: Activity.previousLevel()
onNextLevelClicked: Activity.nextLevel()
onHomeClicked: home()
onConfigClicked: {
dialogActivityConfig.active = true
dialogActivityConfig.setDefaultValues()
displayDialog(dialogActivityConfig)
}
}
Score {
id: score
anchors.top: parent.top
anchors.topMargin: 10 * ApplicationInfo.ratio
anchors.left: parent.left
......@@ -110,7 +191,7 @@ ActivityBase {
id: bonus
Component.onCompleted: win.connect(Activity.nextSubLevel)
}
BarButton {
id: repeatItem
source: "qrc:/gcompris/src/core/resource/bar_repeat.svg";
......@@ -145,13 +226,12 @@ ActivityBase {
width: questionText.width * 2
height: questionText.height * 1.3
visible: false
property alias text: questionText.text
Rectangle {
id: questionRect
anchors.fill: parent
border.color: "#FFFFFFFF"
border.width: 2
color: "#000065"
......@@ -183,13 +263,12 @@ ActivityBase {
color: "#422a2a2a"
source: questionText
}
}
ListModel {
id: trainModel
id: trainModel
}
property int itemWidth: Math.min(parent.width / 7.5, parent.height / 5)
property int itemHeight: itemWidth * 1.11
......@@ -238,10 +317,9 @@ ActivityBase {
nbCarriage: (parent.width - engine.width) / background.itemWidth
}
}
JsonParser {
id: parser
onError: console.error("Click_on_letter: Error parsing JSON: " + msg);
}
......
......@@ -49,6 +49,11 @@ function start(_items, _mode)
items = _items;
mode = _mode;
// register the voices for the locale
var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale)
GCompris.DownloadManager.updateResource(GCompris.DownloadManager.getVoicesResourceForLocale(locale))
loadLevels();
currentLevel = 0;
currentSubLevel = 0;
......@@ -139,12 +144,12 @@ function initLevel() {
items.score.currentSubLevel = currentSubLevel + 1;
}
var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale);
currentLetter = questions.split("")[currentSubLevel];
if (GCompris.ApplicationSettings.isAudioVoicesEnabled &&
GCompris.DownloadManager.haveLocalResource(
GCompris.DownloadManager.getVoicesResourceForLocale(
GCompris.ApplicationSettings.locale))) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/misc/click_on_letter.$CA"));
GCompris.DownloadManager.getVoicesResourceForLocale(locale))) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/"+locale+"/misc/click_on_letter.$CA"));
items.audioVoices.silence(100)
playLetter(currentLetter)
items.questionItem.visible = false
......@@ -159,7 +164,8 @@ function initLevel() {
}
function playLetter(letter) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/$LOCALE/alphabet/"
var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale)
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/"+locale+"/alphabet/"
+ Core.getSoundFilenamForChar(letter)))
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment