From 7fc2595f019ca9b9e4ddc8bf04173489c42dada8 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 30 Nov 2007 02:13:51 +0000 Subject: [PATCH] 2007-11-29 Jim Evins * libglabels/db.h: * libglabels/db.c: Added lgl_db_does_template_name_exist(). In lgl_db_lookup_template_from_name() substitute brand/part of new template from requested alias. * src/prefs-model.c: Proof read recent templates -- make sure they still exist. * src/wdgt-media-select.c: Default to "search all templates" tab if no recent templates found. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@696 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 12 ++++++++ glabels2/libglabels/db.c | 53 +++++++++++++++++++++++++++++++- glabels2/libglabels/db.h | 2 ++ glabels2/src/prefs-model.c | 16 ++++++++-- glabels2/src/wdgt-media-select.c | 12 ++++++++ 5 files changed, 92 insertions(+), 3 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 232975f6..cc133c0c 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,15 @@ +2007-11-29 Jim Evins + + * libglabels/db.h: + * libglabels/db.c: + Added lgl_db_does_template_name_exist(). + In lgl_db_lookup_template_from_name() substitute brand/part of new template from + requested alias. + * src/prefs-model.c: + Proof read recent templates -- make sure they still exist. + * src/wdgt-media-select.c: + Default to "search all templates" tab if no recent templates found. + 2007-11-28 Jim Evins * data/glade/wdgt-media-select.glade: diff --git a/glabels2/libglabels/db.c b/glabels2/libglabels/db.c index 1411408c..b9cb9ad6 100644 --- a/glabels2/libglabels/db.c +++ b/glabels2/libglabels/db.c @@ -1146,6 +1146,53 @@ lgl_db_does_template_exist (const gchar *brand, } +/** + * lgl_db_does_template_name_exist: + * @name: name string + * + * This function test whether a template with the given name exists. + * + * Returns: TRUE if such a template exists in the database. + * + */ +gboolean +lgl_db_does_template_name_exist (const gchar *name) +{ + GList *p_tmplt, *p_alias; + lglTemplate *template; + lglTemplateAlias *alias; + gchar *candidate_name; + + if (!templates) + { + lgl_db_init (); + } + + if (name == NULL) + { + return FALSE; + } + + 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 TRUE; + } + g_free (candidate_name); + } + } + + return FALSE; +} + + /** * lgl_db_get_template_name_list_unique: * @brand: If non NULL, limit results to given brand @@ -1291,6 +1338,7 @@ lgl_db_lookup_template_from_name (const gchar *name) lglTemplate *template; lglTemplateAlias *alias; gchar *candidate_name; + lglTemplate *new_template; if (!templates) { @@ -1313,7 +1361,10 @@ lgl_db_lookup_template_from_name (const gchar *name) if ( UTF8_EQUAL (candidate_name, name) ) { g_free (candidate_name); - return lgl_template_dup (template); + new_template = lgl_template_dup (template); + new_template->brand = g_strdup (alias->brand); + new_template->part = g_strdup (alias->part); + return new_template; } g_free (candidate_name); } diff --git a/glabels2/libglabels/db.h b/glabels2/libglabels/db.h index fe0c85e4..c6b6f7ef 100644 --- a/glabels2/libglabels/db.h +++ b/glabels2/libglabels/db.h @@ -115,6 +115,8 @@ lglDbRegStatus lgl_db_register_template (const lglTemplate *templ gboolean lgl_db_does_template_exist (const gchar *brand, const gchar *part); +gboolean lgl_db_does_template_name_exist (const gchar *name); + GList *lgl_db_get_template_name_list_unique (const gchar *brand, const gchar *paper_id, const gchar *category_id); diff --git a/glabels2/src/prefs-model.c b/glabels2/src/prefs-model.c index c49c155e..b67f92f4 100644 --- a/glabels2/src/prefs-model.c +++ b/glabels2/src/prefs-model.c @@ -385,7 +385,7 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) { gchar *string; lglPaper *paper; - GSList *p; + GSList *p, *p_next; gl_debug (DEBUG_PREFS, "START"); @@ -538,7 +538,6 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) /* Proof read the default page size -- it must be a valid id. */ /* (For compatability with older versions.) */ - /* Note: paper module must be initialized for this to work. */ paper = lgl_db_lookup_paper_from_id (prefs_model->default_page_size); if ( paper == NULL ) { prefs_model->default_page_size = g_strdup (DEFAULT_PAGE_SIZE); @@ -547,6 +546,19 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) paper = NULL; } + /* Proof read the recent templates list. Make sure the template names */ + /* are valid. Remove from list if not. */ + for (p=prefs_model->recent_templates; p != NULL; p=p_next) + { + p_next = p->next; + + if ( !lgl_db_does_template_name_exist (p->data) ) + { + g_free (p->data); + prefs_model->recent_templates = g_slist_delete_link (prefs_model->recent_templates, p); + } + } + gl_debug (DEBUG_PREFS, "max_recents = %d", prefs_model->max_recents); diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index 6906646d..0c4b4764 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -353,6 +353,18 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select) g_free (page_size_name); + gtk_widget_show_all (GTK_WIDGET (media_select)); + if ( gl_prefs->recent_templates ) + { + gtk_notebook_set_current_page (GTK_NOTEBOOK (media_select->priv->notebook), + media_select->priv->recent_page_num); + } + else + { + gtk_notebook_set_current_page (GTK_NOTEBOOK (media_select->priv->notebook), + media_select->priv->search_all_page_num); + } + gl_debug (DEBUG_MEDIA_SELECT, "END"); } -- 2.39.5