Example #1
0
static void
icon_shape_renderer (cairo_t        *cr,
                     PangoAttrShape *attr,
                     gboolean        do_path,
                     gpointer        user_data)
{
        IconShapeData *data = user_data;
        gdouble x, y;

        cairo_get_current_point (cr, &x, &y);
        if (GPOINTER_TO_UINT (attr->data) == data->placeholder) {
                gdouble ascent;
                gdouble height;
                GdkPixbuf *pixbuf;
                GtkIconInfo *info;

                ascent = pango_units_to_double (attr->ink_rect.y);
                height = pango_units_to_double (attr->ink_rect.height);
                info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                                                       data->icon,
                                                       (gint)height,
                                                       GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_USE_BUILTIN);
                pixbuf = gtk_icon_info_load_icon (info, NULL);
                g_object_unref (info);

                cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
                cairo_reset_clip (cr);
                gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y + ascent);
                cairo_paint (cr);
                g_object_unref (pixbuf);
        }
}
Example #2
0
GdkPixbuf *
_g_icon_get_pixbuf (GIcon        *icon,
		    int           icon_size,
		    GtkIconTheme *icon_theme)
{
	GdkPixbuf   *pixbuf = NULL;
	GtkIconInfo *icon_info;

	icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme,
						    icon,
						    icon_size,
						    GTK_ICON_LOOKUP_USE_BUILTIN);

	if (icon_info != NULL) {
		GError *error = NULL;

		pixbuf = gtk_icon_info_load_icon (icon_info, &error);
		if (error != NULL) {
			g_print ("%s\n", error->message);
			g_error_free (error);
		}

		g_object_unref (icon_info);
	}

	return pixbuf;
}
Example #3
0
GdkPixbuf *
gedit_file_browser_utils_pixbuf_from_icon (GIcon       *icon,
                                           GtkIconSize  size)
{
	GdkPixbuf *ret = NULL;
	GtkIconTheme *theme;
	GtkIconInfo *info;
	gint width;

	if (!icon)
		return NULL;

	theme = gtk_icon_theme_get_default ();
	gtk_icon_size_lookup (size, &width, NULL);

	info = gtk_icon_theme_lookup_by_gicon (theme,
					       icon,
					       width,
					       GTK_ICON_LOOKUP_USE_BUILTIN);

	if (!info)
		return NULL;

	ret = gtk_icon_info_load_icon (info, NULL);
	g_object_unref (info);

	return ret;
}
Example #4
0
static void
ensure_pixbuf_for_gicon (GtkIconHelper *self,
                         GtkStyleContext *context)
{
  GtkIconTheme *icon_theme;
  gint width, height;
  GtkIconInfo *info;
  GtkIconLookupFlags flags;

  if (!check_invalidate_pixbuf (self, context))
    return;

  icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context));
  flags = get_icon_lookup_flags (self, context);

  ensure_icon_size (self, context, &width, &height);

  if (self->priv->gicon != NULL)
    {
      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
                                             self->priv->gicon,
                                             MIN (width, height), flags);
    }
  else
    {
      g_assert_not_reached ();
      return;
    }

  self->priv->rendered_pixbuf = ensure_stated_icon_from_info (self, context, info);

  if (info)
    g_object_unref (info);
}
Example #5
0
QImage imageForIconString(const QString& name, int size, GtkIconTheme* theme)
{
    if (!theme) {
        theme = gtk_icon_theme_get_default();
    }
    QByteArray utf8Name = name.toUtf8();

    /* Load the icon by creating a GIcon from the string icon_name.
       icon_name can contain more than a simple icon name but possibly
       a string as returned by g_icon_to_string().
    */
    GObjectScopedPointer<GIcon> icon(g_icon_new_for_string(utf8Name.data(), NULL));
    GScopedPointer<GtkIconInfo, gtk_icon_info_free> iconInfo;
    iconInfo.reset(gtk_icon_theme_lookup_by_gicon(
        theme,
        icon.data(),
        size,
        (GtkIconLookupFlags)0)
        );

    if (!iconInfo) {
        UQ_WARNING << "Failed to find icon:" << name;
        return QImage();
    }

    GObjectScopedPointer<GdkPixbuf> pixbuf(gtk_icon_info_load_icon(iconInfo.data(), NULL));
    if (!pixbuf) {
        UQ_WARNING << "Failed to load icon:" << name;
        return QImage();
    }

    return imageForPixbuf(pixbuf.data(), name);
}
Example #6
0
	foreach_slist (elem, file_list)
	{
		GtkTreeIter iter;
		gchar **path_arr = elem->data;
		GIcon *icon = NULL;
		gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL);

		if (content_type)
		{
			icon = g_content_type_get_icon(content_type);
			if (icon) 
			{
				GtkIconInfo *icon_info;

				icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0);
				if (!icon_info)
				{
					g_object_unref(icon);
					icon = NULL;
				}
				else
					gtk_icon_info_free(icon_info);
			}
			g_free(content_type);
		}

		if (patterns_match(header_patterns, path_arr[level]))
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-header", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}
		else if (patterns_match(source_patterns, path_arr[level]))
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-source", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}
		else
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-file", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}

		if (icon)
			g_object_unref(icon);
	}
