]> git.sesse.net Git - vlc/commitdiff
qt4: make dnd to accepts network-urls
authorIlkka Ollakka <ileoo@videolan.org>
Thu, 10 Jun 2010 19:03:59 +0000 (22:03 +0300)
committerIlkka Ollakka <ileoo@videolan.org>
Thu, 10 Jun 2010 19:10:22 +0000 (22:10 +0300)
drop toNativeSeparators-usage (shoudln't break win32, but then again this could
be my application for the 'stupid win32 breakage of the year' ;). This allows
for example drag youtube links to vlc playlist directly.

Parse also dropper text if it has valid url if we don't have urls on drop ( from browser addressbar for example you get text ).

modules/gui/qt4/main_interface.cpp

index 93588b4facd05a70dc930c9457cb72961c9d59a1..1a86e3478091d3204731fec25fc1ebaf7b40ab73 100644 (file)
@@ -1040,8 +1040,9 @@ void MainInterface::dropEvent(QDropEvent *event)
 
 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
 {
-    event->setDropAction( Qt::CopyAction );
-    if( !event->possibleActions() & Qt::CopyAction )
+    if( event->possibleActions() & Qt::CopyAction )
+       event->setDropAction( Qt::CopyAction );
+    else
         return;
 
     const QMimeData *mimeData = event->mimeData();
@@ -1061,18 +1062,30 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
     bool first = b_play;
     foreach( const QUrl &url, mimeData->urls() )
     {
-        QString s = toNativeSeparators( url.toLocalFile() );
-
-        if( s.length() > 0 ) {
-            char* psz_uri = make_URI( qtu(s) );
+        if( url.isValid() )
+        {
+            char* psz_uri = make_URI( qtu( url.toString() ) );
             playlist_Add( THEPL, psz_uri, NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
                           PLAYLIST_END, true, pl_Unlocked );
             free( psz_uri );
             first = false;
-            RecentsMRL::getInstance( p_intf )->addRecent( s );
+            RecentsMRL::getInstance( p_intf )->addRecent( url.toString() );
         }
     }
+
+    /* 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() )
+    {
+        char *psz_uri = make_URI( qtu( mimeData->text() ) );
+        playlist_Add( THEPL, psz_uri, NULL,
+                      PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
+                      PLAYLIST_END, true, pl_Unlocked );
+        free( psz_uri );
+    }
     event->accept();
 }
 void MainInterface::dragEnterEvent(QDragEnterEvent *event)