]> git.sur5r.net Git - glabels/commitdiff
When looking up templates by name and name isn't found, return
authorJim Evins <evins@snaught.com>
Fri, 26 Dec 2003 06:56:12 +0000 (06:56 +0000)
committerJim Evins <evins@snaught.com>
Fri, 26 Dec 2003 06:56:12 +0000 (06:56 +0000)
first template instead of NULL (suggested by Wayne Schuller <k_wayne@linuxpower.org>).  In addition, added code to register templates (make known, if not already known) when they are encountered when reading a label.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@386 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/paper.c
glabels2/src/paper.h
glabels2/src/template.c
glabels2/src/template.h
glabels2/src/xml-label-191.c
glabels2/src/xml-label.c

index 7f0f21b87ebbe723f5b424357d4c34b61e77199a..55875a7a38484108dcb40a46c929ab81db956054 100644 (file)
@@ -161,6 +161,34 @@ gl_paper_free_name_list (GList **names)
        gl_debug (DEBUG_PAPER, "END");
 }
 
+/*****************************************************************************/
+/* Is page size id known?                                                    */
+/*****************************************************************************/
+gboolean
+gl_paper_is_id_known (const gchar *id)
+{
+       GList       *p;
+       glPaper     *paper;
+
+       gl_debug (DEBUG_PAPER, "START");
+
+       if (id == NULL) {
+               gl_debug (DEBUG_PAPER, "END (false, id=NULL)");
+               return FALSE;
+       }
+
+       for (p = papers; p != NULL; p = p->next) {
+               paper = (glPaper *) p->data;
+               if (g_strcasecmp (paper->id, id) == 0) {
+                       gl_debug (DEBUG_PAPER, "END (true)");
+                       return TRUE;
+               }
+       }
+
+       gl_debug (DEBUG_PAPER, "END (false)");
+       return FALSE;
+}
+
 /*****************************************************************************/
 /* Return a paper structure from id.                                         */
 /*****************************************************************************/
index a765204b636f27531b9a4e943f954abb873355ac..ce418d56c1a7bd5ead0a1617115feb10fbeb146c 100644 (file)
@@ -46,6 +46,8 @@ void                 gl_paper_free_id_list        (GList            **ids);
 GList               *gl_paper_get_name_list       (void);
 void                 gl_paper_free_name_list      (GList            **names);
 
+gboolean             gl_paper_is_id_known         (const gchar       *id);
+
 glPaper             *gl_paper_from_id             (const gchar       *id);
 glPaper             *gl_paper_from_name           (const gchar       *name);
 
index 22e6560569e0bcddd36e961db30a4c497779ab58..dc67ad1e7668177f30da879b0735452005d88cb0 100644 (file)
@@ -149,6 +149,48 @@ gl_template_free_name_list (GList **names)
        gl_debug (DEBUG_TEMPLATE, "END");
 }
 
+/*****************************************************************************/
+/* Register template: if not in current list, add it.                        */
+/*****************************************************************************/
+void
+gl_template_register (const glTemplate  *template)
+{
+       GList      *p_tmplt, *pa1;
+       glTemplate *template1;
+
+       gl_debug (DEBUG_TEMPLATE, "START");
+
+       for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) {
+               template1 = (glTemplate *) p_tmplt->data;
+
+               for (pa1=template1->alias; pa1!=NULL; pa1=pa1->next) {
+                       
+                       gl_debug (DEBUG_TEMPLATE, "comparing \"%s\" & \"%s\"",
+                                 template->name, pa1->data);
+
+                       if (g_strcasecmp (template->name, pa1->data) == 0) {
+                               gl_debug (DEBUG_TEMPLATE, "END (found)");
+                               return;
+                       }
+                               
+               }
+
+       }
+
+       if (gl_paper_is_id_known (template->page_size)) {
+
+               gl_debug (DEBUG_TEMPLATE, "adding \"%s\"", template->name);
+               templates = g_list_prepend (templates, gl_template_dup (template));
+
+               /* TODO: write to a unique file in .glabels. */
+
+       } else {
+               g_warning ("Cannot register new template with unknown page size.");
+       }
+
+       gl_debug (DEBUG_TEMPLATE, "END");
+}
+
 /*****************************************************************************/
 /* Return a template structure from a name.                                  */
 /*****************************************************************************/
@@ -191,7 +233,9 @@ gl_template_from_name (const gchar *name)
        g_strfreev (split_name);
 
        gl_debug (DEBUG_TEMPLATE, "END");
-       return NULL;
+
+       /* No matching template has been found so return the first template */
+       return gl_template_dup ((glTemplate *) templates->data);
 }
 
 /*****************************************************************************/
index 7d8da895ef8f66b41299fc391971b08c89c9eb45..95bd47f843654fbe7faec7fc8978ce0263a9e605 100644 (file)
@@ -151,6 +151,8 @@ void                 gl_template_init                (void);
 GList               *gl_template_get_name_list       (const gchar       *page_size);
 void                 gl_template_free_name_list      (GList            **names);
 
+void                 gl_template_register            (const glTemplate  *template);
+
 glTemplate          *gl_template_from_name           (const gchar       *name);
 
 gchar               *gl_template_get_name_with_desc  (const glTemplate  *template);
index bbf1dc19651607c662ddd5eaf02fc941008079e3..09552b5cd41b9abdc42301e1432b1496b6520302 100644 (file)
@@ -151,6 +151,7 @@ gl_xml_label_191_parse (xmlNodePtr        root,
                                *status = XML_LABEL_UNKNOWN_MEDIA;
                                return NULL;
                        }
+                       gl_template_register (template);
                        gl_label_set_template (label, template);
                        gl_template_free (&template);
                } else if (xmlStrEqual (node->name, "Objects")) {
index 849a74b43f9de80be531ddd22267cbb1a10a05ec..16d6eb3c395446a06878cb6e0618639bd7cb3b1a 100644 (file)
@@ -329,9 +329,11 @@ xml_parse_label (xmlNodePtr        root,
                if (xmlStrEqual (child_node->name, "Template")) {
                        template = gl_xml_template_parse_template (child_node);
                        if (!template) {
+                               g_object_unref (label);
                                *status = XML_LABEL_UNKNOWN_MEDIA;
                                return NULL;
                        }
+                       gl_template_register (template);
                        gl_label_set_template (label, template);
                        gl_template_free (&template);
                } else if (xmlStrEqual (child_node->name, "Objects")) {
@@ -344,6 +346,9 @@ xml_parse_label (xmlNodePtr        root,
                        if (!xmlNodeIsText (child_node)) {
                                g_warning (_("bad node in Document node =  \"%s\""),
                                           child_node->name);
+                               g_object_unref (label);
+                               *status = XML_LABEL_ERROR_OPEN_PARSE;
+                               return NULL;
                        }
                }
        }