static void
from_gicon (GtkSourcePixbufHelper *helper,
            GtkWidget             *widget,
            gint                   size)
{
	GdkScreen *screen;
	GtkIconTheme *icon_theme;
	GtkIconInfo *info;
	GtkIconLookupFlags flags;

	screen = gtk_widget_get_screen (widget);
	icon_theme = gtk_icon_theme_get_for_screen (screen);

	flags = GTK_ICON_LOOKUP_USE_BUILTIN;

	info = gtk_icon_theme_lookup_by_gicon (icon_theme,
	                                       helper->gicon,
	                                       size,
	                                       flags);

	if (info)
	{
		set_cache (helper, gtk_icon_info_load_icon (info, NULL));
	}
}
Example #8
0
static void icon_gicon(pqi inst, GIcon* icon, int size)
{
	GtkIconTheme *ithm = gtk_icon_theme_get_for_screen(gtk_widget_get_screen(inst->box)); /* Get the image theme of our box. */
	GtkIconInfo *iinfo = gtk_icon_theme_lookup_by_gicon(ithm, icon, size, 0); /* We need the pixbuf of our icon. */
	inst->pmainicon = gtk_icon_info_load_icon(iinfo, NULL); /* Now we're cooking with gas. */
	inst->pmainicon_glow = make_bright_pixbuf(inst->pmainicon);
	g_object_ref(inst->pmainicon); g_object_ref(inst->pmainicon_glow);
}
Example #9
0
GdkPixbuf *fm_icon_get_pixbuf (FmIcon *icon, int size)
{
    GtkIconInfo *ii;
    GdkPixbuf *pix;
    GSList *pixs, *l;
    PixEntry *ent;

    g_return_val_if_fail (icon != NULL, NULL);
    
    pixs =  (GSList*)fm_icon_get_user_data (icon);
    for ( l = pixs; l; l=l->next )
    {
        ent =  (PixEntry*)l->data;
        if (ent->size == size) // cached pixbuf is found!
        {
            return ent->pix ?  (GdkPixbuf*)g_object_ref (ent->pix) : NULL;
        }
    }

    // not found! load the icon from disk
    ii = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon->gicon, size, GTK_ICON_LOOKUP_FORCE_SIZE);
    if (ii)
    {
        pix = gtk_icon_info_load_icon (ii, NULL);
        gtk_icon_info_free (ii);

        // increase ref_count to keep this pixbuf in memory
        //   even when no one is using it.
        if (pix)
            g_object_ref (pix);
    }
    else
	{
		char *str = g_icon_to_string (icon->gicon);
		g_debug ("unable to load icon %s", str);
		g_free (str);
        // pix = NULL;
		pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "unknown", 
					size, GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
        if (G_LIKELY (pix))
            g_object_ref (pix);
	}

    // cache this!
    ent = g_slice_new (PixEntry);
    ent->size = size;
    ent->pix = pix;

    // FIXME_pcm: maybe we should unload icons that nobody is using to reduce memory usage.
    // g_object_weak_ref ();
    
    pixs = g_slist_prepend (pixs, ent);
    fm_icon_set_user_data (icon, pixs);

    return pix;
}
Example #10
0
/**
 * fm_pixbuf_from_icon_with_fallback
 * @icon: icon descriptor
 * @size: size in pixels
 * @fallback: (allow-none): name of fallback icon
 *
 * Creates a #GdkPixbuf and draws icon there. If icon cannot be found then
 * icon with name @fallback will be loaded instead.
 *
 * Returns: (transfer full): an image.
 *
 * Since: 1.2.0
 */
GdkPixbuf* fm_pixbuf_from_icon_with_fallback(FmIcon* icon, int size, const char *fallback)
{
    GtkIconInfo* ii;
    GdkPixbuf* pix = NULL;
    GSList *pixs, *l;
    PixEntry* ent;

    pixs = (GSList*)g_object_steal_qdata(G_OBJECT(icon), fm_qdata_id);
    for( l = pixs; l; l=l->next )
    {
        ent = (PixEntry*)l->data;
        if(ent->size == size) /* cached pixbuf is found! */
        {
            return ent->pix ? GDK_PIXBUF(g_object_ref(ent->pix)) : NULL;
        }
    }

    /* not found! load the icon from disk */
    ii = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), G_ICON(icon), size, GTK_ICON_LOOKUP_FORCE_SIZE);
    if(ii)
    {
        pix = gtk_icon_info_load_icon(ii, NULL);
        gtk_icon_info_free(ii);

        /* increase ref_count to keep this pixbuf in memory
           even when no one is using it. */
        if(pix)
            g_object_ref(pix);
    }
    if (pix == NULL)
    {
        char* str = g_icon_to_string(G_ICON(icon));
        g_debug("unable to load icon %s", str);
        if(fallback)
            pix = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), fallback,
                    size, GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
        if(pix == NULL) /* still unloadable */
            pix = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "unknown",
                    size, GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
        if(G_LIKELY(pix))
            g_object_ref(pix);
        g_free(str);
    }

    /* cache this! */
    ent = g_slice_new(PixEntry);
    ent->size = size;
    ent->pix = pix;

    /* FIXME: maybe we should unload icons that nobody is using to reduce memory usage. */
    /* g_object_weak_ref(); */
    pixs = g_slist_prepend(pixs, ent);
    g_object_set_qdata_full(G_OBJECT(icon), fm_qdata_id, pixs, destroy_pixbufs);

    return pix;
}
Example #11
0
/**
 * st_texture_cache_load_gicon:
 *
 * This method returns a new #ClutterClone for a given #GIcon.  If the
 * icon isn't loaded already, the texture will be filled asynchronously.
 *
 * Return Value: (transfer none): A new #ClutterActor for the icon
 */
