Ejemplo n.º 1
0
int
clip_GTK_ICONTHEMEGETICONSIZES(ClipMachine * cm)
{
        C_object  *cicon  = _fetch_co_arg(cm);
        gchar *icon_name  = _clip_parc(cm, 2);
        ClipVar     *cv   = RETPTR(cm);
        gint         *a   ;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);

	LOCALE_TO_UTF(icon_name);
	a = gtk_icon_theme_get_icon_sizes(GTK_ICON_THEME(cicon->object), icon_name);
        FREE_TEXT(icon_name);

	_clip_array(cm, cv, 0, 0);
	while (a)
	{
		ClipVar *item;
		item = NEW(ClipVar);
		item->t.type = NUMERIC_t;
		item->t.flags = 0;
		item->n.d = a[0];
		_clip_aadd(cm, cv, item);
		_clip_delete(cm, item);
                a++;
	}

	free(a);

	return 0;
err:
	return 1;
}
Ejemplo n.º 2
0
int
clip_GTK_ICONTHEMELOADICON(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   = _clip_parc(cm, 2);
        gint       size   = _clip_parni(cm, 3);
        GtkIconLookupFlags flags = _clip_parni(cm, 4);
        GError   *error   ;
        C_object *cpixbuf ;
        GdkPixbuf *pixbuf ;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);
        CHECKARG(3, NUMERIC_t);
        CHECKARG(4, NUMERIC_t);

	pixbuf = gtk_icon_theme_load_icon(GTK_ICON_THEME(cicon->object),
			name, size, flags, &error);

	if (pixbuf)
        {
        	cpixbuf = _list_get_cobject(cm, pixbuf);
                if (!cpixbuf) cpixbuf = _register_object(cm, pixbuf, GDK_TYPE_PIXBUF, NULL, NULL);
                if (cpixbuf) _clip_mclone(cm, RETPTR(cm), &cpixbuf->obj);
        }

	return 0;
err:
	return 1;
}
Ejemplo n.º 3
0
int
clip_GTK_ICONTHEMELISTICONS(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   = _clip_parc(cm, 2);
        ClipVar     *cv   = RETPTR(cm);
        GList     *list   ;
        long          n   ;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);

	list = gtk_icon_theme_list_icons(GTK_ICON_THEME(cicon->object),
			name);
	n = g_list_length(list);
        _clip_array(cm, cv, 1, &n);
        for (n=0; list; list = g_list_next(list), n++)
        {
        	ClipVar c;
                gchar *str;

		str = (gchar *)(list->data);
                _clip_var_str(str, strlen(str), &c);
        	_clip_aset(cm, cv, &c, 1, &n);
                _clip_destroy(cm, &c);
                g_free(str);
        }
        g_list_free(list);
	return 0;
err:
	return 1;
}
Ejemplo n.º 4
0
int
clip_GTK_ICONTHEMEGETSEARCHPATH(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        ClipVar     *cv   = RETPTR(cm) ;
	gchar    **path   ;
        gint n_elements   ;
        long          i   ;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));

	gtk_icon_theme_get_search_path(GTK_ICON_THEME(cicon->object),
		&path, &n_elements);
	i = n_elements;
	_clip_array(cm, cv, 1, &i);
        for(i=0; i<n_elements; i++)
        {
        	ClipVar c;
                _clip_var_str(path[i], strlen(path[i]), &c);
                _clip_aset(cm, cv, &c, 1, &i);
                _clip_destroy(cm, &c);
        }
        g_strfreev(path);
	return 0;
err:
	return 1;
}
Ejemplo n.º 5
0
int
clip_GTK_ICONTHEMESETSEARCHPATH(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        ClipArrVar  *cv   = (ClipArrVar *)_clip_vptr(_clip_spar(cm, 2));
        gint n_elements   = _clip_parni(cm, 3);
        gint          i;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
	CHECKARG(2, ARRAY_t);
        CHECKARG(3, NUMERIC_t);

	i = cv->count;
        n_elements = (i<n_elements)?i:n_elements;
	if (cv)
        {
		const gchar *path[n_elements];
                ClipVar *s;
		for (i=0; i<n_elements; i++)
                {
                	s = &cv->items[i];
                	path[i] = s->s.str.buf;
		}
		gtk_icon_theme_set_search_path(GTK_ICON_THEME(cicon->object),
			path, n_elements);
        }
	return 0;
err:
	return 1;
}
Ejemplo n.º 6
0
int
clip_GTK_ICONTHEMERESCANIFNEEDED(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));

	_clip_retl(cm, gtk_icon_theme_rescan_if_needed(GTK_ICON_THEME(cicon->object)));

	return 0;
err:
	return 1;
}
Ejemplo n.º 7
0
int
clip_GTK_ICONTHEMEHASICON(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   = _clip_parc(cm, 2);

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);

	_clip_retl(cm, gtk_icon_theme_has_icon(GTK_ICON_THEME(cicon->object),
			name));
	return 0;
