]> git.sur5r.net Git - glabels/commitdiff
- Changed gl_prefs from a simple structure to a full-fledged object (prefs_model).
authorJim Evins <evins@snaught.com>
Sat, 6 Dec 2003 14:49:16 +0000 (14:49 +0000)
committerJim Evins <evins@snaught.com>
Sat, 6 Dec 2003 14:49:16 +0000 (14:49 +0000)
- Moved prefs_init after paper_init so that page size proof reading code in prefs_model_load_settings works properly.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@369 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/Makefile.am
glabels2/src/commands.c
glabels2/src/glabels.c
glabels2/src/prefs-dialog.c
glabels2/src/prefs-model.c [new file with mode: 0644]
glabels2/src/prefs-model.h [new file with mode: 0644]
glabels2/src/prefs.c
glabels2/src/prefs.h
glabels2/src/template.c
glabels2/src/ui.c

index ee2494a66857ce69053c142e44d6bb322fbf909d..19de0b58e7d699936f6c72d9149e2614fa31cf53 100644 (file)
@@ -70,6 +70,8 @@ glabels_SOURCES =                     \
        tools.c                         \
        prefs.c                         \
        prefs.h                         \
+       prefs-model.c                   \
+       prefs-model.h                   \
        prefs-dialog.c                  \
        prefs-dialog.h                  \
        hig.c                           \
@@ -239,6 +241,8 @@ glabels_batch_SOURCES =             \
        text-node.h                     \
        prefs.c                         \
        prefs.h                         \
+       prefs-model.c                   \
+       prefs-model.h                   \
        util.c                          \
        util.h                          \
        debug.c                         \
index b959ed186ee8942fa4a52bda3ce907a96a27d265..ee029948e50e92fc855d6eb1b80cd1cc0079714f 100644 (file)
@@ -137,7 +137,7 @@ gl_cmd_file_print (BonoboUIComponent *uic,
 
        if (GL_VIEW(window->view)->print_dialog) {
 
-               gtk_window_present (GL_VIEW(window->view)->print_dialog);
+               gtk_window_present (GTK_WINDOW(GL_VIEW(window->view)->print_dialog));
 
        } else {
 
index 8ae50f1ea9b493766c5c7971ce104016217e5074..5472a016f6ac725b7ba64c856c2dfe2ad754e213 100644 (file)
@@ -173,12 +173,9 @@ main (int argc, char **argv)
                gnome_window_icon_set_default_from_file (ICON_PIXMAP);
        }
        
-       /* Load user preferences */
-       gl_prefs_init ();
-       gl_prefs_load_settings ();
-
        /* Initialize subsystems */
        gl_paper_init();
+       gl_prefs_init ();
        gl_template_init();
        gl_merge_init();
        gl_recent_init();
index e24d87c1155deb9b6b09bf7a6ea90c751aa6aa52..7128fb89d51e1d25095e0a76e7b2db6d22d3577f 100644 (file)
@@ -199,6 +199,7 @@ gl_prefs_dialog_new (GtkWindow *parent)
        GtkWidget *dlg;
 
        gl_debug (DEBUG_PREFS, "START");
+       gl_debug (DEBUG_PREFS, "page size = \"%s\"", gl_prefs->default_page_size);
 
        dlg = GTK_WIDGET (g_object_new (GL_TYPE_PREFS_DIALOG, NULL));
 
@@ -469,17 +470,17 @@ update_locale_page_from_prefs (glPrefsDialog *dlg)
                G_CALLBACK(update_prefs_from_locale_page), G_OBJECT(dlg));
 
        switch (gl_prefs->units) {
-       case GL_PREFS_UNITS_PTS:
+       case GL_UNITS_PTS:
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dlg->priv->units_points_radio),
                        TRUE);
                break;
-       case GL_PREFS_UNITS_INCHES:
+       case GL_UNITS_INCHES:
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dlg->priv->units_inches_radio),
                        TRUE);
                break;
-       case GL_PREFS_UNITS_MM:
+       case GL_UNITS_MM:
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dlg->priv->units_mm_radio),
                        TRUE);
@@ -522,7 +523,7 @@ update_locale_page_from_prefs (glPrefsDialog *dlg)
 /* PRIVATE.  Update object page widgets from current prefs.                 */
 /*--------------------------------------------------------------------------*/
 static void
- update_object_page_from_prefs (glPrefsDialog *dlg)
+update_object_page_from_prefs (glPrefsDialog *dlg)
 {
         GList    *family_names;
         gchar    *good_font_family;
@@ -657,15 +658,15 @@ update_prefs_from_locale_page (glPrefsDialog *dlg)
 {
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dlg->priv->units_points_radio))) {
-               gl_prefs->units = GL_PREFS_UNITS_PTS;
+               gl_prefs->units = GL_UNITS_PTS;
        }
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dlg->priv->units_inches_radio))) {
-               gl_prefs->units = GL_PREFS_UNITS_INCHES;
+               gl_prefs->units = GL_UNITS_INCHES;
        }
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dlg->priv->units_mm_radio))) {
-               gl_prefs->units = GL_PREFS_UNITS_MM;
+               gl_prefs->units = GL_UNITS_MM;
        }
 
        if (gtk_toggle_button_get_active (
@@ -677,7 +678,7 @@ update_prefs_from_locale_page (glPrefsDialog *dlg)
                gl_prefs->default_page_size = A4_ID;
        }
 
-       gl_prefs_save_settings ();
+       gl_prefs_model_save_settings (gl_prefs);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -747,7 +748,7 @@ update_prefs_from_object_page (glPrefsDialog *dlg)
                 gl_prefs->default_fill_color = gl_color_from_gdk_color (gdk_color);
         }
 
-       gl_prefs_save_settings ();
+       gl_prefs_model_save_settings (gl_prefs);
 }
 
 