ClutterActor *
st_texture_cache_load_gicon (StTextureCache    *cache,
                             GIcon             *icon,
                             gint               size)
{
  AsyncTextureLoadData *request;
  ClutterActor *texture;
  char *gicon_string;
  char *key;
  GtkIconTheme *theme;
  GtkIconInfo *info;

  gicon_string = g_icon_to_string (icon);
  key = g_strdup_printf (CACHE_PREFIX_GICON "icon=%s,size=%d", gicon_string, size);
  g_free (gicon_string);

  if (create_texture_and_ensure_request (cache, key, size, &request, &texture))
    {
      g_free (key);
      return texture;
    }

  /* Do theme lookups in the main thread to avoid thread-unsafety */
  theme = gtk_icon_theme_get_default ();

  info = gtk_icon_theme_lookup_by_gicon (theme, icon, size, GTK_ICON_LOOKUP_USE_BUILTIN);
  if (info != NULL)
    {
      /* hardcoded here for now; we should actually blow this away on
       * icon theme changes probably */
      request->key = g_strdup (key);
      request->policy = ST_TEXTURE_CACHE_POLICY_FOREVER;
      request->icon = g_object_ref (icon);
      request->icon_info = info;
      request->width = request->height = size;

      load_icon_pixbuf_async (cache, icon, info, size, NULL, on_pixbuf_loaded, request);
    }
  else
    {
      /* Blah; we failed to find the icon, but we've added our texture to the outstanding
       * requests.  In that case, just undo what create_texture_lookup_status did.
       */
       g_slist_foreach (request->textures, (GFunc) g_object_unref, NULL);
       g_slist_free (request->textures);
       g_free (request);
       g_hash_table_remove (cache->priv->outstanding_requests, key);
    }

  g_free (key);
  return CLUTTER_ACTOR (texture);
}
static GdkPixbuf *
gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
                                       GtkWidget     *widget,
                                       gint           size)
{
  GdkScreen     *screen     = gtk_widget_get_screen (widget);
  GtkIconTheme  *icon_theme = gtk_icon_theme_get_for_screen (screen);
  GimpThumbnail *thumbnail  = gimp_imagefile_get_thumbnail (imagefile);
  GdkPixbuf     *pixbuf     = NULL;

  if (! gimp_object_get_name (imagefile))
    return NULL;

  if (! pixbuf)
    {
      GIcon *icon = gimp_imagefile_get_gicon (imagefile);

      if (icon)
        {
          GtkIconInfo *info;

          info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);

          if (info)
            {
              pixbuf = gtk_icon_info_load_icon (info, NULL);

              gtk_icon_info_free (info);
            }
        }
    }

  if (! pixbuf && thumbnail->image_mimetype)
    {
      pixbuf = get_icon_for_mime_type (thumbnail->image_mimetype, size);
    }

  if (! pixbuf)
    {
      const gchar *icon_name = "text-x-generic";

      if (thumbnail->image_state == GIMP_THUMB_STATE_FOLDER)
        icon_name = "folder";

      pixbuf = gtk_icon_theme_load_icon (icon_theme,
                                         icon_name, size,
                                         GTK_ICON_LOOKUP_USE_BUILTIN,
                                         NULL);
    }

  return pixbuf;
}
Example #13
0
static void
panel_run_dialog_set_icon (PanelRunDialog *dialog,
			   GIcon          *icon,
			   gboolean        force)
{
	GdkPixbuf *pixbuf = NULL;

	if (!force && g_icon_equal(icon, dialog->icon))
		return;

	g_clear_object(&(dialog->icon));

	if (icon) {
		int          size;

		gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL);

		GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
		GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);
		pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
#if GTK_CHECK_VERSION (3, 8, 0)
		g_object_unref (icon_info);
#else
		gtk_icon_info_free (icon_info);
#endif

	}

	if (pixbuf) {
		dialog->icon = g_object_ref (icon);

		/* Don't bother scaling the image if it's too small.
		 * Scaled looks worse than a smaller image.
		 */
		gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->pixmap), pixbuf);

		//FIXME: it'd be better to set an icon of the correct size,
		//(ditto for the drag icon?)
		gtk_window_set_icon (GTK_WINDOW (dialog->run_dialog), pixbuf);

#if GTK_CHECK_VERSION (3, 2, 0)
		gtk_drag_source_set_icon_gicon (dialog->run_dialog, dialog->icon);
#else
		gtk_drag_source_set_icon_pixbuf (dialog->run_dialog, pixbuf);
#endif
		g_object_unref (pixbuf);
	} else {
		panel_run_dialog_set_default_icon (dialog, TRUE);
	}
}
Example #14
0
void
gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
				    GtkIconEntryPosition icon_pos,
				    GIcon *icon)
{
  GdkPixbuf *pixbuf = NULL;
  GtkIconEntryPrivate *priv;
  EntryIconInfo *icon_info;
  GdkScreen *screen;
  GtkIconTheme *icon_theme;
  GtkSettings *settings;
  gint width, height;
  GError *error = NULL;
  GtkIconInfo *info;

  priv = GTK_ICON_ENTRY_GET_PRIVATE (entry);
  icon_info = &priv->icons[icon_pos];

  screen = gtk_widget_get_screen (GTK_WIDGET (entry));
  icon_theme = gtk_icon_theme_get_for_screen (screen);
  settings = gtk_settings_get_for_screen (screen);

  if (icon != NULL)
    {
      gtk_icon_size_lookup_for_settings (settings,
					 GTK_ICON_SIZE_MENU,
					 &width, &height);

      #if #GTK_CHECK_VERSION (2, 14, 0)
      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
					     icon,
					     MIN (width, height), 0);
      #else
      info = NULL;
      #endif
      pixbuf = gtk_icon_info_load_icon (info, &error);
      if (pixbuf == NULL)
	{
	  g_error_free (error);
	  pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
					   GTK_STOCK_MISSING_IMAGE,
					   GTK_ICON_SIZE_MENU,
					   NULL);
	}
    }

  gtk_icon_entry_set_icon_internal ((GtkIconEntry*)entry,
				    icon_pos,
				    pixbuf);
}
Example #15
0
static cairo_surface_t *
draw_from_gicon (GtkNumerableIcon *self)
{
  GtkIconTheme *theme;
  GdkScreen *screen;
  GtkIconInfo *info;
  GdkPixbuf *pixbuf;
  cairo_surface_t *surface;
  cairo_t *cr;

  if (self->priv->style != NULL)
    {
      screen = gtk_style_context_get_screen (self->priv->style);
      theme = gtk_icon_theme_get_for_screen (screen);
    }
  else
    {
      theme = gtk_icon_theme_get_default ();
    }

  info = gtk_icon_theme_lookup_by_gicon (theme, self->priv->background_icon,
                                         self->priv->icon_size,
                                         GTK_ICON_LOOKUP_GENERIC_FALLBACK);
  if (info == NULL)
    return NULL;

  pixbuf = gtk_icon_info_load_icon (info, NULL);
  g_object_unref (info);

  if (pixbuf == NULL)
    return NULL;

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        gdk_pixbuf_get_width (pixbuf),
                                        gdk_pixbuf_get_height (pixbuf));

  cr = cairo_create (surface);

  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);

  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return surface;
}
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;
}
Example #17
0
static void
ensure_pixbuf_for_icon_name_or_gicon (GtkIconHelper *self,
                                      GtkStyleContext *context)
{
  GtkIconTheme *icon_theme;
  gint width, height;
  GtkIconInfo *info;
  GtkIconLookupFlags flags;

  if (!check_invalidate_pixbuf (self, context))
    return;

  icon_theme = gtk_icon_theme_get_default ();
  flags = get_icon_lookup_flags (self);

  ensure_icon_size (self, context, &width, &height);

  if (self->priv->storage_type == GTK_IMAGE_ICON_NAME &&
      self->priv->icon_name != NULL)
    {
      info = gtk_icon_theme_lookup_icon (icon_theme,
                                         self->priv->icon_name,
                                         MIN (width, height), flags);
    }
  else if (self->priv->storage_type == GTK_IMAGE_GICON &&
           self->priv->gicon != NULL)
    {
      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
                                             self->priv->gicon,
                                             MIN (width, height), flags);
    }
  else
    {
      g_assert_not_reached ();
      return;
    }

  self->priv->rendered_pixbuf = ensure_stated_icon_from_info (self, context, info);

  if (info)
    g_object_unref (info);
}
Example #18
0
ASImage* GIcon2ASImage (GIcon *icon)
{
	char        **icon_names;
	ASImage* asim = NULL;

	if (icon == NULL)
		return NULL;
	g_object_get (icon, "names", &icon_names, NULL);

#if 0
	{
		GdkPixbuf* iconPixbuf;
		GtkIconInfo  *icon_info;
		GtkIconTheme *icon_theme;
		GError       *error = NULL;
		icon_info = gtk_icon_theme_choose_icon (gtk_icon_theme_get_default(), (const char **)icon_names, DEFAULT_TILE_WIDTH, 0);
		icon_theme = gtk_icon_theme_get_for_screen (gdk_screen_get_default());
  	icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, v->icon, DEFAULT_TILE_WIDTH, GTK_ICON_LOOKUP_USE_BUILTIN);

		iconPixbuf = gtk_icon_info_load_icon (icon_info, &error);
		gtk_icon_info_free (icon_info);

		if (iconPixbuf )
			asim = GdkPixbuf2ASImage (iconPixbuf);
		else {
			g_warning ("could not load icon pixbuf: %s\n", error->message);
	  	g_clear_error (&error);
		}
	}
