static char * gicon_to_string (GIcon *icon) { GFile *file; const char *const *names; if (G_IS_FILE_ICON (icon)) { file = g_file_icon_get_file (G_FILE_ICON (icon)); if (file) return g_file_get_path (file); } else if (G_IS_THEMED_ICON (icon)) { names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) return g_strdup (names[0]); } else if (G_IS_EMBLEMED_ICON (icon)) { GIcon *base; base = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon)); return gicon_to_string (base); } return NULL; }
static const char * _icon_cache_get_icon_key (GIcon * icon) { const char * key = NULL; if (G_IS_THEMED_ICON (icon)) { char ** icon_names; char * name; g_object_get (icon, "names", &icon_names, NULL); name = g_strjoinv (",", icon_names); key = get_static_string (name); g_free (name); g_strfreev (icon_names); } else if (G_IS_FILE_ICON (icon)) { GFile * file; char * filename; file = g_file_icon_get_file (G_FILE_ICON (icon)); filename = g_file_get_path (file); key = get_static_string (filename); g_free (filename); g_object_unref (file); } return key; }
static char * get_uri_for_gicon (GIcon *icon) { char *uri; uri = NULL; if (G_IS_EMBLEMED_ICON (icon) != FALSE) { GIcon *new_icon; new_icon = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon)); g_object_unref (icon); icon = g_object_ref (new_icon); } if (G_IS_FILE_ICON (icon) != FALSE) { GFile *file; file = g_file_icon_get_file (G_FILE_ICON (icon)); uri = g_file_get_uri (file); g_object_unref (file); return uri; } /* We leave the themed icons up to the applications to set */ return uri; }
static GdkPixbuf* get_icon_pixbuf_for_content_type (const char *ctype, size_t size) { GIcon *icon; GdkPixbuf *pixbuf; icon = g_content_type_get_icon (ctype); pixbuf = NULL; /* based on a snippet from http://www.gtkforums.com/about4721.html */ if (G_IS_THEMED_ICON(icon)) { gchar const * const *names; names = g_themed_icon_get_names (G_THEMED_ICON(icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), *names, size, 0, NULL); } else if (G_IS_FILE_ICON(icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON(icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL); g_free (path); g_object_unref(icon_file); } g_object_unref(icon); return pixbuf; }
GdkPixbuf * _g_icon_get_pixbuf (GIcon *icon, int size, GtkIconTheme *theme) { GdkPixbuf *pixbuf; int w, h; if (icon == NULL) return NULL; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) pixbuf = get_file_icon_pixbuf (G_FILE_ICON (icon), size); if (pixbuf == NULL) return NULL; w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); if (scale_keeping_ratio (&w, &h, size, size, FALSE)) { GdkPixbuf *scaled; scaled = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled; } return pixbuf; }
GdkPixbuf* getPixBuf(char* name) { GFile* file=g_file_new_for_path(name); GFileInfo* file_info=g_file_query_info(file,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,NULL); GIcon* icon=g_file_info_get_icon(file_info); GdkPixbuf* pix=NULL; gchar* path; gchar const* const* names; GFile* icon_file; char* newname; if(G_IS_THEMED_ICON(icon)) { names=g_themed_icon_get_names(G_THEMED_ICON(icon)); pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),*names,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL); if(pix==NULL) { asprintf(&newname,"gnome-mime-%s",*names); pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),(const gchar*)newname,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL); debugFree(&newname); } } else if(G_IS_FILE_ICON(icon)) { icon_file=g_file_icon_get_file(G_FILE_ICON(icon)); path=g_file_get_path(icon_file); pix=gdk_pixbuf_new_from_file_at_size(path,16,16,NULL); debugFree(&path); g_object_unref(G_OBJECT(icon_file)); } g_object_unref(G_OBJECT(file)); g_object_unref(G_OBJECT(file_info)); return(pix); }
static GdkPixbuf * _get_icon_pixbuf (GIcon * icon, int size, GtkIconTheme * theme) { if (icon == NULL) return NULL; if (G_IS_THEMED_ICON (icon)) return get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) return get_file_icon_pixbuf (G_FILE_ICON (icon), size); return NULL; }
static GdkPixbuf * render_icon (GIcon *icon, gint icon_size) { GdkPixbuf *pixbuf; GtkIconInfo *info; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) { gchar const * const *names; info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, icon_size, 0); if (info) { pixbuf = gtk_icon_info_load_icon (info, NULL); gtk_icon_info_free (info); } if (pixbuf == NULL) { names = g_themed_icon_get_names (G_THEMED_ICON (icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), *names, icon_size, 0, NULL); } } else if (G_IS_FILE_ICON (icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON (icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, icon_size, icon_size, NULL); g_free (path); g_object_unref (G_OBJECT (icon_file)); } return pixbuf; }
static gchar *_cd_get_icon_path (GIcon *pIcon) { gchar *cIconPath = NULL; if (G_IS_THEMED_ICON (pIcon)) { const gchar * const *cFileNames = g_themed_icon_get_names (G_THEMED_ICON (pIcon)); //cd_message ("icones possibles : %s\n", g_strjoinv (":", (gchar **) cFileNames)); int i; for (i = 0; cFileNames[i] != NULL && cIconPath == NULL; i ++) { //cd_message (" une icone possible est : %s\n", cFileNames[i]); cIconPath = cairo_dock_search_icon_s_path (cFileNames[i]); //cd_message (" chemin trouve : %s\n", cIconPath); } } else if (G_IS_FILE_ICON (pIcon)) { GFile *pFile = g_file_icon_get_file (G_FILE_ICON (pIcon)); cIconPath = g_file_get_basename (pFile); //cd_message (" file_icon => %s\n", cIconPath); } return cIconPath; }
void ephy_web_application_setup_from_desktop_file (GDesktopAppInfo *desktop_info) { GAppInfo *app_info; const char *wm_class; GIcon *icon; g_assert (G_IS_DESKTOP_APP_INFO (desktop_info)); app_info = G_APP_INFO (desktop_info); g_set_prgname (g_app_info_get_name (app_info)); g_set_application_name (g_app_info_get_display_name (app_info)); icon = g_app_info_get_icon (app_info); if (G_IS_FILE_ICON (icon)) { GFile *file = g_file_icon_get_file (G_FILE_ICON (icon)); char *path = file ? g_file_get_path (file) : NULL; if (path) { gtk_window_set_default_icon_from_file (path, NULL); g_free (path); } g_clear_object (&file); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) gtk_window_set_default_icon_name (names[0]); } g_clear_object (&icon); /* We need to re-set this because we have already parsed the * options, which inits GTK+ and sets this as a side effect. */ wm_class = g_desktop_app_info_get_startup_wm_class (desktop_info); if (wm_class) gdk_set_program_class (wm_class); }
void thunar_notify_unmount (GMount *mount) { const gchar * const *icon_names; NotifyNotification *notification = NULL; const gchar *summary; GFileInfo *info; gboolean read_only = FALSE; GFile *icon_file; GFile *mount_point; GIcon *icon; gchar *icon_name = NULL; gchar *message; gchar *name; g_return_if_fail (G_IS_MOUNT (mount)); if (!thunar_notify_init ()) return; mount_point = g_mount_get_root (mount); info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); g_object_unref (info); } g_object_unref (mount_point); name = g_mount_get_name (mount); icon = g_mount_get_icon (mount); if (G_IS_THEMED_ICON (icon)) { icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (icon_names != NULL) icon_name = g_strdup (icon_names[0]); } else if (G_IS_FILE_ICON (icon)) { icon_file = g_file_icon_get_file (G_FILE_ICON (icon)); if (icon_file != NULL) { icon_name = g_file_get_path (icon_file); g_object_unref (icon_file); } } g_object_unref (icon); if (icon_name == NULL) icon_name = g_strdup ("drive-removable-media"); if (read_only) { summary = _("Unmounting device"); message = g_strdup_printf (_("The device \"%s\" is being unmounted by the system. " "Please do not remove the media or disconnect the " "drive"), name); } else { summary = _("Writing data to device"); message = g_strdup_printf (_("There is data that needs to be written to the " "device \"%s\" before it can be removed. Please " "do not remove the media or disconnect the drive"), name); } #ifdef NOTIFY_CHECK_VERSION #if NOTIFY_CHECK_VERSION (0, 7, 0) notification = notify_notification_new (summary, message, icon_name); #else notification = notify_notification_new (summary, message, icon_name, NULL); #endif #else notification = notify_notification_new (summary, message, icon_name, NULL); #endif notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_show (notification, NULL); g_object_set_data_full (G_OBJECT (mount), "thunar-notification", notification, g_object_unref); g_free (message); g_free (icon_name); g_free (name); }