Change the way icons are loaded and the corresponding define names

This commit is contained in:
Robert Fewell 2017-06-27 13:59:32 +01:00
parent 75f17b6742
commit 69238ec463
3 changed files with 65 additions and 119 deletions

View File

@ -747,7 +747,7 @@ gnc_gui_init(void)
/* Load css configuration file */
gnc_add_css_file ();
gnc_load_stock_icons();
gnc_load_app_icons();
gnc_totd_dialog(GTK_WINDOW(main_window), TRUE);
LEAVE ("");

View File

@ -1,5 +1,5 @@
/*
* gnc-icons.c -- Functions to create a GtkIconFactory for GnuCash
* gnc-icons.c -- Functions to add icons for GnuCash to use
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
*/
@ -33,112 +33,58 @@
#include "gnc-filepath-utils.h"
#include "gnc-gnome-utils.h"
static GtkStockItem items[] =
{
{ GNC_STOCK_ACCOUNT, N_("Account"), 0, 0, NULL },
{ GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Account"), 0, 0, NULL },
{ GNC_STOCK_EDIT_ACCOUNT, N_("_Edit Account"), 0, 0, NULL },
{ GNC_STOCK_NEW_ACCOUNT, N_("_New Account"), 0, 0, NULL },
{ GNC_STOCK_OPEN_ACCOUNT, N_("_Open Account"), 0, 0, NULL },
{ GNC_STOCK_TRANSFER, N_("_Transfer..."), 0, 0, NULL },
{ GNC_STOCK_SPLIT_TRANS, N_("S_plit Transaction"), 0, 0, NULL },
{ GNC_STOCK_JUMP_TO, N_("_Jump"), 0, 0, NULL },
};
typedef struct _item_file
{
const gchar *stock_name;
const gchar *icon_name;
const gchar *filename_lg;
const gchar *filename_sm;
} item_file;
static item_file item_files[] =
{
{ GNC_STOCK_ACCOUNT, "gnc-account.png", "gnc-account-16.png"},
{ GNC_STOCK_ACCOUNT_REPORT, "gnc-account-report.png", "gnc-account-report-16.png"},
{ GNC_STOCK_DELETE_ACCOUNT, "gnc-account-delete.png", "gnc-account-delete-16.png"},
{ GNC_STOCK_EDIT_ACCOUNT, "gnc-account-edit.png", "gnc-account-edit-16.png"},
{ GNC_STOCK_NEW_ACCOUNT, "gnc-account-new.png", "gnc-account-new-16.png"},
{ GNC_STOCK_OPEN_ACCOUNT, "gnc-account-open.png", "gnc-account-open-16.png"},
{ GNC_STOCK_TRANSFER, "gnc-transfer.png", "gnc-transfer-16.png"},
{ GNC_STOCK_SCHEDULE, "gnc-sx-new.png", "gnc-sx-new-16.png"},
{ GNC_STOCK_SPLIT_TRANS, "gnc-split-trans.png", "gnc-split-trans-16.png"},
{ GNC_STOCK_JUMP_TO, "gnc-jumpto.png", "gnc-jumpto-16.png"},
{ GNC_STOCK_INVOICE, "gnc-invoice.png", "gnc-invoice-16.png"},
{ GNC_STOCK_INVOICE_PAY, "gnc-invoice-pay.png", "gnc-invoice-pay-16.png"},
{ GNC_STOCK_INVOICE_POST, "gnc-invoice-post.png", "gnc-invoice-post-16.png"},
{ GNC_STOCK_INVOICE_UNPOST, "gnc-invoice-unpost.png", "gnc-invoice-unpost-16.png"},
{ GNC_STOCK_INVOICE_NEW, "gnc-invoice-new.png", "gnc-invoice-new-16.png"},
{ GNC_STOCK_INVOICE_EDIT, "gnc-invoice-edit.png", "gnc-invoice-edit-16.png"},
{ GNC_STOCK_INVOICE_DUPLICATE, "gnc-invoice-duplicate.png", "gnc-invoice-duplicate-16.png"},
{ GNC_STOCK_PDF_EXPORT, "gnc-gnome-pdf-24.png", "gnc-gnome-pdf-16.png"},
{ GNC_ICON_ACCOUNT, "gnc-account.png", "gnc-account-16.png"},
{ GNC_ICON_ACCOUNT_REPORT, "gnc-account-report.png", "gnc-account-report-16.png"},
{ GNC_ICON_DELETE_ACCOUNT, "gnc-account-delete.png", "gnc-account-delete-16.png"},
{ GNC_ICON_EDIT_ACCOUNT, "gnc-account-edit.png", "gnc-account-edit-16.png"},
{ GNC_ICON_NEW_ACCOUNT, "gnc-account-new.png", "gnc-account-new-16.png"},
{ GNC_ICON_OPEN_ACCOUNT, "gnc-account-open.png", "gnc-account-open-16.png"},
{ GNC_ICON_TRANSFER, "gnc-transfer.png", "gnc-transfer-16.png"},
{ GNC_ICON_SCHEDULE, "gnc-sx-new.png", "gnc-sx-new-16.png"},
{ GNC_ICON_SPLIT_TRANS, "gnc-split-trans.png", "gnc-split-trans-16.png"},
{ GNC_ICON_JUMP_TO, "gnc-jumpto.png", "gnc-jumpto-16.png"},
{ GNC_ICON_INVOICE, "gnc-invoice.png", "gnc-invoice-16.png"},
{ GNC_ICON_INVOICE_PAY, "gnc-invoice-pay.png", "gnc-invoice-pay-16.png"},
{ GNC_ICON_INVOICE_POST, "gnc-invoice-post.png", "gnc-invoice-post-16.png"},
{ GNC_ICON_INVOICE_UNPOST, "gnc-invoice-unpost.png", "gnc-invoice-unpost-16.png"},
{ GNC_ICON_INVOICE_NEW, "gnc-invoice-new.png", "gnc-invoice-new-16.png"},
{ GNC_ICON_INVOICE_EDIT, "gnc-invoice-edit.png", "gnc-invoice-edit-16.png"},
{ GNC_ICON_INVOICE_DUPLICATE, "gnc-invoice-duplicate.png", "gnc-invoice-duplicate-16.png"},
{ GNC_ICON_PDF_EXPORT, "gnc-gnome-pdf-24.png", "gnc-gnome-pdf-16.png"},
{ 0 },
};
static void
gnc_add_stock_icon_pair (GtkIconFactory *factory,
const char *stock,
const char *filename1,
const char *filename2)
{
GtkIconSet *set;
GtkIconSource *source;
GdkPixbuf *pixbuf1, *pixbuf2;
char *fullname1, *fullname2;
/* Find the complete path names for these files */
fullname1 = gnc_filepath_locate_pixmap (filename1);
fullname2 = gnc_filepath_locate_pixmap (filename2);
g_assert (fullname1 && fullname2);
/* Load the pixbufs */
pixbuf1 = gnc_gnome_get_gdkpixbuf (filename1);
pixbuf2 = gnc_gnome_get_gdkpixbuf (filename2);
g_assert (pixbuf1 && pixbuf2);
/* Create the icon set */
set = gtk_icon_set_new ();
source = gtk_icon_source_new ();
gtk_icon_source_set_filename (source, fullname1);
gtk_icon_source_set_pixbuf (source, pixbuf1);
gtk_icon_set_add_source (set, source);
gtk_icon_source_free(source);
source = gtk_icon_source_new ();
gtk_icon_source_set_filename (source, fullname2);
gtk_icon_source_set_pixbuf (source, pixbuf2);
gtk_icon_source_set_size (source, GTK_ICON_SIZE_MENU);
gtk_icon_source_set_size_wildcarded (source, FALSE);
gtk_icon_set_add_source (set, source);
gtk_icon_source_free(source);
/* Add it to the factory */
gtk_icon_factory_add (factory, stock, set);
/* Cleanup */
g_object_unref (pixbuf2);
g_object_unref (pixbuf1);
g_free(fullname2);
g_free(fullname1);
gtk_icon_set_unref (set);
}
void
gnc_load_stock_icons (void)
gnc_load_app_icons (void)
{
GtkIconFactory *factory;
item_file *file;
/* Register our stock items */
gtk_stock_add (items, G_N_ELEMENTS (items));
/* Add our custom icon factory to the list of defaults */
factory = gtk_icon_factory_new ();
for (file = item_files; file->stock_name; file++)
for (file = item_files; file->icon_name; file++)
{
gnc_add_stock_icon_pair (factory, file->stock_name,
file->filename_lg, file->filename_sm);
}
GdkPixbuf *pixbuf_sm, *pixbuf_lg;
char *fullname_sm = NULL, *fullname_lg = NULL;
gtk_icon_factory_add_default (factory);
fullname_sm = gnc_filepath_locate_pixmap (file->filename_sm);
fullname_lg = gnc_filepath_locate_pixmap (file->filename_lg);
g_assert (fullname_sm && fullname_lg);
pixbuf_sm = gnc_gnome_get_gdkpixbuf (fullname_sm);
pixbuf_lg = gnc_gnome_get_gdkpixbuf (fullname_lg);
g_assert (pixbuf_sm && pixbuf_lg);
gtk_icon_theme_add_builtin_icon (file->icon_name, 16, pixbuf_sm);
gtk_icon_theme_add_builtin_icon (file->icon_name, 24, pixbuf_lg);
g_object_unref(pixbuf_sm);
g_object_unref(pixbuf_lg);
}
}

