+2007-10-26 Jim Evins <evins@snaught.com>
+
+ * 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 <evins@snaught.com>
* data/glade/wdgt-media-select.glade:
+<SECTION>
+<FILE>db</FILE>
+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
+</SECTION>
+
<SECTION>
<FILE>xml</FILE>
LGL_XML_NAME_SPACE
lglTemplateFrame
lglTemplateMarkupType
lglTemplateMarkup
-lgl_template_register
-lgl_template_get_brand_list
-lgl_template_free_brand_list
-lgl_template_get_name_list_unique
-lgl_template_get_name_list_all
-lgl_template_free_name_list
-lgl_template_from_name
lgl_template_get_name
lgl_template_do_templates_match
lgl_template_does_brand_match
lgl_template_layout_free
lgl_template_markup_dup
lgl_template_markup_free
-lgl_template_print_known_templates
-lgl_template_print_aliases
</SECTION>
<SECTION>
lgl_xml_category_parse_category_node
</SECTION>
-<SECTION>
-<FILE>init</FILE>
-lgl_init
-</SECTION>
-
<SECTION>
<FILE>category</FILE>
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
</SECTION>
<SECTION>
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
</SECTION>
<title>LibGlabels Reference Manual</title>
</bookinfo>
- <part>
+ <chapter>
<title>Basic LibGlabels Usage</title>
- <xi:include href="xml/init.xml"/>
- <chapter>
- <title>Templates</title>
- <xi:include href="xml/template-struct.xml"/>
- <xi:include href="xml/template-db.xml"/>
- <xi:include href="xml/template-construction.xml"/>
- <xi:include href="xml/template-misc.xml"/>
- </chapter>
+ <xi:include href="xml/db.xml"/>
+ <xi:include href="xml/template.xml"/>
<xi:include href="xml/paper.xml"/>
<xi:include href="xml/category.xml"/>
<xi:include href="xml/enums.xml"/>
- </part>
+ </chapter>
- <part>
+ <chapter>
<title>Working Directly With LibGlabels XML</title>
<xi:include href="xml/xml-paper.xml"/>
<xi:include href="xml/xml-category.xml"/>
<xi:include href="xml/xml-template.xml"/>
<xi:include href="xml/xml.xml"/>
- </part>
+ </chapter>
</book>
<SECTION>
-<FILE>init</FILE>
-<INCLUDE>libglabels/libglabels.h</INCLUDE>
-lgl_init
+<FILE>db</FILE>
+<INCLUDE>libglabels/db.h</INCLUDE>
+lgl_db_init
+<SUBSECTION Paper Functions>
+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
+<SUBSECTION Category Functions>
+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
+<SUBSECTION Brand Functions>
+lgl_db_get_brand_list
+lgl_db_free_brand_list
+<SUBSECTION Template Functions>
+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
+<SUBSECTION Debugging Functions>
+lgl_db_print_known_papers
+lgl_db_print_known_categories
+lgl_db_print_known_templates
+lgl_db_print_aliases
</SECTION>
<SECTION>
-<FILE>enums</FILE>
-<INCLUDE>libglabels/enums.h</INCLUDE>
-lglUnitsType
-</SECTION>
-
-<SECTION>
-<FILE>paper</FILE>
-<INCLUDE>libglabels/paper.h</INCLUDE>
-lglPaper
-lgl_paper_new
-lgl_paper_dup
-lgl_paper_free
-lgl_paper_from_id
-lgl_paper_from_name
-<SUBSECTION List Functions>
-lgl_paper_get_id_list
-lgl_paper_free_id_list
-lgl_paper_get_name_list
-lgl_paper_free_name_list
-<SUBSECTION Query Functions>
-lgl_paper_is_id_known
-lgl_paper_is_id_other
-<SUBSECTION Conversion Functions>
-lgl_paper_lookup_id_from_name
-lgl_paper_lookup_name_from_id
-<SUBSECTION Debug Functions>
-lgl_paper_print_known_papers
-</SECTION>
-
-<SECTION>
-<FILE>category</FILE>
-<INCLUDE>libglabels/category.h</INCLUDE>
-lglCategory
-lgl_category_new
-lgl_category_dup
-lgl_category_free
-lgl_category_from_name
-lgl_category_from_id
-<SUBSECTION List Functions>
-lgl_category_get_id_list
-lgl_category_free_id_list
-lgl_category_get_name_list
-lgl_category_free_name_list
-<SUBSECTION Conversion Functions>
-lgl_category_lookup_id_from_name
-lgl_category_lookup_name_from_id
-</SECTION>
-
-<SECTION>
-<FILE>template-struct</FILE>
+<FILE>template</FILE>
<INCLUDE>libglabels/template.h</INCLUDE>
lglTemplate
<SUBSECTION Alias Structure>
lglTemplateMarkupRect
<SUBSECTION Origin Structure>
lglTemplateOrigin
-<SUBSECTION Template Query Functions>
-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
-<SUBSECTION Frame Frame Query Functions>
-lgl_template_frame_get_size
-lgl_template_frame_get_n_labels
-lgl_template_frame_get_origins
-</SECTION>
-
-<SECTION>
-<FILE>template-db</FILE>
-<INCLUDE>libglabels/template.h</INCLUDE>
-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
-<SUBSECTION Locate Template Functions>
-lgl_template_from_name
-<SUBSECTION Template Registration Functions>
-lgl_template_register
-</SECTION>
-
-<SECTION>
-<FILE>template-construction</FILE>
-<INCLUDE>libglabels/template.h</INCLUDE>
+<SUBSECTION Template Functions>
lgl_template_new
lgl_template_dup
lgl_template_free
lgl_template_add_category
lgl_template_add_frame
lgl_template_add_alias
+<SUBSECTION Template Query Functions>
+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
<SUBSECTION Alias Functions>
lgl_template_alias_new
lgl_template_alias_dup
lgl_template_frame_free
lgl_template_frame_add_layout
lgl_template_frame_add_markup
+<SUBSECTION Frame Frame Query Functions>
+lgl_template_frame_get_size
+lgl_template_frame_get_n_labels
+lgl_template_frame_get_origins
<SUBSECTION Layout Functions>
lgl_template_layout_new
lgl_template_layout_dup
</SECTION>
<SECTION>
-<FILE>template-misc</FILE>
-<INCLUDE>libglabels/template.h</INCLUDE>
-lgl_template_print_known_templates
-lgl_template_print_aliases
+<FILE>paper</FILE>
+<INCLUDE>libglabels/paper.h</INCLUDE>
+lglPaper
+lgl_paper_new
+lgl_paper_dup
+lgl_paper_free
+</SECTION>
+
+<SECTION>
+<FILE>category</FILE>
+<INCLUDE>libglabels/category.h</INCLUDE>
+lglCategory
+lgl_category_new
+lgl_category_dup
+lgl_category_free
+</SECTION>
+
+<SECTION>
+<FILE>enums</FILE>
+<INCLUDE>libglabels/enums.h</INCLUDE>
+lglUnitsType
</SECTION>
<SECTION>
99% symbol docs coverage.
-139 symbols documented.
+135 symbols documented.
0 symbols incomplete.
1 not documented.
<!-- ##### SECTION Title ##### -->
-Categories
+The lglCategory Structure
<!-- ##### SECTION Short_Description ##### -->
Template category definitions
<!-- ##### SECTION Long_Description ##### -->
<para>
-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.
</para>
@category:
-<!-- ##### FUNCTION lgl_category_from_name ##### -->
-<para>
-
-</para>
-
-@name:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_category_from_id ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_category_get_id_list ##### -->
-<para>
-
-</para>
-
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_category_free_id_list ##### -->
-<para>
-
-</para>
-
-@ids:
-
-
-<!-- ##### FUNCTION lgl_category_get_name_list ##### -->
-<para>
-
-</para>
-
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_category_free_name_list ##### -->
-<para>
-
-</para>
-
-@names:
-
-
-<!-- ##### FUNCTION lgl_category_lookup_id_from_name ##### -->
-<para>
-
-</para>
-
-@name:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_category_lookup_name_from_id ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
--- /dev/null
+<!-- ##### SECTION Title ##### -->
+Database
+
+<!-- ##### SECTION Short_Description ##### -->
+Database of pre-defined templates
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+This section describes a set of functions to locate and add templates and related information in
+the LibGlabels template database.
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### FUNCTION lgl_db_init ##### -->
+<para>
+
+</para>
+
+
+
+<!-- ##### FUNCTION lgl_db_get_paper_id_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_paper_id_list ##### -->
+<para>
+
+</para>
+
+@ids:
+
+
+<!-- ##### FUNCTION lgl_db_get_paper_name_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_paper_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_paper_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_paper_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_paper_id_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_paper_name_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_is_paper_id_known ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_is_paper_id_other ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_get_category_id_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_category_id_list ##### -->
+<para>
+
+</para>
+
+@ids:
+
+
+<!-- ##### FUNCTION lgl_db_get_category_name_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_category_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_category_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_category_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_category_id_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_category_name_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_is_category_id_known ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_get_brand_list ##### -->
+<para>
+
+</para>
+
+@paper_id:
+@category_id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_brand_list ##### -->
+<para>
+
+</para>
+
+@brands:
+
+
+<!-- ##### FUNCTION lgl_db_register_template ##### -->
+<para>
+
+</para>
+
+@template:
+
+
+<!-- ##### FUNCTION lgl_db_get_template_name_list_unique ##### -->
+<para>
+
+</para>
+
+@brand:
+@paper_id:
+@category_id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_get_template_name_list_all ##### -->
+<para>
+
+</para>
+
+@brand:
+@paper_id:
+@category_id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_free_template_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+
+<!-- ##### FUNCTION lgl_db_lookup_template_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_db_print_known_papers ##### -->
+<para>
+
+</para>
+
+
+
+<!-- ##### FUNCTION lgl_db_print_known_categories ##### -->
+<para>
+
+</para>
+
+
+
+<!-- ##### FUNCTION lgl_db_print_known_templates ##### -->
+<para>
+
+</para>
+
+
+
+<!-- ##### FUNCTION lgl_db_print_aliases ##### -->
+<para>
+
+</para>
+
+@template:
+
+
+++ /dev/null
-<!-- ##### SECTION Title ##### -->
-Initialization
-
-<!-- ##### SECTION Short_Description ##### -->
-Initialization of the LibGlabels library.
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section describes the LibGlabels initialization function.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### FUNCTION lgl_init ##### -->
-<para>
-
-</para>
-
-
-
+<!-- ##### SECTION ./tmpl/init.sgml:Long_Description ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION ./tmpl/init.sgml:See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION ./tmpl/init.sgml:Short_Description ##### -->
+
+
+
+<!-- ##### SECTION ./tmpl/init.sgml:Stability_Level ##### -->
+
+
+
+<!-- ##### SECTION ./tmpl/init.sgml:Title ##### -->
+init
+
+
<!-- ##### SECTION ./tmpl/libglabels.sgml:Long_Description ##### -->
<para>
libglabels
-<!-- ##### SECTION ./tmpl/template.sgml:Long_Description ##### -->
+<!-- ##### SECTION ./tmpl/template-construction.sgml:Long_Description ##### -->
+<para>
+This section describes a set of functions for constructing new template structures.
+</para>
+
+
+<!-- ##### SECTION ./tmpl/template-construction.sgml:See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION ./tmpl/template-construction.sgml:Short_Description ##### -->
+Functions to help create new templates
+
+
+<!-- ##### SECTION ./tmpl/template-construction.sgml:Stability_Level ##### -->
+
+
+
+<!-- ##### SECTION ./tmpl/template-construction.sgml:Title ##### -->
+Construction Functions
+
+
+<!-- ##### SECTION ./tmpl/template-db.sgml:Long_Description ##### -->
+<para>
+This section describes a set of functions to locate pre-defined templates and add templates
+to the LibGlabels template database.
+</para>
+
+
+<!-- ##### SECTION ./tmpl/template-db.sgml:See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION ./tmpl/template-db.sgml:Short_Description ##### -->
+Database of pre-defined templates
+
+
+<!-- ##### SECTION ./tmpl/template-db.sgml:Stability_Level ##### -->
+
+
+
+<!-- ##### SECTION ./tmpl/template-db.sgml:Title ##### -->
+Database
+
+
+<!-- ##### SECTION ./tmpl/template-misc.sgml:Long_Description ##### -->
<para>
-This section describes a set of structures representing stationary templates and related
-functions.
+This section describes miscellaneous template functions.
</para>
-<!-- ##### SECTION ./tmpl/template.sgml:See_Also ##### -->
+<!-- ##### SECTION ./tmpl/template-misc.sgml:See_Also ##### -->
<para>
</para>
-<!-- ##### SECTION ./tmpl/template.sgml:Short_Description ##### -->
-Template definitions
+<!-- ##### SECTION ./tmpl/template-misc.sgml:Short_Description ##### -->
+Miscellaneous template functions
-<!-- ##### SECTION ./tmpl/template.sgml:Stability_Level ##### -->
+<!-- ##### SECTION ./tmpl/template-misc.sgml:Stability_Level ##### -->
-<!-- ##### SECTION ./tmpl/template.sgml:Title ##### -->
-Templates
+<!-- ##### SECTION ./tmpl/template-misc.sgml:Title ##### -->
+Miscellaneous Functions
<!-- ##### SECTION ./tmpl/template2.sgml:Long_Description ##### -->
@templates:
@utf8_filename:
+<!-- ##### FUNCTION lgl_category_free_id_list ##### -->
+<para>
+
+</para>
+
+@ids:
+
+<!-- ##### FUNCTION lgl_category_free_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+<!-- ##### FUNCTION lgl_category_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_category_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+<!-- ##### FUNCTION lgl_category_get_id_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+<!-- ##### FUNCTION lgl_category_get_name_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
<!-- ##### FUNCTION lgl_category_init ##### -->
<para>
</para>
+<!-- ##### FUNCTION lgl_category_lookup_id_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+<!-- ##### FUNCTION lgl_category_lookup_name_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_init ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION lgl_paper_free_id_list ##### -->
+<para>
+
+</para>
+
+@ids:
+
+<!-- ##### FUNCTION lgl_paper_free_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+<!-- ##### FUNCTION lgl_paper_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_get_id_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_get_name_list ##### -->
+<para>
+
+</para>
+
+@Returns:
+
<!-- ##### FUNCTION lgl_paper_init ##### -->
<para>
</para>
+<!-- ##### FUNCTION lgl_paper_is_id_known ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_is_id_other ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_lookup_id_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_lookup_name_from_id ##### -->
+<para>
+
+</para>
+
+@id:
+@Returns:
+
+<!-- ##### FUNCTION lgl_paper_print_known_papers ##### -->
+<para>
+
+</para>
+
+
<!-- ##### FUNCTION lgl_template_add_layout ##### -->
<para>
@frame:
@markup:
+<!-- ##### FUNCTION lgl_template_free_brand_list ##### -->
+<para>
+
+</para>
+
+@brands:
+
+<!-- ##### FUNCTION lgl_template_free_name_list ##### -->
+<para>
+
+</para>
+
+@names:
+
+<!-- ##### FUNCTION lgl_template_from_name ##### -->
+<para>
+
+</para>
+
+@name:
+@Returns:
+
+<!-- ##### FUNCTION lgl_template_get_brand_list ##### -->
+<para>
+
+</para>
+
+@page_size:
+@category:
+@Returns:
+
<!-- ##### FUNCTION lgl_template_get_first_frame ##### -->
<para>
@template:
@Returns:
+<!-- ##### FUNCTION lgl_template_get_name_list_all ##### -->
+<para>
+
+</para>
+
+@brand:
+@page_size:
+@category:
+@Returns:
+
+<!-- ##### FUNCTION lgl_template_get_name_list_unique ##### -->
+<para>
+
+</para>
+
+@brand:
+@page_size:
+@category:
+@Returns:
+
<!-- ##### FUNCTION lgl_template_init ##### -->
<para>
</para>
+<!-- ##### FUNCTION lgl_template_print_aliases ##### -->
+<para>
+
+</para>
+
+@template:
+
+<!-- ##### FUNCTION lgl_template_print_known_templates ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION lgl_template_register ##### -->
+<para>
+
+</para>
+
+@template:
+
<!-- ##### FUNCTION lgl_xml_template_create_templates_doc ##### -->
<para>
<!-- ##### SECTION Title ##### -->
-Paper Sizes
+The lglPaper Structure
<!-- ##### SECTION Short_Description ##### -->
Paper size definitions
@paper:
-<!-- ##### FUNCTION lgl_paper_from_id ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_from_name ##### -->
-<para>
-
-</para>
-
-@name:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_get_id_list ##### -->
-<para>
-
-</para>
-
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_free_id_list ##### -->
-<para>
-
-</para>
-
-@ids:
-
-
-<!-- ##### FUNCTION lgl_paper_get_name_list ##### -->
-<para>
-
-</para>
-
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_free_name_list ##### -->
-<para>
-
-</para>
-
-@names:
-
-
-<!-- ##### FUNCTION lgl_paper_is_id_known ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_is_id_other ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_lookup_id_from_name ##### -->
-<para>
-
-</para>
-
-@name:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_lookup_name_from_id ##### -->
-<para>
-
-</para>
-
-@id:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_paper_print_known_papers ##### -->
-<para>
-
-</para>
-
-
-
+++ /dev/null
-<!-- ##### SECTION Title ##### -->
-Construction Functions
-
-<!-- ##### SECTION Short_Description ##### -->
-Functions to help create new templates
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section describes a set of functions for constructing new template structures.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### FUNCTION lgl_template_new ##### -->
-<para>
-
-</para>
-
-@brand:
-@part:
-@description:
-@page_size:
-@page_width:
-@page_height:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_dup ##### -->
-<para>
-
-</para>
-
-@orig_template:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_free ##### -->
-<para>
-
-</para>
-
-@template:
-
-
-<!-- ##### FUNCTION lgl_template_add_category ##### -->
-<para>
-
-</para>
-
-@template:
-@category:
-
-
-<!-- ##### FUNCTION lgl_template_add_frame ##### -->
-<para>
-
-</para>
-
-@template:
-@frame:
-
-
-<!-- ##### FUNCTION lgl_template_add_alias ##### -->
-<para>
-
-</para>
-
-@template:
-@alias:
-
-
-<!-- ##### FUNCTION lgl_template_alias_new ##### -->
-<para>
-
-</para>
-
-@brand:
-@part:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_alias_dup ##### -->
-<para>
-
-</para>
-
-@orig_alias:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_alias_free ##### -->
-<para>
-
-</para>
-
-@alias:
-
-
-<!-- ##### FUNCTION lgl_template_frame_rect_new ##### -->
-<para>
-
-</para>
-
-@id:
-@w:
-@h:
-@r:
-@x_waste:
-@y_waste:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_round_new ##### -->
-<para>
-
-</para>
-
-@id:
-@r:
-@waste:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_cd_new ##### -->
-<para>
-
-</para>
-
-@id:
-@r1:
-@r2:
-@w:
-@h:
-@waste:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_dup ##### -->
-<para>
-
-</para>
-
-@orig_frame:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_free ##### -->
-<para>
-
-</para>
-
-@frame:
-
-
-<!-- ##### FUNCTION lgl_template_frame_add_layout ##### -->
-<para>
-
-</para>
-
-@frame:
-@layout:
-
-
-<!-- ##### FUNCTION lgl_template_frame_add_markup ##### -->
-<para>
-
-</para>
-
-@frame:
-@markup:
-
-
-<!-- ##### FUNCTION lgl_template_layout_new ##### -->
-<para>
-
-</para>
-
-@nx:
-@ny:
-@x0:
-@y0:
-@dx:
-@dy:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_layout_dup ##### -->
-<para>
-
-</para>
-
-@orig_layout:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_layout_free ##### -->
-<para>
-
-</para>
-
-@layout:
-
-
-<!-- ##### FUNCTION lgl_template_markup_margin_new ##### -->
-<para>
-
-</para>
-
-@size:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_markup_line_new ##### -->
-<para>
-
-</para>
-
-@x1:
-@y1:
-@x2:
-@y2:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_markup_circle_new ##### -->
-<para>
-
-</para>
-
-@x0:
-@y0:
-@r:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_markup_rect_new ##### -->
-<para>
-
-</para>
-
-@x1:
-@y1:
-@w:
-@h:
-@r:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_markup_dup ##### -->
-<para>
-
-</para>
-
-@orig_markup:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_markup_free ##### -->
-<para>
-
-</para>
-
-@markup:
-
-
+++ /dev/null
-<!-- ##### SECTION Title ##### -->
-Database
-
-<!-- ##### SECTION Short_Description ##### -->
-Database of pre-defined templates
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section describes a set of functions to locate pre-defined templates and add templates
-to the LibGlabels template database.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### FUNCTION lgl_template_get_name_list_unique ##### -->
-<para>
-
-</para>
-
-@brand:
-@page_size:
-@category:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_get_name_list_all ##### -->
-<para>
-
-</para>
-
-@brand:
-@page_size:
-@category:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_free_name_list ##### -->
-<para>
-
-</para>
-
-@names:
-
-
-<!-- ##### FUNCTION lgl_template_get_brand_list ##### -->
-<para>
-
-</para>
-
-@page_size:
-@category:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_free_brand_list ##### -->
-<para>
-
-</para>
-
-@brands:
-
-
-<!-- ##### FUNCTION lgl_template_from_name ##### -->
-<para>
-
-</para>
-
-@name:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_register ##### -->
-<para>
-
-</para>
-
-@template:
-
-
+++ /dev/null
-<!-- ##### SECTION Title ##### -->
-Miscellaneous Functions
-
-<!-- ##### SECTION Short_Description ##### -->
-Miscellaneous template functions
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section describes miscellaneous template functions.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### FUNCTION lgl_template_print_known_templates ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### FUNCTION lgl_template_print_aliases ##### -->
-<para>
-
-</para>
-
-@template:
-
-
+++ /dev/null
-<!-- ##### SECTION Title ##### -->
-The lglTemplate Structure
-
-<!-- ##### SECTION Short_Description ##### -->
-How templates are represented in memory
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section describes a set of structures that represent a template in memory. It also
-describes functions to help interpret these structures.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### STRUCT lglTemplate ##### -->
-<para>
-This is the main structure of a libglabels template. A template represents a single sheet
-of peel-off labels or cards.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateAlias ##### -->
-<para>
-This structure defines an alias for the parent template structure. An alias is used for
-different products that can use the same template.
-</para>
-
-@brand: Brand name of label or card. E.g. "Avery."
-@part: Part name or number of label or card. E.g. "8160."
-
-<!-- ##### ENUM lglTemplateFrameShape ##### -->
-<para>
-This enumeration defines frame types that are supported by libglabels
-</para>
-
-@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.)
-
-<!-- ##### UNION lglTemplateFrame ##### -->
-<para>
-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.
-</para>
-
-
-<!-- ##### STRUCT lglTemplateFrameAll ##### -->
-<para>
-This structure is composed of a set of fields common to all frame structures. All frame types
-can be cast to this structure.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateFrameRect ##### -->
-<para>
-This structure defines the frame for a rectangular label or card.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateFrameRound ##### -->
-<para>
-This structure defines the frame for a round label or card.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateFrameCD ##### -->
-<para>
-This structure defines the frame for a CD or DVD label. This structure also supports
-credit-card CD labels.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateLayout ##### -->
-<para>
-This structure defines a simple grid layout of labels or cards.
-</para>
-
-@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).
-
-<!-- ##### ENUM lglTemplateMarkupType ##### -->
-<para>
-This enumeration defines markup types that are supported by libglabels
-</para>
-
-@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.
-
-<!-- ##### UNION lglTemplateMarkup ##### -->
-<para>
-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.
-</para>
-
-
-<!-- ##### STRUCT lglTemplateMarkupMargin ##### -->
-<para>
-This structure defines a simple margin markup around the perimeter of a label or card.
-</para>
-
-@type: Common field. Always #LGL_TEMPLATE_MARKUP_MARGIN for #lglTemplateMarkupMargin.
-@size: Distance of margin from edge of label or card.
-
-<!-- ##### STRUCT lglTemplateMarkupLine ##### -->
-<para>
-This structure defines a simple line segment markup.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateMarkupCircle ##### -->
-<para>
-This structure defines a simple circle markup.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateMarkupRect ##### -->
-<para>
-This structure defines a simple rectangle markup. The rectangle can have rounded corners.
-</para>
-
-@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.
-
-<!-- ##### STRUCT lglTemplateOrigin ##### -->
-<para>
-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.
-</para>
-
-@x: Distance in points from top edge of page.
-@y: Distance in points from left edge of page.
-
-<!-- ##### FUNCTION lgl_template_get_name ##### -->
-<para>
-
-</para>
-
-@template:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_do_templates_match ##### -->
-<para>
-
-</para>
-
-@template1:
-@template2:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_does_brand_match ##### -->
-<para>
-
-</para>
-
-@template:
-@brand:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_does_page_size_match ##### -->
-<para>
-
-</para>
-
-@template:
-@page_size:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_does_category_match ##### -->
-<para>
-
-</para>
-
-@template:
-@category:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_get_size ##### -->
-<para>
-
-</para>
-
-@frame:
-@w:
-@h:
-
-
-<!-- ##### FUNCTION lgl_template_frame_get_n_labels ##### -->
-<para>
-
-</para>
-
-@frame:
-@Returns:
-
-
-<!-- ##### FUNCTION lgl_template_frame_get_origins ##### -->
-<para>
-
-</para>
-
-@frame:
-@Returns:
-
-
--- /dev/null
+<!-- ##### SECTION Title ##### -->
+The lglTemplate Structure
+
+<!-- ##### SECTION Short_Description ##### -->
+How templates are represented in memory
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+This section describes a set of structures that represent a template in memory. It also
+describes functions to help create and interpret these structures.
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### STRUCT lglTemplate ##### -->
+<para>
+This is the main structure of a libglabels template. A template represents a single sheet
+of peel-off labels or cards.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateAlias ##### -->
+<para>
+This structure defines an alias for the parent template structure. An alias is used for
+different products that can use the same template.
+</para>
+
+@brand: Brand name of label or card. E.g. "Avery."
+@part: Part name or number of label or card. E.g. "8160."
+
+<!-- ##### ENUM lglTemplateFrameShape ##### -->
+<para>
+This enumeration defines frame types that are supported by libglabels
+</para>
+
+@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.)
+
+<!-- ##### UNION lglTemplateFrame ##### -->
+<para>
+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.
+</para>
+
+
+<!-- ##### STRUCT lglTemplateFrameAll ##### -->
+<para>
+This structure is composed of a set of fields common to all frame structures. All frame types
+can be cast to this structure.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateFrameRect ##### -->
+<para>
+This structure defines the frame for a rectangular label or card.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateFrameRound ##### -->
+<para>
+This structure defines the frame for a round label or card.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateFrameCD ##### -->
+<para>
+This structure defines the frame for a CD or DVD label. This structure also supports
+credit-card CD labels.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateLayout ##### -->
+<para>
+This structure defines a simple grid layout of labels or cards.
+</para>
+
+@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).
+
+<!-- ##### ENUM lglTemplateMarkupType ##### -->
+<para>
+This enumeration defines markup types that are supported by libglabels
+</para>
+
+@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.
+
+<!-- ##### UNION lglTemplateMarkup ##### -->
+<para>
+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.
+</para>
+
+
+<!-- ##### STRUCT lglTemplateMarkupMargin ##### -->
+<para>
+This structure defines a simple margin markup around the perimeter of a label or card.
+</para>
+
+@type: Common field. Always #LGL_TEMPLATE_MARKUP_MARGIN for #lglTemplateMarkupMargin.
+@size: Distance of margin from edge of label or card.
+
+<!-- ##### STRUCT lglTemplateMarkupLine ##### -->
+<para>
+This structure defines a simple line segment markup.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateMarkupCircle ##### -->
+<para>
+This structure defines a simple circle markup.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateMarkupRect ##### -->
+<para>
+This structure defines a simple rectangle markup. The rectangle can have rounded corners.
+</para>
+
+@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.
+
+<!-- ##### STRUCT lglTemplateOrigin ##### -->
+<para>
+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.
+</para>
+
+@x: Distance in points from top edge of page.
+@y: Distance in points from left edge of page.
+
+<!-- ##### FUNCTION lgl_template_new ##### -->
+<para>
+
+</para>
+
+@brand:
+@part:
+@description:
+@paper_id:
+@page_width:
+@page_height:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_dup ##### -->
+<para>
+
+</para>
+
+@orig_template:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_free ##### -->
+<para>
+
+</para>
+
+@template:
+
+
+<!-- ##### FUNCTION lgl_template_add_category ##### -->
+<para>
+
+</para>
+
+@template:
+@category_id:
+
+
+<!-- ##### FUNCTION lgl_template_add_frame ##### -->
+<para>
+
+</para>
+
+@template:
+@frame:
+
+
+<!-- ##### FUNCTION lgl_template_add_alias ##### -->
+<para>
+
+</para>
+
+@template:
+@alias:
+
+
+<!-- ##### FUNCTION lgl_template_get_name ##### -->
+<para>
+
+</para>
+
+@template:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_do_templates_match ##### -->
+<para>
+
+</para>
+
+@template1:
+@template2:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_does_brand_match ##### -->
+<para>
+
+</para>
+
+@template:
+@brand:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_does_page_size_match ##### -->
+<para>
+
+</para>
+
+@template:
+@paper_id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_does_category_match ##### -->
+<para>
+
+</para>
+
+@template:
+@category_id:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_alias_new ##### -->
+<para>
+
+</para>
+
+@brand:
+@part:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_alias_dup ##### -->
+<para>
+
+</para>
+
+@orig_alias:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_alias_free ##### -->
+<para>
+
+</para>
+
+@alias:
+
+
+<!-- ##### FUNCTION lgl_template_frame_rect_new ##### -->
+<para>
+
+</para>
+
+@id:
+@w:
+@h:
+@r:
+@x_waste:
+@y_waste:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_frame_round_new ##### -->
+<para>
+
+</para>
+
+@id:
+@r:
+@waste:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_frame_cd_new ##### -->
+<para>
+
+</para>
+
+@id:
+@r1:
+@r2:
+@w:
+@h:
+@waste:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_frame_dup ##### -->
+<para>
+
+</para>
+
+@orig_frame:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_frame_free ##### -->
+<para>
+
+</para>
+
+@frame:
+
+
+<!-- ##### FUNCTION lgl_template_frame_add_layout ##### -->
+<para>
+
+</para>
+
+@frame:
+@layout:
+
+
+<!-- ##### FUNCTION lgl_template_frame_add_markup ##### -->
+<para>
+
+</para>
+
+@frame:
+@markup:
+
+
+<!-- ##### FUNCTION lgl_template_frame_get_size ##### -->
+<para>
+
+</para>
+
+@frame:
+@w:
+@h:
+
+
+<!-- ##### FUNCTION lgl_template_frame_get_n_labels ##### -->
+<para>
+
+</para>
+
+@frame:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_frame_get_origins ##### -->
+<para>
+
+</para>
+
+@frame:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_layout_new ##### -->
+<para>
+
+</para>
+
+@nx:
+@ny:
+@x0:
+@y0:
+@dx:
+@dy:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_layout_dup ##### -->
+<para>
+
+</para>
+
+@orig_layout:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_layout_free ##### -->
+<para>
+
+</para>
+
+@layout:
+
+
+<!-- ##### FUNCTION lgl_template_markup_margin_new ##### -->
+<para>
+
+</para>
+
+@size:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_markup_line_new ##### -->
+<para>
+
+</para>
+
+@x1:
+@y1:
+@x2:
+@y2:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_markup_circle_new ##### -->
+<para>
+
+</para>
+
+@x0:
+@y0:
+@r:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_markup_rect_new ##### -->
+<para>
+
+</para>
+
+@x1:
+@y1:
+@w:
+@h:
+@r:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_markup_dup ##### -->
+<para>
+
+</para>
+
+@orig_markup:
+@Returns:
+
+
+<!-- ##### FUNCTION lgl_template_markup_free ##### -->
+<para>
+
+</para>
+
+@markup:
+
+
libglabels_la_SOURCES = \
libglabels-private.h \
- init.h \
- init.c \
+ db.h \
+ db.c \
enums.h \
paper.h \
paper.c \
libglabelsinclude_HEADERS = \
libglabels.h \
+ db.h \
enums.h \
paper.h \
category.h \
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
-#include <glib/gdir.h>
#include <string.h>
#include "libglabels-private.h"
-#include "xml-category.h"
-
/*===========================================*/
/* Private types */
/*===========================================*/
/* 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
}
-/**
- * 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;
-}
-
-
-
-
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
--- /dev/null
+/* -*- 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 <evins@snaught.com>.
+ *
+ * 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 <config.h>
+
+#include "db.h"
+
+#include <glib/gi18n.h>
+#include <glib/gmem.h>
+#include <glib/gstrfuncs.h>
+#include <glib/gdir.h>
+#include <glib/gmessages.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#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");
+
+}
+
+
--- /dev/null
+/* -*- 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 <evins@snaught.com>.
+ *
+ * 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 <glib/gtypes.h>
+#include <glib/glist.h>
+
+#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
+++ /dev/null
-/*
- * (LIBGLABELS) Template library for GLABELS
- *
- * init.c: initialization module
- *
- * Copyright (C) 2003, 2004 Jim Evins <evins@snaught.com>.
- *
- * 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 <config.h>
-
-#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;
- }
-}
+++ /dev/null
-/*
- * (LIBGLABELS) Template library for GLABELS
- *
- * init.h: initialization module header file
- *
- * Copyright (C) 2007 Jim Evins <evins@snaught.com>.
- *
- * 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 <glib/gtypes.h>
-
-G_BEGIN_DECLS
-
-
-/*
- * Module initialization
- */
-void lgl_init (void);
-
-
-G_END_DECLS
-
-#endif
#include <glib/gutils.h>
#include <glib/gfileutils.h>
+#include <glib/gunicode.h>
/* Data system and user data directories. (must free w/ g_free()) */
#define LGL_SYSTEM_DATA_DIR g_build_filename (LIBGLABELS_TEMPLATE_DIR, NULL)
#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__ */
#ifndef __LIBGLABELS_H__
#define __LIBGLABELS_H__
-#include <libglabels/init.h>
-#include <libglabels/enums.h>
+#include <libglabels/db.h>
#include <libglabels/paper.h>
#include <libglabels/category.h>
#include <libglabels/template.h>
+#include <libglabels/enums.h>
#include <libglabels/xml-paper.h>
#include <libglabels/xml-category.h>
#include <libglabels/xml-template.h>
#include <glib/gi18n.h>
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
-#include <glib/gdir.h>
#include <glib/gmessages.h>
#include <string.h>
#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:
}
-/**
- * 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");
-
-}
-
-
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
#include <glib/gi18n.h>
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
-#include <glib/gdir.h>
+#include <glib/gqsort.h>
#include <glib/gmessages.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#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
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)
{
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;
return template;
}
+
/**
* lgl_template_get_name:
* @template: Pointer to template structure to test
return g_strdup_printf ("%s %s", template->brand, template->part);
}
+
/**
* lgl_template_do_templates_match:
* @template1: Pointer to 1st template structure to test
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
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.
*
*/
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.
*
*/
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;
}
return FALSE;
}
+
/**
* lgl_template_alias_new:
* @brand: Alias brand
return alias;
}
+
/**
* lgl_template_add_alias:
* @template: Pointer to template structure
template->aliases = g_list_append (template->aliases, alias);
}
+
/**
* lgl_template_add_frame:
* @template: Pointer to template structure
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:
return frame;
}
+
/**
* lgl_template_frame_round_new:
* @id: ID of frame. (This should currently always be "0").
return frame;
}
+
/**
* lgl_template_frame_cd_new:
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.
frame->all.layouts = g_list_append (frame->all.layouts, layout);
}
+
/**
* lgl_template_frame_add_markup:
* @frame: Pointer to template frame to add markup to.
frame->all.markups = g_list_append (frame->all.markups, markup);
}
+
/**
* lgl_template_layout_new:
* @nx: Number of labels across.
return layout;
}
+
/**
* lgl_template_markup_margin_new:
* @size: margin size in points.
return markup;
}
+
/**
* lgl_template_markup_line_new:
* @x1: x coordinate of first endpoint.
return markup;
}
+
/**
* lgl_template_markup_circle_new:
* @x0: x coordinate of center of circle.
return markup;
}
+
/**
* lgl_template_markup_rect_new:
* @x1: x coordinate of top-left corner of rectangle.
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);
{
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);
}
return template;
}
+
/**
* lgl_template_free:
* @template: Template to free.
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 ) {
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 ) {
}
+
/**
* lgl_template_alias_dup:
* @orig_alias: Alias to duplicate.
return lgl_template_alias_new (orig_alias->brand, orig_alias->part);
}
+
/**
* lgl_template_alias_free:
* @alias: Alias to free.
}
}
+
/**
* lgl_template_frame_dup:
* @orig_frame: Frame to duplicate.
return frame;
}
+
/**
* lgl_template_frame_free:
* @frame: Frame to free.
}
+
/**
* lgl_template_layout_dup:
* @orig_layout: Layout to duplicate.
return layout;
}
+
/**
* lgl_template_layout_free:
* @layout: Layout to free.
g_free (layout);
}
+
/**
* lgl_template_markup_dup:
* @orig_markup: Markup to duplicate.
return markup;
}
+
/**
* lgl_template_markup_free:
* @markup: Markup to free.
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,
}
}
-/**
- * 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");
-
-}
-
gchar *brand;
gchar *part;
gchar *description;
- gchar *page_size;
+ gchar *paper_id;
gdouble page_width;
gdouble page_height;
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
-/*
- * 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
*/
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);
/*
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);
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);
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
#include "libglabels-private.h"
-#include "paper.h"
+#include "db.h"
#include "xml.h"
/*===========================================*/
gchar *part;
gchar *name;
gchar *description;
- gchar *page_size;
+ gchar *paper_id;
gdouble page_width, page_height;
lglPaper *paper = NULL;
lglTemplate *template;
}
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) {
g_free (brand);
g_free (part);
g_free (description);
- g_free (page_size);
+ g_free (paper_id);
return template;
}
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);
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);
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 );
}
#include "util.h"
#include "window.h"
#include "new-label-dialog.h"
+#include "libglabels/libglabels.h"
#include "debug.h"
/*===========================================*/
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);
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);
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);
#include "xml-label.h"
#include "print.h"
#include "print-op.h"
-#include <libglabels/paper.h>
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include "util.h"
#include "debug.h"
/* 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) {
#include "stock.h"
#include "merge-init.h"
#include "recent.h"
-#include <libglabels/paper.h>
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include "mini-preview-pixbuf-cache.h"
#include "prefs.h"
#include "debug.h"
/* 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 ();
#include "mini-preview-pixbuf-cache.h"
#include "mini-preview-pixbuf.h"
+#include "libglabels/db.h"
+
#include <glib/gmem.h>
#include <glib/ghash.h>
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);
}
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);
#include "prefs-model.h"
-#include <libglabels/paper.h>
+#include <libglabels/db.h>
#include "marshal.h"
#include "util.h"
/* 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 {
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;
#include <math.h>
#include "prefs.h"
-#include <libglabels/paper.h>
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include "wdgt-mini-preview.h"
#include "mini-preview-pixbuf-cache.h"
#include "print-op.h"
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);
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);
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 ) {
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))
#include "util.h"
#include "color.h"
#include "marshal.h"
-#include <libglabels/paper.h>
-#include <libglabels/category.h>
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include "debug.h"
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);
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",
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);
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);
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"));
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"));
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);
#include <math.h>
+#include "libglabels/db.h"
#include "cairo-label-path.h"
#include "marshal.h"
#include "color.h"
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);
#include "marshal.h"
#include "color.h"
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include "cairo-label-path.h"
#include "debug.h"
}
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;
#include "label-ellipse.h"
#include "label-image.h"
#include "label-barcode.h"
+#include <libglabels/db.h>
#include <libglabels/xml.h>
#include "util.h"
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;
#include "label-barcode.h"
#include "base64.h"
#include "xml-label-04.h"
-#include <libglabels/template.h>
+#include <libglabels/db.h>
#include <libglabels/xml-template.h>
#include <libglabels/xml.h>
#include "util.h"
/*========================================================*/
#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. */
}
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)
*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")) {