+2007-11-26 Jim Evins <evins@snaught.com>
+
+ * 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 <evins@snaught.com>
* data/glade/template-designer.glade:
xml-paper.h \
xml-category.h \
xml-template.h \
- xml.h
+ xml.h \
+ str.h
EXTRA_DIST = \
libglabels.pc.in
#include <libglabels/category.h>
#include <libglabels/template.h>
#include <libglabels/enums.h>
+#include <libglabels/str.h>
#include <libglabels/xml-paper.h>
#include <libglabels/xml-category.h>
#include <libglabels/xml-template.h>
#include <glib/gi18n.h>
#include "marshal.h"
+#include "prefs.h"
#include "util.h"
#include "debug.h"
gl_label_set_template (glLabel *label,
lglTemplate *template)
{
+ gchar *name;
+
gl_debug (DEBUG_LABEL, "START");
g_return_if_fail (label && GL_IS_LABEL (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");
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);
#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"
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);
{
gchar *string;
lglPaper *paper;
+ GSList *p;
gl_debug (DEBUG_PREFS, "START");
/* 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,
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.) */
/* Recent files */
gint max_recents;
+
+ /* Recent templates */
+ GSList *recent_templates;
+ gint max_recent_templates;
};
struct _glPrefsModelClass {
#include "prefs.h"
#include <glib/gi18n.h>
+#include <libglabels/libglabels.h>
#include "debug.h"
}
}
+/****************************************************************************/
+/* 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);
+}
gint gl_prefs_get_units_precision (void);
+void gl_prefs_add_recent_template (const gchar *name);
+
G_END_DECLS
#endif /* __PREFS_H__ */