#include #include #include #include #include #include #include #include #include "theme-common.h" static GList * themes_common_list_add_dir (GList *list, const char *dirname) { DIR *dir; struct dirent *de; const gchar *suffix = "gtk-2.0"; const gchar *key_suffix = "gtk-2.0-key"; g_return_val_if_fail (dirname != NULL, list); dir = opendir (dirname); if (!dir) return list; while ((de = readdir (dir))) { char *tmp; ThemeInfo *info = NULL; if (de->d_name[0] == '.') continue; tmp = g_build_filename (dirname, de->d_name, suffix, NULL); if (g_file_test (tmp, G_FILE_TEST_IS_DIR)) { info = g_new0 (ThemeInfo, 1); info->path = g_build_filename (dirname, de->d_name, NULL); info->name = g_strdup (de->d_name); info->has_gtk = TRUE; } g_free (tmp); tmp = g_build_filename (dirname, de->d_name, key_suffix, NULL); if (g_file_test (tmp, G_FILE_TEST_IS_DIR)) { if (info == NULL) { info = g_new0 (ThemeInfo, 1); info->path = g_build_filename (dirname, de->d_name, NULL); info->name = g_strdup (de->d_name); } info->has_keybinding = TRUE; } g_free (tmp); if (info) list = g_list_prepend (list, info); } closedir (dir); return list; } GList * theme_common_get_list (void) { gchar *dir; GList *theme_list = NULL; dir = g_build_filename (g_get_home_dir (), ".themes", NULL); theme_list = themes_common_list_add_dir (theme_list, dir); g_free (dir); dir = gtk_rc_get_theme_dir (); theme_list = themes_common_list_add_dir (theme_list, dir); g_free (dir); return theme_list; } void theme_common_list_free (GList *list) { if (list == NULL) return; g_list_foreach (list, g_free, NULL); g_list_free (list); } static void theme_dir_changed_callback (GnomeVFSMonitorHandle *handle, const gchar *monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType event_type, gpointer user_data) { g_print ("%s\n", monitor_uri); g_closure_invoke ((GClosure *) user_data, NULL, 0, NULL, NULL); } void theme_common_register_theme_change (GCallback func, gpointer data) { GnomeVFSResult result; GnomeVFSMonitorHandle *handle = NULL; gchar *text_uri; GClosure *closure; /* We're unlikely to ever need to cancel this with the control center */ closure = g_cclosure_new (func, data, NULL); text_uri = g_build_filename (g_get_home_dir (), ".themes", NULL); gnome_vfs_monitor_add (&handle, text_uri, GNOME_VFS_MONITOR_DIRECTORY, theme_dir_changed_callback, closure); g_free (text_uri); text_uri = gtk_rc_get_theme_dir (); gnome_vfs_monitor_add (&handle, text_uri, GNOME_VFS_MONITOR_DIRECTORY, theme_dir_changed_callback, closure); g_free (text_uri); }