[vlmc-devel] commit: MediaLibrary: Fixed (multiple video file) drag and drop on media library. (Rohit Yadav )
git at videolan.org
git at videolan.org
Thu Oct 7 23:31:21 CEST 2010
vlmc | branch: master | Rohit Yadav <rohityadav89 at gmail.com> | Fri Oct 8 03:15:13 2010 +0530| [a88974e28c149394245428c5c76ddbaaf066f3da] | committer: Rohit Yadav
MediaLibrary: Fixed (multiple video file) drag and drop on media library.
Used urls mime-type instead of plain text. Applied HACKINGS.
Patch tested on Ubuntu Linux, Windows XP & 7.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=a88974e28c149394245428c5c76ddbaaf066f3da
---
src/Gui/library/MediaLibrary.cpp | 77 ++++++++++++++++++++++++-------------
src/Gui/library/MediaLibrary.h | 2 +
2 files changed, 52 insertions(+), 27 deletions(-)
diff --git a/src/Gui/library/MediaLibrary.cpp b/src/Gui/library/MediaLibrary.cpp
index e3c388d..a913b6b 100644
--- a/src/Gui/library/MediaLibrary.cpp
+++ b/src/Gui/library/MediaLibrary.cpp
@@ -30,12 +30,15 @@
#include "StackViewController.h"
#include "ViewController.h"
-#include <QtDebug>
+#include <QDebug>
+#include <QUrl>
MediaLibrary::MediaLibrary(QWidget *parent) : QWidget(parent),
m_ui( new Ui::MediaLibrary() )
{
m_ui->setupUi( this );
+ setAcceptDrops( true );
+
StackViewController *nav = new StackViewController( m_ui->mediaListContainer );
m_mediaListView = new MediaListView( nav, Library::getInstance() );
nav->pushViewController( m_mediaListView );
@@ -56,8 +59,8 @@ void
MediaLibrary::filterUpdated( const QString &filter )
{
const MediaListView::MediaList &medias = m_mediaListView->mediaList();
- MediaListView::MediaList::const_iterator it = medias.begin();
- MediaListView::MediaList::const_iterator ite = medias.end();
+ MediaListView::MediaList::const_iterator it = medias.begin();
+ MediaListView::MediaList::const_iterator ite = medias.end();
while ( it != ite )
{
@@ -73,22 +76,23 @@ MediaLibrary::currentFilter()
{
switch ( m_ui->filterType->currentIndex() )
{
- case 0:
- return &filterByName;
- case 1:
- return &filterByTags;
- default:
- return &filterByName;
+ case 0:
+ return &filterByName;
+ case 1:
+ return &filterByTags;
+ default:
+ return &filterByName;
}
}
void
MediaLibrary::viewChanged( ViewController *view )
{
- MediaListView *mlv = qobject_cast<MediaListView*>( view );
+ MediaListView *mlv = qobject_cast<MediaListView*>( view );
if ( mlv == NULL )
return ;
+
m_mediaListView = mlv;
//Force an update as the media has changed
filterUpdated( m_ui->filterInput->text() );
@@ -115,39 +119,58 @@ MediaLibrary::filterTypeChanged()
void
MediaLibrary::dragEnterEvent( QDragEnterEvent *event )
{
- if ( event->mimeData()->hasFormat( "TEXT" ) &&
- event->mimeData()->data( "TEXT" ).startsWith( "file://" ) )
+ if ( event->mimeData()->hasFormat( "text/uri-list" ) )
{
- event->accept();
+ event->acceptProposedAction();
}
else
event->ignore();
}
void
+MediaLibrary::dragMoveEvent( QDragMoveEvent *event )
+{
+ event->acceptProposedAction();
+}
+
+void
+MediaLibrary::dragLeaveEvent( QDragLeaveEvent *event )
+{
+ event->accept();
+}
+
+void
MediaLibrary::dropEvent( QDropEvent *event )
{
- if ( event->mimeData()->hasFormat( "TEXT" ) == true )
+ QList<QUrl> fileList = event->mimeData()->urls();
+
+ if ( fileList.isEmpty() )
{
- const QString &data = event->mimeData()->data( "TEXT" );
- qDebug() << data;
- if ( data.startsWith( "file://" ) == false )
- {
- event->ignore();
- return ;
- }
- Media *media = Library::getInstance()->addMedia( data.mid( 7 ) );
+ event->ignore();
+ return;
+ }
+
+ Q_ASSERT( Library::getInstance() != NULL );
+
+ foreach ( QUrl url, fileList )
+ {
+ const QString &fileName = url.toLocalFile();
+
+ if ( fileName.isEmpty() )
+ continue;
+
+ Media *media = Library::getInstance()->addMedia( fileName );
+
if ( media != NULL )
{
- Clip* clip = new Clip( media );
+ Clip* clip = new Clip( media );
media->setBaseClip( clip );
Library::getInstance()->addClip( clip );
-
event->accept();
- return ;
}
else
- qDebug() << "Failed to load media:" << data.mid(7);
+ qCritical() << "Clip already present in library or an error occurred while loading media:" << fileName;
+
}
- event->ignore();
+ event->accept();
}
diff --git a/src/Gui/library/MediaLibrary.h b/src/Gui/library/MediaLibrary.h
index d7e7571..f78822c 100644
--- a/src/Gui/library/MediaLibrary.h
+++ b/src/Gui/library/MediaLibrary.h
@@ -41,6 +41,8 @@ class MediaLibrary : public QWidget
protected:
void dragEnterEvent( QDragEnterEvent *event );
+ void dragMoveEvent( QDragMoveEvent *event );
+ void dragLeaveEvent( QDragLeaveEvent *event );
void dropEvent( QDropEvent *event );
private:
More information about the Vlmc-devel
mailing list