Commit 930d852f authored by Johnny Jazeix's avatar Johnny Jazeix Committed by Bruno Coudoin
Browse files

Merge branch 'activityconfig' into devel

parent c72c54ff
......@@ -82,7 +82,7 @@ if(ANDROID)
set(GCOMPRIS_TRANSLATIONS_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir} CACHE INTERNAL "" FORCE)
set(GCOMPRIS_RCC_DIR ${CMAKE_BINARY_DIR}/${_data_dest_dir} CACHE INTERNAL "" FORCE)
if(WITH_ACTIVATION_CODE)
set(ANDROID_BILLING_PERMISSION "<uses-permission android:name=\"com.android.vending.BILLING\"/>")
set(ANDROID_BILLING_PERMISSION '<uses-permission android:name="com.android.vending.BILLING"/>')
set(ANDROID_PACKAGE "net.gcompris")
else(WITH_ACTIVATION_CODE)
set(ANDROID_PACKAGE "net.gcompris.full")
......
......@@ -21,6 +21,7 @@
*/
import QtQuick 2.1
import QtQuick.Controls 1.1
import GCompris 1.0
import "../../core"
......@@ -58,8 +59,11 @@ ActivityBase {
signal start
signal stop
property string locale: "$LOCALE"
Component.onCompleted: {
dialogActivityConfig.getInitialConfiguration()
activity.start.connect(start)
activity.stop.connect(stop)
}
......@@ -77,6 +81,7 @@ ActivityBase {
property alias keyboard: keyboard
property alias wordDropTimer: wordDropTimer
property GCAudio audioEffects: activity.audioEffects
property alias locale: background.locale
}
onStart: {
......@@ -105,6 +110,86 @@ ActivityBase {
}
DialogActivityConfig {
id: dialogActivityConfig
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
ComboBox {
id: localeBox
style: GCComboBoxStyle {}
model: langs.languages
width: 250 * ApplicationInfo.ratio
}
GCText {
text: qsTr("Select your locale")
fontSize: mediumSize
wrapMode: Text.WordWrap
}
}
/* TODO handle this:
GCDialogCheckBox {
id: uppercaseBox
width: 250 * ApplicationInfo.ratio
text: qsTr("Uppercase only mode")
checked: true
onCheckedChanged: {
print("uppercase changed")
}
}
*/
}
}
}
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
newLocale = newLocale.substring(0, newLocale.indexOf('.'))
dataToSave = {"locale": newLocale}
background.locale = newLocale;
// Restart the activity with new informations
if(oldLocale !== newLocale) {
background.stop();
background.start();
}
}
function setDefaultValues() {
var localeUtf8 = background.locale + ".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: dialogHelp
onClose: home()
......@@ -113,13 +198,18 @@ ActivityBase {
Bar {
id: bar
anchors.bottom: keyboard.top
content: BarEnumContent { value: help | home | level }
content: BarEnumContent { value: help | home | level | config }
onHelpClicked: {
displayDialog(dialogHelp)
}
onPreviousLevelClicked: Activity.previousLevel()
onNextLevelClicked: Activity.nextLevel()
onHomeClicked: activity.home()
onConfigClicked: {
dialogActivityConfig.active = true
dialogActivityConfig.setDefaultValues()
displayDialog(dialogActivityConfig)
}
}
Bonus {
......@@ -152,6 +242,9 @@ ActivityBase {
Wordlist {
id: wordlist
defaultFilename: activity.dataSetUrl + "default-en.json"
// To switch between locales: xx_XX stored in configuration and
// possibly correct xx if available (ie fr_FR for french but dataset is fr.)
useDefault: false
filename: ""
onError: console.log("Gletters: Wordlist error: " + msg);
......
......@@ -72,8 +72,21 @@ function start(items_, uppercaseOnly_, _mode) {
mode = _mode;
currentLevel = 0;
currentSubLevel = 0;
var locale = items.locale == "system" ? "$LOCALE" : items.locale
items.wordlist.loadFromFile(GCompris.ApplicationInfo.getLocaleFilePath(
items.ourActivity.dataSetUrl + "default-$LOCALE.json"));
items.ourActivity.dataSetUrl + "default-"+items.locale+".json"));
// If wordlist is empty, we try to load from short locale and if not present again, we switch to default one
var localeUnderscoreIndex = items.locale.indexOf('_')
// probably exist a better way to see if the list is empty
if(items.wordlist.maxLevel == 0 && localeUnderscoreIndex > 0) {
var localeShort = items.locale.substring(0, localeUnderscoreIndex)
items.wordlist.useDefault = true
items.wordlist.loadFromFile(GCompris.ApplicationInfo.getLocaleFilePath(
items.ourActivity.dataSetUrl + "default-"+localeShort+".json"));
items.wordlist.useDefault = false
}
maxLevel = items.wordlist.maxLevel;
droppedWords = new Array();
initLevel();
......@@ -364,6 +377,6 @@ function nextSubLevel() {
}
function playLetter(letter) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/alphabet/"
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices/"+items.locale+"/alphabet/"
+ Core.getSoundFilenamForChar(letter)))
}
/* GCompris - ConfigurationItem.qml
*
* Copyright (C) 2014 Johnny Jazeix <jazeix@gmail.com>
*
* Authors:
* Johnny Jazeix <jazeix@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import GCompris 1.0
import QtQuick.Layouts 1.1
import "../../core"
import "qrc:/gcompris/src/core/core.js" as Core
Item {
property var languages: allLangs.languages
id: dialogConfig
height: column.height
LanguageList {
id: allLangs
}
Column {
id: column
spacing: 10
width: parent.width
// Put configuration here
Row {
id: demoModeBox
width: parent.width
spacing: 10
property bool checked: !ApplicationSettings.isDemoMode
Image {
sourceSize.height: 50 * ApplicationInfo.ratio
source:
demoModeBox.checked ? "qrc:/gcompris/src/core/resource/apply.svgz" :
"qrc:/gcompris/src/core/resource/cancel.svgz"
MouseArea {
anchors.fill: parent
onClicked: {
if(ApplicationSettings.isDemoMode)
ApplicationSettings.isDemoMode = false
}
}
}
Button {
width: parent.parent.width - 50 * ApplicationInfo.ratio - 10 * 2
height: parent.height
enabled: ApplicationSettings.isDemoMode
anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter
text: demoModeBox.checked ? qsTr("You have the full version") :
qsTr("Buy the full version").toUpperCase()
style: ButtonStyle {
background: Rectangle {
implicitWidth: 100
implicitHeight: 25
border.width: control.activeFocus ? 4 : 2
border.color: "black"
radius: 10
gradient: Gradient {
GradientStop { position: 0 ; color: control.pressed ? "#87ff5c" :
ApplicationSettings.isDemoMode ? "#ffe85c" : "#EEEEEE"}
GradientStop { position: 1 ; color: control.pressed ? "#44ff00" :
ApplicationSettings.isDemoMode ? "#f8d600" : "#AAAAAA"}
}
}
label: GCText {
text: control.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
}
}
onClicked: {
if(ApplicationSettings.isDemoMode)
ApplicationSettings.isDemoMode = false
}
}
}
GCDialogCheckBox {
id: displayLockedActivitiesBox
text: qsTr("Show locked activities")
visible: ApplicationSettings.isDemoMode
checked: showLockedActivities
onCheckedChanged: {
showLockedActivities = checked;
}
}
GCDialogCheckBox {
id: enableAudioVoicesBox
text: qsTr("Enable audio voices")
checked: isAudioVoicesEnabled
onCheckedChanged: {
isAudioVoicesEnabled = checked;
}
}
GCDialogCheckBox {
id: enableAudioEffectsBox
text: qsTr("Enable audio effects")
checked: isAudioEffectsEnabled
onCheckedChanged: {
isAudioEffectsEnabled = checked;
}
}
GCDialogCheckBox {
id: enableFullscreenBox
text: qsTr("Fullscreen")
checked: isFullscreen
onCheckedChanged: {
isFullscreen = checked;
}
}
GCDialogCheckBox {
id: enableVirtualKeyboardBox
text: qsTr("Virtual Keyboard")
checked: isVirtualKeyboard
onCheckedChanged: {
isVirtualKeyboard = checked;
}
}
GCDialogCheckBox {
id: enableAutomaticDownloadsBox
checked: isAutomaticDownloadsEnabled
text: qsTr("Enable automatic downloads/updates of sound files")
onCheckedChanged: {
isAutomaticDownloadsEnabled = checked;
}
}
GCDialogCheckBox {
id: sectionVisibleBox
checked: sectionVisible
text: qsTr("The activity section menu is visible")
onCheckedChanged: {
sectionVisible = checked;
}
}
Flow {
spacing: 5
width: parent.width
ComboBox {
id: fontBox
style: GCComboBoxStyle {}
model: fonts
width: 250 * ApplicationInfo.ratio
}
GCText {
text: qsTr("Font selector")
fontSize: mediumSize
wrapMode: Text.WordWrap
}
}
Flow {
spacing: 5
width: parent.width
Slider {
id: baseFontSizeSlider
width: 250 * ApplicationInfo.ratio
style: GCSliderStyle {}
maximumValue: ApplicationSettings.baseFontSizeMax
minimumValue: ApplicationSettings.baseFontSizeMin
stepSize: 1.0
tickmarksEnabled: true
updateValueWhileDragging: true
value: baseFontSize
onValueChanged: ApplicationSettings.baseFontSize = value;
}
GCText {
id: baseFontSizeText
text: qsTr("Font size")
fontSize: mediumSize
wrapMode: Text.WordWrap
}
Button {
height: 30 * ApplicationInfo.ratio
text: qsTr("Default");
style: GCButtonStyle {}
onClicked: baseFontSizeSlider.value = 0.0
}
}
Flow {
spacing: 5
width: parent.width
ComboBox {
id: languageBox
style: GCComboBoxStyle {}
model: dialogConfig.languages
width: 300 * ApplicationInfo.ratio
onCurrentIndexChanged: voicesRow.localeChanged();
}
GCText {
text: qsTr("Language selector")
fontSize: mediumSize
wrapMode: Text.WordWrap
}
}
Flow {
id: voicesRow
width: parent.width
spacing: 5 * ApplicationInfo.ratio
property bool haveLocalResource: false
function localeChanged() {
var language = dialogConfig.languages[languageBox.currentIndex].text;
voicesText.text = language;
voicesRow.haveLocalResource = DownloadManager.haveLocalResource(
DownloadManager.getVoicesResourceForLocale(
dialogConfig.languages[languageBox.currentIndex].locale));
}
Connections {
target: DownloadManager
onDownloadFinished: voicesRow.localeChanged()
}
GCText {
id: voicesText
text: qsTr("Sounds")
}
Image {
id: voicesImage
sourceSize.height: 30 * ApplicationInfo.ratio
source: voicesRow.haveLocalResource ? "qrc:/gcompris/src/core/resource/apply.svgz" :
"qrc:/gcompris/src/core/resource/cancel.svgz"
}
Button {
id: voicesButton
height: 30 * ApplicationInfo.ratio
text: voicesRow.haveLocalResource ? qsTr("Check for updates") :
qsTr("Download")
style: GCButtonStyle {}
onClicked: {
if (DownloadManager.downloadResource(
DownloadManager.getVoicesResourceForLocale(dialogConfig.languages[languageBox.currentIndex].locale)))
{
var downloadDialog = Core.showDownloadDialog(dialogConfig.parent.rootItem, {});
}
}
}
}
Flow {
width: parent.width
spacing: 5 * ApplicationInfo.ratio
GCText {
text: qsTr("Difficulty filter:")
fontSize: mediumSize
height: 50 * ApplicationInfo.ratio
}
// Padding
Item {
height: 1
width: 10 * ApplicationInfo.ratio
}
Image {
source: "qrc:/gcompris/src/core/resource/bar_next.svgz"
sourceSize.height: Math.min(50 * ApplicationInfo.ratio, parent.width / 8)
MouseArea {
anchors.fill: parent
onClicked: {
filterRepeater.setMin(filterRepeater.min + 1)
}
}
}
// Padding
Item {
height: 1
width: 5 * ApplicationInfo.ratio
}
// Level filtering
Repeater {
id: filterRepeater
model: 6
property int min: ApplicationSettings.filterLevelMin
property int max: ApplicationSettings.filterLevelMax
function setMin(value) {
var newMin
if(min < 1)
newMin = 1
else if(min > 6)
newMin = 6
else if(max >= value)
newMin = value
if(newMin)
ApplicationSettings.filterLevelMin = newMin
}
function setMax(value) {
var newMax
if(max < 1)
newMax = 1
else if(max > 6)
newMax = 6
else if(min <= value)
newMax = value
if(newMax)
ApplicationSettings.filterLevelMax = newMax
}
Image {
source: "qrc:/gcompris/src/core/resource/difficulty" +
(modelData + 1) + ".svgz";
sourceSize.width: Math.min(50 * ApplicationInfo.ratio, parent.width / 8)
opacity: modelData + 1 >= filterRepeater.min &&
modelData + 1 <= filterRepeater.max
? 1 : 0.4
property int value: modelData + 1
MouseArea {
anchors.fill: parent
onClicked: {
if(parent.value < filterRepeater.max) {
if(parent.opacity == 1)
filterRepeater.setMin(parent.value + 1)
else
filterRepeater.setMin(parent.value)
} else if(parent.value > filterRepeater.min) {
if(parent.opacity == 1)
filterRepeater.setMax(parent.value - 1)
else
filterRepeater.setMax(parent.value)
}
}
}
}
}
// Padding
Item {
height: 1
width: 5 * ApplicationInfo.ratio
}
Image {
source: "qrc:/gcompris/src/core/resource/bar_previous.svgz"
sourceSize.height: Math.min(50 * ApplicationInfo.ratio, parent.width / 8)
MouseArea {
anchors.fill: parent
onClicked: {
filterRepeater.setMax(filterRepeater.max - 1)
}
}
}
}
}
property bool showLockedActivities: ApplicationSettings.showLockedActivities
property bool isAudioVoicesEnabled: ApplicationSettings.isAudioVoicesEnabled
property bool isAudioEffectsEnabled: ApplicationSettings.isAudioEffectsEnabled
property bool isFullscreen: ApplicationSettings.isFullscreen
property bool isVirtualKeyboard: ApplicationSettings.isVirtualKeyboard
property bool isAutomaticDownloadsEnabled: ApplicationSettings.isAutomaticDownloadsEnabled
property bool sectionVisible: ApplicationSettings.sectionVisible
property int baseFontSize // don't bind to ApplicationSettings.baseFontSize
// or we get a binding loop warning
function loadFromConfig() {
// Synchronize settings with data
showLockedActivities = ApplicationSettings.showLockedActivities
isAudioVoicesEnabled = ApplicationSettings.isAudioVoicesEnabled
enableAudioVoicesBox.checked = isAudioVoicesEnabled
isAudioEffectsEnabled = ApplicationSettings.isAudioEffectsEnabled
enableAudioEffectsBox.checked = isAudioEffectsEnabled
isFullscreen = ApplicationSettings.isFullscreen
enableFullscreenBox.checked = isFullscreen
isVirtualKeyboard = ApplicationSettings.isVirtualKeyboard
enableVirtualKeyboardBox.checked = isVirtualKeyboard