]> git.sur5r.net Git - glabels/commitdiff
2007-04-10 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 10 Apr 2007 14:42:24 +0000 (14:42 +0000)
committerJim Evins <evins@snaught.com>
Tue, 10 Apr 2007 14:42:24 +0000 (14:42 +0000)
* 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

glabels2/ChangeLog
glabels2/libglabels/template.c
glabels2/libglabels/template.h
glabels2/src/Makefile.am
glabels2/src/file.c
glabels2/src/glabels.c
glabels2/src/mini-preview-pixbuf-cache.c [new file with mode: 0644]
glabels2/src/mini-preview-pixbuf-cache.h [new file with mode: 0644]
glabels2/src/mini-preview-pixbuf.c
glabels2/src/wdgt-media-select.c

index 01f21220b83e749021bb994364a0c03f1860c6e1..1d4b430b90ff8b878c0c7919a43118f731434d53 100644 (file)
@@ -1,3 +1,27 @@
+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),
index fd8f8a52406408f511822db14270361da85614ec..3c11288dfe287ff2de14dfeb6460f6ee6939ca40 100644 (file)
@@ -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.                                         */
 /*****************************************************************************/
index 2dc1308bc7828c7dfe079d6ca3cb05d08834f103..db56f81c814bbd379592fe33875c89439b347fce 100644 (file)
@@ -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,
index ff5bb35e897c7f9b9f4a481be46603c03b62837c..d687e1ba8e2183142e080b914678b7155a30467f 100644 (file)
@@ -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              \
index 3ebfbfddb8b2c0144e6fc6359064edc37a060354..85162ea9c0caca4dd318541047d932bfcf2020d0 100644 (file)
@@ -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);
index 36389e28f24ba780718167f9634c4d084be4ce38..1e957f40933c2e12ada6525fc09f1d9c9c67666c 100644 (file)
@@ -36,6 +36,7 @@
 #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"
@@ -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 (file)
index 0000000..b87d657
--- /dev/null
@@ -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 <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);
+}
+
diff --git a/glabels2/src/mini-preview-pixbuf-cache.h b/glabels2/src/mini-preview-pixbuf-cache.h
new file mode 100644 (file)
index 0000000..1322a68
--- /dev/null
@@ -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 <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__ */
index a2159e8f92eeae0b7ec347ec07bfebdc3d66d0c6..b8f5e99abd6a7a1c8bf435cdac50634553358551 100644 (file)
@@ -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);
 
index a33029a9cf5fc764ea54169eb4c157de0548df14..9babee7d93c261e1d646320566d2d3cfe026b79a 100644 (file)
@@ -37,7 +37,7 @@
 #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"
@@ -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 ("<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);