~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/gnome-utils/gnc-icons.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gnc-icons.c -- Functions to create a GtkIconFactory for GnuCash
 
3
 * Copyright (C) 2003 Jan Arne Petersen
 
4
 * Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
 
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-gnome-utils.h"
 
14
 
 
15
static GtkStockItem items[] = {
 
16
  { GNC_STOCK_ACCOUNT,        N_("Account"),         0, 0, NULL },
 
17
  { GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Account"), 0, 0, NULL },
 
18
  { GNC_STOCK_EDIT_ACCOUNT,   N_("_Edit Account"),   0, 0, NULL },
 
19
  { GNC_STOCK_NEW_ACCOUNT,    N_("_New Account"),    0, 0, NULL },
 
20
  { GNC_STOCK_OPEN_ACCOUNT,   N_("_Open Account"),   0, 0, NULL },
 
21
  { GNC_STOCK_TRANSFER,       N_("_Transfer..."),    0, 0, NULL },
 
22
  { GNC_STOCK_SPLIT_TRANS,    N_("S_plit Transaction"), 0, 0, NULL },
 
23
  { GNC_STOCK_JUMP_TO,        N_("_Jump"),              0, 0, NULL },
 
24
};
 
25
 
 
26
typedef struct _item_file {
 
27
  const gchar *stock_name;
 
28
  const gchar *filename_lg;
 
29
  const gchar *filename_sm;
 
30
} item_file;
 
31
 
 
32
static item_file item_files[] = {
 
33
  { GNC_STOCK_ACCOUNT,        "gnc-account.png",        "gnc-account-16.png"},
 
34
  { GNC_STOCK_DELETE_ACCOUNT, "gnc-account-delete.png", "gnc-account-delete-16.png"},
 
35
  { GNC_STOCK_EDIT_ACCOUNT,   "gnc-account-edit.png",   "gnc-account-edit-16.png"},
 
36
  { GNC_STOCK_NEW_ACCOUNT,    "gnc-account-new.png",    "gnc-account-new-16.png"},
 
37
  { GNC_STOCK_OPEN_ACCOUNT,   "gnc-account-open.png",   "gnc-account-open-16.png"},
 
38
  { GNC_STOCK_TRANSFER,       "gnc-transfer.png",       "gnc-transfer-16.png"},
 
39
  { GNC_STOCK_SCHEDULE,       "gnc-sx-new.png",         "gnc-sx-new-16.png"},
 
40
  { GNC_STOCK_SPLIT_TRANS,    "gnc-split-trans.png",    "gnc-split-trans-16.png"},
 
41
  { GNC_STOCK_JUMP_TO,        "gnc-jumpto.png",         "gnc-jumpto-16.png"},
 
42
  { GNC_STOCK_INVOICE,        "gnc-invoice.png",        "gnc-invoice-16.png"},
 
43
  { GNC_STOCK_INVOICE_POST,   "gnc-invoice-post.png",   "gnc-invoice-post-16.png"},
 
44
  { GNC_STOCK_INVOICE_UNPOST, "gnc-invoice-unpost.png", "gnc-invoice-unpost-16.png"},
 
45
  { GNC_STOCK_INVOICE_EDIT,   "gnc-invoice-edit.png",   "gnc-invoice-edit-16.png"},
 
46
  { 0 },
 
47
};
 
48
 
 
49
static void
 
50
gnc_add_stock_icon_pair (GtkIconFactory *factory,
 
51
                         const char *stock,
 
52
                         const char *filename1,
 
53
                         const char *filename2)
 
54
{
 
55
        GtkIconSet *set;
 
56
        GtkIconSource *source;
 
57
        GdkPixbuf *pixbuf1, *pixbuf2;
 
58
        char *fullname1, *fullname2;
 
59
 
 
60
        /* Find the complete path names for these files */
 
61
        fullname1 = gnc_gnome_locate_pixmap (filename1);
 
62
        fullname2 = gnc_gnome_locate_pixmap (filename2);
 
63
        g_assert (fullname1 && fullname2);
 
64
 
 
65
        /* Load the pixbufs */
 
66
        pixbuf1 = gnc_gnome_get_gdkpixbuf (filename1);
 
67
        pixbuf2 = gnc_gnome_get_gdkpixbuf (filename2);
 
68
        g_assert (pixbuf1 && pixbuf2);
 
69
 
 
70
        /* Create the icon set */
 
71
        set = gtk_icon_set_new ();
 
72
        source = gtk_icon_source_new ();
 
73
        gtk_icon_source_set_filename (source, fullname1);
 
74
        gtk_icon_source_set_pixbuf (source, pixbuf1);
 
75
        gtk_icon_set_add_source (set, source);
 
76
        gtk_icon_source_free(source);
 
77
 
 
78
        source = gtk_icon_source_new ();
 
79
        gtk_icon_source_set_filename (source, fullname2);
 
80
        gtk_icon_source_set_pixbuf (source, pixbuf2);
 
81
        gtk_icon_source_set_size (source, GTK_ICON_SIZE_MENU);
 
82
        gtk_icon_source_set_size_wildcarded (source, FALSE);
 
83
        gtk_icon_set_add_source (set, source);
 
84
        gtk_icon_source_free(source);
 
85
 
 
86
        /* Add it to the factory */
 
87
        gtk_icon_factory_add (factory, stock, set);
 
88
 
 
89
        /* Cleanup */
 
90
        g_object_unref (pixbuf2);
 
91
        g_object_unref (pixbuf1);
 
92
        g_free(fullname2);
 
93
        g_free(fullname1);
 
94
        gtk_icon_set_unref (set);
 
95
}
 
96
 
 
97
void
 
98
gnc_load_stock_icons (void)
 
99
{
 
100
        GtkIconFactory *factory;
 
101
        item_file *file;
 
102
 
 
103
        /* Register our stock items */
 
104
        gtk_stock_add (items, G_N_ELEMENTS (items));
 
105
      
 
106
        /* Add our custom icon factory to the list of defaults */
 
107
        factory = gtk_icon_factory_new ();
 
108
        for (file = item_files; file->stock_name; file++) {
 
109
          gnc_add_stock_icon_pair (factory, file->stock_name,
 
110
                                   file->filename_lg, file->filename_sm);
 
111
        }
 
112
 
 
113
        gtk_icon_factory_add_default (factory);
 
114
}