diff --git a/src/core/editorsession.cpp b/src/core/editorsession.cpp index c28cd82..77a79ca 100644 --- a/src/core/editorsession.cpp +++ b/src/core/editorsession.cpp @@ -1,258 +1,255 @@ /* * Copyright 2013-2015 Andreas Cord-Landwehr * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . */ #include "editorsession.h" #include "core/language.h" #include "core/resources/editablecourseresource.h" #include "core/resources/skeletonresource.h" #include "core/unit.h" #include "core/iunit.h" #include "core/phrase.h" #include "core/trainingaction.h" #include "core/contributorrepository.h" #include "artikulate_debug.h" EditorSession::EditorSession(QObject *parent) : ISessionActions(parent) { connect(this, &EditorSession::courseChanged, this, &EditorSession::skeletonModeChanged); } void EditorSession::setRepository(IEditableRepository *repository) { m_repository = repository; } bool EditorSession::skeletonMode() const { for (const auto &skeleton : m_repository->skeletons()) { if (skeleton->id() == m_course->id()) { return true; } } return false; } ILanguage * EditorSession::language() const { if (m_course && m_course->language()) { return m_course->language().get(); } return nullptr; } IEditableCourse *EditorSession::course() const { return m_course; } void EditorSession::setCourse(IEditableCourse *course) { if (m_course == course) { return; } m_course = course; updateTrainingActions(); emit languageChanged(); emit courseChanged(); } IUnit * EditorSession::activeUnit() const { if (auto phrase = activePhrase()) { return phrase->unit().get(); } return nullptr; } void EditorSession::setActiveUnit(IUnit *unit) { // checking phrases in increasing order ensures that always the first phrase is selected for (int i = 0; i < m_actions.count(); ++i) { for (int j = 0; j < m_actions.at(i)->actions().count(); ++j) { const auto testPhrase = qobject_cast(m_actions.at(i)->actions().at(j))->phrase(); if (unit == testPhrase->unit().get()) { if (auto action = activeAction()) { action->setChecked(false); } m_indexUnit = i; m_indexPhrase = j; if (auto action = activeAction()) { action->setChecked(true); } emit phraseChanged(); return; } } } } void EditorSession::setActivePhrase(IPhrase * phrase) { for (int i = 0; i < m_actions.count(); ++i) { for (int j = 0; j < m_actions.at(i)->actions().count(); ++j) { const auto testPhrase = qobject_cast(m_actions.at(i)->actions().at(j))->phrase(); if (phrase == testPhrase) { if (auto action = activeAction()) { action->setChecked(false); } m_indexUnit = i; m_indexPhrase = j; if (auto action = activeAction()) { action->setChecked(true); } emit phraseChanged(); return; } } } } IPhrase * EditorSession::activePhrase() const { if (const auto action = activeAction()) { return action->phrase(); } return nullptr; } void EditorSession::switchToPreviousPhrase() { if (hasPreviousPhrase()) { if (m_indexPhrase == 0) { qCDebug(ARTIKULATE_CORE()) << "switching to previous unit"; if (m_indexUnit > 0) { --m_indexUnit; m_indexPhrase = m_actions.at(m_indexUnit)->actions().count() - 1; } } else { --m_indexPhrase; } if (auto action = activeAction()) { action->setChecked(true); } emit phraseChanged(); } else { qCWarning(ARTIKULATE_CORE()) << "The is no previous phrase, aborting"; } } void EditorSession::switchToNextPhrase() { if (hasNextPhrase()) { if (m_indexPhrase >= m_actions.at(m_indexUnit)->actions().count() - 1) { qCDebug(ARTIKULATE_CORE()) << "switching to next unit"; if (m_indexUnit < m_actions.count() - 1) { ++m_indexUnit; m_indexPhrase = 0; } } else { ++m_indexPhrase; } if (auto action = activeAction()) { action->setChecked(true); } emit phraseChanged(); } else { qCWarning(ARTIKULATE_CORE()) << "The is no next phrase, aborting"; } } bool EditorSession::hasPreviousPhrase() const { return m_indexUnit > 0 || m_indexPhrase > 0; } bool EditorSession::hasNextPhrase() const { if (m_indexUnit < m_actions.count() - 1) { return true; } if (m_actions.constLast()) { if (m_indexPhrase < m_actions.constLast()->actions().count() - 1) { return true; } } return false; } void EditorSession::updateCourseFromSkeleton() { if (!m_course) { qCritical() << "Not updating course from skeleton, no one set."; return; } m_repository->updateCourseFromSkeleton(m_course->self()); } TrainingAction * EditorSession::activeAction() const { if (m_indexUnit < 0 || m_indexPhrase < 0) { return nullptr; } return qobject_cast(m_actions.at(m_indexUnit)->actions().at(m_indexPhrase)); } void EditorSession::updateTrainingActions() { for (const auto &action : qAsConst(m_actions)) { action->deleteLater(); } m_actions.clear(); if (!m_course) { m_indexUnit = -1; m_indexPhrase = -1; return; } const auto unitList = m_course->units(); for (const auto &unit : qAsConst(unitList)) { auto action = new TrainingAction(unit->title(), this); const auto phraseList = unit->phrases(); for (const auto &phrase : qAsConst(phraseList)) { - if (phrase->sound().isEmpty()) { - continue; - } action->appendChild(new TrainingAction(phrase, this, unit.get())); } if (action->hasChildren()) { m_actions.append(action); } else { action->deleteLater(); } } // update indices m_indexUnit = -1; m_indexPhrase = -1; if (m_course->units().count() > 0) { m_indexUnit = 0; if (m_course->units().constFirst()->phrases().count() > 0) { m_indexPhrase = 0; } } } QVector EditorSession::trainingActions() const { return m_actions; } diff --git a/src/qml/CourseConfigurationPage.qml b/src/qml/CourseConfigurationPage.qml index d34ccf8..1407ed0 100644 --- a/src/qml/CourseConfigurationPage.qml +++ b/src/qml/CourseConfigurationPage.qml @@ -1,90 +1,90 @@ /* * Copyright 2019 Andreas Cord-Landwehr * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 . */ import QtQuick 2.1 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.4 import QtQuick.Dialogs 1.2 import org.kde.kirigami 2.7 as Kirigami Kirigami.Page { id: root title: g_editorSession.skeletonMode ? i18n("Prototype Configuration") : i18n("Course Configuration") Kirigami.FormLayout { anchors.fill: parent Kirigami.Separator { Kirigami.FormData.label: g_editorSession.skeletonMode ? i18n("Prototype Description") : i18n("Course Description") Kirigami.FormData.isSection: true } TextField { Kirigami.FormData.label: i18n("Title:") text: g_editorSession.course.title Layout.preferredWidth: .7 * root.width onAccepted: g_editorSession.course.title = text } TextField { visible: !g_editorSession.skeletonMode Kirigami.FormData.label: i18n("Localized Title:") text: g_editorSession.course.i18nTitle Layout.preferredWidth: .7 * root.width onAccepted: g_editorSession.course.i18nTitle = text } TextField { Kirigami.FormData.label: i18n("Description:") text: g_editorSession.course.description Layout.preferredWidth: .7 * root.width onAccepted: g_editorSession.course.description = text } TextField { visible: !g_editorSession.skeletonMode Kirigami.FormData.label: i18n("Language:") text: g_editorSession.course.languageTitle readOnly: true Layout.preferredWidth: .7 * root.width } Kirigami.Separator { visible: !g_editorSession.skeletonMode Kirigami.FormData.label: i18n("Prototype") Kirigami.FormData.isSection: true } Button { visible: !g_editorSession.skeletonMode Kirigami.FormData.label: i18n("Update from Prototype:") - enabled: g_editorSession.isSkeletonMode + enabled: g_editorSession.skeletonMode Layout.minimumWidth: 200 text: i18n("Update") icon.name: "view-refresh" ToolTip.visible: hovered ToolTip.delay: 1000 ToolTip.timeout: 5000 ToolTip.text: i18n("Update the course with elements from prototype.") onClicked: g_editorSession.updateCourseFromSkeleton() } // TODO add export functionalities // Kirigami.Separator { // Kirigami.FormData.label: i18n("Export") // Kirigami.FormData.isSection: true // } } }