[glabels] Created new glTemplateHistoryModel



commit ebe7c16c62c4d724b2a09b51c8a7c72c42cb0960
Author: Jim Evins <evins snaught com>
Date:   Sat Oct 24 09:58:52 2009 -0400

    Created new glTemplateHistoryModel
    
    Pulled recent template history from glPrefsModel and created a separate
    glTemplateHistoryModel object to track this history.  Based on
    glFontHistoryModel.

 .gitignore                   |    1 +
 po/POTFILES.in               |    4 +
 src/Makefile.am              |    8 +
 src/glabels-batch.c          |    1 +
 src/glabels.c                |    1 +
 src/label.c                  |    4 +-
 src/prefs-model.c            |   41 ------
 src/prefs-model.h            |    3 -
 src/prefs.c                  |   47 -------
 src/prefs.h                  |    1 -
 src/template-history-model.c |  290 ++++++++++++++++++++++++++++++++++++++++++
 src/template-history-model.h |   89 +++++++++++++
 src/template-history.c       |   67 ++++++++++
 src/template-history.h       |   50 +++++++
 src/wdgt-media-select.c      |   16 ++-
 15 files changed, 524 insertions(+), 99 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index df5d29c..15f4b69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,6 +53,7 @@ Makefile.in.in
 /po/*.gmo
 /po/POTFILES
 /po/stamp-it
+/po/glabels.pot
 
 /help/glabels-*.omf
 /help/*/.xml2po.mo
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f83e8ca..69435c3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -141,6 +141,10 @@ src/str-util.c
 src/str-util.h
 src/template-designer.c
 src/template-designer.h
+src/template-history.c
+src/template-history.h
+src/template-history-model.c
+src/template-history-model.h
 src/text-node.c
 src/text-node.h
 src/ui.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 36de5af..55e5e2f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -171,6 +171,10 @@ glabels_SOURCES = 			\
 	mini-preview-pixbuf-cache.h	\
 	wdgt-media-select.c		\
 	wdgt-media-select.h		\
+	template-history.c		\
+	template-history.h		\
+	template-history-model.c	\
+	template-history-model.h	\
 	mini-preview.c			\
 	mini-preview.h			\
 	mini-label-preview.c		\
@@ -290,6 +294,10 @@ glabels_batch_SOURCES = 		\
 	font-history.h			\
 	font-history-model.c		\
 	font-history-model.h		\
+	template-history.c		\
+	template-history.h		\
+	template-history-model.c	\
+	template-history-model.h	\
 	str-util.c			\
 	str-util.h			\
 	color.c				\
diff --git a/src/glabels-batch.c b/src/glabels-batch.c
index b3113cb..b05673b 100644
--- a/src/glabels-batch.c
+++ b/src/glabels-batch.c
@@ -128,6 +128,7 @@ main (int argc, char **argv)
         gl_merge_init ();
         lgl_db_init ();
 	gl_prefs_init ();
+        gl_template_history_init ();
         gl_font_history_init ();
 
         /* now print the files */
diff --git a/src/glabels.c b/src/glabels.c
index 61f4dc8..43d1290 100644
--- a/src/glabels.c
+++ b/src/glabels.c
@@ -116,6 +116,7 @@ main (int argc, char **argv)
 	gl_mini_preview_pixbuf_cache_init ();
 	gl_merge_init ();
 	gl_recent_init ();
+        gl_template_history_init ();
         gl_font_history_init ();
 	
 
diff --git a/src/label.c b/src/label.c
index 659c110..9de9a73 100644
--- a/src/label.c
+++ b/src/label.c
@@ -24,7 +24,7 @@
 
 #include <glib/gi18n.h>
 
-#include "prefs.h"
+#include "template-history.h"
 #include "file-util.h"
 #include "marshal.h"
 
@@ -408,7 +408,7 @@ gl_label_set_template (glLabel     *label,
 		g_signal_emit (G_OBJECT(label), signals[CHANGED], 0);
 
                 name = lgl_template_get_name (template);
-                gl_prefs_add_recent_template (name);
+                gl_template_history_model_add_name (gl_template_history, name);
                 g_free (name);
 	}
 
diff --git a/src/prefs-model.c b/src/prefs-model.c
index 1ec1c0b..3aefa08 100644
--- a/src/prefs-model.c
+++ b/src/prefs-model.c
@@ -69,8 +69,6 @@
 
 #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_US    units_to_string (LGL_UNITS_INCH)
@@ -350,17 +348,6 @@ 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);
 	
