1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * mini-preview-pixbuf-cache.c: GLabels mini-preview pixbuf cache module
8 * Copyright (C) 2007 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "mini-preview-pixbuf-cache.h"
27 #include "mini-preview-pixbuf.h"
29 #include <glib/gmem.h>
30 #include <glib/ghash.h>
34 /*========================================================*/
36 /*========================================================*/
38 /*========================================================*/
39 /* Private globals. */
40 /*========================================================*/
42 static GHashTable *mini_preview_pixbuf_cache = NULL;
44 /*========================================================*/
45 /* Private function prototypes. */
46 /*========================================================*/
49 /*****************************************************************************/
50 /* Create a new hash table to keep track of cached mini preview pixbufs. */
51 /*****************************************************************************/
53 gl_mini_preview_pixbuf_cache_init (void)
58 gl_debug (DEBUG_PIXBUF_CACHE, "START");
60 mini_preview_pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
62 names = gl_template_get_name_list_unique (NULL, NULL);
63 for ( p=names; p != NULL; p=p->next )
65 gl_mini_preview_pixbuf_cache_add_by_name ((gchar *)p->data);
67 gl_template_free_name_list (names);
69 gl_debug (DEBUG_PIXBUF_CACHE, "END pixbuf_cache=%p", mini_preview_pixbuf_cache);
72 /*****************************************************************************/
73 /* Add pixbuf to cache by name. */
74 /*****************************************************************************/
76 gl_mini_preview_pixbuf_cache_add_by_name (gchar *name)
81 gl_debug (DEBUG_PIXBUF_CACHE, "START");
83 template = gl_template_from_name (name);
84 pixbuf = gl_mini_preview_pixbuf_new (template, 72, 72);
85 gl_template_free (template);
87 g_hash_table_insert (mini_preview_pixbuf_cache, g_strdup (name), pixbuf);
89 gl_debug (DEBUG_PIXBUF_CACHE, "END");
92 /*****************************************************************************/
94 /*****************************************************************************/
96 gl_mini_preview_pixbuf_cache_get_pixbuf (gchar *name)
100 gl_debug (DEBUG_PIXBUF_CACHE, "START pixbuf_cache=%p", mini_preview_pixbuf_cache);
102 pixbuf = g_hash_table_lookup (mini_preview_pixbuf_cache, name);
104 gl_debug (DEBUG_PIXBUF_CACHE, "END");
106 return g_object_ref (pixbuf);