diff --git a/glabels2/src/prefs-model.c b/glabels2/src/prefs-model.c
new file mode 100644 (file)
index 0000000..d1c42cc
--- /dev/null
@@ -0,0 +1,685 @@
+/*
+ *  (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ *  prefs-model.c:  Application preferences model module
+ *
+ *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+#include <config.h>
+
+
+#include "marshal.h"
+#include "prefs-model.h"
+#include "util.h"
+#include "paper.h"
+#include "color.h"
+
+#include "debug.h"
+
+/*========================================================*/
+/* Private macros and constants.                          */
+/*========================================================*/
+
+/* GConf keys */
+#define BASE_KEY                            "/apps/glabels"
+
+#define PREF_UNITS                          "/units"
+#define PREF_DEFAULT_PAGE_SIZE              "/default-page-size"
+
+#define PREF_DEFAULT_FONT_FAMILY            "/default-font-family"
+#define PREF_DEFAULT_FONT_SIZE              "/default-font-size"
+#define PREF_DEFAULT_FONT_WEIGHT            "/default-font-weight"
+#define PREF_DEFAULT_FONT_ITALIC_FLAG       "/default-font-italic-flag"
+#define PREF_DEFAULT_TEXT_COLOR             "/default-text-color"
+#define PREF_DEFAULT_TEXT_ALIGNMENT         "/default-text-alignment"
+
+#define PREF_DEFAULT_LINE_WIDTH             "/default-line-width"
+#define PREF_DEFAULT_LINE_COLOR             "/default-line-color"
+
+#define PREF_DEFAULT_FILL_COLOR             "/default-fill-color"
+
+#define PREF_MAIN_TOOLBAR_VISIBLE           "/main-toolbar-visible"
+#define PREF_MAIN_TOOLBAR_BUTTONS_STYLE     "/main-toolbar-buttons-style"
+#define PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS     "/main-toolbar-view-tooltips"
+
+#define PREF_DRAWING_TOOLBAR_VISIBLE        "/drawing-toolbar-visible"
+#define PREF_DRAWING_TOOLBAR_BUTTONS_STYLE  "/drawing-toolbar-buttons-style"
+#define PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS  "/drawing-toolbar-view-tooltips"
+
+#define PREF_GRID_VISIBLE                   "/grid-visible"
+#define PREF_MARKUP_VISIBLE                 "/markup-visible"
+
+#define PREF_MAX_RECENTS                    "/max-recents"
+
+/* Default values */
+#define DEFAULT_UNITS_STRING       units_to_string (GL_UNITS_INCHES)
+#define DEFAULT_PAGE_SIZE          "US-Letter"
+
+#define DEFAULT_FONT_FAMILY        "Sans"
+#define DEFAULT_FONT_SIZE          14.0
+#define DEFAULT_FONT_WEIGHT_STRING gl_util_weight_to_string (GNOME_FONT_BOOK)
+#define DEFAULT_FONT_ITALIC_FLAG   FALSE
+#define DEFAULT_TEXT_JUST_STRING   gl_util_just_to_string (GTK_JUSTIFY_LEFT)
+#define DEFAULT_TEXT_COLOR         GNOME_CANVAS_COLOR (0,0,0)
+
+#define DEFAULT_LINE_WIDTH         1.0
+#define DEFAULT_LINE_COLOR         GNOME_CANVAS_COLOR_A (0, 0, 0, 255)
+
+#define DEFAULT_FILL_COLOR         GNOME_CANVAS_COLOR_A (0, 255, 0, 255)
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+enum {
+       CHANGED,
+       LAST_SIGNAL
+};
+
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static GObjectClass *parent_class = NULL;
+
+static guint signals[LAST_SIGNAL] = {0};
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+static void           gl_prefs_model_class_init    (glPrefsModelClass   *klass);
+static void           gl_prefs_model_instance_init (glPrefsModel        *object);
+static void           gl_prefs_model_finalize      (GObject             *object);
+
+static void           notify_cb                    (GConfClient         *client,
+                                                   guint                cnxn_id,
+                                                   GConfEntry          *entry,
+                                                   glPrefsModel        *prefs_model);
+
+static gchar         *get_string                   (GConfClient         *client,
+                                                   const gchar         *key,
+                                                   const gchar         *def);
+
+static gboolean       get_bool                     (GConfClient         *client,
+                                                   const gchar         *key,
+                                                   gboolean             def);
+
+static gint           get_int                      (GConfClient         *client,
+                                                   const gchar         *key,
+                                                   gint                 def);
+
+static gdouble        get_float                    (GConfClient         *client,
+                                                   const gchar         *key,
+                                                   gdouble              def);
+
+static glPrefsUnits   string_to_units              (const gchar         *string);
+static const gchar   *units_to_string              (glPrefsUnits         units);
+
+
+\f
+/*****************************************************************************/
+/* Boilerplate object stuff.                                                 */
+/*****************************************************************************/
+GType
+gl_prefs_model_get_type (void)
+{
+       static GType type = 0;
+
+       if (!type) {
+               GTypeInfo info = {
+                       sizeof (glPrefsModelClass),
+                       NULL,
+                       NULL,
+                       (GClassInitFunc) gl_prefs_model_class_init,
+                       NULL,
+                       NULL,
+                       sizeof (glPrefsModel),
+                       0,
+                       (GInstanceInitFunc) gl_prefs_model_instance_init,
+               };
+
+               type = g_type_register_static (G_TYPE_OBJECT,
+                                              "glPrefsModel", &info, 0);
+       }
+
+       return type;
+}
+
+static void
+gl_prefs_model_class_init (glPrefsModelClass *klass)
+{
+       GObjectClass *object_class = (GObjectClass *) klass;
+
+       gl_debug (DEBUG_PREFS, "START");
+
+       parent_class = g_type_class_peek_parent (klass);
+
+       object_class->finalize = gl_prefs_model_finalize;
+
+       signals[CHANGED] =
+               g_signal_new ("changed",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (glPrefsModelClass, changed),
+                             NULL, NULL,
+                             gl_marshal_VOID__VOID,
+                             G_TYPE_NONE,
+                             0);
+
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+static void
+gl_prefs_model_instance_init (glPrefsModel *prefs_model)
+{
+       gl_debug (DEBUG_PREFS, "START");
+
+        prefs_model->gconf_client = gconf_client_get_default ();
+
+        g_return_if_fail (prefs_model->gconf_client != NULL);
+        gconf_client_add_dir (prefs_model->gconf_client,
+                              BASE_KEY,
+                              GCONF_CLIENT_PRELOAD_ONELEVEL,
+                              NULL);
+         
+        gconf_client_notify_add (prefs_model->gconf_client,
+                                 BASE_KEY,
+                                 (GConfClientNotifyFunc)notify_cb, prefs_model,
+                                 NULL, NULL);
+
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+static void
+gl_prefs_model_finalize (GObject *object)
+{
+       gl_debug (DEBUG_PREFS, "START");
+
+       g_return_if_fail (object && GL_IS_PREFS_MODEL (object));
+
+       g_object_unref (G_OBJECT(GL_PREFS_MODEL(object)->gconf_client));
+
+       g_free (GL_PREFS_MODEL(object)->default_page_size);
+       g_free (GL_PREFS_MODEL(object)->default_font_family);
+
+       G_OBJECT_CLASS (parent_class)->finalize (object);
+
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+/*****************************************************************************/
+/* New prefs_model object.                                                   */
+/*****************************************************************************/
+glPrefsModel *
+gl_prefs_model_new (void)
+{
+       glPrefsModel *prefs_model;
+
+       gl_debug (DEBUG_PREFS, "START");
+
+       prefs_model = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL));
+
+       gl_debug (DEBUG_PREFS, "END");
+
+       return prefs_model;
+}
+
+
+
+/*****************************************************************************/
+/* Save all settings.                                                        */
+/*****************************************************************************/
+void 
+gl_prefs_model_save_settings (glPrefsModel *prefs_model)
+{
+       gl_debug (DEBUG_PREFS, "START");
+       
+       g_return_if_fail (prefs_model && GL_IS_PREFS_MODEL(prefs_model));
+       g_return_if_fail (prefs_model->gconf_client != NULL);
+
+       /* We are saving settings because presumably some of them have been changed. */
+       g_signal_emit (G_OBJECT(prefs_model), signals[CHANGED], 0);
+
+       /* Units */
+       gconf_client_set_string (prefs_model->gconf_client,
+                                BASE_KEY PREF_UNITS,
+                                units_to_string(prefs_model->units),
+                                NULL);
+
+       /* Default page size */
+       gconf_client_set_string (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_PAGE_SIZE,
+                                prefs_model->default_page_size,
+                                NULL);
+
+
+       /* Text properties */
+       gconf_client_set_string (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FONT_FAMILY,
+                                prefs_model->default_font_family,
+                                NULL);
+
+       gconf_client_set_float  (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FONT_SIZE,
+                                prefs_model->default_font_size,
+                                NULL);
+
+       gconf_client_set_string (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
+                                gl_util_weight_to_string(prefs_model->default_font_weight),
+                                NULL);
+
+       gconf_client_set_int    (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_TEXT_COLOR,
+                                prefs_model->default_text_color,
+                                NULL);
+
+       gconf_client_set_string (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
+                                gl_util_just_to_string(prefs_model->default_text_alignment),
+                                NULL);
+
+
+       /* Line properties */
+       gconf_client_set_float  (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_LINE_WIDTH,
+                                prefs_model->default_line_width,
+                                NULL);
+
+       gconf_client_set_int    (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_LINE_COLOR,
+                                prefs_model->default_line_color,
+                                NULL);
+
+
+       /* Fill properties */
+       gconf_client_set_int    (prefs_model->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FILL_COLOR,
+                                prefs_model->default_fill_color,
+                                NULL);
+
+
+       /* Main Toolbar */
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
+                              prefs_model->main_toolbar_visible,
+                              NULL);
+
+       gconf_client_set_int (prefs_model->gconf_client,
+                             BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
+                             prefs_model->main_toolbar_buttons_style,
+                             NULL);
+
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS,
+                              prefs_model->main_toolbar_view_tooltips,
+                              NULL);
+
+       /* Drawing Toolbar */
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
+                              prefs_model->drawing_toolbar_visible,
+                              NULL);
+
+       gconf_client_set_int (prefs_model->gconf_client,
+                             BASE_KEY PREF_DRAWING_TOOLBAR_BUTTONS_STYLE,
+                             prefs_model->drawing_toolbar_buttons_style,
+                             NULL);
+
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS,
+                              prefs_model->drawing_toolbar_view_tooltips,
+                              NULL);
+
+       /* View properties */
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_GRID_VISIBLE,
+                              prefs_model->grid_visible,
+                              NULL);
+
+       gconf_client_set_bool (prefs_model->gconf_client,
+                              BASE_KEY PREF_MARKUP_VISIBLE,
+                              prefs_model->markup_visible,
+                              NULL);
+
+       /* Recent files */
+       gconf_client_set_int (prefs_model->gconf_client,
+                             BASE_KEY PREF_MAX_RECENTS,
+                             prefs_model->max_recents,
+                             NULL);
+
+
+       gconf_client_suggest_sync (prefs_model->gconf_client, NULL);
+       
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+/*****************************************************************************/
+/* Load all settings.                                                        */
+/*****************************************************************************/
+void
+gl_prefs_model_load_settings (glPrefsModel *prefs_model)
+{
+       gchar   *string;
+       glPaper *paper;
+
+       gl_debug (DEBUG_PREFS, "START");
+       
+       g_return_if_fail (prefs_model && GL_IS_PREFS_MODEL(prefs_model));
+       g_return_if_fail (prefs_model->gconf_client != NULL);
+
+       /* Units */
+       string =
+               get_string (prefs_model->gconf_client,
+                           BASE_KEY PREF_UNITS,
+                           DEFAULT_UNITS_STRING);
+       prefs_model->units = string_to_units( string );
+       g_free( string );
+
+
+       /* Page size */
+       prefs_model->default_page_size =
+               get_string (prefs_model->gconf_client,
+                           BASE_KEY PREF_DEFAULT_PAGE_SIZE,
+                           DEFAULT_PAGE_SIZE);
+
+       /* Text properties */
+       prefs_model->default_font_family =
+               get_string (prefs_model->gconf_client,
+                           BASE_KEY PREF_DEFAULT_FONT_FAMILY,
+                           DEFAULT_FONT_FAMILY);
+
+       prefs_model->default_font_size =
+               get_float (prefs_model->gconf_client,
+                          BASE_KEY PREF_DEFAULT_FONT_SIZE,
+                          DEFAULT_FONT_SIZE);
+
+       string =
+               get_string (prefs_model->gconf_client,
+                           BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
+                           DEFAULT_FONT_WEIGHT_STRING);
+       prefs_model->default_font_weight = gl_util_string_to_weight( string );
+       g_free( string );
+
+       prefs_model->default_text_color =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_DEFAULT_TEXT_COLOR,
+                        DEFAULT_TEXT_COLOR);
+
+       string =
+               get_string (prefs_model->gconf_client,
+                           BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
+                           DEFAULT_TEXT_JUST_STRING);
+       prefs_model->default_text_alignment = gl_util_string_to_just( string );
+       g_free( string );
+
+
+       /* Line properties */
+       prefs_model->default_line_width =
+               get_float (prefs_model->gconf_client,
+                          BASE_KEY PREF_DEFAULT_LINE_WIDTH,
+                          DEFAULT_LINE_WIDTH);
+       prefs_model->default_line_color =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_DEFAULT_LINE_COLOR,
+                        DEFAULT_LINE_COLOR);
+
+       /* Fill properties */
+       prefs_model->default_fill_color =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_DEFAULT_FILL_COLOR,
+                        DEFAULT_FILL_COLOR);
+
+
+       /* User Inferface/Main Toolbar */
+       prefs_model->main_toolbar_visible =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
+                         TRUE);
+
+       prefs_model->main_toolbar_buttons_style =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
+                        GL_TOOLBAR_SYSTEM);
+
+       prefs_model->main_toolbar_view_tooltips =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS,
+                         TRUE);
+
+       /* User Inferface/Drawing Toolbar */
+       prefs_model->drawing_toolbar_visible =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
+                         TRUE);
+
+       prefs_model->drawing_toolbar_buttons_style =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_DRAWING_TOOLBAR_BUTTONS_STYLE,
+                        GL_TOOLBAR_SYSTEM);
+
+       prefs_model->drawing_toolbar_view_tooltips =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS,
+                         TRUE);
+
+
+       /* View properties */
+       prefs_model->grid_visible =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_GRID_VISIBLE,
+                         TRUE);
+
+       prefs_model->markup_visible =
+               get_bool (prefs_model->gconf_client,
+                         BASE_KEY PREF_MARKUP_VISIBLE,
+                         TRUE);
+
+       /* Recent files */
+       prefs_model->max_recents =
+               get_int (prefs_model->gconf_client,
+                        BASE_KEY PREF_MAX_RECENTS,
+                        4);
+
+
+       /* Proof read the default page size -- it must be a valid id. */
+       /* (For compatability with older versions.) */
+       /* Note: paper module must be initialized for this to work. */
+       paper = gl_paper_from_id (prefs_model->default_page_size);
+       if ( paper == NULL ) {
+               prefs_model->default_page_size = g_strdup (DEFAULT_PAGE_SIZE);
+       } else {
+               gl_paper_free (&paper);
+       }
+
+       gl_debug (DEBUG_PREFS, "max_recents = %d", prefs_model->max_recents);
+
+
+       g_signal_emit (G_OBJECT(prefs_model), signals[CHANGED], 0);
+
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Key changed callback.                                           */
+/*---------------------------------------------------------------------------*/
+static void 
+notify_cb (GConfClient  *client,
+          guint         cnxn_id,
+          GConfEntry   *entry,
+          glPrefsModel *prefs_model)
+{
+       gl_debug (DEBUG_PREFS, "Key was changed: %s", entry->key);
+
+       gl_prefs_model_load_settings (prefs_model);
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Utilities to get values with defaults.                          */
+/*---------------------------------------------------------------------------*/
+static gchar*
+get_string (GConfClient *client,
+           const gchar *key,
+           const gchar *def)
+{
+       gchar* val;
+
+       val = gconf_client_get_string (client, key, NULL);
+
+       if (val != NULL) {
+
+               return val;
+
+       } else {
+
+               return def ? g_strdup (def) : NULL;
+
+       }
+}
+
+static gboolean
+get_bool (GConfClient *client,
+         const gchar *key,
+         gboolean     def)
+{
+       GConfValue* val;
+       gboolean retval;
+
+       val = gconf_client_get (client, key, NULL);
+
+       if (val != NULL) {
+
+               if ( val->type == GCONF_VALUE_BOOL ) {
+                       retval = gconf_value_get_bool (val);
+               } else {
+                       retval = def;
+               }
+
+               gconf_value_free (val);
+
+               return retval;
+
+       } else {
+
+               return def;
+
+       }
+}
+
+static gint
+get_int (GConfClient *client,
+        const gchar *key,
+        gint         def)
+{
+       GConfValue* val;
+       gint retval;
+
+       val = gconf_client_get (client, key, NULL);
+
+       if (val != NULL) {
+
+               if ( val->type == GCONF_VALUE_INT) {
+                       retval = gconf_value_get_int(val);
+               } else {
+                       retval = def;
+               }
+
+               gconf_value_free (val);
+
+               return retval;
+
+       } else {
+
+               return def;
+
+       }
+}
+
+static gdouble
+get_float (GConfClient *client,
+          const gchar *key,
+          gdouble      def)
+{
+       GConfValue* val;
+       gdouble retval;
+
+       val = gconf_client_get (client, key, NULL);
+
+       if (val != NULL) {
+
+               if ( val->type == GCONF_VALUE_FLOAT ) {
+                       retval = gconf_value_get_float(val);
+               } else {
+                       retval = def;
+               }
+
+               gconf_value_free (val);
+
+               return retval;
+
+       } else {
+
+               return def;
+
+       }
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE.  Utilities to deal with units.                                   */
+/*---------------------------------------------------------------------------*/
+static glPrefsUnits
+string_to_units (const gchar *string)
+{
+       glPrefsUnits units;
+
+       if (g_strcasecmp (string, "Points") == 0) {
+               units = GL_UNITS_PTS;
+       } else if (g_strcasecmp (string, "Inches") == 0) {
+               units = GL_UNITS_INCHES;
+       } else if (g_strcasecmp (string, "Millimeters") == 0) {
+               units = GL_UNITS_MM;
+       } else {
+               units = GL_UNITS_INCHES;
+       }
+
+       return units;
+}
+
+static const
+gchar *units_to_string (glPrefsUnits units)
+{
+       switch (units) {
+       case GL_UNITS_PTS:
+               return "Points";
+               break;
+       case GL_UNITS_INCHES:
+               return "Inches";
+               break;
+       case GL_UNITS_MM:
+               return "Millimeters";
+               break;
+       default:
+               return "Inches";
+               break;
+       }
+}
+
+
diff --git a/glabels2/src/prefs-model.h b/glabels2/src/prefs-model.h
new file mode 100644 (file)
index 0000000..b8f3d9a
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ *  (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ *  prefs-model.h:  Application preferences model module header file
+ *
+ *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+#ifndef __PREFS_MODEL_H__
+#define __PREFS_MODEL_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <gconf/gconf-client.h>
+#include <libgnomeprint/gnome-font.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+       GL_TOOLBAR_SYSTEM = 0,
+       GL_TOOLBAR_ICONS,
+       GL_TOOLBAR_ICONS_AND_TEXT
+} glToolbarSetting;
+
+typedef enum {
+       GL_UNITS_PTS,
+       GL_UNITS_INCHES,
+       GL_UNITS_MM,
+} glPrefsUnits;
+
+#define GL_TYPE_PREFS_MODEL              (gl_prefs_model_get_type ())
+#define GL_PREFS_MODEL(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_PREFS_MODEL, glPrefsModel))
+#define GL_PREFS_MODEL_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_PREFS_MODEL, glPrefsModelClass))
+#define GL_IS_PREFS_MODEL(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_PREFS_MODEL))
+#define GL_IS_PREFS_MODEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_PREFS_MODEL))
+#define GL_PREFS_MODEL_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), GL_TYPE_PREFS_MODEL, glPrefsModelClass))
+
+
+typedef struct _glPrefsModel          glPrefsModel;
+typedef struct _glPrefsModelClass     glPrefsModelClass;
+
+typedef struct _glPrefsModelPrivate   glPrefsModelPrivate;
+
+
+struct _glPrefsModel {
+       GObject          *object;
+
+       GConfClient      *gconf_client;
+
+       /* Units */
+       glPrefsUnits      units;
+
+       /* Page size */
+       gchar            *default_page_size;
+
+       /* Text properties */
+       gchar            *default_font_family;
+       gdouble           default_font_size;
+       GnomeFontWeight   default_font_weight;
+       gboolean          default_font_italic_flag;
+       guint             default_text_color;
+       GtkJustification  default_text_alignment;
+       
+       /* Line properties */
+       gdouble           default_line_width;
+       guint             default_line_color;
+       
+       /* Fill properties */
+       guint             default_fill_color;
+
+       /* User Interface/Main Toolbar */
+       gboolean          main_toolbar_visible;
+       glToolbarSetting  main_toolbar_buttons_style; 
+       gboolean          main_toolbar_view_tooltips;
+
+       /* User Interface/Drawing Toolbar */
+       gboolean          drawing_toolbar_visible;
+       glToolbarSetting  drawing_toolbar_buttons_style; 
+       gboolean          drawing_toolbar_view_tooltips;
+
+       /* View properties */
+       gboolean          grid_visible;
+       gboolean          markup_visible;
+
+       /* Recent files */
+       gint              max_recents;
+};
+
+struct _glPrefsModelClass {
+       GObjectClass     parent_class;
+
+        void (*changed)          (glPrefsModel *prefs_model, gpointer user_data);
+};
+
+
+GType         gl_prefs_model_get_type            (void);
+
+glPrefsModel *gl_prefs_model_new                 (void);
+
+void          gl_prefs_model_save_settings       (glPrefsModel   *prefs_model);
+
+void          gl_prefs_model_load_settings       (glPrefsModel   *prefs_model);
+
+G_END_DECLS
+
+#endif /* __PREFS_MODEL_H__ */
+
index 6b18929de1342bb9e7a7ee6794a901d4fae4602d..d4c6d67678e80ac44a9fee1df3553da3a3c3713c 100644 (file)
@@ -1,9 +1,9 @@
 /*
  *  (GLABELS) Label and Business Card Creation program for GNOME
  *
- *  prefs.h:  Application preferences module header file
+ *  prefs.c:  Application preferences module
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
+ *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
+#include <config.h>
 
-#include <libgnome/libgnome.h>
-#include <libgnomeui/libgnomeui.h>
+#include <gnome.h>
 
-#include <gconf/gconf-client.h>
-
-#include "prefs.h"
-#include "util.h"
-#include "paper.h"
+#include "prefs-model.h"
 
 #include "debug.h"
 
-glPreferences      *gl_prefs     = NULL;
+glPrefsModel      *gl_prefs     = NULL;
 
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
 
-/* GConf keys */
-#define BASE_KEY                            "/apps/glabels"
-
-#define PREF_UNITS                          "/units"
-#define PREF_DEFAULT_PAGE_SIZE              "/default-page-size"
-
-#define PREF_DEFAULT_FONT_FAMILY            "/default-font-family"
-#define PREF_DEFAULT_FONT_SIZE              "/default-font-size"
-#define PREF_DEFAULT_FONT_WEIGHT            "/default-font-weight"
-#define PREF_DEFAULT_FONT_ITALIC_FLAG       "/default-font-italic-flag"
-#define PREF_DEFAULT_TEXT_COLOR             "/default-text-color"
-#define PREF_DEFAULT_TEXT_ALIGNMENT         "/default-text-alignment"
-
-#define PREF_DEFAULT_LINE_WIDTH             "/default-line-width"
-#define PREF_DEFAULT_LINE_COLOR             "/default-line-color"
-
-#define PREF_DEFAULT_FILL_COLOR             "/default-fill-color"
-
-#define PREF_MAIN_TOOLBAR_VISIBLE           "/main-toolbar-visible"
-#define PREF_MAIN_TOOLBAR_BUTTONS_STYLE     "/main-toolbar-buttons-style"
-#define PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS     "/main-toolbar-view-tooltips"
-
-#define PREF_DRAWING_TOOLBAR_VISIBLE        "/drawing-toolbar-visible"
-#define PREF_DRAWING_TOOLBAR_BUTTONS_STYLE  "/drawing-toolbar-buttons-style"
-#define PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS  "/drawing-toolbar-view-tooltips"
-
-#define PREF_GRID_VISIBLE                   "/grid-visible"
-#define PREF_MARKUP_VISIBLE                 "/markup-visible"
-
-#define PREF_MAX_RECENTS                    "/max-recents"
-
-/* Default values */
-#define DEFAULT_UNITS_STRING       units_to_string (GL_PREFS_UNITS_INCHES)
-#define DEFAULT_PAGE_SIZE          "US-Letter"
-
-#define DEFAULT_FONT_FAMILY        "Sans"
-#define DEFAULT_FONT_SIZE          14.0
-#define DEFAULT_FONT_WEIGHT_STRING gl_util_weight_to_string (GNOME_FONT_BOOK)
-#define DEFAULT_FONT_ITALIC_FLAG   FALSE
-#define DEFAULT_TEXT_JUST_STRING   gl_util_just_to_string (GTK_JUSTIFY_LEFT)
-#define DEFAULT_TEXT_COLOR         GNOME_CANVAS_COLOR (0,0,0)
-
-#define DEFAULT_LINE_WIDTH         1.0
-#define DEFAULT_LINE_COLOR         GNOME_CANVAS_COLOR_A (0, 0, 0, 255)
-
-#define DEFAULT_FILL_COLOR         GNOME_CANVAS_COLOR_A (0, 255, 0, 255)
 
 /*========================================================*/
 /* Private types.                                         */
@@ -92,25 +42,12 @@ glPreferences      *gl_prefs     = NULL;
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
-static GConfClient *gconf_client = NULL;
+
 
 /*========================================================*/
 /* Private function prototypes.                           */
 /*========================================================*/
 
-static void notify_cb (GConfClient *client,
-                      guint cnxn_id,
-                      GConfEntry *entry,
-                      gpointer user_data);
-
-static gchar *get_string (GConfClient* client, const gchar* key, const gchar* def);
-static gboolean get_bool (GConfClient* client, const gchar* key, gboolean def);
-static gint get_int (GConfClient* client, const gchar* key, gint def);
-static gdouble get_float (GConfClient* client, const gchar* key, gdouble def);
-
-static glPrefsUnits string_to_units (const gchar *string);
-static const gchar *units_to_string (glPrefsUnits units);
-
 
 \f
 /*****************************************************************************/
@@ -118,461 +55,16 @@ static const gchar *units_to_string (glPrefsUnits units);
 /*****************************************************************************/
 void 
 gl_prefs_init (void)
-{
-       gl_debug (DEBUG_PREFS, "");
-
-       gconf_client = gconf_client_get_default ();
-       
-       g_return_if_fail (gconf_client != NULL);
-
-       gconf_client_add_dir (gconf_client,
-                             BASE_KEY,
-                             GCONF_CLIENT_PRELOAD_ONELEVEL,
-                             NULL);
-       
-       gconf_client_notify_add (gconf_client,
-                                BASE_KEY,
-                                notify_cb,
-                                NULL, NULL, NULL);
-}
-
-
-/*****************************************************************************/
-/* Save all settings.                                                        */
-/*****************************************************************************/
-void 
-gl_prefs_save_settings (void)
 {
        gl_debug (DEBUG_PREFS, "START");
-       
-       g_return_if_fail (gconf_client != NULL);
-       g_return_if_fail (gl_prefs != NULL);
-
-       /* Units */
-       gconf_client_set_string (gconf_client,
-                                BASE_KEY PREF_UNITS,
-                                units_to_string(gl_prefs->units),
-                                NULL);
-
-       /* Default page size */
-       gconf_client_set_string (gconf_client,
-                                BASE_KEY PREF_DEFAULT_PAGE_SIZE,
-                                gl_prefs->default_page_size,
-                                NULL);
-
-
-       /* Text properties */
-       gconf_client_set_string (gconf_client,
-                                BASE_KEY PREF_DEFAULT_FONT_FAMILY,
-                                gl_prefs->default_font_family,
-                                NULL);
-
-       gconf_client_set_float  (gconf_client,
-                                BASE_KEY PREF_DEFAULT_FONT_SIZE,
-                                gl_prefs->default_font_size,
-                                NULL);
-
-       gconf_client_set_string (gconf_client,
-                                BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
-                                gl_util_weight_to_string(gl_prefs->default_font_weight),
-                                NULL);
-
-       gconf_client_set_int    (gconf_client,
-                                BASE_KEY PREF_DEFAULT_TEXT_COLOR,
-                                gl_prefs->default_text_color,
-                                NULL);
-
-       gconf_client_set_string (gconf_client,
-                                BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
-                                gl_util_just_to_string(gl_prefs->default_text_alignment),
-                                NULL);
-
-
-       /* Line properties */
-       gconf_client_set_float  (gconf_client,
-                                BASE_KEY PREF_DEFAULT_LINE_WIDTH,
-                                gl_prefs->default_line_width,
-                                NULL);
 
-       gconf_client_set_int    (gconf_client,
-                                BASE_KEY PREF_DEFAULT_LINE_COLOR,
-                                gl_prefs->default_line_color,
-                                NULL);
+       gl_prefs = gl_prefs_model_new ();
 
+       gl_prefs_model_load_settings (gl_prefs);
 
-       /* Fill properties */
-       gconf_client_set_int    (gconf_client,
-                                BASE_KEY PREF_DEFAULT_FILL_COLOR,
-                                gl_prefs->default_fill_color,
-                                NULL);
-
-
-       /* Main Toolbar */
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
-                              gl_prefs->main_toolbar_visible,
-                              NULL);
-
-       gconf_client_set_int (gconf_client,
-                             BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
-                             gl_prefs->main_toolbar_buttons_style,
-                             NULL);
-
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS,
-                              gl_prefs->main_toolbar_view_tooltips,
-                              NULL);
-
-       /* Drawing Toolbar */
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
-                              gl_prefs->drawing_toolbar_visible,
-                              NULL);
-
-       gconf_client_set_int (gconf_client,
-                             BASE_KEY PREF_DRAWING_TOOLBAR_BUTTONS_STYLE,
-                             gl_prefs->drawing_toolbar_buttons_style,
-                             NULL);
-
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS,
-                              gl_prefs->drawing_toolbar_view_tooltips,
-                              NULL);
-
-       /* View properties */
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_GRID_VISIBLE,
-                              gl_prefs->grid_visible,
-                              NULL);
-
-       gconf_client_set_bool (gconf_client,
-                              BASE_KEY PREF_MARKUP_VISIBLE,
-                              gl_prefs->markup_visible,
-                              NULL);
-
-       /* Recent files */
-       gconf_client_set_int (gconf_client,
-                             BASE_KEY PREF_MAX_RECENTS,
-                             gl_prefs->max_recents,
-                             NULL);
-
-
-       gconf_client_suggest_sync (gconf_client, NULL);
-       
        gl_debug (DEBUG_PREFS, "END");
 }
 
