static gboolean mx_icon_theme_equal_func (GThemedIcon *icon, GThemedIcon *search) { gint i; const gchar * const *names1 = g_themed_icon_get_names (icon); const gchar * const *names2 = g_themed_icon_get_names (search); for (i = 0; names1[i] && names2[i]; i++) if (!g_str_equal (names1[i], names2[i])) return FALSE; return TRUE; }
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 gboolean ignore_drive (GDrive *drive) { GIcon *icon; if (g_drive_can_eject (drive) == FALSE || g_drive_has_media (drive) == FALSE) { GRL_DEBUG ("%s: Not adding %s as cannot eject or has no media", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } /* Hack to avoid USB devices showing up * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */ icon = g_drive_get_icon (drive); if (icon && G_IS_THEMED_ICON (icon)) { const gchar * const * names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) { g_object_unref (icon); GRL_DEBUG ("%s: Not adding drive %s as is not optical drive", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } } g_clear_object (&icon); return FALSE; }
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; }
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; }
QIcon get_file_icon(const QString& content_type) { static QCache<QString, QIcon> cache; cache.setMaxCost(100); if (cache.contains(content_type)) return QIcon(*(cache.object(content_type))); QByteArray ba = content_type.toLocal8Bit(); GIcon* gicon = g_content_type_get_icon(ba.constData()); QStringList tried_names; if (G_IS_THEMED_ICON(gicon)) { const gchar * const * names = g_themed_icon_get_names(reinterpret_cast<GThemedIcon*>(gicon)); if (names != 0) { int i = 0; while(names[i] != 0) { QString name = QString::fromLocal8Bit(names[i]); QIcon r = QIcon::fromTheme(name); if (r.isNull()) { tried_names << name; } else { cache.insert(content_type, new QIcon(r)); g_object_unref(gicon); return r; } i++; } } else { qDebug() << "get_file_icon: empty or invalid result of g_themed_icon_get_names"; } } else { qDebug() << "get_file_icon: gicon is not themed icon"; } qDebug() << "get_file_icon(" << content_type << "): no valid names" << tried_names << "; returning null icon"; cache.insert(content_type, new QIcon()); g_object_unref(gicon); return QIcon(); }
const gchar * _gtk_icon_helper_get_icon_name (GtkIconHelper *self) { if (self->priv->storage_type != GTK_IMAGE_ICON_NAME) return NULL; return g_themed_icon_get_names (G_THEMED_ICON (self->priv->gicon))[0]; }
static GList * mx_icon_theme_get_icons (MxIconTheme *theme, const gchar *icon_name) { gint i; GIcon *icon; GList *data; const gchar * const *names = NULL; MxIconThemePrivate *priv = theme->priv; /* Load the icon, or a fallback */ icon = g_themed_icon_new_with_default_fallbacks (icon_name); names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (!names) { g_object_unref (icon); return NULL; } data = NULL; for (i = 0; names[i]; i++) { /* See if we've loaded this before */ GIcon *single_icon = g_themed_icon_new (names[i]); gboolean success = g_hash_table_lookup_extended (priv->icon_hash, single_icon, NULL, (gpointer *)&data); g_object_unref (single_icon); /* Found in cache on first hit, break */ if (success && (i == 0)) break; /* Found in cache after searching the disk, store again as a new icon */ if (success) { /* If we found this as a fallback, store it so we don't look on * disk again. */ if (data) data = mx_icon_theme_copy_data_list (data); g_hash_table_insert (priv->icon_hash, g_object_ref (icon), data); break; } /* Try to load from disk */ if ((data = mx_icon_theme_load_icon (theme, names[i], icon))) break; } g_object_unref (icon); return data; }
const gchar * st_icon_get_icon_name (StIcon *icon) { StIconPrivate *priv; g_return_val_if_fail (ST_IS_ICON (icon), NULL); priv = icon->priv; if (priv->gicon && G_IS_THEMED_ICON (priv->gicon)) return g_themed_icon_get_names (G_THEMED_ICON (priv->gicon)) [0]; else return NULL; }
static void set_icon(GtkWindow *window, const gchar *uri) { GFile *file; GIcon *icon; GFileInfo *info; GdkScreen *screen; GtkIconTheme *icon_theme; const gchar *icon_name = NULL, *content_type; screen = gtk_widget_get_screen (GTK_WIDGET (window)); icon_theme = gtk_icon_theme_get_for_screen (screen); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (! info) return; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (G_IS_THEMED_ICON (icon)) { const gchar * const *names = NULL; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) { gint i; for (i = 0; names[i]; i++) { if (gtk_icon_theme_has_icon (icon_theme, names[i])) { icon_name = names[i]; break; } } } } if (icon_name) { gtk_window_set_icon_name (window, icon_name); } g_object_unref (icon); }
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; }
gboolean nautilus_icon_theme_can_render (GThemedIcon *icon) { GtkIconTheme *icon_theme; const gchar * const *names; gint idx; names = g_themed_icon_get_names (icon); icon_theme = gtk_icon_theme_get_default (); for (idx = 0; names[idx] != NULL; idx++) { if (gtk_icon_theme_has_icon (icon_theme, names[idx])) { return TRUE; } } return FALSE; }
char * panel_util_get_icon_name_from_g_icon (GIcon *gicon) { const char * const *names; GtkIconTheme *icon_theme; int i; if (!G_IS_THEMED_ICON (gicon)) return NULL; names = g_themed_icon_get_names (G_THEMED_ICON (gicon)); icon_theme = gtk_icon_theme_get_default (); for (i = 0; names[i] != NULL; i++) { if (gtk_icon_theme_has_icon (icon_theme, names[i])) return g_strdup (names[i]); } return NULL; }
gboolean _gtk_icon_helper_set_use_fallback (GtkIconHelper *self, gboolean use_fallback) { if (self->priv->use_fallback != use_fallback) { self->priv->use_fallback = use_fallback; _gtk_icon_helper_invalidate (self); if (self->priv->storage_type == GTK_IMAGE_ICON_NAME) { GIcon *old_icon = self->priv->gicon; const char *icon_name = g_themed_icon_get_names (G_THEMED_ICON (self->priv->gicon))[0]; if (self->priv->use_fallback) self->priv->gicon = g_themed_icon_new_with_default_fallbacks (icon_name); else self->priv->gicon = g_themed_icon_new (icon_name); g_object_unref (old_icon); } return TRUE; } return FALSE; }
static GList * add_drive (GList *media_list, GDrive *drive, GrlOpticalMediaSource *source) { GList *volumes, *i; GIcon *icon; if (g_drive_can_eject (drive) == FALSE || g_drive_has_media (drive) == FALSE) { return media_list; } /* Hack to avoid USB devices showing up * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */ icon = g_drive_get_icon (drive); if (icon && G_IS_THEMED_ICON (icon)) { const gchar * const * names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) { g_object_unref (icon); return media_list; } } g_clear_object (&icon); /* Repeat for all the drive's volumes */ volumes = g_drive_get_volumes (drive); for (i = volumes; i != NULL; i = i->next) { GVolume *volume = i->data; media_list = add_volume (media_list, volume, drive, source); g_object_unref (volume); } g_list_free (volumes); return media_list; }
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); }
gchar* plank_drawing_drawing_service_get_icon_from_gicon (GIcon* icon) { gchar* result = NULL; GIcon* _tmp0_ = NULL; GIcon* _tmp7_ = NULL; _tmp0_ = icon; if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, g_themed_icon_get_type ())) { gchar* icons = NULL; GIcon* _tmp1_ = NULL; gchar** _tmp2_ = NULL; gchar** _tmp3_ = NULL; gchar* _tmp4_ = NULL; const gchar* _tmp5_ = NULL; gchar* _tmp6_ = NULL; _tmp1_ = icon; _tmp3_ = _tmp2_ = g_themed_icon_get_names (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, g_themed_icon_get_type (), GThemedIcon)); _tmp4_ = _vala_g_strjoinv (";;", _tmp3_, _vala_array_length (_tmp2_)); icons = _tmp4_; _tmp5_ = icons; _tmp6_ = string_replace (_tmp5_, "(null);;", ""); result = _tmp6_; _g_free0 (icons); return result; } _tmp7_ = icon; if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, g_file_icon_get_type ())) { GIcon* _tmp8_ = NULL; GFile* _tmp9_ = NULL; gchar* _tmp10_ = NULL; _tmp8_ = icon; _tmp9_ = g_file_icon_get_file (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, g_file_icon_get_type (), GFileIcon)); _tmp10_ = g_file_get_path (_tmp9_); result = _tmp10_; return result; } result = NULL; return result; }
static guint mx_icon_theme_hash (GThemedIcon *icon) { const gchar * const *names = g_themed_icon_get_names (icon); return g_str_hash (names[0]); }
void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) { // Get basic information this->mount.reset_without_add(mount); if (!mount) return; mount_name = ConvertAndFree(g_mount_get_name(mount)); // Get the icon name(s) mount_icon_names.clear(); GIcon* icon = g_mount_get_icon(mount); if (G_IS_THEMED_ICON(icon)) { const char* const * icons = g_themed_icon_get_names(G_THEMED_ICON(icon)); for (const char* const * p = icons ; *p ; ++p) { mount_icon_names << QString::fromUtf8(*p); } } g_object_unref(icon); GFile* root = g_mount_get_root(mount); // Get the mount path mount_path = ConvertAndFree(g_file_get_path(root)); mount_uri = ConvertAndFree(g_file_get_uri(root)); // Do a sanity check to make sure the root is actually this mount - when a // device is unmounted GIO sends a changed signal before the removed signal, // and we end up reading information about the / filesystem by mistake. GError* error = NULL; GMount* actual_mount = g_file_find_enclosing_mount(root, NULL, &error); if (error || !actual_mount) { g_error_free(error); invalid_enclosing_mount = true; } else if (actual_mount) { g_object_unref(actual_mount); } // Query the filesystem info for size, free space, and type error = NULL; GFileInfo* info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE "," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { filesystem_size = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); filesystem_free = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)); g_object_unref(info); } // Query the file's info for a filesystem ID // Only afc devices (that I know of) give reliably unique IDs if (filesystem_type == "afc") { error = NULL; info = g_file_query_info(root, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { mount_uuid = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref(info); } } g_object_unref(root); }
NautilusIconInfo * nautilus_icon_info_lookup (GIcon *icon, int size) { NautilusIconInfo *icon_info; GdkPixbuf *pixbuf; if (G_IS_LOADABLE_ICON (icon)) { LoadableIconKey lookup_key; LoadableIconKey *key; GInputStream *stream; if (loadable_icon_cache == NULL) { loadable_icon_cache = g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash, (GEqualFunc)loadable_icon_key_equal, (GDestroyNotify) loadable_icon_key_free, (GDestroyNotify) g_object_unref); } lookup_key.icon = icon; lookup_key.size = size; icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key); if (icon_info) { return g_object_ref (icon_info); } pixbuf = NULL; stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), size, NULL, NULL, NULL); if (stream) { pixbuf = eel_gdk_pixbuf_load_from_stream_at_size (stream, size); g_object_unref (stream); } icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf); key = loadable_icon_key_new (icon, size); g_hash_table_insert (loadable_icon_cache, key, icon_info); return g_object_ref (icon_info); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names; ThemedIconKey lookup_key; ThemedIconKey *key; GtkIconTheme *icon_theme; GtkIconInfo *gtkicon_info; const char *filename; if (themed_icon_cache == NULL) { themed_icon_cache = g_hash_table_new_full ((GHashFunc)themed_icon_key_hash, (GEqualFunc)themed_icon_key_equal, (GDestroyNotify) themed_icon_key_free, (GDestroyNotify) g_object_unref); } names = g_themed_icon_get_names (G_THEMED_ICON (icon)); icon_theme = gtk_icon_theme_get_default (); gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0); if (gtkicon_info == NULL) { return nautilus_icon_info_new_for_pixbuf (NULL); } filename = gtk_icon_info_get_filename (gtkicon_info); lookup_key.filename = (char *)filename; lookup_key.size = size; icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); if (icon_info) { gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info); key = themed_icon_key_new (filename, size); g_hash_table_insert (themed_icon_cache, key, icon_info); gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } else { GdkPixbuf *pixbuf; GtkIconInfo *gtk_icon_info; gtk_icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (gtk_icon_info != NULL) { pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL); gtk_icon_info_free (gtk_icon_info); } else { pixbuf = NULL; } return nautilus_icon_info_new_for_pixbuf (pixbuf); } }
/** * rb_device_source_set_display_details: * @source: a #RBDeviceSource * * Sets the icon and display name for a device-based source. * The details come from the mount and/or volume. This should * be called in the source's constructed method. */ void rb_device_source_set_display_details (RBDeviceSource *source) { GMount *mount = NULL; GVolume *volume = NULL; GIcon *icon = NULL; char *display_name; GdkPixbuf *pixbuf = NULL; if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } /* prefer mount details to volume details, as the nautilus sidebar does */ if (mount != NULL) { mount = g_object_ref (mount); } else if (volume != NULL) { mount = g_volume_get_mount (volume); } else { mount = NULL; } if (mount != NULL) { display_name = g_mount_get_name (mount); icon = g_mount_get_icon (mount); rb_debug ("details from mount: display name = %s, icon = %p", display_name, icon); } else if (volume != NULL) { display_name = g_volume_get_name (volume); icon = g_volume_get_icon (volume); rb_debug ("details from volume: display name = %s, icon = %p", display_name, icon); } else { display_name = g_strdup ("Unknown Device"); icon = g_themed_icon_new ("multimedia-player"); } g_object_set (source, "name", display_name, NULL); g_free (display_name); if (icon == NULL) { rb_debug ("no icon set"); pixbuf = NULL; } else if (G_IS_THEMED_ICON (icon)) { GtkIconTheme *theme; const char * const *names; gint size; int i; theme = gtk_icon_theme_get_default (); gtk_icon_size_lookup (RB_SOURCE_ICON_SIZE, &size, NULL); i = 0; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); while (names[i] != NULL && pixbuf == NULL) { rb_debug ("looking up themed icon: %s", names[i]); pixbuf = gtk_icon_theme_load_icon (theme, names[i], size, 0, NULL); i++; } } else if (G_IS_LOADABLE_ICON (icon)) { rb_debug ("loading of GLoadableIcons is not implemented yet"); pixbuf = NULL; } if (pixbuf != NULL) { g_object_set (source, "pixbuf", pixbuf, NULL); g_object_unref (pixbuf); } if (mount != NULL) { g_object_unref (mount); } if (volume != NULL) { g_object_unref (volume); } if (icon != NULL) { g_object_unref (icon); } }
NautilusIconInfo * nautilus_icon_info_lookup (GIcon *icon, int size) { NautilusIconInfo *icon_info; GdkPixbuf *pixbuf; if (G_IS_LOADABLE_ICON (icon)) { LoadableIconKey lookup_key; LoadableIconKey *key; GInputStream *stream; if (loadable_icon_cache == NULL) { loadable_icon_cache = g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash, (GEqualFunc)loadable_icon_key_equal, (GDestroyNotify) loadable_icon_key_free, (GDestroyNotify) g_object_unref); } lookup_key.icon = icon; lookup_key.size = size; icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key); if (icon_info) { return g_object_ref (icon_info); } pixbuf = NULL; stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), size, NULL, NULL, NULL); if (stream) { GdkPixbuf *scaled_pixbuf; int w, h, s; double scale; pixbuf = eel_gdk_pixbuf_load_from_stream (stream); g_object_unref (stream); w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); s = MAX (w, h); if (size != s) { scale = (double)size / s; scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, w * scale, h * scale, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled_pixbuf; } } icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf); key = loadable_icon_key_new (icon, size); g_hash_table_insert (loadable_icon_cache, key, icon_info); return g_object_ref (icon_info); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names; ThemedIconKey lookup_key; ThemedIconKey *key; GtkIconTheme *icon_theme; GtkIconInfo *gtkicon_info; const char *filename; if (themed_icon_cache == NULL) { themed_icon_cache = g_hash_table_new_full ((GHashFunc)themed_icon_key_hash, (GEqualFunc)themed_icon_key_equal, (GDestroyNotify) themed_icon_key_free, (GDestroyNotify) g_object_unref); } names = g_themed_icon_get_names (G_THEMED_ICON (icon)); icon_theme = gtk_icon_theme_get_default (); gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0); if (gtkicon_info == NULL) { return nautilus_icon_info_new_for_pixbuf (NULL); } filename = gtk_icon_info_get_filename (gtkicon_info); lookup_key.filename = (char *)filename; lookup_key.size = size; icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); if (icon_info) { gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info); key = themed_icon_key_new (filename, size); g_hash_table_insert (themed_icon_cache, key, icon_info); gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } return nautilus_icon_info_new_for_pixbuf (NULL); }
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); }