2005-07-13 05:44:22 +00:00
|
|
|
/* testicontheme.c
|
|
|
|
* Copyright (C) 2002, 2003 Red Hat, Inc.
|
|
|
|
* Authors: Alexander Larsson, Owen Taylor
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2004-10-19 18:49:03 +00:00
|
|
|
#include <gtk/gtk.h>
|
2003-07-03 21:26:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-10-19 04:30:35 +00:00
|
|
|
#include <locale.h>
|
2003-07-03 21:26:35 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage (void)
|
|
|
|
{
|
2013-09-23 10:07:30 +00:00
|
|
|
g_print ("usage: test-icon-theme lookup <theme name> <icon name> [size] [scale]\n"
|
2003-07-03 21:26:35 +00:00
|
|
|
" or\n"
|
2004-10-19 18:49:03 +00:00
|
|
|
"usage: test-icon-theme list <theme name> [context]\n"
|
|
|
|
" or\n"
|
2013-09-23 10:07:30 +00:00
|
|
|
"usage: test-icon-theme display <theme name> <icon name> [size] [scale]\n"
|
2007-03-21 19:31:01 +00:00
|
|
|
" or\n"
|
|
|
|
"usage: test-icon-theme contexts <theme name>\n"
|
2004-10-19 18:49:03 +00:00
|
|
|
);
|
2003-07-03 21:26:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
static void
|
|
|
|
icon_loaded_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2019-08-30 19:26:21 +00:00
|
|
|
GdkPaintable *paintable;
|
2013-02-14 12:32:30 +00:00
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
2019-08-30 19:26:21 +00:00
|
|
|
paintable = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object),
|
|
|
|
res, &error);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
if (paintable == NULL)
|
2013-02-14 12:32:30 +00:00
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (user_data), paintable);
|
|
|
|
g_object_unref (paintable);
|
2013-02-14 12:32:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
GtkIconInfo *icon_info;
|
|
|
|
char *context;
|
|
|
|
char *themename;
|
|
|
|
GList *list;
|
|
|
|
int size = 48;
|
2013-09-23 10:07:30 +00:00
|
|
|
int scale = 1;
|
2014-09-21 18:09:16 +00:00
|
|
|
GtkIconLookupFlags flags;
|
2003-07-03 21:26:35 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2003-07-03 21:26:35 +00:00
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-09-21 18:09:16 +00:00
|
|
|
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
|
|
|
|
|
|
|
|
if (g_getenv ("RTL"))
|
|
|
|
flags |= GTK_ICON_LOOKUP_DIR_RTL;
|
|
|
|
else
|
|
|
|
flags |= GTK_ICON_LOOKUP_DIR_LTR;
|
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
themename = argv[2];
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_new ();
|
|
|
|
|
|
|
|
gtk_icon_theme_set_custom_theme (icon_theme, themename);
|
|
|
|
|
2004-10-19 18:49:03 +00:00
|
|
|
if (strcmp (argv[1], "display") == 0)
|
|
|
|
{
|
2008-10-31 08:56:42 +00:00
|
|
|
GError *error;
|
2019-08-30 18:54:16 +00:00
|
|
|
GdkPaintable *paintable;
|
2004-10-19 18:49:03 +00:00
|
|
|
GtkWidget *window, *image;
|
|
|
|
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc >= 5)
|
|
|
|
size = atoi (argv[4]);
|
2013-09-23 10:07:30 +00:00
|
|
|
|
|
|
|
if (argc >= 6)
|
|
|
|
scale = atoi (argv[5]);
|
2008-10-31 08:56:42 +00:00
|
|
|
|
|
|
|
error = NULL;
|
2019-08-30 18:54:16 +00:00
|
|
|
paintable = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error);
|
|
|
|
if (!paintable)
|
2008-10-31 08:56:42 +00:00
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-19 18:49:03 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2008-10-31 08:56:42 +00:00
|
|
|
image = gtk_image_new ();
|
2019-08-30 18:54:16 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (image), paintable);
|
|
|
|
g_object_unref (paintable);
|
2004-10-19 18:49:03 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), image);
|
2017-12-31 17:52:54 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2004-10-19 18:49:03 +00:00
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
gtk_main ();
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "display-async") == 0)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *image;
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc >= 5)
|
|
|
|
size = atoi (argv[4]);
|
2013-09-23 10:07:30 +00:00
|
|
|
|
|
|
|
if (argc >= 6)
|
|
|
|
scale = atoi (argv[5]);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
image = gtk_image_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), image);
|
2017-12-31 17:52:54 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
2014-09-21 18:09:16 +00:00
|
|
|
info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, argv[3], size, scale, flags);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
g_print ("Icon not found\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_info_load_icon_async (info,
|
|
|
|
NULL, icon_loaded_cb, image);
|
|
|
|
|
2004-10-19 18:49:03 +00:00
|
|
|
gtk_main ();
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "list") == 0)
|
2003-07-03 21:26:35 +00:00
|
|
|
{
|
|
|
|
if (argc >= 4)
|
|
|
|
context = argv[3];
|
|
|
|
else
|
|
|
|
context = NULL;
|
|
|
|
|
|
|
|
list = gtk_icon_theme_list_icons (icon_theme,
|
|
|
|
context);
|
|
|
|
|
2007-03-21 19:31:01 +00:00
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
g_print ("%s\n", (char *)list->data);
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "contexts") == 0)
|
|
|
|
{
|
|
|
|
list = gtk_icon_theme_list_contexts (icon_theme);
|
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
g_print ("%s\n", (char *)list->data);
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "lookup") == 0)
|
|
|
|
{
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
2013-09-23 10:07:30 +00:00
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
if (argc >= 5)
|
|
|
|
size = atoi (argv[4]);
|
2013-09-23 10:07:30 +00:00
|
|
|
|
|
|
|
if (argc >= 6)
|
|
|
|
scale = atoi (argv[5]);
|
|
|
|
|
2014-09-21 18:09:16 +00:00
|
|
|
icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, argv[3], size, scale, flags);
|
2013-09-23 10:07:30 +00:00
|
|
|
g_print ("icon for %s at %dx%d@%dx is %s\n", argv[3], size, size, scale,
|
2016-10-22 15:25:57 +00:00
|
|
|
icon_info ? gtk_icon_info_get_filename (icon_info) : "<none>");
|
2003-07-03 21:26:35 +00:00
|
|
|
|
2013-09-23 10:07:30 +00:00
|
|
|
if (icon_info)
|
2003-07-03 21:26:35 +00:00
|
|
|
{
|
2019-08-30 20:20:51 +00:00
|
|
|
GdkTexture *texture;
|
2013-09-23 10:07:30 +00:00
|
|
|
|
|
|
|
g_print ("Base size: %d, Scale: %d\n", gtk_icon_info_get_base_size (icon_info), gtk_icon_info_get_base_scale (icon_info));
|
|
|
|
|
2019-08-30 20:20:51 +00:00
|
|
|
texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL));
|
|
|
|
if (texture != NULL)
|
2013-09-23 10:07:30 +00:00
|
|
|
{
|
2019-08-30 20:20:51 +00:00
|
|
|
g_print ("texture size: %dx%d\n", gdk_texture_get_width (texture), gdk_texture_get_height (texture));
|
|
|
|
g_object_unref (texture);
|
2013-09-23 10:07:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2003-07-03 21:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|