about.c: cosmetix
[k8lowj.git] / src / icons.c
blobaa85f4250724041477c89729d4d64116e6788620
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
5 */
7 #include <glib/gi18n.h>
8 #include <gtk/gtkiconfactory.h>
9 #include <gtk/gtkwindow.h>
10 #include <gtk/gtkstock.h>
12 #include "icons.h"
13 #include "pixbufs.h"
15 static GtkStockItem logjam_stock_items[] = {
16 /* XXX we shouldn't need those spaces in there for this to look good. :( */
17 { "logjam-submit", N_(" Submit "), 0, 0, "logjam" }
20 static GdkPixbuf*
21 inline_to_listpixbuf(const guint8 *data) {
22 GdkPixbuf *pb, *spb;
23 gint width, height, sourcewidth, sourceheight;
25 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
26 height -= 5; /* FIXME: slightly smaller looks good, but it shouldn't. */
27 pb = gdk_pixbuf_new_from_inline(-1, data, FALSE, NULL);
29 /* now adjust width to be proportionate to the height for this icon. */
30 sourceheight = gdk_pixbuf_get_height(pb);
31 sourcewidth = gdk_pixbuf_get_width(pb);
32 width = sourcewidth * height / sourceheight;
34 spb = gdk_pixbuf_scale_simple(pb, width, height, GDK_INTERP_BILINEAR);
35 g_object_unref(pb);
37 return spb;
39 GdkPixbuf*
40 icons_rarrow_pixbuf(void) {
41 return inline_to_listpixbuf(logjam_rarrow);
43 GdkPixbuf*
44 icons_larrow_pixbuf(void) {
45 return inline_to_listpixbuf(logjam_larrow);
47 GdkPixbuf*
48 icons_lrarrow_pixbuf(void) {
49 return inline_to_listpixbuf(logjam_lrarrow);
52 static GdkPixbuf*
53 add(GtkIconFactory *factory,
54 const guchar *inline_data,
55 const gchar *stock_id) {
56 GtkIconSet *set;
57 GdkPixbuf *pixbuf;
59 pixbuf = gdk_pixbuf_new_from_inline(-1, inline_data, FALSE, NULL);
60 set = gtk_icon_set_new_from_pixbuf(pixbuf);
61 g_object_unref(G_OBJECT(pixbuf));
63 gtk_icon_factory_add(factory, stock_id, set);
64 gtk_icon_set_unref(set);
66 return pixbuf;
69 void
70 icons_initialize(void) {
71 GtkIconFactory *factory;
72 GdkPixbuf *goat;
73 GList *l;
75 factory = gtk_icon_factory_new();
76 goat = add(factory, logjam_goat, "logjam-goat");
77 add(factory, logjam_pencil, "logjam-server");
78 add(factory, logjam_ljuser, "logjam-ljuser");
79 add(factory, logjam_ljcomm, "logjam-ljcomm");
80 add(factory, logjam_protected, "logjam-protected");
81 add(factory, logjam_private, "logjam-private");
82 add(factory, logjam_blogger, "logjam-blogger");
83 gtk_icon_factory_add_default(factory);
85 l = g_list_append(NULL, goat);
86 gtk_window_set_default_icon_list(l);
87 g_list_free(l);
89 gtk_stock_add_static(logjam_stock_items, G_N_ELEMENTS(logjam_stock_items));
92 #ifndef HAVE_LIBRSVG
93 void
94 icons_load_throbber(GdkPixbuf *pbs[]) {
95 const guint8 *data;
96 int i;
97 GdkPixbuf *pb;
98 gint w, h;
100 gtk_icon_size_lookup(GTK_ICON_SIZE_DIALOG, &w, &h);
102 for (i = 0; i < THROBBER_COUNT; i++) {
103 switch (i) {
104 case 0: data = logjam_throbber_1; break;
105 case 1: data = logjam_throbber_2; break;
106 case 2: data = logjam_throbber_3; break;
107 case 3: data = logjam_throbber_4; break;
108 case 4: data = logjam_throbber_5; break;
109 case 5: data = logjam_throbber_6; break;
110 case 6: data = logjam_throbber_7; break;
111 case 7: data = logjam_throbber_8; break;
112 default:
113 g_warning("tried to load unknown throbber %d.", i);
114 return;
116 pb = gdk_pixbuf_new_from_inline(-1, data, FALSE, NULL);
117 pbs[i] = gdk_pixbuf_scale_simple(pb, w, h, GDK_INTERP_BILINEAR);
118 g_object_unref(G_OBJECT(pb));
121 #endif /* HAVE_LIBRSVG */