-/*****************************************************************************/
-/* Load all settings.                                                        */
-/*****************************************************************************/
-void
-gl_prefs_load_settings (void)
-{
-       gchar   *string;
-       glPaper *paper;
-
-       gl_debug (DEBUG_PREFS, "START");
-       
-       if (gl_prefs == NULL)
-               gl_prefs = g_new0 (glPreferences, 1);
-
-       if (gconf_client == NULL)
-       {
-               /* TODO: in any case set default values */
-               g_warning ("Cannot load settings.");
-               return;
-       }
-
-
-       /* Units */
-       string =
-               get_string (gconf_client,
-                           BASE_KEY PREF_UNITS,
-                           DEFAULT_UNITS_STRING);
-       gl_prefs->units = string_to_units( string );
-       g_free( string );
-
-
-       /* Page size */
-       gl_prefs->default_page_size =
-               get_string (gconf_client,
-                           BASE_KEY PREF_DEFAULT_PAGE_SIZE,
-                           DEFAULT_PAGE_SIZE);
-
-       /* Text properties */
-       gl_prefs->default_font_family =
-               get_string (gconf_client,
-                           BASE_KEY PREF_DEFAULT_FONT_FAMILY,
-                           DEFAULT_FONT_FAMILY);
-
-       gl_prefs->default_font_size =
-               get_float (gconf_client,
-                          BASE_KEY PREF_DEFAULT_FONT_SIZE,
-                          DEFAULT_FONT_SIZE);
-
-       string =
-               get_string (gconf_client,
-                           BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
-                           DEFAULT_FONT_WEIGHT_STRING);
-       gl_prefs->default_font_weight = gl_util_string_to_weight( string );
-       g_free( string );
-
-       gl_prefs->default_text_color =
-               get_int (gconf_client,
-                        BASE_KEY PREF_DEFAULT_TEXT_COLOR,
-                        DEFAULT_TEXT_COLOR);
-
-       string =
-               get_string (gconf_client,
-                           BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
-                           DEFAULT_TEXT_JUST_STRING);
-       gl_prefs->default_text_alignment = gl_util_string_to_just( string );
-       g_free( string );
-
-
-       /* Line properties */
-       gl_prefs->default_line_width =
-               get_float (gconf_client,
-                          BASE_KEY PREF_DEFAULT_LINE_WIDTH,
-                          DEFAULT_LINE_WIDTH);
-       gl_prefs->default_line_color =
-               get_int (gconf_client,
-                        BASE_KEY PREF_DEFAULT_LINE_COLOR,
-                        DEFAULT_LINE_COLOR);
-
-       /* Fill properties */
-       gl_prefs->default_fill_color =
-               get_int (gconf_client,
-                        BASE_KEY PREF_DEFAULT_FILL_COLOR,
-                        DEFAULT_FILL_COLOR);
-
-
-       /* User Inferface/Main Toolbar */
-       gl_prefs->main_toolbar_visible =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
-                         TRUE);
-
-       gl_prefs->main_toolbar_buttons_style =
-               get_int (gconf_client,
-                        BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
-                        GL_TOOLBAR_SYSTEM);
-
-       gl_prefs->main_toolbar_view_tooltips =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_MAIN_TOOLBAR_VIEW_TOOLTIPS,
-                         TRUE);
-
-       /* User Inferface/Drawing Toolbar */
-       gl_prefs->drawing_toolbar_visible =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
-                         TRUE);
-
-       gl_prefs->drawing_toolbar_buttons_style =
-               get_int (gconf_client,
-                        BASE_KEY PREF_DRAWING_TOOLBAR_BUTTONS_STYLE,
-                        GL_TOOLBAR_SYSTEM);
-
-       gl_prefs->drawing_toolbar_view_tooltips =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS,
-                         TRUE);
-
-
-       /* View properties */
-       gl_prefs->grid_visible =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_GRID_VISIBLE,
-                         TRUE);
-
-       gl_prefs->markup_visible =
-               get_bool (gconf_client,
-                         BASE_KEY PREF_MARKUP_VISIBLE,
-                         TRUE);
-
-       /* Recent files */
-       gl_prefs->max_recents =
-               get_int (gconf_client,
-                        BASE_KEY PREF_MAX_RECENTS,
-                        4);
-
-
-       /* Proof read the default page size -- it must be a valid id. */
-       /* (For compatability with older versions.) */
-       paper = gl_paper_from_id (gl_prefs->default_page_size);
-       if ( paper == NULL ) {
-               gl_prefs->default_page_size = g_strdup (DEFAULT_PAGE_SIZE);
-       } else {
-               gl_paper_free (&paper);
-       }
-
-       gl_debug (DEBUG_PREFS, "max_recents = %d", gl_prefs->max_recents);
-
-       gl_debug (DEBUG_PREFS, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  Key changed callback.                                           */
-/*---------------------------------------------------------------------------*/
-static void 
-notify_cb (GConfClient *client,
-          guint cnxn_id,
-          GConfEntry *entry,
-          gpointer user_data)
-{
-       gl_debug (DEBUG_PREFS, "Key was changed: %s", entry->key);
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  Utilities to get values with defaults.                          */
-/*---------------------------------------------------------------------------*/
-static gchar*
-get_string (GConfClient* client,
-           const gchar* key,
-           const gchar* def)
-{
-  gchar* val;
-
-  val = gconf_client_get_string (client, key, NULL);
-
-  if (val != NULL) {
-
-      return val;
-
-  } else {
-
-      return def ? g_strdup (def) : NULL;
-
-  }
-}
-
-static gboolean
-get_bool (GConfClient* client,
-         const gchar* key,
-         gboolean def)
-{
-  GConfValue* val;
-  gboolean retval;
-
-  val = gconf_client_get (client, key, NULL);
-
-  if (val != NULL) {
-
-         if ( val->type == GCONF_VALUE_BOOL ) {
-                 retval = gconf_value_get_bool (val);
-         } else {
-                 retval = def;
-         }
-
-         gconf_value_free (val);
-
-         return retval;
-
-  } else {
-
-      return def;
-
-  }
-}
-
-static gint
-get_int (GConfClient* client,
-        const gchar* key,
-        gint def)
-{
-  GConfValue* val;
-  gint retval;
-
-  val = gconf_client_get (client, key, NULL);
-
-  if (val != NULL) {
-
-         if ( val->type == GCONF_VALUE_INT) {
-                 retval = gconf_value_get_int(val);
-         } else {
-                 retval = def;
-         }
-
-         gconf_value_free (val);
-
-         return retval;
-
-  } else {
-
-         return def;
-
-  }
-}
-
-static gdouble
-get_float (GConfClient* client,
-          const gchar* key,
-          gdouble def)
-{
-  GConfValue* val;
-  gdouble retval;
-
-  val = gconf_client_get (client, key, NULL);
-
-  if (val != NULL) {
-
-         if ( val->type == GCONF_VALUE_FLOAT ) {
-                 retval = gconf_value_get_float(val);
-         } else {
-                 retval = def;
-         }
-
-         gconf_value_free (val);
-
-         return retval;
-
-  } else {
-
-         return def;
-
-  }
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  Utilities to deal with units.                                   */
-/*---------------------------------------------------------------------------*/
-static glPrefsUnits string_to_units (const gchar *string)
-{
-       glPrefsUnits units;
-
-       if (g_strcasecmp (string, "Points") == 0) {
-               units = GL_PREFS_UNITS_PTS;
-       } else if (g_strcasecmp (string, "Inches") == 0) {
-               units = GL_PREFS_UNITS_INCHES;
-       } else if (g_strcasecmp (string, "Millimeters") == 0) {
-               units = GL_PREFS_UNITS_MM;
-       } else {
-               units = GL_PREFS_UNITS_INCHES;
-       }
-
-       return units;
-}
-
-static const gchar *units_to_string (glPrefsUnits units)
-{
-       switch (units) {
-       case GL_PREFS_UNITS_PTS:
-               return "Points";
-               break;
-       case GL_PREFS_UNITS_INCHES:
-               return "Inches";
-               break;
-       case GL_PREFS_UNITS_MM:
-               return "Millimeters";
-               break;
-       default:
-               return "Inches";
-               break;
-       }
-}
-
-
 \f
 /****************************************************************************/
 /* Get string representing desired units.                                   */
@@ -600,11 +92,11 @@ gl_prefs_get_units_per_point (void)
 {
 
        switch (gl_prefs->units) {
-       case GL_PREFS_UNITS_PTS:
+       case GL_UNITS_PTS:
                return 1.0;     /* points */
-       case GL_PREFS_UNITS_INCHES:
+       case GL_UNITS_INCHES:
                return 1.0 / 72.0;      /* inches */
-       case GL_PREFS_UNITS_MM:
+       case GL_UNITS_MM:
                return 0.35277778;      /* mm */
        default:
                g_warning ("Illegal units");    /* Should not happen */
@@ -620,11 +112,11 @@ gl_prefs_get_units_precision (void)
 {
 
        switch (gl_prefs->units) {
-       case GL_PREFS_UNITS_PTS:
+       case GL_UNITS_PTS:
                return 1;       /* points */
-       case GL_PREFS_UNITS_INCHES:
+       case GL_UNITS_INCHES:
                return 3;       /* inches */
-       case GL_PREFS_UNITS_MM:
+       case GL_UNITS_MM:
                return 1;       /* mm */
        default:
                g_warning ("Illegal units");    /* Should not happen */
@@ -640,11 +132,11 @@ gl_prefs_get_units_step_size (void)
 {
 
        switch (gl_prefs->units) {
-       case GL_PREFS_UNITS_PTS:
+       case GL_UNITS_PTS:
                return 0.1;     /* points */
-       case GL_PREFS_UNITS_INCHES:
+       case GL_UNITS_INCHES:
                return 0.001;   /* inches */
-       case GL_PREFS_UNITS_MM:
+       case GL_UNITS_MM:
                return 0.1;     /* mm */
        default:
                g_warning ("Illegal units");    /* Should not happen */
@@ -660,11 +152,11 @@ gl_prefs_get_units_string (void)
 {
 
        switch (gl_prefs->units) {
-       case GL_PREFS_UNITS_PTS:
+       case GL_UNITS_PTS:
                return _("points");
-       case GL_PREFS_UNITS_INCHES:
+       case GL_UNITS_INCHES:
                return _("inches");
-       case GL_PREFS_UNITS_MM:
+       case GL_UNITS_MM:
                return _("mm");
        default:
                g_warning ("Illegal units");    /* Should not happen */
index 50f7dba3902ea339de017e50dce59598f395940f..f8f43a250793532c8b18c49ffe56ac2f4f483819 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  prefs.h:  Application preferences module header file
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
+ *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #ifndef __PREFS_H__
 #define __PREFS_H__
 
-#include <gtk/gtk.h>
-#include <libgnomeprint/gnome-font.h>
+#include "prefs-model.h"
 
 G_BEGIN_DECLS
 
-typedef struct _glPreferences glPreferences;
-
-typedef enum {
-       GL_TOOLBAR_SYSTEM = 0,
-       GL_TOOLBAR_ICONS,
-       GL_TOOLBAR_ICONS_AND_TEXT
-} glToolbarSetting;
-
-typedef enum {
-       GL_PREFS_UNITS_PTS,
-       GL_PREFS_UNITS_INCHES,
-       GL_PREFS_UNITS_MM,
-} glPrefsUnits;
-
-struct _glPreferences
-{
-       /* Units */
-       glPrefsUnits      units;
-
-       /* Page size */
-       gchar            *default_page_size;
-
-       /* Text properties */
-       gchar            *default_font_family;
-       gdouble           default_font_size;
-       GnomeFontWeight   default_font_weight;
-       gboolean          default_font_italic_flag;
-       guint             default_text_color;
-       GtkJustification  default_text_alignment;
-       
-       /* Line properties */
-       gdouble           default_line_width;
-       guint             default_line_color;
-       
-       /* Fill properties */
-       guint             default_fill_color;
-
-       /* User Interface/Main Toolbar */
-       gboolean          main_toolbar_visible;
-       glToolbarSetting  main_toolbar_buttons_style; 
-       gboolean          main_toolbar_view_tooltips;
-
-       /* User Interface/Drawing Toolbar */
-       gboolean          drawing_toolbar_visible;
-       glToolbarSetting  drawing_toolbar_buttons_style; 
-       gboolean          drawing_toolbar_view_tooltips;
-
-       /* View properties */
-       gboolean          grid_visible;
-       gboolean          markup_visible;
-
-       /* Recent files */
-       gint              max_recents;
-};
-
-glPreferences *gl_prefs;
-
-void          gl_prefs_save_settings       (void);
-
-void          gl_prefs_load_settings       (void);
 
-void          gl_prefs_init                (void);
 
+extern glPrefsModel *gl_prefs;
+
+
+
+void          gl_prefs_init                (void);
 
 const gchar  *gl_prefs_get_page_size       (void);
 
index b26c4ddd137f4f21d1917d6f428476e6c888e323..22e6560569e0bcddd36e961db30a4c497779ab58 100644 (file)
@@ -453,7 +453,7 @@ gl_template_get_label_size_desc (const glTemplate *template)
 
        switch (template->label.style) {
        case GL_TEMPLATE_STYLE_RECT:
-               if ( units == GL_PREFS_UNITS_INCHES ) {
+               if ( units == GL_UNITS_INCHES ) {
                        gchar *xstr, *ystr;
 
                        xstr = gl_util_fraction (template->label.rect.w * units_per_point);
@@ -470,7 +470,7 @@ gl_template_get_label_size_desc (const glTemplate *template)
                }
                break;
        case GL_TEMPLATE_STYLE_ROUND:
-               if ( units == GL_PREFS_UNITS_INCHES ) {
+               if ( units == GL_UNITS_INCHES ) {
                        gchar *dstr;
 
                        dstr = gl_util_fraction (2.0 * template->label.round.r * units_per_point);
@@ -484,7 +484,7 @@ gl_template_get_label_size_desc (const glTemplate *template)
                }
                break;
        case GL_TEMPLATE_STYLE_CD:
-               if ( units == GL_PREFS_UNITS_INCHES ) {
+               if ( units == GL_UNITS_INCHES ) {
                        gchar *dstr;
 
                        dstr = gl_util_fraction (2.0 * template->label.cd.r1 * units_per_point);
index 62ecce867ae4b3d98de3cf375dd160f675cb179b..eb0b60df2b162e1a9e06c3499801f50ac411dd34 100644 (file)
@@ -536,7 +536,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {
                gl_prefs->main_toolbar_visible = s;
                set_app_main_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -545,7 +545,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
                set_app_main_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -554,7 +554,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS;
                set_app_main_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -563,7 +563,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
                set_app_main_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -572,7 +572,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {
                gl_prefs->main_toolbar_view_tooltips = s;
                set_app_main_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -581,7 +581,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {
                gl_prefs->drawing_toolbar_visible = s;
                set_app_drawing_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -590,7 +590,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
                set_app_drawing_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -599,7 +599,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS;
                set_app_drawing_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -608,7 +608,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {               
                gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
                set_app_drawing_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -617,7 +617,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
        {
                gl_prefs->drawing_toolbar_view_tooltips = s;
                set_app_drawing_toolbar_style (ui_component);
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -630,7 +630,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
                } else {
                        gl_view_hide_grid (GL_VIEW(GL_WINDOW(win)->view));
                }
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }
@@ -643,7 +643,7 @@ view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
                } else {
                        gl_view_hide_markup (GL_VIEW(GL_WINDOW(win)->view));
                }
-               gl_prefs_save_settings ();
+               gl_prefs_model_save_settings (gl_prefs);
 
                return;
        }