gchar *
gkbd_indicator_config_get_images_file (GkbdIndicatorConfig *
				       ind_config,
				       GkbdKeyboardConfig *
				       kbd_config, int group)
{
	char *image_file = NULL;
	GtkIconInfo *icon_info = NULL;

	if (!ind_config->show_flags)
		return NULL;

	if ((kbd_config->layouts_variants != NULL) &&
	    (g_strv_length (kbd_config->layouts_variants) > group)) {
		char *full_layout_name =
		    kbd_config->layouts_variants[group];

		if (full_layout_name != NULL) {
			char *l, *v;
			gkbd_keyboard_config_split_items (full_layout_name,
							  &l, &v);
			if (l != NULL) {
				/* probably there is something in theme? */
				icon_info = gtk_icon_theme_lookup_icon
				    (ind_config->icon_theme, l, 48, 0);

				/* Unbelievable but happens */
				if (icon_info != NULL &&
				    gtk_icon_info_get_filename (icon_info)
				    == NULL) {
					gtk_icon_info_free (icon_info);
					icon_info = NULL;
				}
			}
		}
	}
	/* fallback to the default value */
	if (icon_info == NULL) {
		icon_info = gtk_icon_theme_lookup_icon
		    (ind_config->icon_theme, "stock_dialog-error", 48, 0);
	}
	if (icon_info != NULL) {
		image_file =
		    g_strdup (gtk_icon_info_get_filename (icon_info));
		gtk_icon_info_free (icon_info);
	}

	return image_file;
}
/**
 * e_icon_factory_get_icon_filename:
 * @icon_name: name of the icon
 * @icon_size: size of the icon
 *
 * Returns the filename of the requested icon in the default icon theme.
 *
 * Returns: the filename of the requested icon
 **/
gchar *
e_icon_factory_get_icon_filename (const gchar *icon_name,
                                  GtkIconSize icon_size)
{
	GtkIconTheme *icon_theme;
	GtkIconInfo *icon_info;
	gchar *filename = NULL;
	gint width, height;

	g_return_val_if_fail (icon_name != NULL, NULL);

	icon_theme = gtk_icon_theme_get_default ();

	if (!gtk_icon_size_lookup (icon_size, &width, &height))
		return NULL;

	icon_info = gtk_icon_theme_lookup_icon (
		icon_theme, icon_name, height, 0);
	if (icon_info != NULL) {
		filename = g_strdup (
			gtk_icon_info_get_filename (icon_info));
		gtk_icon_info_free (icon_info);
	}

	return filename;
}
	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);
	}
Exemple #4
0
static GdkPixbuf *
get_themed_icon_pixbuf (GThemedIcon   * icon,
                        int             size,
                        GtkIconTheme  * icon_theme)
{
    char        ** icon_names = NULL;
    GtkIconInfo  * icon_info;
    GdkPixbuf    * pixbuf;
    GError       * error = NULL;

    g_object_get (icon, "names", &icon_names, NULL);

    icon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)icon_names, size, 0);
    if (icon_info == NULL)
        icon_info = gtk_icon_theme_lookup_icon (icon_theme, "text-x-generic", size, GTK_ICON_LOOKUP_USE_BUILTIN);

    pixbuf = gtk_icon_info_load_icon (icon_info, &error);
    if (pixbuf == NULL) {
        if (error && error->message)
            g_warning ("could not load icon pixbuf: %s\n", error->message);
        g_clear_error (&error);
    }

#if GTK_CHECK_VERSION(3,8,0)
    g_object_unref (icon_info);
#else
    gtk_icon_info_free (icon_info);
