diff --git a/ui/videowidget.cpp b/ui/videowidget.cpp index 50341c91f..659172a9c 100644 --- a/ui/videowidget.cpp +++ b/ui/videowidget.cpp @@ -99,6 +99,25 @@ public: double repetitionsLeft; }; +static QUrl urlFromUrlString(const QString &url, Okular::Document *document) +{ + QUrl newurl; + if ( url.startsWith( QLatin1Char( '/' ) ) ) + { + newurl = QUrl::fromLocalFile( url ); + } + else + { + newurl = QUrl( url ); + if ( newurl.isRelative() ) + { + newurl = document->currentDocument().adjusted(QUrl::RemoveFilename); + newurl.setPath( newurl.path() + url ); + } + } + return newurl; +} + void VideoWidget::Private::load() { repetitionsLeft = movie->playRepetitions(); @@ -107,21 +126,7 @@ void VideoWidget::Private::load() loaded = true; - QString url = movie->url(); - QUrl newurl; - if ( QDir::isRelativePath( url ) ) - { - newurl = document->currentDocument().adjusted(QUrl::RemoveFilename); - newurl.setPath( newurl.path() + url ); - } - else - { - newurl = QUrl::fromLocalFile(url); - } - if ( newurl.isLocalFile() ) - player->load( newurl ); - else - player->load( newurl ); + player->load( urlFromUrlString( movie->url(), document ) ); connect( player->mediaObject(), SIGNAL( stateChanged( Phonon::State, Phonon::State ) ), q, SLOT( stateChanged( Phonon::State, Phonon::State ) ) ); @@ -145,23 +150,8 @@ void VideoWidget::Private::setupPlayPauseAction( PlayPauseMode mode ) void VideoWidget::Private::takeSnapshot() { - const QString url = movie->url(); - QUrl newurl; - if ( QDir::isRelativePath( url ) ) - { - newurl = document->currentDocument().adjusted(QUrl::RemoveFilename); - newurl.setPath( newurl.path() + url ); - } - else - { - newurl = QUrl::fromLocalFile(url); - } - - SnapshotTaker *taker = 0; - if ( newurl.isLocalFile() ) - taker = new SnapshotTaker( newurl, q ); - else - taker = new SnapshotTaker( newurl, q ); + const QUrl url = urlFromUrlString( movie->url(), document ); + SnapshotTaker *taker = new SnapshotTaker( url, q ); q->connect( taker, SIGNAL( finished( const QImage& ) ), q, SLOT( setPosterImage( const QImage& ) ) ); }