GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-icons.c
1 /*
2  * gnc-icons.c -- Functions to create a GtkIconFactory for GnuCash
3  * Copyright (C) 2003 Jan Arne Petersen
4  * Author: Jan Arne Petersen <[email protected]>
5  */
6 
7 #include "config.h"
8 
9 #include <gtk/gtk.h>
10 #include <glib/gi18n.h>
11 
12 #include "gnc-icons.h"
13 #include "gnc-filepath-utils.h"
14 #include "gnc-gnome-utils.h"
15 
16 static GtkStockItem items[] =
17 {
18  { GNC_STOCK_ACCOUNT, N_("Account"), 0, 0, NULL },
19  { GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Account"), 0, 0, NULL },
20  { GNC_STOCK_EDIT_ACCOUNT, N_("_Edit Account"), 0, 0, NULL },
21  { GNC_STOCK_NEW_ACCOUNT, N_("_New Account"), 0, 0, NULL },
22  { GNC_STOCK_OPEN_ACCOUNT, N_("_Open Account"), 0, 0, NULL },
23  { GNC_STOCK_TRANSFER, N_("_Transfer..."), 0, 0, NULL },
24  { GNC_STOCK_SPLIT_TRANS, N_("S_plit Transaction"), 0, 0, NULL },
25  { GNC_STOCK_JUMP_TO, N_("_Jump"), 0, 0, NULL },
26 };
27 
28 typedef struct _item_file
29 {
30  const gchar *stock_name;
31  const gchar *filename_lg;
32  const gchar *filename_sm;
33 } item_file;
34 
35 static item_file item_files[] =
36 {
37  { GNC_STOCK_ACCOUNT, "gnc-account.png", "gnc-account-16.png"},
38  { GNC_STOCK_DELETE_ACCOUNT, "gnc-account-delete.png", "gnc-account-delete-16.png"},
39  { GNC_STOCK_EDIT_ACCOUNT, "gnc-account-edit.png", "gnc-account-edit-16.png"},
40  { GNC_STOCK_NEW_ACCOUNT, "gnc-account-new.png", "gnc-account-new-16.png"},
41  { GNC_STOCK_OPEN_ACCOUNT, "gnc-account-open.png", "gnc-account-open-16.png"},
42  { GNC_STOCK_TRANSFER, "gnc-transfer.png", "gnc-transfer-16.png"},
43  { GNC_STOCK_SCHEDULE, "gnc-sx-new.png", "gnc-sx-new-16.png"},
44  { GNC_STOCK_SPLIT_TRANS, "gnc-split-trans.png", "gnc-split-trans-16.png"},
45  { GNC_STOCK_JUMP_TO, "gnc-jumpto.png", "gnc-jumpto-16.png"},
46  { GNC_STOCK_INVOICE, "gnc-invoice.png", "gnc-invoice-16.png"},
47  { GNC_STOCK_INVOICE_PAY, "gnc-invoice-pay.png", "gnc-invoice-pay-16.png"},
48  { GNC_STOCK_INVOICE_POST, "gnc-invoice-post.png", "gnc-invoice-post-16.png"},
49  { GNC_STOCK_INVOICE_UNPOST, "gnc-invoice-unpost.png", "gnc-invoice-unpost-16.png"},
50  { GNC_STOCK_INVOICE_NEW, "gnc-invoice-new.png", "gnc-invoice-new-16.png"},
51  { GNC_STOCK_INVOICE_EDIT, "gnc-invoice-edit.png", "gnc-invoice-edit-16.png"},
52  { GNC_STOCK_INVOICE_DUPLICATE, "gnc-invoice-duplicate.png", "gnc-invoice-duplicate-16.png"},
53  { GNC_STOCK_PDF_EXPORT, "gnc-gnome-pdf-24.png", "gnc-gnome-pdf-16.png"},
54  { 0 },
55 };
56 
57 static void
58 gnc_add_stock_icon_pair (GtkIconFactory *factory,
59  const char *stock,
60  const char *filename1,
61  const char *filename2)
62 {
63  GtkIconSet *set;
64  GtkIconSource *source;
65  GdkPixbuf *pixbuf1, *pixbuf2;
66  char *fullname1, *fullname2;
67 
68  /* Find the complete path names for these files */
69  fullname1 = gnc_filepath_locate_pixmap (filename1);
70  fullname2 = gnc_filepath_locate_pixmap (filename2);
71  g_assert (fullname1 && fullname2);
72 
73  /* Load the pixbufs */
74  pixbuf1 = gnc_gnome_get_gdkpixbuf (filename1);
75  pixbuf2 = gnc_gnome_get_gdkpixbuf (filename2);
76  g_assert (pixbuf1 && pixbuf2);
77 
78  /* Create the icon set */
79  set = gtk_icon_set_new ();
80  source = gtk_icon_source_new ();
81  gtk_icon_source_set_filename (source, fullname1);
82  gtk_icon_source_set_pixbuf (source, pixbuf1);
83  gtk_icon_set_add_source (set, source);
84  gtk_icon_source_free(source);
85 
86  source = gtk_icon_source_new ();
87  gtk_icon_source_set_filename (source, fullname2);
88  gtk_icon_source_set_pixbuf (source, pixbuf2);
89  gtk_icon_source_set_size (source, GTK_ICON_SIZE_MENU);
90  gtk_icon_source_set_size_wildcarded (source, FALSE);
91  gtk_icon_set_add_source (set, source);
92  gtk_icon_source_free(source);
93 
94  /* Add it to the factory */
95  gtk_icon_factory_add (factory, stock, set);
96 
97  /* Cleanup */
98  g_object_unref (pixbuf2);
99  g_object_unref (pixbuf1);
100  g_free(fullname2);
101  g_free(fullname1);
102  gtk_icon_set_unref (set);
103 }
104 
105 void
106 gnc_load_stock_icons (void)
107 {
108  GtkIconFactory *factory;
109  item_file *file;
110 
111  /* Register our stock items */
112  gtk_stock_add (items, G_N_ELEMENTS (items));
113 
114  /* Add our custom icon factory to the list of defaults */
115  factory = gtk_icon_factory_new ();
116  for (file = item_files; file->stock_name; file++)
117  {
118  gnc_add_stock_icon_pair (factory, file->stock_name,
119  file->filename_lg, file->filename_sm);
120  }
121 
122  gtk_icon_factory_add_default (factory);
123 }
Gnome specific utility functions.
gchar * gnc_filepath_locate_pixmap(const gchar *name)
GdkPixbuf * gnc_gnome_get_gdkpixbuf(const char *name)
File path resolution utility functions.