From: Jeremy Paul Whiting Date: Thu, 6 Sep 2007 00:50:28 +0000 (+0000) Subject: store/read/write image and sound tags per translation X-Git-Tag: v3.94.0~74 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=4d3fda8d87daa65e9fcc9b02ccf3864f455a3c63;p=libqmvoc.git store/read/write image and sound tags per translation svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=708914 --- diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 45da085..2cbf6f7 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -84,6 +84,23 @@ bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc ) bool result = readGroups( domElementKvtml ); // read sub-groups + int defaultLessonNumber = m_doc->addLesson(i18n("Default Lesson")); + + // now make sure we don't have any orphan entries (lesson 0) + for (int i = 0; i < m_doc->entryCount(); ++i) + { + if (m_doc->entry(i)->lesson() == 0) + { + m_doc->entry(i)->setLesson(defaultLessonNumber); + m_doc->lesson(defaultLessonNumber).addEntry(i); + } + } + + if (m_doc->lesson(defaultLessonNumber).entries().size() == 0) + { + m_doc->deleteLesson(defaultLessonNumber, KEduVocDocument::DeleteEmptyLesson); + } + return result; } @@ -426,13 +443,13 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement, // image currentElement = translationElement.firstChildElement( KVTML_IMAGE ); if ( !currentElement.isNull() ) { - // TODO: do something with the image + expr.translation( index ).setImageUrl( currentElement.text() ); } // sound currentElement = translationElement.firstChildElement( KVTML_SOUND ); if ( !currentElement.isNull() ) { - // TODO: do something with the sound + expr.translation( index ).setSoundUrl( currentElement.text() ); } return true; diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 35edeb2..3ee224b 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -457,7 +457,15 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd } // image + if ( !translation.imageUrl().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_IMAGE, translation.imageUrl() ) ); + } + // sound + if ( !translation.soundUrl().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_SOUND, translation.soundUrl() ) ); + } + return true; } diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 0e93315..413b6b5 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -48,6 +48,10 @@ public: QString m_antonym; /// Pronunciation QString m_pronunciation; + /// Image url + QString m_imageUrl; + /// Sound url + QString m_soundUrl; /// Usages give a context (eg. this word is usually used in [biology]) QSet m_usages; /// Conjugations of a word (I go, you go, he goes... boring in english) @@ -96,6 +100,8 @@ KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( n d->m_multipleChoice = other.d->m_multipleChoice; d->m_grades = other.d->m_grades; d->m_falseFriends = other.d->m_falseFriends; + d->m_imageUrl = other.d->m_imageUrl; + d->m_soundUrl = other.d->m_soundUrl; } KEduVocTranslation::~KEduVocTranslation() @@ -116,6 +122,8 @@ bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) d->m_example == translation.d->m_example && d->m_antonym == translation.d->m_antonym && d->m_pronunciation == translation.d->m_pronunciation && + d->m_imageUrl == translation.d->m_imageUrl && + d->m_soundUrl == translation.d->m_soundUrl && d->m_comparison == translation.d->m_comparison && d->m_multipleChoice == translation.d->m_multipleChoice && d->m_falseFriends == translation.d->m_falseFriends && @@ -136,6 +144,8 @@ KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & d->m_example = translation.d->m_example; d->m_antonym = translation.d->m_antonym; d->m_pronunciation = translation.d->m_pronunciation; + d->m_imageUrl = translation.d->m_imageUrl; + d->m_soundUrl = translation.d->m_soundUrl; d->m_comparison = translation.d->m_comparison; d->m_multipleChoice = translation.d->m_multipleChoice; d->m_falseFriends = translation.d->m_falseFriends; @@ -346,3 +356,29 @@ QString KEduVocTranslation::irregularPlural() const return d->m_irregularPlural; } +/** get the sound url for this translation if it exists */ +QString KEduVocTranslation::soundUrl() +{ + return d->m_soundUrl; +} + +/** set the sound url for this translation + * @param url url of the sound file */ +void KEduVocTranslation::setSoundUrl(const QString &url) +{ + d->m_soundUrl = url; +} + +/** get the image url for this translation if it exists */ +QString KEduVocTranslation::imageUrl() +{ + return d->m_imageUrl; +} + +/** set the image url for this translation + * @param url url of the image + */ +void KEduVocTranslation::setImageUrl(const QString &url) +{ + d->m_imageUrl = url; +} diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index d63e04c..c88fbb5 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -234,6 +234,20 @@ public: */ void setMultipleChoice( const KEduVocMultipleChoice &mc ); + /** get the sound url for this translation if it exists */ + QString soundUrl(); + + /** set the sound url for this translation + * @param url url of the sound file */ + void setSoundUrl(const QString &url); + + /** get the image url for this translation if it exists */ + QString imageUrl(); + + /** set the image url for this translation + * @param url url of the image + */ + void setImageUrl(const QString &url); /** * Equal operator to assing a translation to another one. @@ -241,6 +255,7 @@ public: * @return reference to the new translation */ KEduVocTranslation& operator= ( const KEduVocTranslation &translation ); + /** * Compare two translations, including word type etc. * @param translation