#else	
	{
		int i;
		for (i = 0 ; icon_names[i] ; ++i)
			if ((asim = load_environment_icon ("devices", icon_names[i], DEFAULT_TILE_WIDTH)) != NULL)
				break;
	}
#endif
	g_strfreev (icon_names);
	return asim;
}
Example #19
0
static GdkPixbuf *
get_fallback_icon (void)
{
    GtkIconTheme *icon_theme;
    GtkIconInfo *icon_info;
    GdkPixbuf *pix;
    GIcon *icon = NULL;

    icon_theme = gtk_icon_theme_get_default ();
    icon = g_content_type_get_icon ("application/x-font-ttf");
    icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, 
                                                128, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
    g_object_unref (icon);

    if (!icon_info)
        return NULL;

    pix = gtk_icon_info_load_icon (icon_info, NULL);
    gtk_icon_info_free (icon_info);

    return pix;
}
Example #20
0
static GdkPixbuf *
load_pixbuf_fallback(AsyncTextureLoadData *data)
{
  GdkPixbuf *pixbuf = NULL;

  if (data->thumbnail)
    {

      GtkIconTheme *theme = gtk_icon_theme_get_default ();

      if (data->recent_info)
          pixbuf = gtk_recent_info_get_icon (data->recent_info, data->width);
      else
        {
          GIcon *icon = icon_for_mimetype (data->mimetype);
          if (icon != NULL)
            {
              GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (theme,
                                                                       icon,
                                                                       data->width,
                                                                       GTK_ICON_LOOKUP_USE_BUILTIN);
              g_object_unref (icon);
              if (icon_info != NULL)
                pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
            }
        }

      if (pixbuf == NULL)
        pixbuf = gtk_icon_theme_load_icon (theme,
                                           "gtk-file",
                                           data->width,
                                           GTK_ICON_LOOKUP_USE_BUILTIN,
                                           NULL);
    }
  /* Maybe we could need a fallback for outher image types? */

  return pixbuf;
}
Example #21
0
wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime)
{
    wxString icon;
#if GTK_CHECK_VERSION(2,14,0)
    if (!wx_is_at_least_gtk2(14))
        return icon;

    wxGtkString type(g_content_type_from_mime_type(mime.utf8_str()));

    wxGtkObject<GIcon> gicon(g_content_type_get_icon(type));
    if ( !gicon )
        return icon;

    GtkIconTheme *theme(gtk_icon_theme_get_default());
    if ( !theme )
        return icon;

    // Notice that we can't use wxGtkObject here because a special function
    // needs to be used for freeing this object prior to GTK+ 3.8.
    GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon
                                   (
                                        theme,
                                        gicon,
                                        256,
                                        GTK_ICON_LOOKUP_NO_SVG
                                   );

    if ( giconinfo )
    {
        icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo));

        wxGCC_WARNING_SUPPRESS(deprecated-declarations)
        gtk_icon_info_free(giconinfo);
        wxGCC_WARNING_RESTORE()
    }
