Support custom sizes of icons in res_server

This commit is contained in:
Christian Dywan 2009-05-15 23:08:52 +02:00
parent 3395d0a0f2
commit 4c2a3f5bb7
2 changed files with 25 additions and 5 deletions

View file

@ -153,8 +153,7 @@
.activated p { .activated p {
cursor: text; cursor: text;
background: url({stock}/gtk-edit) 98% 70% no-repeat; background: url({stock}/16/gtk-edit) 98% 70% no-repeat;
-webkit-background-size: 16px 15px;
opacity: 0.6; opacity: 0.6;
color: rgba(0,0,0,1); color: rgba(0,0,0,1);
} }

View file

@ -1008,12 +1008,33 @@ res_server_handler_cb (SoupServer* res_server,
else if (g_str_has_prefix (path, "/stock/")) else if (g_str_has_prefix (path, "/stock/"))
{ {
GtkIconTheme* icon_theme = gtk_icon_theme_get_default (); GtkIconTheme* icon_theme = gtk_icon_theme_get_default ();
const gchar* icon_name = &path[7]; const gchar* icon_name = &path[7] ? &path[7] : "";
GdkPixbuf* icon = gtk_icon_theme_load_icon (icon_theme, icon_name, gint icon_size = 22;
strstr (icon_name, "dialog") ? 48 : 22, 0, NULL); GdkPixbuf* icon;
gchar* contents; gchar* contents;
gsize length; gsize length;
if (g_ascii_isalpha (icon_name[0]))
icon_size = strstr (icon_name, "dialog") ? 48 : 22;
else if (g_ascii_isdigit (icon_name[0]))
{
guint i = 0;
while (icon_name[i])
if (icon_name[i++] == '/')
{
gchar* size = g_strndup (icon_name, i - 1);
icon_size = atoi (size);
g_free (size);
icon_name = &icon_name[i];
}
}
icon = gtk_icon_theme_load_icon (icon_theme, icon_name,
icon_size, 0, NULL);
if (!icon)
icon = gtk_icon_theme_load_icon (icon_theme, "gtk-missing-image",
icon_size, 0, NULL);
gdk_pixbuf_save_to_buffer (icon, &contents, &length, "png", NULL, NULL); gdk_pixbuf_save_to_buffer (icon, &contents, &length, "png", NULL, NULL);
g_object_unref (icon); g_object_unref (icon);
soup_message_set_response (msg, "image/png", SOUP_MEMORY_TAKE, soup_message_set_response (msg, "image/png", SOUP_MEMORY_TAKE,