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
// 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;
// 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;
}
/// 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)
}
/** 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;
}
/** 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;
}
#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;
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.
* @return reference to the new translation
*/
KEduVocTranslation& operator= ( const KEduVocTranslation &translation );
-
+
/**
* Compare two translations, including word type etc.
* @param translation