static void ev_stock_icons_add_icons_path_for_screen (GdkScreen *screen) { GtkIconTheme *icon_theme; g_return_if_fail (ev_icons_path != NULL); icon_theme = screen ? gtk_icon_theme_get_for_screen (screen) : gtk_icon_theme_get_default (); if (icon_theme) { gchar **path = NULL; gint n_paths; gint i; /* GtkIconTheme will then look in Atril custom hicolor dir * for icons as well as the standard search paths */ gtk_icon_theme_get_search_path (icon_theme, &path, &n_paths); for (i = n_paths - 1; i >= 0; i--) { if (g_ascii_strcasecmp (ev_icons_path, path[i]) == 0) break; } if (i < 0) gtk_icon_theme_append_search_path (icon_theme, ev_icons_path); g_strfreev (path); } }
static void get_theme_names(GPtrArray* names) { void add_themes_from_dir(GPtrArray* names, const char* dir) { if (access(dir, F_OK) != 0) return; GPtrArray* list = list_dir((guchar*)dir); g_return_if_fail(list != NULL); int i; for (i = 0; i < list->len; i++){ char* index_path = g_build_filename(dir, list->pdata[i], "index.theme", NULL); if (access(index_path, F_OK) == 0){ g_ptr_array_add(names, list->pdata[i]); } else g_free(list->pdata[i]); g_free(index_path); } g_ptr_array_free(list, TRUE); } gint n_dirs = 0; gchar** theme_dirs = NULL; gtk_icon_theme_get_search_path(icon_theme, &theme_dirs, &n_dirs); // dir list is derived from XDG_DATA_DIRS int i; for (i = 0; i < n_dirs; i++) add_themes_from_dir(names, theme_dirs[i]); g_strfreev(theme_dirs); g_ptr_array_sort(names, strcmp2); }
int clip_GTK_ICONTHEMEGETSEARCHPATH(ClipMachine * cm) { C_object *cicon = _fetch_co_arg(cm); ClipVar *cv = RETPTR(cm) ; gchar **path ; gint n_elements ; long i ; CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object)); gtk_icon_theme_get_search_path(GTK_ICON_THEME(cicon->object), &path, &n_elements); i = n_elements; _clip_array(cm, cv, 1, &i); for(i=0; i<n_elements; i++) { ClipVar c; _clip_var_str(path[i], strlen(path[i]), &c); _clip_aset(cm, cv, &c, 1, &i); _clip_destroy(cm, &c); } g_strfreev(path); return 0; err: return 1; }
static void print_theme_path(GtkIconTheme *theme) { gchar **paths; gint n_paths; gint i; gtk_icon_theme_get_search_path(theme, &paths, &n_paths); g_print("path elements:%d\n", n_paths); for (i = 0; i < n_paths; i++) { g_print("%s theme path[%d]: %s\n", G_STRFUNC, i, paths[i]); } g_strfreev(paths); }
static VALUE it_get_search_path(VALUE self) { gchar** path; gint size, i; VALUE ret = rb_ary_new(); gtk_icon_theme_get_search_path(_SELF(self), &path, &size); for (i = 0; i < size; i++){ rb_ary_push(ret, CSTR2RVAL(path[i])); } g_strfreev(path); return ret; }
static gboolean has_icon_path (const char *path) { char **paths; int i; gboolean has = FALSE; gtk_icon_theme_get_search_path(gtk_icon_theme_get_default(), &paths, NULL); for (i = 0; paths[i]; i++) if (! strcmp(paths[i], path)) { has = TRUE; break; } g_strfreev(paths); return has; }
GList* icon_theme_init() { // Build a menu list of available themes. icon_theme_set_theme(NULL); if(_debug_){ gint n_elements; gchar** path[64]; gtk_icon_theme_get_search_path(icon_theme, path, &n_elements); int i; for(i=0;i<n_elements;i++){ dbg(2, "icon_theme_path=%s", path[0][i]); } g_strfreev(*path); } GtkWidget* menu = gtk_menu_new(); GPtrArray* names = g_ptr_array_new(); get_theme_names(names); int i; for (i = 0; i < names->len; i++) { char* name = names->pdata[i]; dbg(2, "name=%s", name); GtkWidget* item = gtk_menu_item_new_with_label(name); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_object_set_data(G_OBJECT(item), "theme", g_strdup(name)); //make sure this string is free'd when menu is updated. g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(icon_theme_on_select), NULL); g_free(name); } gtk_widget_show_all(menu); g_ptr_array_free(names, TRUE); return themes = g_list_append(NULL, menu); }
G_MODULE_EXPORT void thunar_extension_initialize(ThunarxProviderPlugin* plugin) { const gchar* mismatch; /* verify that the thunarx versions are compatible */ mismatch = thunarx_check_version(THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION); if(G_LIKELY(mismatch == NULL)) { g_message("Initializing xdiff-ext extension; DIFF_EXT_DATA_DIR='%s'", DIFF_EXT_DATA_DIR); { int n; char** path; int i; gtk_icon_theme_get_search_path(gtk_icon_theme_get_default(), &path, &n); for(i = 0; i < n; i++) { g_message("icon search path: '%s'", path[i]); } } #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, DIFF_EXT_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); #endif /* ENABLE_NLS */ /* register the types provided by this plugin */ diff_ext_register_type(plugin); /* setup the plugin type list */ type_list[0] = diff_ext_get_type(); _saved = g_queue_new(); thunarx_provider_plugin_set_resident(plugin, TRUE); } else { g_warning("Version mismatch: %s", mismatch); } }
GdkPixbufAnimation* pgpug_animated_icon (PgpugPixEnum icon_id, gint size) { g_return_val_if_fail (icon_id < PIX_NUMBER, NULL); GdkPixbufSimpleAnim *result = NULL; PgpugPixEntry entry = icon_entries_array [icon_id]; /* assert that ids are in order */ g_return_val_if_fail (entry.id == icon_id, NULL); GPtrArray *frames_array = g_ptr_array_new (); GtkIconTheme* theme; GdkPixbuf *pixbuf; GError *error = NULL, *error_anim = NULL; theme = gtk_icon_theme_get_default (); pixbuf = gtk_icon_theme_load_icon (theme, entry.name, size, GTK_ICON_LOOKUP_FORCE_SIZE, &error); if (error == NULL && pixbuf != NULL) { DEBG_MSG ("Loaded icon with name %s", entry.name); //it's a static image g_ptr_array_add (frames_array, (gpointer)pixbuf); }else{ //else try to get frame sequence gchar *name_template = g_strconcat (entry.name, "%02d", NULL); int i = 1; do { gchar *name = g_strdup_printf (name_template, i++); pixbuf = gtk_icon_theme_load_icon (theme, name, size, GTK_ICON_LOOKUP_FORCE_SIZE, &error_anim); if (pixbuf != NULL){ DEBG_MSG ("Loaded animation frame with name %s, address %p", name, pixbuf); g_ptr_array_add (frames_array, (gpointer)pixbuf); } g_free (name); } while (error_anim == NULL && i < 100); g_free (name_template); } if (frames_array->len != 0){ //construct animation result = gdk_pixbuf_simple_anim_new (size, size, frames_array->len); guint i; for (i = 0;i < frames_array->len; i++) gdk_pixbuf_simple_anim_add_frame (result, frames_array->pdata[i]); } else{ //we didn't find any images gchar **search_paths; gint index; gchar *search_path_str; gtk_icon_theme_get_search_path (theme, &search_paths, &index); search_path_str = g_strjoinv ("\n", search_paths); WARN_MSG ("Icon with name \"%s\" can not be loaded.\n" "Icon search paths are: \n%s\n" "Error message: %s", entry.name, search_path_str, error->message); g_strfreev (search_paths); g_free (search_path_str); } g_ptr_array_foreach (frames_array, (GFunc)g_object_unref, NULL); g_ptr_array_free (frames_array, TRUE); if (error != NULL) g_error_free (error); if (error_anim != NULL) g_error_free (error_anim); return GDK_PIXBUF_ANIMATION (result); }
char * panel_xdg_icon_name_from_icon_path (const char *path, GdkScreen *screen) { GtkIconTheme *theme; GtkSettings *settings; char *theme_name; char *icon; char **paths; int n_paths; int i; GFile *file; /* we look if the icon comes from the current icon theme */ if (!screen) screen = gdk_screen_get_default (); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-icon-theme-name", &theme_name, NULL); theme = gtk_icon_theme_get_for_screen (screen); gtk_icon_theme_get_search_path (theme, &paths, &n_paths); file = g_file_new_for_path (path); icon = NULL; for (i = 0; i < n_paths; i++) { GFile *parent; char *basename; parent = g_file_new_for_path (paths[i]); if (!g_file_has_prefix (file, parent)) { g_object_unref (parent); continue; } basename = g_file_get_basename (parent); if (g_strcmp0 (basename, "pixmaps") == 0) { char *relative_path; relative_path = g_file_get_relative_path (parent, file); /* if the icon is in a subdir of pixmaps, then it's not * a real icon name */ if (!strchr (relative_path, G_DIR_SEPARATOR)) icon = panel_xdg_icon_remove_extension (relative_path); g_free (relative_path); } else { /* real icon theme; but is it the current one? */ GFile *theme_dir; gboolean current; theme_dir = g_file_get_child (parent, theme_name); current = FALSE; if (g_file_has_prefix (file, theme_dir)) { /* it's the current one */ current = TRUE; } else { /* it's the default one */ g_object_unref (theme_dir); theme_dir = g_file_get_child (parent, DEFAULT_THEME_NAME); current = g_file_has_prefix (file, theme_dir); } g_object_unref (theme_dir); if (current) { char *buffer; buffer = g_file_get_basename (file); icon = panel_xdg_icon_remove_extension (buffer); g_free (buffer); } } g_free (basename); g_object_unref (parent); break; } g_object_unref (file); g_free (theme_name); return icon; }
/* Get available icon themes. This code is based on code from xfce4-appearance-settings */ static void load_icon_themes(GtkWidget* icon_theme_combo, GtkListStore* store) { GDir *dir; GKeyFile *index_file; const gchar *file; gchar *index_filename; gchar *theme_name; gchar *active_theme_name; gint i,j,n,act; gboolean is_dup; GtkIconTheme* theme; gchar **path; GtkTreeIter iter; gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _("PNMixer Icons"), -1); theme = gtk_icon_theme_get_default(); index_file = g_key_file_new(); active_theme_name = g_key_file_get_string(keyFile,"PNMixer","IconTheme",NULL); act = 1; gtk_icon_theme_get_search_path(theme, &path, &n); for (i = 0; i < n; i++) { /* Make sure we don't double search */ is_dup = FALSE; for (j = 0; j < n; j++) { if (j >= i) break; if (g_strcmp0(path[i],path[j]) == 0) { is_dup = TRUE; break; } } if (is_dup) continue; /* Open directory handle */ dir = g_dir_open(path[i], 0, NULL); /* Try next base directory if this one cannot be read */ if (G_UNLIKELY (dir == NULL)) continue; /* Iterate over filenames in the directory */ while ((file = g_dir_read_name (dir)) != NULL) { /* Build filename for the index.theme of the current icon theme directory */ index_filename = g_build_filename (path[i], file, "index.theme", NULL); /* Try to open the theme index file */ if (g_key_file_load_from_file(index_file,index_filename,0,NULL)) { if (g_key_file_has_key(index_file,"Icon Theme","Directories",NULL) && !g_key_file_get_boolean(index_file,"Icon Theme","Hidden",NULL)) { theme_name = g_key_file_get_string (index_file, "Icon Theme","Name",NULL); if (theme_name) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _(theme_name), -1); if ((active_theme_name != NULL) && g_strcmp0(theme_name,active_theme_name) == 0) gtk_combo_box_set_active (GTK_COMBO_BOX (icon_theme_combo), act); else act++; g_free(theme_name); } } } g_free(index_filename); } } g_key_file_free(index_file); if (active_theme_name != NULL) g_free(active_theme_name); else gtk_combo_box_set_active(GTK_COMBO_BOX (icon_theme_combo), 0); }
static void gimp_icons_change_icon_theme (GFile *new_search_path) { GFile *old_search_path = g_file_get_parent (icon_theme_path); if (! default_search_path) default_search_path = gimp_data_directory_file ("icons", NULL); if (! g_file_equal (new_search_path, old_search_path)) { GtkIconTheme *icon_theme = gtk_icon_theme_get_default (); if (g_file_equal (old_search_path, default_search_path)) { /* if the old icon theme is in the default search path, * simply prepend the new theme's path */ gchar *path_str = g_file_get_path (new_search_path); gtk_icon_theme_prepend_search_path (icon_theme, path_str); g_free (path_str); } else { /* if the old theme is not in the default search path, * we need to deal with the search path's first element */ gchar **paths; gint n_paths; gtk_icon_theme_get_search_path (icon_theme, &paths, &n_paths); if (g_file_equal (new_search_path, default_search_path)) { /* when switching to a theme in the default path, remove * the first search path element, the default search path * is still in the search path */ gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths + 1, n_paths - 1); } else { /* when switching between two non-default search paths, replace * the first element of the search path with the new * theme's path */ g_free (paths[0]); paths[0] = g_file_get_path (new_search_path); gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths, n_paths); } g_strfreev (paths); } } g_object_unref (old_search_path); }