From: Jim Evins Date: Sun, 18 Nov 2007 05:06:41 +0000 (+0000) Subject: 2007-11-18 Jim Evins X-Git-Tag: glabels-2_3_0~308 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8afdc497ab84d6fb788e9822a15c24320d686fbe;p=glabels 2007-11-18 Jim Evins * libglabels/db.c: (lgl_db_register_template), (read_templates): When registering a new template, don't add to "User defined" category before writing to file. Add to "User defined" category when reading from "~/.glabels" directory instead. This will allow legacy templates (and manually created templates) to be automatically added to the "user defined" category. * libglabels/xml-template.c: (lgl_xml_template_create_template_node): Fixed typo/bug causing brand to be wrong. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@690 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index b0f0df18..cd93db28 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,14 @@ +2007-11-18 Jim Evins + + * libglabels/db.c: (lgl_db_register_template), (read_templates): + When registering a new template, don't add to "User defined" category before + writing to file. Add to "User defined" category when reading from "~/.glabels" + directory instead. This will allow legacy templates (and manually created + templates) to be automatically added to the "user defined" category. + * libglabels/xml-template.c: + (lgl_xml_template_create_template_node): + Fixed typo/bug causing brand to be wrong. + 2007-11-16 Jim Evins * libglabels/db.c: diff --git a/glabels2/libglabels/db.c b/glabels2/libglabels/db.c index c38294ea..8e4f1924 100644 --- a/glabels2/libglabels/db.c +++ b/glabels2/libglabels/db.c @@ -1069,20 +1069,19 @@ lgl_db_register_template (const lglTemplate *template) if (lgl_db_is_paper_id_known (template->paper_id)) { - template_copy = lgl_template_dup (template); - lgl_template_add_category (template_copy, "user-defined"); - dir = LGL_USER_DATA_DIR; mkdir (dir, 0775); /* Try to make sure directory exists. */ filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); abs_filename = g_build_filename (dir, filename, NULL); - bytes_written = lgl_xml_template_write_template_to_file (template_copy, abs_filename); + bytes_written = lgl_xml_template_write_template_to_file (template, abs_filename); g_free (dir); g_free (filename); g_free (abs_filename); if (bytes_written > 0) { + template_copy = lgl_template_dup (template); + lgl_template_add_category (template_copy, "user-defined"); templates = g_list_append (templates, template_copy); return LGL_DB_REG_OK; } @@ -1328,14 +1327,27 @@ lgl_db_lookup_template_from_name (const gchar *name) static GList * read_templates (void) { - gchar *data_dir; - GList *templates = NULL; + gchar *data_dir; + GList *templates = NULL; + GList *p; + lglTemplate *template; - data_dir = LGL_SYSTEM_DATA_DIR; + /* + * User defined templates. Add to user-defined category. + */ + data_dir = LGL_USER_DATA_DIR; templates = read_template_files_from_dir (templates, data_dir); g_free (data_dir); + for ( p=templates; p != NULL; p=p->next ) + { + template = (lglTemplate *)p->data; + lgl_template_add_category (template, "user-defined"); + } - data_dir = LGL_USER_DATA_DIR; + /* + * System templates. + */ + data_dir = LGL_SYSTEM_DATA_DIR; templates = read_template_files_from_dir (templates, data_dir); g_free (data_dir); diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c index 8d83a577..e4442bec 100644 --- a/glabels2/libglabels/xml-template.c +++ b/glabels2/libglabels/xml-template.c @@ -728,7 +728,7 @@ lgl_xml_template_create_template_node (const lglTemplate *template, node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL); - lgl_xml_set_prop_string (node, "brand", template->part); + lgl_xml_set_prop_string (node, "brand", template->brand); lgl_xml_set_prop_string (node, "part", template->part); lgl_xml_set_prop_string (node, "size", template->paper_id);