[vlc-devel] [PATCH 2/2] Implements dynamic file extension manager.
Benjamin Gerard
benjihan at users.sourceforge.net
Mon Mar 2 15:14:32 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 | 18 ------------
modules/gui/qt4/dialogs_provider.hpp | 51 ++++++++++++++++------------------
modules/gui/skins2/src/dialogs.cpp | 21 ++++++++++---
src/libvlc.c | 7 ++++
4 files changed, 47 insertions(+), 50 deletions(-)
diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index dbbc75b..123a46f 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -171,24 +171,6 @@ typedef enum vlc_dialog {
/* Useful text messages shared by interfaces */
#define INTF_ABOUT_MSG LICENSE_MSG
-#define EXTENSIONS_AUDIO "*.a52;*.aac;*.ac3;*.ape;*.dts;*.flac;*.m4a;*.m4p;*.mka;" \
- "*.mlp;*.mod;*.mp1;*.mp2;*.mp3;*.oga;*.ogg;*.oma;*.spx;" \
- "*.wav;*.wma;*.wv;*.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"
-
/** \defgroup vlc_interaction Interaction
* \ingroup vlc_interface
* Interaction between user and modules
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index c08a6a5..88fc4e5 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 += ");;";
+#include <vlc_fileext.h>
+#define ADD_FILTER_ANY( string, type, label ) \
+ if (1) { \
+ char * ext = fileext_Get( FILEEXT_POOL, FILEEXT_##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..b479805 100644
--- a/modules/gui/skins2/src/dialogs.cpp
+++ b/modules/gui/skins2/src/dialogs.cpp
@@ -29,6 +29,7 @@
#include "../commands/cmd_playlist.hpp"
#include "../commands/cmd_playtree.hpp"
#include <vlc_playlist.h>
+#include <vlc_fileext.h>
/// Callback called when a new skin is chosen
void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
@@ -223,13 +224,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;
+
+ if( ( psz_exts = fileext_Get( FILEEXT_POOL, FILEEXT_PLAYLIST ) ) == NULL )
+ 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 1d1d71d..a6eb2e0 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -39,6 +39,7 @@
#include <vlc_common.h>
#include "control/libvlc_internal.h"
#include <vlc_input.h>
+#include <vlc_fileext.h>
#include "modules/modules.h"
#include "config/configuration.h"
@@ -321,6 +322,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
@@ -1099,6 +1103,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