/* Data system and user data directories. (must free w/ g_free()) */
#define SYSTEM_CONFIG_DIR g_build_filename (LIBGLABELS_CONFIG_DIR, "templates", NULL)
#define USER_CONFIG_DIR g_build_filename (g_get_user_config_dir (), "libglabels", "templates" , NULL)
-#define USER_CONFIG_DIR_OLD22 g_build_filename (g_get_home_dir (), ".glabels", NULL)
+#define ALT_USER_CONFIG_DIR g_build_filename (g_get_home_dir (), ".glabels", NULL)
/*===========================================*/
static lglTemplate *template_full_page (const gchar *page_size);
-static void copy_old_custom_files (void);
-
/*****************************************************************************/
/* Object infrastructure. */
GList *page_sizes;
GList *p;
- copy_old_custom_files ();
-
model = lgl_db_model_new ();
/*
filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
abs_filename = g_build_filename (dir, filename, NULL);
+ if (!g_file_test (abs_filename, G_FILE_TEST_EXISTS))
+ {
+ g_message ("File \"%s\" does not exist. Cannot delete it.");
+ return LGL_DB_DELETE_DOES_NOT_EXIST;
+ }
+
g_unlink (abs_filename);
g_free (dir);
lgl_template_add_category (template, "user-defined");
}
+ /*
+ * Alternate user defined templates. (Used for manually created templates).
+ */
+ data_dir = ALT_USER_CONFIG_DIR;
+ read_template_files_from_dir (data_dir);
+ g_free (data_dir);
+
/*
* System templates.
*/
}
-/*
- * Migrate custom files from the old ~/.glabels location to the new
- * ~/.config/libglabels/templates directory. Place a timestamp file
- * in the old directory to prevent future copies.
- */
-static void
-copy_old_custom_files (void)
-{
- gchar *old_dir_name;
- gchar *new_dir_name;
- gchar *timestamp_file_name;
- GDir *dir;
- const gchar *name;
- gchar *old_full_name, *new_full_name;
- gchar *contents;
- gsize length;
-
- old_dir_name = USER_CONFIG_DIR_OLD22;
- timestamp_file_name = g_build_filename (old_dir_name, ".copied_to_30", NULL);
-
- if ( g_file_test (old_dir_name, G_FILE_TEST_EXISTS) &&
- !g_file_test (timestamp_file_name, G_FILE_TEST_EXISTS) )
- {
-
- new_dir_name = USER_CONFIG_DIR;
- g_mkdir_with_parents (new_dir_name, 0775); /* Try to make sure directory exists. */
-
- dir = g_dir_open (old_dir_name, 0, NULL);
-
- if (dir)
- {
- while ((name = g_dir_read_name (dir)) != NULL)
- {
- old_full_name = g_build_filename (old_dir_name, name, NULL);
- new_full_name = g_build_filename (new_dir_name, name, NULL);
-
- if ( g_file_get_contents (old_full_name, &contents, &length, NULL) )
- {
- g_file_set_contents (new_full_name, contents, length, NULL);
- g_free (contents);
- }
-
- g_free (old_full_name);
- g_free (new_full_name);
- }
-
- g_dir_close (dir);
-
- g_file_set_contents (timestamp_file_name, NULL, 0, NULL);
- }
-
- g_free (new_dir_name);
- }
-
- g_free (timestamp_file_name);
- g_free (old_dir_name);
-}
-
-
/**
* lgl_db_print_known_templates:
*
LIBXML_TEST_VERSION;
root = xmlDocGetRootElement (templates_doc);
- if (!root || !root->name) {
+ if (!root || !root->name)
+ {
g_message ("\"%s\" is not a glabels template file (no root node)",
templates_doc->URL);
return;
}
- if (!lgl_xml_is_node (root, "Glabels-templates")) {
+ if (!lgl_xml_is_node (root, "Glabels-templates"))
+ {
g_message ("\"%s\" is not a glabels template file (wrong root node)",
templates_doc->URL);
return;
}
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
+ for (node = root->xmlChildrenNode; node != NULL; node = node->next)
+ {
- if (lgl_xml_is_node (node, "Template")) {
+ if (lgl_xml_is_node (node, "Template"))
+ {
template = lgl_xml_template_parse_template_node (node);
- _lgl_db_register_template_internal (template);
- lgl_template_free (template);
- } else {
- if ( !xmlNodeIsText(node) ) {
- if (!lgl_xml_is_node (node,"comment")) {
+ if (template)
+ {
+ _lgl_db_register_template_internal (template);
+ lgl_template_free (template);
+ }
+ }
+ else
+ {
+ if ( !xmlNodeIsText(node) )
+ {
+ if (!lgl_xml_is_node (node,"comment"))
+ {
g_message ("bad node = \"%s\"",node->name);
}
}