]> git.sesse.net Git - vlc/commitdiff
skins(Linux): add support for multiple files in drag&drap
authorErwan Tulou <erwan10@videolan.org>
Sun, 11 Apr 2010 19:39:08 +0000 (21:39 +0200)
committerErwan Tulou <erwan10@videolan.org>
Sun, 11 Apr 2010 19:49:05 +0000 (21:49 +0200)
selection is made of several items separated with '\n' and terminated with a final '\0'. When selection is limited to one item, the '\n' is missing.

modules/gui/skins2/x11/x11_dragdrop.cpp

index 6e9fc78497e148ad7de278199dfcdf33e1bab19a..ff327e747658e7c0bf66a2898d27d9f90a3f7bd2 100644 (file)
@@ -163,35 +163,24 @@ void X11DragDrop::dndDrop( ldata_t data )
     XGetWindowProperty( XDISPLAY, src, propAtom, 0, 1024, False,
                         AnyPropertyType, &type, &format, &nitems, &nbytes,
                         (unsigned char**)&buffer );
-    string selection = "";
-    if( buffer != NULL )
-    {
-        selection = buffer;
-        XFree( buffer );
-    }
 
-    if( selection != "" )
+    if( buffer != NULL )
     {
-        // TODO: multiple files handling
-        string::size_type end = selection.find( "\n", 0 );
-        selection = selection.substr( 0, end - 1 );
-        end = selection.find( "\r", 0 );
-        selection = selection.substr( 0, end - 1 );
-
-        // Find the protocol, if any
-        if( selection.find( "file://", 0 ) == 0 )
+        char* psz_dup = strdup( buffer );
+        char* psz_new = psz_dup;
+        while( psz_new && *psz_new )
         {
-            selection.erase( 0, 7 );
-        }
-
-        char *psz_fileName = new char[selection.size() + 1];
-        strncpy( psz_fileName, selection.c_str(), selection.size() + 1 );
+            char* psz_end = strchr( psz_new, '\n' );
+            if( psz_end )
+                *psz_end = '\0';
 
-        // Add the file
-        CmdAddItem cmd( getIntf(), psz_fileName, m_playOnDrop );
-        cmd.execute();
+            CmdAddItem cmd( getIntf(), psz_new, m_playOnDrop );
+            cmd.execute();
 
-        delete[] psz_fileName;
+            psz_new = psz_end ? psz_end + 1 : NULL;
+        }
+        free( psz_dup );
+        XFree( buffer );
     }
 
     // Tell the source we accepted the drop