From: Jim Evins Date: Sat, 27 Oct 2007 01:45:25 +0000 (+0000) Subject: 2007-10-26 Jim Evins X-Git-Tag: glabels-2_3_0~311 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c4087c54cb13e22815a28921fdcc214b0b5c122c;p=glabels 2007-10-26 Jim Evins * libglabels/Makefile.am: * libglabels/category.c: * libglabels/category.h: * libglabels/db.c: * libglabels/db.h: * libglabels/libglabels-private.h: * libglabels/libglabels.h: * libglabels/paper.c: * libglabels/paper.h: * libglabels/template.c: * libglabels/template.h: * libglabels/xml-template.c: Another pass at screwing with the libglabels API. Moved all database related stuff to db.[ch]. * docs/libglabels/libglabels-decl-list.txt: * docs/libglabels/libglabels-docs.sgml: * docs/libglabels/libglabels-sections.txt: * docs/libglabels/libglabels-undocumented.txt: * docs/libglabels/tmpl/category.sgml: * docs/libglabels/tmpl/db.sgml: * docs/libglabels/tmpl/init.sgml: * docs/libglabels/tmpl/libglabels-unused.sgml: * docs/libglabels/tmpl/paper.sgml: * docs/libglabels/tmpl/template-construction.sgml: * docs/libglabels/tmpl/template-db.sgml: * docs/libglabels/tmpl/template-misc.sgml: * docs/libglabels/tmpl/template-struct.sgml: * docs/libglabels/tmpl/template.sgml: Updated documentation to reflect above changes to libglabels API. * src/file.c: * src/glabels-batch.c: * src/glabels.c: * src/mini-preview-pixbuf-cache.c: * src/prefs-model.c: * src/print.c: * src/template-designer.c: * src/wdgt-media-select.c: * src/wdgt-mini-preview.c: * src/wdgt-rotate-label.c: * src/xml-label-04.c: * src/xml-label.c: Reconciled usage with above libglabels API changes. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@687 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 671864f0..10d816f5 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,48 @@ +2007-10-26 Jim Evins + + * libglabels/Makefile.am: + * libglabels/category.c: + * libglabels/category.h: + * libglabels/db.c: + * libglabels/db.h: + * libglabels/libglabels-private.h: + * libglabels/libglabels.h: + * libglabels/paper.c: + * libglabels/paper.h: + * libglabels/template.c: + * libglabels/template.h: + * libglabels/xml-template.c: + Another pass at screwing with the libglabels API. Moved all + database related stuff to db.[ch]. + * docs/libglabels/libglabels-decl-list.txt: + * docs/libglabels/libglabels-docs.sgml: + * docs/libglabels/libglabels-sections.txt: + * docs/libglabels/libglabels-undocumented.txt: + * docs/libglabels/tmpl/category.sgml: + * docs/libglabels/tmpl/db.sgml: + * docs/libglabels/tmpl/init.sgml: + * docs/libglabels/tmpl/libglabels-unused.sgml: + * docs/libglabels/tmpl/paper.sgml: + * docs/libglabels/tmpl/template-construction.sgml: + * docs/libglabels/tmpl/template-db.sgml: + * docs/libglabels/tmpl/template-misc.sgml: + * docs/libglabels/tmpl/template-struct.sgml: + * docs/libglabels/tmpl/template.sgml: + Updated documentation to reflect above changes to libglabels API. + * src/file.c: + * src/glabels-batch.c: + * src/glabels.c: + * src/mini-preview-pixbuf-cache.c: + * src/prefs-model.c: + * src/print.c: + * src/template-designer.c: + * src/wdgt-media-select.c: + * src/wdgt-mini-preview.c: + * src/wdgt-rotate-label.c: + * src/xml-label-04.c: + * src/xml-label.c: + Reconciled usage with above libglabels API changes. + 2007-10-21 Jim Evins * data/glade/wdgt-media-select.glade: diff --git a/glabels2/docs/libglabels/libglabels-decl-list.txt b/glabels2/docs/libglabels/libglabels-decl-list.txt index 6a9fd956..fc9e697b 100644 --- a/glabels2/docs/libglabels/libglabels-decl-list.txt +++ b/glabels2/docs/libglabels/libglabels-decl-list.txt @@ -1,3 +1,38 @@ +
+db +lgl_db_init +lgl_db_get_paper_id_list +lgl_db_free_paper_id_list +lgl_db_get_paper_name_list +lgl_db_free_paper_name_list +lgl_db_lookup_paper_from_name +lgl_db_lookup_paper_from_id +lgl_db_lookup_paper_id_from_name +lgl_db_lookup_paper_name_from_id +lgl_db_is_paper_id_known +lgl_db_is_paper_id_other +lgl_db_get_category_id_list +lgl_db_free_category_id_list +lgl_db_get_category_name_list +lgl_db_free_category_name_list +lgl_db_lookup_category_from_name +lgl_db_lookup_category_from_id +lgl_db_lookup_category_id_from_name +lgl_db_lookup_category_name_from_id +lgl_db_is_category_id_known +lgl_db_get_brand_list +lgl_db_free_brand_list +lgl_db_register_template +lgl_db_get_template_name_list_unique +lgl_db_get_template_name_list_all +lgl_db_free_template_name_list +lgl_db_lookup_template_from_name +lgl_db_print_known_papers +lgl_db_print_known_categories +lgl_db_print_known_templates +lgl_db_print_aliases +
+
xml LGL_XML_NAME_SPACE @@ -56,13 +91,6 @@ lglTemplateFrameShape 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 @@ -96,8 +124,6 @@ lgl_template_layout_dup lgl_template_layout_free lgl_template_markup_dup lgl_template_markup_free -lgl_template_print_known_templates -lgl_template_print_aliases
@@ -114,25 +140,12 @@ lgl_xml_category_parse_categories_doc lgl_xml_category_parse_category_node
-
-init -lgl_init -
-
category lglCategory lgl_category_new lgl_category_dup lgl_category_free -lgl_category_get_id_list -lgl_category_free_id_list -lgl_category_get_name_list -lgl_category_free_name_list -lgl_category_from_name -lgl_category_from_id -lgl_category_lookup_id_from_name -lgl_category_lookup_name_from_id
@@ -141,16 +154,5 @@ lglPaper lgl_paper_new lgl_paper_dup lgl_paper_free -lgl_paper_get_id_list -lgl_paper_free_id_list -lgl_paper_get_name_list -lgl_paper_free_name_list -lgl_paper_is_id_known -lgl_paper_is_id_other -lgl_paper_from_id -lgl_paper_from_name -lgl_paper_lookup_id_from_name -lgl_paper_lookup_name_from_id -lgl_paper_print_known_papers
diff --git a/glabels2/docs/libglabels/libglabels-docs.sgml b/glabels2/docs/libglabels/libglabels-docs.sgml index b9b412c3..993afd01 100644 --- a/glabels2/docs/libglabels/libglabels-docs.sgml +++ b/glabels2/docs/libglabels/libglabels-docs.sgml @@ -8,27 +8,21 @@ LibGlabels Reference Manual - + Basic LibGlabels Usage - - - Templates - - - - - + + - + - + Working Directly With LibGlabels XML - + diff --git a/glabels2/docs/libglabels/libglabels-sections.txt b/glabels2/docs/libglabels/libglabels-sections.txt index bed47815..1c53d0be 100644 --- a/glabels2/docs/libglabels/libglabels-sections.txt +++ b/glabels2/docs/libglabels/libglabels-sections.txt @@ -1,60 +1,46 @@
-init -libglabels/libglabels.h -lgl_init +db +libglabels/db.h +lgl_db_init + +lgl_db_get_paper_id_list +lgl_db_free_paper_id_list +lgl_db_get_paper_name_list +lgl_db_free_paper_name_list +lgl_db_lookup_paper_from_id +lgl_db_lookup_paper_from_name +lgl_db_lookup_paper_id_from_name +lgl_db_lookup_paper_name_from_id +lgl_db_is_paper_id_known +lgl_db_is_paper_id_other + +lgl_db_get_category_id_list +lgl_db_free_category_id_list +lgl_db_get_category_name_list +lgl_db_free_category_name_list +lgl_db_lookup_category_from_id +lgl_db_lookup_category_from_name +lgl_db_lookup_category_id_from_name +lgl_db_lookup_category_name_from_id +lgl_db_is_category_id_known + +lgl_db_get_brand_list +lgl_db_free_brand_list + +lgl_db_register_template +lgl_db_get_template_name_list_unique +lgl_db_get_template_name_list_all +lgl_db_free_template_name_list +lgl_db_lookup_template_from_name + +lgl_db_print_known_papers +lgl_db_print_known_categories +lgl_db_print_known_templates +lgl_db_print_aliases
-enums -libglabels/enums.h -lglUnitsType -
- -
-paper -libglabels/paper.h -lglPaper -lgl_paper_new -lgl_paper_dup -lgl_paper_free -lgl_paper_from_id -lgl_paper_from_name - -lgl_paper_get_id_list -lgl_paper_free_id_list -lgl_paper_get_name_list -lgl_paper_free_name_list - -lgl_paper_is_id_known -lgl_paper_is_id_other - -lgl_paper_lookup_id_from_name -lgl_paper_lookup_name_from_id - -lgl_paper_print_known_papers -
- -
-category -libglabels/category.h -lglCategory -lgl_category_new -lgl_category_dup -lgl_category_free -lgl_category_from_name -lgl_category_from_id - -lgl_category_get_id_list -lgl_category_free_id_list -lgl_category_get_name_list -lgl_category_free_name_list - -lgl_category_lookup_id_from_name -lgl_category_lookup_name_from_id -
- -
-template-struct +template libglabels/template.h lglTemplate @@ -77,41 +63,19 @@ lglTemplateMarkupCircle 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 - -lgl_template_frame_get_size -lgl_template_frame_get_n_labels -lgl_template_frame_get_origins -
- -
-template-db -libglabels/template.h -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 - -lgl_template_register -
- -
-template-construction -libglabels/template.h + lgl_template_new lgl_template_dup lgl_template_free lgl_template_add_category lgl_template_add_frame lgl_template_add_alias + +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_alias_new lgl_template_alias_dup @@ -124,6 +88,10 @@ lgl_template_frame_dup lgl_template_frame_free lgl_template_frame_add_layout lgl_template_frame_add_markup + +lgl_template_frame_get_size +lgl_template_frame_get_n_labels +lgl_template_frame_get_origins lgl_template_layout_new lgl_template_layout_dup @@ -138,10 +106,27 @@ lgl_template_markup_free
-template-misc -libglabels/template.h -lgl_template_print_known_templates -lgl_template_print_aliases +paper +libglabels/paper.h +lglPaper +lgl_paper_new +lgl_paper_dup +lgl_paper_free +
+ +
+category +libglabels/category.h +lglCategory +lgl_category_new +lgl_category_dup +lgl_category_free +
+ +
+enums +libglabels/enums.h +lglUnitsType
diff --git a/glabels2/docs/libglabels/libglabels-undocumented.txt b/glabels2/docs/libglabels/libglabels-undocumented.txt index e487606c..73f1d9e0 100644 --- a/glabels2/docs/libglabels/libglabels-undocumented.txt +++ b/glabels2/docs/libglabels/libglabels-undocumented.txt @@ -1,5 +1,5 @@ 99% symbol docs coverage. -139 symbols documented. +135 symbols documented. 0 symbols incomplete. 1 not documented. diff --git a/glabels2/docs/libglabels/tmpl/category.sgml b/glabels2/docs/libglabels/tmpl/category.sgml index 1a603f37..2143fd19 100644 --- a/glabels2/docs/libglabels/tmpl/category.sgml +++ b/glabels2/docs/libglabels/tmpl/category.sgml @@ -1,12 +1,12 @@ -Categories +The lglCategory Structure Template category definitions -This section describes a structure for representing categories of stationary and related +This section describes a structure for representing a category of stationary and related functions. @@ -53,71 +53,3 @@ This structure defines a category. @category: - - - - - -@name: -@Returns: - - - - - - - -@id: -@Returns: - - - - - - - -@Returns: - - - - - - - -@ids: - - - - - - - -@Returns: - - - - - - - -@names: - - - - - - - -@name: -@Returns: - - - - - - - -@id: -@Returns: - - diff --git a/glabels2/docs/libglabels/tmpl/db.sgml b/glabels2/docs/libglabels/tmpl/db.sgml new file mode 100644 index 00000000..734bb9c1 --- /dev/null +++ b/glabels2/docs/libglabels/tmpl/db.sgml @@ -0,0 +1,284 @@ + +Database + + +Database of pre-defined templates + + + +This section describes a set of functions to locate and add templates and related information in +the LibGlabels template database. + + + + + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@ids: + + + + + + + +@Returns: + + + + + + + +@names: + + + + + + + +@id: +@Returns: + + + + + + + +@name: +@Returns: + + + + + + + +@name: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@Returns: + + + + + + + +@ids: + + + + + + + +@Returns: + + + + + + + +@names: + + + + + + + +@id: +@Returns: + + + + + + + +@name: +@Returns: + + + + + + + +@name: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@paper_id: +@category_id: +@Returns: + + + + + + + +@brands: + + + + + + + +@template: + + + + + + + +@brand: +@paper_id: +@category_id: +@Returns: + + + + + + + +@brand: +@paper_id: +@category_id: +@Returns: + + + + + + + +@names: + + + + + + + +@name: +@Returns: + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@template: + + diff --git a/glabels2/docs/libglabels/tmpl/init.sgml b/glabels2/docs/libglabels/tmpl/init.sgml deleted file mode 100644 index 14024cbf..00000000 --- a/glabels2/docs/libglabels/tmpl/init.sgml +++ /dev/null @@ -1,26 +0,0 @@ - -Initialization - - -Initialization of the LibGlabels library. - - - -This section describes the LibGlabels initialization function. - - - - - - - - - - - - - - - - - diff --git a/glabels2/docs/libglabels/tmpl/libglabels-unused.sgml b/glabels2/docs/libglabels/tmpl/libglabels-unused.sgml index 946b837f..dc089b42 100644 --- a/glabels2/docs/libglabels/tmpl/libglabels-unused.sgml +++ b/glabels2/docs/libglabels/tmpl/libglabels-unused.sgml @@ -1,3 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + +init + + @@ -22,29 +46,77 @@ libglabels - + + +This section describes a set of functions for constructing new template structures. + + + + + + + + + + +Functions to help create new templates + + + + + + + +Construction Functions + + + + +This section describes a set of functions to locate pre-defined templates and add templates +to the LibGlabels template database. + + + + + + + + + + +Database of pre-defined templates + + + + + + + +Database + + + -This section describes a set of structures representing stationary templates and related -functions. +This section describes miscellaneous template functions. - + - -Template definitions + +Miscellaneous template functions - + - -Templates + +Miscellaneous Functions @@ -1176,18 +1248,166 @@ the CSS2 Specification (Section 4.3.2). @templates: @utf8_filename: + + + + + +@ids: + + + + + + +@names: + + + + + + +@id: +@Returns: + + + + + + +@name: +@Returns: + + + + + + +@Returns: + + + + + + +@Returns: + + + + + + +@name: +@Returns: + + + + + + +@id: +@Returns: + + + + + + + + + + + + +@ids: + + + + + + +@names: + + + + + + +@id: +@Returns: + + + + + + +@name: +@Returns: + + + + + + +@Returns: + + + + + + +@Returns: + + + + + + +@id: +@Returns: + + + + + + +@id: +@Returns: + + + + + + +@name: +@Returns: + + + + + + +@id: +@Returns: + + + + + + + @@ -1204,6 +1424,37 @@ the CSS2 Specification (Section 4.3.2). @frame: @markup: + + + + + +@brands: + + + + + + +@names: + + + + + + +@name: +@Returns: + + + + + + +@page_size: +@category: +@Returns: + @@ -1212,12 +1463,52 @@ the CSS2 Specification (Section 4.3.2). @template: @Returns: + + + + + +@brand: +@page_size: +@category: +@Returns: + + + + + + +@brand: +@page_size: +@category: +@Returns: + + + + + + +@template: + + + + + + + + + + + + +@template: + diff --git a/glabels2/docs/libglabels/tmpl/paper.sgml b/glabels2/docs/libglabels/tmpl/paper.sgml index 17ec6ac8..d08f8729 100644 --- a/glabels2/docs/libglabels/tmpl/paper.sgml +++ b/glabels2/docs/libglabels/tmpl/paper.sgml @@ -1,5 +1,5 @@ -Paper Sizes +The lglPaper Structure Paper size definitions @@ -57,96 +57,3 @@ This structure defines a paper (page) size. @paper: - - - - - -@id: -@Returns: - - - - - - - -@name: -@Returns: - - - - - - - -@Returns: - - - - - - - -@ids: - - - - - - - -@Returns: - - - - - - - -@names: - - - - - - - -@id: -@Returns: - - - - - - - -@id: -@Returns: - - - - - - - -@name: -@Returns: - - - - - - - -@id: -@Returns: - - - - - - - - - diff --git a/glabels2/docs/libglabels/tmpl/template-construction.sgml b/glabels2/docs/libglabels/tmpl/template-construction.sgml deleted file mode 100644 index f486869a..00000000 --- a/glabels2/docs/libglabels/tmpl/template-construction.sgml +++ /dev/null @@ -1,271 +0,0 @@ - -Construction Functions - - -Functions to help create new templates - - - -This section describes a set of functions for constructing new template structures. - - - - - - - - - - - - - - - -@brand: -@part: -@description: -@page_size: -@page_width: -@page_height: -@Returns: - - - - - - - -@orig_template: -@Returns: - - - - - - - -@template: - - - - - - - -@template: -@category: - - - - - - - -@template: -@frame: - - - - - - - -@template: -@alias: - - - - - - - -@brand: -@part: -@Returns: - - - - - - - -@orig_alias: -@Returns: - - - - - - - -@alias: - - - - - - - -@id: -@w: -@h: -@r: -@x_waste: -@y_waste: -@Returns: - - - - - - - -@id: -@r: -@waste: -@Returns: - - - - - - - -@id: -@r1: -@r2: -@w: -@h: -@waste: -@Returns: - - - - - - - -@orig_frame: -@Returns: - - - - - - - -@frame: - - - - - - - -@frame: -@layout: - - - - - - - -@frame: -@markup: - - - - - - - -@nx: -@ny: -@x0: -@y0: -@dx: -@dy: -@Returns: - - - - - - - -@orig_layout: -@Returns: - - - - - - - -@layout: - - - - - - - -@size: -@Returns: - - - - - - - -@x1: -@y1: -@x2: -@y2: -@Returns: - - - - - - - -@x0: -@y0: -@r: -@Returns: - - - - - - - -@x1: -@y1: -@w: -@h: -@r: -@Returns: - - - - - - - -@orig_markup: -@Returns: - - - - - - - -@markup: - - diff --git a/glabels2/docs/libglabels/tmpl/template-db.sgml b/glabels2/docs/libglabels/tmpl/template-db.sgml deleted file mode 100644 index 81aa6941..00000000 --- a/glabels2/docs/libglabels/tmpl/template-db.sgml +++ /dev/null @@ -1,85 +0,0 @@ - -Database - - -Database of pre-defined templates - - - -This section describes a set of functions to locate pre-defined templates and add templates -to the LibGlabels template database. - - - - - - - - - - - - - - - -@brand: -@page_size: -@category: -@Returns: - - - - - - - -@brand: -@page_size: -@category: -@Returns: - - - - - - - -@names: - - - - - - - -@page_size: -@category: -@Returns: - - - - - - - -@brands: - - - - - - - -@name: -@Returns: - - - - - - - -@template: - - diff --git a/glabels2/docs/libglabels/tmpl/template-misc.sgml b/glabels2/docs/libglabels/tmpl/template-misc.sgml deleted file mode 100644 index 1b773d7c..00000000 --- a/glabels2/docs/libglabels/tmpl/template-misc.sgml +++ /dev/null @@ -1,34 +0,0 @@ - -Miscellaneous Functions - - -Miscellaneous template functions - - - -This section describes miscellaneous template functions. - - - - - - - - - - - - - - - - - - - - - - -@template: - - diff --git a/glabels2/docs/libglabels/tmpl/template-struct.sgml b/glabels2/docs/libglabels/tmpl/template-struct.sgml deleted file mode 100644 index 5357607e..00000000 --- a/glabels2/docs/libglabels/tmpl/template-struct.sgml +++ /dev/null @@ -1,280 +0,0 @@ - -The lglTemplate Structure - - -How templates are represented in memory - - - -This section describes a set of structures that represent a template in memory. It also -describes functions to help interpret these structures. - - - - - - - - - - - - -This is the main structure of a libglabels template. A template represents a single sheet -of peel-off labels or cards. - - -@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. - - - -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." - - - -This enumeration defines frame types that are supported by libglabels - - -@LGL_TEMPLATE_FRAME_SHAPE_RECT: A rectangular frame. (May have rounded corners.) -@LGL_TEMPLATE_FRAME_SHAPE_ROUND: A round frame. -@LGL_TEMPLATE_FRAME_SHAPE_CD: A CD or DVD frame. (Includes credit-card style CDs.) - - - -A union of all possible frame structures. The type of structure is indicated by the shape -member, which overlays the first field of all other member structures. - - - - - -This structure is composed of a set of fields common to all frame structures. All frame types -can be cast to this structure. - - -@shape: The shape of the frame. -@id: Reserved for future use. Should always be zero. -@layouts: A list of (#lglTemplateLayout *) structures. Typically a frame will have a single -layout, representing a simple grid of labels or cards. If the layout of labels or cards is -more complex, multiple (#lglTemplateLayout *) structures may be needed. -@markups: A list of (#lglTemplateMarkup *) structures, which represent non-printing markup lines. - - - -This structure defines the frame for a rectangular label or card. - - -@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_RECT for #lglTemplateFrameRect. -@id: Common field. See #lglTemplateFrameAll. -@layouts: Common field. See #lglTemplateFrameAll. -@markups: Common field. See #lglTemplateFrameAll. -@w: Width of label or card in points. -@h: Height of label or card in points. -@r: Radius of corners in points. -@x_waste: Amount of horizontal over-print to allow in points. -@y_waste: Amount of vertical over-print to allow in points. - - - -This structure defines the frame for a round label or card. - - -@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_ROUND for #lglTemplateFrameRound. -@id: Common field. See #lglTemplateFrameAll. -@layouts: Common field. See #lglTemplateFrameAll. -@markups: Common field. See #lglTemplateFrameAll. -@r: Radius of label or card in points. -@waste: Amount of over-print to allow in points. - - - -This structure defines the frame for a CD or DVD label. This structure also supports -credit-card CD labels. - - -@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_CD for #lglTemplateFrameCD. -@id: Common field. See #lglTemplateFrameAll. -@layouts: Common field. See #lglTemplateFrameAll. -@markups: Common field. See #lglTemplateFrameAll. -@r1: Outer radius of label in points. -@r2: Radius of center hole in points. -@w: Clip width in points. Used for credit-card CD labels. This field is ignored if zero. -@h: Clip height in points. Used for credit-card CD labels. This field is ignored if zero. -@waste: Amount of over-print to allow in points. - - - -This structure defines a simple grid layout of labels or cards. - - -@nx: Number of labels or cards across in the grid (horizontal). -@ny: Number of labels or cards down in the grid (vertical). -@x0: Distance (in points) from the left edge of page to the left edge of the left column of -cards or labels in the layout. -@y0: Distance (in points) from the top edge of page to the top edge of the top row of -cards or labels in the layout. -@dx: Horizontal pitch of grid in points. This is the distance from left edge to left edge -(not the gap between labels or cards). -@dy: Vertical pitch of grid in points. This is the distance from top edge to top edge -(not the gap between labels or cards). - - - -This enumeration defines markup types that are supported by libglabels - - -@LGL_TEMPLATE_MARKUP_MARGIN: A margin line around perimeter of label or card. -@LGL_TEMPLATE_MARKUP_LINE: A simple line segment. -@LGL_TEMPLATE_MARKUP_CIRCLE: A circle. -@LGL_TEMPLATE_MARKUP_RECT: A rectangle. Possibly with rounded corners. - - - -A union of all possible markup structures. The type of structure is indicated by the type -member, which overlays the first field of all other member structures. - - - - - -This structure defines a simple margin markup around the perimeter of a label or card. - - -@type: Common field. Always #LGL_TEMPLATE_MARKUP_MARGIN for #lglTemplateMarkupMargin. -@size: Distance of margin from edge of label or card. - - - -This structure defines a simple line segment markup. - - -@type: Common field. Always #LGL_TEMPLATE_MARKUP_LINE for #lglTemplateMarkupLine. -@x1: Distance (in points) of first endpoint from left edge of label or card. -@y1: Distance (in points) of first endpoint from top edge of label or card. -@x2: Distance (in points) of second endpoint from left edge of label or card. -@y2: Distance (in points) of second endpoint from top edge of label or card. - - - -This structure defines a simple circle markup. - - -@type: Common field. Always #LGL_TEMPLATE_MARKUP_CIRCLE for #lglTemplateMarkupCircle. -@x0: Distance (in points) of vertex from left edge of label or card. -@y0: Distance (in points) of vertex from top edge of label or card. -@r: Radius of circle in points. - - - -This structure defines a simple rectangle markup. The rectangle can have rounded corners. - - -@type: Common field. Always #LGL_TEMPLATE_MARKUP_RECT for #lglTemplateMarkupRect. -@x1: Distance (in points) of left edge of markup from left edge of label or card. -@y1: Distance (in points) of top edge of markup from top edge of label or card. -@w: Width of rectangle in points. -@h: Height of rectangle in points. -@r: Radius of corners in points. Should be zero for sharp corners. - - - -This structure represents the cartesian coordinates of the origin of a label or card on the page. -The orign is the upper left corner of the extent of the label or card. These coordinates are -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: - - - - - - - -@template: -@page_size: -@Returns: - - - - - - - -@template: -@category: -@Returns: - - - - - - - -@frame: -@w: -@h: - - - - - - - -@frame: -@Returns: - - - - - - - -@frame: -@Returns: - - diff --git a/glabels2/docs/libglabels/tmpl/template.sgml b/glabels2/docs/libglabels/tmpl/template.sgml new file mode 100644 index 00000000..e7a58879 --- /dev/null +++ b/glabels2/docs/libglabels/tmpl/template.sgml @@ -0,0 +1,532 @@ + +The lglTemplate Structure + + +How templates are represented in memory + + + +This section describes a set of structures that represent a template in memory. It also +describes functions to help create and interpret these structures. + + + + + + + + + + + + +This is the main structure of a libglabels template. A template represents a single sheet +of peel-off labels or cards. + + +@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." +@paper_id: A paper ID. E.g. "A4" or "US-Letter." +@page_width: Page width in points. Used only if paper_id is "Other." +@page_height: Page height in points. Used only if paper_id is "Other." +@aliases: A list of alternate names for this template. Often a single template can be used for +multiple products. +@category_ids: A list of category IDs that this template belongs to. +@frames: A list of (#lglTemplateFrame *) structures. GLabels currently only supports one frame +per template -- future versions may support multiple frames per template. + + + +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." + + + +This enumeration defines frame types that are supported by libglabels + + +@LGL_TEMPLATE_FRAME_SHAPE_RECT: A rectangular frame. (May have rounded corners.) +@LGL_TEMPLATE_FRAME_SHAPE_ROUND: A round frame. +@LGL_TEMPLATE_FRAME_SHAPE_CD: A CD or DVD frame. (Includes credit-card style CDs.) + + + +A union of all possible frame structures. The type of structure is indicated by the shape +member, which overlays the first field of all other member structures. + + + + + +This structure is composed of a set of fields common to all frame structures. All frame types +can be cast to this structure. + + +@shape: The shape of the frame. +@id: Reserved for future use. Should always be zero. +@layouts: A list of (#lglTemplateLayout *) structures. Typically a frame will have a single +layout, representing a simple grid of labels or cards. If the layout of labels or cards is +more complex, multiple (#lglTemplateLayout *) structures may be needed. +@markups: A list of (#lglTemplateMarkup *) structures, which represent non-printing markup lines. + + + +This structure defines the frame for a rectangular label or card. + + +@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_RECT for #lglTemplateFrameRect. +@id: Common field. See #lglTemplateFrameAll. +@layouts: Common field. See #lglTemplateFrameAll. +@markups: Common field. See #lglTemplateFrameAll. +@w: Width of label or card in points. +@h: Height of label or card in points. +@r: Radius of corners in points. +@x_waste: Amount of horizontal over-print to allow in points. +@y_waste: Amount of vertical over-print to allow in points. + + + +This structure defines the frame for a round label or card. + + +@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_ROUND for #lglTemplateFrameRound. +@id: Common field. See #lglTemplateFrameAll. +@layouts: Common field. See #lglTemplateFrameAll. +@markups: Common field. See #lglTemplateFrameAll. +@r: Radius of label or card in points. +@waste: Amount of over-print to allow in points. + + + +This structure defines the frame for a CD or DVD label. This structure also supports +credit-card CD labels. + + +@shape: Common field. Always #LGL_TEMPLATE_FRAME_SHAPE_CD for #lglTemplateFrameCD. +@id: Common field. See #lglTemplateFrameAll. +@layouts: Common field. See #lglTemplateFrameAll. +@markups: Common field. See #lglTemplateFrameAll. +@r1: Outer radius of label in points. +@r2: Radius of center hole in points. +@w: Clip width in points. Used for credit-card CD labels. This field is ignored if zero. +@h: Clip height in points. Used for credit-card CD labels. This field is ignored if zero. +@waste: Amount of over-print to allow in points. + + + +This structure defines a simple grid layout of labels or cards. + + +@nx: Number of labels or cards across in the grid (horizontal). +@ny: Number of labels or cards down in the grid (vertical). +@x0: Distance (in points) from the left edge of page to the left edge of the left column of +cards or labels in the layout. +@y0: Distance (in points) from the top edge of page to the top edge of the top row of +cards or labels in the layout. +@dx: Horizontal pitch of grid in points. This is the distance from left edge to left edge +(not the gap between labels or cards). +@dy: Vertical pitch of grid in points. This is the distance from top edge to top edge +(not the gap between labels or cards). + + + +This enumeration defines markup types that are supported by libglabels + + +@LGL_TEMPLATE_MARKUP_MARGIN: A margin line around perimeter of label or card. +@LGL_TEMPLATE_MARKUP_LINE: A simple line segment. +@LGL_TEMPLATE_MARKUP_CIRCLE: A circle. +@LGL_TEMPLATE_MARKUP_RECT: A rectangle. Possibly with rounded corners. + + + +A union of all possible markup structures. The type of structure is indicated by the type +member, which overlays the first field of all other member structures. + + + + + +This structure defines a simple margin markup around the perimeter of a label or card. + + +@type: Common field. Always #LGL_TEMPLATE_MARKUP_MARGIN for #lglTemplateMarkupMargin. +@size: Distance of margin from edge of label or card. + + + +This structure defines a simple line segment markup. + + +@type: Common field. Always #LGL_TEMPLATE_MARKUP_LINE for #lglTemplateMarkupLine. +@x1: Distance (in points) of first endpoint from left edge of label or card. +@y1: Distance (in points) of first endpoint from top edge of label or card. +@x2: Distance (in points) of second endpoint from left edge of label or card. +@y2: Distance (in points) of second endpoint from top edge of label or card. + + + +This structure defines a simple circle markup. + + +@type: Common field. Always #LGL_TEMPLATE_MARKUP_CIRCLE for #lglTemplateMarkupCircle. +@x0: Distance (in points) of vertex from left edge of label or card. +@y0: Distance (in points) of vertex from top edge of label or card. +@r: Radius of circle in points. + + + +This structure defines a simple rectangle markup. The rectangle can have rounded corners. + + +@type: Common field. Always #LGL_TEMPLATE_MARKUP_RECT for #lglTemplateMarkupRect. +@x1: Distance (in points) of left edge of markup from left edge of label or card. +@y1: Distance (in points) of top edge of markup from top edge of label or card. +@w: Width of rectangle in points. +@h: Height of rectangle in points. +@r: Radius of corners in points. Should be zero for sharp corners. + + + +This structure represents the cartesian coordinates of the origin of a label or card on the page. +The orign is the upper left corner of the extent of the label or card. These coordinates are +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. + + + + + + +@brand: +@part: +@description: +@paper_id: +@page_width: +@page_height: +@Returns: + + + + + + + +@orig_template: +@Returns: + + + + + + + +@template: + + + + + + + +@template: +@category_id: + + + + + + + +@template: +@frame: + + + + + + + +@template: +@alias: + + + + + + + +@template: +@Returns: + + + + + + + +@template1: +@template2: +@Returns: + + + + + + + +@template: +@brand: +@Returns: + + + + + + + +@template: +@paper_id: +@Returns: + + + + + + + +@template: +@category_id: +@Returns: + + + + + + + +@brand: +@part: +@Returns: + + + + + + + +@orig_alias: +@Returns: + + + + + + + +@alias: + + + + + + + +@id: +@w: +@h: +@r: +@x_waste: +@y_waste: +@Returns: + + + + + + + +@id: +@r: +@waste: +@Returns: + + + + + + + +@id: +@r1: +@r2: +@w: +@h: +@waste: +@Returns: + + + + + + + +@orig_frame: +@Returns: + + + + + + + +@frame: + + + + + + + +@frame: +@layout: + + + + + + + +@frame: +@markup: + + + + + + + +@frame: +@w: +@h: + + + + + + + +@frame: +@Returns: + + + + + + + +@frame: +@Returns: + + + + + + + +@nx: +@ny: +@x0: +@y0: +@dx: +@dy: +@Returns: + + + + + + + +@orig_layout: +@Returns: + + + + + + + +@layout: + + + + + + + +@size: +@Returns: + + + + + + + +@x1: +@y1: +@x2: +@y2: +@Returns: + + + + + + + +@x0: +@y0: +@r: +@Returns: + + + + + + + +@x1: +@y1: +@w: +@h: +@r: +@Returns: + + + + + + + +@orig_markup: +@Returns: + + + + + + + +@markup: + + diff --git a/glabels2/libglabels/Makefile.am b/glabels2/libglabels/Makefile.am index bdf42eeb..bc6774f4 100644 --- a/glabels2/libglabels/Makefile.am +++ b/glabels2/libglabels/Makefile.am @@ -17,8 +17,8 @@ libglabelsincludedir=$(includedir)/libglabels libglabels_la_SOURCES = \ libglabels-private.h \ - init.h \ - init.c \ + db.h \ + db.c \ enums.h \ paper.h \ paper.c \ @@ -37,6 +37,7 @@ libglabels_la_SOURCES = \ libglabelsinclude_HEADERS = \ libglabels.h \ + db.h \ enums.h \ paper.h \ category.h \ diff --git a/glabels2/libglabels/category.c b/glabels2/libglabels/category.c index 11cc40bb..e82e0849 100644 --- a/glabels2/libglabels/category.c +++ b/glabels2/libglabels/category.c @@ -32,13 +32,10 @@ #include #include #include -#include #include #include "libglabels-private.h" -#include "xml-category.h" - /*===========================================*/ /* Private types */ /*===========================================*/ @@ -48,38 +45,15 @@ /* Private globals */ /*===========================================*/ -static GList *categories = NULL; - /*===========================================*/ /* Local function prototypes */ /*===========================================*/ -static GList *read_categories (void); - -static GList *read_category_files_from_dir (GList *categories, - const gchar *dirname); - - -/** - * lgl_category_init: - * - * Initialize libglabels category module by reading all category definition - * files located in system and user template directories. - * - * The end user would typically call lgl_init() instead. - */ -void -lgl_category_init (void) -{ - if (categories) { - return; /* Already initialized. */ - } - - categories = read_categories (); -} - +/*===========================================*/ +/* Functions. */ +/*===========================================*/ /** * lgl_category_new: * @id: Id of category definition. (E.g. label, card, etc.) Should be @@ -153,313 +127,3 @@ void lgl_category_free (lglCategory *category) } -/** - * lgl_category_get_id_list: - * - * Get a list of all category ids known to libglabels. - * - * Returns: a list of category ids. - * - */ -GList * -lgl_category_get_id_list (void) -{ - GList *ids = NULL; - GList *p; - lglCategory *category; - - if (!categories) { - lgl_category_init (); - } - - for ( p=categories; p != NULL; p=p->next ) { - category = (lglCategory *)p->data; - ids = g_list_append (ids, g_strdup (category->id)); - } - - return ids; -} - -/** - * lgl_category_free_id_list: - * @ids: List of id strings to be freed. - * - * Free up all storage associated with an id list obtained with - * lgl_category_get_id_list(). - * - */ -void -lgl_category_free_id_list (GList *ids) -{ - GList *p; - - for (p = ids; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - - g_list_free (ids); -} - - -/** - * lgl_category_get_name_list: - * - * Get a list of all localized category names known to liblglabels. - * - * Returns: a list of localized category names. - * - */ -GList * -lgl_category_get_name_list (void) -{ - GList *names = NULL; - GList *p; - lglCategory *category; - - if (!categories) { - lgl_category_init (); - } - - for ( p=categories; p != NULL; p=p->next ) { - category = (lglCategory *)p->data; - names = g_list_append (names, g_strdup (category->name)); - } - - return names; -} - - -/** - * lgl_category_free_name_list: - * @names: List of localized category name strings to be freed. - * - * Free up all storage associated with a name list obtained with - * lgl_category_get_name_list(). - * - */ -void -lgl_category_free_name_list (GList *names) -{ - GList *p; - - for (p = names; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - - g_list_free (names); -} - - -/** - * lgl_category_from_id: - * @id: category id string - * - * Lookup category definition from id string. - * - * Returns: pointer to a newly allocated #lglCategory structure. - * - */ -lglCategory * -lgl_category_from_id (const gchar *id) -{ - GList *p; - lglCategory *category; - - if (!categories) { - lgl_category_init (); - } - - if (id == NULL) { - /* If no id, return first category as a default */ - return lgl_category_dup ((lglCategory *) categories->data); - } - - for (p = categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; - if (g_strcasecmp (category->id, id) == 0) { - return lgl_category_dup (category); - } - } - - return NULL; -} - - -/** - * lgl_category_from_name: - * @name: localized category name string - * - * Lookup category definition from localized category name string. - * - * Returns: pointer to a newly allocated #lglCategory structure. - * - */ -lglCategory * -lgl_category_from_name (const gchar *name) -{ - GList *p; - lglCategory *category; - - if (!categories) { - lgl_category_init (); - } - - if (name == NULL) { - /* If no name, return first category as a default */ - return lgl_category_dup ((lglCategory *) categories->data); - } - - for (p = categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; - if (g_strcasecmp (category->name, name) == 0) { - return lgl_category_dup (category); - } - } - - return NULL; -} - - -/** - * lgl_category_lookup_id_from_name: - * @name: localized category name stringp - * - * Lookup category name string from localized category name string. - * - * Returns: pointer to a newly allocated id string. - * - */ -gchar * -lgl_category_lookup_id_from_name (const gchar *name) -{ - lglCategory *category = NULL; - gchar *id = NULL; - - if (name != NULL) - { - category = lgl_category_from_name (name); - if ( category != NULL ) - { - id = g_strdup (category->id); - lgl_category_free (category); - category = NULL; - } - } - - return id; -} - -/** - * lgl_category_lookup_name_from_id: - * @id: category id string - * - * Lookup localized category name string from category id string. - * - * Returns: pointer to a newly allocated localized category name string. - * - */ -gchar * -lgl_category_lookup_name_from_id (const gchar *id) -{ - lglCategory *category = NULL; - gchar *name = NULL; - - if (id != NULL) - { - category = lgl_category_from_id (id); - if ( category != NULL ) - { - name = g_strdup (category->name); - lgl_category_free (category); - category = NULL; - } - } - - return name; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read categories from various files. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_categories (void) -{ - gchar *data_dir; - GList *categories = NULL; - - data_dir = LGL_SYSTEM_DATA_DIR; - categories = read_category_files_from_dir (categories, data_dir); - g_free (data_dir); - - data_dir = LGL_USER_DATA_DIR; - categories = read_category_files_from_dir (categories, data_dir); - g_free (data_dir); - - if (categories == NULL) { - g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!")); - } - - return categories; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read all category files from given directory. Append to list. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_category_files_from_dir (GList *categories, - const gchar *dirname) -{ - GDir *dp; - const gchar *filename, *extension; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_categories = NULL; - - if (dirname == NULL) { - return categories; - } - - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return categories; - } - - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return categories; - } - - while ((filename = g_dir_read_name (dp)) != NULL) { - - extension = strrchr (filename, '.'); - - if (extension != NULL) { - - if ( (g_strcasecmp (extension, ".categories") == 0) - || (g_strcasecmp (filename, "categories.xml") == 0) ) { - - full_filename = - g_build_filename (dirname, filename, NULL); - new_categories = - lgl_xml_category_read_categories_from_file (full_filename); - g_free (full_filename); - - categories = g_list_concat (categories, new_categories); - new_categories = NULL; - - } - - } - - } - - g_dir_close (dp); - - return categories; -} - - - - diff --git a/glabels2/libglabels/category.h b/glabels2/libglabels/category.h index cab4585d..3727d47d 100644 --- a/glabels2/libglabels/category.h +++ b/glabels2/libglabels/category.h @@ -54,28 +54,6 @@ lglCategory *lgl_category_dup (const lglCategory *orig); void lgl_category_free (lglCategory *category); -/* - * ID lists - */ -GList *lgl_category_get_id_list (void); -void lgl_category_free_id_list (GList *ids); - - -/* - * Known category name lists - */ -GList *lgl_category_get_name_list (void); -void lgl_category_free_name_list (GList *names); - - -/* - * Query functions - */ -lglCategory *lgl_category_from_name (const gchar *name); -lglCategory *lgl_category_from_id (const gchar *id); -gchar *lgl_category_lookup_id_from_name (const gchar *name); -gchar *lgl_category_lookup_name_from_id (const gchar *id); - G_END_DECLS #endif diff --git a/glabels2/libglabels/db.c b/glabels2/libglabels/db.c new file mode 100644 index 00000000..89b097d2 --- /dev/null +++ b/glabels2/libglabels/db.c @@ -0,0 +1,1454 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + +/* + * (LIBGLABELS) Template library for GLABELS + * + * db.c: template db module + * + * Copyright (C) 2003-2007 Jim Evins . + * + * This file is part of the LIBGLABELS library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA + */ +#include + +#include "db.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libglabels-private.h" + +#include "xml-paper.h" +#include "xml-category.h" +#include "xml-template.h" + + +/*===========================================*/ +/* Private types */ +/*===========================================*/ + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ + +static GList *papers = NULL; +static GList *categories = NULL; +static GList *templates = NULL; + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static GList *read_papers (void); +static GList *read_paper_files_from_dir (GList *papers, + const gchar *dirname); + +static GList *read_categories (void); +static GList *read_category_files_from_dir (GList *categories, + const gchar *dirname); + +static GList *read_templates (void); +static GList *read_template_files_from_dir (GList *templates, + const gchar *dirname); + +static lglTemplate *template_full_page (const gchar *page_size); + + + +/*===========================================*/ +/* Module initialization */ +/*===========================================*/ + +/** + * lgl_db_init: + * + * Initialize all libglabels subsystems. It is not necessary for an application to call + * lgl_init(), because libglabels will initialize on demand. An application programmer may + * choose to call lgl_init() at startup to minimize the impact of the first libglabels call + * on GUI response time. + * + * This function initializes its paper definitions, category definitions, and its template + * database.. It will search both system and user template directories to locate + * this data. + */ +void +lgl_db_init (void) +{ + lglPaper *other; + GList *page_sizes; + GList *p; + + /* + * Paper definitions + */ + if (!papers) + { + + papers = read_papers (); + + /* Create and append an "Other" entry. */ + other = lgl_paper_new ("Other", _("Other"), 0.0, 0.0); + papers = g_list_append (papers, other); + + } + + /* + * Categories + */ + if (!categories) + { + categories = read_categories (); + } + + /* + * Templates + */ + if (!templates) + { + + templates = read_templates (); + + /* Create and append generic full page templates. */ + page_sizes = lgl_db_get_paper_id_list (); + for ( p=page_sizes; p != NULL; p=p->next ) + { + if ( !lgl_db_is_paper_id_other (p->data) ) + { + templates = g_list_append (templates, + template_full_page (p->data)); + } + } + lgl_db_free_paper_id_list (page_sizes); + + } +} + + + +/*===========================================*/ +/* Paper db functions. */ +/*===========================================*/ + +/** + * lgl_db_get_paper_id_list: + * + * Get a list of all paper ids known to libglabels. + * + * Returns: a list of paper ids. + * + */ +GList * +lgl_db_get_paper_id_list (void) +{ + GList *ids = NULL; + GList *p; + lglPaper *paper; + + if (!papers) + { + lgl_db_init (); + } + + for ( p=papers; p != NULL; p=p->next ) + { + paper = (lglPaper *)p->data; + ids = g_list_append (ids, g_strdup (paper->id)); + } + + return ids; +} + + +/** + * lgl_db_free_paper_id_list: + * @ids: List of id strings to be freed. + * + * Free up all storage associated with an id list obtained with + * lgl_paper_get_id_list(). + * + */ +void +lgl_db_free_paper_id_list (GList *ids) +{ + GList *p; + + for (p = ids; p != NULL; p = p->next) + { + g_free (p->data); + p->data = NULL; + } + + g_list_free (ids); +} + + +/** + * lgl_db_get_paper_name_list: + * + * Get a list of all localized paper names known to libglabels. + * + * Returns: a list of localized paper names. + * + */ +GList * +lgl_db_get_paper_name_list (void) +{ + GList *names = NULL; + GList *p; + lglPaper *paper; + + if (!papers) + { + lgl_db_init (); + } + + for ( p=papers; p != NULL; p=p->next ) + { + paper = (lglPaper *)p->data; + names = g_list_append (names, g_strdup (paper->name)); + } + + return names; +} + + +/** + * lgl_db_free_paper_name_list: + * @names: List of localized paper name strings to be freed. + * + * Free up all storage associated with a name list obtained with + * lgl_paper_get_name_list(). + * + */ +void +lgl_db_free_paper_name_list (GList *names) +{ + GList *p; + + for (p = names; p != NULL; p = p->next) + { + g_free (p->data); + p->data = NULL; + } + + g_list_free (names); +} + + +/** + * lgl_db_lookup_paper_from_name: + * @name: localized paper name string + * + * Lookup paper definition from localized paper name string. + * + * Returns: pointer to a newly allocated #lglPaper structure. + * + */ +lglPaper * +lgl_db_lookup_paper_from_name (const gchar *name) +{ + GList *p; + lglPaper *paper; + + if (!papers) + { + lgl_db_init (); + } + + if (name == NULL) + { + /* If no name, return first paper as a default */ + return lgl_paper_dup ((lglPaper *) papers->data); + } + + for (p = papers; p != NULL; p = p->next) + { + paper = (lglPaper *) p->data; + if (UTF8_EQUAL (paper->name, name)) + { + return lgl_paper_dup (paper); + } + } + + return NULL; +} + + +/** + * lgl_db_lookup_paper_from_id: + * @id: paper id string + * + * Lookup paper definition from id string. + * + * Returns: pointer to a newly allocated #lglPaper structure. + * + */ +lglPaper * +lgl_db_lookup_paper_from_id (const gchar *id) +{ + GList *p; + lglPaper *paper; + + if (!papers) + { + lgl_db_init (); + } + + if (id == NULL) + { + /* If no id, return first paper as a default */ + return lgl_paper_dup ((lglPaper *) papers->data); + } + + for (p = papers; p != NULL; p = p->next) + { + paper = (lglPaper *) p->data; + if (ASCII_EQUAL (paper->id, id)) + { + return lgl_paper_dup (paper); + } + } + + return NULL; +} + + +/** + * lgl_db_lookup_paper_id_from_name: + * @name: localized paper name stringp + * + * Lookup paper name string from localized paper name string. + * + * Returns: pointer to a newly allocated id string. + * + */ +gchar * +lgl_db_lookup_paper_id_from_name (const gchar *name) +{ + lglPaper *paper = NULL; + gchar *id = NULL; + + if (name != NULL) + { + paper = lgl_db_lookup_paper_from_name (name); + if ( paper != NULL ) + { + id = g_strdup (paper->id); + lgl_paper_free (paper); + paper = NULL; + } + } + + return id; +} + + +/** + * lgl_db_lookup_paper_name_from_id: + * @id: paper id string + * + * Lookup localized paper name string from paper id string. + * + * Returns: pointer to a newly allocated localized paper name string. + * + */ +gchar * +lgl_db_lookup_paper_name_from_id (const gchar *id) +{ + lglPaper *paper = NULL; + gchar *name = NULL; + + if (id != NULL) + { + paper = lgl_db_lookup_paper_from_id (id); + if ( paper != NULL ) + { + name = g_strdup (paper->name); + lgl_paper_free (paper); + paper = NULL; + } + } + + return name; +} + + +/** + * lgl_db_is_paper_id_known: + * @id: paper id to test + * + * Determine if given paper id is known to libglabels. + * + * Returns: TRUE if id is known, otherwise FALSE. + * + */ +gboolean +lgl_db_is_paper_id_known (const gchar *id) +{ + GList *p; + lglPaper *paper; + + if (!papers) + { + lgl_db_init (); + } + + if (id == NULL) + { + return FALSE; + } + + for (p = papers; p != NULL; p = p->next) + { + paper = (lglPaper *) p->data; + if (ASCII_EQUAL (paper->id, id)) + { + return TRUE; + } + } + + return FALSE; +} + +/** + * lgl_db_is_paper_id_other: + * @id: paper id to test + * + * Determine if given paper id is the special id "Other." + * + * Returns: TRUE if id is "Other", otherwise FALSE. + * + */ +gboolean +lgl_db_is_paper_id_other (const gchar *id) +{ + if (id == NULL) + { + return FALSE; + } + + return (ASCII_EQUAL (id, "Other")); +} + + +static GList * +read_papers (void) +{ + gchar *data_dir; + GList *papers = NULL; + + data_dir = LGL_SYSTEM_DATA_DIR; + papers = read_paper_files_from_dir (papers, data_dir); + g_free (data_dir); + + data_dir = LGL_USER_DATA_DIR; + papers = read_paper_files_from_dir (papers, data_dir); + g_free (data_dir); + + if (papers == NULL) { + g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!")); + } + + return papers; +} + + +static GList * +read_paper_files_from_dir (GList *papers, + const gchar *dirname) +{ + GDir *dp; + const gchar *filename, *extension; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_papers = NULL; + + if (dirname == NULL) { + return papers; + } + + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { + return papers; + } + + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) { + g_message ("cannot open data directory: %s", gerror->message ); + return papers; + } + + while ((filename = g_dir_read_name (dp)) != NULL) { + + extension = strrchr (filename, '.'); + + if (extension != NULL) { + + if ( ASCII_EQUAL (extension, ".paper") || + ASCII_EQUAL (filename, "paper-sizes.xml") ) + { + + full_filename = + g_build_filename (dirname, filename, NULL); + new_papers = + lgl_xml_paper_read_papers_from_file (full_filename); + g_free (full_filename); + + papers = g_list_concat (papers, new_papers); + new_papers = NULL; + + } + + } + + } + + g_dir_close (dp); + + return papers; +} + + +/** + * lgl_db_print_known_papers: + * + * For debugging purposes: print a list of all paper definitions known to + * libglabels. + * + */ +void +lgl_db_print_known_papers (void) +{ + GList *p; + lglPaper *paper; + + if (!papers) { + lgl_db_init (); + } + + g_print ("%s():\n", __FUNCTION__); + for (p = papers; p != NULL; p = p->next) { + paper = (lglPaper *) p->data; + + g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n", + paper->id, paper->name, paper->width, paper->height); + + } + g_print ("\n"); + +} + + +/*===========================================*/ +/* Category db functions. */ +/*===========================================*/ + +/** + * lgl_db_get_category_id_list: + * + * Get a list of all category ids known to libglabels. + * + * Returns: a list of category ids. + * + */ +GList * +lgl_db_get_category_id_list (void) +{ + GList *ids = NULL; + GList *p; + lglCategory *category; + + if (!categories) + { + lgl_db_init (); + } + + for ( p=categories; p != NULL; p=p->next ) + { + category = (lglCategory *)p->data; + ids = g_list_append (ids, g_strdup (category->id)); + } + + return ids; +} + + +/** + * lgl_db_free_category_id_list: + * @ids: List of id strings to be freed. + * + * Free up all storage associated with an id list obtained with + * lgl_category_get_id_list(). + * + */ +void +lgl_db_free_category_id_list (GList *ids) +{ + GList *p; + + for (p = ids; p != NULL; p = p->next) + { + g_free (p->data); + p->data = NULL; + } + + g_list_free (ids); +} + + +/** + * lgl_db_get_category_name_list: + * + * Get a list of all localized category names known to libglabels. + * + * Returns: a list of localized category names. + * + */ +GList * +lgl_db_get_category_name_list (void) +{ + GList *names = NULL; + GList *p; + lglCategory *category; + + if (!categories) + { + lgl_db_init (); + } + + for ( p=categories; p != NULL; p=p->next ) + { + category = (lglCategory *)p->data; + names = g_list_append (names, g_strdup (category->name)); + } + + return names; +} + + +/** + * lgl_db_free_category_name_list: + * @names: List of localized category name strings to be freed. + * + * Free up all storage associated with a name list obtained with + * lgl_category_get_name_list(). + * + */ +void +lgl_db_free_category_name_list (GList *names) +{ + GList *p; + + for (p = names; p != NULL; p = p->next) + { + g_free (p->data); + p->data = NULL; + } + + g_list_free (names); +} + + +/** + * lgl_db_lookup_category_from_name: + * @name: localized category name string + * + * Lookup category definition from localized category name string. + * + * Returns: pointer to a newly allocated #lglCategory structure. + * + */ +lglCategory * +lgl_db_lookup_category_from_name (const gchar *name) +{ + GList *p; + lglCategory *category; + + if (!categories) + { + lgl_db_init (); + } + + if (name == NULL) + { + /* If no name, return first category as a default */ + return lgl_category_dup ((lglCategory *) categories->data); + } + + for (p = categories; p != NULL; p = p->next) + { + category = (lglCategory *) p->data; + if (UTF8_EQUAL (category->name, name)) + { + return lgl_category_dup (category); + } + } + + return NULL; +} + + +/** + * lgl_db_lookup_category_from_id: + * @id: category id string + * + * Lookup category definition from id string. + * + * Returns: pointer to a newly allocated #lglCategory structure. + * + */ +lglCategory * +lgl_db_lookup_category_from_id (const gchar *id) +{ + GList *p; + lglCategory *category; + + if (!categories) + { + lgl_db_init (); + } + + if (id == NULL) + { + /* If no id, return first category as a default */ + return lgl_category_dup ((lglCategory *) categories->data); + } + + for (p = categories; p != NULL; p = p->next) + { + category = (lglCategory *) p->data; + if (ASCII_EQUAL (category->id, id)) + { + return lgl_category_dup (category); + } + } + + return NULL; +} + + +/** + * lgl_db_lookup_category_id_from_name: + * @name: localized category name stringp + * + * Lookup category name string from localized category name string. + * + * Returns: pointer to a newly allocated id string. + * + */ +gchar * +lgl_db_lookup_category_id_from_name (const gchar *name) +{ + lglCategory *category = NULL; + gchar *id = NULL; + + if (name != NULL) + { + category = lgl_db_lookup_category_from_name (name); + if ( category != NULL ) + { + id = g_strdup (category->id); + lgl_category_free (category); + category = NULL; + } + } + + return id; +} + + +/** + * lgl_db_lookup_category_name_from_id: + * @id: category id string + * + * Lookup localized category name string from category id string. + * + * Returns: pointer to a newly allocated localized category name string. + * + */ +gchar * +lgl_db_lookup_category_name_from_id (const gchar *id) +{ + lglCategory *category = NULL; + gchar *name = NULL; + + if (id != NULL) + { + category = lgl_db_lookup_category_from_id (id); + if ( category != NULL ) + { + name = g_strdup (category->name); + lgl_category_free (category); + category = NULL; + } + } + + return name; +} + + +/** + * lgl_db_is_category_id_known: + * @id: category id to test + * + * Determine if given category id is known to libglabels. + * + * Returns: TRUE if id is known, otherwise FALSE. + * + */ +gboolean +lgl_db_is_category_id_known (const gchar *id) +{ + GList *p; + lglCategory *category; + + if (!categories) + { + lgl_db_init (); + } + + if (id == NULL) + { + return FALSE; + } + + for (p = categories; p != NULL; p = p->next) + { + category = (lglCategory *) p->data; + if (ASCII_EQUAL (category->id, id)) + { + return TRUE; + } + } + + return FALSE; +} + + +static GList * +read_categories (void) +{ + gchar *data_dir; + GList *categories = NULL; + + data_dir = LGL_SYSTEM_DATA_DIR; + categories = read_category_files_from_dir (categories, data_dir); + g_free (data_dir); + + data_dir = LGL_USER_DATA_DIR; + categories = read_category_files_from_dir (categories, data_dir); + g_free (data_dir); + + if (categories == NULL) { + g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!")); + } + + return categories; +} + + +static GList * +read_category_files_from_dir (GList *categories, + const gchar *dirname) +{ + GDir *dp; + const gchar *filename, *extension; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_categories = NULL; + + if (dirname == NULL) { + return categories; + } + + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { + return categories; + } + + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) { + g_message ("cannot open data directory: %s", gerror->message ); + return categories; + } + + while ((filename = g_dir_read_name (dp)) != NULL) { + + extension = strrchr (filename, '.'); + + if (extension != NULL) { + + if ( ASCII_EQUAL (extension, ".category") || + ASCII_EQUAL (filename, "categories.xml") ) + { + + full_filename = + g_build_filename (dirname, filename, NULL); + new_categories = + lgl_xml_category_read_categories_from_file (full_filename); + g_free (full_filename); + + categories = g_list_concat (categories, new_categories); + new_categories = NULL; + + } + + } + + } + + g_dir_close (dp); + + return categories; +} + + +/** + * lgl_db_print_known_categories: + * + * For debugging purposes: print a list of all category definitions known to + * libglabels. + * + */ +void +lgl_db_print_known_categories (void) +{ + GList *p; + lglCategory *category; + + if (!categories) { + lgl_db_init (); + } + + g_print ("%s():\n", __FUNCTION__); + for (p = categories; p != NULL; p = p->next) { + category = (lglCategory *) p->data; + + g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name); + + } + g_print ("\n"); + +} + + + +/*===========================================*/ +/* Brand db functions. */ +/*===========================================*/ + +/** + * lgl_db_get_brand_list: + * @paper_id: If non NULL, limit results to given page size. + * @category_id: 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_db_get_brand_list (const gchar *paper_id, + const gchar *category_id) +{ + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + GList *brands = NULL; + + if (!templates) + { + lgl_db_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, paper_id) && + lgl_template_does_category_match (template, category_id)) + { + 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_db_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_db_get_brand_list(). + * + */ +void +lgl_db_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); +} + + + +/*===========================================*/ +/* Template db functions. */ +/*===========================================*/ + +/** + * lgl_db_register_template: + * @template: Pointer to a template structure to add to database. + * + * Register a template. This function adds a template to the template database. + * The template will be stored in an individual XML file in the user template directory. + */ +void +lgl_db_register_template (const lglTemplate *template) +{ + GList *p_tmplt1, *p_a1; + lglTemplate *template1; + lglTemplateAlias *alias1; + + if (!templates) + { + lgl_db_init (); + } + + for (p_tmplt1 = templates; p_tmplt1 != NULL; p_tmplt1 = p_tmplt1->next) + { + template1 = (lglTemplate *) p_tmplt1->data; + + for (p_a1=template1->aliases; p_a1!=NULL; p_a1=p_a1->next) + { + alias1 = (lglTemplateAlias *) p_a1->data; + + if ( UTF8_EQUAL (template->brand, alias1->brand) && + UTF8_EQUAL (template->part, alias1->part) ) + { + + /* FIXME: make sure templates are really identical */ + /* if not, apply hash to name to make unique. */ + return; + } + + } + + } + + if (lgl_db_is_paper_id_known (template->paper_id)) + { + + gchar *dir, *filename, *abs_filename; + + templates = g_list_append (templates, + lgl_template_dup (template)); + + /* FIXME: make sure filename is unique */ + 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); + lgl_xml_template_write_template_to_file (template, abs_filename); + g_free (dir); + g_free (filename); + g_free (abs_filename); + + } + else + { + g_message ("Cannot register new template with unknown page size."); + } + +} + + +/** + * lgl_db_get_template_name_list_unique: + * @brand: If non NULL, limit results to given brand + * @paper_id: If non NULL, limit results to given page size. + * @category_id: If non NULL, limit results to given template category. + * + * Get a list of valid names of unique 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(). + * + * This function differs from lgl_db_get_template_name_list_all(), because it does not + * return multiple names for the same template. + * + * Returns: a list of template names. + */ +GList * +lgl_db_get_template_name_list_unique (const gchar *brand, + const gchar *paper_id, + const gchar *category_id) +{ + GList *p_tmplt; + lglTemplate *template; + gchar *name; + GList *names = NULL; + + if (!templates) + { + lgl_db_init (); + } + + for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + { + template = (lglTemplate *) p_tmplt->data; + + if (lgl_template_does_brand_match (template, brand) && + lgl_template_does_page_size_match (template, paper_id) && + lgl_template_does_category_match (template, category_id)) + { + name = g_strdup_printf ("%s %s", template->brand, template->part); + names = g_list_insert_sorted (names, name, + (GCompareFunc)g_utf8_collate); + } + } + + return names; +} + + +/** + * lgl_db_get_template_name_list_all: + * @brand: If non NULL, limit results to given brand + * @paper_id: If non NULL, limit results to given page size. + * @category_id: If non NULL, limit results to given template category. + * + * Get a list of all valid names and aliases 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(). + * + * This function differs from lgl_db_get_template_name_list_unique(), because it will + * return multiple names for the same template. + * + * Returns: a list of template names and aliases. + */ +GList * +lgl_db_get_template_name_list_all (const gchar *brand, + const gchar *paper_id, + const gchar *category_id) +{ + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + gchar *name; + GList *names = NULL; + + if (!templates) + { + lgl_db_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, paper_id) && + lgl_template_does_category_match (template, category_id)) + { + for (p_alias = template->aliases; p_alias != NULL; + p_alias = p_alias->next) + { + alias = (lglTemplateAlias *)p_alias->data; + + if ( !brand || UTF8_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); + } + } + } + } + + return names; +} + + +/** + * lgl_db_free_template_name_list: + * @names: List of template name strings to be freed. + * + * Free up all storage associated with a list of template names obtained with + * lgl_get_template_name_list_all() or lgl_get_template_name_list_unique(). + * + */ +void +lgl_db_free_template_name_list (GList *names) +{ + GList *p_name; + + for (p_name = names; p_name != NULL; p_name = p_name->next) + { + g_free (p_name->data); + p_name->data = NULL; + } + + g_list_free (names); +} + + +/** + * lgl_db_lookup_template_from_name: + * @name: name string + * + * Lookup template in template database from name string. + * + * Returns: pointer to a newly allocated #lglTemplate structure. + * + */ +lglTemplate * +lgl_db_lookup_template_from_name (const gchar *name) +{ + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + gchar *candidate_name; + + if (!templates) + { + lgl_db_init (); + } + + 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) + { + template = (lglTemplate *) p_tmplt->data; + 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 ( UTF8_EQUAL (candidate_name, name) ) { + g_free (candidate_name); + return lgl_template_dup (template); + } + g_free (candidate_name); + } + } + + /* No matching template has been found so return the first template */ + return lgl_template_dup ((lglTemplate *) templates->data); +} + + +static GList * +read_templates (void) +{ + gchar *data_dir; + GList *templates = NULL; + + data_dir = LGL_SYSTEM_DATA_DIR; + templates = read_template_files_from_dir (templates, data_dir); + g_free (data_dir); + + data_dir = LGL_USER_DATA_DIR; + templates = read_template_files_from_dir (templates, data_dir); + g_free (data_dir); + + if (templates == NULL) + { + g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!")); + } + + return templates; +} + + +static GList * +read_template_files_from_dir (GList *templates, + const gchar *dirname) +{ + GDir *dp; + const gchar *filename, *extension, *extension2; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_templates = NULL; + + if (dirname == NULL) + return templates; + + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) + { + return templates; + } + + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) + { + g_message ("cannot open data directory: %s", gerror->message ); + return templates; + } + + while ((filename = g_dir_read_name (dp)) != NULL) + { + + extension = strrchr (filename, '.'); + extension2 = strrchr (filename, '-'); + + if ( (extension && ASCII_EQUAL (extension, ".template")) || + (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) ) + { + + full_filename = g_build_filename (dirname, filename, NULL); + new_templates = + lgl_xml_template_read_templates_from_file (full_filename); + g_free (full_filename); + + templates = g_list_concat (templates, new_templates); + new_templates = NULL; + } + + } + + g_dir_close (dp); + + return templates; +} + + +static lglTemplate * +template_full_page (const gchar *paper_id) +{ + lglPaper *paper = NULL; + lglTemplate *template = NULL; + lglTemplateFrame *frame = NULL; + gchar *part; + gchar *desc; + + g_return_val_if_fail (paper_id, NULL); + + paper = lgl_db_lookup_paper_from_id (paper_id); + if ( paper == NULL ) + { + return NULL; + } + + part = g_strdup_printf ("%s-Full-Page", paper->id); + desc = g_strdup_printf (_("Generic %s full page template"), paper->name); + + template = lgl_template_new ("Generic", part, desc, + paper_id, paper->width, paper->height); + + + frame = lgl_template_frame_rect_new ("0", + paper->width, + paper->height, + 0.0, + 0.0, + 0.0); + lgl_template_add_frame (template, frame); + + lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.)); + + lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0)); + + g_free (desc); + desc = NULL; + lgl_paper_free (paper); + paper = NULL; + + return template; +} + + +/** + * lgl_db_print_known_templates: + * + * Print all known templates (for debugging purposes). + * + */ +void +lgl_db_print_known_templates (void) +{ + GList *p; + lglTemplate *template; + + g_print ("%s():\n", __FUNCTION__); + for (p=templates; p!=NULL; p=p->next) + { + template = (lglTemplate *)p->data; + + g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n", + template->brand, template->part, template->description); + + } + g_print ("\n"); + +} + +/** + * lgl_db_print_aliases: + * @template: template + * + * Print all aliases of a template (for debugging purposes). + * + */ +void +lgl_db_print_aliases (const lglTemplate *template) +{ + GList *p; + lglTemplateAlias *alias; + + g_print ("%s():\n", __FUNCTION__); + 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"); + +} + + diff --git a/glabels2/libglabels/db.h b/glabels2/libglabels/db.h new file mode 100644 index 00000000..f9dd72aa --- /dev/null +++ b/glabels2/libglabels/db.h @@ -0,0 +1,135 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + +/* + * (LIBGLABELS) Template library for GLABELS + * + * db.h: template db module header file + * + * Copyright (C) 2006-2007 Jim Evins . + * + * This file is part of the LIBGLABELS library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA + */ + +#ifndef __DB_H__ +#define __DB_H__ + +#include +#include + +#include "paper.h" +#include "category.h" +#include "template.h" + +G_BEGIN_DECLS + +/* + * Module initialization + */ +void lgl_db_init (void); + + +/* + * Paper + */ +GList *lgl_db_get_paper_id_list (void); + +void lgl_db_free_paper_id_list (GList *ids); + +GList *lgl_db_get_paper_name_list (void); + +void lgl_db_free_paper_name_list (GList *names); + +lglPaper *lgl_db_lookup_paper_from_name (const gchar *name); + +lglPaper *lgl_db_lookup_paper_from_id (const gchar *id); + +gchar *lgl_db_lookup_paper_id_from_name (const gchar *name); + +gchar *lgl_db_lookup_paper_name_from_id (const gchar *id); + +gboolean lgl_db_is_paper_id_known (const gchar *id); + +gboolean lgl_db_is_paper_id_other (const gchar *id); + + + +/* + * Template categories + */ +GList *lgl_db_get_category_id_list (void); + +void lgl_db_free_category_id_list (GList *ids); + +GList *lgl_db_get_category_name_list (void); + +void lgl_db_free_category_name_list (GList *names); + +lglCategory *lgl_db_lookup_category_from_name (const gchar *name); + +lglCategory *lgl_db_lookup_category_from_id (const gchar *id); + +gchar *lgl_db_lookup_category_id_from_name (const gchar *name); + +gchar *lgl_db_lookup_category_name_from_id (const gchar *id); + +gboolean lgl_db_is_category_id_known (const gchar *id); + + +/* + * Template brands + */ +GList *lgl_db_get_brand_list (const gchar *paper_id, + const gchar *category_id); + +void lgl_db_free_brand_list (GList *brands); + + +/* + * Templates + */ +void lgl_db_register_template (const lglTemplate *template); + +GList *lgl_db_get_template_name_list_unique (const gchar *brand, + const gchar *paper_id, + const gchar *category_id); + +GList *lgl_db_get_template_name_list_all (const gchar *brand, + const gchar *paper_id, + const gchar *category_id); + +void lgl_db_free_template_name_list (GList *names); + +lglTemplate *lgl_db_lookup_template_from_name (const gchar *name); + + +/* + * Debugging functions + */ +void lgl_db_print_known_papers (void); + +void lgl_db_print_known_categories (void); + +void lgl_db_print_known_templates (void); + +void lgl_db_print_aliases (const lglTemplate *template); + + + +G_END_DECLS + +#endif diff --git a/glabels2/libglabels/init.c b/glabels2/libglabels/init.c deleted file mode 100644 index 270d3160..00000000 --- a/glabels2/libglabels/init.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * (LIBGLABELS) Template library for GLABELS - * - * init.c: initialization module - * - * Copyright (C) 2003, 2004 Jim Evins . - * - * This file is part of the LIBGLABELS library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA - */ -#include - -#include "init.h" - -#include "paper.h" -#include "category.h" -#include "template.h" - -/*===========================================*/ -/* Private types */ -/*===========================================*/ - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - - - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -/** - * lgl_init: - * - * Initialize all libglabels subsystems. It is not necessary for an application to call - * lgl_init(), because libglabels will initialize on demand. An application programmer may - * choose to call lgl_init() at startup to minimize the impact of the first libglabels call - * on GUI response time. - * - * This function initializes its paper definitions, category definitions, and its template - * database.. It will search both system and user template directories to locate - * this data. - */ -void -lgl_init (void) -{ - static gboolean initialized = FALSE; - - if (!initialized) - { - - lgl_paper_init(); - lgl_category_init(); - lgl_template_init(); - - initialized = TRUE; - } -} diff --git a/glabels2/libglabels/init.h b/glabels2/libglabels/init.h deleted file mode 100644 index 6a160634..00000000 --- a/glabels2/libglabels/init.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * (LIBGLABELS) Template library for GLABELS - * - * init.h: initialization module header file - * - * Copyright (C) 2007 Jim Evins . - * - * This file is part of the LIBGLABELS library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA - */ - -#ifndef __INIT_H__ -#define __INIT_H__ - -#include - -G_BEGIN_DECLS - - -/* - * Module initialization - */ -void lgl_init (void); - - -G_END_DECLS - -#endif diff --git a/glabels2/libglabels/libglabels-private.h b/glabels2/libglabels/libglabels-private.h index af98b90f..bf171270 100644 --- a/glabels2/libglabels/libglabels-private.h +++ b/glabels2/libglabels/libglabels-private.h @@ -28,6 +28,7 @@ #include #include +#include /* Data system and user data directories. (must free w/ g_free()) */ #define LGL_SYSTEM_DATA_DIR g_build_filename (LIBGLABELS_TEMPLATE_DIR, NULL) @@ -36,9 +37,8 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "LibGlabels" -void lgl_template_init (void); -void lgl_paper_init (void); -void lgl_category_init (void); +#define UTF8_EQUAL(s1,s2) (!g_utf8_collate (s1, s2)) +#define ASCII_EQUAL(s1,s2) (!g_ascii_strcasecmp (s1, s2)) #endif /* __LIBGLABELS_PRIVATE_H__ */ diff --git a/glabels2/libglabels/libglabels.h b/glabels2/libglabels/libglabels.h index 34dffa27..45c62128 100644 --- a/glabels2/libglabels/libglabels.h +++ b/glabels2/libglabels/libglabels.h @@ -26,11 +26,11 @@ #ifndef __LIBGLABELS_H__ #define __LIBGLABELS_H__ -#include -#include +#include #include #include #include +#include #include #include #include diff --git a/glabels2/libglabels/paper.c b/glabels2/libglabels/paper.c index 50ff6419..e4d266a6 100644 --- a/glabels2/libglabels/paper.c +++ b/glabels2/libglabels/paper.c @@ -29,56 +29,29 @@ #include #include #include -#include #include #include #include "libglabels-private.h" -#include "xml-paper.h" - /*===========================================*/ /* Private types */ /*===========================================*/ + /*===========================================*/ /* Private globals */ /*===========================================*/ -static GList *papers = NULL; /*===========================================*/ /* Local function prototypes */ /*===========================================*/ -static GList *read_papers (void); -static GList *read_paper_files_from_dir (GList *papers, - const gchar *dirname); - -/** - * lgl_paper_init: - * - * Initialize libglabels paper module by reading all paper definition - * files located in system and user template directories. - * - * The end user would typically call lgl_init() instead. - */ -void -lgl_paper_init (void) -{ - lglPaper *other; - - if (papers) { - return; /* Already initialized. */ - } - - papers = read_papers (); - - /* Create and append an "Other" entry. */ - other = lgl_paper_new ("Other", _("Other"), 0.0, 0.0); - papers = g_list_append (papers, other); -} +/*===========================================*/ +/* Functions. */ +/*===========================================*/ /** * lgl_paper_new: @@ -161,395 +134,3 @@ void lgl_paper_free (lglPaper *paper) } -/** - * lgl_paper_get_id_list: - * - * Get a list of all paper ids known to libglabels. - * - * Returns: a list of paper ids. - * - */ -GList * -lgl_paper_get_id_list (void) -{ - GList *ids = NULL; - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - for ( p=papers; p != NULL; p=p->next ) { - paper = (lglPaper *)p->data; - ids = g_list_append (ids, g_strdup (paper->id)); - } - - return ids; -} - -/** - * lgl_paper_free_id_list: - * @ids: List of id strings to be freed. - * - * Free up all storage associated with an id list obtained with - * lgl_paper_get_id_list(). - * - */ -void -lgl_paper_free_id_list (GList *ids) -{ - GList *p; - - for (p = ids; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - - g_list_free (ids); -} - - -/** - * lgl_paper_get_name_list: - * - * Get a list of all localized paper names known to libglabels. - * - * Returns: a list of localized paper names. - * - */ -GList * -lgl_paper_get_name_list (void) -{ - GList *names = NULL; - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - for ( p=papers; p != NULL; p=p->next ) { - paper = (lglPaper *)p->data; - names = g_list_append (names, g_strdup (paper->name)); - } - - return names; -} - - -/** - * lgl_paper_free_name_list: - * @names: List of localized paper name strings to be freed. - * - * Free up all storage associated with a name list obtained with - * lgl_paper_get_name_list(). - * - */ -void -lgl_paper_free_name_list (GList *names) -{ - GList *p; - - for (p = names; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - - g_list_free (names); -} - - -/** - * lgl_paper_is_id_known: - * @id: paper id to test - * - * Determine if given paper id is known to libglabels. - * - * Returns: TRUE if id is known, otherwise FALSE. - * - */ -gboolean -lgl_paper_is_id_known (const gchar *id) -{ - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - if (id == NULL) { - return FALSE; - } - - for (p = papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (g_strcasecmp (paper->id, id) == 0) { - return TRUE; - } - } - - return FALSE; -} - - -/** - * lgl_paper_is_id_other: - * @id: paper id to test - * - * Determine if given paper id is the special id "Other." - * - * Returns: TRUE if id is "Other", otherwise FALSE. - * - */ -gboolean -lgl_paper_is_id_other (const gchar *id) -{ - if (id == NULL) { - return FALSE; - } - - return (g_strcasecmp (id, "Other") == 0); -} - - -/** - * lgl_paper_from_id: - * @id: paper id string - * - * Lookup paper definition from id string. - * - * Returns: pointer to a newly allocated #lglPaper structure. - * - */ -lglPaper * -lgl_paper_from_id (const gchar *id) -{ - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - if (id == NULL) { - /* If no id, return first paper as a default */ - return lgl_paper_dup ((lglPaper *) papers->data); - } - - for (p = papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (g_strcasecmp (paper->id, id) == 0) { - return lgl_paper_dup (paper); - } - } - - return NULL; -} - - -/** - * lgl_paper_from_name: - * @name: localized paper name string - * - * Lookup paper definition from localized paper name string. - * - * Returns: pointer to a newly allocated #lglPaper structure. - * - */ -lglPaper * -lgl_paper_from_name (const gchar *name) -{ - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - if (name == NULL) { - /* If no name, return first paper as a default */ - return lgl_paper_dup ((lglPaper *) papers->data); - } - - for (p = papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (g_strcasecmp (paper->name, name) == 0) { - return lgl_paper_dup (paper); - } - } - - return NULL; -} - - -/** - * lgl_paper_lookup_id_from_name: - * @name: localized paper name stringp - * - * Lookup paper name string from localized paper name string. - * - * Returns: pointer to a newly allocated id string. - * - */ -gchar * -lgl_paper_lookup_id_from_name (const gchar *name) -{ - lglPaper *paper = NULL; - gchar *id = NULL; - - if (name != NULL) - { - paper = lgl_paper_from_name (name); - if ( paper != NULL ) - { - id = g_strdup (paper->id); - lgl_paper_free (paper); - paper = NULL; - } - } - - return id; -} - -/** - * lgl_paper_lookup_name_from_id: - * @id: paper id string - * - * Lookup localized paper name string from paper id string. - * - * Returns: pointer to a newly allocated localized paper name string. - * - */ -gchar * -lgl_paper_lookup_name_from_id (const gchar *id) -{ - lglPaper *paper = NULL; - gchar *name = NULL; - - if (id != NULL) - { - paper = lgl_paper_from_id (id); - if ( paper != NULL ) - { - name = g_strdup (paper->name); - lgl_paper_free (paper); - paper = NULL; - } - } - - return name; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read papers from various files. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_papers (void) -{ - gchar *data_dir; - GList *papers = NULL; - - data_dir = LGL_SYSTEM_DATA_DIR; - papers = read_paper_files_from_dir (papers, data_dir); - g_free (data_dir); - - data_dir = LGL_USER_DATA_DIR; - papers = read_paper_files_from_dir (papers, data_dir); - g_free (data_dir); - - if (papers == NULL) { - g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!")); - } - - return papers; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read all paper files from given directory. Append to list. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_paper_files_from_dir (GList *papers, - const gchar *dirname) -{ - GDir *dp; - const gchar *filename, *extension; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_papers = NULL; - - if (dirname == NULL) { - return papers; - } - - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return papers; - } - - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return papers; - } - - while ((filename = g_dir_read_name (dp)) != NULL) { - - extension = strrchr (filename, '.'); - - if (extension != NULL) { - - if ( (g_strcasecmp (extension, ".paper") == 0) - || (g_strcasecmp (filename, "paper-sizes.xml") == 0) ) { - - full_filename = - g_build_filename (dirname, filename, NULL); - new_papers = - lgl_xml_paper_read_papers_from_file (full_filename); - g_free (full_filename); - - papers = g_list_concat (papers, new_papers); - new_papers = NULL; - - } - - } - - } - - g_dir_close (dp); - - return papers; -} - - -/** - * lgl_paper_print_known_papers: - * - * For debugging purposes: print a list of all paper definitions known to - * libglabels. - * - */ -void -lgl_paper_print_known_papers (void) -{ - GList *p; - lglPaper *paper; - - if (!papers) { - lgl_paper_init (); - } - - g_print ("%s():\n", __FUNCTION__); - for (p = papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - - g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n", - paper->id, paper->name, paper->width, paper->height); - - } - g_print ("\n"); - -} - - diff --git a/glabels2/libglabels/paper.h b/glabels2/libglabels/paper.h index 70c7cc77..12fe978f 100644 --- a/glabels2/libglabels/paper.h +++ b/glabels2/libglabels/paper.h @@ -58,39 +58,6 @@ lglPaper *lgl_paper_dup (const lglPaper *orig); void lgl_paper_free (lglPaper *paper); -/* - * ID lists - */ -GList *lgl_paper_get_id_list (void); -void lgl_paper_free_id_list (GList *ids); - - -/* - * Name lists - */ -GList *lgl_paper_get_name_list (void); -void lgl_paper_free_name_list (GList *names); - - -/* - * Query functions - */ -gboolean lgl_paper_is_id_known (const gchar *id); -gboolean lgl_paper_is_id_other (const gchar *id); - -lglPaper *lgl_paper_from_id (const gchar *id); -lglPaper *lgl_paper_from_name (const gchar *name); - -gchar *lgl_paper_lookup_id_from_name (const gchar *name); -gchar *lgl_paper_lookup_name_from_id (const gchar *id); - - -/* - * Debugging - */ -void lgl_paper_print_known_papers (void); - - G_END_DECLS #endif diff --git a/glabels2/libglabels/template.c b/glabels2/libglabels/template.c index 6de739a5..f6d6d212 100644 --- a/glabels2/libglabels/template.c +++ b/glabels2/libglabels/template.c @@ -31,503 +31,46 @@ #include #include #include -#include +#include #include #include #include #include #include "libglabels-private.h" -#include "xml.h" -#include "xml-template.h" -#include "paper.h" -#define EQUAL(s1,s2) (!g_utf8_collate (s1, s2)) +#include "paper.h" /*===========================================*/ /* Private types */ /*===========================================*/ + /*===========================================*/ /* Private globals */ /*===========================================*/ -static GList *templates = NULL; /*===========================================*/ /* Local function prototypes */ /*===========================================*/ -static lglTemplate *template_full_page (const gchar *page_size); - -static GList *read_templates (void); - -static GList *read_template_files_from_dir (GList *templates, - const gchar *dirname); static gint compare_origins (gconstpointer a, gconstpointer b, gpointer user_data); -/** - * lgl_template_init: - * - * Initialize libglabels template module by reading all paper definition - * files located in system and user template directories. - * - * The end user would typically call lgl_init() instead. - */ -void -lgl_template_init (void) -{ - GList *page_sizes, *p; - - if (templates) { - return; /* Already initialized */ - } - - templates = read_templates (); - - page_sizes = lgl_paper_get_id_list (); - for ( p=page_sizes; p != NULL; p=p->next ) { - if ( !lgl_paper_is_id_other (p->data) ) { - templates = g_list_append (templates, - template_full_page (p->data)); - } - } - lgl_paper_free_id_list (page_sizes); -} - -/** - * lgl_template_register: - * @template: Pointer to a template structure to add to database. - * - * Register a template. This function adds a template to the template database. - * The template will be stored in an individual XML file in the user template directory. - */ -void -lgl_template_register (const lglTemplate *template) -{ - GList *p_tmplt1, *p_a1; - lglTemplate *template1; - lglTemplateAlias *alias1; - - if (!templates) { - lgl_template_init (); - } - - for (p_tmplt1 = templates; p_tmplt1 != NULL; p_tmplt1 = p_tmplt1->next) { - template1 = (lglTemplate *) p_tmplt1->data; - - 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. */ - return; - } - - } - - } - - if (lgl_paper_is_id_known (template->page_size)) { - - gchar *dir, *filename, *abs_filename; - - templates = g_list_append (templates, - lgl_template_dup (template)); - - /* FIXME: make sure filename is unique */ - 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); - lgl_xml_template_write_template_to_file (template, abs_filename); - g_free (dir); - g_free (filename); - g_free (abs_filename); - - } else { - g_message ("Cannot register new template with unknown page size."); - } - -} - -/** - * 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. - * - * Get a list of valid names of unique 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(). - * - * This function differs from lgl_template_get_name_list_all(), because it does not - * return multiple names for the same template. - * - * Returns: a list of template names. - */ -GList * -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) - { - lgl_template_init (); - } - - for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) - { - template = (lglTemplate *) p_tmplt->data; - - if (lgl_template_does_brand_match (template, brand) && - lgl_template_does_page_size_match (template, page_size) && - lgl_template_does_category_match (template, category)) - { - name = g_strdup_printf ("%s %s", template->brand, template->part); - names = g_list_insert_sorted (names, name, - (GCompareFunc)g_utf8_collate); - } - } - - return names; -} - -/** - * 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. - * - * Get a list of all valid names and aliases 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(). - * - * This function differs from lgl_template_get_name_list_unique(), because it will - * return multiple names for the same template. - * - * Returns: a list of template names and aliases. - */ -GList * -lgl_template_get_name_list_all (const gchar *brand, - const gchar *page_size, - const gchar *category) -{ - GList *p_tmplt, *p_alias; - lglTemplate *template; - lglTemplateAlias *alias; - gchar *name; - GList *names = 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 ( !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); - } - } - } - } - - return names; -} - - -/** - * lgl_template_free_name_list: - * @names: List of template name strings to be freed. - * - * Free up all storage associated with a list of template names obtained with - * lgl_template_get_name_list_all() or lgl_template_get_name_list_unique(). - * - */ -void -lgl_template_free_name_list (GList *names) -{ - GList *p_name; - - for (p_name = names; p_name != NULL; p_name = p_name->next) - { - g_free (p_name->data); - p_name->data = NULL; - } - - g_list_free (names); -} - -/** - * lgl_template_from_name: - * @name: name string - * - * Lookup template in template database from name string. - * - * Returns: pointer to a newly allocated #lglTemplate structure. - * - */ -lglTemplate * -lgl_template_from_name (const gchar *name) -{ - GList *p_tmplt, *p_alias; - lglTemplate *template; - lglTemplateAlias *alias; - gchar *candidate_name; - - if (!templates) - { - lgl_template_init (); - } - - 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) - { - template = (lglTemplate *) p_tmplt->data; - 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); - } - } - - /* No matching template has been found so return the first template */ - return lgl_template_dup ((lglTemplate *) templates->data); -} - -/** - * lgl_template_frame_get_size: - * @frame: #lglTemplateFrame structure to query - * @w: pointer to location to receive width of frame - * @h: pointer to location to receive height of frame - * - * Get size (width and height) of given #lglTemplateFrame in points. - * - */ -void -lgl_template_frame_get_size (const lglTemplateFrame *frame, - gdouble *w, - gdouble *h) -{ - g_return_if_fail (frame); - - switch (frame->shape) { - case LGL_TEMPLATE_FRAME_SHAPE_RECT: - *w = frame->rect.w; - *h = frame->rect.h; - break; - case LGL_TEMPLATE_FRAME_SHAPE_ROUND: - *w = 2.0 * frame->round.r; - *h = 2.0 * frame->round.r; - break; - case LGL_TEMPLATE_FRAME_SHAPE_CD: - if (frame->cd.w == 0.0) { - *w = 2.0 * frame->cd.r1; - } else { - *w = frame->cd.w; - } - if (frame->cd.h == 0.0) { - *h = 2.0 * frame->cd.r1; - } else { - *h = frame->cd.h; - } - break; - default: - *w = 0.0; - *h = 0.0; - break; - } -} - -/** - * lgl_template_frame_get_n_labels: - * @frame: #lglTemplateFrame structure to query - * - * Get total number of labels per sheet corresponding to the given frame. - * - * Returns: number of labels per sheet. - * - */ -gint -lgl_template_frame_get_n_labels (const lglTemplateFrame *frame) -{ - gint n_labels = 0; - GList *p; - lglTemplateLayout *layout; - - g_return_val_if_fail (frame, 0); - - for ( p=frame->all.layouts; p != NULL; p=p->next ) { - layout = (lglTemplateLayout *)p->data; - - n_labels += layout->nx * layout->ny; - } - - return n_labels; -} - -/** - * lgl_template_frame_get_origins: - * @frame: #lglTemplateFrame structure to query - * - * Get an array of label origins for the given frame. These origins represent the - * upper left hand corner of each label on a page corresponding to the given frame. - * The origins will be ordered geometrically left to right and then top to bottom. - * The array should be freed using g_free(). - * - * Returns: A newly allocated array of #lglTemplateOrigin structures. - * - */ -lglTemplateOrigin * -lgl_template_frame_get_origins (const lglTemplateFrame *frame) -{ - gint i_label, n_labels, ix, iy; - lglTemplateOrigin *origins; - GList *p; - lglTemplateLayout *layout; - - g_return_val_if_fail (frame, NULL); - - n_labels = lgl_template_frame_get_n_labels (frame); - origins = g_new0 (lglTemplateOrigin, n_labels); - - i_label = 0; - for ( p=frame->all.layouts; p != NULL; p=p->next ) { - layout = (lglTemplateLayout *)p->data; - - for (iy = 0; iy < layout->ny; iy++) { - for (ix = 0; ix < layout->nx; ix++, i_label++) { - origins[i_label].x = ix*layout->dx + layout->x0; - origins[i_label].y = iy*layout->dy + layout->y0; - } - } - } - - g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin), - compare_origins, NULL); - - return origins; -} +/*===========================================*/ +/* Functions. */ +/*===========================================*/ /** * lgl_template_new: * @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" - * @page_height: Page height in points, set to zero unless page_size="Other" + * @paper_id: Page size id + * @page_width: Page width in points, set to zero unless paper_id="Other" + * @page_height: Page height in points, set to zero unless paper_id="Other" * * Create a new template structure, with the given top-level attributes. The * created template will have no initial aliases, categories, or frames @@ -541,7 +84,7 @@ lglTemplate * lgl_template_new (const gchar *brand, const gchar *part, const gchar *description, - const gchar *page_size, + const gchar *paper_id, gdouble page_width, gdouble page_height) { @@ -553,7 +96,7 @@ lgl_template_new (const gchar *brand, template->brand = g_strdup (brand); template->part = g_strdup (part); template->description = g_strdup (description); - template->page_size = g_strdup (page_size); + template->paper_id = g_strdup (paper_id); template->page_width = page_width; template->page_height = page_height; @@ -565,6 +108,7 @@ lgl_template_new (const gchar *brand, return template; } + /** * lgl_template_get_name: * @template: Pointer to template structure to test @@ -583,6 +127,7 @@ lgl_template_get_name (const lglTemplate *template) return g_strdup_printf ("%s %s", template->brand, template->part); } + /** * lgl_template_do_templates_match: * @template1: Pointer to 1st template structure to test @@ -601,10 +146,11 @@ lgl_template_do_templates_match (const lglTemplate *template1, 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)); + return (UTF8_EQUAL (template1->brand, template2->brand) && + UTF8_EQUAL (template1->part, template2->part)); } + /** * lgl_template_does_brand_match: * @template: Pointer to template structure to test @@ -627,13 +173,14 @@ lgl_template_does_brand_match (const lglTemplate *template, return TRUE; } - return EQUAL (template->brand, brand); + return UTF8_EQUAL (template->brand, brand); } + /** * lgl_template_does_page_size_match: * @template: Pointer to template structure to test - * @page_size: Page size ID string + * @paper_id: Page size ID string * * This function tests if the page size of the template matches the given ID. * @@ -642,23 +189,24 @@ lgl_template_does_brand_match (const lglTemplate *template, */ gboolean lgl_template_does_page_size_match (const lglTemplate *template, - const gchar *page_size) + const gchar *paper_id) { g_return_val_if_fail (template, FALSE); /* NULL matches everything. */ - if (page_size == NULL) + if (paper_id == NULL) { return TRUE; } - return g_ascii_strcasecmp(page_size, template->page_size) == 0; + return ASCII_EQUAL(paper_id, template->paper_id); } + /** * lgl_template_does_category_match: - * @template: Pointer to template structure to test - * @category: Category ID string + * @template: Pointer to template structure to test + * @category_id: Category ID string * * This function tests if the given template belongs to the given category ID. * @@ -667,21 +215,21 @@ lgl_template_does_page_size_match (const lglTemplate *template, */ gboolean lgl_template_does_category_match (const lglTemplate *template, - const gchar *category) + const gchar *category_id) { GList *p; g_return_val_if_fail (template, FALSE); /* NULL matches everything. */ - if (category == NULL) + if (category_id == NULL) { return TRUE; } - for ( p=template->categories; p != NULL; p=p->next ) + for ( p=template->category_ids; p != NULL; p=p->next ) { - if (g_ascii_strcasecmp(category, p->data) == 0) + if (ASCII_EQUAL(category_id, p->data)) { return TRUE; } @@ -690,6 +238,7 @@ lgl_template_does_category_match (const lglTemplate *template, return FALSE; } + /** * lgl_template_alias_new: * @brand: Alias brand @@ -714,6 +263,7 @@ lgl_template_alias_new (const gchar *brand, return alias; } + /** * lgl_template_add_alias: * @template: Pointer to template structure @@ -732,6 +282,7 @@ lgl_template_add_alias (lglTemplate *template, template->aliases = g_list_append (template->aliases, alias); } + /** * lgl_template_add_frame: * @template: Pointer to template structure @@ -753,25 +304,27 @@ lgl_template_add_frame (lglTemplate *template, template->frames = g_list_append (template->frames, frame); } + /** * lgl_template_add_category: - * @template: Pointer to template structure - * @category: Category ID string + * @template: Pointer to template structure + * @category_id: Category ID string * * This function adds the given category ID to a templates category list. * */ void lgl_template_add_category (lglTemplate *template, - const gchar *category) + const gchar *category_id) { g_return_if_fail (template); - g_return_if_fail (category); + g_return_if_fail (category_id); - template->categories = g_list_append (template->categories, - g_strdup (category)); + template->category_ids = g_list_append (template->category_ids, + g_strdup (category_id)); } + /** * lgl_template_frame_rect_new: @@ -811,6 +364,7 @@ lgl_template_frame_rect_new (const gchar *id, return frame; } + /** * lgl_template_frame_round_new: * @id: ID of frame. (This should currently always be "0"). @@ -839,6 +393,7 @@ lgl_template_frame_round_new (const gchar *id, return frame; } + /** * lgl_template_frame_cd_new: @@ -878,6 +433,124 @@ lgl_template_frame_cd_new (const gchar *id, return frame; } + +/** + * lgl_template_frame_get_size: + * @frame: #lglTemplateFrame structure to query + * @w: pointer to location to receive width of frame + * @h: pointer to location to receive height of frame + * + * Get size (width and height) of given #lglTemplateFrame in points. + * + */ +void +lgl_template_frame_get_size (const lglTemplateFrame *frame, + gdouble *w, + gdouble *h) +{ + g_return_if_fail (frame); + + switch (frame->shape) { + case LGL_TEMPLATE_FRAME_SHAPE_RECT: + *w = frame->rect.w; + *h = frame->rect.h; + break; + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: + *w = 2.0 * frame->round.r; + *h = 2.0 * frame->round.r; + break; + case LGL_TEMPLATE_FRAME_SHAPE_CD: + if (frame->cd.w == 0.0) { + *w = 2.0 * frame->cd.r1; + } else { + *w = frame->cd.w; + } + if (frame->cd.h == 0.0) { + *h = 2.0 * frame->cd.r1; + } else { + *h = frame->cd.h; + } + break; + default: + *w = 0.0; + *h = 0.0; + break; + } +} + + +/** + * lgl_template_frame_get_n_labels: + * @frame: #lglTemplateFrame structure to query + * + * Get total number of labels per sheet corresponding to the given frame. + * + * Returns: number of labels per sheet. + * + */ +gint +lgl_template_frame_get_n_labels (const lglTemplateFrame *frame) +{ + gint n_labels = 0; + GList *p; + lglTemplateLayout *layout; + + g_return_val_if_fail (frame, 0); + + for ( p=frame->all.layouts; p != NULL; p=p->next ) { + layout = (lglTemplateLayout *)p->data; + + n_labels += layout->nx * layout->ny; + } + + return n_labels; +} + + +/** + * lgl_template_frame_get_origins: + * @frame: #lglTemplateFrame structure to query + * + * Get an array of label origins for the given frame. These origins represent the + * upper left hand corner of each label on a page corresponding to the given frame. + * The origins will be ordered geometrically left to right and then top to bottom. + * The array should be freed using g_free(). + * + * Returns: A newly allocated array of #lglTemplateOrigin structures. + * + */ +lglTemplateOrigin * +lgl_template_frame_get_origins (const lglTemplateFrame *frame) +{ + gint i_label, n_labels, ix, iy; + lglTemplateOrigin *origins; + GList *p; + lglTemplateLayout *layout; + + g_return_val_if_fail (frame, NULL); + + n_labels = lgl_template_frame_get_n_labels (frame); + origins = g_new0 (lglTemplateOrigin, n_labels); + + i_label = 0; + for ( p=frame->all.layouts; p != NULL; p=p->next ) { + layout = (lglTemplateLayout *)p->data; + + for (iy = 0; iy < layout->ny; iy++) { + for (ix = 0; ix < layout->nx; ix++, i_label++) { + origins[i_label].x = ix*layout->dx + layout->x0; + origins[i_label].y = iy*layout->dy + layout->y0; + } + } + } + + g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin), + compare_origins, NULL); + + return origins; +} + + /** * lgl_template_frame_add_layout: * @frame: Pointer to template frame to add layout to. @@ -896,6 +569,7 @@ lgl_template_frame_add_layout (lglTemplateFrame *frame, frame->all.layouts = g_list_append (frame->all.layouts, layout); } + /** * lgl_template_frame_add_markup: * @frame: Pointer to template frame to add markup to. @@ -914,6 +588,7 @@ lgl_template_frame_add_markup (lglTemplateFrame *frame, frame->all.markups = g_list_append (frame->all.markups, markup); } + /** * lgl_template_layout_new: * @nx: Number of labels across. @@ -950,6 +625,7 @@ lgl_template_layout_new (gint nx, return layout; } + /** * lgl_template_markup_margin_new: * @size: margin size in points. @@ -972,6 +648,7 @@ lgl_template_markup_margin_new (gdouble size) return markup; } + /** * lgl_template_markup_line_new: * @x1: x coordinate of first endpoint. @@ -1003,6 +680,7 @@ lgl_template_markup_line_new (gdouble x1, return markup; } + /** * lgl_template_markup_circle_new: * @x0: x coordinate of center of circle. @@ -1031,6 +709,7 @@ lgl_template_markup_circle_new (gdouble x0, return markup; } + /** * lgl_template_markup_rect_new: * @x1: x coordinate of top-left corner of rectangle. @@ -1088,7 +767,7 @@ lgl_template_dup (const lglTemplate *orig_template) template = lgl_template_new (orig_template->brand, orig_template->part, orig_template->description, - orig_template->page_size, + orig_template->paper_id, orig_template->page_width, orig_template->page_height); @@ -1096,15 +775,15 @@ lgl_template_dup (const lglTemplate *orig_template) { alias = (lglTemplateAlias *)p->data; - if ( !(EQUAL (template->brand, alias->brand) && - EQUAL (template->part, alias->part)) ) + if ( !(UTF8_EQUAL (template->brand, alias->brand) && + UTF8_EQUAL (template->part, alias->part)) ) { lgl_template_add_alias (template, lgl_template_alias_dup (alias)); } } - for ( p=orig_template->categories; p != NULL; p=p->next ) + for ( p=orig_template->category_ids; p != NULL; p=p->next ) { lgl_template_add_category (template, p->data); } @@ -1119,6 +798,7 @@ lgl_template_dup (const lglTemplate *orig_template) return template; } + /** * lgl_template_free: * @template: Template to free. @@ -1143,8 +823,8 @@ lgl_template_free (lglTemplate *template) g_free (template->description); template->description = NULL; - g_free (template->page_size); - template->page_size = NULL; + g_free (template->paper_id); + template->paper_id = NULL; for ( p=template->aliases; p != NULL; p=p->next ) { @@ -1155,14 +835,14 @@ lgl_template_free (lglTemplate *template) g_list_free (template->aliases); template->aliases = NULL; - for ( p=template->categories; p != NULL; p=p->next ) { + for ( p=template->category_ids; p != NULL; p=p->next ) { g_free (p->data); p->data = NULL; } - g_list_free (template->categories); - template->categories = NULL; + g_list_free (template->category_ids); + template->category_ids = NULL; for ( p=template->frames; p != NULL; p=p->next ) { @@ -1180,6 +860,7 @@ lgl_template_free (lglTemplate *template) } + /** * lgl_template_alias_dup: * @orig_alias: Alias to duplicate. @@ -1197,6 +878,7 @@ lgl_template_alias_dup (const lglTemplateAlias *orig_alias) return lgl_template_alias_new (orig_alias->brand, orig_alias->part); } + /** * lgl_template_alias_free: * @alias: Alias to free. @@ -1220,6 +902,7 @@ lgl_template_alias_free (lglTemplateAlias *alias) } } + /** * lgl_template_frame_dup: * @orig_frame: Frame to duplicate. @@ -1290,6 +973,7 @@ lgl_template_frame_dup (const lglTemplateFrame *orig_frame) return frame; } + /** * lgl_template_frame_free: * @frame: Frame to free. @@ -1335,6 +1019,7 @@ lgl_template_frame_free (lglTemplateFrame *frame) } + /** * lgl_template_layout_dup: * @orig_layout: Layout to duplicate. @@ -1359,6 +1044,7 @@ lgl_template_layout_dup (const lglTemplateLayout *orig_layout) return layout; } + /** * lgl_template_layout_free: * @layout: Layout to free. @@ -1372,6 +1058,7 @@ lgl_template_layout_free (lglTemplateLayout *layout) g_free (layout); } + /** * lgl_template_markup_dup: * @orig_markup: Markup to duplicate. @@ -1395,6 +1082,7 @@ lgl_template_markup_dup (const lglTemplateMarkup *orig_markup) return markup; } + /** * lgl_template_markup_free: * @markup: Markup to free. @@ -1408,129 +1096,7 @@ lgl_template_markup_free (lglTemplateMarkup *markup) g_free (markup); } -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Make a template for a full page of the given page size. */ -/*--------------------------------------------------------------------------*/ -static lglTemplate * -template_full_page (const gchar *page_size) -{ - lglPaper *paper = NULL; - lglTemplate *template = NULL; - lglTemplateFrame *frame = NULL; - gchar *part; - gchar *desc; - - g_return_val_if_fail (page_size, NULL); - - paper = lgl_paper_from_id (page_size); - if ( paper == NULL ) { - return NULL; - } - - part = g_strdup_printf ("%s-Full-Page", paper->id); - desc = g_strdup_printf (_("Generic %s full page template"), paper->name); - - template = lgl_template_new ("Generic", part, desc, - page_size, paper->width, paper->height); - - - frame = lgl_template_frame_rect_new ("0", - paper->width, - paper->height, - 0.0, - 0.0, - 0.0); - lgl_template_add_frame (template, frame); - - lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.)); - lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0)); - - g_free (desc); - desc = NULL; - lgl_paper_free (paper); - paper = NULL; - - return template; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read templates from various files. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_templates (void) -{ - gchar *data_dir; - GList *templates = NULL; - - data_dir = LGL_SYSTEM_DATA_DIR; - templates = read_template_files_from_dir (templates, data_dir); - g_free (data_dir); - - data_dir = LGL_USER_DATA_DIR; - templates = read_template_files_from_dir (templates, data_dir); - g_free (data_dir); - - if (templates == NULL) { - g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!")); - } - - return templates; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Read all template files from given directory. Append to list. */ -/*--------------------------------------------------------------------------*/ -static GList * -read_template_files_from_dir (GList *templates, - const gchar *dirname) -{ - GDir *dp; - const gchar *filename, *extension, *extension2; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_templates = NULL; - - if (dirname == NULL) - return templates; - - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return templates; - } - - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return templates; - } - - while ((filename = g_dir_read_name (dp)) != NULL) { - - extension = strrchr (filename, '.'); - extension2 = strrchr (filename, '-'); - - if ( (extension && (g_ascii_strcasecmp (extension, ".template") == 0)) || - (extension2 && (g_ascii_strcasecmp (extension2, "-templates.xml") == 0)) ) { - - full_filename = g_build_filename (dirname, filename, NULL); - new_templates = - lgl_xml_template_read_templates_from_file (full_filename); - g_free (full_filename); - - templates = g_list_concat (templates, new_templates); - new_templates = NULL; - } - - } - - g_dir_close (dp); - - return templates; -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Sort origins comparison function, first by y then by x. */ -/*--------------------------------------------------------------------------*/ static gint compare_origins (gconstpointer a, gconstpointer b, @@ -1553,53 +1119,3 @@ compare_origins (gconstpointer a, } } -/** - * lgl_template_print_known_templates: - * - * Print all known templates (for debugging purposes). - * - */ -void -lgl_template_print_known_templates (void) -{ - GList *p; - lglTemplate *template; - - g_print ("%s():\n", __FUNCTION__); - for (p=templates; p!=NULL; p=p->next) - { - template = (lglTemplate *)p->data; - - g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n", - template->brand, template->part, template->description); - - } - g_print ("\n"); - -} - -/** - * lgl_template_print_aliases: - * @template: template - * - * Print all aliases of a template (for debugging purposes). - * - */ -void -lgl_template_print_aliases (const lglTemplate *template) -{ - GList *p; - lglTemplateAlias *alias; - - g_print ("%s():\n", __FUNCTION__); - 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"); - -} - diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h index ebc44af6..cbcbccf2 100644 --- a/glabels2/libglabels/template.h +++ b/glabels2/libglabels/template.h @@ -61,7 +61,7 @@ struct _lglTemplate { gchar *brand; gchar *part; gchar *description; - gchar *page_size; + gchar *paper_id; gdouble page_width; gdouble page_height; @@ -69,7 +69,7 @@ struct _lglTemplate { GList *aliases; /* List of (gchar *) category ids. */ - GList *categories; + GList *category_ids; /* List of (lglTemplateFrame *) label frame structures. * Currently glabels only supports a single label frame per @@ -258,32 +258,6 @@ struct _lglTemplateOrigin { -/* - * Template registration - */ -void lgl_template_register (const lglTemplate *template); - -/* - * Known templates query functions - */ -GList *lgl_template_get_brand_list (const gchar *page_size, - const gchar *category); - -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); - -lglTemplate *lgl_template_from_name (const gchar *name); - - /* * Template query functions */ @@ -296,10 +270,10 @@ gboolean lgl_template_does_brand_match (const lglTemplate const gchar *brand); gboolean lgl_template_does_page_size_match (const lglTemplate *template, - const gchar *page_size); + const gchar *paper_id); gboolean lgl_template_does_category_match (const lglTemplate *template, - const gchar *category); + const gchar *category_id); /* @@ -320,7 +294,7 @@ lglTemplateOrigin *lgl_template_frame_get_origins (const lglTemplateFrame lglTemplate *lgl_template_new (const gchar *brand, const gchar *part, const gchar *description, - const gchar *page_size, + const gchar *paper_id, gdouble page_width, gdouble page_height); @@ -328,7 +302,7 @@ void lgl_template_add_alias (lglTemplate *te lglTemplateAlias *alias); void lgl_template_add_category (lglTemplate *template, - const gchar *category); + const gchar *category_id); void lgl_template_add_frame (lglTemplate *template, lglTemplateFrame *frame); @@ -401,13 +375,6 @@ lglTemplateMarkup *lgl_template_markup_dup (const lglTemplateMarkup void lgl_template_markup_free (lglTemplateMarkup *markup); -/* - * Debugging functions - */ -void lgl_template_print_known_templates (void); -void lgl_template_print_aliases (const lglTemplate *template); - - G_END_DECLS #endif diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c index bcb0ffe9..0d03e841 100644 --- a/glabels2/libglabels/xml-template.c +++ b/glabels2/libglabels/xml-template.c @@ -35,7 +35,7 @@ #include "libglabels-private.h" -#include "paper.h" +#include "db.h" #include "xml.h" /*===========================================*/ @@ -201,7 +201,7 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) gchar *part; gchar *name; gchar *description; - gchar *page_size; + gchar *paper_id; gdouble page_width, page_height; lglPaper *paper = NULL; lglTemplate *template; @@ -230,37 +230,37 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) } description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL); - page_size = lgl_xml_get_prop_string (template_node, "size", NULL); + paper_id = lgl_xml_get_prop_string (template_node, "size", NULL); - if (lgl_paper_is_id_other (page_size)) { + if (lgl_db_is_paper_id_other (paper_id)) { page_width = lgl_xml_get_prop_length (template_node, "width", 0); page_height = lgl_xml_get_prop_length (template_node, "height", 0); } else { - paper = lgl_paper_from_id (page_size); + paper = lgl_db_lookup_paper_from_id (paper_id); if (paper == NULL) { /* This should always be an id, but just in case a name slips by! */ g_message (_("Unknown page size id \"%s\", trying as name"), - page_size); - paper = lgl_paper_from_name (page_size); - g_free (page_size); - page_size = g_strdup (paper->id); + paper_id); + paper = lgl_db_lookup_paper_from_name (paper_id); + g_free (paper_id); + paper_id = g_strdup (paper->id); } if (paper != NULL) { page_width = paper->width; page_height = paper->height; } else { g_message (_("Unknown page size id or name \"%s\""), - page_size); + paper_id); } lgl_paper_free (paper); paper = NULL; } template = lgl_template_new (brand, part, description, - page_size, page_width, page_height); + paper_id, page_width, page_height); for (node = template_node->xmlChildrenNode; node != NULL; node = node->next) { @@ -286,7 +286,7 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) g_free (brand); g_free (part); g_free (description); - g_free (page_size); + g_free (paper_id); return template; } @@ -603,7 +603,6 @@ xml_parse_alias_node (xmlNodePtr alias_node, 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); @@ -726,8 +725,8 @@ lgl_xml_template_create_template_node (const lglTemplate *template, 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")) + lgl_xml_set_prop_string (node, "size", template->paper_id); + if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other")) { lgl_xml_set_prop_length (node, "width", template->page_width); @@ -745,7 +744,7 @@ lgl_xml_template_create_template_node (const lglTemplate *template, xml_create_alias_node ( alias, node, ns ); } } - for ( p=template->categories; p != NULL; p=p->next ) + for ( p=template->category_ids; p != NULL; p=p->next ) { xml_create_meta_node ( p->data, node, ns ); } diff --git a/glabels2/src/file.c b/glabels2/src/file.c index d1f20243..58dc4916 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -39,6 +39,7 @@ #include "util.h" #include "window.h" #include "new-label-dialog.h" +#include "libglabels/libglabels.h" #include "debug.h" /*===========================================*/ @@ -142,7 +143,7 @@ new_response (GtkDialog *dialog, rotate_flag = gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); - template = lgl_template_from_name (sheet_name); + template = lgl_db_lookup_template_from_name (sheet_name); label = GL_LABEL(gl_label_new ()); gl_label_set_template (label, template); @@ -194,9 +195,9 @@ gl_file_properties (glLabel *label, g_signal_connect (G_OBJECT(dialog), "response", G_CALLBACK (properties_response), dialog); - if (label->template->page_size != NULL) { + if (label->template->paper_id != NULL) { gl_new_label_dialog_set_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), - label->template->page_size, + label->template->paper_id, NULL); } name = lgl_template_get_name (label->template); @@ -243,7 +244,7 @@ properties_response (GtkDialog *dialog, rotate_flag = gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); - template = lgl_template_from_name (sheet_name); + template = lgl_db_lookup_template_from_name (sheet_name); label = GL_LABEL(g_object_get_data (G_OBJECT (dialog), "label")); gl_label_set_template (label, template); diff --git a/glabels2/src/glabels-batch.c b/glabels2/src/glabels-batch.c index 7e3023b1..01e08145 100644 --- a/glabels2/src/glabels-batch.c +++ b/glabels2/src/glabels-batch.c @@ -31,8 +31,7 @@ #include "xml-label.h" #include "print.h" #include "print-op.h" -#include -#include +#include #include "util.h" #include "debug.h" @@ -121,7 +120,7 @@ main (int argc, char **argv) /* initialize components */ gl_debug_init (); gl_merge_init (); - lgl_init (); + lgl_db_init (); /* now print the files */ for (p = file_list; p; p = p->next) { diff --git a/glabels2/src/glabels.c b/glabels2/src/glabels.c index c6eb728f..832b0821 100644 --- a/glabels2/src/glabels.c +++ b/glabels2/src/glabels.c @@ -34,8 +34,7 @@ #include "stock.h" #include "merge-init.h" #include "recent.h" -#include -#include +#include #include "mini-preview-pixbuf-cache.h" #include "prefs.h" #include "debug.h" @@ -119,7 +118,7 @@ main (int argc, char **argv) /* Initialize subsystems */ gl_debug_init (); gl_stock_init (); - lgl_init (); + lgl_db_init (); gl_prefs_init (); gl_mini_preview_pixbuf_cache_init (); gl_merge_init (); diff --git a/glabels2/src/mini-preview-pixbuf-cache.c b/glabels2/src/mini-preview-pixbuf-cache.c index cdcca3ba..d5b53365 100644 --- a/glabels2/src/mini-preview-pixbuf-cache.c +++ b/glabels2/src/mini-preview-pixbuf-cache.c @@ -26,6 +26,8 @@ #include "mini-preview-pixbuf-cache.h" #include "mini-preview-pixbuf.h" +#include "libglabels/db.h" + #include #include @@ -59,13 +61,13 @@ 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, NULL); + names = lgl_db_get_template_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); + lgl_db_free_template_name_list (names); gl_debug (DEBUG_PIXBUF_CACHE, "END pixbuf_cache=%p", mini_preview_pixbuf_cache); } @@ -81,7 +83,7 @@ gl_mini_preview_pixbuf_cache_add_by_name (gchar *name) gl_debug (DEBUG_PIXBUF_CACHE, "START"); - template = lgl_template_from_name (name); + template = lgl_db_lookup_template_from_name (name); pixbuf = gl_mini_preview_pixbuf_new (template, 72, 72); lgl_template_free (template); diff --git a/glabels2/src/prefs-model.c b/glabels2/src/prefs-model.c index 62b814b4..51832024 100644 --- a/glabels2/src/prefs-model.c +++ b/glabels2/src/prefs-model.c @@ -25,7 +25,7 @@ #include "prefs-model.h" -#include +#include #include "marshal.h" #include "util.h" @@ -506,7 +506,7 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) /* Proof read the default page size -- it must be a valid id. */ /* (For compatability with older versions.) */ /* Note: paper module must be initialized for this to work. */ - paper = lgl_paper_from_id (prefs_model->default_page_size); + paper = lgl_db_lookup_paper_from_id (prefs_model->default_page_size); if ( paper == NULL ) { prefs_model->default_page_size = g_strdup (DEFAULT_PAGE_SIZE); } else { diff --git a/glabels2/src/print.c b/glabels2/src/print.c index ec0420e4..b19c5c5b 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -335,14 +335,14 @@ print_info_new (cairo_t *cr, g_return_val_if_fail (label && GL_IS_LABEL (label), NULL); g_return_val_if_fail (label->template, NULL); - g_return_val_if_fail (label->template->page_size, NULL); + g_return_val_if_fail (label->template->paper_id, NULL); g_return_val_if_fail (label->template->page_width > 0, NULL); g_return_val_if_fail (label->template->page_height > 0, NULL); pi->cr = cr; gl_debug (DEBUG_PRINT, - "setting page size = \"%s\"", label->template->page_size); + "setting page size = \"%s\"", label->template->paper_id); pi->page_width = label->template->page_width; pi->page_height = label->template->page_height; diff --git a/glabels2/src/template-designer.c b/glabels2/src/template-designer.c index 26d25439..097083b3 100644 --- a/glabels2/src/template-designer.c +++ b/glabels2/src/template-designer.c @@ -35,8 +35,7 @@ #include #include "prefs.h" -#include -#include +#include #include "wdgt-mini-preview.h" #include "mini-preview-pixbuf-cache.h" #include "print-op.h" @@ -519,11 +518,11 @@ construct_pg_size_page (glTemplateDesigner *dialog, TRUE); /* Load page size combo */ - page_sizes = lgl_paper_get_name_list (); + page_sizes = lgl_db_get_paper_name_list (); gl_util_combo_box_set_strings (GTK_COMBO_BOX (dialog->priv->pg_size_combo), page_sizes); - lgl_paper_free_name_list (page_sizes); + lgl_db_free_paper_name_list (page_sizes); default_page_size_id = gl_prefs_get_page_size (); - default_page_size_name = lgl_paper_lookup_name_from_id (default_page_size_id); + default_page_size_name = lgl_db_lookup_paper_name_from_id (default_page_size_id); gl_util_combo_box_set_active_text (GTK_COMBO_BOX (dialog->priv->pg_size_combo), default_page_size_name); g_free (default_page_size_name); @@ -1115,7 +1114,7 @@ apply_cb (glTemplateDesigner *dialog) gchar *name; template = build_template (dialog); - lgl_template_register (template); + lgl_db_register_template (template); name = lgl_template_get_name (template); gl_mini_preview_pixbuf_cache_add_by_name (name); g_free (name); @@ -1275,7 +1274,7 @@ pg_size_page_changed_cb (glTemplateDesigner *dialog) if (page_size_name && strlen(page_size_name)) { - paper = lgl_paper_from_name (page_size_name); + paper = lgl_db_lookup_paper_from_name (page_size_name); if ( g_strcasecmp (paper->id, "Other") == 0 ) { @@ -1621,7 +1620,7 @@ build_template (glTemplateDesigner *dialog) page_size_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->pg_size_combo)); - paper = lgl_paper_from_name (page_size_name); + paper = lgl_db_lookup_paper_from_name (page_size_name); if ( g_strcasecmp (paper->id, "Other") == 0 ) { paper->width = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->pg_w_spin)) diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index 7cfbd3e2..6af577a5 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -42,9 +42,7 @@ #include "util.h" #include "color.h" #include "marshal.h" -#include -#include -#include +#include #include "debug.h" @@ -225,34 +223,34 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select) g_object_unref (gui); page_size_id = gl_prefs_get_page_size (); - page_size_name = lgl_paper_lookup_name_from_id (page_size_id); + page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id); /* Brand selection control */ gl_util_combo_box_add_text_model (GTK_COMBO_BOX (media_select->priv->brand_combo)); - brands = lgl_template_get_brand_list (NULL, NULL); + brands = lgl_db_get_brand_list (NULL, NULL); brands = g_list_prepend (brands, g_strdup (_("Any"))); gl_util_combo_box_set_strings (GTK_COMBO_BOX (media_select->priv->brand_combo), brands); - lgl_template_free_brand_list (brands); + lgl_db_free_brand_list (brands); gl_util_combo_box_set_active_text (GTK_COMBO_BOX (media_select->priv->brand_combo), _("Any")); /* Page size selection control */ gl_util_combo_box_add_text_model (GTK_COMBO_BOX (media_select->priv->page_size_combo)); - page_sizes = lgl_paper_get_name_list (); + page_sizes = lgl_db_get_paper_name_list (); page_sizes = g_list_prepend (page_sizes, g_strdup (_("Any"))); gl_util_combo_box_set_strings (GTK_COMBO_BOX (media_select->priv->page_size_combo), page_sizes); - lgl_paper_free_name_list (page_sizes); + lgl_db_free_paper_name_list (page_sizes); gl_util_combo_box_set_active_text (GTK_COMBO_BOX (media_select->priv->page_size_combo), page_size_name); /* Category selection control */ gl_util_combo_box_add_text_model (GTK_COMBO_BOX (media_select->priv->category_combo)); - categories = lgl_category_get_name_list (); + categories = lgl_db_get_category_name_list (); categories = g_list_prepend (categories, g_strdup (_("Any"))); gl_util_combo_box_set_strings (GTK_COMBO_BOX (media_select->priv->category_combo), categories); gl_util_combo_box_set_active_text (GTK_COMBO_BOX (media_select->priv->category_combo), _("Any")); - lgl_category_free_name_list (categories); + lgl_db_free_category_name_list (categories); /* Actual selection control */ media_select->priv->template_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING); @@ -273,9 +271,9 @@ 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 (NULL, page_size_id, NULL); + template_names = lgl_db_get_template_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); + lgl_db_free_template_name_list (template_names); /* Connect signals to controls */ g_signal_connect (G_OBJECT (media_select->priv->brand_combo), "changed", @@ -331,14 +329,14 @@ filter_changed_cb (GtkComboBox *combo, g_free (brand); brand = NULL; } - page_size_id = lgl_paper_lookup_id_from_name (page_size_name); - category_id = lgl_category_lookup_id_from_name (category_name); + page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name); + category_id = lgl_db_lookup_category_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 (brand, page_size_id, category_id); + template_names = lgl_db_get_template_name_list_all (brand, 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); + lgl_db_free_template_name_list (template_names); g_free (page_size_id); g_free (category_id); @@ -463,12 +461,12 @@ gl_wdgt_media_select_get_filter_parameters (glWdgtMediaSelect *media_select, page_size_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (media_select->priv->page_size_combo)); - *page_size_id = lgl_paper_lookup_id_from_name (page_size_name); + *page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name); category_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (media_select->priv->category_combo)); - *category_id = lgl_category_lookup_id_from_name (category_name); + *category_id = lgl_db_lookup_category_id_from_name (category_name); g_free (page_size_name); g_free (category_name); @@ -487,7 +485,7 @@ gl_wdgt_media_select_set_filter_parameters (glWdgtMediaSelect *media_select, gl_debug (DEBUG_MEDIA_SELECT, "START"); - page_size_name = lgl_paper_lookup_name_from_id (page_size_id); + page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id); if (page_size_name == NULL) { page_size_name = g_strdup (_("Any")); @@ -496,7 +494,7 @@ gl_wdgt_media_select_set_filter_parameters (glWdgtMediaSelect *media_select, gl_util_combo_box_set_active_text (GTK_COMBO_BOX (media_select->priv->page_size_combo), page_size_name); - category_name = lgl_category_lookup_name_from_id (category_id); + category_name = lgl_db_lookup_category_name_from_id (category_id); if (category_name == NULL) { category_name = g_strdup (_("Any")); @@ -629,7 +627,7 @@ load_list (GtkListStore *store, gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data); - template = lgl_template_from_name (p->data); + template = lgl_db_lookup_template_from_name (p->data); name = lgl_template_get_name (template); pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (name); diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c index 55f519a4..c539e6bf 100644 --- a/glabels2/src/wdgt-mini-preview.c +++ b/glabels2/src/wdgt-mini-preview.c @@ -28,6 +28,7 @@ #include +#include "libglabels/db.h" #include "cairo-label-path.h" #include "marshal.h" #include "color.h" @@ -259,7 +260,7 @@ void gl_wdgt_mini_preview_set_label_by_name (glWdgtMiniPreview *preview, gl_debug (DEBUG_MINI_PREVIEW, "START"); /* Fetch template */ - template = lgl_template_from_name (name); + template = lgl_db_lookup_template_from_name (name); gl_wdgt_mini_preview_set_template (preview, template); diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index 95c0b804..4edca601 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -35,7 +35,7 @@ #include "marshal.h" #include "color.h" -#include +#include #include "cairo-label-path.h" #include "debug.h" @@ -376,7 +376,7 @@ gl_wdgt_rotate_label_set_template_name (glWdgtRotateLabel *rotate_label, } else { - template = lgl_template_from_name (name); + template = lgl_db_lookup_template_from_name (name); frame = (lglTemplateFrame *)template->frames->data; rotate_label->priv->template = template; diff --git a/glabels2/src/xml-label-04.c b/glabels2/src/xml-label-04.c index 68d146b0..89a94b6b 100644 --- a/glabels2/src/xml-label-04.c +++ b/glabels2/src/xml-label-04.c @@ -34,6 +34,7 @@ #include "label-ellipse.h" #include "label-image.h" #include "label-barcode.h" +#include #include #include "util.h" @@ -148,11 +149,11 @@ xml04_parse_media_description (xmlNodePtr node, template_name = xmlNodeGetContent (node); - template = lgl_template_from_name ((gchar *)template_name); + template = lgl_db_lookup_template_from_name ((gchar *)template_name); if (template == NULL) { g_message ("Undefined template \"%s\"", template_name); /* Get a default */ - template = lgl_template_from_name (NULL); + template = lgl_db_lookup_template_from_name (NULL); ret = FALSE; } else { ret = TRUE; diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index 54f8b633..39729a51 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -42,7 +42,7 @@ #include "label-barcode.h" #include "base64.h" #include "xml-label-04.h" -#include +#include #include #include #include "util.h" @@ -54,6 +54,7 @@ /*========================================================*/ #define COMPAT01_NAME_SPACE "http://snaught.com/glabels/0.1/" #define COMPAT04_NAME_SPACE "http://snaught.com/glabels/0.4/" +#define COMPAT20_NAME_SPACE "http://snaught.com/glabels/2.0/" /*========================================================*/ /* Private types. */ @@ -265,6 +266,10 @@ xml_doc_to_label (xmlDocPtr doc, } ns = xmlSearchNsByHref (doc, root, (xmlChar *)LGL_XML_NAME_SPACE); + if (ns == NULL) { + /* Try compatability mode 2.0 */ + ns = xmlSearchNsByHref (doc, root, (xmlChar *)COMPAT20_NAME_SPACE); + } if (ns != NULL) { label = xml_parse_label (root, status); if (label) @@ -338,7 +343,7 @@ xml_parse_label (xmlNodePtr root, *status = XML_LABEL_UNKNOWN_MEDIA; return NULL; } - lgl_template_register (template); + lgl_db_register_template (template); gl_label_set_template (label, template); lgl_template_free (template); } else if (lgl_xml_is_node (child_node, "Objects")) {