From: Jim Evins Date: Tue, 10 Apr 2007 14:42:24 +0000 (+0000) Subject: 2007-04-10 Jim Evins X-Git-Tag: glabels-2_3_0~346 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=964caeca001e6f6b7c26d5beb6dc5cc34b7debba;p=glabels 2007-04-10 Jim Evins * 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. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@650 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 01f21220..1d4b430b 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,27 @@ +2007-04-10 Jim Evins + + * 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 * src/mini-preview-pixbuf.c: (gl_mini_preview_pixbuf_new), diff --git a/glabels2/libglabels/template.c b/glabels2/libglabels/template.c index fd8f8a52..3c11288d 100644 --- a/glabels2/libglabels/template.c +++ b/glabels2/libglabels/template.c @@ -141,12 +141,42 @@ gl_template_register (const glTemplate *template) } -/*****************************************************************************/ -/* 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; @@ -167,9 +197,7 @@ gl_template_get_name_list (const gchar *page_size, 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); } @@ -202,8 +230,7 @@ glTemplate * 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 (); @@ -214,45 +241,21 @@ gl_template_from_name (const gchar *name) 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. */ /*****************************************************************************/ diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h index 2dc1308b..db56f81c 100644 --- a/glabels2/libglabels/template.h +++ b/glabels2/libglabels/template.h @@ -191,7 +191,10 @@ void gl_template_register (const glTemplate *temp /* * 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); @@ -202,8 +205,6 @@ glTemplate *gl_template_from_name (const gchar *name /* * 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, diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index ff5bb35e..d687e1ba 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -160,6 +160,8 @@ glabels_SOURCES = \ 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 \ diff --git a/glabels2/src/file.c b/glabels2/src/file.c index 3ebfbfdd..85162ea9 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -199,12 +199,8 @@ gl_file_properties (glLabel *label, 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); diff --git a/glabels2/src/glabels.c b/glabels2/src/glabels.c index 36389e28..1e957f40 100644 --- a/glabels2/src/glabels.c +++ b/glabels2/src/glabels.c @@ -36,6 +36,7 @@ #include "recent.h" #include #include +#include "mini-preview-pixbuf-cache.h" #include "prefs.h" #include "debug.h" #include "window.h" @@ -121,6 +122,7 @@ main (int argc, char **argv) gl_paper_init (); gl_prefs_init (); gl_template_init (); + gl_mini_preview_pixbuf_cache_init (); gl_merge_init (); gl_recent_init (); diff --git a/glabels2/src/mini-preview-pixbuf-cache.c b/glabels2/src/mini-preview-pixbuf-cache.c new file mode 100644 index 00000000..b87d657a --- /dev/null +++ b/glabels2/src/mini-preview-pixbuf-cache.c @@ -0,0 +1,108 @@ +/* -*- 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 . + * + * 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 + +#include "mini-preview-pixbuf-cache.h" +#include "mini-preview-pixbuf.h" + +#include +#include + +#include "debug.h" + +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +/*========================================================*/ +/* Private globals. */ +/*========================================================*/ + +static GHashTable *mini_preview_pixbuf_cache = NULL; + +/*========================================================*/ +/* Private function prototypes. */ +/*========================================================*/ + + +/*****************************************************************************/ +/* 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); +} + diff --git a/glabels2/src/mini-preview-pixbuf-cache.h b/glabels2/src/mini-preview-pixbuf-cache.h new file mode 100644 index 00000000..1322a68a --- /dev/null +++ b/glabels2/src/mini-preview-pixbuf-cache.h @@ -0,0 +1,40 @@ +/* -*- 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 . + * + * 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 + +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__ */ diff --git a/glabels2/src/mini-preview-pixbuf.c b/glabels2/src/mini-preview-pixbuf.c index a2159e8f..b8f5e99a 100644 --- a/glabels2/src/mini-preview-pixbuf.c +++ b/glabels2/src/mini-preview-pixbuf.c @@ -149,7 +149,6 @@ draw_paper (cairo_t *cr, 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); @@ -254,8 +253,6 @@ draw_rect_label_outline (cairo_t *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); @@ -288,8 +285,6 @@ draw_round_label_outline (cairo_t *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); @@ -326,8 +321,6 @@ draw_cd_label_outline (cairo_t *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); diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index a33029a9..9babee7d 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -37,7 +37,7 @@ #include #include -#include "mini-preview-pixbuf.h" +#include "mini-preview-pixbuf-cache.h" #include "prefs.h" #include "util.h" #include "color.h" @@ -257,7 +257,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select) 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); @@ -305,7 +305,7 @@ filter_changed_cb (GtkComboBox *combo, 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, @@ -596,12 +596,13 @@ load_list (GtkListStore *store, 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 ("%s\n%s\n%s", + description = g_strdup_printf ("%s: %s\n%s\n%s", (gchar *)p->data, + template->description, size, layout); g_free (size);