Commit 2d32506a authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

REVIEW: 129200 external wordset, change behaviour

parent 14dba467
......@@ -29,11 +29,11 @@ import "qrc:/gcompris/src/core/core.js" as Core
ActivityBase {
id: activity
// Overload this in your activity to change it
// Put you default-<locale>.json files in it
property string dataSetUrl: "qrc:/gcompris/src/activities/hangman/resource/"
onStart: focus = true
onStop: { }
// When going on configuration, it steals the focus and re set it to the activity.
......@@ -53,13 +53,12 @@ ActivityBase {
// system locale by default
property string locale: "system"
readonly property string wordsResource: "data2/words/words.rcc"
property bool englishFallback: false
signal start
signal stop
Component.onCompleted: {
dialogActivityConfig.getInitialConfiguration()
activity.start.connect(start)
......@@ -127,7 +126,7 @@ ActivityBase {
}
z: 11
}
TextInput {
// Helper element to capture composed key events like french ô which
// are not available via Keys.onPressed() on linux. Must be
......@@ -144,7 +143,7 @@ ActivityBase {
}
onAccepted: if(items.remainingLife === 0) Activity.nextSubLevel()
}
Item {
id: imageframe
width: Math.min(300 * ApplicationInfo.ratio,
......@@ -235,7 +234,6 @@ ActivityBase {
label: qsTr("Select your locale")
}
}
}
}
}
......@@ -265,7 +263,6 @@ ActivityBase {
}
}
function setDefaultValues() {
var localeUtf8 = background.locale;
if(background.locale != "system") {
......@@ -280,7 +277,7 @@ ActivityBase {
}
}
}
DialogHelp {
id: dialogHelp
onClose: home()
......@@ -302,7 +299,7 @@ ActivityBase {
displayDialog(dialogActivityConfig)
}
}
Score {
id: score
anchors.top: undefined
......@@ -311,7 +308,7 @@ ActivityBase {
anchors.rightMargin: 10 * ApplicationInfo.ratio
anchors.bottom: keyboard.top
}
BarButton {
id: ok
source: "qrc:/gcompris/src/core/resource/bar_ok.svg";
......@@ -371,8 +368,7 @@ ActivityBase {
}
}
}
VirtualKeyboard {
id: keyboard
anchors.bottom: parent.bottom
......@@ -381,7 +377,7 @@ ActivityBase {
onKeypress: Activity.processKeyPress(text);
onError: console.log("VirtualKeyboard error: " + msg);
}
Bonus {
id: bonus
interval: 2000
......@@ -405,5 +401,4 @@ ActivityBase {
onStatusChanged: if (status == Loader.Ready) item.start()
}
}
}
......@@ -21,8 +21,8 @@
*/
.pragma library
.import QtQuick 2.0 as Quick
.import GCompris 1.0 as GCompris
.import QtQuick 2.0 as Quick
.import GCompris 1.0 as GCompris
.import "qrc:/gcompris/src/core/core.js" as Core
.import "qrc:/gcompris/src/activities/lang/lang_api.js" as Lang
......@@ -51,7 +51,7 @@ function start(items_) {
currentLevel = 0;
currentSubLevel = 0;
items.remainingLife = 6;
var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale)
var resourceUrl = "qrc:/gcompris/src/activities/lang/resource/"
......@@ -59,46 +59,16 @@ function start(items_) {
// register the voices for the locale
GCompris.DownloadManager.updateResource(
GCompris.DownloadManager.getVoicesResourceForLocale(locale))
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+ locale +".json")
// If dataset is empty, we try to load from short locale
// and if not present again, we switch to default one
var localeUnderscoreIndex = locale.indexOf('_')
if(!dataset) {
var localeShort;
// We will first look again for locale xx (without _XX if exist)
if(localeUnderscoreIndex > 0) {
localeShort = locale.substring(0, localeUnderscoreIndex)
} else {
localeShort = locale;
}
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+localeShort+ ".json")
}
// If still dataset is empty then fallback to english
if(!dataset) {
// English fallback
items.background.englishFallback = true
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-en.json")
} else {
items.background.englishFallback = false
}
var data = Lang.loadDataset(items.parser, resourceUrl, locale);
dataset = data["dataset"];
items.background.englishFallback = data["englishFallback"];
lessons = Lang.getAllLessons(dataset)
maxLevel = lessons.length
initLevel();
}
function stop() {
}
function initLevel() {
......
......@@ -42,7 +42,6 @@ ActivityBase {
fillMode: Image.PreserveAspectCrop
sourceSize.width: Math.max(parent.width, parent.height)
readonly property string wordsResource: "data2/words/words.rcc"
property bool englishFallback: false
signal start
......@@ -114,8 +113,7 @@ ActivityBase {
displayDialog(dialogHelp)
}
onHomeClicked: {
// if we don't have the images, we leave the activity on home()
if(DownloadManager.haveLocalResource(wordsResource) && !items.menuScreen.started && !items.imageReview.started)
if(!items.menuScreen.started && !items.imageReview.started)
// We're in a mini game, start imageReview
items.imageReview.start()
else if(items.imageReview.started)
......
......@@ -20,7 +20,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/.pragma library
*/
.pragma library
.import QtQuick 2.0 as Quick
.import GCompris 1.0 as GCompris
.import "qrc:/gcompris/src/core/core.js" as Core
......@@ -50,36 +51,9 @@ function start() {
// register the voices for the locale
GCompris.DownloadManager.updateResource(GCompris.DownloadManager.getVoicesResourceForLocale(locale))
dataset = Lang.load(items.parser, baseUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+ locale +".json")
// If dataset is empty, we try to load from short locale
// and if not present again, we switch to default one
var localeUnderscoreIndex = locale.indexOf('_')
if(!dataset) {
var localeShort;
// We will first look again for locale xx (without _XX if exist)
if(localeUnderscoreIndex > 0) {
localeShort = locale.substring(0, localeUnderscoreIndex)
} else {
localeShort = locale;
}
dataset = Lang.load(items.parser, baseUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+localeShort+ ".json")
}
// If still dataset is empty then fallback to english
if(!dataset) {
// English fallback
items.background.englishFallback = true
dataset = Lang.load(items.parser, baseUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-en.json")
} else {
items.background.englishFallback = false
}
var data = Lang.loadDataset(items.parser, baseUrl, locale);
dataset = data["dataset"];
items.background.englishFallback = data["englishFallback"];
// We have to keep it because we can't access content from the model
lessons = Lang.getAllLessons(dataset)
......
......@@ -126,3 +126,37 @@ function applyImgPrefix(dataset) {
}
}
}
/**
* Helper to load a dataset
*/
function loadDataset(parser, resourceUrl, locale) {
var wordset = GCompris.ApplicationSettings.useExternalWordset() ? "words.json" : "words_sample.json";
var dataset = load(parser, resourceUrl, wordset,
"content-"+ locale +".json")
var englishFallback = false
// If dataset is empty, we try to load from short locale
// and if not present again, we switch to default one
var localeUnderscoreIndex = locale.indexOf('_')
if(!dataset) {
var localeShort;
// We will first look again for locale xx (without _XX if exist)
if(localeUnderscoreIndex > 0) {
localeShort = locale.substring(0, localeUnderscoreIndex)
} else {
localeShort = locale;
}
dataset = load(parser, resourceUrl, wordset,
"content-"+localeShort+ ".json")
}
// If still dataset is empty then fallback to english
if(!dataset) {
// English fallback
englishFallback = true
dataset = load(parser, resourceUrl, wordset, "content-en.json")
}
return {"dataset": dataset, "englishFallback": englishFallback};
}
......@@ -45,6 +45,8 @@ ActivityBase {
// system locale by default
property string locale: "system"
property bool englishFallback: false
property bool keyboardMode: false
signal start
......@@ -61,6 +63,7 @@ ActivityBase {
id: items
property Item main: activity.main
property alias bar: bar
property alias background: background
property alias wordsModel: wordsModel
property GCAudio audioVoices: activity.audioVoices
property alias parser: parser
......@@ -69,6 +72,7 @@ ActivityBase {
property alias score: score
property alias bonus: bonus
property alias locale: background.locale
property alias englishFallbackDialog: englishFallbackDialog
property string question
}
......@@ -327,5 +331,20 @@ ActivityBase {
onError: console.error("Click_on_letter: Error parsing JSON: " + msg);
}
Loader {
id: englishFallbackDialog
sourceComponent: GCDialog {
parent: activity.main
message: qsTr("We are sorry, we don't have yet a translation for your language.") + " " +
qsTr("GCompris is developed by the KDE community, you can translate GCompris by joining a translation team on <a href=\"%2\">%2</a>").arg("http://l10n.kde.org/") +
"<br /> <br />" +
qsTr("We switched to English for this activity but you can select another language in the configuration dialog.")
onClose: background.englishFallback = false
}
anchors.fill: parent
focus: true
active: background.englishFallback
onStatusChanged: if (status == Loader.Ready) item.start()
}
}
}
......@@ -61,33 +61,9 @@ function start(_items) {
function loadDataset() {
var resourceUrl = "qrc:/gcompris/src/activities/lang/resource/"
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+ locale +".json")
// If dataset is empty, we try to load from short locale
// and if not present again, we switch to default one
var localeUnderscoreIndex = locale.indexOf('_')
if(!dataset) {
var localeShort;
// We will first look again for locale xx (without _XX if exist)
if(localeUnderscoreIndex > 0) {
localeShort = locale.substring(0, localeUnderscoreIndex)
}
else {
localeShort = locale;
}
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-"+localeShort+ ".json")
}
if(!dataset) {
// English fallback
dataset = Lang.load(items.parser, resourceUrl,
GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json",
"content-en.json")
}
var data = Lang.loadDataset(items.parser, resourceUrl, locale);
dataset = data["dataset"];
items.background.englishFallback = data["englishFallback"];
}
function stop() {
......
......@@ -242,14 +242,15 @@ Item {
}
/* Technically wordset config is a string that holds the wordset name or '' for the
* internal wordset. But as we support only internal and words its best to show the
* user a boolean choice.
*/
* internal wordset. But as we support only internal and words its best to show the
* user a boolean choice.
*/
GCDialogCheckBox {
id: wordsetBox
checked: wordset
checked: DownloadManager.isDataRegistered("words")
text: qsTr("Use external large word image set")
visible: ApplicationInfo.isDownloadAllowed
enabled: !DownloadManager.isDataRegistered("words")
onCheckedChanged: {
wordset = checked ? 'data2/words/words.rcc' : '';
}
......@@ -556,7 +557,8 @@ Item {
sectionVisibleBox.checked = sectionVisible
wordset = ApplicationSettings.wordset
wordsetBox.checked = (wordset != '')
wordsetBox.checked = DownloadManager.isDataRegistered("words") || ApplicationSettings.wordset == 'data2/words/words.rcc'
wordsetBox.enabled = !DownloadManager.isDataRegistered("words")
baseFontSize = ApplicationSettings.baseFontSize;
fontLetterSpacing = ApplicationSettings.fontLetterSpacing;
......@@ -627,6 +629,39 @@ Item {
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale))
}
}
// download words.rcc if needed
if(ApplicationSettings.wordset != "") {
// we want to use the external dataset, it is either in
// words/words.rcc or full-${CA}.rcc
if(DownloadManager.isDataRegistered("words")) {
// we either have it, we try to update in the background
// or we are downloading it
if(DownloadManager.haveLocalResource(wordset))
DownloadManager.updateResource(wordset)
}
else {
// download automatically if automatic download else ask for download
if(isAutomaticDownloadsEnabled) {
var prevAutomaticDownload = ApplicationSettings.isAutomaticDownloadsEnabled
ApplicationSettings.isAutomaticDownloadsEnabled = true;
DownloadManager.updateResource(wordset);
ApplicationSettings.isAutomaticDownloadsEnabled = prevAutomaticDownload
}
else {
Core.showMessageDialog(main,
qsTr("The images for several activities are not yet installed. ")
+ qsTr("Do you want to download them now?"),
qsTr("Yes"),
function() {
if (DownloadManager.downloadResource(wordset))
var downloadDialog = Core.showDownloadDialog(pageView.currentItem, {});
},
qsTr("No"), function() { ApplicationSettings.wordset = '' },
null
);
}
}
}
}
ListModel {
......@@ -694,7 +729,6 @@ Item {
(ApplicationSettings.showLockedActivities != showLockedActivities)
);
}
}
......@@ -47,7 +47,6 @@ ActivityBase {
// system locale by default
property string locale: "system"
readonly property string wordsResource: "data2/words/words.rcc"
property bool englishFallback: false
property bool downloadWordsNeeded: false
......
......@@ -451,7 +451,6 @@ int ApplicationSettings::loadActivityProgress(const QString &activity)
m_config.endGroup();
qDebug() << "loaded progress for activity" << activity << ":" << progress;
return progress;
}
void ApplicationSettings::saveActivityProgress(const QString &activity, int progress)
......@@ -459,6 +458,12 @@ void ApplicationSettings::saveActivityProgress(const QString &activity, int prog
updateValueInConfig(activity, PROGRESS_KEY, progress);
}
bool ApplicationSettings::useExternalWordset()
{
return !m_wordset.isEmpty() && DownloadManager::getInstance()->isDataRegistered("words");
}
QObject *ApplicationSettings::systeminfoProvider(QQmlEngine *engine,
QJSEngine *scriptEngine)
{
......
......@@ -447,6 +447,13 @@ public:
emit lastGCVersionRanChanged();
}
/**
* Check if we use the external wordset for activity based on lang_api
* @returns true if wordset is loaded
* false if wordset is not loaded
*/
Q_INVOKABLE bool useExternalWordset();
protected slots:
Q_INVOKABLE void notifyShowLockedActivitiesChanged();
......
......@@ -121,23 +121,14 @@ Window {
// words.rcc is there -> register old file first
// then try to update in the background
if(DownloadManager.updateResource(wordset)) {
DownloadManager.resourceRegistered.connect(function() {
// not sure if needed, we check if the resource registered is the one we updated here?
if(wordset === arguments[0]) {
DownloadManager.resourceRegistered.disconnect(arguments.callee);
// force configuration to use the local wordset
ApplicationSettings.wordset = wordset
}
})
ApplicationSettings.wordset = wordset
}
} else if(ApplicationSettings.wordset) { // Only if wordset specified
// words.rcc has not been downloaded yet -> ask for download
Core.showMessageDialog(
main,
qsTr("The images for several activities are not yet installed.")
+ qsTr("Do you want to download them now?"),
qsTr("The images for several activities are not yet installed. " +
"Do you want to download them now?"),
qsTr("Yes"),
function() {
if (DownloadManager.downloadResource(wordset))
......@@ -188,30 +179,18 @@ Window {
pageView.currentItem.focus = true
checkWordset()
}
);
);
}
else {
// Register voices-resources for current locale, updates/downloads only if
// not prohibited by the settings
if (!DownloadManager.areVoicesRegistered()) {
if (DownloadManager.updateResource(
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale))) {
DownloadManager.resourceRegistered.connect(function() {
// not sure if needed, we check if the resource registered is the one we updated here?
if(DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale) === arguments[0]) {
DownloadManager.resourceRegistered.disconnect(arguments.callee);
checkWordset();
}
});
}
else {
checkWordset()
}
}
else {
checkWordset()
DownloadManager.updateResource(
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale));
}
checkWordset()
if(changelog.isNewerVersion(ApplicationSettings.lastGCVersionRan, ApplicationInfo.GCVersionCode)) {
// display log between ApplicationSettings.lastGCVersionRan and ApplicationInfo.GCVersionCode
var dialog;
......
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