[vlc-devel] [PATCH 1/3] Qt: Implement handling of QFileOpenEvent to play/enqueue files.

Juho Vähä-Herttua juhovh at iki.fi
Tue Nov 30 22:56:27 CET 2010


According to Qt4.6 docs this is currently supported for Mac OS X
only, but should work for others too if support is added later.
---
 modules/gui/qt4/dialogs_provider.cpp |   19 +++++++++++++++++++
 modules/gui/qt4/dialogs_provider.hpp |    1 +
 modules/gui/qt4/qt4.cpp              |    6 ++++++
 modules/gui/qt4/util/qvlcapp.hpp     |   13 +++++++++++++
 4 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 7cb0037..bca6071 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -730,3 +730,22 @@ void DialogsProvider::playMRL( const QString &mrl )
            PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
     RecentsMRL::getInstance( p_intf )->addRecent( mrl );
 }
+
+/**
+ * Queue the MRL received from the QFileOpenEvent, if the playlist
+ * is empty, acts the same way as playMRL above.
+ **/
+void DialogsProvider::enqueueMRL( const QString &mrl )
+{
+    playlist_Lock( THEPL );
+
+    bool first = playlist_IsEmpty( THEPL );
+    char* psz_uri = make_URI( qtu(mrl), NULL );
+    playlist_Add( THEPL, psz_uri, NULL,
+           PLAYLIST_APPEND | (first ? PLAYLIST_GO : PLAYLIST_PREPARSE),
+           PLAYLIST_END, true, true );
+    free( psz_uri );
+
+    playlist_Unlock( THEPL );
+    RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+}
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index 279f83b..4bae021 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -138,6 +138,7 @@ private:
 
 public slots:
     void playMRL( const QString & );
+    void enqueueMRL( const QString & );
 
     void playlistDialog();
     void bookmarksDialog();
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 6f1ada6..a034ce6 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -465,6 +465,12 @@ static void *Thread( void *obj )
     /* Initialize timers and the Dialog Provider */
     DialogsProvider::getInstance( p_intf );
 
+    /* Receive QFileOpenEvents to play/enqueue files */
+    QObject::connect( &app,
+                      SIGNAL( fileOpenEvent( const QString & ) ),
+                      DialogsProvider::getInstance( p_intf ),
+                      SLOT( enqueueMRL( const QString & ) ) );
+
     /* Detect screensize for small screens like TV or Netbooks */
     p_intf->p_sys->i_screenHeight =
         app.QApplication::desktop()->availableGeometry().height();
diff --git a/modules/gui/qt4/util/qvlcapp.hpp b/modules/gui/qt4/util/qvlcapp.hpp
index 66fa024..b3a45d4 100644
--- a/modules/gui/qt4/util/qvlcapp.hpp
+++ b/modules/gui/qt4/util/qvlcapp.hpp
@@ -27,6 +27,7 @@
 
 #include <QApplication>
 #include <QEvent>
+#include <QFileOpenEvent>
 
 #if defined(Q_WS_WIN)
 #   include <windows.h>
@@ -60,8 +61,20 @@ public:
             emit app->quitSignal();
     }
 
+    bool event( QEvent *event ) 
+    {
+        if( event->type() == QEvent::FileOpen )
+        {
+            QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(event);
+            emit fileOpenEvent( foe->file() );
+            return true;
+        }
+        return QApplication::event( event );
+    }
+
 signals:
     void quitSignal();
+    void fileOpenEvent( const QString & );
 
 };
 #endif
-- 
1.6.5.7




More information about the vlc-devel mailing list