View File

@ -1,5 +1,5 @@
/*
* gnc-icons.h -- Functions to create a GtkIconFactory for GnuCash
* gnc-icons.h -- Functions to add icons for GnuCash to use
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
*/
@ -29,34 +29,34 @@
G_BEGIN_DECLS
#define GNC_STOCK_ACCOUNT "gnc-account"
#define GNC_STOCK_ACCOUNT_REPORT "gnc-account-report"
#define GNC_STOCK_DELETE_ACCOUNT "gnc-delete-account"
#define GNC_STOCK_EDIT_ACCOUNT "gnc-edit-account"
#define GNC_STOCK_NEW_ACCOUNT "gnc-new-account"
#define GNC_STOCK_OPEN_ACCOUNT "gnc-open-account"
#define GNC_STOCK_SPLIT_TRANS "gnc-split-transaction"
#define GNC_STOCK_SCHEDULE "gnc-schedule-new"
#define GNC_STOCK_TRANSFER "gnc-transfer"
#define GNC_STOCK_JUMP_TO "gnc-jump-to"
#define GNC_STOCK_INVOICE "gnc-invoice-post"
#define GNC_STOCK_INVOICE_POST "gnc-invoice-post"
#define GNC_STOCK_INVOICE_UNPOST "gnc-invoice-unpost"
#define GNC_STOCK_INVOICE_PAY "gnc-invoice-pay"
#define GNC_STOCK_INVOICE_NEW "gnc-invoice-new"
#define GNC_STOCK_INVOICE_EDIT "gnc-invoice-edit"
#define GNC_STOCK_INVOICE_DUPLICATE "gnc-invoice-duplicate"
#define GNC_STOCK_PDF_EXPORT "gnc-pdf-export"
#define GNC_ICON_ACCOUNT "gnc-account"
#define GNC_ICON_ACCOUNT_REPORT "gnc-account-report"
#define GNC_ICON_DELETE_ACCOUNT "gnc-account-delete"
#define GNC_ICON_EDIT_ACCOUNT "gnc-account-edit"
#define GNC_ICON_NEW_ACCOUNT "gnc-account-new"
#define GNC_ICON_OPEN_ACCOUNT "gnc-account-open"
#define GNC_ICON_SPLIT_TRANS "gnc-split-trans"
#define GNC_ICON_SCHEDULE "gnc-sx-new"
#define GNC_ICON_TRANSFER "gnc-transfer"
#define GNC_ICON_JUMP_TO "gnc-jumpto"
#define GNC_ICON_INVOICE "gnc-invoice"
#define GNC_ICON_INVOICE_POST "gnc-invoice-post"
#define GNC_ICON_INVOICE_UNPOST "gnc-invoice-unpost"
#define GNC_ICON_INVOICE_PAY "gnc-invoice-pay"
#define GNC_ICON_INVOICE_NEW "gnc-invoice-new"
#define GNC_ICON_INVOICE_EDIT "gnc-invoice-edit"
#define GNC_ICON_INVOICE_DUPLICATE "gnc-invoice-duplicate"
#define GNC_ICON_PDF_EXPORT "gnc-gnome-pdf"
//FIXME: use own budget icons?
#define GNC_STOCK_BUDGET "gnc-budget"
#define GNC_STOCK_NEW_BUDGET "gnc-account"
#define GNC_STOCK_OPEN_BUDGET "gnc-open-account"
//#define GNC_STOCK_CLOSE_BUDGET "gnc-close-account"
//#define GNC_STOCK_EDIT_BUDGET "gnc-edit-account"
#define GNC_STOCK_DELETE_BUDGET "gnc-delete-account"
#define GNC_ICON_BUDGET "gnc-budget"
#define GNC_ICON_NEW_BUDGET "gnc-account"
#define GNC_ICON_OPEN_BUDGET "gnc-account-open"
//#define GNC_ICON_CLOSE_BUDGET "gnc-close-account"
//#define GNC_ICON_EDIT_BUDGET "gnc-edit-account"
#define GNC_ICON_DELETE_BUDGET "gnc-account-delete"
void gnc_load_stock_icons (void);
void gnc_load_app_icons (void);
G_END_DECLS