]> git.sur5r.net Git - glabels/commitdiff
2007-11-26 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 27 Nov 2007 04:42:41 +0000 (04:42 +0000)
committerJim Evins <evins@snaught.com>
Tue, 27 Nov 2007 04:42:41 +0000 (04:42 +0000)
* 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

glabels2/ChangeLog
glabels2/libglabels/Makefile.am
glabels2/libglabels/libglabels.h
glabels2/src/label.c
glabels2/src/prefs-dialog.c
glabels2/src/prefs-model.c
glabels2/src/prefs-model.h
glabels2/src/prefs.c
glabels2/src/prefs.h

index 73aaece3c76626ebbd5e49b1cd87af8762d1f980..c5f498e9ea939e1e7e0ade5287ac922f72d16ae9 100644 (file)
@@ -1,3 +1,16 @@
+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:
index 5bc36773f9fdb746bfbe170d49952e2477d05cf0..2d1228ab9119a6905d46ed11710744c7de999512 100644 (file)
@@ -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
index 45c62128ab17c75b45e305fe4e1ead04666c9244..c74fbe01a2d6053f92fe93bdf636efa30b3a74e9 100644 (file)
@@ -31,6 +31,7 @@
 #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>
index a68bb43c4111f6b1a05e65c050990af7e8b18c33..c886529bf629ffed94539570f579581423b90d1c 100644 (file)
@@ -29,6 +29,7 @@
 #include <glib/gi18n.h>
 
 #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");
index 218f11daadad80cc5f28e03d9c0f128232bd1d22..683926fb906d22ed9ae4663f0ad7c6a1da30701f 100644 (file)
@@ -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);
index 5183202493ec4ad16cd78759763169973453a176..c49c155eac9e093282d894d7e0c593a31d011520 100644 (file)
@@ -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.) */
index 2303e1712ef2f09701630fa678836244d06ffd8b..b2cc1cbd85289ee79154971bf5c295081afe181c 100644 (file)
@@ -97,6 +97,10 @@ struct _glPrefsModel {
 
        /* Recent files */
        gint              max_recents;
+
+       /* Recent templates */
+        GSList           *recent_templates;
+       gint              max_recent_templates;
 };
 
 struct _glPrefsModelClass {
index c2ef4e3a40457f949505d6b46b55f24988721754..32011b790d632a90eb266c0e6b4bb63c06f16efd 100644 (file)
@@ -26,6 +26,7 @@
 #include "prefs.h"
 
 #include <glib/gi18n.h>
+#include <libglabels/libglabels.h>
 
 #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);
+}
index b4da528dc8dfec2f0d98757c9cb2b1f15b4199bc..98474f5c8f2897db0cf7ad84d7b17e8ba252a534 100644 (file)
@@ -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__ */