err:
	return 1;
}
Ejemplo n.º 8
0
int
clip_GTK_ICONTHEMESETCUSTOMTHEME(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   = _clip_parc(cm, 2);

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);

	gtk_icon_theme_set_custom_theme(GTK_ICON_THEME(cicon->object),
			name);
	return 0;
err:
	return 1;
}
Ejemplo n.º 9
0
int
clip_GTK_ICONTHEMEPREPENDSEARCHPATH(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *path   = _clip_parc(cm, 2);

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);

	gtk_icon_theme_prepend_search_path(GTK_ICON_THEME(cicon->object),
			path);
	return 0;
err:
	return 1;
}
Ejemplo n.º 10
0
int
clip_GTK_ICONTHEMESETSCREEN(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        C_object *cscreen = _fetch_cobject(cm, _clip_spar(cm, 2));

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
	CHECKCOBJ(cscreen, GDK_IS_SCREEN(cscreen->object));

	gtk_icon_theme_set_screen(GTK_ICON_THEME(cicon->object),
		GDK_SCREEN(cscreen->object));

	return 0;
err:
	return 1;
}
Ejemplo n.º 11
0
int
clip_GTK_ICONTHEMEGETEXAMPLEICONNAME(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   ;

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));

	name = gtk_icon_theme_get_example_icon_name(GTK_ICON_THEME(cicon->object));

	_clip_retc(cm, name);

        g_free(name);
	return 0;
err:
	return 1;
}
Ejemplo n.º 12
0
int
clip_GTK_ICONTHEMELOOKUPICON(ClipMachine * cm)
{
        C_object *cicon   = _fetch_co_arg(cm);
        gchar     *name   = _clip_parc(cm, 2);
        gint       size   = _clip_parni(cm, 3);
        GtkIconLookupFlags flags = _clip_parni(cm, 4);

	CHECKCOBJ(cicon, GTK_IS_ICON_THEME(cicon->object));
        CHECKARG(2, CHARACTER_t);
        CHECKARG(3, NUMERIC_t);
        CHECKARG(4, NUMERIC_t);

	gtk_icon_theme_lookup_icon(GTK_ICON_THEME(cicon->object),
			name, size, flags);
	return 0;
err:
	return 1;
}
/**
 * xfce_panel_pixbuf_from_source_at_size:
 * @source: string that contains the location of an icon
 * @icon_theme: icon theme or %NULL to use the default icon theme
 * @dest_width: the maximum returned width of the GdkPixbuf
 * @dest_height: the maximum returned height of the GdkPixbuf
 *
 * Try to load a pixbuf from a source string. The source could be
 * an abolute path, an icon name or a filename that points to a
 * file in the pixmaps directory.
 *
 * This function is particularly usefull for loading names from
 * the Icon key of desktop files.
 *
 * The pixbuf is never bigger than @dest_width and @dest_height.
 * If it is when loaded from the disk, the pixbuf is scaled
 * preserving the aspect ratio.
 *
 * Returns: a GdkPixbuf or %NULL if nothing was found. The value should
 *          be released with g_object_unref when no longer used.
 *
 * See also: XfcePanelImage
 *
 * Since: 4.10
 **/
