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"
|
2004-10-19 18:49:03 +00:00
|
|
|
);
|
2003-07-03 21:26:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
char *themename;
|
|
|
|
int size = 48;
|
2013-09-23 10:07:30 +00:00
|
|
|
int scale = 1;
|
2014-09-21 18:09:16 +00:00
|
|
|
GtkIconLookupFlags flags;
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkTextDirection direction;
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-01 23:35:42 +00:00
|
|
|
flags = 0;
|
2014-09-21 18:09:16 +00:00
|
|
|
|
|
|
|
if (g_getenv ("RTL"))
|
2020-02-01 23:27:14 +00:00
|
|
|
direction = GTK_TEXT_DIR_RTL;
|
|
|
|
else if (g_getenv ("LTR"))
|
|
|
|
direction = GTK_TEXT_DIR_LTR;
|
2014-09-21 18:09:16 +00:00
|
|
|
else
|
2020-02-01 23:27:14 +00:00
|
|
|
direction = GTK_TEXT_DIR_NONE;
|
2014-09-21 18:09:16 +00:00
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
themename = argv[2];
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_new ();
|
|
|
|
|
2020-02-18 05:56:37 +00:00
|
|
|
gtk_icon_theme_set_theme_name (icon_theme, themename);
|
2003-07-03 21:26:35 +00:00
|
|
|
|
2004-10-19 18:49:03 +00:00
|
|
|
if (strcmp (argv[1], "display") == 0)
|
|
|
|
{
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
2004-10-19 18:49:03 +00:00
|
|
|
GtkWidget *window, *image;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2004-10-19 18:49:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-02-04 02:53:22 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
|
2020-01-27 14:40:58 +00:00
|
|
|
if (!icon)
|
2008-10-31 08:56:42 +00:00
|
|
|
{
|
2020-01-27 14:40:58 +00:00
|
|
|
g_print ("Icon '%s' not found\n", argv[3]);
|
2008-10-31 08:56:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2008-10-31 08:56:42 +00:00
|
|
|
image = gtk_image_new ();
|
2020-01-27 14:40:58 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (icon));
|
|
|
|
g_object_unref (icon);
|
2004-10-19 18:49:03 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), image);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2020-01-27 14:40:58 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2004-10-19 18:49:03 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "list") == 0)
|
2003-07-03 21:26:35 +00:00
|
|
|
{
|
2020-02-18 05:56:37 +00:00
|
|
|
char **icons;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
icons = gtk_icon_theme_get_icon_names (icon_theme);
|
|
|
|
for (i = 0; icons[i]; i++)
|
|
|
|
g_print ("%s\n", icons[i]);
|
|
|
|
g_strfreev (icons);
|
2003-07-03 21:26:35 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (argv[1], "lookup") == 0)
|
|
|
|
{
|
2020-02-10 11:33:17 +00:00
|
|
|
GFile *file;
|
2020-03-06 17:05:43 +00:00
|
|
|
GtkIconPaintable *icon;
|
2020-02-10 11:33:17 +00:00
|
|
|
|
2003-07-03 21:26:35 +00:00
|
|
|
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]);
|
|
|
|
|
2020-02-04 02:53:22 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
|
2020-02-10 11:33:17 +00:00
|
|
|
file = gtk_icon_paintable_get_file (icon);
|
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,
|
2020-02-10 11:33:17 +00:00
|
|
|
file ? g_file_get_uri (file) : "<none>");
|
2013-09-23 10:07:30 +00:00
|
|
|
|
2020-02-10 11:33:17 +00:00
|
|
|
g_print ("texture size: %dx%d\n", gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (icon)), gdk_paintable_get_intrinsic_height (GDK_PAINTABLE (icon)));
|
|
|
|
g_object_unref (icon);
|
2003-07-03 21:26:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
usage ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|