]> Git trees. - libqmvoc.git/commitdiff
Better url handling for sound/image.
authorFrederik Gladhorn <gladhorn@kde.org>
Fri, 21 Sep 2007 07:29:54 +0000 (07:29 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Fri, 21 Sep 2007 07:29:54 +0000 (07:29 +0000)
Use KUrl internally, only save as relative path, when the sound/image is in the same or a subdir of the document.
Move handling of relative urls into the lib.

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=715072

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

index 9f081770b5242daeb19c06abe82e6308d508947f..ab9780a0a929c06d240304e8c08b4d019abb639d 100644 (file)
@@ -421,13 +421,13 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
     // image
     currentElement = translationElement.firstChildElement( KVTML_IMAGE );
     if ( !currentElement.isNull() ) {
-        expr.translation( index ).setImageUrl( currentElement.text() );
+        expr.translation( index ).setImageUrl( KUrl( m_doc->url(), currentElement.text() ) );
     }
 
     // sound
     currentElement = translationElement.firstChildElement( KVTML_SOUND );
     if ( !currentElement.isNull() ) {
-        expr.translation( index ).setSoundUrl( currentElement.text() );
+        expr.translation( index ).setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) );
     }
 
     return true;
index 0704ac3fb95c5f4261e452aa20ccd6061d8e6573..a962d474a04b2202773a11b595b0039898c926d6 100644 (file)
@@ -456,15 +456,28 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
 
     // image
     if ( !translation.imageUrl().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_IMAGE, translation.imageUrl() ) );
+        QString urlString;
+        if ( translation.imageUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
+            // try to save as relative url
+            urlString = KUrl::relativeUrl( m_doc->url() , translation.imageUrl() );
+        } else {
+            urlString =  translation.imageUrl().url();
+        }
+        translationElement.appendChild( newTextElement( KVTML_IMAGE, urlString ) );
     }
 
     // sound
     if ( !translation.soundUrl().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_SOUND, translation.soundUrl() ) );
+        QString urlString;
+        if ( translation.soundUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
+            // try to save as relative url
+            urlString = KUrl::relativeUrl( m_doc->url() , translation.soundUrl() );
+        } else {
+            urlString =  translation.soundUrl().url();
+        }
+        translationElement.appendChild( newTextElement( KVTML_SOUND, urlString ) );
     }
 
-
     return true;
 }
 
index 2d21f346cf979a41f4cc1ac10921018e10c7e8c5..7a5db65b308555dc0ed5dafb942a7fd95b4d3ac6 100644 (file)
@@ -48,9 +48,9 @@ public:
     /// Pronunciation
     QString m_pronunciation;
     /// Image url
-    QString m_imageUrl;
+    KUrl m_imageUrl;
     /// Sound url
-    QString m_soundUrl;
+    KUrl m_soundUrl;
     /// Usages give a context (eg. this word is usually used in [biology])
     QSet<QString> m_usages;
     /// When creating multiple choice tests, these are possible answers. (otherwise other words are added randomly)
@@ -348,20 +348,20 @@ void KEduVocTranslation::setConjugations(const QMap< QString, KEduVocConjugation
 }
 
 /** get the sound url for this translation if it exists */
-QString KEduVocTranslation::soundUrl()
+KUrl 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)
+void KEduVocTranslation::setSoundUrl(const KUrl &url)
 {
     d->m_soundUrl = url;
 }
 
 /** get the image url for this translation if it exists */
-QString KEduVocTranslation::imageUrl()
+KUrl KEduVocTranslation::imageUrl()
 {
     return d->m_imageUrl;
 }
@@ -369,7 +369,7 @@ QString KEduVocTranslation::imageUrl()
 /** set the image url for this translation
  * @param url               url of the image
  */
-void KEduVocTranslation::setImageUrl(const QString &url)
+void KEduVocTranslation::setImageUrl(const KUrl &url)
 {
     d->m_imageUrl = url;
 }
index c88fbb54b2c6c73dc685d6c31b75d40dee038d81..f70cfe7df3cfd278cb24bdca633e20b32b0ccdec 100644 (file)
 #define KEDUVOCTRANSLATION_H
 
 #include "libkeduvocdocument_export.h"
-
-#include <QtCore/QString>
-
 #include "keduvocgrammar.h"
 #include "keduvocconjugation.h"
 #include "keduvocmultiplechoice.h"
+#include <KUrl>
+#include <QtCore/QString>
+
 
 class KEduVocGrade;
 
@@ -235,19 +235,19 @@ public:
     void setMultipleChoice( const KEduVocMultipleChoice &mc );
 
     /** get the sound url for this translation if it exists */
-    QString soundUrl();
-    
+    KUrl soundUrl();
+
     /** set the sound url for this translation
      * @param url               url of the sound file */
-    void setSoundUrl(const QString &url);
-    
+    void setSoundUrl(const KUrl &url);
+
     /** get the image url for this translation if it exists */
-    QString imageUrl();
-    
-    /** set the image url for this translation 
+    KUrl imageUrl();
+
+    /** set the image url for this translation
      * @param url               url of the image
      */
-    void setImageUrl(const QString &url);
+    void setImageUrl(const KUrl &url);
 
     /**
      * Equal operator to assing a translation to another one.
@@ -255,7 +255,7 @@ public:
      * @return reference to the new translation
      */
     KEduVocTranslation& operator= ( const KEduVocTranslation &translation );
-    
+
     /**
      * Compare two translations, including word type etc.
      * @param translation