+2007-04-10 Jim Evins <evins@snaught.com>
+
+ * libglabels/template.h:
+ * libglabels/template.c: (gl_template_get_name_list_unique),
+ (gl_template_get_name_list_all), (gl_template_from_name):
+ Modified libglabels to allow you to get a list of all template names
+ including all aliases or just a list of primary names of each unique
+ template.
+ * src/Makefile.am:
+ * src/file.c: (gl_file_properties):
+ * src/glabels.c: (main):
+ * src/mini-preview-pixbuf-cache.h:
+ * src/mini-preview-pixbuf-cache.c:
+ * src/wdgt-media-select.c: (gl_wdgt_media_select_construct),
+ (filter_changed_cb), (load_list):
+ Added mini-preview pixbuf cache, so that only one mini-preview is
+ needed for a unique template and gets reused for all aliases. These
+ pixbufs will also live for the life of the program so they are not
+ rebuilt everytime a new label dialog is invoked.
+ * src/mini-preview-pixbuf.c: (draw_paper),
+ (draw_rect_label_outline), (draw_round_label_outline),
+ (draw_cd_label_outline):
+ Removed some comment artifacts.
+
2007-04-04 Jim Evins <evins@snaught.com>
* src/mini-preview-pixbuf.c: (gl_mini_preview_pixbuf_new),
}
-/*****************************************************************************/
-/* Get a list of valid template names for given page size */
-/*****************************************************************************/
+/*********************************************************************************/
+/* Get a list of valid names of unique templates for given page size */
+/*********************************************************************************/
+GList *
+gl_template_get_name_list_unique (const gchar *page_size,
+ const gchar *category)
+{
+ GList *p_tmplt;
+ glTemplate *template;
+ GList *names = NULL;
+
+ if (!templates)
+ {
+ gl_template_init ();
+ }
+
+ for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ {
+ template = (glTemplate *) p_tmplt->data;
+ if (gl_template_does_page_size_match (template, page_size) &&
+ gl_template_does_category_match (template, category))
+ {
+ names = g_list_insert_sorted (names, g_strdup (template->name),
+ (GCompareFunc)g_strcasecmp);
+ }
+ }
+
+ return names;
+}
+
+/*********************************************************************************/
+/* Get a list of all valid template names for given page size (includes aliases) */
+/*********************************************************************************/
GList *
-gl_template_get_name_list (const gchar *page_size,
- const gchar *category)
+gl_template_get_name_list_all (const gchar *page_size,
+ const gchar *category)
{
GList *p_tmplt, *p_alias;
glTemplate *template;
for (p_alias = template->aliases; p_alias != NULL;
p_alias = p_alias->next)
{
- str = g_strdup_printf("%s: %s",
- (gchar *) p_alias->data,
- template->description);
+ str = g_strdup ((gchar *) p_alias->data);
names = g_list_insert_sorted (names, str,
(GCompareFunc)g_strcasecmp);
}
gl_template_from_name (const gchar *name)
{
GList *p_tmplt, *p_alias;
- glTemplate *template, *new_template;
- gchar **split_name;
+ glTemplate *template;
if (!templates) {
gl_template_init ();
return gl_template_dup ((glTemplate *) templates->data);
}
- /* Strip off any descriptions */
- split_name = g_strsplit (name, ":", 2);
-
for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
template = (glTemplate *) p_tmplt->data;
for (p_alias = template->aliases; p_alias != NULL;
p_alias = p_alias->next) {
- if (g_strcasecmp (p_alias->data, split_name[0]) == 0) {
-
- new_template = gl_template_dup (template);
-
- /* Use the real name */
- g_free (new_template->name);
- new_template->name = g_strdup (split_name[0]);
+ if (g_strcasecmp (p_alias->data, name) == 0) {
- g_strfreev (split_name);
-
- return new_template;
+ return gl_template_dup (template);
}
}
}
- g_strfreev (split_name);
-
/* No matching template has been found so return the first template */
return gl_template_dup ((glTemplate *) templates->data);
}
-/*****************************************************************************/
-/* Get name and format with description. */
-/*****************************************************************************/
-gchar *
-gl_template_get_name_with_desc (const glTemplate *template)
-{
- g_return_val_if_fail (template, NULL);
-
- return g_strdup_printf("%s: %s", template->name, template->description);
-}
-
/*****************************************************************************/
/* Get first label type in template. */
/*****************************************************************************/
/*
* Known templates query functions
*/
-GList *gl_template_get_name_list (const gchar *page_size,
+GList *gl_template_get_name_list_unique (const gchar *page_size,
+ const gchar *category);
+
+GList *gl_template_get_name_list_all (const gchar *page_size,
const gchar *category);
void gl_template_free_name_list (GList *names);
/*
* Template query functions
*/
-gchar *gl_template_get_name_with_desc (const glTemplate *template);
-
const glTemplateLabelType *gl_template_get_first_label_type (const glTemplate *template);
gboolean gl_template_does_page_size_match (const glTemplate *template,
text-node.h \
mini-preview-pixbuf.c \
mini-preview-pixbuf.h \
+ mini-preview-pixbuf-cache.c \
+ mini-preview-pixbuf-cache.h \
wdgt-print-copies.c \
wdgt-print-copies.h \
wdgt-print-merge.c \
NULL);
}
if (label->template->name != NULL) {
- gchar *template_name = gl_template_get_name_with_desc (label->template);
gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog),
- template_name);
- gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog),
- template_name);
- g_free (template_name);
+ label->template->name);
}
gl_new_label_dialog_set_rotate_state (GL_NEW_LABEL_DIALOG (dialog),
label->rotate_flag);
#include "recent.h"
#include <libglabels/paper.h>
#include <libglabels/template.h>
+#include "mini-preview-pixbuf-cache.h"
#include "prefs.h"
#include "debug.h"
#include "window.h"
gl_paper_init ();
gl_prefs_init ();
gl_template_init ();
+ gl_mini_preview_pixbuf_cache_init ();
gl_merge_init ();
gl_recent_init ();
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * mini-preview-pixbuf-cache.c: GLabels mini-preview pixbuf cache module
+ *
+ * Copyright (C) 2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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
+ */
+#include <config.h>
+
+#include "mini-preview-pixbuf-cache.h"
+#include "mini-preview-pixbuf.h"
+
+#include <glib/gmem.h>
+#include <glib/ghash.h>
+
+#include "debug.h"
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private globals. */
+/*========================================================*/
+
+static GHashTable *mini_preview_pixbuf_cache = NULL;
+
+/*========================================================*/
+/* Private function prototypes. */
+/*========================================================*/
+
+\f
+/*****************************************************************************/
+/* Create a new hash table to keep track of cached mini preview pixbufs. */
+/*****************************************************************************/
+void
+gl_mini_preview_pixbuf_cache_init (void)
+{
+ GList *names = NULL;
+ GList *p;
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "START");
+
+ mini_preview_pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
+
+ names = gl_template_get_name_list_unique (NULL, NULL);
+ for ( p=names; p != NULL; p=p->next )
+ {
+ gl_mini_preview_pixbuf_cache_add_by_name ((gchar *)p->data);
+ }
+ gl_template_free_name_list (names);
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "END pixbuf_cache=%p", mini_preview_pixbuf_cache);
+}
+
+/*****************************************************************************/
+/* Add pixbuf to cache by name. */
+/*****************************************************************************/
+void
+gl_mini_preview_pixbuf_cache_add_by_name (gchar *name)
+{
+ glTemplate *template;
+ GdkPixbuf *pixbuf;
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "START");
+
+ template = gl_template_from_name (name);
+ pixbuf = gl_mini_preview_pixbuf_new (template, 72, 72);
+ gl_template_free (template);
+
+ g_hash_table_insert (mini_preview_pixbuf_cache, g_strdup (name), pixbuf);
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "END");
+}
+
+/*****************************************************************************/
+/* Get pixbuf. */
+/*****************************************************************************/
+GdkPixbuf *
+gl_mini_preview_pixbuf_cache_get_pixbuf (gchar *name)
+{
+ GdkPixbuf *pixbuf;
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "START pixbuf_cache=%p", mini_preview_pixbuf_cache);
+
+ pixbuf = g_hash_table_lookup (mini_preview_pixbuf_cache, name);
+
+ gl_debug (DEBUG_PIXBUF_CACHE, "END");
+
+ return g_object_ref (pixbuf);
+}
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * mini-preview-pixbuf-cache.h: GLabels mini-preview pixbuf cache module
+ *
+ * Copyright (C) 2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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
+ */
+#ifndef __MINI_PREVIEW_PIXBUF_CACHE_H__
+#define __MINI_PREVIEW_PIXBUF_CACHE_H__
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+G_BEGIN_DECLS
+
+void gl_mini_preview_pixbuf_cache_init (void);
+
+void gl_mini_preview_pixbuf_cache_add_by_name (gchar *name);
+
+GdkPixbuf *gl_mini_preview_pixbuf_cache_get_pixbuf (gchar *name);
+
+
+G_END_DECLS
+
+#endif /*__MINI_PREVIEW_PIXBUF_CACHE_H__ */
gl_debug (DEBUG_MINI_PREVIEW, "START");
cairo_save (cr);
- //cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_rectangle (cr, 0.0, 0.0, template->page_width, template->page_height);
cairo_set_source_rgb (cr, 0.95, 0.95, 0.95);
cairo_fill_preserve (cr);
cairo_save (cr);
- //cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
-
label_type = gl_template_get_first_label_type (template);
gl_template_get_label_size (label_type, &w, &h);
cairo_save (cr);
- //cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
-
label_type = gl_template_get_first_label_type (template);
gl_template_get_label_size (label_type, &w, &h);
cairo_save (cr);
- //cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
-
label_type = gl_template_get_first_label_type (template);
gl_template_get_label_size (label_type, &w, &h);
#include <gtk/gtkstock.h>
#include <string.h>
-#include "mini-preview-pixbuf.h"
+#include "mini-preview-pixbuf-cache.h"
#include "prefs.h"
#include "util.h"
#include "color.h"
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_append_column (GTK_TREE_VIEW (media_select->priv->template_treeview), column);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (media_select->priv->template_treeview));
- template_names = gl_template_get_name_list (page_size_id, NULL);
+ template_names = gl_template_get_name_list_all (page_size_id, NULL);
load_list (media_select->priv->template_store, selection, template_names);
gl_template_free_name_list (template_names);
category_id = gl_category_lookup_id_from_name (category_name);
gl_debug (DEBUG_MEDIA_SELECT, "page_size_id = \"%s\"", page_size_id);
gl_debug (DEBUG_MEDIA_SELECT, "category_id = \"%s\"", category_id);
- template_names = gl_template_get_name_list (page_size_id, category_id);
+ template_names = gl_template_get_name_list_all (page_size_id, category_id);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (media_select->priv->template_treeview));
g_signal_handlers_block_by_func (G_OBJECT (selection),
template_selection_changed_cb,
template = gl_template_from_name (p->data);
- pixbuf = gl_mini_preview_pixbuf_new (template, 72, 72);
+ pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (template->name);
size = get_label_size_desc (template);
layout = get_layout_desc (template);
- description = g_strdup_printf ("<b>%s</b>\n%s\n%s",
+ description = g_strdup_printf ("<b>%s: %s</b>\n%s\n%s",
(gchar *)p->data,
+ template->description,
size,
layout);
g_free (size);