]> git.sur5r.net Git - glabels/blob - glabels2/src/mini-preview-pixbuf-cache.c
2007-09-14 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / mini-preview-pixbuf-cache.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  mini-preview-pixbuf-cache.c:  GLabels mini-preview pixbuf cache module
7  *
8  *  Copyright (C) 2007  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24 #include <config.h>
25
26 #include "mini-preview-pixbuf-cache.h"
27 #include "mini-preview-pixbuf.h"
28
29 #include <glib/gmem.h>
30 #include <glib/ghash.h>
31
32 #include "debug.h"
33
34 /*========================================================*/
35 /* Private types.                                         */
36 /*========================================================*/
37
38 /*========================================================*/
39 /* Private globals.                                       */
40 /*========================================================*/
41
42 static GHashTable *mini_preview_pixbuf_cache = NULL;
43
44 /*========================================================*/
45 /* Private function prototypes.                           */
46 /*========================================================*/
47
48 \f
49 /*****************************************************************************/
50 /* Create a new hash table to keep track of cached mini preview pixbufs.     */
51 /*****************************************************************************/
52 void
53 gl_mini_preview_pixbuf_cache_init (void)
54 {
55         GList      *names = NULL;
56         GList      *p;
57
58         gl_debug (DEBUG_PIXBUF_CACHE, "START");
59
60         mini_preview_pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
61
62         names = gl_template_get_name_list_unique (NULL, NULL);
63         for ( p=names; p != NULL; p=p->next )
64         {
65                 gl_mini_preview_pixbuf_cache_add_by_name ((gchar *)p->data);
66         }
67         gl_template_free_name_list (names);
68
69         gl_debug (DEBUG_PIXBUF_CACHE, "END pixbuf_cache=%p", mini_preview_pixbuf_cache);
70 }
71
72 /*****************************************************************************/
73 /* Add pixbuf to cache by name.                                              */
74 /*****************************************************************************/
75 void
76 gl_mini_preview_pixbuf_cache_add_by_name (gchar      *name)
77 {
78         glTemplate *template;
79         GdkPixbuf  *pixbuf;
80
81         gl_debug (DEBUG_PIXBUF_CACHE, "START");
82
83         template = gl_template_from_name (name);
84         pixbuf = gl_mini_preview_pixbuf_new (template, 72, 72);
85         gl_template_free (template);
86
87         g_hash_table_insert (mini_preview_pixbuf_cache, g_strdup (name), pixbuf);
88
89         gl_debug (DEBUG_PIXBUF_CACHE, "END");
90 }
91
92 /*****************************************************************************/
93 /* Get pixbuf.                                                               */
94 /*****************************************************************************/
95 GdkPixbuf *
96 gl_mini_preview_pixbuf_cache_get_pixbuf (gchar      *name)
97 {
98         GdkPixbuf   *pixbuf;
99
100         gl_debug (DEBUG_PIXBUF_CACHE, "START pixbuf_cache=%p", mini_preview_pixbuf_cache);
101
102         pixbuf = g_hash_table_lookup (mini_preview_pixbuf_cache, name);
103
104         gl_debug (DEBUG_PIXBUF_CACHE, "END");
105
106         return g_object_ref (pixbuf);
107 }
108