#endif // GTK_CHECK_VERSION(2,14,0)
    return icon;
}
Example #22
0
static gboolean
swatch_draw (GtkWidget *widget,
             cairo_t   *cr)
{
  GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
  gdouble width, height;
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkIconTheme *theme;
  GtkBorder border, padding;
  GdkRectangle rect;
  GtkIconInfo *icon_info = NULL;

  theme = gtk_icon_theme_get_default ();
  context = gtk_widget_get_style_context (widget);
  state = gtk_style_context_get_state (context);
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  gtk_render_background (context, cr, 0, 0, width, height);

  if (swatch->priv->has_color)
    {
      cairo_pattern_t *pattern;
      cairo_matrix_t matrix;

      gtk_render_content_path (context, cr, 0, 0, width, height);

      if (swatch->priv->use_alpha)
        {
          cairo_save (cr);

          cairo_clip_preserve (cr);

          cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
          cairo_fill_preserve (cr);

          pattern = _gtk_color_chooser_get_checkered_pattern ();
          cairo_matrix_init_scale (&matrix, 0.125, 0.125);
          cairo_pattern_set_matrix (pattern, &matrix);

          cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
          cairo_mask (cr, pattern);
          cairo_pattern_destroy (pattern);

          cairo_restore (cr);

          gdk_cairo_set_source_rgba (cr, &swatch->priv->color);
        }
      else
        {
          cairo_set_source_rgb (cr,
                                swatch->priv->color.red,
                                swatch->priv->color.green,
                                swatch->priv->color.blue);
        }

      cairo_fill (cr);
    }

  gtk_render_frame (context, cr, 0, 0, width, height);

  if (swatch->priv->icon)
    {
      icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, PIXBUF_SIZE,
                                              GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                              | GTK_ICON_LOOKUP_USE_BUILTIN);
    }
  else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
    {
      GIcon *gicon;

      gicon = g_themed_icon_new ("object-select-symbolic");
      /* fallback for themes that don't have object-select-symbolic */
      g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");

      icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, PIXBUF_SIZE,
                                                  GTK_ICON_LOOKUP_GENERIC_FALLBACK
                                                  | GTK_ICON_LOOKUP_USE_BUILTIN);
      g_object_unref (gicon);
    }

  /* now draw the overlay image */
  gtk_style_context_get_border (context, state, &border);
  gtk_style_context_get_padding (context, state, &padding);
  rect.width = width - (border.left + border.right + padding.left + padding.right);
  rect.height = height - (border.top + border.bottom + padding.top + padding.bottom);
  rect.x = border.left + padding.left;
  rect.y = border.top + padding.top;

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, "overlay");
  
  gtk_render_background (context, cr, rect.x, rect.y, rect.width, rect.height);
  gtk_render_frame (context, cr, rect.x, rect.y, rect.width, rect.height);

  if (icon_info != NULL)
    {
      GdkPixbuf *pixbuf;

      pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context,
                                                        NULL, NULL);

      if (pixbuf != NULL)
        {
          gtk_render_icon (context, cr, pixbuf,
                           rect.x + (rect.width - gdk_pixbuf_get_width (pixbuf)) / 2,
                           rect.y + (rect.height - gdk_pixbuf_get_height (pixbuf)) / 2);
          g_object_unref (pixbuf);
        }

      g_object_unref (icon_info);
    }

  if (gtk_widget_has_visible_focus (widget))
    {
      gtk_render_focus (context, cr, 0, 0, width, height);
    }

  gtk_style_context_restore (context);

  return FALSE;
}
nsresult
nsIconChannel::InitWithGIO(nsIMozIconURI *aIconURI)
{
    GIcon *icon = NULL;
    nsCOMPtr<nsIURL> fileURI;

    // Read icon content
    aIconURI->GetIconURL(getter_AddRefs(fileURI));

    // Get icon for file specified by URI
    if (fileURI) {
        bool isFile;
        nsAutoCString spec;
        fileURI->GetAsciiSpec(spec);
        if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) {
            GFile *file = g_file_new_for_uri(spec.get());
            GFileInfo *fileInfo = g_file_query_info(file,
                                                    G_FILE_ATTRIBUTE_STANDARD_ICON,
                                                    G_FILE_QUERY_INFO_NONE, NULL, NULL);
            g_object_unref(file);
            if (fileInfo) {
                // icon from g_content_type_get_icon doesn't need unref
                icon = g_file_info_get_icon(fileInfo);
                if (icon)
                    g_object_ref(icon);
                g_object_unref(fileInfo);
            }
        }
    }

    // Try to get icon by using MIME type
    if (!icon) {
        nsAutoCString type;
        aIconURI->GetContentType(type);
        // Try to get MIME type from file extension by using nsIMIMEService
        if (type.IsEmpty()) {
            nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1"));
            if (ms) {
                nsAutoCString fileExt;
                aIconURI->GetFileExtension(fileExt);
                ms->GetTypeFromExtension(fileExt, type);
            }
        }
        char *ctype = NULL; // character representation of content type
        if (!type.IsEmpty()) {
            ctype = g_content_type_from_mime_type(type.get());
        }
        if (ctype) {
            icon = g_content_type_get_icon(ctype);
            g_free(ctype);
        }
    }

    // Get default icon theme
    GtkIconTheme *iconTheme = gtk_icon_theme_get_default();
    GtkIconInfo *iconInfo = NULL;
    // Get icon size
    int32_t iconSize = GetIconSize(aIconURI);

    if (icon) {
        // Use icon and theme to get GtkIconInfo
        iconInfo = gtk_icon_theme_lookup_by_gicon(iconTheme,
                   icon, iconSize,
                   (GtkIconLookupFlags)0);
        g_object_unref(icon);
    }

    if (!iconInfo) {
        // Mozilla's mimetype lookup failed. Try the "unknown" icon.
        iconInfo = gtk_icon_theme_lookup_icon(iconTheme,
                                              "unknown", iconSize,
                                              (GtkIconLookupFlags)0);
        if (!iconInfo) {
            return NS_ERROR_NOT_AVAILABLE;
        }
    }

    // Create a GdkPixbuf buffer containing icon and scale it
    GdkPixbuf* buf = gtk_icon_info_load_icon(iconInfo, NULL);
    gtk_icon_info_free(iconInfo);
    if (!buf) {
        return NS_ERROR_UNEXPECTED;
    }

    nsresult rv = ScaleIconBuf(&buf, iconSize);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = moz_gdk_pixbuf_to_channel(buf, aIconURI,
                                   getter_AddRefs(mRealChannel));
    g_object_unref(buf);
    return rv;
}
Example #24
0
/**
 * gd_create_symbolic_icon:
 * @name:
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_symbolic_icon (const gchar *name,
                         gint base_size)
{
  gchar *symbolic_name;
  GIcon *icon, *retval = NULL;
  cairo_surface_t *surface;
  cairo_t *cr;
  GtkStyleContext *style;
  GtkWidgetPath *path;
  GdkPixbuf *pixbuf;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  gint bg_size;
  gint emblem_size;
  gint total_size;

  total_size = base_size / 2;
  bg_size = MAX (total_size / 2, _BG_MIN_SIZE);
  emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size, total_size);
  cr = cairo_create (surface);

  style = gtk_style_context_new ();

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (style, path);
  gtk_widget_path_unref (path);

  gtk_style_context_add_class (style, "documents-icon-bg");

  gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size);

  symbolic_name = g_strconcat (name, "-symbolic", NULL);
  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
  g_free (symbolic_name);

  theme = gtk_icon_theme_get_default();
  info = gtk_icon_theme_lookup_by_gicon (theme, icon, emblem_size,
                                         GTK_ICON_LOOKUP_FORCE_SIZE);
  g_object_unref (icon);

  if (info == NULL)
    goto out;

  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
  gtk_icon_info_free (info);

  if (pixbuf == NULL)
    goto out;

  gtk_render_icon (style, cr, pixbuf, (total_size - emblem_size) / 2,  (total_size - emblem_size) / 2);
  g_object_unref (pixbuf);

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size, total_size));

 out:
  g_object_unref (style);
  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  return retval;
}
void
xfburn_directory_browser_load_path (XfburnDirectoryBrowser * browser, const gchar * path)
{
  XfburnDirectoryBrowserPrivate *priv = XFBURN_DIRECTORY_BROWSER_GET_PRIVATE (browser);
  
  GtkTreeModel *model;
  GDir *dir;
  GError *error = NULL;
  GdkPixbuf *icon_directory, *icon_file;
  const gchar *dir_entry;
  int x, y;
  gchar *temp;
  GdkScreen *screen;
  GtkIconTheme *icon_theme;
  gboolean show_hidden;
  
  dir = g_dir_open (path, 0, &error);
  if (!dir) {
    g_warning ("unable to open the %s directory : %s", path, error->message);
    g_error_free (error);
    return;
  }
  
  temp = g_strdup (path);
  g_free (priv->current_path);
  priv->current_path = temp;
 
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (browser));
  gtk_list_store_clear (GTK_LIST_STORE (model));

  screen = gtk_widget_get_screen (GTK_WIDGET (browser));
  icon_theme = gtk_icon_theme_get_for_screen (screen);

  gtk_icon_size_lookup (GTK_ICON_SIZE_SMALL_TOOLBAR, &x, &y);
  icon_directory = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory", x, 0, NULL);
  icon_file = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-regular", x, 0, NULL);

  show_hidden = xfburn_settings_get_boolean ("show-hidden-files", FALSE);

  while ((dir_entry = g_dir_read_name (dir))) {
    gchar *full_path;
    struct stat s;

    if (dir_entry[0] == '.') {
      /* skip . and .. */
      if (dir_entry[1] == '\0' ||
          (dir_entry[1] == '.' && dir_entry[2] == '\0'))
        continue;

      if (!show_hidden)
        continue;
    }

    full_path = g_build_filename (path, dir_entry, NULL);
