Allow diddling with the paths.

SVN revision: 25580
This commit is contained in:
David Walter Seikel 2006-09-07 13:16:21 +00:00
parent 87924604ed
commit 7b44542ef9
2 changed files with 170 additions and 36 deletions

View File

@ -86,7 +86,8 @@ enum _Ecore_Desktop_Paths_Type
ECORE_DESKTOP_PATHS_DESKTOPS = 3,
ECORE_DESKTOP_PATHS_ICONS = 4,
ECORE_DESKTOP_PATHS_KDE_LEGACY = 5,
ECORE_DESKTOP_PATHS_XSESSIONS = 6
ECORE_DESKTOP_PATHS_XSESSIONS = 6,
ECORE_DESKTOP_PATHS_MAX = 7
};
typedef enum _Ecore_Desktop_Paths_Type Ecore_Desktop_Paths_Type;
@ -123,6 +124,12 @@ extern "C"
/* Function Prototypes */
EAPI int ecore_desktop_paths_init(void);
EAPI void ecore_desktop_paths_extras_clear(void);
EAPI void ecore_desktop_paths_prepend_user(Ecore_Desktop_Paths_Type type, char *paths);
EAPI void ecore_desktop_paths_prepend_system(Ecore_Desktop_Paths_Type type, char *paths);
EAPI void ecore_desktop_paths_append_user(Ecore_Desktop_Paths_Type type, char *paths);
EAPI void ecore_desktop_paths_append_system(Ecore_Desktop_Paths_Type type, char *paths);
EAPI void ecore_desktop_paths_regen(void);
char *ecore_desktop_paths_file_find(Ecore_List * paths,
const char *file, int sub,
int (*func) (void

View File

@ -38,10 +38,10 @@
* and correct those guesses.
*/
static int init_count = 0;
static Ecore_List *_ecore_desktop_paths_get(char *before, char *env_home,
static Ecore_List *_ecore_desktop_paths_get(Ecore_Desktop_Paths_Type path_type,
char *before, char *env_home,
char *env, char *env_home_default,
char *env_default, char *type,
char *gnome_extra, char *kde);
@ -50,10 +50,16 @@ static void _ecore_desktop_paths_massage_path(char *path, char *home,
char *second);
static void _ecore_desktop_paths_check_and_add(Ecore_List * paths,
char *path);
static void _ecore_desktop_paths_create();
static void _ecore_desktop_paths_destroy();
static Ecore_List *gnome_data = NULL;
static Ecore_List *prepend_user_paths[ECORE_DESKTOP_PATHS_MAX];
static Ecore_List *prepend_system_paths[ECORE_DESKTOP_PATHS_MAX];
static Ecore_List *append_user_paths[ECORE_DESKTOP_PATHS_MAX];
static Ecore_List *append_system_paths[ECORE_DESKTOP_PATHS_MAX];
static char *home;
static int init_count = 0;
#if defined GNOME_SUPPORT || defined KDE_SUPPORT
struct _config_exe_data
@ -80,14 +86,13 @@ ecore_desktop_paths_init()
{
if (++init_count != 1) return init_count;
/* FIXME: Keep track of any loose strdups in a list, so that we can free them at shutdown time. */
#if defined GNOME_SUPPORT || defined KDE_SUPPORT
exit_handler =
ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
_ecore_desktop_paths_cb_exe_exit, NULL);
#endif
ecore_desktop_paths_extras_clear();
gnome_data = ecore_list_new();
home = ecore_desktop_home_get();
@ -123,10 +128,40 @@ ecore_desktop_paths_init()
#endif
}
_ecore_desktop_paths_create();
return init_count;
}
EAPI int
ecore_desktop_paths_shutdown()
{
if (--init_count != 0) return init_count;
_ecore_desktop_paths_destroy();
E_FN_DEL(ecore_list_destroy, gnome_data);
#if defined GNOME_SUPPORT || defined KDE_SUPPORT
if (exit_handler)
ecore_event_handler_del(exit_handler);
#endif
free(home);
return init_count;
}
EAPI void
ecore_desktop_paths_regen()
{
_ecore_desktop_paths_destroy();
_ecore_desktop_paths_create();
}
static void
_ecore_desktop_paths_create()
{
if (!ecore_desktop_paths_desktops)
{
ecore_desktop_paths_desktops =
_ecore_desktop_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_DESKTOPS, NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
"~/.local/share:~/.kde/share",
"/usr/local/share:/usr/share",
"applications:applnk:applications/kde",
@ -144,11 +179,11 @@ ecore_desktop_paths_init()
#ifdef KDE_SUPPORT
ecore_desktop_paths_kde_legacy =
_ecore_desktop_paths_get(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_KDE_LEGACY, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"apps");
#else
ecore_desktop_paths_kde_legacy =
_ecore_desktop_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_KDE_LEGACY, NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
"~/.local/share:~/.kde/share",
"/usr/local/share:/usr/share",
"applnk",
@ -190,7 +225,7 @@ ecore_desktop_paths_init()
char *gnome;
ecore_desktop_paths_icons =
_ecore_desktop_paths_get("~/.e/e/icons:~/.icons", "XDG_DATA_HOME",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_ICONS, "~/.icons", "XDG_DATA_HOME",
"XDG_DATA_DIRS", "~/.local/share:~/.kde/share",
"/usr/local/share:/usr/share:/usr/X11R6/share", "icons:pixmaps",
"dist/icons", "icon:pixmap");
@ -206,42 +241,32 @@ ecore_desktop_paths_init()
}
if (!ecore_desktop_paths_menus)
ecore_desktop_paths_menus =
_ecore_desktop_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_MENUS, NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS",
"~/.config", "/etc/xdg:/var/lib/menu-xdg", "menus", NULL,
"xdgconf-menu");
if (!ecore_desktop_paths_directories)
ecore_desktop_paths_directories =
_ecore_desktop_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_DIRECTORIES, NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
"~/.local/share:~/.kde/share",
"/usr/local/share:/usr/share",
"desktop-directories", "gnome/vfolders",
"xdgdata-dirs");
if (!ecore_desktop_paths_config)
ecore_desktop_paths_config =
_ecore_desktop_paths_get(NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_CONFIG, NULL, "XDG_CONFIG_HOME", "XDG_CONFIG_DIRS",
"~/.config", "/etc/xdg", "", NULL, NULL);
if (!ecore_desktop_paths_xsessions)
ecore_desktop_paths_xsessions =
_ecore_desktop_paths_get(NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
_ecore_desktop_paths_get(ECORE_DESKTOP_PATHS_XSESSIONS, NULL, "XDG_DATA_HOME", "XDG_DATA_DIRS",
"~/.local/share:~/.kde/share",
"/usr/local/share:/usr/share",
"xsessions", NULL,
NULL);
#if defined GNOME_SUPPORT || defined KDE_SUPPORT
if (exit_handler)
ecore_event_handler_del(exit_handler);
#endif
free(home);
return init_count;
}
EAPI int
ecore_desktop_paths_shutdown()
static void
_ecore_desktop_paths_destroy()
{
if (--init_count != 0) return init_count;
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_xsessions);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_config);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_directories);
@ -249,9 +274,60 @@ ecore_desktop_paths_shutdown()
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_icons);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_kde_legacy);
E_FN_DEL(ecore_list_destroy, ecore_desktop_paths_desktops);
E_FN_DEL(ecore_list_destroy, gnome_data);
}
return init_count;
EAPI void
ecore_desktop_paths_extras_clear()
{
int i;
for (i = 0; i < ECORE_DESKTOP_PATHS_MAX; i++)
{
E_FN_DEL(ecore_list_destroy, prepend_user_paths[i]);
E_FN_DEL(ecore_list_destroy, prepend_system_paths[i]);
E_FN_DEL(ecore_list_destroy, append_user_paths[i]);
E_FN_DEL(ecore_list_destroy, append_system_paths[i]);
prepend_user_paths[i] = ecore_list_new();
if (prepend_user_paths[i])
ecore_list_set_free_cb(prepend_user_paths[i], free);
prepend_system_paths[i] = ecore_list_new();
if (prepend_system_paths[i])
ecore_list_set_free_cb(prepend_system_paths[i], free);
append_user_paths[i] = ecore_list_new();
if (append_user_paths[i])
ecore_list_set_free_cb(append_user_paths[i], free);
append_system_paths[i] = ecore_list_new();
if (append_system_paths[i])
ecore_list_set_free_cb(append_system_paths[i], free);
}
}
EAPI void
ecore_desktop_paths_prepend_user(Ecore_Desktop_Paths_Type type, char *paths)
{
if (prepend_user_paths[type])
ecore_list_append(prepend_user_paths[type], strdup(paths));
}
EAPI void
ecore_desktop_paths_prepend_system(Ecore_Desktop_Paths_Type type, char *paths)
{
if (prepend_system_paths[type])
ecore_list_append(prepend_system_paths[type], strdup(paths));
}
EAPI void
ecore_desktop_paths_append_user(Ecore_Desktop_Paths_Type type, char *paths)
{
if (append_user_paths[type])
ecore_list_append(append_user_paths[type], strdup(paths));
}
EAPI void
ecore_desktop_paths_append_system(Ecore_Desktop_Paths_Type type, char *paths)
{
if (append_system_paths[type])
ecore_list_append(append_system_paths[type], strdup(paths));
}
/** Search for a file in fdo compatible locations.
@ -314,7 +390,8 @@ icons=pathlist
*/
static Ecore_List *
_ecore_desktop_paths_get(char *before, char *env_home, char *env,
_ecore_desktop_paths_get(Ecore_Desktop_Paths_Type path_type,
char *before, char *env_home, char *env,
char *env_home_default, char *env_default, char *type,
char *gnome_extra, char *kde)
{
@ -344,6 +421,7 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
Ecore_List *env_list;
ecore_list_set_free_cb(paths, free);
if (before)
{
Ecore_List *befores;
@ -364,6 +442,18 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
}
}
if (prepend_user_paths[path_type])
{
char *this_path;
ecore_list_goto_first(prepend_user_paths[path_type]);
while ((this_path = ecore_list_next(prepend_user_paths[path_type])) != NULL)
{
_ecore_desktop_paths_massage_path(path, home, this_path, NULL);
_ecore_desktop_paths_check_and_add(paths, path);
}
}
if (env_home)
{
char *value;
@ -392,6 +482,30 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
}
}
if (append_user_paths[path_type])
{
char *this_path;
ecore_list_goto_first(append_user_paths[path_type]);
while ((this_path = ecore_list_next(append_user_paths[path_type])) != NULL)
{
_ecore_desktop_paths_massage_path(path, home, this_path, NULL);
_ecore_desktop_paths_check_and_add(paths, path);
}
}
if (prepend_system_paths[path_type])
{
char *this_path;
ecore_list_goto_first(prepend_system_paths[path_type]);
while ((this_path = ecore_list_next(prepend_system_paths[path_type])) != NULL)
{
_ecore_desktop_paths_massage_path(path, home, this_path, NULL);
_ecore_desktop_paths_check_and_add(paths, path);
}
}
if (env)
{
char *value;
@ -420,6 +534,18 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
}
}
if (append_system_paths[path_type])
{
char *this_path;
ecore_list_goto_first(append_system_paths[path_type]);
while ((this_path = ecore_list_next(append_system_paths[path_type])) != NULL)
{
_ecore_desktop_paths_massage_path(path, home, this_path, NULL);
_ecore_desktop_paths_check_and_add(paths, path);
}
}
/*
* Get the pathlist from the config file - type=pathlist
* for each path in config
@ -853,13 +979,14 @@ ecore_desktop_paths_for_each(Ecore_Desktop_Paths_Type type, Ecore_For_Each funct
switch (type)
{
case ECORE_DESKTOP_PATHS_CONFIG : list = ecore_desktop_paths_config;
case ECORE_DESKTOP_PATHS_MENUS : list = ecore_desktop_paths_menus;
case ECORE_DESKTOP_PATHS_DIRECTORIES : list = ecore_desktop_paths_directories;
case ECORE_DESKTOP_PATHS_DESKTOPS : list = ecore_desktop_paths_desktops;
case ECORE_DESKTOP_PATHS_ICONS : list = ecore_desktop_paths_icons;
case ECORE_DESKTOP_PATHS_KDE_LEGACY : list = ecore_desktop_paths_kde_legacy;
case ECORE_DESKTOP_PATHS_XSESSIONS : list = ecore_desktop_paths_xsessions;
case ECORE_DESKTOP_PATHS_CONFIG : list = ecore_desktop_paths_config; break;
case ECORE_DESKTOP_PATHS_MENUS : list = ecore_desktop_paths_menus; break;
case ECORE_DESKTOP_PATHS_DIRECTORIES : list = ecore_desktop_paths_directories; break;
case ECORE_DESKTOP_PATHS_DESKTOPS : list = ecore_desktop_paths_desktops; break;
case ECORE_DESKTOP_PATHS_ICONS : list = ecore_desktop_paths_icons; break;
case ECORE_DESKTOP_PATHS_KDE_LEGACY : list = ecore_desktop_paths_kde_legacy; break;
case ECORE_DESKTOP_PATHS_XSESSIONS : list = ecore_desktop_paths_xsessions; break;
case ECORE_DESKTOP_PATHS_MAX : break;
}
if (list)
return ecore_list_for_each(list, function, user_data);