#endif
    g_strfreev (icon_names);

    return pixbuf;
}
Exemple #5
0
/****f* pekwm-menu/get_item_icon_path
 * OUTPUT
 *   return the path for the themed icon if item.
 *   If no icon found, it returns the "empty" icon path.
 *
 *   The returned string should be freed when no longer needed
 *
 * NOTES
 *   Imlib2, used by OpenBox to display icons, doesn't load SVG graphics.
 *   We have to use GTK_ICON_LOOKUP_NO_SVG flag to look up icons.
 *
 * Notes
 *   Pekwm uses libpng, libjpeg, and libXpm directly rather than Imlib2.
 *   The net effect is the same, just a clarification.
 *
 * TODO
 *   The "2nd fallback" is annoying, I have to think about this.
 ****/
gchar *
get_item_icon_path (MenuCacheItem *item)
{
	GtkIconInfo *icon_info = NULL;
	gchar *icon = NULL;
	gchar *tmp_name = NULL;

	/* type changed from gchar to const char due to removal of get_safe_name function - NF 2013-08-21 */
	const gchar *name = menu_cache_item_get_icon (MENU_CACHE_ITEM(item));

	if (name)
	{
		if (g_path_is_absolute (name))
			return g_strdup (name);

		/*  We remove the file extension as gtk_icon_theme_lookup_icon can't
		 *  lookup a theme icon for, ie, 'geany.png'. It has to be 'geany'.
		 */
		tmp_name = strndup (name, strrchr (name, '.') - name);
	/* Pekwm has no svg support so disabled svg ifdef code completely
	 * NF 2013-08-29*/
		icon_info = gtk_icon_theme_lookup_icon (icon_theme, tmp_name, 16, GTK_ICON_LOOKUP_NO_SVG | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
		g_free (tmp_name);
	}

	if (!icon_info) /* 2nd fallback */
		icon_info = gtk_icon_theme_lookup_icon (icon_theme, "empty", 16, GTK_ICON_LOOKUP_NO_SVG);

	icon = g_strdup (gtk_icon_info_get_filename (icon_info));
	gtk_icon_info_free (icon_info);

	return icon;
}
Exemple #6
0
static const char *get_tray_icon_name (char *name)
{
	const char * icon_name;

	if (strcasecmp(show_in_the_tray, "Icon") == 0)
	{
		icon_name = PACKAGE;
		return icon_name;
	}

	GtkIconTheme * theme = gtk_icon_theme_get_default( );

	// if the tray's icon is a 48x48 file, use it;
	// otherwise, use the fallback builtin icon 
	if (!gtk_icon_theme_has_icon (theme, name))
	{
		icon_name = PACKAGE;
	}
	else
	{
		GtkIconInfo * icon_info = gtk_icon_theme_lookup_icon (theme, name, 48, GTK_ICON_LOOKUP_USE_BUILTIN);
		const gboolean icon_is_builtin = gtk_icon_info_get_filename (icon_info) == NULL;
		gtk_icon_info_free (icon_info);
		icon_name = icon_is_builtin ? PACKAGE : name;
	}

	return icon_name;
}
Exemple #7
0
// iconName should be a icon name constraints to the freeedesktop standard.
QString MainItem::getThemeIconPath(QString iconName)
{
    // iconPath is an absolute path of the system.
    if (QFile::exists(iconName) && iconName.contains(QDir::separator())) {
        return iconName;
    }
    else {
        QByteArray bytes = iconName.toUtf8();
        const char *name = bytes.constData();

        GtkIconTheme* theme = gtk_icon_theme_get_default();

        GtkIconInfo* info = gtk_icon_theme_lookup_icon(theme, name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);

        if (info) {
            char* path = g_strdup(gtk_icon_info_get_filename(info));
#if GTK_MAJOR_VERSION >= 3
            g_object_unref(info);
#elif GTK_MAJOR_VERSION == 2
            gtk_icon_info_free(info);
#endif
            return QString(path);
        } else {
            return "";
        }
    }
}
GdkPixbuf *
pluma_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);
	gtk_icon_info_free (info);
	
	return ret;
}
Exemple #9
0
GdkPixbuf* vfs_load_icon( GtkIconTheme* theme, const char* icon_name, int size )
{
    GdkPixbuf* icon = NULL;
    const char* file;

    if ( !icon_name )
        return NULL;

    GtkIconInfo* inf = gtk_icon_theme_lookup_icon( theme, icon_name, size,
                                             GTK_ICON_LOOKUP_USE_BUILTIN |
                                             GTK_ICON_LOOKUP_FORCE_SIZE );

    if ( !inf && icon_name[0] == '/' )
        return gdk_pixbuf_new_from_file_at_size ( icon_name, size, size, NULL );
    
    if( G_UNLIKELY( ! inf ) )
        return NULL;

    file = gtk_icon_info_get_filename( inf );
    if( G_LIKELY( file ) )
        icon = gdk_pixbuf_new_from_file_at_size( file, size, size, NULL );
    else
    {
        icon = gtk_icon_info_get_builtin_pixbuf( inf );
        g_object_ref( icon );
    }
    gtk_icon_info_free( inf );
/*
    if( G_LIKELY( icon ) )
    {
        // scale down the icon if it's too big
        int width, height;
        height = gdk_pixbuf_get_height(icon);
        width = gdk_pixbuf_get_width(icon);

        if( G_UNLIKELY( height > size || width > size ) )
        {
            GdkPixbuf* scaled;
            if( height > width )
            {
                width = size * height / width;
                height = size;
            }
            else if( height < width )
            {
                height = size * width / height;
                width = size;
            }
            else
                height = width = size;
            scaled = gdk_pixbuf_scale_simple( icon, width, height, GDK_INTERP_BILINEAR );
            g_object_unref( icon );
            icon = scaled;
        }
    }
*/
    return icon;
}
Exemple #10
0
/**
 * gul_gui_image_set_from_mime_type:
 * @image: a #GtkImage
 * @mime_type: a MIME type
 * @icon_size: a stock icon size
 *
 * Set the @image to display the icon for MIME type @mime_type.  Sample MIME
 * types are "text/plain", "application/ogg".  Sample stock sizes are
 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_DIALOG.
 */
