Commit 970cd8d7 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Merge branch 'Applications/16.04'

parents 97e8c985 543d2b5b
......@@ -232,20 +232,21 @@ QList< LearningGoal* > ProfileManager::goals() const
return d->m_goals;
}
void ProfileManager::registerGoal(LearningGoal::Category category,
LearningGoal * ProfileManager::registerGoal(LearningGoal::Category category,
const QString &identifier,
const QString &name)
{
// test whether goal is already registered
foreach (LearningGoal *cmpGoal, d->m_goals) {
if (cmpGoal->category() == category && cmpGoal->identifier() == identifier) {
return;
return cmpGoal;
}
}
LearningGoal *goal = new LearningGoal(category, identifier, this);
goal->setName(name);
d->m_goals.append(goal);
d->m_storage.storeGoal(goal);
return goal;
}
LearnerProfile::LearningGoal * LearnerProfile::ProfileManager::goal(
......@@ -253,15 +254,10 @@ LearnerProfile::LearningGoal * LearnerProfile::ProfileManager::goal(
const QString& identifier) const
{
foreach (LearningGoal *goal, d->m_goals) {
if (goal->category() != category) {
continue;
if (goal->category() == category && goal->identifier() == identifier) {
return goal;
}
if (goal->identifier() != identifier) {
continue;
}
return goal;
}
qCWarning(LIBLEARNER_LOG) << "no goal found for:" << category << identifier;
return nullptr;
}
......@@ -277,6 +273,9 @@ void ProfileManager::recordProgress(Learner *learner,
QHash<QString, int> ProfileManager::progressValues(Learner *learner, LearningGoal *goal,
const QString &container) const
{
if (!learner || !goal) {
return QHash<QString, int>();
}
return d->m_storage.readProgressValues(learner, goal, container);
}
......
......@@ -60,7 +60,7 @@ public:
* Register learning goal if not registered yet. The registered goals will be stored at the
* internal database.
*/
void registerGoal(LearningGoal::Category category, const QString &identifier, const QString &name);
LearningGoal * registerGoal(LearningGoal::Category category, const QString &identifier, const QString &name);
LearningGoal * goal(LearningGoal::Category category, const QString &identifier) const;
/**
* updates current learning goal by activity, adds new learning goal if necessary,
......
......@@ -180,17 +180,6 @@ bool ResourceManager::modified() const
return false;
}
void ResourceManager::registerLearningGoals(LearnerProfile::ProfileManager *profileManger)
{
foreach (LanguageResource *languageResource, languageResources()) {
profileManger->registerGoal(
LearnerProfile::LearningGoal::Language,
languageResource->language()->id(),
languageResource->language()->i18nTitle()
);
}
}
void ResourceManager::addLanguage(const QUrl &languageFile)
{
if (m_loadedResources.contains(languageFile.toLocalFile())) {
......
......@@ -78,14 +78,6 @@ public:
*/
bool modified() const;
/**
* Register loaded languages as learning goals in profile manager.
*
* TODO this should not be done by explicit call, but by putting data at shared data storage
* for profile manager
*/
void registerLearningGoals(LearnerProfile::ProfileManager *profileManger);
/**
* \return \c true if a repository is used, else \c false
*/
......
......@@ -57,8 +57,6 @@ void TrainingSession::setLanguage(Language *language)
if (m_language == language) {
return;
}
setCourse(nullptr);
setUnit(nullptr);
m_language = language;
emit languageChanged();
}
......@@ -70,6 +68,9 @@ Course * TrainingSession::course() const
void TrainingSession::setCourse(Course *course)
{
if (!course) {
return;
}
if (m_course == course) {
return;
}
......@@ -81,6 +82,13 @@ void TrainingSession::setCourse(Course *course)
// lazy loading of training data
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
if (!goal) {
goal = m_profileManager->registerGoal(
LearnerProfile::LearningGoal::Language,
course->language()->id(),
course->language()->i18nTitle()
);
}
auto data = m_profileManager->progressValues(m_profileManager->activeProfile(),
goal,
m_course->id()
......@@ -155,7 +163,7 @@ void TrainingSession::showNextPhrase()
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
......@@ -175,7 +183,7 @@ void TrainingSession::skipPhrase()
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
......@@ -204,7 +212,7 @@ void TrainingSession::updateGoal()
return;
}
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
learner->addGoal(goal);
learner->setActiveGoal(goal);
}
......@@ -67,7 +67,6 @@ MainWindow::MainWindow()
qFatal("No language resources found, cannot start application.");
}
m_resourceManager->loadCourseResources();
m_resourceManager->registerLearningGoals(m_profileManager);
m_trainingSession->setProfileManager(m_profileManager);
// create menu
......
......@@ -78,7 +78,7 @@ ApplicationWindow {
TreeView {
id: phraseTree
Layout.preferredWidth: Math.floor(main.width * 0.3)
implicitWidth: Math.floor(root.width * 0.3)
Layout.fillHeight: true
TableViewColumn {
title: i18n("Categories")
......@@ -179,7 +179,7 @@ ApplicationWindow {
Loader {
Layout.fillHeight: true
sourceComponent: {
g_trainingSession.language == null && courseFilterModel.filteredCount == 0
g_trainingSession.language == null
? welcomeScreen
: trainingScreen
}
......
......@@ -22,6 +22,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2
import QtQuick.Controls.Styles 1.4
import artikulate 1.0
Item {
......@@ -78,13 +79,16 @@ Item {
text: (g_trainingSession.phrase != null) ? g_trainingSession.phrase.text : ""
wrapMode: Text.WordWrap
readOnly: true
backgroundVisible: false
horizontalAlignment: Text.AlignHCenter
style: TextAreaStyle {
backgroundColor: trainingTextRect.color
}
}
SoundPlayer {
id: buttonNativePlay
anchors {
bottom: trainingTextRect.bottom
leftMargin: theme.spacing
horizontalCenter: parent.horizontalCenter
bottomMargin: theme.spacing
}
text: i18n("Listen")
......
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