base-dirs: add a SUBDIR_WIREPLUMBER flag to append "/wireplumber" to the base dirs

This removes the previous hardcoding of this suffix and allows the
functions to be useful to other projects that use libwireplumber
and want to use this code to locate their data & config.
This commit is contained in:
George Kiagiadakis 2024-03-01 11:22:51 +02:00
parent e7484c16a3
commit ad4c6999e8
2 changed files with 17 additions and 9 deletions

View file

@ -55,6 +55,8 @@ lookup_dirs (guint flags, gboolean is_absolute)
{
g_autoptr(GPtrArray) dirs = g_ptr_array_new_with_free_func (g_free);
const gchar *dir;
const gchar *subdir =
(flags & WP_BASE_DIRS_FLAG_SUBDIR_WIREPLUMBER) ? "wireplumber" : ".";
/* Compile the list of lookup directories in priority order */
if (is_absolute) {
@ -84,17 +86,16 @@ lookup_dirs (guint flags, gboolean is_absolute)
else {
if (flags & WP_BASE_DIRS_XDG_CONFIG_HOME) {
dir = g_get_user_config_dir ();
g_ptr_array_add (dirs, g_build_filename (dir, "wireplumber", NULL));
g_ptr_array_add (dirs, g_canonicalize_filename (subdir, dir));
}
if (flags & WP_BASE_DIRS_XDG_DATA_HOME) {
dir = g_get_user_data_dir ();
g_ptr_array_add (dirs, g_build_filename (dir, "wireplumber", NULL));
g_ptr_array_add (dirs, g_canonicalize_filename (subdir, dir));
}
if (flags & WP_BASE_DIRS_XDG_CONFIG_DIRS) {
const gchar * const *xdg_dirs = g_get_system_config_dirs ();
for (guint i = 0; xdg_dirs[i]; i++) {
g_ptr_array_add (dirs, g_build_filename (xdg_dirs[i], "wireplumber",
NULL));
g_ptr_array_add (dirs, g_canonicalize_filename (subdir, xdg_dirs[i]));
}
}
if (flags & WP_BASE_DIRS_BUILD_SYSCONFDIR) {
@ -104,8 +105,7 @@ lookup_dirs (guint flags, gboolean is_absolute)
if (flags & WP_BASE_DIRS_XDG_DATA_DIRS) {
const gchar * const *xdg_dirs = g_get_system_data_dirs ();
for (guint i = 0; xdg_dirs[i]; i++) {
g_ptr_array_add (dirs, g_build_filename (xdg_dirs[i], "wireplumber",
NULL));
g_ptr_array_add (dirs, g_canonicalize_filename (subdir, xdg_dirs[i]));
}
}
if (flags & WP_BASE_DIRS_BUILD_DATADIR) {

View file

@ -48,24 +48,32 @@ typedef enum { /*< flags >*/
/*! the file is a loadable module; prepend "lib" and append ".so" if needed */
WP_BASE_DIRS_FLAG_MODULE = (1 << 24),
/*! append "/wireplumber" to the location, except in the case of locations
that are specified via WirePlumber-specific environment variables;
in LIBDIR, append "/wireplumber-$API_version" instead */
WP_BASE_DIRS_FLAG_SUBDIR_WIREPLUMBER = (1 << 25),
WP_BASE_DIRS_CONFIGURATION =
WP_BASE_DIRS_ENV_CONFIG |
WP_BASE_DIRS_XDG_CONFIG_HOME |
WP_BASE_DIRS_XDG_CONFIG_DIRS |
WP_BASE_DIRS_BUILD_SYSCONFDIR |
WP_BASE_DIRS_XDG_DATA_DIRS |
WP_BASE_DIRS_BUILD_DATADIR,
WP_BASE_DIRS_BUILD_DATADIR |
WP_BASE_DIRS_FLAG_SUBDIR_WIREPLUMBER,
WP_BASE_DIRS_DATA =
WP_BASE_DIRS_ENV_DATA |
WP_BASE_DIRS_XDG_DATA_HOME |
WP_BASE_DIRS_XDG_DATA_DIRS |
WP_BASE_DIRS_BUILD_DATADIR,
WP_BASE_DIRS_BUILD_DATADIR |
WP_BASE_DIRS_FLAG_SUBDIR_WIREPLUMBER,
WP_BASE_DIRS_MODULE =
WP_BASE_DIRS_ENV_MODULE |
WP_BASE_DIRS_BUILD_LIBDIR |
WP_BASE_DIRS_FLAG_MODULE,
WP_BASE_DIRS_FLAG_MODULE |
WP_BASE_DIRS_FLAG_SUBDIR_WIREPLUMBER,
} WpBaseDirsFlags;
WP_API