Commit 1f8ddf5d authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Active skeleton-sync functionality again

parent fdcc05bf
......@@ -85,11 +85,18 @@ public:
{
return m_languages;
}
void updateCourseFromSkeleton(IEditableCourse *course) override
{
Q_UNUSED(course);
// do nothing
}
Q_SIGNALS:
void courseAboutToBeAdded(ICourse*,int) override;
void courseAdded() override;
void courseAboutToBeRemoved(int) override;
void courseRemoved() override;
private:
QVector<Language *> m_languages;
QVector<IEditableCourse *> m_skeletons;
......
......@@ -97,6 +97,10 @@ public:
{
return m_units.toList();
}
void addUnit(Unit *unit) override
{
m_units.append(unit);
}
QUrl file() const override
{
return QUrl();
......@@ -133,8 +137,7 @@ void TestEditorSession::createEditorSession()
Language languageEnglish;
languageEnglish.setId("en");
EditableCourseStub course(&languageGerman, QVector<Unit *>());
course.setLanguage(&languageGerman);
SkeletonResource skeleton(QUrl(), nullptr);
course.setLanguage(&languageGerman); SkeletonResource skeleton(QUrl(), nullptr);
EditableRepositoryStub repository{
{&languageGerman, &languageEnglish}, // languages
......
......@@ -22,7 +22,6 @@
#include <QTest>
#include <QSignalSpy>
#include <QObject>
#include "src/core/resourcerepository.h"
#include "src/core/language.h"
......@@ -82,5 +81,4 @@ void TestResourceRepository::iResourceRepositoryCompatability()
QCOMPARE(interface->courses(nullptr).count(), 2); // all courses in total are 2
}
QTEST_GUILESS_MAIN(TestResourceRepository)
......@@ -308,7 +308,7 @@ void ContributorRepository::reloadCourses()
emit repositoryChanged();
}
void ContributorRepository::updateCourseFromSkeleton(EditableCourseResource *course)
void ContributorRepository::updateCourseFromSkeleton(IEditableCourse *course)
{
//TODO implement status information that are shown at mainwindow
if (course->foreignId().isEmpty()) {
......@@ -328,11 +328,11 @@ void ContributorRepository::updateCourseFromSkeleton(EditableCourseResource *cou
}
// update now
foreach (Unit *unitSkeleton, skeleton->unitList()) {
for (Unit *unitSkeleton : skeleton->unitList()) {
// import unit if not exists
Unit *currentUnit = nullptr;
bool found = false;
foreach (Unit *unit, course->unitList()) {
for (Unit *unit : course->unitList()) {
if (unit->foreignId() == unitSkeleton->id()) {
found = true;
currentUnit = unit;
......@@ -346,13 +346,12 @@ void ContributorRepository::updateCourseFromSkeleton(EditableCourseResource *cou
currentUnit->setForeignId(unitSkeleton->id());
currentUnit->setCourse(course);
course->addUnit(currentUnit);
course->setModified(true);
}
// update phrases
foreach (Phrase *phraseSkeleton, unitSkeleton->phraseList()) {
for (Phrase *phraseSkeleton : unitSkeleton->phraseList()) {
bool found = false;
foreach (Phrase *phrase, currentUnit->phraseList()) {
for (Phrase *phrase : currentUnit->phraseList()) {
if (phrase->foreignId() == phraseSkeleton->id()) {
if (phrase->i18nText() != phraseSkeleton->text()) {
phrase->setEditState(Phrase::Unknown);
......@@ -371,12 +370,10 @@ void ContributorRepository::updateCourseFromSkeleton(EditableCourseResource *cou
newPhrase->setType(phraseSkeleton->type());
newPhrase->setUnit(currentUnit);
currentUnit->addPhrase(newPhrase);
course->setModified(true);
}
}
}
// FIXME deassociate removed phrases
qCDebug(ARTIKULATE_LOG) << "Update performed!";
}
......
......@@ -115,12 +115,7 @@ public:
*/
void reloadCourses() override;
/**
* Imports units and phrases from skeleton, deassociates removed ones.
*
* \param course the course to be update
*/
void updateCourseFromSkeleton(EditableCourseResource *course);
void updateCourseFromSkeleton(IEditableCourse *course) override;
/**
* Add language to resource manager by parsing the given language specification file.
......
......@@ -250,5 +250,5 @@ void EditorSession::updateCourseFromSkeleton()
qCritical() << "Not updating course from skeleton, no one set.";
return;
}
// m_resourceManager->updateCourseFromSkeleton(m_course); //FIXME
m_repository->updateCourseFromSkeleton(m_course);
}
......@@ -42,6 +42,7 @@ public:
virtual void setI18nTitle(QString title) = 0;
virtual void setDescription(QString description) = 0;
virtual void setLanguage(Language *language) = 0;
virtual void addUnit(Unit *unit) = 0;
};
Q_DECLARE_INTERFACE(IEditableCourse, "com.kde.artikulate.IEditableCourse/1.0")
......
......@@ -40,6 +40,12 @@ public:
virtual QVector<IEditableCourse *> editableCourses() const = 0;
virtual IEditableCourse * editableCourse(Language *language, int index) const = 0;
virtual QVector<IEditableCourse *> skeletons() const = 0;
/**
* Imports units and phrases from skeleton, deassociates removed ones.
*
* \param course the course to be updated
*/
virtual void updateCourseFromSkeleton(IEditableCourse *course) = 0;
};
Q_DECLARE_INTERFACE(IEditableRepository, "IEditableRepository")
......
......@@ -158,6 +158,7 @@ bool EditableCourseResource::exportCourse(const QUrl &filePath)
void EditableCourseResource::addUnit(Unit *unit)
{
m_course->addUnit(unit);
setModified(true);
}
bool EditableCourseResource::isModified() const
......
......@@ -107,11 +107,10 @@ public:
*/
bool exportCourse(const QUrl &filePath);
void addUnit(Unit *);
void addUnit(Unit *unit) override;
bool isModified() const;
void setModified(bool modified); //TODO this method should not be public API but only used internally
QUrl file() const override;
......@@ -132,6 +131,7 @@ Q_SIGNALS:
private:
Q_DISABLE_COPY(EditableCourseResource)
void setModified(bool modified);
bool m_modified{ false };
const std::unique_ptr<CourseResource> m_course;
};
......
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