From 7381cfd88fa386dc1fc3a7cce0d0aaac9c4dce45 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 21 Apr 2010 22:37:57 -0400 Subject: [PATCH] Added test for duplicate templates Added test for duplicate pre-defined templates. Removed duplicate template in pearl-iso-templates.xml. Also added lgl_template_print() for debugging purposes. --- libglabels/db.c | 13 +++++++++--- libglabels/template.c | 33 +++++++++++++++++++++++++++++++ libglabels/template.h | 6 ++++++ templates/pearl-iso-templates.xml | 15 +------------- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/libglabels/db.c b/libglabels/db.c index 3370b03c..ba01850d 100644 --- a/libglabels/db.c +++ b/libglabels/db.c @@ -1437,9 +1437,16 @@ _lgl_db_register_template_internal (const lglTemplate *template) { lglTemplate *template_copy; - template_copy = lgl_template_dup (template); - model->templates = g_list_append (model->templates, template_copy); - add_to_template_cache (template_copy); + if (!lgl_db_does_template_exist (template->brand, template->part)) + { + template_copy = lgl_template_dup (template); + model->templates = g_list_append (model->templates, template_copy); + add_to_template_cache (template_copy); + } + else + { + g_message ("Duplicate template: %s %s.", template->brand, template->part); + } } diff --git a/libglabels/template.c b/libglabels/template.c index 50271fbb..50ba454b 100644 --- a/libglabels/template.c +++ b/libglabels/template.c @@ -1474,6 +1474,39 @@ compare_origins (gconstpointer a, } +/** + * lgl_template_print: + * @template: template + * + * Print template details (for debugging purposes). + * + */ +void +lgl_template_print (const lglTemplate *template) +{ + GList *p; + lglTemplateAlias *alias; + + g_print ("---- %s( TEMPLATE=%p ) ----\n", __FUNCTION__, template); + + g_print("brand=\"%s\", part=\"%s\", description=\"%s\"\n", + template->brand, template->part, template->description); + + g_print("paper_id=\"%s\", page_width=%g, page_height=%g\n", + template->paper_id, template->page_width, template->page_height); + + for (p=template->aliases; p!=NULL; p=p->next) + { + alias = (lglTemplateAlias *)p->data; + g_print("Alias: brand=\"%s\", part=\"%s\"\n", alias->brand, alias->part); + + } + + g_print ("\n"); + +} + + /* * Local Variables: -- emacs diff --git a/libglabels/template.h b/libglabels/template.h index a3c01115..a7f43fc0 100644 --- a/libglabels/template.h +++ b/libglabels/template.h @@ -426,6 +426,12 @@ lglTemplateMarkup *lgl_template_markup_dup (const lglTemplateMarkup void lgl_template_markup_free (lglTemplateMarkup *markup); +/* + * Debugging functions. + */ +void lgl_template_print (const lglTemplate *template); + + G_END_DECLS #endif /* __LGL_TEMPLATE_H__ */ diff --git a/templates/pearl-iso-templates.xml b/templates/pearl-iso-templates.xml index d7724253..c499ce32 100644 --- a/templates/pearl-iso-templates.xml +++ b/templates/pearl-iso-templates.xml @@ -34,7 +34,7 @@ -