From: Jim Evins Date: Sat, 20 Oct 2007 22:02:40 +0000 (+0000) Subject: 2007-10-20 Jim Evins X-Git-Tag: glabels-2_3_0~317 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a068fff04513122c2b6c7d039aeb9987b19350e2;p=glabels 2007-10-20 Jim Evins * data/dtd/Makefile.am: * data/dtd/glabels-2.0.dtd: * data/dtd/glabels-2.2.dtd: Rename glabels-2.0.dtd to glabels-2.2.dtd. Added brand and part attributes to template node. * libglabels/template.c: * libglabels/template.h: * libglabels/xml-template.c: * libglabels/xml.h: Added brand and part attributes to template and alias structures and nodes. * src/file.c: * src/label.c: * src/mini-preview-pixbuf-cache.c: * src/template-designer.c: * src/wdgt-media-select.c: Use modified libglabels API. * docs/libglabels/libglabels-decl-list.txt: * docs/libglabels/libglabels-sections.txt: * docs/libglabels/libglabels-undocumented.txt: * docs/libglabels/tmpl/template-construction.sgml: * docs/libglabels/tmpl/template-db.sgml: * docs/libglabels/tmpl/template-struct.sgml: Update libglabels documentation to reflect above modifications. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@681 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 463a4912..31e0ba5f 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,29 @@ +2007-10-20 Jim Evins + + * data/dtd/Makefile.am: + * data/dtd/glabels-2.0.dtd: + * data/dtd/glabels-2.2.dtd: + Rename glabels-2.0.dtd to glabels-2.2.dtd. Added brand and part attributes to + template node. + * libglabels/template.c: + * libglabels/template.h: + * libglabels/xml-template.c: + * libglabels/xml.h: + Added brand and part attributes to template and alias structures and nodes. + * src/file.c: + * src/label.c: + * src/mini-preview-pixbuf-cache.c: + * src/template-designer.c: + * src/wdgt-media-select.c: + Use modified libglabels API. + * docs/libglabels/libglabels-decl-list.txt: + * docs/libglabels/libglabels-sections.txt: + * docs/libglabels/libglabels-undocumented.txt: + * docs/libglabels/tmpl/template-construction.sgml: + * docs/libglabels/tmpl/template-db.sgml: + * docs/libglabels/tmpl/template-struct.sgml: + Update libglabels documentation to reflect above modifications. + 2007-10-14 Jim Evins * docs/libglabels/libglabels-decl-list.txt: diff --git a/glabels2/data/dtd/Makefile.am b/glabels2/data/dtd/Makefile.am index d74bc6c3..0dce23d6 100644 --- a/glabels2/data/dtd/Makefile.am +++ b/glabels2/data/dtd/Makefile.am @@ -3,7 +3,7 @@ dtddir = $(datadir)/glabels/dtd dtd_DATA = \ - glabels-2.0.dtd + glabels-2.2.dtd EXTRA_DIST = $(dtd_DATA) diff --git a/glabels2/data/dtd/glabels-2.0.dtd b/glabels2/data/dtd/glabels-2.0.dtd deleted file mode 100644 index ad2f50a2..00000000 --- a/glabels2/data/dtd/glabels-2.0.dtd +++ /dev/null @@ -1,374 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/glabels2/data/dtd/glabels-2.2.dtd b/glabels2/data/dtd/glabels-2.2.dtd new file mode 100644 index 00000000..4565d812 --- /dev/null +++ b/glabels2/data/dtd/glabels-2.2.dtd @@ -0,0 +1,378 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/glabels2/docs/libglabels/libglabels-decl-list.txt b/glabels2/docs/libglabels/libglabels-decl-list.txt index 1cbc8701..6a9fd956 100644 --- a/glabels2/docs/libglabels/libglabels-decl-list.txt +++ b/glabels2/docs/libglabels/libglabels-decl-list.txt @@ -41,6 +41,7 @@ lglUnitsType
template lglTemplate +lglTemplateAlias lglTemplateFrameAll lglTemplateFrameRect lglTemplateFrameRound @@ -56,20 +57,26 @@ lglTemplateFrame lglTemplateMarkupType lglTemplateMarkup lgl_template_register +lgl_template_get_brand_list +lgl_template_free_brand_list lgl_template_get_name_list_unique lgl_template_get_name_list_all lgl_template_free_name_list lgl_template_from_name +lgl_template_get_name +lgl_template_do_templates_match +lgl_template_does_brand_match lgl_template_does_page_size_match lgl_template_does_category_match lgl_template_frame_get_size lgl_template_frame_get_n_labels lgl_template_frame_get_origins lgl_template_new +lgl_template_add_alias lgl_template_add_category lgl_template_add_frame -lgl_template_add_alias lgl_template_frame_rect_new +lgl_template_alias_new lgl_template_frame_round_new lgl_template_frame_cd_new lgl_template_frame_add_layout @@ -81,6 +88,8 @@ lgl_template_markup_circle_new lgl_template_markup_rect_new lgl_template_dup lgl_template_free +lgl_template_alias_dup +lgl_template_alias_free lgl_template_frame_dup lgl_template_frame_free lgl_template_layout_dup diff --git a/glabels2/docs/libglabels/libglabels-sections.txt b/glabels2/docs/libglabels/libglabels-sections.txt index d29ec3d6..bed47815 100644 --- a/glabels2/docs/libglabels/libglabels-sections.txt +++ b/glabels2/docs/libglabels/libglabels-sections.txt @@ -57,6 +57,8 @@ lgl_category_lookup_name_from_id template-struct libglabels/template.h lglTemplate + +lglTemplateAlias lglTemplateFrameShape lglTemplateFrame @@ -76,6 +78,9 @@ lglTemplateMarkupRect lglTemplateOrigin +lgl_template_get_name +lgl_template_do_templates_match +lgl_template_does_brand_match lgl_template_does_page_size_match lgl_template_does_category_match @@ -90,6 +95,8 @@ lgl_template_frame_get_origins lgl_template_get_name_list_unique lgl_template_get_name_list_all lgl_template_free_name_list +lgl_template_get_brand_list +lgl_template_free_brand_list lgl_template_from_name @@ -105,6 +112,10 @@ lgl_template_free lgl_template_add_category lgl_template_add_frame lgl_template_add_alias + +lgl_template_alias_new +lgl_template_alias_dup +lgl_template_alias_free lgl_template_frame_rect_new lgl_template_frame_round_new diff --git a/glabels2/docs/libglabels/libglabels-undocumented.txt b/glabels2/docs/libglabels/libglabels-undocumented.txt index 2b02c59e..e487606c 100644 --- a/glabels2/docs/libglabels/libglabels-undocumented.txt +++ b/glabels2/docs/libglabels/libglabels-undocumented.txt @@ -1,5 +1,5 @@ 99% symbol docs coverage. -130 symbols documented. +139 symbols documented. 0 symbols incomplete. 1 not documented. diff --git a/glabels2/docs/libglabels/tmpl/template-construction.sgml b/glabels2/docs/libglabels/tmpl/template-construction.sgml index 55da76bb..f486869a 100644 --- a/glabels2/docs/libglabels/tmpl/template-construction.sgml +++ b/glabels2/docs/libglabels/tmpl/template-construction.sgml @@ -22,7 +22,8 @@ This section describes a set of functions for constructing new template structur -@name: +@brand: +@part: @description: @page_size: @page_width: @@ -74,6 +75,33 @@ This section describes a set of functions for constructing new template structur @alias: + + + + + +@brand: +@part: +@Returns: + + + + + + + +@orig_alias: +@Returns: + + + + + + + +@alias: + + diff --git a/glabels2/docs/libglabels/tmpl/template-db.sgml b/glabels2/docs/libglabels/tmpl/template-db.sgml index 3241c832..81aa6941 100644 --- a/glabels2/docs/libglabels/tmpl/template-db.sgml +++ b/glabels2/docs/libglabels/tmpl/template-db.sgml @@ -23,6 +23,7 @@ to the LibGlabels template database. +@brand: @page_size: @category: @Returns: @@ -33,6 +34,7 @@ to the LibGlabels template database. +@brand: @page_size: @category: @Returns: @@ -46,6 +48,24 @@ to the LibGlabels template database. @names: + + + + + +@page_size: +@category: +@Returns: + + + + + + + +@brands: + + diff --git a/glabels2/docs/libglabels/tmpl/template-struct.sgml b/glabels2/docs/libglabels/tmpl/template-struct.sgml index 7aa46193..5357607e 100644 --- a/glabels2/docs/libglabels/tmpl/template-struct.sgml +++ b/glabels2/docs/libglabels/tmpl/template-struct.sgml @@ -24,16 +24,26 @@ This is the main structure of a libglabels template. A template represents a si of peel-off labels or cards. -@name: The primary name of the template. Usually a manufacturer followed by a part number. +@brand: Brand name of label or card. E.g. "Avery." +@part: Part name or number of label or card. E.g. "8160." @description: A description of the template. E.g. "Mailing labels." @page_size: A page size ID. E.g. "US-Letter" or "A4." @page_width: Page width in points. Used only if page_size is "Other." @page_height: Page height in points. Used only if page_size is "Other." +@aliases: A list of alternate names for this template. Often a single template can be used for +multiple products. @categories: A list of category IDs associated with this template. @frames: A list of (#lglTemplateFrame *) structures. GLabels currently only supports one frame per template -- future versions may support multiple frames per template. -@aliases: A list of alternate names for this template. Often a single template can be used for -multiple products. + + + +This structure defines an alias for the parent template structure. An alias is used for +different products that can use the same template. + + +@brand: Brand name of label or card. E.g. "Avery." +@part: Part name or number of label or card. E.g. "8160." @@ -191,6 +201,35 @@ relative to the upper left corner of the page. @x: Distance in points from top edge of page. @y: Distance in points from left edge of page. + + + + + +@template: +@Returns: + + + + + + + +@template1: +@template2: +@Returns: + + + + + + + +@template: +@brand: +@Returns: + + diff --git a/glabels2/libglabels/template.c b/glabels2/libglabels/template.c index 784fae9d..6de739a5 100644 --- a/glabels2/libglabels/template.c +++ b/glabels2/libglabels/template.c @@ -42,7 +42,7 @@ #include "xml-template.h" #include "paper.h" -#define FULL_PAGE "Full-page" +#define EQUAL(s1,s2) (!g_utf8_collate (s1, s2)) /*===========================================*/ /* Private types */ @@ -107,19 +107,23 @@ lgl_template_init (void) void lgl_template_register (const lglTemplate *template) { - GList *p_tmplt, *pa1; - lglTemplate *template1; + GList *p_tmplt1, *p_a1; + lglTemplate *template1; + lglTemplateAlias *alias1; if (!templates) { lgl_template_init (); } - for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template1 = (lglTemplate *) p_tmplt->data; + for (p_tmplt1 = templates; p_tmplt1 != NULL; p_tmplt1 = p_tmplt1->next) { + template1 = (lglTemplate *) p_tmplt1->data; - for (pa1=template1->aliases; pa1!=NULL; pa1=pa1->next) { - - if (g_utf8_collate (template->name, pa1->data) == 0) { + for (p_a1=template1->aliases; p_a1!=NULL; p_a1=p_a1->next) { + alias1 = (lglTemplateAlias *) p_a1->data; + + if ( EQUAL (template->brand, alias1->brand) && + EQUAL (template->part, alias1->part) ) + { /* FIXME: make sure templates are really identical */ /* if not, apply hash to name to make unique. */ @@ -140,7 +144,7 @@ lgl_template_register (const lglTemplate *template) /* FIXME: make sure filename is unique */ dir = LGL_USER_DATA_DIR; mkdir (dir, 0775); /* Try to make sure directory exists. */ - filename = g_strconcat (template->name, ".template", NULL); + filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); abs_filename = g_build_filename (dir, filename, NULL); lgl_xml_template_write_template_to_file (template, abs_filename); g_free (dir); @@ -153,8 +157,83 @@ lgl_template_register (const lglTemplate *template) } +/** + * lgl_template_get_brand_list: + * @page_size: If non NULL, limit results to given page size. + * @category: If non NULL, limit results to given template category. + * + * Get a list of all valid brands of templates in the template database. + * Results can be filtered by page size and/or template category. A list of valid page + * sizes can be obtained using lgl_paper_get_id_list(). A list of valid template + * categories can be obtained using lgl_category_get_id_list(). + * + * Returns: a list of brands + */ +GList * +lgl_template_get_brand_list (const gchar *page_size, + const gchar *category) +{ + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + GList *brands = NULL; + + if (!templates) + { + lgl_template_init (); + } + + for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + { + template = (lglTemplate *) p_tmplt->data; + if (lgl_template_does_page_size_match (template, page_size) && + lgl_template_does_category_match (template, category)) + { + for (p_alias = template->aliases; p_alias != NULL; + p_alias = p_alias->next) + { + alias = (lglTemplateAlias *)p_alias->data; + + if ( !g_list_find_custom (brands, alias->brand, + (GCompareFunc)g_utf8_collate) ) + { + brands = g_list_insert_sorted (brands, + g_strdup (alias->brand), + (GCompareFunc)g_utf8_collate); + } + } + } + } + + return brands; +} + +/** + * lgl_template_free_brand_list: + * @brands: List of template brand strings to be freed. + * + * Free up all storage associated with a list of template names obtained with + * lgl_template_get_brand_list(). + * + */ +void +lgl_template_free_brand_list (GList *brands) +{ + GList *p_brand; + + for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next) + { + g_free (p_brand->data); + p_brand->data = NULL; + } + + g_list_free (brands); +} + + /** * lgl_template_get_name_list_unique: + * @brand: If non NULL, limit results to given brand * @page_size: If non NULL, limit results to given page size. * @category: If non NULL, limit results to given template category. * @@ -169,11 +248,13 @@ lgl_template_register (const lglTemplate *template) * Returns: a list of template names. */ GList * -lgl_template_get_name_list_unique (const gchar *page_size, +lgl_template_get_name_list_unique (const gchar *brand, + const gchar *page_size, const gchar *category) { GList *p_tmplt; lglTemplate *template; + gchar *name; GList *names = NULL; if (!templates) @@ -184,12 +265,15 @@ lgl_template_get_name_list_unique (const gchar *page_size, for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { template = (lglTemplate *) p_tmplt->data; - if (lgl_template_does_page_size_match (template, page_size) && + + if (lgl_template_does_brand_match (template, brand) && + lgl_template_does_page_size_match (template, page_size) && lgl_template_does_category_match (template, category)) { - names = g_list_insert_sorted (names, g_strdup (template->name), + name = g_strdup_printf ("%s %s", template->brand, template->part); + names = g_list_insert_sorted (names, name, (GCompareFunc)g_utf8_collate); - } + } } return names; @@ -197,6 +281,7 @@ lgl_template_get_name_list_unique (const gchar *page_size, /** * lgl_template_get_name_list_all: + * @brand: If non NULL, limit results to given brand * @page_size: If non NULL, limit results to given page size. * @category: If non NULL, limit results to given template category. * @@ -211,13 +296,15 @@ lgl_template_get_name_list_unique (const gchar *page_size, * Returns: a list of template names and aliases. */ GList * -lgl_template_get_name_list_all (const gchar *page_size, +lgl_template_get_name_list_all (const gchar *brand, + const gchar *page_size, const gchar *category) { - GList *p_tmplt, *p_alias; - lglTemplate *template; - gchar *str; - GList *names = NULL; + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + gchar *name; + GList *names = NULL; if (!templates) { @@ -233,9 +320,14 @@ lgl_template_get_name_list_all (const gchar *page_size, for (p_alias = template->aliases; p_alias != NULL; p_alias = p_alias->next) { - str = g_strdup ((gchar *) p_alias->data); - names = g_list_insert_sorted (names, str, - (GCompareFunc)g_utf8_collate); + alias = (lglTemplateAlias *)p_alias->data; + + if ( !brand || EQUAL( alias->brand, brand) ) + { + name = g_strdup_printf ("%s %s", alias->brand, alias->part); + names = g_list_insert_sorted (names, name, + (GCompareFunc)g_utf8_collate); + } } } } @@ -243,6 +335,7 @@ lgl_template_get_name_list_all (const gchar *page_size, return names; } + /** * lgl_template_free_name_list: * @names: List of template name strings to be freed. @@ -256,7 +349,8 @@ lgl_template_free_name_list (GList *names) { GList *p_name; - for (p_name = names; p_name != NULL; p_name = p_name->next) { + for (p_name = names; p_name != NULL; p_name = p_name->next) + { g_free (p_name->data); p_name->data = NULL; } @@ -276,26 +370,35 @@ lgl_template_free_name_list (GList *names) lglTemplate * lgl_template_from_name (const gchar *name) { - GList *p_tmplt, *p_alias; - lglTemplate *template; + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + gchar *candidate_name; - if (!templates) { + if (!templates) + { lgl_template_init (); } - if (name == NULL) { + if (name == NULL) + { /* If no name, return first template as a default */ return lgl_template_dup ((lglTemplate *) templates->data); } - for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { + for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + { template = (lglTemplate *) p_tmplt->data; - for (p_alias = template->aliases; p_alias != NULL; - p_alias = p_alias->next) { - if (g_utf8_collate (p_alias->data, name) == 0) { + for (p_alias = template->aliases; p_alias != NULL; p_alias = p_alias->next) + { + alias = (lglTemplateAlias *)p_alias->data; + candidate_name = g_strdup_printf ("%s %s", alias->brand, alias->part); + if ( EQUAL (candidate_name, name) ) { + g_free (candidate_name); return lgl_template_dup (template); } + g_free (candidate_name); } } @@ -419,7 +522,8 @@ lgl_template_frame_get_origins (const lglTemplateFrame *frame) /** * lgl_template_new: - * @name: Template name + * @brand: Template brand + * @part: Template part name/number * @description: Template descriptions * @page_size: Page size id * @page_width: Page width in points, set to zero unless page_size="Other" @@ -434,17 +538,20 @@ lgl_template_frame_get_origins (const lglTemplateFrame *frame) * */ lglTemplate * -lgl_template_new (const gchar *name, +lgl_template_new (const gchar *brand, + const gchar *part, const gchar *description, const gchar *page_size, gdouble page_width, gdouble page_height) { - lglTemplate *template; + lglTemplate *template; + lglTemplateAlias *alias; template = g_new0 (lglTemplate,1); - template->name = g_strdup (name); + template->brand = g_strdup (brand); + template->part = g_strdup (part); template->description = g_strdup (description); template->page_size = g_strdup (page_size); template->page_width = page_width; @@ -452,11 +559,77 @@ lgl_template_new (const gchar *name, /* Always include primary name in alias list. */ template->aliases = NULL; - template->aliases = g_list_append (template->aliases, g_strdup (name)); + alias = lgl_template_alias_new (brand, part); + lgl_template_add_alias (template, alias); return template; } +/** + * lgl_template_get_name: + * @template: Pointer to template structure to test + * + * This function returns the name of the given template. The name is the concetenation + * of the brand and part name/number. + * + * Returns: A pointer to a newly allocated name string. Should be freed with g_free(). + * + */ +gchar * +lgl_template_get_name (const lglTemplate *template) +{ + g_return_val_if_fail (template, NULL); + + return g_strdup_printf ("%s %s", template->brand, template->part); +} + +/** + * lgl_template_do_templates_match: + * @template1: Pointer to 1st template structure to test + * @template2: Pointer to 2nd template structure to test + * + * This function tests if the given templates match. This is a simple test that only tests + * the brand and part name/number. It does not test if they are actually identical. + * + * Returns: TRUE if the two template matche. + * + */ +gboolean +lgl_template_do_templates_match (const lglTemplate *template1, + const lglTemplate *template2) +{ + g_return_val_if_fail (template1, FALSE); + g_return_val_if_fail (template2, FALSE); + + return (EQUAL (template1->brand, template2->brand) && + EQUAL (template1->part, template2->part)); +} + +/** + * lgl_template_does_brand_match: + * @template: Pointer to template structure to test + * @brand: Brand string + * + * This function tests if the brand of the template matches the given brand. + * + * Returns: TRUE if the template matches the given brand. + * + */ +gboolean +lgl_template_does_brand_match (const lglTemplate *template, + const gchar *brand) +{ + g_return_val_if_fail (template, FALSE); + + /* NULL matches everything. */ + if (brand == NULL) + { + return TRUE; + } + + return EQUAL (template->brand, brand); +} + /** * lgl_template_does_page_size_match: * @template: Pointer to template structure to test @@ -517,6 +690,48 @@ lgl_template_does_category_match (const lglTemplate *template, return FALSE; } +/** + * lgl_template_alias_new: + * @brand: Alias brand + * @part: Alias part name/number + * + * Create a new template alias structure, with the given brand and part number. + * + * Returns: pointer to a newly allocated #lglTemplateAlias structure. + * + */ +lglTemplateAlias * +lgl_template_alias_new (const gchar *brand, + const gchar *part) +{ + lglTemplateAlias *alias; + + alias = g_new0 (lglTemplateAlias,1); + + alias->brand = g_strdup (brand); + alias->part = g_strdup (part); + + return alias; +} + +/** + * lgl_template_add_alias: + * @template: Pointer to template structure + * @alias: Alias string + * + * This function adds the given alias to a templates list of aliases. + * + */ +void +lgl_template_add_alias (lglTemplate *template, + lglTemplateAlias *alias) +{ + g_return_if_fail (template); + g_return_if_fail (alias); + + template->aliases = g_list_append (template->aliases, alias); +} + /** * lgl_template_add_frame: * @template: Pointer to template structure @@ -558,25 +773,6 @@ lgl_template_add_category (lglTemplate *template, g_strdup (category)); } -/** - * lgl_template_add_alias: - * @template: Pointer to template structure - * @alias: Alias string - * - * This function adds the given alias to a templates list of aliases. - * - */ -void -lgl_template_add_alias (lglTemplate *template, - const gchar *alias) -{ - g_return_if_fail (template); - g_return_if_fail (alias); - - template->aliases = g_list_append (template->aliases, - g_strdup (alias)); -} - /** * lgl_template_frame_rect_new: * @id: ID of frame. (This should currently always be "0"). @@ -883,38 +1079,43 @@ lglTemplate * lgl_template_dup (const lglTemplate *orig_template) { lglTemplate *template; + lglTemplateAlias *alias; GList *p; lglTemplateFrame *frame; g_return_val_if_fail (orig_template, NULL); - template = lgl_template_new (orig_template->name, + template = lgl_template_new (orig_template->brand, + orig_template->part, orig_template->description, orig_template->page_size, orig_template->page_width, orig_template->page_height); - for ( p=orig_template->categories; p != NULL; p=p->next ) { + for ( p=orig_template->aliases; p != NULL; p=p->next ) + { + alias = (lglTemplateAlias *)p->data; - lgl_template_add_category (template, p->data); + if ( !(EQUAL (template->brand, alias->brand) && + EQUAL (template->part, alias->part)) ) + { + lgl_template_add_alias (template, lgl_template_alias_dup (alias)); + } } - for ( p=orig_template->frames; p != NULL; p=p->next ) { + for ( p=orig_template->categories; p != NULL; p=p->next ) + { + lgl_template_add_category (template, p->data); + } + for ( p=orig_template->frames; p != NULL; p=p->next ) + { frame = (lglTemplateFrame *)p->data; lgl_template_add_frame (template, lgl_template_frame_dup (frame)); } - for ( p=orig_template->aliases; p != NULL; p=p->next ) { - - if (g_utf8_collate (template->name, p->data) != 0) { - lgl_template_add_alias (template, p->data); - } - - } - return template; } @@ -933,8 +1134,11 @@ lgl_template_free (lglTemplate *template) if ( template != NULL ) { - g_free (template->name); - template->name = NULL; + g_free (template->brand); + template->brand = NULL; + + g_free (template->part); + template->part = NULL; g_free (template->description); template->description = NULL; @@ -942,6 +1146,15 @@ lgl_template_free (lglTemplate *template) g_free (template->page_size); template->page_size = NULL; + for ( p=template->aliases; p != NULL; p=p->next ) { + + lgl_template_alias_free (p->data); + p->data = NULL; + + } + g_list_free (template->aliases); + template->aliases = NULL; + for ( p=template->categories; p != NULL; p=p->next ) { g_free (p->data); @@ -961,19 +1174,50 @@ lgl_template_free (lglTemplate *template) g_list_free (template->frames); template->frames = NULL; - for ( p=template->aliases; p != NULL; p=p->next ) { + g_free (template); - g_free (p->data); - p->data = NULL; + } - } - g_list_free (template->aliases); - template->aliases = NULL; +} - g_free (template); +/** + * lgl_template_alias_dup: + * @orig_alias: Alias to duplicate. + * + * This function duplicates a template alias structure. + * + * Returns: a newly allocated #lglTemplateAlias structure. + * + */ +lglTemplateAlias * +lgl_template_alias_dup (const lglTemplateAlias *orig_alias) +{ + g_return_val_if_fail (orig_alias, NULL); - } + return lgl_template_alias_new (orig_alias->brand, orig_alias->part); +} + +/** + * lgl_template_alias_free: + * @alias: Alias to free. + * + * This function frees all memory associated with given template alias structure. + * + */ +void +lgl_template_alias_free (lglTemplateAlias *alias) +{ + + if ( alias != NULL ) + { + g_free (alias->brand); + alias->brand = NULL; + + g_free (alias->part); + alias->part = NULL; + g_free (alias); + } } /** @@ -1173,7 +1417,8 @@ template_full_page (const gchar *page_size) lglPaper *paper = NULL; lglTemplate *template = NULL; lglTemplateFrame *frame = NULL; - gchar *name; + gchar *part; + gchar *desc; g_return_val_if_fail (page_size, NULL); @@ -1182,13 +1427,11 @@ template_full_page (const gchar *page_size) return NULL; } - name = g_strdup_printf (_("Generic %s full page"), page_size); + part = g_strdup_printf ("%s-Full-Page", paper->id); + desc = g_strdup_printf (_("Generic %s full page template"), paper->name); - template = lgl_template_new (name, - FULL_PAGE, - page_size, - paper->width, - paper->height); + template = lgl_template_new ("Generic", part, desc, + page_size, paper->width, paper->height); frame = lgl_template_frame_rect_new ("0", @@ -1203,8 +1446,8 @@ template_full_page (const gchar *page_size) lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0)); - g_free (name); - name = NULL; + g_free (desc); + desc = NULL; lgl_paper_free (paper); paper = NULL; @@ -1323,11 +1566,12 @@ lgl_template_print_known_templates (void) lglTemplate *template; g_print ("%s():\n", __FUNCTION__); - for (p=templates; p!=NULL; p=p->next) { + for (p=templates; p!=NULL; p=p->next) + { template = (lglTemplate *)p->data; - g_print("TEMPLATE name=\"%s\", description=\"%s\"\n", - template->name, template->description); + g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n", + template->brand, template->part, template->description); } g_print ("\n"); @@ -1344,12 +1588,15 @@ lgl_template_print_known_templates (void) void lgl_template_print_aliases (const lglTemplate *template) { - GList *p; + GList *p; + lglTemplateAlias *alias; g_print ("%s():\n", __FUNCTION__); - for (p=template->aliases; p!=NULL; p=p->next) { + for (p=template->aliases; p!=NULL; p=p->next) + { + alias = (lglTemplateAlias *)p->data; - g_print("Alias = \"%s\"\n", (gchar *)p->data); + g_print("Alias: brand=\"%s\", part=\"%s\"\n", alias->brand, alias->part); } g_print ("\n"); diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h index 72767002..ebc44af6 100644 --- a/glabels2/libglabels/template.h +++ b/glabels2/libglabels/template.h @@ -35,6 +35,8 @@ G_BEGIN_DECLS typedef struct _lglTemplate lglTemplate; +typedef struct _lglTemplateAlias lglTemplateAlias; + typedef union _lglTemplateFrame lglTemplateFrame; typedef struct _lglTemplateFrameAll lglTemplateFrameAll; typedef struct _lglTemplateFrameRect lglTemplateFrameRect; @@ -56,12 +58,16 @@ typedef struct _lglTemplateOrigin lglTemplateOrigin; */ struct _lglTemplate { - gchar *name; + gchar *brand; + gchar *part; gchar *description; gchar *page_size; gdouble page_width; gdouble page_height; + /* List of (lglTemplateAlias *) aliase structures. */ + GList *aliases; + /* List of (gchar *) category ids. */ GList *categories; @@ -70,12 +76,19 @@ struct _lglTemplate { * template. */ GList *frames; - /* List of (gchar *) aliases. */ - GList *aliases; - }; +/* + * Top-level Template Structure + */ +struct _lglTemplateAlias { + + gchar *brand; + gchar *part; + +}; + /* * Possible Frame Shapes */ @@ -253,10 +266,17 @@ void lgl_template_register (const lglTemplate *t /* * Known templates query functions */ -GList *lgl_template_get_name_list_unique (const gchar *page_size, +GList *lgl_template_get_brand_list (const gchar *page_size, const gchar *category); -GList *lgl_template_get_name_list_all (const gchar *page_size, +void lgl_template_free_brand_list (GList *brands); + +GList *lgl_template_get_name_list_unique (const gchar *brand, + const gchar *page_size, + const gchar *category); + +GList *lgl_template_get_name_list_all (const gchar *brand, + const gchar *page_size, const gchar *category); void lgl_template_free_name_list (GList *names); @@ -267,6 +287,14 @@ lglTemplate *lgl_template_from_name (const gchar *nam /* * Template query functions */ +gchar *lgl_template_get_name (const lglTemplate *template); + +gboolean lgl_template_do_templates_match (const lglTemplate *template1, + const lglTemplate *template2); + +gboolean lgl_template_does_brand_match (const lglTemplate *template, + const gchar *brand); + gboolean lgl_template_does_page_size_match (const lglTemplate *template, const gchar *page_size); @@ -289,21 +317,22 @@ lglTemplateOrigin *lgl_template_frame_get_origins (const lglTemplateFrame /* * Template Construction */ -lglTemplate *lgl_template_new (const gchar *name, +lglTemplate *lgl_template_new (const gchar *brand, + const gchar *part, const gchar *description, const gchar *page_size, gdouble page_width, gdouble page_height); +void lgl_template_add_alias (lglTemplate *template, + lglTemplateAlias *alias); + void lgl_template_add_category (lglTemplate *template, const gchar *category); void lgl_template_add_frame (lglTemplate *template, lglTemplateFrame *frame); -void lgl_template_add_alias (lglTemplate *template, - const gchar *alias); - lglTemplateFrame *lgl_template_frame_rect_new (const gchar *id, gdouble w, gdouble h, @@ -311,6 +340,9 @@ lglTemplateFrame *lgl_template_frame_rect_new (const gchar *id gdouble x_waste, gdouble y_waste); +lglTemplateAlias *lgl_template_alias_new (const gchar *brand, + const gchar *part); + lglTemplateFrame *lgl_template_frame_round_new (const gchar *id, gdouble r, gdouble waste); @@ -356,6 +388,9 @@ lglTemplate *lgl_template_dup (const lglTemplate *or void lgl_template_free (lglTemplate *template); +lglTemplateAlias *lgl_template_alias_dup (const lglTemplateAlias *orig_alias); +void lgl_template_alias_free (lglTemplateAlias *alias); + lglTemplateFrame *lgl_template_frame_dup (const lglTemplateFrame *orig_frame); void lgl_template_frame_free (lglTemplateFrame *frame); diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c index 3ce41222..bcb0ffe9 100644 --- a/glabels2/libglabels/xml-template.c +++ b/glabels2/libglabels/xml-template.c @@ -91,7 +91,7 @@ static void xml_create_markup_circle_node (const lglTemplateMarkup *circl static void xml_create_markup_rect_node (const lglTemplateMarkup *circle, xmlNodePtr root, const xmlNsPtr ns); -static void xml_create_alias_node (const gchar *name, +static void xml_create_alias_node (const lglTemplateAlias *alias, xmlNodePtr root, const xmlNsPtr ns); @@ -197,6 +197,8 @@ lgl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) lglTemplate * lgl_xml_template_parse_template_node (const xmlNodePtr template_node) { + gchar *brand; + gchar *part; gchar *name; gchar *description; gchar *page_size; @@ -204,8 +206,29 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) lglPaper *paper = NULL; lglTemplate *template; xmlNodePtr node; + gchar **v; + + brand = lgl_xml_get_prop_string (template_node, "brand", NULL); + part = lgl_xml_get_prop_string (template_node, "part", NULL); + if (!brand || !part) + { + name = lgl_xml_get_prop_string (template_node, "name", NULL); + if (name) + { + g_message (_("Missing required \"brand\" or \"part\" attribute, trying deprecated name.")); + v = g_strsplit (name, " ", 2); + brand = g_strdup (v[0]); + part = g_strdup (v[1]); + g_free (name); + g_strfreev (v); + + } + else + { + g_message (_("Name attribute also missing.")); + } + } - name = lgl_xml_get_prop_string (template_node, "name", NULL); description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL); page_size = lgl_xml_get_prop_string (template_node, "size", NULL); @@ -236,10 +259,8 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) paper = NULL; } - template = lgl_template_new (name, - description, - page_size, - page_width, page_height); + template = lgl_template_new (brand, part, description, + page_size, page_width, page_height); for (node = template_node->xmlChildrenNode; node != NULL; node = node->next) { @@ -262,7 +283,8 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) } } - g_free (name); + g_free (brand); + g_free (part); g_free (description); g_free (page_size); @@ -577,13 +599,37 @@ static void xml_parse_alias_node (xmlNodePtr alias_node, lglTemplate *template) { - gchar *name; - - name = lgl_xml_get_prop_string (alias_node, "name", NULL); - - lgl_template_add_alias (template, (gchar *)name); - - g_free (name); + gchar *brand; + gchar *part; + gchar *name; + gchar **v; + lglTemplateAlias *alias; + + brand = lgl_xml_get_prop_string (alias_node, "brand", NULL); + part = lgl_xml_get_prop_string (alias_node, "part", NULL); + if (!brand || !part) + { + name = lgl_xml_get_prop_string (alias_node, "name", NULL); + if (name) + { + g_message (_("Missing required \"brand\" or \"part\" attribute, trying deprecated name.")); + v = g_strsplit (name, " ", 2); + brand = g_strdup (v[0]); + part = g_strdup (v[1]); + g_free (name); + g_strfreev (v); + + } + else + { + g_message (_("Name attribute also missing.")); + } + } + + lgl_template_add_alias (template, lgl_template_alias_new (brand, part)); + + g_free (brand); + g_free (part); } /** @@ -672,14 +718,17 @@ lgl_xml_template_create_template_node (const lglTemplate *template, { xmlNodePtr node; GList *p; + lglTemplateAlias *alias; lglTemplateFrame *frame; node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL); - lgl_xml_set_prop_string (node, "name", template->name); + lgl_xml_set_prop_string (node, "brand", template->part); + lgl_xml_set_prop_string (node, "part", template->part); lgl_xml_set_prop_string (node, "size", template->page_size); - if (xmlStrEqual ((xmlChar *)template->page_size, (xmlChar *)"Other")) { + if (xmlStrEqual ((xmlChar *)template->page_size, (xmlChar *)"Other")) + { lgl_xml_set_prop_length (node, "width", template->page_width); lgl_xml_set_prop_length (node, "height", template->page_height); @@ -688,20 +737,24 @@ lgl_xml_template_create_template_node (const lglTemplate *template, lgl_xml_set_prop_string (node, "description", template->description); - for ( p=template->categories; p != NULL; p=p->next ) { + for ( p=template->aliases; p != NULL; p=p->next ) { + alias = (lglTemplateAlias *)p->data; + if ( !(xmlStrEqual ((xmlChar *)template->brand, (xmlChar *)alias->brand) && + xmlStrEqual ((xmlChar *)template->part, (xmlChar *)alias->part)) ) + { + xml_create_alias_node ( alias, node, ns ); + } + } + for ( p=template->categories; p != NULL; p=p->next ) + { xml_create_meta_node ( p->data, node, ns ); } - for ( p=template->frames; p != NULL; p=p->next ) { + for ( p=template->frames; p != NULL; p=p->next ) + { frame = (lglTemplateFrame *)p->data; xml_create_label_node (frame, node, ns); } - for ( p=template->aliases; p != NULL; p=p->next ) { - if (!xmlStrEqual ((xmlChar *)template->name, (xmlChar *)p->data)) { - xml_create_alias_node ( p->data, node, ns ); - } - } - } /*--------------------------------------------------------------------------*/ @@ -897,14 +950,16 @@ xml_create_markup_rect_node (const lglTemplateMarkup *markup, /* PRIVATE. Add XML Template->Alias Node. */ /*--------------------------------------------------------------------------*/ static void -xml_create_alias_node (const gchar *name, - xmlNodePtr root, - const xmlNsPtr ns) +xml_create_alias_node (const lglTemplateAlias *alias, + xmlNodePtr root, + const xmlNsPtr ns) { xmlNodePtr node; node = xmlNewChild (root, ns, (xmlChar *)"Alias", NULL); - lgl_xml_set_prop_string (node, "name", name); + + lgl_xml_set_prop_string (node, "brand", alias->brand); + lgl_xml_set_prop_string (node, "part", alias->part); } diff --git a/glabels2/libglabels/xml.h b/glabels2/libglabels/xml.h index 3bfd01a4..3ef2e495 100644 --- a/glabels2/libglabels/xml.h +++ b/glabels2/libglabels/xml.h @@ -31,7 +31,7 @@ #include "enums.h" -#define LGL_XML_NAME_SPACE "http://snaught.com/glabels/2.0/" +#define LGL_XML_NAME_SPACE "http://snaught.com/glabels/2.2/" G_BEGIN_DECLS diff --git a/glabels2/src/file.c b/glabels2/src/file.c index 65adec7d..d1f20243 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -179,6 +179,7 @@ gl_file_properties (glLabel *label, glWindow *window) { GtkWidget *dialog; + gchar *name; gl_debug (DEBUG_FILE, "START"); @@ -198,10 +199,12 @@ gl_file_properties (glLabel *label, label->template->page_size, NULL); } - if (label->template->name != NULL) { - gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog), - label->template->name); + name = lgl_template_get_name (label->template); + if (name != NULL) { + gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog), name); } + g_free (name); + gl_new_label_dialog_set_rotate_state (GL_NEW_LABEL_DIALOG (dialog), label->rotate_flag); diff --git a/glabels2/src/label.c b/glabels2/src/label.c index 555268e0..a68bb43c 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -380,9 +380,10 @@ gl_label_set_template (glLabel *label, gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (label && GL_IS_LABEL (label)); + g_return_if_fail (template); if ((label->template == NULL) || - (g_strcasecmp (template->name, label->template->name) != 0)) { + !lgl_template_do_templates_match (template, label->template)) { lgl_template_free (label->template); label->template = lgl_template_dup (template); diff --git a/glabels2/src/mini-preview-pixbuf-cache.c b/glabels2/src/mini-preview-pixbuf-cache.c index a260e3d8..cdcca3ba 100644 --- a/glabels2/src/mini-preview-pixbuf-cache.c +++ b/glabels2/src/mini-preview-pixbuf-cache.c @@ -59,9 +59,10 @@ gl_mini_preview_pixbuf_cache_init (void) mini_preview_pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal); - names = lgl_template_get_name_list_unique (NULL, NULL); + names = lgl_template_get_name_list_unique (NULL, NULL, NULL); for ( p=names; p != NULL; p=p->next ) { + gl_debug (DEBUG_PIXBUF_CACHE, "name = \"%s\"", p->data); gl_mini_preview_pixbuf_cache_add_by_name ((gchar *)p->data); } lgl_template_free_name_list (names); diff --git a/glabels2/src/template-designer.c b/glabels2/src/template-designer.c index a4b3bb04..26d25439 100644 --- a/glabels2/src/template-designer.c +++ b/glabels2/src/template-designer.c @@ -1112,10 +1112,13 @@ static void apply_cb (glTemplateDesigner *dialog) { lglTemplate *template; + gchar *name; template = build_template (dialog); lgl_template_register (template); - gl_mini_preview_pixbuf_cache_add_by_name (template->name); + name = lgl_template_get_name (template); + gl_mini_preview_pixbuf_cache_add_by_name (name); + g_free (name); } /*--------------------------------------------------------------------------*/ @@ -1599,7 +1602,7 @@ static lglTemplate * build_template (glTemplateDesigner *dialog) { gdouble upp; - gchar *brand, *part_num, *name, *desc; + gchar *brand, *part_num, *desc; gchar *page_size_name; lglPaper *paper; lglTemplateFrameShape shape; @@ -1614,7 +1617,6 @@ build_template (glTemplateDesigner *dialog) brand = gtk_editable_get_chars (GTK_EDITABLE(dialog->priv->brand_entry), 0, -1); part_num = gtk_editable_get_chars (GTK_EDITABLE(dialog->priv->part_num_entry), 0, -1); - name = g_strdup_printf ("%s %s", brand, part_num); desc = gtk_editable_get_chars (GTK_EDITABLE(dialog->priv->description_entry), 0, -1); page_size_name = @@ -1671,7 +1673,7 @@ build_template (glTemplateDesigner *dialog) dy_2 = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->layout2_dy_spin)); - template = lgl_template_new (name, desc, paper->id, paper->width, paper->height); + template = lgl_template_new (brand, part_num, desc, paper->id, paper->width, paper->height); switch (shape) { case LGL_TEMPLATE_FRAME_SHAPE_RECT: @@ -1711,7 +1713,6 @@ build_template (glTemplateDesigner *dialog) g_free (brand); g_free (part_num); - g_free (name); g_free (desc); g_free (page_size_name); diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index dd5c47b9..d453de9c 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -260,7 +260,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 = lgl_template_get_name_list_all (page_size_id, NULL); + template_names = lgl_template_get_name_list_all (NULL, page_size_id, NULL); load_list (media_select->priv->template_store, selection, template_names); lgl_template_free_name_list (template_names); @@ -310,7 +310,7 @@ filter_changed_cb (GtkComboBox *combo, category_id = lgl_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 = lgl_template_get_name_list_all (page_size_id, category_id); + template_names = lgl_template_get_name_list_all (NULL, page_size_id, category_id); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (media_select->priv->template_treeview)); load_list (media_select->priv->template_store, selection, template_names); lgl_template_free_name_list (template_names); @@ -587,6 +587,7 @@ load_list (GtkListStore *store, gchar *size; gchar *layout; gchar *description; + gchar *name; gl_debug (DEBUG_MEDIA_SELECT, "START"); @@ -601,8 +602,10 @@ load_list (GtkListStore *store, gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data); template = lgl_template_from_name (p->data); - - pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (template->name); + + name = lgl_template_get_name (template); + pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (name); + g_free (name); size = get_label_size_desc (template); layout = get_layout_desc (template);