X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fframework%2Fmlt_repository.c;h=81b80654e33898487167782f632a267ac0a2d4a0;hb=46fc89b27e98266757dfb7a55912becef8d419e2;hp=3d75bcbe8e68cab98e08f120f698fb515919949c;hpb=e3c3b7aacb11e269668203eab7894d16e2e584de;p=mlt diff --git a/src/framework/mlt_repository.c b/src/framework/mlt_repository.c index 3d75bcbe..81b80654 100644 --- a/src/framework/mlt_repository.c +++ b/src/framework/mlt_repository.c @@ -26,11 +26,14 @@ #include "mlt_properties.h" #include "mlt_tokeniser.h" #include "mlt_log.h" +#include "mlt_factory.h" #include #include #include #include +#include +#include /** \brief Repository class * @@ -426,3 +429,71 @@ mlt_properties mlt_repository_languages( mlt_repository self ) mlt_properties_set_data( &self->parent, "languages", languages, 0, ( mlt_destructor )mlt_properties_close, NULL ); return languages; } + +static void list_presets( mlt_properties properties, const char *path, const char *dirname ) +{ + DIR *dir = opendir( dirname ); + + if ( dir ) + { + struct dirent *de = readdir( dir ); + char fullname[ PATH_MAX ]; + + while ( de != NULL ) + { + if ( de->d_name[0] != '.' && de->d_name[strlen( de->d_name ) - 1] != '~' ) + { + snprintf( fullname, sizeof(fullname), "%s/%s", dirname, de->d_name ); + if ( de->d_type & DT_DIR ) + { + // recurse into subdirectories + char sub[ PATH_MAX ]; + if ( path ) + snprintf( sub, sizeof(sub), "%s/%s", path, de->d_name ); + else + strncpy( sub, de->d_name, sizeof(sub) ); + list_presets( properties, sub, fullname ); + } + else + { + // load the preset + mlt_properties preset = mlt_properties_load( fullname ); + if ( preset && mlt_properties_count( preset ) ) + { + snprintf( fullname, 1024, "%s/%s", path, de->d_name ); + mlt_properties_set_data( properties, fullname, preset, 0, (mlt_destructor) mlt_properties_close, NULL ); + } + } + } + de = readdir( dir ); + } + closedir( dir ); + } +} + +/** Get the list of presets. + * + * \public \memberof mlt_repository_s + * \return a properties list of all the presets + */ + +mlt_properties mlt_repository_presets( ) +{ + mlt_properties result = mlt_properties_new(); + char *path = getenv( "MLT_PRESETS_PATH" ); + + if ( path ) + { + path = strdup( path ); + } + else + { + path = malloc( strlen( mlt_environment( "MLT_DATA" ) ) + 9 ); + strcpy( path, mlt_environment( "MLT_DATA" ) ); + strcat( path, "/presets" ); + } + list_presets( result, NULL, path ); + free( path ); + + return result; +}