]> git.sur5r.net Git - glabels/commitdiff
Created new glTemplateHistoryModel
authorJim Evins <evins@snaught.com>
Sat, 24 Oct 2009 13:58:52 +0000 (09:58 -0400)
committerJim Evins <evins@snaught.com>
Sat, 24 Oct 2009 13:58:52 +0000 (09:58 -0400)
Pulled recent template history from glPrefsModel and created a separate
glTemplateHistoryModel object to track this history.  Based on
glFontHistoryModel.

15 files changed:
.gitignore
po/POTFILES.in
src/Makefile.am
src/glabels-batch.c
src/glabels.c
src/label.c
src/prefs-model.c
src/prefs-model.h
src/prefs.c
src/prefs.h
src/template-history-model.c [new file with mode: 0644]
src/template-history-model.h [new file with mode: 0644]
src/template-history.c [new file with mode: 0644]
src/template-history.h [new file with mode: 0644]
src/wdgt-media-select.c

index df5d29c71b904d46ad62eaa681042466118d43b8..15f4b69ea6d93dde8b79e690330de0240ca5572e 100644 (file)
@@ -53,6 +53,7 @@ Makefile.in.in
 /po/*.gmo
 /po/POTFILES
 /po/stamp-it
+/po/glabels.pot
 
 /help/glabels-*.omf
 /help/*/.xml2po.mo
index f83e8cafeb75eb974d093df6ccca2c303fd85349..69435c32426caf0483ef09a3bf41b73915666933 100644 (file)
@@ -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
index 36de5af874a8cf72be92ed68e04765259bd78746..55e5e2fc0bb140994192b60c4975f08aea5a45c2 100644 (file)
@@ -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                         \
index b3113cbc5159f451fc84cd92ce80bf688a741e57..b05673bd2e33966d35d69ffb86260791edf0d316 100644 (file)
@@ -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 */
index 61f4dc8829b321cc826f2736a8d87675b5d2c030..43d1290919d86a488e24bfe90be1130e43e8399c 100644 (file)
@@ -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 ();
        
 
index 659c1107b80affa7f88f6cbad7e3d4bca9d62784..9de9a730d96fab74ef052992ee0adbca12bd72e0 100644 (file)
@@ -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);
        }
 
index 1ec1c0bdb457da32d5c24b0ed81a85740200d238..3aefa08af986eb7ecee13da206917147f5da045b 100644 (file)
@@ -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);
 
index bb5ca1807853fbcd79867c7f70c58e7c6f1b7755..e01b0481f252cf5ced5de3f5911ec7b895179d6b 100644 (file)
@@ -92,9 +92,6 @@ struct _glPrefsModel {
        /* Recent files */
        gint              max_recents;
 
-       /* Recent templates */
-        GSList           *recent_templates;
-       gint              max_recent_templates;
 };
 
 struct _glPrefsModelClass {
index 85922bf552ff7e0dba2fb6d029027f8b8b3ca4ee..198e852294e290c0c0330c2ab9f5e3165263008f 100644 (file)
@@ -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);
-}
-
-
 
 
 /*
index 5787debb3329b2d1fae277023f8e1e5b21f1fe62..6e389ff22d120d09e2dfb867fe5e862eba6b390e 100644 (file)
@@ -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 (file)
index 0000000..7d70b76
--- /dev/null
@@ -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 (file)
index 0000000..1de9866
--- /dev/null
@@ -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 (file)
index 0000000..166567c
--- /dev/null
@@ -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 (file)
index 0000000..4b0e784
--- /dev/null
@@ -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
+ */
index 0ad67804513679f37daa009b098cafb6871015fc..c7cb8de0ce46247b09c6d7b64e888d45f1a1e753 100644 (file)
@@ -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;