[vlmc-devel] commit: MediaLibrary: Allow a media to be drag and dropped directly into the media library. ( Hugo Beauzée-Luyssen )
git at videolan.org
git at videolan.org
Sun Sep 26 22:50:02 CEST 2010
vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Sep 26 19:33:03 2010 +0200| [bcd0f5e8f4e07248baa8d12d75b194c1f635178b] | committer: Hugo Beauzée-Luyssen
MediaLibrary: Allow a media to be drag and dropped directly into the media library.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=bcd0f5e8f4e07248baa8d12d75b194c1f635178b
---
src/Gui/library/MediaLibrary.cpp | 40 ++++++++++++++++++++++++++++++++++++
src/Gui/library/MediaLibrary.h | 4 +++
src/Gui/library/ui/MediaLibrary.ui | 3 ++
src/Library/Library.cpp | 15 +++++++++----
4 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/src/Gui/library/MediaLibrary.cpp b/src/Gui/library/MediaLibrary.cpp
index 857d21b..e3c388d 100644
--- a/src/Gui/library/MediaLibrary.cpp
+++ b/src/Gui/library/MediaLibrary.cpp
@@ -111,3 +111,43 @@ MediaLibrary::filterTypeChanged()
{
filterUpdated( m_ui->filterInput->text() );
}
+
+void
+MediaLibrary::dragEnterEvent( QDragEnterEvent *event )
+{
+ if ( event->mimeData()->hasFormat( "TEXT" ) &&
+ event->mimeData()->data( "TEXT" ).startsWith( "file://" ) )
+ {
+ event->accept();
+ }
+ else
+ event->ignore();
+}
+
+void
+MediaLibrary::dropEvent( QDropEvent *event )
+{
+ if ( event->mimeData()->hasFormat( "TEXT" ) == true )
+ {
+ 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 ) );
+ if ( media != NULL )
+ {
+ Clip* clip = new Clip( media );
+ media->setBaseClip( clip );
+ Library::getInstance()->addClip( clip );
+
+ event->accept();
+ return ;
+ }
+ else
+ qDebug() << "Failed to load media:" << data.mid(7);
+ }
+ event->ignore();
+}
diff --git a/src/Gui/library/MediaLibrary.h b/src/Gui/library/MediaLibrary.h
index e557fe4..d7e7571 100644
--- a/src/Gui/library/MediaLibrary.h
+++ b/src/Gui/library/MediaLibrary.h
@@ -39,6 +39,10 @@ class MediaLibrary : public QWidget
typedef bool (*Filter)( const Clip*, const QString& filter );
explicit MediaLibrary( QWidget *parent = 0);
+ protected:
+ void dragEnterEvent( QDragEnterEvent *event );
+ void dropEvent( QDropEvent *event );
+
private:
/**
* \return The appropriate filter function
diff --git a/src/Gui/library/ui/MediaLibrary.ui b/src/Gui/library/ui/MediaLibrary.ui
index aec2122..906a185 100644
--- a/src/Gui/library/ui/MediaLibrary.ui
+++ b/src/Gui/library/ui/MediaLibrary.ui
@@ -16,6 +16,9 @@
<height>0</height>
</size>
</property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
<property name="windowTitle">
<string>Form</string>
</property>
diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp
index 3dc2d55..e625ef8 100644
--- a/src/Library/Library.cpp
+++ b/src/Library/Library.cpp
@@ -69,11 +69,10 @@ Library::loadProject( const QDomElement& doc )
mrl = projectPath + mrl.mid( Workspace::workspacePrefix.length() );
}
Media* m = addMedia( mrl );
- connect( m, SIGNAL( metaDataComputed( const Media* ) ),
- this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
- m_medias[mrl] = m;
- m_nbMediaToLoad.fetchAndAddAcquire( 1 );
- m->computeMetadata();
+ if ( m == NULL )
+ qWarning() << "Failed to load media" << mrl << "when loading project.";
+ else
+ m_nbMediaToLoad.fetchAndAddAcquire( 1 );
}
media = media.nextSiblingElement();
}
@@ -128,7 +127,13 @@ Library::addMedia( const QFileInfo &fileInfo )
{
Media* media = MediaContainer::addMedia( fileInfo );
if ( media != NULL )
+ {
setCleanState( false );
+ connect( media, SIGNAL( metaDataComputed( const Media* ) ),
+ this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
+ m_medias[fileInfo.absoluteFilePath()] = media;
+ media->computeMetadata();
+ }
return media;
}
More information about the Vlmc-devel
mailing list