#if 0
    if (g_file_test (full_path, G_FILE_TEST_IS_SYMLINK)) {
      g_free (full_path);
      continue;
    }
#endif

    if (stat (full_path, &s) == 0) {
      gchar *humansize;

      gchar *path_utf8;
      GError *conv_error = NULL;

      /* from the g_dir_read_name () docs: most of the time Linux stores 
         filenames in utf8, but older versions might not, so convert here */

      path_utf8 = g_filename_to_utf8 (full_path, -1, NULL, NULL, &conv_error);

      if (!path_utf8 || conv_error) {
        g_warning ("Failed to convert filename '%s' to utf8: %s. Falling back to native encoding.", full_path, conv_error->message);
        path_utf8 = g_strdup (full_path);

        if (conv_error)
          g_error_free (conv_error);
      }
      
      humansize = xfburn_humanreadable_filesize (s.st_size);
      
      if ((s.st_mode & S_IFDIR)) {
        GtkTreeIter iter;
        
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                            DIRECTORY_BROWSER_COLUMN_ICON, icon_directory,
                            DIRECTORY_BROWSER_COLUMN_FILE, dir_entry,
                            DIRECTORY_BROWSER_COLUMN_HUMANSIZE, humansize,
                            DIRECTORY_BROWSER_COLUMN_SIZE, (guint64) s.st_size,
                            DIRECTORY_BROWSER_COLUMN_TYPE, _(DIRECTORY), DIRECTORY_BROWSER_COLUMN_PATH, path_utf8, -1);
      }
      else if ((s.st_mode & S_IFREG)) {
        GtkTreeIter iter;
        GFileInfo *mime_info = NULL;
        GIcon *mime_icon = NULL;
        GdkPixbuf *mime_icon_pixbuf = NULL;
        const gchar *mime_str = NULL;
        GFile *file = NULL;
        const gchar *content_type = NULL;

        gtk_list_store_append (GTK_LIST_STORE (model), &iter);

        file = g_file_new_for_path(path_utf8);
        mime_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
        content_type = g_file_info_get_content_type (mime_info);
	mime_str = g_content_type_get_description (content_type);
        mime_icon = g_content_type_get_icon (content_type);
        if (mime_icon != NULL) {
            GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, mime_icon, x, GTK_ICON_LOOKUP_USE_BUILTIN);
            if (icon_info != NULL) {
                mime_icon_pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
                gtk_icon_info_free (icon_info);
            }
            g_object_unref (mime_icon);
        }
	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                            DIRECTORY_BROWSER_COLUMN_ICON, (G_IS_OBJECT (mime_icon_pixbuf) ? mime_icon_pixbuf : icon_file),
                            DIRECTORY_BROWSER_COLUMN_FILE, dir_entry,
                            DIRECTORY_BROWSER_COLUMN_HUMANSIZE, humansize,
                            DIRECTORY_BROWSER_COLUMN_SIZE, (guint64) s.st_size,
                            DIRECTORY_BROWSER_COLUMN_TYPE, mime_str, DIRECTORY_BROWSER_COLUMN_PATH, path_utf8, -1);
        g_object_unref(file);
      }
      g_free (humansize);
      g_free (path_utf8);
    }
    g_free (full_path);
  }

  if (icon_directory)
    g_object_unref (icon_directory);
  if (icon_file)
    g_object_unref (icon_file);

  g_dir_close (dir);
}
Example #26
0
static void
exo_cell_renderer_icon_render (GtkCellRenderer     *renderer,
                               GdkWindow           *window,
                               GtkWidget           *widget,
                               GdkRectangle        *background_area,
                               GdkRectangle        *cell_area,
                               GdkRectangle        *expose_area,
                               GtkCellRendererState flags)
{
  const ExoCellRendererIconPrivate *priv = EXO_CELL_RENDERER_ICON_GET_PRIVATE (renderer);
  GtkIconSource                    *icon_source;
  GtkIconTheme                     *icon_theme;
  GdkRectangle                      icon_area;
  GdkRectangle                      draw_area;
  GtkStateType                      state;
  const gchar                      *filename;
  GtkIconInfo                      *icon_info = NULL;
  GdkPixbuf                        *icon = NULL;
  GdkPixbuf                        *temp;
  GError                           *err = NULL;
  gchar                            *display_name = NULL;
  gint                             *icon_sizes;
  gint                              icon_size;
  gint                              n;

  /* verify that we have an icon */
  if (G_UNLIKELY (priv->icon == NULL && priv->gicon == NULL))
    return;

  /* icon may be either an image file or a named icon */
  if (priv->icon != NULL && g_path_is_absolute (priv->icon))
    {
      /* load the icon via the thumbnail database */
      icon = _exo_thumbnail_get_for_file (priv->icon, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err);
    }
  else if (priv->icon != NULL || priv->gicon != NULL)
    {
      /* determine the best icon size (GtkIconTheme is somewhat messy scaling up small icons) */
      icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));

      if (priv->icon != NULL)
        {
          icon_sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->icon);
          for (icon_size = -1, n = 0; icon_sizes[n] != 0; ++n)
            {
              /* we can use any size if scalable, because we load the file directly */
              if (icon_sizes[n] == -1)
                icon_size = priv->size;
              else if (icon_sizes[n] > icon_size && icon_sizes[n] <= priv->size)
                icon_size = icon_sizes[n];
            }
          g_free (icon_sizes);

          /* if we don't know any icon sizes at all, the icon is probably not present */
          if (G_UNLIKELY (icon_size < 0))
            icon_size = priv->size;

          /* lookup the icon in the icon theme */
          icon_info = gtk_icon_theme_lookup_icon (icon_theme, priv->icon, icon_size, 0);
        }
      else if (priv->gicon != NULL)
        {
          icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme,
                                                      priv->gicon,
                                                      priv->size,
                                                      GTK_ICON_LOOKUP_USE_BUILTIN);
        }

      if (G_UNLIKELY (icon_info == NULL))
        return;

      /* check if we have an SVG icon here */
      filename = gtk_icon_info_get_filename (icon_info);
      if (filename != NULL && g_str_has_suffix (filename, ".svg"))
        {
          /* loading SVG icons is terribly slow, so we try to use thumbnail instead, and we use the
           * real available cell area directly here, because loading thumbnails involves scaling anyway
           * and this way we need to the thumbnail pixbuf scale only once.
           */
          icon = _exo_thumbnail_get_for_file (filename, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err);
        }
      else
        {
          /* regularly load the icon from the theme */
          icon = gtk_icon_info_load_icon (icon_info, &err);
        }
      gtk_icon_info_free (icon_info);
    }

  /* check if we failed */
  if (G_UNLIKELY (icon == NULL))
    {
      /* better let the user know whats going on, might be surprising otherwise */
      if (G_LIKELY (priv->icon != NULL))
        {
          display_name = g_filename_display_name (priv->icon);
        }
      else if (G_UNLIKELY (priv->gicon != NULL
                           && g_object_class_find_property (G_OBJECT_GET_CLASS (priv->gicon),
                                                            "name")))
        {
          g_object_get (priv->gicon, "name", &display_name, NULL);
        }

      if (display_name != NULL)
        {
          g_warning ("Failed to load \"%s\": %s", display_name, err->message);
          g_free (display_name);
        }

      g_error_free (err);
      return;
    }

  /* determine the real icon size */
  icon_area.width = gdk_pixbuf_get_width (icon);
  icon_area.height = gdk_pixbuf_get_height (icon);

  /* scale down the icon on-demand */
  if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height))
    {
      /* scale down to fit */
      temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height);
      g_object_unref (G_OBJECT (icon));
      icon = temp;

      /* determine the icon dimensions again */
      icon_area.width = gdk_pixbuf_get_width (icon);
      icon_area.height = gdk_pixbuf_get_height (icon);
    }

  icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2;
  icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2;

  /* check whether the icon is affected by the expose event */
  if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area))
    {
      /* colorize the icon if we should follow the selection state */
      if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && priv->follow_state)
        {
          if ((flags & GTK_CELL_RENDERER_SELECTED) != 0)
            {
              state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
              temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }

          if ((flags & GTK_CELL_RENDERER_PRELIT) != 0)
            {
              temp = exo_gdk_pixbuf_spotlight (icon);
              g_object_unref (G_OBJECT (icon));
              icon = temp;
            }
        }

      /* check if we should render an insensitive icon */
      if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive))
        {
          /* allocate an icon source */
          icon_source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (icon_source, icon);
          gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
          gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR);

          /* render the insensitive icon */
          temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget),
                                        GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf");
          g_object_unref (G_OBJECT (icon));
          icon = temp;

          /* release the icon source */
          gtk_icon_source_free (icon_source);
        }

      /* render the invalid parts of the icon */
      gdk_draw_pixbuf (window, widget->style->black_gc, icon,
                       draw_area.x - icon_area.x, draw_area.y - icon_area.y,
                       draw_area.x, draw_area.y, draw_area.width, draw_area.height,
                       GDK_RGB_DITHER_NORMAL, 0, 0);
    }

  /* release the file's icon */
  g_object_unref (G_OBJECT (icon));
}
Example #27
0
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);
        }
}
Example #28
0
static GPtrArray *
ct_name_render (DonnaColumnType    *ct,
                gpointer            data,
                guint               index,
                DonnaNode          *node,
                GtkCellRenderer    *renderer)
{
    g_return_val_if_fail (DONNA_IS_COLUMN_TYPE_NAME (ct), NULL);

    if (index == 1)
    {
        DonnaNodeHasValue has_value;
        GIcon *icon;

        has_value = donna_node_get_icon (node, FALSE, &icon);
        if (has_value == DONNA_NODE_VALUE_SET)
        {
            GtkIconInfo *info;

            info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
                    icon, 16, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
            g_object_unref (icon);
            if (info)
            {
                g_object_unref (info);
                g_object_set (renderer, "visible", TRUE, "gicon", icon, NULL);
                return NULL;
            }

            /* fallthrough if lookup failed, so instead of showing tke "broken"
             * image, we can default to the file/folder one */
        }
        else if (has_value == DONNA_NODE_VALUE_NEED_REFRESH)
        {
            GPtrArray *arr;

            arr = g_ptr_array_sized_new (1);
            g_ptr_array_add (arr, (gpointer) "icon");
            return arr;
        }

        if (donna_node_get_node_type (node) == DONNA_NODE_ITEM)
            g_object_set (renderer,
                    "visible",      TRUE,
                    "icon-name",    "text-x-generic",
                    NULL);
        else /* DONNA_NODE_CONTAINER */
            g_object_set (renderer,
                    "visible",      TRUE,
                    "icon-name",    "folder",
                    NULL);
    }
    else /* index == 2 */
    {
        gchar *name;

        name = donna_node_get_name (node);
        g_object_set (renderer,
                "visible",      TRUE,
                "text",         name,
                "ellipsize",    PANGO_ELLIPSIZE_END,
                "ellipsize-set",TRUE,
                NULL);
        donna_renderer_set (renderer, "ellipsize-set", NULL);
        g_free (name);
    }

    return NULL;
}
Example #29
0
static void
photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
{
  PhotosBaseItemPrivate *priv = self->priv;
  GApplication *app;
  GIcon *pix;
  GList *emblem_icons = NULL;
  GList *windows;
  GdkPixbuf *emblemed_pixbuf = NULL;
  GdkPixbuf *thumbnailed_pixbuf = NULL;
  GdkWindow *window;
  gint scale;

  if (priv->original_icon == NULL)
    goto out;

  emblemed_pixbuf = g_object_ref (priv->original_icon);

  if (priv->favorite)
    {
      pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE);
      emblem_icons = g_list_prepend (emblem_icons, pix);
    }

  if (g_list_length (emblem_icons) > 0)
    {
      GIcon *emblemed_icon;
      GList *l;
      GtkIconInfo *icon_info;
      GtkIconTheme *theme;
      gint height;
      gint size;
      gint width;

      emblem_icons = g_list_reverse (emblem_icons);
      emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL);
      for (l = emblem_icons; l != NULL; l = g_list_next (l))
        {
          GEmblem *emblem;
          GIcon *emblem_icon = G_ICON (l->data);

          emblem = g_emblem_new (emblem_icon);
          g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
          g_object_unref (emblem);
        }

      theme = gtk_icon_theme_get_default ();

      width = gdk_pixbuf_get_width (priv->original_icon);
      height = gdk_pixbuf_get_height (priv->original_icon);
      size = (width > height) ? width : height;

      icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);

      if (icon_info != NULL)
        {
          GError *error = NULL;
          GdkPixbuf *tmp;

          tmp = gtk_icon_info_load_icon (icon_info, &error);
          if (error != NULL)
            {
              g_warning ("Unable to render the emblem: %s", error->message);
              g_error_free (error);
            }
          else
            {
              g_object_unref (emblemed_pixbuf);
              emblemed_pixbuf = tmp;
            }

          g_object_unref (icon_info);
        }

      g_object_unref (emblemed_icon);
    }

  g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);

  if (priv->thumb_path != NULL)
    {
      GtkBorder *slice;

      slice = photos_utils_get_thumbnail_frame_border ();
      thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf,
                                                    "resource:///org/gnome/photos/thumbnail-frame.png",
                                                    slice,
                                                    slice);
      gtk_border_free (slice);
    }
  else
    thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf);

  app = g_application_get_default ();
  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
  windows = gtk_application_get_windows (GTK_APPLICATION (app));
  window = gtk_widget_get_window (GTK_WIDGET (windows->data));
  priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window);

  g_signal_emit (self, signals[INFO_UPDATED], 0);

 out:
  g_clear_object (&thumbnailed_pixbuf);
  g_clear_object (&emblemed_pixbuf);
  g_list_free_full (emblem_icons, g_object_unref);
}
Example #30
0
static ClutterActor *
load_gicon_with_colors (StTextureCache    *cache,
                        GIcon             *icon,
                        gint               size,
                        StIconColors      *colors)
{
  AsyncTextureLoadData *request;
  ClutterActor *texture;
  char *gicon_string;
  char *key;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  StTextureCachePolicy policy;

  /* Do theme lookups in the main thread to avoid thread-unsafety */
  theme = cache->priv->icon_theme;

  info = gtk_icon_theme_lookup_by_gicon (theme, icon, size, GTK_ICON_LOOKUP_USE_BUILTIN);
  if (info == NULL)
    return NULL;

  gicon_string = g_icon_to_string (icon);
  /* A return value of NULL indicates that the icon can not be serialized,
   * so don't have a unique identifier for it as a cache key, and thus can't
   * be cached. If it is cachable, we hardcode a policy of FOREVER here for
   * now; we should actually blow this away on icon theme changes probably */
  policy = gicon_string != NULL ? ST_TEXTURE_CACHE_POLICY_FOREVER
                                : ST_TEXTURE_CACHE_POLICY_NONE;
  if (colors)
    {
      /* This raises some doubts about the practice of using string keys */
      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x",
                             gicon_string, size,
                             colors->foreground.red, colors->foreground.blue, colors->foreground.green, colors->foreground.alpha,
                             colors->warning.red, colors->warning.blue, colors->warning.green, colors->warning.alpha,
                             colors->error.red, colors->error.blue, colors->error.green, colors->error.alpha,
                             colors->success.red, colors->success.blue, colors->success.green, colors->success.alpha);
    }
  else
    {
      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d",
                             gicon_string, size);
    }
  g_free (gicon_string);

  texture = (ClutterActor *) create_default_texture ();
  clutter_actor_set_size (texture, size, size);

  if (ensure_request (cache, key, policy, &request, texture))
    {
      /* If there's an outstanding request, we've just added ourselves to it */
      g_object_unref (info);
      g_free (key);
    }
  else
    {
      /* Else, make a new request */

      request->cache = cache;
      /* Transfer ownership of key */
      request->key = key;
      request->policy = policy;
      request->colors = colors ? st_icon_colors_ref (colors) : NULL;
      request->icon_info = info;
      request->width = request->height = size;
      request->enforced_square = TRUE;

      load_texture_async (cache, request);
    }

  return CLUTTER_ACTOR (texture);
}