1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (LIBGLABELS) Template library for GLABELS
6 * db.c: template db module
8 * Copyright (C) 2003-2007 Jim Evins <evins@snaught.com>.
10 * This file is part of the LIBGLABELS library.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
31 #include <glib/gi18n.h>
32 #include <glib/gmem.h>
33 #include <glib/gstrfuncs.h>
34 #include <glib/gdir.h>
35 #include <glib/gmessages.h>
38 #include <sys/types.h>
40 #include "libglabels-private.h"
42 #include "xml-paper.h"
43 #include "xml-category.h"
44 #include "xml-template.h"
47 /*===========================================*/
49 /*===========================================*/
51 /*===========================================*/
53 /*===========================================*/
55 static GList *papers = NULL;
56 static GList *categories = NULL;
57 static GList *templates = NULL;
59 /*===========================================*/
60 /* Local function prototypes */
61 /*===========================================*/
63 static GList *read_papers (void);
64 static GList *read_paper_files_from_dir (GList *papers,
65 const gchar *dirname);
67 static GList *read_categories (void);
68 static GList *read_category_files_from_dir (GList *categories,
69 const gchar *dirname);
71 static GList *read_templates (void);
72 static GList *read_template_files_from_dir (GList *templates,
73 const gchar *dirname);
75 static lglTemplate *template_full_page (const gchar *page_size);
79 /*===========================================*/
80 /* Module initialization */
81 /*===========================================*/
86 * Initialize all libglabels subsystems. It is not necessary for an application to call
87 * lgl_init(), because libglabels will initialize on demand. An application programmer may
88 * choose to call lgl_init() at startup to minimize the impact of the first libglabels call
89 * on GUI response time.
91 * This function initializes its paper definitions, category definitions, and its template
92 * database.. It will search both system and user template directories to locate
108 papers = read_papers ();
110 /* Create and append an "Other" entry. */
111 other = lgl_paper_new ("Other", _("Other"), 0.0, 0.0);
112 papers = g_list_append (papers, other);
121 categories = read_categories ();
130 templates = read_templates ();
132 /* Create and append generic full page templates. */
133 page_sizes = lgl_db_get_paper_id_list ();
134 for ( p=page_sizes; p != NULL; p=p->next )
136 if ( !lgl_db_is_paper_id_other (p->data) )
138 templates = g_list_append (templates,
139 template_full_page (p->data));
142 lgl_db_free_paper_id_list (page_sizes);
149 /*===========================================*/
150 /* Paper db functions. */
151 /*===========================================*/
154 * lgl_db_get_paper_id_list:
156 * Get a list of all paper ids known to libglabels.
158 * Returns: a list of paper ids.
162 lgl_db_get_paper_id_list (void)
173 for ( p=papers; p != NULL; p=p->next )
175 paper = (lglPaper *)p->data;
176 ids = g_list_append (ids, g_strdup (paper->id));
184 * lgl_db_free_paper_id_list:
185 * @ids: List of id strings to be freed.
187 * Free up all storage associated with an id list obtained with
188 * lgl_paper_get_id_list().
192 lgl_db_free_paper_id_list (GList *ids)
196 for (p = ids; p != NULL; p = p->next)
207 * lgl_db_get_paper_name_list:
209 * Get a list of all localized paper names known to libglabels.
211 * Returns: a list of localized paper names.
215 lgl_db_get_paper_name_list (void)
226 for ( p=papers; p != NULL; p=p->next )
228 paper = (lglPaper *)p->data;
229 names = g_list_append (names, g_strdup (paper->name));
237 * lgl_db_free_paper_name_list:
238 * @names: List of localized paper name strings to be freed.
240 * Free up all storage associated with a name list obtained with
241 * lgl_paper_get_name_list().
245 lgl_db_free_paper_name_list (GList *names)
249 for (p = names; p != NULL; p = p->next)
260 * lgl_db_lookup_paper_from_name:
261 * @name: localized paper name string
263 * Lookup paper definition from localized paper name string.
265 * Returns: pointer to a newly allocated #lglPaper structure.
269 lgl_db_lookup_paper_from_name (const gchar *name)
281 /* If no name, return first paper as a default */
282 return lgl_paper_dup ((lglPaper *) papers->data);
285 for (p = papers; p != NULL; p = p->next)
287 paper = (lglPaper *) p->data;
288 if (UTF8_EQUAL (paper->name, name))
290 return lgl_paper_dup (paper);
299 * lgl_db_lookup_paper_from_id:
300 * @id: paper id string
302 * Lookup paper definition from id string.
304 * Returns: pointer to a newly allocated #lglPaper structure.
308 lgl_db_lookup_paper_from_id (const gchar *id)
320 /* If no id, return first paper as a default */
321 return lgl_paper_dup ((lglPaper *) papers->data);
324 for (p = papers; p != NULL; p = p->next)
326 paper = (lglPaper *) p->data;
327 if (ASCII_EQUAL (paper->id, id))
329 return lgl_paper_dup (paper);
338 * lgl_db_lookup_paper_id_from_name:
339 * @name: localized paper name stringp
341 * Lookup paper name string from localized paper name string.
343 * Returns: pointer to a newly allocated id string.
347 lgl_db_lookup_paper_id_from_name (const gchar *name)
349 lglPaper *paper = NULL;
354 paper = lgl_db_lookup_paper_from_name (name);
357 id = g_strdup (paper->id);
358 lgl_paper_free (paper);
368 * lgl_db_lookup_paper_name_from_id:
369 * @id: paper id string
371 * Lookup localized paper name string from paper id string.
373 * Returns: pointer to a newly allocated localized paper name string.
377 lgl_db_lookup_paper_name_from_id (const gchar *id)
379 lglPaper *paper = NULL;
384 paper = lgl_db_lookup_paper_from_id (id);
387 name = g_strdup (paper->name);
388 lgl_paper_free (paper);
398 * lgl_db_is_paper_id_known:
399 * @id: paper id to test
401 * Determine if given paper id is known to libglabels.
403 * Returns: TRUE if id is known, otherwise FALSE.
407 lgl_db_is_paper_id_known (const gchar *id)
422 for (p = papers; p != NULL; p = p->next)
424 paper = (lglPaper *) p->data;
425 if (ASCII_EQUAL (paper->id, id))
435 * lgl_db_is_paper_id_other:
436 * @id: paper id to test
438 * Determine if given paper id is the special id "Other."
440 * Returns: TRUE if id is "Other", otherwise FALSE.
444 lgl_db_is_paper_id_other (const gchar *id)
451 return (ASCII_EQUAL (id, "Other"));
459 GList *papers = NULL;
461 data_dir = LGL_SYSTEM_DATA_DIR;
462 papers = read_paper_files_from_dir (papers, data_dir);
465 data_dir = LGL_USER_DATA_DIR;
466 papers = read_paper_files_from_dir (papers, data_dir);
469 if (papers == NULL) {
470 g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!"));
478 read_paper_files_from_dir (GList *papers,
479 const gchar *dirname)
482 const gchar *filename, *extension;
483 gchar *full_filename = NULL;
484 GError *gerror = NULL;
485 GList *new_papers = NULL;
487 if (dirname == NULL) {
491 if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
495 dp = g_dir_open (dirname, 0, &gerror);
496 if (gerror != NULL) {
497 g_message ("cannot open data directory: %s", gerror->message );
501 while ((filename = g_dir_read_name (dp)) != NULL) {
503 extension = strrchr (filename, '.');
505 if (extension != NULL) {
507 if ( ASCII_EQUAL (extension, ".paper") ||
508 ASCII_EQUAL (filename, "paper-sizes.xml") )
512 g_build_filename (dirname, filename, NULL);
514 lgl_xml_paper_read_papers_from_file (full_filename);
515 g_free (full_filename);
517 papers = g_list_concat (papers, new_papers);
533 * lgl_db_print_known_papers:
535 * For debugging purposes: print a list of all paper definitions known to
540 lgl_db_print_known_papers (void)
549 g_print ("%s():\n", __FUNCTION__);
550 for (p = papers; p != NULL; p = p->next) {
551 paper = (lglPaper *) p->data;
553 g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n",
554 paper->id, paper->name, paper->width, paper->height);
562 /*===========================================*/
563 /* Category db functions. */
564 /*===========================================*/
567 * lgl_db_get_category_id_list:
569 * Get a list of all category ids known to libglabels.
571 * Returns: a list of category ids.
575 lgl_db_get_category_id_list (void)
579 lglCategory *category;
586 for ( p=categories; p != NULL; p=p->next )
588 category = (lglCategory *)p->data;
589 ids = g_list_append (ids, g_strdup (category->id));
597 * lgl_db_free_category_id_list:
598 * @ids: List of id strings to be freed.
600 * Free up all storage associated with an id list obtained with
601 * lgl_category_get_id_list().
605 lgl_db_free_category_id_list (GList *ids)
609 for (p = ids; p != NULL; p = p->next)
620 * lgl_db_get_category_name_list:
622 * Get a list of all localized category names known to libglabels.
624 * Returns: a list of localized category names.
628 lgl_db_get_category_name_list (void)
632 lglCategory *category;
639 for ( p=categories; p != NULL; p=p->next )
641 category = (lglCategory *)p->data;
642 names = g_list_append (names, g_strdup (category->name));
650 * lgl_db_free_category_name_list:
651 * @names: List of localized category name strings to be freed.
653 * Free up all storage associated with a name list obtained with
654 * lgl_category_get_name_list().
658 lgl_db_free_category_name_list (GList *names)
662 for (p = names; p != NULL; p = p->next)
673 * lgl_db_lookup_category_from_name:
674 * @name: localized category name string
676 * Lookup category definition from localized category name string.
678 * Returns: pointer to a newly allocated #lglCategory structure.
682 lgl_db_lookup_category_from_name (const gchar *name)
685 lglCategory *category;
694 /* If no name, return first category as a default */
695 return lgl_category_dup ((lglCategory *) categories->data);
698 for (p = categories; p != NULL; p = p->next)
700 category = (lglCategory *) p->data;
701 if (UTF8_EQUAL (category->name, name))
703 return lgl_category_dup (category);
712 * lgl_db_lookup_category_from_id:
713 * @id: category id string
715 * Lookup category definition from id string.
717 * Returns: pointer to a newly allocated #lglCategory structure.
721 lgl_db_lookup_category_from_id (const gchar *id)
724 lglCategory *category;
733 /* If no id, return first category as a default */
734 return lgl_category_dup ((lglCategory *) categories->data);
737 for (p = categories; p != NULL; p = p->next)
739 category = (lglCategory *) p->data;
740 if (ASCII_EQUAL (category->id, id))
742 return lgl_category_dup (category);
751 * lgl_db_lookup_category_id_from_name:
752 * @name: localized category name stringp
754 * Lookup category name string from localized category name string.
756 * Returns: pointer to a newly allocated id string.
760 lgl_db_lookup_category_id_from_name (const gchar *name)
762 lglCategory *category = NULL;
767 category = lgl_db_lookup_category_from_name (name);
768 if ( category != NULL )
770 id = g_strdup (category->id);
771 lgl_category_free (category);
781 * lgl_db_lookup_category_name_from_id:
782 * @id: category id string
784 * Lookup localized category name string from category id string.
786 * Returns: pointer to a newly allocated localized category name string.
790 lgl_db_lookup_category_name_from_id (const gchar *id)
792 lglCategory *category = NULL;
797 category = lgl_db_lookup_category_from_id (id);
798 if ( category != NULL )
800 name = g_strdup (category->name);
801 lgl_category_free (category);
811 * lgl_db_is_category_id_known:
812 * @id: category id to test
814 * Determine if given category id is known to libglabels.
816 * Returns: TRUE if id is known, otherwise FALSE.
820 lgl_db_is_category_id_known (const gchar *id)
823 lglCategory *category;
835 for (p = categories; p != NULL; p = p->next)
837 category = (lglCategory *) p->data;
838 if (ASCII_EQUAL (category->id, id))
849 read_categories (void)
852 GList *categories = NULL;
854 data_dir = LGL_SYSTEM_DATA_DIR;
855 categories = read_category_files_from_dir (categories, data_dir);
858 data_dir = LGL_USER_DATA_DIR;
859 categories = read_category_files_from_dir (categories, data_dir);
862 if (categories == NULL) {
863 g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!"));
871 read_category_files_from_dir (GList *categories,
872 const gchar *dirname)
875 const gchar *filename, *extension;
876 gchar *full_filename = NULL;
877 GError *gerror = NULL;
878 GList *new_categories = NULL;
880 if (dirname == NULL) {
884 if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
888 dp = g_dir_open (dirname, 0, &gerror);
889 if (gerror != NULL) {
890 g_message ("cannot open data directory: %s", gerror->message );
894 while ((filename = g_dir_read_name (dp)) != NULL) {
896 extension = strrchr (filename, '.');
898 if (extension != NULL) {
900 if ( ASCII_EQUAL (extension, ".category") ||
901 ASCII_EQUAL (filename, "categories.xml") )
905 g_build_filename (dirname, filename, NULL);
907 lgl_xml_category_read_categories_from_file (full_filename);
908 g_free (full_filename);
910 categories = g_list_concat (categories, new_categories);
911 new_categories = NULL;
926 * lgl_db_print_known_categories:
928 * For debugging purposes: print a list of all category definitions known to
933 lgl_db_print_known_categories (void)
936 lglCategory *category;
942 g_print ("%s():\n", __FUNCTION__);
943 for (p = categories; p != NULL; p = p->next) {
944 category = (lglCategory *) p->data;
946 g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name);
955 /*===========================================*/
956 /* Brand db functions. */
957 /*===========================================*/
960 * lgl_db_get_brand_list:
961 * @paper_id: If non NULL, limit results to given page size.
962 * @category_id: If non NULL, limit results to given template category.
964 * Get a list of all valid brands of templates in the template database.
965 * Results can be filtered by page size and/or template category. A list of valid page
966 * sizes can be obtained using lgl_paper_get_id_list(). A list of valid template
967 * categories can be obtained using lgl_category_get_id_list().
969 * Returns: a list of brands
972 lgl_db_get_brand_list (const gchar *paper_id,
973 const gchar *category_id)
975 GList *p_tmplt, *p_alias;
976 lglTemplate *template;
977 lglTemplateAlias *alias;
978 GList *brands = NULL;
985 for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
987 template = (lglTemplate *) p_tmplt->data;
988 if (lgl_template_does_page_size_match (template, paper_id) &&
989 lgl_template_does_category_match (template, category_id))
991 for (p_alias = template->aliases; p_alias != NULL;
992 p_alias = p_alias->next)
994 alias = (lglTemplateAlias *)p_alias->data;
996 if ( !g_list_find_custom (brands, alias->brand,
997 (GCompareFunc)g_utf8_collate) )
999 brands = g_list_insert_sorted (brands,
1000 g_strdup (alias->brand),
1001 (GCompareFunc)g_utf8_collate);
1012 * lgl_db_free_brand_list:
1013 * @brands: List of template brand strings to be freed.
1015 * Free up all storage associated with a list of template names obtained with
1016 * lgl_db_get_brand_list().
1020 lgl_db_free_brand_list (GList *brands)
1024 for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next)
1026 g_free (p_brand->data);
1027 p_brand->data = NULL;
1030 g_list_free (brands);
1035 /*===========================================*/
1036 /* Template db functions. */
1037 /*===========================================*/
1040 * lgl_db_register_template:
1041 * @template: Pointer to a template structure to add to database.
1043 * Register a template. This function adds a template to the template database.
1044 * The template will be stored in an individual XML file in the user template directory.
1047 lgl_db_register_template (const lglTemplate *template)
1049 GList *p_tmplt1, *p_a1;
1050 lglTemplate *template1;
1051 lglTemplateAlias *alias1;
1058 for (p_tmplt1 = templates; p_tmplt1 != NULL; p_tmplt1 = p_tmplt1->next)
1060 template1 = (lglTemplate *) p_tmplt1->data;
1062 for (p_a1=template1->aliases; p_a1!=NULL; p_a1=p_a1->next)
1064 alias1 = (lglTemplateAlias *) p_a1->data;
1066 if ( UTF8_EQUAL (template->brand, alias1->brand) &&
1067 UTF8_EQUAL (template->part, alias1->part) )
1070 /* FIXME: make sure templates are really identical */
1071 /* if not, apply hash to name to make unique. */
1079 if (lgl_db_is_paper_id_known (template->paper_id))
1082 gchar *dir, *filename, *abs_filename;
1084 templates = g_list_append (templates,
1085 lgl_template_dup (template));
1087 /* FIXME: make sure filename is unique */
1088 dir = LGL_USER_DATA_DIR;
1089 mkdir (dir, 0775); /* Try to make sure directory exists. */
1090 filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
1091 abs_filename = g_build_filename (dir, filename, NULL);
1092 lgl_xml_template_write_template_to_file (template, abs_filename);
1095 g_free (abs_filename);
1100 g_message ("Cannot register new template with unknown page size.");
1107 * lgl_db_get_template_name_list_unique:
1108 * @brand: If non NULL, limit results to given brand
1109 * @paper_id: If non NULL, limit results to given page size.
1110 * @category_id: If non NULL, limit results to given template category.
1112 * Get a list of valid names of unique templates in the template database. Results
1113 * can be filtered by page size and/or template category. A list of valid page sizes
1114 * can be obtained using lgl_paper_get_id_list(). A list of valid template categories
1115 * can be obtained using lgl_category_get_id_list().
1117 * This function differs from lgl_db_get_template_name_list_all(), because it does not
1118 * return multiple names for the same template.
1120 * Returns: a list of template names.
1123 lgl_db_get_template_name_list_unique (const gchar *brand,
1124 const gchar *paper_id,
1125 const gchar *category_id)
1128 lglTemplate *template;
1130 GList *names = NULL;
1137 for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
1139 template = (lglTemplate *) p_tmplt->data;
1141 if (lgl_template_does_brand_match (template, brand) &&
1142 lgl_template_does_page_size_match (template, paper_id) &&
1143 lgl_template_does_category_match (template, category_id))
1145 name = g_strdup_printf ("%s %s", template->brand, template->part);
1146 names = g_list_insert_sorted (names, name,
1147 (GCompareFunc)g_utf8_collate);
1156 * lgl_db_get_template_name_list_all:
1157 * @brand: If non NULL, limit results to given brand
1158 * @paper_id: If non NULL, limit results to given page size.
1159 * @category_id: If non NULL, limit results to given template category.
1161 * Get a list of all valid names and aliases of templates in the template database.
1162 * Results can be filtered by page size and/or template category. A list of valid page
1163 * sizes can be obtained using lgl_paper_get_id_list(). A list of valid template
1164 * categories can be obtained using lgl_category_get_id_list().
1166 * This function differs from lgl_db_get_template_name_list_unique(), because it will
1167 * return multiple names for the same template.
1169 * Returns: a list of template names and aliases.
1172 lgl_db_get_template_name_list_all (const gchar *brand,
1173 const gchar *paper_id,
1174 const gchar *category_id)
1176 GList *p_tmplt, *p_alias;
1177 lglTemplate *template;
1178 lglTemplateAlias *alias;
1180 GList *names = NULL;
1187 for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
1189 template = (lglTemplate *) p_tmplt->data;
1190 if (lgl_template_does_page_size_match (template, paper_id) &&
1191 lgl_template_does_category_match (template, category_id))
1193 for (p_alias = template->aliases; p_alias != NULL;
1194 p_alias = p_alias->next)
1196 alias = (lglTemplateAlias *)p_alias->data;
1198 if ( !brand || UTF8_EQUAL( alias->brand, brand) )
1200 name = g_strdup_printf ("%s %s", alias->brand, alias->part);
1201 names = g_list_insert_sorted (names, name,
1202 (GCompareFunc)g_utf8_collate);
1213 * lgl_db_free_template_name_list:
1214 * @names: List of template name strings to be freed.
1216 * Free up all storage associated with a list of template names obtained with
1217 * lgl_get_template_name_list_all() or lgl_get_template_name_list_unique().
1221 lgl_db_free_template_name_list (GList *names)
1225 for (p_name = names; p_name != NULL; p_name = p_name->next)
1227 g_free (p_name->data);
1228 p_name->data = NULL;
1231 g_list_free (names);
1236 * lgl_db_lookup_template_from_name:
1237 * @name: name string
1239 * Lookup template in template database from name string.
1241 * Returns: pointer to a newly allocated #lglTemplate structure.
1245 lgl_db_lookup_template_from_name (const gchar *name)
1247 GList *p_tmplt, *p_alias;
1248 lglTemplate *template;
1249 lglTemplateAlias *alias;
1250 gchar *candidate_name;
1259 /* If no name, return first template as a default */
1260 return lgl_template_dup ((lglTemplate *) templates->data);
1263 for (p_tmplt = templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
1265 template = (lglTemplate *) p_tmplt->data;
1266 for (p_alias = template->aliases; p_alias != NULL; p_alias = p_alias->next)
1268 alias = (lglTemplateAlias *)p_alias->data;
1269 candidate_name = g_strdup_printf ("%s %s", alias->brand, alias->part);
1271 if ( UTF8_EQUAL (candidate_name, name) ) {
1272 g_free (candidate_name);
1273 return lgl_template_dup (template);
1275 g_free (candidate_name);
1279 /* No matching template has been found so return the first template */
1280 return lgl_template_dup ((lglTemplate *) templates->data);
1285 read_templates (void)
1288 GList *templates = NULL;
1290 data_dir = LGL_SYSTEM_DATA_DIR;
1291 templates = read_template_files_from_dir (templates, data_dir);
1294 data_dir = LGL_USER_DATA_DIR;
1295 templates = read_template_files_from_dir (templates, data_dir);
1298 if (templates == NULL)
1300 g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!"));
1308 read_template_files_from_dir (GList *templates,
1309 const gchar *dirname)
1312 const gchar *filename, *extension, *extension2;
1313 gchar *full_filename = NULL;
1314 GError *gerror = NULL;
1315 GList *new_templates = NULL;
1317 if (dirname == NULL)
1320 if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
1325 dp = g_dir_open (dirname, 0, &gerror);
1328 g_message ("cannot open data directory: %s", gerror->message );
1332 while ((filename = g_dir_read_name (dp)) != NULL)
1335 extension = strrchr (filename, '.');
1336 extension2 = strrchr (filename, '-');
1338 if ( (extension && ASCII_EQUAL (extension, ".template")) ||
1339 (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) )
1342 full_filename = g_build_filename (dirname, filename, NULL);
1344 lgl_xml_template_read_templates_from_file (full_filename);
1345 g_free (full_filename);
1347 templates = g_list_concat (templates, new_templates);
1348 new_templates = NULL;
1359 static lglTemplate *
1360 template_full_page (const gchar *paper_id)
1362 lglPaper *paper = NULL;
1363 lglTemplate *template = NULL;
1364 lglTemplateFrame *frame = NULL;
1368 g_return_val_if_fail (paper_id, NULL);
1370 paper = lgl_db_lookup_paper_from_id (paper_id);
1371 if ( paper == NULL )
1376 part = g_strdup_printf ("%s-Full-Page", paper->id);
1377 desc = g_strdup_printf (_("Generic %s full page template"), paper->name);
1379 template = lgl_template_new ("Generic", part, desc,
1380 paper_id, paper->width, paper->height);
1383 frame = lgl_template_frame_rect_new ("0",
1389 lgl_template_add_frame (template, frame);
1391 lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.));
1393 lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0));
1397 lgl_paper_free (paper);
1405 * lgl_db_print_known_templates:
1407 * Print all known templates (for debugging purposes).
1411 lgl_db_print_known_templates (void)
1414 lglTemplate *template;
1416 g_print ("%s():\n", __FUNCTION__);
1417 for (p=templates; p!=NULL; p=p->next)
1419 template = (lglTemplate *)p->data;
1421 g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n",
1422 template->brand, template->part, template->description);
1430 * lgl_db_print_aliases:
1431 * @template: template
1433 * Print all aliases of a template (for debugging purposes).
1437 lgl_db_print_aliases (const lglTemplate *template)
1440 lglTemplateAlias *alias;
1442 g_print ("%s():\n", __FUNCTION__);
1443 for (p=template->aliases; p!=NULL; p=p->next)
1445 alias = (lglTemplateAlias *)p->data;
1447 g_print("Alias: brand=\"%s\", part=\"%s\"\n", alias->brand, alias->part);