From: Jim Evins Date: Tue, 27 Nov 2007 04:42:41 +0000 (+0000) Subject: 2007-11-26 Jim Evins X-Git-Tag: glabels-2_3_0~304 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5aca44500cc85783f61bd7a572c38645f8513cc0;p=glabels 2007-11-26 Jim Evins * libglabels/Makefile.am: * libglabels/libglabels.h: Make str.h public. * src/label.c: * src/prefs-dialog.c: * src/prefs-model.c: * src/prefs-model.h: * src/prefs.c: * src/prefs.h: Added tracking of recently used templates. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@694 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 73aaece3..c5f498e9 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,16 @@ +2007-11-26 Jim Evins + + * libglabels/Makefile.am: + * libglabels/libglabels.h: + Make str.h public. + * src/label.c: + * src/prefs-dialog.c: + * src/prefs-model.c: + * src/prefs-model.h: + * src/prefs.c: + * src/prefs.h: + Added tracking of recently used templates. + 2007-11-20 Jim Evins * data/glade/template-designer.glade: diff --git a/glabels2/libglabels/Makefile.am b/glabels2/libglabels/Makefile.am index 5bc36773..2d1228ab 100644 --- a/glabels2/libglabels/Makefile.am +++ b/glabels2/libglabels/Makefile.am @@ -47,7 +47,8 @@ libglabelsinclude_HEADERS = \ xml-paper.h \ xml-category.h \ xml-template.h \ - xml.h + xml.h \ + str.h EXTRA_DIST = \ libglabels.pc.in diff --git a/glabels2/libglabels/libglabels.h b/glabels2/libglabels/libglabels.h index 45c62128..c74fbe01 100644 --- a/glabels2/libglabels/libglabels.h +++ b/glabels2/libglabels/libglabels.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/glabels2/src/label.c b/glabels2/src/label.c index a68bb43c..c886529b 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -29,6 +29,7 @@ #include #include "marshal.h" +#include "prefs.h" #include "util.h" #include "debug.h" @@ -377,6 +378,8 @@ extern void gl_label_set_template (glLabel *label, lglTemplate *template) { + gchar *name; + gl_debug (DEBUG_LABEL, "START"); g_return_if_fail (label && GL_IS_LABEL (label)); @@ -394,6 +397,9 @@ gl_label_set_template (glLabel *label, g_signal_emit (G_OBJECT(label), signals[SIZE_CHANGED], 0); g_signal_emit (G_OBJECT(label), signals[CHANGED], 0); + name = lgl_template_get_name (template); + gl_prefs_add_recent_template (name); + g_free (name); } gl_debug (DEBUG_LABEL, "END"); diff --git a/glabels2/src/prefs-dialog.c b/glabels2/src/prefs-dialog.c index 218f11da..683926fb 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -593,12 +593,14 @@ update_prefs_from_locale_page (glPrefsDialog *dialog) if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(dialog->priv->page_size_us_letter_radio))) { - gl_prefs->default_page_size = US_LETTER_ID; + g_free (gl_prefs->default_page_size); + gl_prefs->default_page_size = g_strdup (US_LETTER_ID); } if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(dialog->priv->page_size_a4_radio))) { - gl_prefs->default_page_size = A4_ID; + g_free (gl_prefs->default_page_size); + gl_prefs->default_page_size = g_strdup (A4_ID); } gl_prefs_model_save_settings (gl_prefs); diff --git a/glabels2/src/prefs-model.c b/glabels2/src/prefs-model.c index 51832024..c49c155e 100644 --- a/glabels2/src/prefs-model.c +++ b/glabels2/src/prefs-model.c @@ -71,6 +71,9 @@ #define PREF_MAX_RECENTS "/max-recents" +#define PREF_RECENT_TEMPLATES "/recent-templates" +#define PREF_MAX_RECENT_TEMPLATES "/max-recent-templates" + /* Default values */ #define DEFAULT_UNITS_STRING units_to_string (LGL_UNITS_INCH) #define DEFAULT_PAGE_SIZE "US-Letter" @@ -357,6 +360,17 @@ gl_prefs_model_save_settings (glPrefsModel *prefs_model) prefs_model->max_recents, NULL); + /* Recent templates */ + gconf_client_set_list (prefs_model->gconf_client, + BASE_KEY PREF_RECENT_TEMPLATES, + GCONF_VALUE_STRING, + prefs_model->recent_templates, + NULL); + gconf_client_set_int (prefs_model->gconf_client, + BASE_KEY PREF_MAX_RECENT_TEMPLATES, + prefs_model->max_recent_templates, + NULL); + gconf_client_suggest_sync (prefs_model->gconf_client, NULL); @@ -371,6 +385,7 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) { gchar *string; lglPaper *paper; + GSList *p; gl_debug (DEBUG_PREFS, "START"); @@ -387,12 +402,14 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) /* Page size */ + g_free (prefs_model->default_page_size); prefs_model->default_page_size = get_string (prefs_model->gconf_client, BASE_KEY PREF_DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE); /* Text properties */ + g_free (prefs_model->default_font_family); prefs_model->default_font_family = get_string (prefs_model->gconf_client, BASE_KEY PREF_DEFAULT_FONT_FAMILY, @@ -502,6 +519,22 @@ gl_prefs_model_load_settings (glPrefsModel *prefs_model) BASE_KEY PREF_MAX_RECENTS, -1); + /* Recent templates */ + for (p=prefs_model->recent_templates; p != NULL; p=p->next) + { + g_free (p->data); + } + g_slist_free (prefs_model->recent_templates); + prefs_model->recent_templates = + gconf_client_get_list (prefs_model->gconf_client, + BASE_KEY PREF_RECENT_TEMPLATES, + GCONF_VALUE_STRING, + NULL); + prefs_model->max_recent_templates = + get_int (prefs_model->gconf_client, + BASE_KEY PREF_MAX_RECENT_TEMPLATES, + 5); + /* Proof read the default page size -- it must be a valid id. */ /* (For compatability with older versions.) */ diff --git a/glabels2/src/prefs-model.h b/glabels2/src/prefs-model.h index 2303e171..b2cc1cbd 100644 --- a/glabels2/src/prefs-model.h +++ b/glabels2/src/prefs-model.h @@ -97,6 +97,10 @@ struct _glPrefsModel { /* Recent files */ gint max_recents; + + /* Recent templates */ + GSList *recent_templates; + gint max_recent_templates; }; struct _glPrefsModelClass { diff --git a/glabels2/src/prefs.c b/glabels2/src/prefs.c index c2ef4e3a..32011b79 100644 --- a/glabels2/src/prefs.c +++ b/glabels2/src/prefs.c @@ -26,6 +26,7 @@ #include "prefs.h" #include +#include #include "debug.h" @@ -166,3 +167,48 @@ gl_prefs_get_units_string (void) } } +/****************************************************************************/ +/* Add template to recent template list. */ +/****************************************************************************/ +void +gl_prefs_add_recent_template (const gchar *name) +{ + GSList *p; + + /* + * If already in list, remove that entry. + */ + p = g_slist_find_custom (gl_prefs->recent_templates, + name, + (GCompareFunc)lgl_str_utf8_casecmp); + if (p) + { + gl_prefs->recent_templates = + g_slist_remove_link (gl_prefs->recent_templates, p); + g_free (p->data); + g_slist_free_1 (p); + } + + /* + * Now prepend to list. + */ + gl_prefs->recent_templates = + g_slist_prepend (gl_prefs->recent_templates, g_strdup (name)); + + /* + * Truncate list to maximum size + */ + while (g_slist_length (gl_prefs->recent_templates) > gl_prefs->max_recent_templates) + { + p = g_slist_last (gl_prefs->recent_templates); + gl_prefs->recent_templates = + g_slist_remove_link (gl_prefs->recent_templates, p); + g_free (p->data); + g_slist_free_1 (p); + } + + /* + * Sync to disk. + */ + gl_prefs_model_save_settings (gl_prefs); +} diff --git a/glabels2/src/prefs.h b/glabels2/src/prefs.h index b4da528d..98474f5c 100644 --- a/glabels2/src/prefs.h +++ b/glabels2/src/prefs.h @@ -48,6 +48,8 @@ gdouble gl_prefs_get_units_step_size (void); gint gl_prefs_get_units_precision (void); +void gl_prefs_add_recent_template (const gchar *name); + G_END_DECLS #endif /* __PREFS_H__ */