/*
- * (GLABELS) Label and Business Card Creation program for GNOME
+ * pixbuf-cache.c
+ * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
*
- * pixbuf-cache.c: GLabels pixbuf cache module
+ * This file is part of gLabels.
*
- * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
- *
- * This program is free software; you can redistribute it and/or modify
+ * gLabels is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * gLabels is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include <config.h>
#include "pixbuf-cache.h"
#include "debug.h"
+
/*========================================================*/
/* Private types. */
/*========================================================*/
GdkPixbuf *pixbuf;
} CacheRecord;
+
/*========================================================*/
/* Private globals. */
/*========================================================*/
+
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
gpointer val,
gpointer user_data);
-\f
+
/*---------------------------------------------------------------------------*/
/* PRIVATE. Destroy cache record. */
/*---------------------------------------------------------------------------*/
g_free (record);
}
+
/*****************************************************************************/
/* Create a new hash table to keep track of cached pixbufs. */
/*****************************************************************************/
return pixbuf_cache;
}
+
/*****************************************************************************/
/* Free up previously allocated hash table and its contents. */
/*****************************************************************************/
gl_debug (DEBUG_PIXBUF_CACHE, "END");
}
+
/*****************************************************************************/
-/* Add pixbuf to cache explicitly. */
+/* Add pixbuf to cache explicitly (not a reference). */
/*****************************************************************************/
void
gl_pixbuf_cache_add_pixbuf (GHashTable *pixbuf_cache,
GdkPixbuf *pixbuf)
{
CacheRecord *test_record, *record;
- gchar *key;
gl_debug (DEBUG_PIXBUF_CACHE, "START");
record = g_new0 (CacheRecord, 1);
record->key = g_strdup (name);
- record->references = 0;
- record->pixbuf = pixbuf;
+ record->references = 0; /* Nobody has referenced it yet. */
+ record->pixbuf = g_object_ref (G_OBJECT (pixbuf));
g_hash_table_insert (pixbuf_cache, record->key, record);
gl_debug (DEBUG_PIXBUF_CACHE, "END");
}
+
/*****************************************************************************/
/* Get pixbuf. If not in cache, read it and add to cache. */
/*****************************************************************************/
record = g_hash_table_lookup (pixbuf_cache, name);
if (record != NULL) {
- gl_debug (DEBUG_PIXBUF_CACHE, "END cached");
record->references++;
+ gl_debug (DEBUG_PIXBUF_CACHE, "references=%d", record->references);
+ gl_debug (DEBUG_PIXBUF_CACHE, "END cached");
return record->pixbuf;
}
return pixbuf;
}
+
/*****************************************************************************/
/* Remove pixbuf, but only if no references left. */
/*****************************************************************************/
{
CacheRecord *record;
+ if (name == NULL) return;
+
gl_debug (DEBUG_PIXBUF_CACHE, "START");
record = g_hash_table_lookup (pixbuf_cache, name);
gl_debug (DEBUG_PIXBUF_CACHE, "END");
}
+
/*---------------------------------------------------------------------------*/
/* PRIVATE. Add a name to a GList while iterating over cache. */
/*---------------------------------------------------------------------------*/
gl_debug (DEBUG_PIXBUF_CACHE, "END");
}
+
/*****************************************************************************/
/* Return a list of names for all pixbufs in the cache. */
/*****************************************************************************/
return name_list;
}
+
/*****************************************************************************/
/* Free up a list of pixbuf names. */
/*****************************************************************************/
}
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */