From 95848385ab76356275c0dedde28b29e19b523a95 Mon Sep 17 00:00:00 2001 From: Erwan Tulou Date: Sun, 11 Apr 2010 21:39:08 +0200 Subject: [PATCH] skins(Linux): add support for multiple files in drag&drap 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 | 37 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/modules/gui/skins2/x11/x11_dragdrop.cpp b/modules/gui/skins2/x11/x11_dragdrop.cpp index 6e9fc78497..ff327e7476 100644 --- a/modules/gui/skins2/x11/x11_dragdrop.cpp +++ b/modules/gui/skins2/x11/x11_dragdrop.cpp @@ -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 -- 2.11.4.GIT