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

Re-integrate course update

parent 87eb2daa
......@@ -49,7 +49,10 @@ public:
{
m_self = self;
}
std::shared_ptr<IEditableCourse> self() const override
{
return std::static_pointer_cast<IEditableCourse>(m_self.lock());
}
QString id() const override
{
return m_id;
......
......@@ -304,58 +304,9 @@ void ContributorRepository::updateCourseFromSkeleton(std::shared_ptr<IEditableCo
}
if (!skeleton) {
qCritical() << "Could not find skeleton with id " << course->foreignId() << ", aborting update.";
return;
} else {
course->updateFrom(skeleton);
}
// FIXME memory handling logic is broken
// // update now
// for (Unit *unitSkeleton : skeleton->unitList()) {
// // import unit if not exists
// std::unique_ptr<Unit> currentUnit(new Unit);
// bool found = false;
// for (Unit *unit : course->unitList()) {
// if (unit->foreignId() == unitSkeleton->id()) {
// found = true;
// currentUnit = unit;
// break;
// }
// }
// if (found == false) {
// currentUnit = new Unit(course);
// currentUnit->setId(QUuid::createUuid().toString());
// currentUnit->setTitle(unitSkeleton->title());
// currentUnit->setForeignId(unitSkeleton->id());
// currentUnit->setCourse(course);
// course->addUnit(std::move(currentUnit));
// }
// // update phrases
// for (Phrase *phraseSkeleton : unitSkeleton->phraseList()) {
// bool found = false;
// for (Phrase *phrase : currentUnit->phraseList()) {
// if (phrase->foreignId() == phraseSkeleton->id()) {
// if (phrase->i18nText() != phraseSkeleton->text()) {
// phrase->setEditState(Phrase::Unknown);
// phrase->seti18nText(phraseSkeleton->text());
// }
// found = true;
// break;
// }
// }
// if (found == false) {
// Phrase *newPhrase = new Phrase(course);
// newPhrase->setForeignId(phraseSkeleton->id());
// newPhrase->setId(QUuid::createUuid().toString());
// newPhrase->setText(phraseSkeleton->text());
// newPhrase->seti18nText(phraseSkeleton->text());
// newPhrase->setType(phraseSkeleton->type());
// newPhrase->setUnit(currentUnit.get());
// currentUnit->addPhrase(newPhrase);
// }
// }
// }
// FIXME deassociate removed phrases
qCDebug(ARTIKULATE_LOG) << "Update performed!";
}
std::shared_ptr<EditableCourseResource> ContributorRepository::addCourse(const QUrl &courseFile)
......
......@@ -332,6 +332,5 @@ void EditorSession::updateCourseFromSkeleton()
qCritical() << "Not updating course from skeleton, no one set.";
return;
}
//FIXME convert to interface
// m_repository->updateCourseFromSkeleton(m_course);
m_repository->updateCourseFromSkeleton(m_course->self());
}
......@@ -59,6 +59,7 @@ public:
*/
virtual void updateFrom(std::shared_ptr<ICourse> skeleton) = 0;
virtual bool isModified() const = 0;
virtual std::shared_ptr<IEditableCourse> self() const = 0;
protected:
IEditableCourse()
......
......@@ -96,6 +96,11 @@ void CourseResource::setSelf(std::shared_ptr<ICourse> self)
d->m_self = self;
}
std::shared_ptr<ICourse> CourseResource::self() const
{
return d->m_self.lock();
}
CourseResource::CourseResource(const QUrl &path, IResourceRepository *repository)
: ICourse()
, d(new CourseResourcePrivate())
......
......@@ -109,6 +109,7 @@ private:
*/
explicit CourseResource(const QUrl &path, IResourceRepository *repository);
void setSelf(std::shared_ptr<ICourse> self) override;
std::shared_ptr<ICourse> self() const;
const std::unique_ptr<CourseResourcePrivate> d;
friend EditableCourseResource;
......
......@@ -66,9 +66,15 @@ std::shared_ptr<EditableCourseResource> EditableCourseResource::create(
return course;
}
void EditableCourseResource::setSelf(std::shared_ptr<ICourse> self) { m_course->setSelf(self); }
void EditableCourseResource::setSelf(std::shared_ptr<ICourse> self)
{
m_course->setSelf(self);
}
QString EditableCourseResource::id() const { return m_course->id(); }
QString EditableCourseResource::id() const
{
return m_course->id();
}
void EditableCourseResource::setId(QString id)
{
......@@ -125,7 +131,15 @@ void EditableCourseResource::setLanguage(std::shared_ptr<ILanguage> language)
}
}
QUrl EditableCourseResource::file() const { return m_course->file(); }
QUrl EditableCourseResource::file() const
{
return m_course->file();
}
std::shared_ptr<IEditableCourse> EditableCourseResource::self() const
{
return std::static_pointer_cast<IEditableCourse>(m_course->self());
}
bool EditableCourseResource::sync()
{
......
......@@ -99,6 +99,7 @@ public:
void updateFrom(std::shared_ptr<ICourse> course) override;
bool isModified() const override;
QUrl file() const override;
std::shared_ptr<IEditableCourse> self() const override;
Q_INVOKABLE Unit * createUnit();
Q_INVOKABLE Phrase * createPhrase(Unit *unit);
......
......@@ -218,6 +218,11 @@ void SkeletonResource::setSelf(std::shared_ptr<ICourse> self)
d->m_self = self;
}
std::shared_ptr<IEditableCourse> SkeletonResource::self() const
{
return std::static_pointer_cast<IEditableCourse>(d->m_self.lock());
}
QString SkeletonResource::id() const
{
return d->m_identifier;
......
......@@ -58,8 +58,9 @@ public:
bool exportToFile(const QUrl &filePath) const override;
std::shared_ptr<Unit> addUnit(std::unique_ptr<Unit> unit) override;
bool sync() override;
void updateFrom(std::shared_ptr<ICourse>);
void updateFrom(std::shared_ptr<ICourse>) override;
bool isModified() const override;
std::shared_ptr<IEditableCourse> self() const;
private:
/**
......
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