From: Frederik Gladhorn Date: Fri, 21 Sep 2007 07:29:54 +0000 (+0000) Subject: Better url handling for sound/image. X-Git-Tag: v3.94.0~29 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=e2dd933d2122eda927f5d029916720562f01d43d;p=libqmvoc.git Better url handling for sound/image. 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 --- diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 9f08177..ab9780a 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -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; diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 0704ac3..a962d47 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -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; } diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 2d21f34..7a5db65 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -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 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; } diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index c88fbb5..f70cfe7 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -18,12 +18,12 @@ #define KEDUVOCTRANSLATION_H #include "libkeduvocdocument_export.h" - -#include - #include "keduvocgrammar.h" #include "keduvocconjugation.h" #include "keduvocmultiplechoice.h" +#include +#include + 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