pixlist.c File Reference

#include <gtk/gtk.h>
#include <string.h>
#include <libergtk/ergtk.h>
#include "log.h"
#include "pixlist.h"
Include dependency graph for pixlist.c:

Go to the source code of this file.

Defines

#define LOGGING_ON   0

Functions

gint compareString (gconstpointer a, gconstpointer b)
static GdkPixbuf * load_icon (const gchar *filename)
GdkPixbuf * pixlist_icon_state (const char *icon, const char *state)
GdkPixbuf * pixlist_toolbar_icon (const char *name, const char *state)

Variables

static GTree * g_icon_cache = NULL

Define Documentation

#define LOGGING_ON   0

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Note: possibly could have used reference count of gobject instead

Definition at line 33 of file pixlist.c.


Function Documentation

gint compareString ( gconstpointer  a,
gconstpointer  b 
)

Definition at line 47 of file pixlist.c.

00047                                                      {
00048     return strcmp((const gchar*)a, (const gchar*)b);
00049 }

static GdkPixbuf* load_icon ( const gchar *  filename  )  [static]

Definition at line 51 of file pixlist.c.

References compareString(), g_icon_cache, and LOGPRINTF.

Referenced by pixlist_icon_state(), and pixlist_toolbar_icon().

00052 {
00053     if (g_icon_cache == NULL) g_icon_cache = g_tree_new(compareString);
00054 
00055     gpointer cache = g_tree_lookup(g_icon_cache, filename);
00056     if (cache) return (GdkPixbuf *)cache;
00057 
00058     GError *err = NULL;
00059     GdkPixbuf *icon = gdk_pixbuf_new_from_file(filename, &err);
00060     if (icon) {
00061         g_tree_insert(g_icon_cache, g_strdup(filename), icon);
00062     } else  {
00063         LOGPRINTF("cannot load iconfile [%s] error [%s]", filename, err->message);
00064         g_clear_error(&err);
00065     }
00066     return icon;
00067 }

Here is the call graph for this function:

Here is the caller graph for this function:

GdkPixbuf* pixlist_icon_state ( const char *  icon,
const char *  state 
)

Definition at line 70 of file pixlist.c.

References load_icon(), LOGPRINTF, and PATH_IMG.

Referenced by add_popup_submenu(), get_pixbuf(), menustore_add_group(), menustore_add_item(), statusbar_add_item(), and statusbar_add_item_state().

00071 {
00072     LOGPRINTF("entry %s, %s", icon, state);
00073     
00074     if ((icon == NULL) || (icon[0] == '\0'))
00075     {
00076         // no icon name so don't bother to load/ref image
00077         return NULL;
00078     }
00079 
00080     gchar *iconfile = NULL;
00081     gchar *fileext = g_utf8_strrchr(icon, strlen(icon), '.');
00082     if (fileext == NULL)
00083     {
00084         // name is not a filename or path 
00085         // prefix with path and postfix with state and file extension
00086         if (state && (strcmp(state, "normal") == 0))
00087         {
00088             iconfile = g_strdup_printf("%s%s.png", PATH_IMG, icon);
00089         }
00090         else
00091         {
00092             iconfile = g_strdup_printf("%s%s_%s.png", PATH_IMG, icon, state);
00093         }
00094     }
00095     else
00096     {
00097         gchar *strcopy = g_strdup(icon);
00098         gchar *filepath = g_utf8_strrchr(strcopy, strlen(strcopy), '.');
00099         *filepath = '\0';
00100         
00101         // icon is a full path
00102         // postfix with state only
00103         if (strcmp(state, "normal") ==0)
00104         {
00105             iconfile = g_strdup_printf("%s%s", strcopy, fileext);
00106         }
00107         else
00108         {
00109             iconfile = g_strdup_printf("%s_%s%s", strcopy, state, fileext);
00110         }
00111         g_free(strcopy);
00112     }
00113         
00114     GdkPixbuf* pixbuf = load_icon(iconfile);
00115     g_free(iconfile);
00116     return pixbuf;
00117 }

Here is the call graph for this function:

Here is the caller graph for this function:

GdkPixbuf* pixlist_toolbar_icon ( const char *  name,
const char *  state 
)

Definition at line 120 of file pixlist.c.

References filename, load_icon(), PATH_IMG, and WARNPRINTF.

00121 {
00122     GdkPixbuf* icon = NULL;
00123     if (name != NULL && name[0] != 0) {
00124         static char filename[256];
00125         snprintf(filename, sizeof(filename), "%stoolbar_%s_%s.png", PATH_IMG, name, state);
00126         icon = load_icon(filename);
00127         if (icon == NULL) {
00128             WARNPRINTF("cannot find icon %s", filename);
00129         }
00130     }
00131     if (icon == NULL) {
00132         icon = load_icon(PATH_IMG"toolbar_blank.png");
00133     }
00134     return icon;
00135 }

Here is the call graph for this function:


Variable Documentation

GTree* g_icon_cache = NULL [static]

Definition at line 45 of file pixlist.c.

Referenced by load_icon().

Generated by  doxygen 1.6.2-20100208