void
gul_gui_image_set_from_mime_type (GtkWidget  *image,
		                  const char *mime_type,
				  GtkIconSize icon_size)
{
	GtkIconTheme *theme;
	char           *icon;
	GtkIconSource  *source;
	GtkIconSet     *icon_set;

	g_return_if_fail (GTK_IS_IMAGE(image));
	g_return_if_fail (mime_type != NULL);

	theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (image));

	icon = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
				  mime_type,
				  GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);

	if (!g_path_is_absolute (icon))
	{
		int   width, height;
		GtkIconInfo *icon_info;

		if (!gtk_icon_size_lookup_for_settings 
			(gtk_widget_get_settings (GTK_WIDGET(image)),
			 icon_size, &width, &height))
		{
			width = height = -1;
		}

		icon_info = gtk_icon_theme_lookup_icon (theme, icon, height,0);
		g_free (icon);

		g_return_if_fail (icon_info != NULL);

		icon = g_strdup (gtk_icon_info_get_filename (icon_info));
		gtk_icon_info_free (icon_info);
	}

	/* Now that we have the icon filename, wrap it into an GtkIconSet so
	 * that we really get the desired size; the icon size in the file may
	 * still be arbitrary, in case of SVG themes, for example.
	 */

	source = gtk_icon_source_new ();
	gtk_icon_source_set_filename (source, icon);
	g_free (icon);

	icon_set = gtk_icon_set_new ();
	gtk_icon_set_add_source (icon_set, source);
	gtk_icon_source_free (source);

	gtk_image_set_from_icon_set (GTK_IMAGE(image), icon_set, icon_size);

	gtk_icon_set_unref (icon_set);
}
Exemple #11
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;
}
Exemple #12
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;
}
Exemple #13
0
static GdkPixbuf *
get_fs_icon (IconName icon_name,
	     double   icon_size)
{
	GdkPixbuf *pixbuf = NULL;
	gboolean   scale = TRUE;

	if (icon_pixbuf[icon_name] == NULL) {
		GtkIconInfo         *icon_info = NULL;

		icon_info = gtk_icon_theme_lookup_icon (icon_theme,
							icon_mime_name[icon_name],
							icon_size,
							0);

		if (icon_info == NULL) {
			icon_pixbuf[icon_name] = gdk_pixbuf_new_from_inline (-1,
									     dir_16_rgba,
									     FALSE,
									     NULL);
			scale = FALSE;
		} else {
			icon_pixbuf[icon_name] = gtk_icon_info_load_icon (icon_info, NULL);
			gtk_icon_info_free (icon_info);
		}
	}

	/* Scale keeping aspect ratio. */

 	if (! scale) {
		g_object_ref (icon_pixbuf[icon_name]);
		return icon_pixbuf[icon_name];
	}

	if (icon_pixbuf[icon_name] != NULL) {
		int w, h;

		w = gdk_pixbuf_get_width (icon_pixbuf[icon_name]);
		h = gdk_pixbuf_get_height (icon_pixbuf[icon_name]);
		if (scale_keepping_ratio (&w, &h, icon_size, icon_size))
			pixbuf = gdk_pixbuf_scale_simple (icon_pixbuf[icon_name],
							  w,
							  h,
							  GDK_INTERP_BILINEAR);
		else {
			pixbuf = icon_pixbuf[icon_name];
			g_object_ref (pixbuf);
		}
	}

	return pixbuf;
}
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;
}
Exemple #15
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);
	}
}
QString ThemeAppIcon::getThemeIconPath(QString iconName, int size)
{
    QByteArray bytes = iconName.toUtf8();
    char *name = bytes.data();

    if (g_path_is_absolute(name))
            return g_strdup(name);

        g_return_val_if_fail(name != NULL, NULL);

        int pic_name_len = strlen(name);
        char* ext = strrchr(name, '.');
        if (ext != NULL) {
            if (g_ascii_strcasecmp(ext+1, "png") == 0 || g_ascii_strcasecmp(ext+1, "svg") == 0 || g_ascii_strcasecmp(ext+1, "jpg") == 0) {
                pic_name_len = ext - name;
//                qDebug() << "desktop's Icon name should an absoulte path or an basename without extension";
            }
        }

        // In pratice, default icon theme may not gets the right icon path when program starting.
        if (them == NULL)
            them = gtk_icon_theme_new();
        char* icon_theme_name = get_icon_theme_name();
        gtk_icon_theme_set_custom_theme(them, icon_theme_name);
        g_free(icon_theme_name);

        char* pic_name = g_strndup(name, pic_name_len);

        GtkIconInfo* info = gtk_icon_theme_lookup_icon(them, pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
        if (info == NULL) {
            info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
            if (info == NULL) {
//                qWarning() << "get gtk icon theme info failed for" << pic_name;
                g_free(pic_name);
                return "";
            }
        }
        g_free(pic_name);

        char* path = g_strdup(gtk_icon_info_get_filename(info));

    #if GTK_MAJOR_VERSION >= 3
        g_object_unref(info);
    #elif GTK_MAJOR_VERSION == 2
        gtk_icon_info_free(info);
    #endif
        g_debug("get icon from icon theme is: %s", path);
        return path;
}
/*! \fn GdkPixbuf* CDesktopAppChooser::m_LoadThemeIcon(GtkIconTheme* theme, const char* icon_name, int size)
    \brief To load a icon contents found in theme icon pool.

    \param[in] theme.
    \param[in] icon_name. 
    \param[in] size.
    \return PixelBuffer object representing the designated icon.
*/
GdkPixbuf* CDesktopAppChooser::m_LoadThemeIcon(GtkIconTheme* theme, const char* icon_name, int size)
{
  GdkPixbuf *icon = NULL;
  const char *file = NULL;
  GtkIconInfo *info = gtk_icon_theme_lookup_icon(theme, icon_name, size, GTK_ICON_LOOKUP_USE_BUILTIN);

  if( G_UNLIKELY(!info) )
    return NULL;

  file = gtk_icon_info_get_filename( info );

  if( G_LIKELY( file ) )
    icon = gdk_pixbuf_new_from_file( file, NULL );
  else
    icon = gtk_icon_info_get_builtin_pixbuf( info );

  gtk_icon_info_free( info );

  if( G_LIKELY( icon ) )
  {
	int height = gdk_pixbuf_get_height(icon);
    int width = gdk_pixbuf_get_width(icon);

    /* Scale down the icon if it's too big to be shown. */
    if(G_UNLIKELY( (height > size) || (width > size) ))
    {
      GdkPixbuf *scaled = NULL;

      if( height > width )
      {
         width = size * height / width;
		 height = size;
      }
      else if( height < width )
      {
         height = size * width / height;
         width = size;
      }
      else
         height = width = size;

      scaled = gdk_pixbuf_scale_simple( icon, width, height, GDK_INTERP_BILINEAR );
      g_object_unref( icon );
      icon = scaled;
    }
  }

  return icon;
}
Exemple #18
0
static void
select_icon (GtkTreeSelection * sel, IconBrowserData * data)
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  GtkIconInfo *info;
  gint *sz, i;
  gchar *icon, *file;
  GString *sizes;

  if (!gtk_tree_selection_get_selected (sel, &model, &iter))
    return;

  gtk_tree_model_get (model, &iter, 1, &icon, -1);

  gtk_image_set_from_icon_name (GTK_IMAGE (data->image), icon, GTK_ICON_SIZE_DIALOG);

  sz = gtk_icon_theme_get_icon_sizes (data->theme, icon);
  info = gtk_icon_theme_lookup_icon (data->theme, icon, sz[0], 0);

  if (info)
    file = (gchar *) gtk_icon_info_get_filename (info);
  else
    file = NULL;

  /* create sizes string */
  i = 0;
  sizes = g_string_new ("");
  while (sz[i])
    {
      if (sz[i] == -1)
        g_string_append (sizes, _("scalable "));
      else
        g_string_append_printf (sizes, "%dx%d ", sz[i], sz[i]);
      i++;
    }
  /* free memory */
  g_free (sz);

  gtk_label_set_text (GTK_LABEL (data->lname), icon);
  gtk_label_set_text (GTK_LABEL (data->lsize), sizes->str);
  gtk_label_set_text (GTK_LABEL (data->lfile), file ? file : _("built-in"));

  g_string_free (sizes, TRUE);

  if (info)
    gtk_icon_info_free (info);
}
Exemple #19
0
char *
panel_find_icon (GtkIconTheme  *icon_theme,
                 const char    *icon_name,
                 gint           size)
{
    GtkIconInfo *info;
    char        *retval;
    char        *icon_no_extension;

    if (icon_name == NULL || strcmp (icon_name, "") == 0)
        return NULL;

    if (g_path_is_absolute (icon_name)) {
        if (g_file_test (icon_name, G_FILE_TEST_EXISTS)) {
            return g_strdup (icon_name);
        } else {
            char *basename;

            basename = g_path_get_basename (icon_name);
            retval = panel_find_icon (icon_theme, basename,
                                      size);
            g_free (basename);

            return retval;
        }
    }

    /* This is needed because some .desktop files have an icon name *and*
     * an extension as icon */
    icon_no_extension = panel_xdg_icon_remove_extension (icon_name);

    info = gtk_icon_theme_lookup_icon (icon_theme, icon_no_extension,
                                       size, 0);

    g_free (icon_no_extension);

    if (info) {
        retval = g_strdup (gtk_icon_info_get_filename (info));
#if GTK_CHECK_VERSION (3, 8, 0)
        g_object_unref (info);
#else
        gtk_icon_info_free (info);
#endif
    } else
        retval = NULL;

    return retval;
}
Exemple #20
0
static char *icon_path(char *to, const char *icon) {
    if (STR_IS_EMPTY(icon)) {
        to[0] = 0;
        return to;
    }
    GtkIconInfo* info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),
            icon, GTK_ICON_SIZE_SMALL_TOOLBAR, 0);
    if (info != NULL) {
        const char *path = gtk_icon_info_get_filename(info);
        strcpy(to, path);
        gtk_icon_info_free(info);
    } else {
        strcpy(to, icon);
    }
    return to;
}
Exemple #21
0
static gboolean
icon_available (const gchar *icon)
{
	GtkIconTheme *icon_theme;
	GtkIconInfo *icon_info;

	if (!icon)
		return FALSE;

	icon_theme = gtk_icon_theme_get_default ();
	icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon, 16, 0);
	if (icon_info != NULL)
		gtk_icon_info_free (icon_info);

	return icon_info != NULL;
}
Exemple #22
0
static void update_icon (GtkWidget *p, volume_t *vol)
{
	GdkPixbuf *icon;
	GtkWidget *image;
	GtkIconTheme* theme;
	GtkIconInfo* info;
	int icon_size;

	theme = panel_get_icon_theme(vol->panel);
	icon_size = panel_get_icon_size(vol->panel);

	if (curr_volume <= 0) {
		info = gtk_icon_theme_lookup_icon( theme, "stock_volume-mute", icon_size, 0 );
	}
	else if (curr_volume > 0 && curr_volume <= 50) {
		info = gtk_icon_theme_lookup_icon( theme, "stock_volume-min", icon_size, 0 );
	}
	else if (curr_volume > 50 && curr_volume <= 75) {
		info = gtk_icon_theme_lookup_icon( theme, "stock_volume-med", icon_size, 0 );
	}
	else /* curr_volume > 75 */ {
		info = gtk_icon_theme_lookup_icon( theme, "stock_volume-max", icon_size, 0 );
	}

	if (info ) {
		icon = gdk_pixbuf_new_from_file_at_size(
				gtk_icon_info_get_filename( info ),
				icon_size, icon_size, NULL );
		gtk_icon_info_free( info );
	}
	else {
			icon = gdk_pixbuf_new_from_xpm_data((const char **) volume_xpm);
	}

	if (icon) {
		if (curr_image) {
			gtk_widget_destroy(curr_image);
			curr_image = NULL;
		}
		image = gtk_image_new_from_pixbuf(icon);
		gtk_container_add(GTK_CONTAINER(p), image);

		curr_image = image;
	}
	gtk_widget_show_all(p);
	return;
}
Exemple #23
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);
  gtk_icon_info_free (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;
}
char *
matekbd_indicator_config_get_images_file (MatekbdIndicatorConfig *
        ind_config,
        MatekbdKeyboardConfig *
        kbd_config, int group)
{
    char *image_file = NULL;
    GtkIconInfo *icon_info = NULL;

    if (!ind_config->show_flags)
        return NULL;

    if ((kbd_config->layouts_variants != NULL) &&
            (g_strv_length (kbd_config->layouts_variants) > group)) {
        char *full_layout_name =
            kbd_config->layouts_variants[group];

        if (full_layout_name != NULL) {
            char *l, *v;
            matekbd_keyboard_config_split_items (full_layout_name,
                                                 &l, &v);
            if (l != NULL) {
                /* probably there is something in theme? */
                icon_info = gtk_icon_theme_lookup_icon
                            (ind_config->icon_theme, l, 48, 0);
            }
        }
    }
    /* fallback to the default value */
    if (icon_info == NULL) {
        icon_info = gtk_icon_theme_lookup_icon
                    (ind_config->icon_theme, "stock_dialog-error", 48, 0);
    }
    if (icon_info != NULL) {
        image_file =
            g_strdup (gtk_icon_info_get_filename (icon_info));
#if GTK_CHECK_VERSION (3, 8, 0)
        g_object_unref (icon_info);
#else
        gtk_icon_info_free (icon_info);
#endif
    }

    return image_file;
}
static GdkPixbuf *
render_icon (GIcon *icon, gint icon_size)
{
	GdkPixbuf *pixbuf;
	GtkIconInfo *info;

	pixbuf = NULL;

	if (G_IS_THEMED_ICON (icon)) {
		gchar const * const *names;

		info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
				                       icon,
				                       icon_size,
				                       0);

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

		if (pixbuf == NULL) {
			names = g_themed_icon_get_names (G_THEMED_ICON (icon));
			pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
							   *names,
							   icon_size,
							   0, NULL);
		}
	}
	else
	if (G_IS_FILE_ICON (icon)) {
		GFile *icon_file;
		gchar *path;

		icon_file = g_file_icon_get_file (G_FILE_ICON (icon));
		path = g_file_get_path (icon_file);
		pixbuf = gdk_pixbuf_new_from_file_at_size (path,
							   icon_size, icon_size, 
							   NULL);
		g_free (path);
		g_object_unref (G_OBJECT (icon_file));
	}

	return pixbuf;
}
static void
icon_lookup_data_destroy (gpointer p)
{
  AsyncIconLookupData *data = p;

  if (data->icon)
    {
      g_object_unref (data->icon);
      gtk_icon_info_free (data->icon_info);
    }
  else if (data->uri)
    g_free (data->uri);
  if (data->mimetype)
    g_free (data->mimetype);
  if (data->recent_info)
    gtk_recent_info_unref (data->recent_info);

  g_free (data);
}
Exemple #27
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)
    gtk_icon_info_free (info);
}
static void
texture_load_data_destroy (gpointer p)
{
  AsyncTextureLoadData *data = p;

  if (data->icon_info)
    {
      gtk_icon_info_free (data->icon_info);
      if (data->colors)
        st_icon_colors_unref (data->colors);
    }
  else if (data->uri)
    g_free (data->uri);

  if (data->key)
    g_free (data->key);

  if (data->textures)
    g_slist_free_full (data->textures, (GDestroyNotify) g_object_unref);
}
Exemple #29
0
// iconName should be a icon name constraints to the freeedesktop standard.
QString DockAppIcon::getThemeIconPath(QString iconName)
{
    QByteArray bytes = iconName.toUtf8();
    const char *name = bytes.constData();

    GtkIconTheme* theme = gtk_icon_theme_get_default();

    GtkIconInfo* info = gtk_icon_theme_lookup_icon(theme, name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);

    if (info) {
        char* path = g_strdup(gtk_icon_info_get_filename(info));
#if GTK_MAJOR_VERSION >= 3
        g_object_unref(info);
#elif GTK_MAJOR_VERSION == 2
        gtk_icon_info_free(info);
#endif
        return QString(path);
    } else {
        return "";
    }
}
Exemple #30
0
bool
check_default_theme(gpointer data)
{
	// The default gtk icon theme "hi-color" does not contain any mimetype icons.

	static char* names[] = {"audio-x-wav", "audio-x-generic", "gnome-mime-audio"};

	if(!theme_name[0]){
		GtkIconInfo* info;
		int i = 0;
		while(i++ < G_N_ELEMENTS(names) && !(info = gtk_icon_theme_lookup_icon(icon_theme, names[i], ICON_HEIGHT, 0)));
		if(info){
			gtk_icon_info_free(info);
		}else{
			warnprintf("default icon theme appears not to contain audio mime-type icons\n");

			// TODO use a random fallback theme
		}
	}
	return G_SOURCE_REMOVE;
}