[vlc-devel] [PATCH 1/3] gui/qt: refactor handling of drag-drop-play
Filip Roséen
filip at atch.se
Thu Jan 12 19:34:40 CET 2017
The previous implementation contained duplicate functionality in
different code-paths, as well as suffering from a bug where a
potential subtitle-drop would not be probed for such.
These changes simplifies the implementation, as well as making sure
that we treat a drop of one (1) URL the same, no matter if the
mime-type is stating that it is a URI, or text/* (such as when dragged
from a web browser).
One should also be able to drag-and-drop entities that are referring
to non-local entities, as such that check has been removed.
refs #17657
---
modules/gui/qt/main_interface.cpp | 64 ++++++++++++---------------------------
1 file changed, 19 insertions(+), 45 deletions(-)
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 894da7afd6..810fdbdf8d 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -1420,58 +1420,32 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play, bool b_playli
else
return;
- const QMimeData *mimeData = event->mimeData();
+ QMimeData const* md = event->mimeData();
+ QList<QUrl> urls = md->urls();
- /* D&D of a subtitles file, add it on the fly */
- if( mimeData->urls().count() == 1 && THEMIM->getIM()->hasInput() )
- {
- if( !input_AddSubtitleOSD( THEMIM->getInput(),
- qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
- true, true ) )
- {
- event->accept();
- return;
- }
- }
+ if( urls.count() == 0 && md->hasText() )
+ urls << QUrl( md->text() );
- bool first = b_play;
- foreach( const QUrl &url, mimeData->urls() )
+ if( urls.count() == 1 && urls.back().isValid() &&
+ input_AddSubtitleOSD( THEMIM->getInput(),
+ qtu( urls.back().toString( QUrl::FullyEncoded ) ),
+ true, true ) == VLC_SUCCESS )
{
- if( url.isValid() )
- {
- QString mrl = toURI( url.toEncoded().constData() );
- QFileInfo info( url.toLocalFile() );
- if( info.exists() && info.isSymLink() )
- {
- QString target = info.symLinkTarget();
- QUrl url;
- if( QFile::exists( target ) )
- {
- url = QUrl::fromLocalFile( target );
- }
- else
- {
- url.setUrl( target );
- }
- mrl = toURI( url.toEncoded().constData() );
- }
- if( mrl.length() > 0 )
- {
- Open::openMRL( p_intf, mrl, first, b_playlist );
- first = false;
- }
- }
+ event->accept();
+ return;
}
- /* Browsers give content as text if you dnd the addressbar,
- so check if mimedata has valid url in text and use it
- if we didn't get any normal Urls()*/
- if( !mimeData->hasUrls() && mimeData->hasText() &&
- QUrl(mimeData->text()).isValid() )
+ foreach( const QUrl& url, urls )
{
- QString mrl = toURI( mimeData->text() );
- Open::openMRL( p_intf, mrl, first, b_playlist );
+ if( url.isValid() == false )
+ continue;
+
+ Open::openMRL( p_intf, url.toString( QUrl::FullyEncoded ),
+ b_play, b_playlist );
+
+ b_play = false; /* only immediately play the first entry */
}
+
event->accept();
}
void MainInterface::dragEnterEvent(QDragEnterEvent *event)
--
2.11.0
More information about the vlc-devel
mailing list