GdkPixbuf *
xfce_panel_pixbuf_from_source_at_size (const gchar  *source,
                                       GtkIconTheme *icon_theme,
                                       gint          dest_width,
                                       gint          dest_height)
{
  GdkPixbuf *pixbuf = NULL;
  gchar     *p;
  gchar     *name;
  gchar     *filename;
  gint       src_w, src_h;
  gdouble    ratio;
  GdkPixbuf *dest;
  GError    *error = NULL;
  gint       size = MIN (dest_width, dest_height);

  g_return_val_if_fail (source != NULL, NULL);
  g_return_val_if_fail (icon_theme == NULL || GTK_IS_ICON_THEME (icon_theme), NULL);
  g_return_val_if_fail (dest_width > 0, NULL);
  g_return_val_if_fail (dest_height > 0, NULL);

  if (G_UNLIKELY (g_path_is_absolute (source)))
    {
      pixbuf = gdk_pixbuf_new_from_file (source, &error);
      if (G_UNLIKELY (pixbuf == NULL))
        {
          g_message ("Failed to load image \"%s\": %s",
                     source, error->message);
          g_error_free (error);
        }
    }
  else
    {
      if (G_UNLIKELY (icon_theme == NULL))
        icon_theme = gtk_icon_theme_get_default ();

      /* try to load from the icon theme */
      pixbuf = gtk_icon_theme_load_icon (icon_theme, source, size, 0, NULL);
      if (G_UNLIKELY (pixbuf == NULL))
        {
          /* try to lookup names like application.png in the theme */
          p = strrchr (source, '.');
          if (p != NULL)
            {
              name = g_strndup (source, p - source);
              pixbuf = gtk_icon_theme_load_icon (icon_theme, name, size, 0, NULL);
              g_free (name);
            }

          /* maybe they point to a file in the pixbufs folder */
          if (G_UNLIKELY (pixbuf == NULL))
            {
              filename = g_build_filename ("pixmaps", source, NULL);
              name = xfce_resource_lookup (XFCE_RESOURCE_DATA, filename);
              g_free (filename);

              if (name != NULL)
                {
                  pixbuf = gdk_pixbuf_new_from_file (name, NULL);
                  g_free (name);
                }
            }
        }
    }

  if (G_UNLIKELY (pixbuf == NULL))
    {
      if (G_UNLIKELY (icon_theme == NULL))
        icon_theme = gtk_icon_theme_get_default ();

      /* bit ugly as a fallback, but in most cases better then no icon */
      pixbuf = gtk_icon_theme_load_icon (icon_theme, GTK_STOCK_MISSING_IMAGE,
                                         size, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
    }

  /* scale the pixbug if required */
  if (G_LIKELY (pixbuf != NULL))
    {
      src_w = gdk_pixbuf_get_width (pixbuf);
      src_h = gdk_pixbuf_get_height (pixbuf);

      if (src_w > dest_width || src_h > dest_height)
        {
          /* calculate the new dimensions */
          ratio = MIN ((gdouble) dest_width / (gdouble) src_w,
                       (gdouble) dest_height / (gdouble) src_h);

          dest_width  = rint (src_w * ratio);
          dest_height = rint (src_h * ratio);

          dest = gdk_pixbuf_scale_simple (pixbuf,
                                          MAX (dest_width, 1),
                                          MAX (dest_height, 1),
                                          GDK_INTERP_BILINEAR);

          g_object_unref (G_OBJECT (pixbuf));
          pixbuf = dest;
        }
    }

  return pixbuf;
}
Ejemplo n.º 14
0
static void
tny_gtk_attach_list_model_add (TnyGtkAttachListModel *self, TnyMimePart *part, listaddfunc func)
{
	GtkListStore *model = GTK_LIST_STORE (self);
	GtkTreeIter iter;
	TnyGtkAttachListModelPriv *priv = TNY_GTK_ATTACH_LIST_MODEL_GET_PRIVATE (self);
	static GdkPixbuf *stock_file_pixbuf = NULL;
	GdkPixbuf *pixbuf;
	gchar *icon;

	if (tny_mime_part_get_content_type (part) &&
			tny_mime_part_is_attachment (part))
	{

		if (!priv->theme || !GTK_IS_ICON_THEME (priv->theme))
		{
			priv->theme = gtk_icon_theme_get_default ();
			g_object_ref (priv->theme);
		}

#ifdef GNOME
		if (priv->theme && GTK_IS_ICON_THEME (priv->theme))
		{
			icon = gnome_icon_lookup (priv->theme, NULL, 
				tny_mime_part_get_filename (part), NULL, NULL,
				tny_mime_part_get_content_type (part), 0, NULL);
		}
#else
		icon = GTK_STOCK_FILE;
#endif

		if (G_LIKELY (icon) && priv->theme && GTK_IS_ICON_THEME (priv->theme))
		{
			pixbuf = gtk_icon_theme_load_icon (priv->theme, icon, 
				GTK_ICON_SIZE_LARGE_TOOLBAR, 0, NULL);
#ifdef GNOME
			g_free (icon);
#endif
		} else {
			if (G_UNLIKELY (!stock_file_pixbuf) && priv->theme && GTK_IS_ICON_THEME (priv->theme))
				stock_file_pixbuf = gtk_icon_theme_load_icon (priv->theme, 
					GTK_STOCK_FILE, GTK_ICON_SIZE_LARGE_TOOLBAR, 
					0, NULL);

			pixbuf = stock_file_pixbuf;
		}

		func (model, &iter);

		gtk_list_store_set (model, &iter,
			TNY_GTK_ATTACH_LIST_MODEL_PIXBUF_COLUMN, 
			pixbuf,
			TNY_GTK_ATTACH_LIST_MODEL_FILENAME_COLUMN, 
			tny_mime_part_get_filename (part),
			TNY_GTK_ATTACH_LIST_MODEL_INSTANCE_COLUMN,
			part, -1);
	} else {

		func (model, &iter);

		gtk_list_store_set (model, &iter,
			TNY_GTK_ATTACH_LIST_MODEL_FILENAME_COLUMN, 
			tny_mime_part_get_description (part)?
				tny_mime_part_get_description (part):
				"Unknown attachment",
			TNY_GTK_ATTACH_LIST_MODEL_INSTANCE_COLUMN,
			part, -1);
	}

	return;
}