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. */
/*****************************************************************************/
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);
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. */
/*****************************************************************************/
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);
}
/*****************************************************************************/
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);
*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")) {
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")) {
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;
}
}
}