[vlc-devel] [PATCH 2/2] Implements dynamic file extension manager.

Benjamin Gerard benjihan at users.sourceforge.net
Thu Feb 26 10:23:15 CET 2009


Modifies current libvlc and GUI to use the new file extension manager. Basically currently the static shared file extension container FILEEXT_POOL is used by all instance of libvlc. It should be somewhat easy to implement a per libvlc instance container version if it is required.
---
 include/vlc_interface.h              |   26 ++++++-----------
 modules/gui/qt4/dialogs_provider.hpp |   51 ++++++++++++++++------------------
 modules/gui/skins2/src/dialogs.cpp   |   20 ++++++++++---
 src/libvlc.c                         |    6 ++++
 4 files changed, 54 insertions(+), 49 deletions(-)

diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index 7dde2a5..68852c6 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -171,23 +171,15 @@ typedef enum vlc_dialog {
 /* Useful text messages shared by interfaces */
 #define INTF_ABOUT_MSG LICENSE_MSG
 
-#define EXTENSIONS_AUDIO "*.a52;*.aac;*.ac3;*.dts;*.flac;*.m4a;*.m4p;*.mka;" \
-                         "*.mod;*.mp1;*.mp2;*.mp3;*.oga;*.ogg;*.oma;*.spx;" \
-                         "*.wav;*.wma;*.xm"
-
-#define EXTENSIONS_VIDEO "*.asf;*.avi;*.divx;*.dv;*.flv;*.gxf;*.iso;*.m1v;*.m2v;" \
-                         "*.m2t;*.m2ts;*.m4v;*.mkv;*.mov;*.mp2;*.mp4;*.mpeg;*.mpeg1;" \
-                         "*.mpeg2;*.mpeg4;*.mpg;*.mts;*.mxf;*.nuv;" \
-                         "*.ogg;*.ogm;*.ogv;*.ogx;*.ps;" \
-                         "*.rec;*.rm;*.rmvb;*.ts;*.vob;*.wmv;"
-
-#define EXTENSIONS_PLAYLIST "*.asx;*.b4s;*.m3u;*.pls;*.vlc;*.xspf"
-
-#define EXTENSIONS_MEDIA EXTENSIONS_VIDEO ";" EXTENSIONS_AUDIO ";" \
-                          EXTENSIONS_PLAYLIST
-
-#define EXTENSIONS_SUBTITLE "*.cdg;*.idx;*.srt;*.sub;*.utf;*.ass;*.ssa;*.aqt;" \
-                            "*.jss;*.psb;*.rt;*.smi"
+  /* XXX: dynamic file extension:
+     returns MALLOCated strings caller should FREE them !
+  */
+# include <vlc_fileext.h>
+# define EXTENSIONS_AUDIO    fileext_Get( FILEEXT_POOL, FILEEXT_AUDIO )
+# define EXTENSIONS_VIDEO    fileext_Get( FILEEXT_POOL, FILEEXT_VIDEO )
+# define EXTENSIONS_PLAYLIST fileext_Get( FILEEXT_POOL, FILEEXT_PLAYLIST )
+# define EXTENSIONS_MEDIA    fileext_Get( FILEEXT_POOL, FILEEXT_MEDIA )
+# define EXTENSIONS_SUBTITLE fileext_Get( FILEEXT_POOL, FILEEXT_SUBTITLE )
 
 /** \defgroup vlc_interaction Interaction
  * \ingroup vlc_interface
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index c08a6a5..b2b1ffe 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -35,34 +35,31 @@
 
 #include <QObject>
 
-#define ADD_FILTER_MEDIA( string )     \
-    string += qtr( "Media Files" );    \
-    string += " ( ";                   \
-    string += EXTENSIONS_MEDIA;        \
-    string += ");;";
-#define ADD_FILTER_VIDEO( string )     \
-    string += qtr( "Video Files" );    \
-    string += " ( ";                   \
-    string += EXTENSIONS_VIDEO;        \
-    string += ");;";
-#define ADD_FILTER_AUDIO( string )     \
-    string += qtr( "Audio Files" );    \
-    string += " ( ";                   \
-    string += EXTENSIONS_AUDIO;        \
-    string += ");;";
-#define ADD_FILTER_PLAYLIST( string )  \
-    string += qtr( "Playlist Files" ); \
-    string += " ( ";                   \
-    string += EXTENSIONS_PLAYLIST;     \
-    string += ");;";
-#define ADD_FILTER_SUBTITLE( string )  \
-    string += qtr( "Subtitles Files" );\
-    string += " ( ";                   \
-    string += EXTENSIONS_SUBTITLE;     \
-    string += ");;";
+#define ADD_FILTER_ANY( string, type, label )	\
+    if (1) {					\
+	char * ext = EXTENSIONS_##type;		\
+	string += qtr( label );			\
+	string += " ( ";			\
+	string += ext;				\
+	string += ");;";			\
+	free( ext );				\
+    } else
+
+#define ADD_FILTER_MEDIA( string )\
+    ADD_FILTER_ANY( string, MEDIA, "Media Files" )
+#define ADD_FILTER_VIDEO( string )\
+    ADD_FILTER_ANY( string, VIDEO, "Video Files" )
+#define ADD_FILTER_AUDIO( string )\
+    ADD_FILTER_ANY( string, AUDIO, "Audio Files" )
+#define ADD_FILTER_PLAYLIST( string )\
+    ADD_FILTER_ANY( string, PLAYLIST, "Playlist Files" )
+#define ADD_FILTER_SUBTITLE( string )\
+    ADD_FILTER_ANY( string, SUBTITLE, "Subtitles Files" )
 #define ADD_FILTER_ALL( string )       \
-    string += qtr( "All Files" );      \
-    string += " (*)";
+    if (1) {			       \
+	string += qtr( "All Files" );  \
+	string += " (*)";	       \
+    } else
 
 enum {
     EXT_FILTER_MEDIA     =  0x01,
diff --git a/modules/gui/skins2/src/dialogs.cpp b/modules/gui/skins2/src/dialogs.cpp
index bf4b541..3cacf13 100644
--- a/modules/gui/skins2/src/dialogs.cpp
+++ b/modules/gui/skins2/src/dialogs.cpp
@@ -223,13 +223,23 @@ void Dialogs::showChangeSkin()
 
 void Dialogs::showPlaylistLoad()
 {
-    showFileGeneric( _("Open playlist"),
-                     _("Playlist Files|"EXTENSIONS_PLAYLIST"|"
-                       "All Files|*"),
-                     showPlaylistLoadCB, kOPEN );
+   const char * psz_playlist = _("Playlist Files");
+   const char * psz_allfiles = _("All Files");
+   char * list, * psz_exts  = EXTENSIONS_PLAYLIST;
+
+   if( ! psz_exts )
+      return;
+   if( -1 !=
+       asprintf( &list, "%s|%s|%s|*", psz_playlist, psz_exts, psz_allfiles ) )
+   {
+      showFileGeneric( _("Open playlist"),
+		       list,
+		       showPlaylistLoadCB, kOPEN );
+      free( list );
+   }
+   free( psz_exts );
 }
 
-
 void Dialogs::showPlaylistSave()
 {
     showFileGeneric( _("Save playlist"), _("XSPF playlist|*.xspf|"
diff --git a/src/libvlc.c b/src/libvlc.c
index fb7aa52..ab45657 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -321,6 +321,9 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      */
     LoadMessages ();
 
+    /* Initialize file extension manager */
+    fileext_Default( FILEEXT_POOL );
+
     /* Initialize the module bank and load the configuration of the
      * main module. We need to do this at this stage to be able to display
      * a short help if required by the user. (short help == main module
@@ -1111,6 +1114,9 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     /* Free module bank. It is refcounted, so we call this each time  */
     module_EndBank( p_libvlc, true );
 
+    /* Cleanup file extension manager */
+    fileext_Destroy( FILEEXT_POOL );
+
     FREENULL( priv->psz_configfile );
     var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
                      p_libvlc->p_hotkeys );
-- 
1.6.1.3





More information about the vlc-devel mailing list