]> Git trees. - libqmvoc.git/commitdiff
store/read/write image and sound tags per translation
authorJeremy Paul Whiting <jpwhiting@kde.org>
Thu, 6 Sep 2007 00:50:28 +0000 (00:50 +0000)
committerJeremy Paul Whiting <jpwhiting@kde.org>
Thu, 6 Sep 2007 00:50:28 +0000 (00:50 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=708914

keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvoctranslation.cpp
keduvocdocument/keduvoctranslation.h

index 45da08573b2c20e36a0e78d00d2df2b80dfa4bc1..2cbf6f72540684a35669945fad48ccc4904f0ab0 100644 (file)
@@ -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;
index 35edeb2faddd2453460ca0b09b2bc8cd3d4229a9..3ee224b22efd83c6482378a262aa0da14064fab2 100644 (file)
@@ -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;
 }
index 0e933158467e8f2728e08718ac6d92d3a8d9e31a..413b6b55ceb5059b15c32a964502b15eec2d1b3a 100644 (file)
@@ -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<QString> 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;
+}
index d63e04c3d8826c491f7f0b9395c05f41912192aa..c88fbb54b2c6c73dc685d6c31b75d40dee038d81 100644 (file)
@@ -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