@@ -509,22 +496,6 @@ 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.) */
@@ -536,18 +507,6 @@ 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/src/prefs-model.h b/src/prefs-model.h
index bb5ca18..e01b048 100644
--- a/src/prefs-model.h
+++ b/src/prefs-model.h
@@ -92,9 +92,6 @@ struct _glPrefsModel {
 	/* Recent files */
 	gint              max_recents;
 
-	/* Recent templates */
-        GSList           *recent_templates;
-	gint              max_recent_templates;
 };
 
 struct _glPrefsModelClass {
diff --git a/src/prefs.c b/src/prefs.c
index 85922bf..198e852 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -164,53 +164,6 @@ 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/src/prefs.h b/src/prefs.h
index 5787deb..6e389ff 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -45,7 +45,6 @@ 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
 
diff --git a/src/template-history-model.c b/src/template-history-model.c
new file mode 100644
index 0000000..7d70b76
--- /dev/null
+++ b/src/template-history-model.c
@@ -0,0 +1,290 @@
+/*
+ *  template-history-model.c
+ *  Copyright (C) 2009  Jim Evins <evins snaught com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "template-history-model.h"
+
+#include <gconf/gconf-client.h>
+
+#include <libglabels/libglabels.h>
+#include "marshal.h"
+
+
+#define BASE_KEY              "/apps/glabels"
+#define RECENT_TEMPLATES_KEY  BASE_KEY "/recent-templates"
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+/** GL_TEMPLATE_HISTORY_MODEL Private fields */
+struct _glTemplateHistoryModelPrivate {
+
+	GConfClient *gconf_client;
+
+        guint        max_n;
+};
+
+enum {
+	CHANGED,
+	LAST_SIGNAL
+};
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+static void gl_template_history_model_finalize (GObject                 *object);
+
+static void conf_notify_cb                     (GConfClient             *client,
+                                                guint                    cnxn_id,
+                                                GConfEntry              *entry,
+                                                glTemplateHistoryModel  *this);
+
+
+/*****************************************************************************/
+/* Object infrastructure.                                                    */
+/*****************************************************************************/
+G_DEFINE_TYPE (glTemplateHistoryModel, gl_template_history_model, G_TYPE_OBJECT);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_template_history_model_class_init (glTemplateHistoryModelClass *class)
+{
+        GObjectClass  *gobject_class = (GObjectClass *) class;
+
+        gl_template_history_model_parent_class = g_type_class_peek_parent (class);
+
+        gobject_class->finalize = gl_template_history_model_finalize;
+
+	signals[CHANGED] =
+		g_signal_new ("changed",
+			      G_OBJECT_CLASS_TYPE (gobject_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (glTemplateHistoryModelClass, changed),
+			      NULL, NULL,
+			      gl_marshal_VOID__VOID,
+			      G_TYPE_NONE,
+			      0);
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_template_history_model_init (glTemplateHistoryModel *this)
+{
+        this->priv = g_new0 (glTemplateHistoryModelPrivate, 1);
+
+        this->priv->gconf_client = gconf_client_get_default ();
+
+        g_return_if_fail (this->priv->gconf_client != NULL);
+
+        gconf_client_add_dir (this->priv->gconf_client,
+                              BASE_KEY,
+                              GCONF_CLIENT_PRELOAD_ONELEVEL,
+                              NULL);
+
+        gconf_client_notify_add (this->priv->gconf_client,
+                                 RECENT_TEMPLATES_KEY,
+                                 (GConfClientNotifyFunc)conf_notify_cb, this,
+                                 NULL, NULL);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_template_history_model_finalize (GObject *object)
+{
+        glTemplateHistoryModel    *this;
+
+        g_return_if_fail (object && IS_GL_TEMPLATE_HISTORY_MODEL (object));
+        this = GL_TEMPLATE_HISTORY_MODEL (object);
+
+        g_object_unref (G_OBJECT(this->priv->gconf_client));
+        g_free (this->priv);
+
+        G_OBJECT_CLASS (gl_template_history_model_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+glTemplateHistoryModel *
+gl_template_history_model_new (guint n)
+{
+        glTemplateHistoryModel *this;
+
+        this = g_object_new (TYPE_GL_TEMPLATE_HISTORY_MODEL, NULL);
+
+        this->priv->max_n = n;
+
+        return this;
+}
+
+
+/*****************************************************************************/
+/* Add template to history.                                                      */
+/*****************************************************************************/
+void
+gl_template_history_model_add_name (glTemplateHistoryModel *this,
+                                    const gchar            *name)
+{
+        GSList *list = NULL;
+        GList  *old_list;
+        GList  *p;
+        GSList *ps;
+
+        /*
+         * Start new list with this name.
+         */
+        list = g_slist_append (list, (gchar *)name);
+
+        /*
+         * Transfer old list to new list, ignoring any duplicate of this name
+         */
+        old_list = gl_template_history_model_get_name_list (this);
+        for ( p = old_list; p; p=p->next )
+        {
+                if ( lgl_str_utf8_casecmp (name, p->data) )
+                {
+                        list = g_slist_append (list, p->data);
+                }
+                else
+                {
+                        g_free (p->data);
+                }
+        }
+        g_list_free (old_list);
+
+        /*
+         * Truncate list to maximum size
+         */
+        while (g_slist_length (list) > this->priv->max_n)
+        {
+                ps = g_slist_last (list);
+                list = g_slist_remove_link (list, ps);
+                g_slist_free_1 (ps);
+        }
+
+        /*
+         * Update conf
+         */
+        gconf_client_set_list (this->priv->gconf_client,
+                               RECENT_TEMPLATES_KEY,
+                               GCONF_VALUE_STRING,
+                               list,
+                               NULL);
+}
+
+
+/*****************************************************************************/
+/* GConf notify callback.                                                    */
+/*****************************************************************************/
+static void
+conf_notify_cb (GConfClient         *client,
+                guint                cnxn_id,
+                GConfEntry          *entry,
+                glTemplateHistoryModel  *this)
+{
+        g_signal_emit (G_OBJECT(this), signals[CHANGED], 0);
+}
+
+
+/*****************************************************************************/
+/* Get list of template families.                                            */
+/*****************************************************************************/
+GList *
+gl_template_history_model_get_name_list (glTemplateHistoryModel *this)
+{
+        GList  *list = NULL;
+        GSList *tmp_list;
+        GSList *p;
+
+        /*
+         * Get name list.
+         */
+	tmp_list = gconf_client_get_list (this->priv->gconf_client,
+                                          RECENT_TEMPLATES_KEY,
+                                          GCONF_VALUE_STRING,
+                                          NULL);
+
+        /*
+         * Proof read name list; transfer storage to new list.
+         */
+        for (p=tmp_list; p != NULL; p=p->next)
+        {
+                if ( lgl_db_does_template_name_exist (p->data) )
+                {
+                        list = g_list_append (list, p->data);
+                }
+                else
+                {
+                        g_free (p->data);
+                }
+        }
+        g_slist_free (tmp_list);
+
+        return list;
+}
+
+
+/*****************************************************************************/
+/* Free template name list.                                                  */
+/*****************************************************************************/
+void
+gl_template_history_model_free_name_list (GList *list)
+{
+        GList *p;
+
+        for ( p = list; p; p=p->next )
+        {
+                g_free (p->data);
+        }
+        g_list_free (list);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/template-history-model.h b/src/template-history-model.h
new file mode 100644
index 0000000..1de9866
--- /dev/null
+++ b/src/template-history-model.h
@@ -0,0 +1,89 @@
+/*
+ *  template-history-model.h
+ *  Copyright (C) 2009  Jim Evins <evins snaught com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_TEMPLATE_HISTORY_MODEL_H__
+#define __GL_TEMPLATE_HISTORY_MODEL_H__
+
+
+#include <glib-object.h>
+
+
+G_BEGIN_DECLS
+
+/* Utility Macros */
+#define TYPE_GL_TEMPLATE_HISTORY_MODEL              (gl_template_history_model_get_type ())
+#define GL_TEMPLATE_HISTORY_MODEL(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_TEMPLATE_HISTORY_MODEL, glTemplateHistoryModel))
+#define GL_TEMPLATE_HISTORY_MODEL_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_TEMPLATE_HISTORY_MODEL, glTemplateHistoryModelClass))
+#define IS_GL_TEMPLATE_HISTORY_MODEL(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_TEMPLATE_HISTORY_MODEL))
+#define IS_GL_TEMPLATE_HISTORY_MODEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_TEMPLATE_HISTORY_MODEL))
+#define GL_TEMPLATE_HISTORY_MODEL_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_TEMPLATE_HISTORY_MODEL, glTemplateHistoryModelClass))
+
+
+/* Type definitions */
+typedef struct _glTemplateHistoryModel          glTemplateHistoryModel;
+typedef struct _glTemplateHistoryModelPrivate   glTemplateHistoryModelPrivate;
+typedef struct _glTemplateHistoryModelClass     glTemplateHistoryModelClass;
+
+
+/** GL_TEMPLATE_HISTORY_MODEL Object */
+struct _glTemplateHistoryModel {
+        GObject                           parent;
+
+        glTemplateHistoryModelPrivate    *priv;
+};
+
+/** GL_TEMPLATE_HISTORY_MODEL Class */
+struct _glTemplateHistoryModelClass {
+        GObjectClass                      parent_class;
+
+        /*
+         * Signals
+         */
+        void (*changed)     (glTemplateHistoryModel *this,
+                             gpointer                user_data);
+
+};
+
+
+GType                   gl_template_history_model_get_type       (void) G_GNUC_CONST;
+
+glTemplateHistoryModel *gl_template_history_model_new            (guint                   n);
+
+void                    gl_template_history_model_add_name       (glTemplateHistoryModel *this,
+                                                                  const gchar            *name);
+
+GList                  *gl_template_history_model_get_name_list  (glTemplateHistoryModel *this);
+void                    gl_template_history_model_free_name_list (GList                  *list);
+
+
+G_END_DECLS
+
+#endif /* __GL_TEMPLATE_HISTORY_MODEL_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/template-history.c b/src/template-history.c
new file mode 100644
index 0000000..166567c
--- /dev/null
+++ b/src/template-history.c
@@ -0,0 +1,67 @@
+/*
+ *  template-history.c
+ *  Copyright (C) 2009  Jim Evins <evins snaught com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "template-history.h"
+
+
+#define MAX_TEMPLATES 5
+
+
+/*========================================================*/
+/* Public globals.                                        */
+/*========================================================*/
+
+glTemplateHistoryModel *gl_template_history = NULL;
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+
+/*****************************************************************************/
+/* Initialize template history.                                                  */
+/*****************************************************************************/
+void
+gl_template_history_init (void)
+{
+        gl_template_history = gl_template_history_model_new (MAX_TEMPLATES);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/template-history.h b/src/template-history.h
new file mode 100644
index 0000000..4b0e784
--- /dev/null
+++ b/src/template-history.h
@@ -0,0 +1,50 @@
+/*
+ *  template-history.h
+ *  Copyright (C) 2009  Jim Evins <evins snaught com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_TEMPLATE_HISTORY_H__
+#define __GL_TEMPLATE_HISTORY_H__
+
+
+#include "template-history-model.h"
+
+
+G_BEGIN_DECLS
+
+
+glTemplateHistoryModel *gl_template_history;
+
+
+void            gl_template_history_init (void);
+
+
+G_END_DECLS
+
+#endif /* __GL_TEMPLATE_HISTORY_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/wdgt-media-select.c b/src/wdgt-media-select.c
index 0ad6780..c7cb8de 100644
--- a/src/wdgt-media-select.c
+++ b/src/wdgt-media-select.c
@@ -29,6 +29,7 @@
 #include <libglabels/libglabels.h>
 #include "mini-preview-pixbuf-cache.h"
 #include "prefs.h"
+#include "template-history.h"
 #include "str-util.h"
 #include "combo-util.h"
 #include "builder-util.h"
@@ -38,6 +39,8 @@
 #include "debug.h"
 
 
+#define HISTORY_SIZE 5
+
 /*===========================================*/
 /* Private types                             */
 /*===========================================*/
@@ -111,7 +114,7 @@ static gchar *get_layout_desc                  (const lglTemplate      *template
 static gchar *get_label_size_desc              (const lglTemplate      *template);
 static void   load_recent_list                 (GtkListStore           *store,
                                                 GtkTreeSelection       *selection,
-                                                GSList                 *list);
+                                                GList                  *list);
 static void   load_search_all_list             (GtkListStore           *store,
                                                 GtkTreeSelection       *selection,
                                                 GList                  *list);
@@ -209,6 +212,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
         static gchar      *object_ids[] = { "wdgt_media_select_hbox", NULL };
         GError            *error = NULL;
         GtkWidget         *hbox;
+        GList             *recent_list = NULL;
         GList             *brands = NULL;
         GList             *page_sizes = NULL;
         GList             *categories = NULL;
@@ -279,7 +283,8 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
         gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
         gtk_tree_view_append_column (GTK_TREE_VIEW (media_select->priv->recent_treeview), column);
         recent_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (media_select->priv->recent_treeview));
-        load_recent_list (media_select->priv->recent_store, recent_selection, gl_prefs->recent_templates);
+        recent_list = gl_template_history_model_get_name_list (gl_template_history);
+        load_recent_list (media_select->priv->recent_store, recent_selection, recent_list);
 
         page_size_id = gl_prefs_get_page_size ();
         page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id);
@@ -357,7 +362,7 @@ 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 )
+        if ( recent_list )
         {
                 gtk_notebook_set_current_page (GTK_NOTEBOOK (media_select->priv->notebook),
                                                media_select->priv->recent_page_num);
@@ -367,6 +372,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
                 gtk_notebook_set_current_page (GTK_NOTEBOOK (media_select->priv->notebook),
                                                media_select->priv->search_all_page_num);
         }
+        gl_template_history_model_free_name_list (recent_list);
 
         gl_debug (DEBUG_MEDIA_SELECT, "END");
 }
@@ -734,9 +740,9 @@ get_label_size_desc (const lglTemplate *template)
 static void
 load_recent_list (GtkListStore           *store,
                   GtkTreeSelection       *selection,
-                  GSList                  *list)
+                  GList                  *list)
 {
-        GSList      *p;
+        GList       *p;
         GtkTreeIter  iter;
         lglTemplate *template;
         GdkPixbuf   *pixbuf;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]