/po/*.gmo
/po/POTFILES
/po/stamp-it
+/po/glabels.pot
/help/glabels-*.omf
/help/*/.xml2po.mo
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
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 \
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 \
gl_merge_init ();
lgl_db_init ();
gl_prefs_init ();
+ gl_template_history_init ();
gl_font_history_init ();
/* now print the files */
gl_mini_preview_pixbuf_cache_init ();
gl_merge_init ();
gl_recent_init ();
+ gl_template_history_init ();
gl_font_history_init ();
#include <glib/gi18n.h>
-#include "prefs.h"
+#include "template-history.h"
#include "file-util.h"
#include "marshal.h"
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);
}
#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)
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);
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.) */
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);
/* Recent files */
gint max_recents;
- /* Recent templates */
- GSList *recent_templates;
- gint max_recent_templates;
};
struct _glPrefsModelClass {
}
}
-/****************************************************************************/
-/* 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
--- /dev/null
+/*
+ * 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
+ */
--- /dev/null
+/*
+ * 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
+ */
--- /dev/null
+/*
+ * 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
+ */
--- /dev/null
+/*
+ * 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
+ */
#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"
#include "debug.h"
+#define HISTORY_SIZE 5
+
/*===========================================*/
/* Private types */
/*===========================================*/
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);
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;
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);
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);
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");
}
static void
load_recent_list (GtkListStore *store,
GtkTreeSelection *selection,
- GSList *list)
+ GList *list)
{
- GSList *p;
+ GList *p;
GtkTreeIter iter;
lglTemplate *template;
GdkPixbuf *pixbuf;