[glabels] Removed laste vestiges of windowing system or dbus dependencies from glabels-batch.



commit 26943b3fd358bb2ab88701b93304edc8e2bc3c5e
Author: Jim Evins <evins snaught com>
Date:   Thu Mar 3 22:55:49 2016 -0500

    Removed laste vestiges of windowing system or dbus dependencies from glabels-batch.

 src/font-history-model.c     |  109 ++++++++-----
 src/font-history-model.h     |    1 +
 src/font-history.c           |   10 ++
 src/font-history.h           |    1 +
 src/glabels-batch.c          |   10 +-
 src/prefs-model.c            |  367 ++++++++++++++++++++++++++++--------------
 src/prefs.c                  |   15 ++
 src/prefs.h                  |    1 +
 src/template-history-model.c |  115 ++++++++------
 src/template-history-model.h |    1 +
 src/template-history.c       |   10 ++
 src/template-history.h       |    1 +
 12 files changed, 422 insertions(+), 219 deletions(-)
---
diff --git a/src/font-history-model.c b/src/font-history-model.c
index 3ae9a86..65d135b 100644
--- a/src/font-history-model.c
+++ b/src/font-history-model.c
@@ -99,14 +99,6 @@ static void
 gl_font_history_model_init (glFontHistoryModel *this)
 {
         this->priv = g_new0 (glFontHistoryModelPrivate, 1);
-
-        this->priv->history = g_settings_new ("org.gnome.glabels-3.history");
-
-        g_return_if_fail (this->priv->history != NULL);
-
-        g_signal_connect_swapped (G_OBJECT (this->priv->history),
-                                  "changed::recent-fonts",
-                                  G_CALLBACK (history_changed_cb), this);
 }
 
 
@@ -138,6 +130,12 @@ gl_font_history_model_new (guint n)
 
         this = g_object_new (TYPE_GL_FONT_HISTORY_MODEL, NULL);
 
+        this->priv->history = g_settings_new ("org.gnome.glabels-3.history");
+
+        g_signal_connect_swapped (G_OBJECT (this->priv->history),
+                                  "changed::recent-fonts",
+                                  G_CALLBACK (history_changed_cb), this);
+
         this->priv->max_n = n;
 
         return this;
@@ -145,37 +143,56 @@ gl_font_history_model_new (guint n)
 
 
 /*****************************************************************************/
+/** New Null Object Generator.                                               */
+/*****************************************************************************/
+glFontHistoryModel *
+gl_font_history_model_new_null (void)
+{
+        glFontHistoryModel *this;
+
+        this = g_object_new (TYPE_GL_FONT_HISTORY_MODEL, NULL);
+
+        this->priv->max_n = 0;
+
+        return this;
+}
+
+
+/*****************************************************************************/
 /* Add font to history.                                                      */
 /*****************************************************************************/
 void
 gl_font_history_model_add_family (glFontHistoryModel *this,
                                   const gchar        *family)
 {
-        gchar **old;
-        gchar **new;
-        gint    i, j;
+       if ( this->priv->history )
+       {
+               gchar **old;
+               gchar **new;
+               gint    i, j;
 
-        old = g_settings_get_strv (this->priv->history, "recent-fonts");
+               old = g_settings_get_strv (this->priv->history, "recent-fonts");
                                    
-        new = g_new0 (gchar *, this->priv->max_n+1);
-
-        /* Put in first slot. */
-        new[0] = g_strdup (family);
-
-        /* Push everthing else down, pruning any duplicate found. */
-        for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
-        {
-                if ( lgl_str_utf8_casecmp (family, old[i]) != 0 )
-                {
-                        new[j++] = g_strdup (old[i]);
-                }
-        }
-
-        g_settings_set_strv (this->priv->history, "recent-fonts",
-                             (const gchar * const *)new);
-
-        g_strfreev (old);
-        g_strfreev (new);
+               new = g_new0 (gchar *, this->priv->max_n+1);
+
+               /* Put in first slot. */
+               new[0] = g_strdup (family);
+
+               /* Push everthing else down, pruning any duplicate found. */
+               for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
+               {
+                       if ( lgl_str_utf8_casecmp (family, old[i]) != 0 )
+                       {
+                               new[j++] = g_strdup (old[i]);
+                       }
+               }
+
+               g_settings_set_strv (this->priv->history, "recent-fonts",
+                                    (const gchar * const *)new);
+
+               g_strfreev (old);
+               g_strfreev (new);
+       }
 }
 
 
@@ -195,23 +212,27 @@ history_changed_cb                  (glFontHistoryModel  *this)
 GList *
 gl_font_history_model_get_family_list (glFontHistoryModel *this)
 {
-        gchar **strv;
         GList  *list = NULL;
-        gint    i;
-
-        strv = g_settings_get_strv (this->priv->history, "recent-fonts");
 
-        /*
-         * Proof read name list; transfer storage to new list.
-         */
-        for ( i = 0; strv[i]; i++ )
+        if ( this->priv->history )
         {
-                if ( gl_font_util_is_family_installed (strv[i]) )
-                {
-                        list = g_list_append (list, g_strdup (strv[i]));
-                }
+               gchar **strv;
+               gint    i;
+
+               strv = g_settings_get_strv (this->priv->history, "recent-fonts");
+
+               /*
+                * Proof read name list; transfer storage to new list.
+                */
+               for ( i = 0; strv[i]; i++ )
+               {
+                       if ( gl_font_util_is_family_installed (strv[i]) )
+                       {
+                               list = g_list_append (list, g_strdup (strv[i]));
+                       }
+               }
+               g_strfreev (strv);
         }
-        g_strfreev (strv);
 
         return list;
 }
diff --git a/src/font-history-model.h b/src/font-history-model.h
index 690c3c7..4cda312 100644
--- a/src/font-history-model.h
+++ b/src/font-history-model.h
@@ -65,6 +65,7 @@ struct _glFontHistoryModelClass {
 GType                gl_font_history_model_get_type         (void) G_GNUC_CONST;
 
 glFontHistoryModel  *gl_font_history_model_new              (guint               n);
+glFontHistoryModel  *gl_font_history_model_new_null         (void);
 
 void                 gl_font_history_model_add_family       (glFontHistoryModel *this,
                                                              const gchar        *family);
diff --git a/src/font-history.c b/src/font-history.c
index ec076fc..354f7db 100644
--- a/src/font-history.c
+++ b/src/font-history.c
@@ -56,6 +56,16 @@ gl_font_history_init (void)
 }
 
 
+/*****************************************************************************/
+/* Initialize font history with a null model.                                */
+/*****************************************************************************/
+void
+gl_font_history_init_null (void)
+{
+       gl_font_history = gl_font_history_model_new_null ();
+}
+
+
 
 /*
  * Local Variables:       -- emacs
diff --git a/src/font-history.h b/src/font-history.h
index c877c7b..ffbc113 100644
--- a/src/font-history.h
+++ b/src/font-history.h
@@ -32,6 +32,7 @@ glFontHistoryModel *gl_font_history;
 
 
 void            gl_font_history_init (void);
+void            gl_font_history_init_null (void);
 
 
 G_END_DECLS
diff --git a/src/glabels-batch.c b/src/glabels-batch.c
index fb5cc7a..64dbb0c 100644
--- a/src/glabels-batch.c
+++ b/src/glabels-batch.c
@@ -100,8 +100,8 @@ main (int argc, char **argv)
        g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
 
 
-        /* Initialize minimal gnome program */
-        gtk_init_check (&argc, &argv);
+        /* Initialize minimal gtk program */
+        gtk_parse_args (&argc, &argv);
         if (!g_option_context_parse (option_context, &argc, &argv, &error))
        {
                g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
@@ -129,9 +129,9 @@ main (int argc, char **argv)
         gl_debug_init ();
         gl_merge_init ();
         lgl_db_init ();
-       gl_prefs_init ();
-       gl_template_history_init ();
-       gl_font_history_init ();
+        gl_prefs_init_null ();
+       gl_template_history_init_null ();
+       gl_font_history_init_null ();
 
         /* now print the files */
         for (p = file_list; p; p = p->next) {
diff --git a/src/prefs-model.c b/src/prefs-model.c
index b9232a7..b4ff709 100644
--- a/src/prefs-model.c
+++ b/src/prefs-model.c
@@ -118,21 +118,6 @@ gl_prefs_model_init (glPrefsModel *this)
 
         this->priv = g_new0 (glPrefsModelPrivate, 1);
 
-        this->priv->locale  = g_settings_new ("org.gnome.glabels-3.locale");
-        this->priv->objects = g_settings_new ("org.gnome.glabels-3.objects");
-        this->priv->ui      = g_settings_new ("org.gnome.glabels-3.ui");
-
-        g_return_if_fail (this->priv->locale != NULL);
-        g_return_if_fail (this->priv->objects != NULL);
-        g_return_if_fail (this->priv->ui != NULL);
- 
-        g_signal_connect_swapped (G_OBJECT (this->priv->locale), "changed",
-                                  G_CALLBACK (gsettings_changed_cb), this);
-        g_signal_connect_swapped (G_OBJECT (this->priv->objects), "changed",
-                                  G_CALLBACK (gsettings_changed_cb), this);
-        g_signal_connect_swapped (G_OBJECT (this->priv->ui), "changed",
-                                  G_CALLBACK (gsettings_changed_cb), this);
-
         gl_debug (DEBUG_PREFS, "END");
 }
 
@@ -169,6 +154,35 @@ gl_prefs_model_new (void)
 
         this = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL));
 
+        this->priv->locale  = g_settings_new ("org.gnome.glabels-3.locale");
+        this->priv->objects = g_settings_new ("org.gnome.glabels-3.objects");
+        this->priv->ui      = g_settings_new ("org.gnome.glabels-3.ui");
+
+        g_signal_connect_swapped (G_OBJECT (this->priv->locale), "changed",
+                                  G_CALLBACK (gsettings_changed_cb), this);
+        g_signal_connect_swapped (G_OBJECT (this->priv->objects), "changed",
+                                  G_CALLBACK (gsettings_changed_cb), this);
+        g_signal_connect_swapped (G_OBJECT (this->priv->ui), "changed",
+                                  G_CALLBACK (gsettings_changed_cb), this);
+
+        gl_debug (DEBUG_PREFS, "END");
+
+        return this;
+}
+
+
+/*****************************************************************************/
+/* New null prefs_model object.                                              */
+/*****************************************************************************/
+glPrefsModel *
+gl_prefs_model_new_null (void)
+{
+        glPrefsModel *this;
+
+        gl_debug (DEBUG_PREFS, "START");
+
+        this = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL));
+
         gl_debug (DEBUG_PREFS, "END");
 
         return this;
@@ -182,9 +196,12 @@ void
 gl_prefs_model_set_units (glPrefsModel     *this,
                           lglUnits          units)
 {
-        g_settings_set_string (this->priv->locale,
-                               "units",
-                               lgl_units_get_id (units));
+        if ( this->priv->locale )
+        {
+               g_settings_set_string (this->priv->locale,
+                                      "units",
+                                      lgl_units_get_id (units));
+        }
 }
 
 
@@ -194,6 +211,11 @@ gl_prefs_model_set_units (glPrefsModel     *this,
 lglUnits
 gl_prefs_model_get_units (glPrefsModel     *this)
 {
+        if ( !this->priv->locale )
+        {
+               return lgl_units_from_id (DEFAULT_UNITS_STRING_METRIC);
+        }
+
         const gchar  *pgsize;
         gchar        *string;
         lglUnits      units;
@@ -242,9 +264,12 @@ void
 gl_prefs_model_set_default_page_size (glPrefsModel     *this,
                                       const gchar      *page_size)
 {
-        g_settings_set_string (this->priv->locale,
-                               "default-page-size",
-                               page_size);
+        if ( this->priv->locale )
+        {
+               g_settings_set_string (this->priv->locale,
+                                      "default-page-size",
+                                      page_size);
+        }
 }
 
 
@@ -254,6 +279,11 @@ gl_prefs_model_set_default_page_size (glPrefsModel     *this,
 gchar *
 gl_prefs_model_get_default_page_size (glPrefsModel     *this)
 {
+        if ( !this->priv->locale )
+        {
+               return g_strdup (DEFAULT_PAGE_SIZE_METRIC);
+        }
+
         const gchar *pgsize;
         gchar       *page_size;
         lglPaper    *paper;
@@ -295,9 +325,12 @@ void
 gl_prefs_model_set_default_font_family (glPrefsModel     *this,
                                         const gchar      *family)
 {
-        g_settings_set_string (this->priv->objects,
-                               "default-font-family",
-                               family);
+        if ( this->priv->objects )
+        {
+               g_settings_set_string (this->priv->objects,
+                                      "default-font-family",
+                                      family);
+        }
 }
 
 
@@ -307,10 +340,13 @@ gl_prefs_model_set_default_font_family (glPrefsModel     *this,
 gchar *
 gl_prefs_model_get_default_font_family (glPrefsModel     *this)
 {
-        gchar *family;
+        if ( !this->priv->objects )
+        {
+               return g_strdup ("Sans");
+        }
 
-        family = g_settings_get_string (this->priv->objects,
-                                        "default-font-family");
+        gchar *family = g_settings_get_string (this->priv->objects,
+                                               "default-font-family");
 
         return family;
 }
@@ -323,9 +359,12 @@ void
 gl_prefs_model_set_default_font_size (glPrefsModel     *this,
                                       gdouble           size)
 {
-        g_settings_set_double (this->priv->objects,
-                               "default-font-size",
-                               size);
+        if ( this->priv->objects )
+        {
+               g_settings_set_double (this->priv->objects,
+                                      "default-font-size",
+                                      size);
+        }
 }
 
 
@@ -335,10 +374,13 @@ gl_prefs_model_set_default_font_size (glPrefsModel     *this,
 gdouble
 gl_prefs_model_get_default_font_size (glPrefsModel     *this)
 {
-        gdouble size;
+        if ( !this->priv->objects )
+        {
+               return 12;
+        }
 
-        size = g_settings_get_double (this->priv->objects,
-                                      "default-font-size");
+        gdouble size = g_settings_get_double (this->priv->objects,
+                                              "default-font-size");
 
         return size;
 }
@@ -351,9 +393,12 @@ void
 gl_prefs_model_set_default_font_weight (glPrefsModel     *this,
                                         PangoWeight       weight)
 {
-        g_settings_set_string (this->priv->objects,
-                               "default-font-weight",
-                               gl_str_util_weight_to_string(weight));
+        if ( this->priv->objects )
+        {
+               g_settings_set_string (this->priv->objects,
+                                      "default-font-weight",
+                                      gl_str_util_weight_to_string(weight));
+        }
 }
 
 
@@ -363,12 +408,14 @@ gl_prefs_model_set_default_font_weight (glPrefsModel     *this,
 PangoWeight
 gl_prefs_model_get_default_font_weight (glPrefsModel     *this)
 {
-        gchar       *string;
-        PangoWeight  weight;
+        if ( !this->priv->objects )
+        {
+               return PANGO_WEIGHT_NORMAL;
+        }
 
-        string = g_settings_get_string (this->priv->objects,
+        gchar *string = g_settings_get_string (this->priv->objects,
                                         "default-font-weight");
-        weight = gl_str_util_string_to_weight (string);
+        PangoWeight weight = gl_str_util_string_to_weight (string);
         g_free (string);
 
         return weight;
@@ -382,9 +429,12 @@ void
 gl_prefs_model_set_default_font_italic_flag (glPrefsModel     *this,
                                              gboolean          italic_flag)
 {
-        g_settings_set_boolean (this->priv->objects,
-                                "default-font-italic-flag",
-                                italic_flag);
+        if ( this->priv->objects )
+        {
+               g_settings_set_boolean (this->priv->objects,
+                                       "default-font-italic-flag",
+                                       italic_flag);
+        }
 }
 
 
@@ -394,10 +444,13 @@ gl_prefs_model_set_default_font_italic_flag (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_default_font_italic_flag (glPrefsModel     *this)
 {
-        gboolean italic_flag;
+        if ( !this->priv->objects )
+        {
+               return FALSE;
+        }
 
-        italic_flag = g_settings_get_boolean (this->priv->objects,
-                                              "default-font-italic-flag");
+        gboolean italic_flag = g_settings_get_boolean (this->priv->objects,
+                                                       "default-font-italic-flag");
 
         return italic_flag;
 }
@@ -410,9 +463,12 @@ void
 gl_prefs_model_set_default_text_color (glPrefsModel     *this,
                                        guint             color)
 {
-        g_settings_set_value (this->priv->objects,
-                              "default-text-color",
-                              g_variant_new_uint32 (color));
+        if ( this->priv->objects )
+        {
+               g_settings_set_value (this->priv->objects,
+                                     "default-text-color",
+                                     g_variant_new_uint32 (color));
+        }
 }
 
 
@@ -422,11 +478,13 @@ gl_prefs_model_set_default_text_color (glPrefsModel     *this,
 guint
 gl_prefs_model_get_default_text_color (glPrefsModel     *this)
 {
-        GVariant *value;
-        guint     color;
+        if ( !this->priv->objects )
+        {
+               return 0x000000FF;
+        }
 
-        value = g_settings_get_value (this->priv->objects, "default-text-color");
-        color = g_variant_get_uint32 (value);
+        GVariant *value = g_settings_get_value (this->priv->objects, "default-text-color");
+        guint color = g_variant_get_uint32 (value);
         g_variant_unref (value);
 
         return color;
@@ -440,9 +498,12 @@ void
 gl_prefs_model_set_default_text_alignment (glPrefsModel     *this,
                                            PangoAlignment    alignment)
 {
-        g_settings_set_string (this->priv->objects,
-                               "default-text-alignment",
-                               gl_str_util_align_to_string(alignment));
+        if ( this->priv->objects )
+        {
+               g_settings_set_string (this->priv->objects,
+                                      "default-text-alignment",
+                                      gl_str_util_align_to_string(alignment));
+        }
 }
 
 
@@ -452,12 +513,14 @@ gl_prefs_model_set_default_text_alignment (glPrefsModel     *this,
 PangoAlignment
 gl_prefs_model_get_default_text_alignment (glPrefsModel     *this)
 {
-        gchar          *string;
-        PangoAlignment  alignment;
+        if ( !this->priv->objects )
+        {
+               return PANGO_ALIGN_LEFT;
+        }
 
-        string = g_settings_get_string (this->priv->objects,
-                                        "default-text-alignment");
-        alignment = gl_str_util_string_to_align (string);
+        gchar *string = g_settings_get_string (this->priv->objects,
+                                               "default-text-alignment");
+        PangoAlignment alignment = gl_str_util_string_to_align (string);
         g_free (string);
 
         return alignment;
@@ -471,9 +534,12 @@ void
 gl_prefs_model_set_default_text_line_spacing (glPrefsModel     *this,
                                               gdouble           spacing)
 {
-        g_settings_set_double (this->priv->objects,
-                               "default-text-line-spacing",
-                               spacing);
+        if ( this->priv->objects )
+        {
+               g_settings_set_double (this->priv->objects,
+                                      "default-text-line-spacing",
+                                      spacing);
+        }
 }
 
 
@@ -483,10 +549,13 @@ gl_prefs_model_set_default_text_line_spacing (glPrefsModel     *this,
 gdouble
 gl_prefs_model_get_default_text_line_spacing (glPrefsModel     *this)
 {
-        gdouble spacing;
+        if ( !this->priv->objects )
+        {
+               return 1;
+        }
 
-        spacing = g_settings_get_double (this->priv->objects,
-                                         "default-text-line-spacing");
+        gdouble spacing = g_settings_get_double (this->priv->objects,
+                                                 "default-text-line-spacing");
 
         return spacing;
 }
@@ -499,9 +568,12 @@ void
 gl_prefs_model_set_default_line_width (glPrefsModel     *this,
                                        gdouble           width)
 {
-        g_settings_set_double (this->priv->objects,
-                               "default-line-width",
-                               width);
+        if ( this->priv->objects )
+        {
+               g_settings_set_double (this->priv->objects,
+                                      "default-line-width",
+                                      width);
+        }
 }
 
 
@@ -511,10 +583,13 @@ gl_prefs_model_set_default_line_width (glPrefsModel     *this,
 gdouble
 gl_prefs_model_get_default_line_width (glPrefsModel     *this)
 {
-        gdouble width;
+        if ( !this->priv->objects )
+        {
+               return 1;
+        }
 
-        width = g_settings_get_double (this->priv->objects,
-                                       "default-line-width");
+        gdouble width = g_settings_get_double (this->priv->objects,
+                                               "default-line-width");
 
         return width;
 }
@@ -527,9 +602,12 @@ void
 gl_prefs_model_set_default_line_color (glPrefsModel     *this,
                                        guint             color)
 {
-        g_settings_set_value (this->priv->objects,
-                              "default-line-color",
-                              g_variant_new_uint32 (color));
+        if ( this->priv->objects )
+        {
+               g_settings_set_value (this->priv->objects,
+                                     "default-line-color",
+                                     g_variant_new_uint32 (color));
+        }
 }
 
 
@@ -539,11 +617,13 @@ gl_prefs_model_set_default_line_color (glPrefsModel     *this,
 guint
 gl_prefs_model_get_default_line_color (glPrefsModel     *this)
 {
-        GVariant *value;
-        guint     color;
+        if ( !this->priv->objects )
+        {
+               return 0x000000FF;
+        }
 
-        value = g_settings_get_value (this->priv->objects, "default-line-color");
-        color = g_variant_get_uint32 (value);
+        GVariant *value = g_settings_get_value (this->priv->objects, "default-line-color");
+        guint color = g_variant_get_uint32 (value);
         g_variant_unref (value);
 
         return color;
@@ -557,9 +637,12 @@ void
 gl_prefs_model_set_default_fill_color (glPrefsModel     *this,
                                        guint             color)
 {
-        g_settings_set_value (this->priv->objects,
-                              "default-fill-color",
-                              g_variant_new_uint32 (color));
+        if ( this->priv->objects )
+        {
+               g_settings_set_value (this->priv->objects,
+                                     "default-fill-color",
+                                     g_variant_new_uint32 (color));
+        }
 }
 
 
@@ -569,11 +652,13 @@ gl_prefs_model_set_default_fill_color (glPrefsModel     *this,
 guint
 gl_prefs_model_get_default_fill_color (glPrefsModel     *this)
 {
-        GVariant *value;
-        guint     color;
+        if ( !this->priv->objects )
+        {
+               return 0x00FF00FF;
+        }
 
-        value = g_settings_get_value (this->priv->objects, "default-fill-color");
-        color = g_variant_get_uint32 (value);
+        GVariant *value = g_settings_get_value (this->priv->objects, "default-fill-color");
+        guint color = g_variant_get_uint32 (value);
         g_variant_unref (value);
 
         return color;
@@ -587,9 +672,12 @@ void
 gl_prefs_model_set_main_toolbar_visible (glPrefsModel     *this,
                                          gboolean          visible)
 {
-        g_settings_set_boolean (this->priv->ui,
-                                "main-toolbar-visible",
-                                visible);
+        if ( this->priv->ui )
+        {
+               g_settings_set_boolean (this->priv->ui,
+                                       "main-toolbar-visible",
+                                       visible);
+        }
 }
 
 
@@ -599,10 +687,13 @@ gl_prefs_model_set_main_toolbar_visible (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_main_toolbar_visible (glPrefsModel     *this)
 {
-        gboolean visible;
+        if ( !this->priv->ui )
+        {
+               return TRUE;
+        }
 
-        visible = g_settings_get_boolean (this->priv->ui,
-                                          "main-toolbar-visible");
+        gboolean visible = g_settings_get_boolean (this->priv->ui,
+                                                   "main-toolbar-visible");
 
         return visible;
 }
@@ -615,9 +706,12 @@ void
 gl_prefs_model_set_drawing_toolbar_visible (glPrefsModel     *this,
                                             gboolean          visible)
 {
-        g_settings_set_boolean (this->priv->ui,
-                                "drawing-toolbar-visible",
-                                visible);
+        if ( this->priv->ui )
+        {
+               g_settings_set_boolean (this->priv->ui,
+                                       "drawing-toolbar-visible",
+                                       visible);
+        }
 }
 
 
@@ -627,10 +721,13 @@ gl_prefs_model_set_drawing_toolbar_visible (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_drawing_toolbar_visible (glPrefsModel     *this)
 {
-        gboolean visible;
+        if ( !this->priv->ui )
+        {
+               return TRUE;
+        }
 
-        visible = g_settings_get_boolean (this->priv->ui,
-                                          "drawing-toolbar-visible");
+        gboolean visible = g_settings_get_boolean (this->priv->ui,
+                                                   "drawing-toolbar-visible");
 
         return visible;
 }
@@ -643,9 +740,12 @@ void
 gl_prefs_model_set_property_toolbar_visible (glPrefsModel     *this,
                                              gboolean          visible)
 {
-        g_settings_set_boolean (this->priv->ui,
-                                "property-toolbar-visible",
-                                visible);
+        if ( this->priv->ui )
+        {
+               g_settings_set_boolean (this->priv->ui,
+                                       "property-toolbar-visible",
+                                       visible);
+        }
 }
 
 
@@ -655,10 +755,13 @@ gl_prefs_model_set_property_toolbar_visible (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_property_toolbar_visible (glPrefsModel     *this)
 {
-        gboolean visible;
+        if ( !this->priv->ui )
+        {
+               return TRUE;
+        }
 
-        visible = g_settings_get_boolean (this->priv->ui,
-                                          "property-toolbar-visible");
+        gboolean visible = g_settings_get_boolean (this->priv->ui,
+                                                   "property-toolbar-visible");
 
         return visible;
 }
@@ -671,9 +774,12 @@ void
 gl_prefs_model_set_grid_visible (glPrefsModel     *this,
                                  gboolean          visible)
 {
-        g_settings_set_boolean (this->priv->ui,
-                                "grid-visible",
-                                visible);
+        if ( this->priv->ui )
+        {
+               g_settings_set_boolean (this->priv->ui,
+                                       "grid-visible",
+                                       visible);
+        }
 }
 
 
@@ -683,10 +789,13 @@ gl_prefs_model_set_grid_visible (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_grid_visible (glPrefsModel     *this)
 {
-        gboolean visible;
+        if ( !this->priv->ui )
+        {
+               return TRUE;
+        }
 
-        visible = g_settings_get_boolean (this->priv->ui,
-                                          "grid-visible");
+        gboolean visible = g_settings_get_boolean (this->priv->ui,
+                                                   "grid-visible");
 
         return visible;
 }
@@ -699,9 +808,12 @@ void
 gl_prefs_model_set_markup_visible (glPrefsModel     *this,
                                    gboolean          visible)
 {
-        g_settings_set_boolean (this->priv->ui,
-                                "markup-visible",
-                                visible);
+        if ( this->priv->ui )
+        {
+               g_settings_set_boolean (this->priv->ui,
+                                       "markup-visible",
+                                       visible);
+        }
 }
 
 
@@ -711,10 +823,13 @@ gl_prefs_model_set_markup_visible (glPrefsModel     *this,
 gboolean
 gl_prefs_model_get_markup_visible (glPrefsModel     *this)
 {
-        gboolean visible;
+        if ( !this->priv->ui )
+        {
+               return TRUE;
+        }
 
-        visible = g_settings_get_boolean (this->priv->ui,
-                                          "markup-visible");
+        gboolean visible = g_settings_get_boolean (this->priv->ui,
+                                                   "markup-visible");
 
         return visible;
 }
@@ -727,9 +842,12 @@ void
 gl_prefs_model_set_max_recents (glPrefsModel     *this,
                                 gint              max_recents)
 {
-        g_settings_set_int (this->priv->ui,
-                            "max-recents",
-                            max_recents);
+        if ( this->priv->ui )
+        {
+               g_settings_set_int (this->priv->ui,
+                                   "max-recents",
+                                   max_recents);
+        }
 }
 
 
@@ -739,10 +857,13 @@ gl_prefs_model_set_max_recents (glPrefsModel     *this,
 gint
 gl_prefs_model_get_max_recents (glPrefsModel     *this)
 {
-        gint max_recents;
+        if ( !this->priv->ui )
+        {
+               return 10;
+        }
 
-        max_recents = g_settings_get_int (this->priv->ui,
-                                          "max-recents");
+        gint max_recents = g_settings_get_int (this->priv->ui,
+                                               "max-recents");
 
         return max_recents;
 }
diff --git a/src/prefs.c b/src/prefs.c
index dc58f7d..3e8aa50 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -64,6 +64,21 @@ gl_prefs_init (void)
 
 
 
+/*****************************************************************************/
+/* Initialize preferences module with null model.                            */
+/*****************************************************************************/
+void 
+gl_prefs_init_null (void)
+{
+       gl_debug (DEBUG_PREFS, "START");
+
+       gl_prefs = gl_prefs_model_new_null ();
+
+       gl_debug (DEBUG_PREFS, "END");
+}
+
+
+
 /*
  * Local Variables:       -- emacs
  * mode: C                -- emacs
diff --git a/src/prefs.h b/src/prefs.h
index 7cabea1..96277e2 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -30,6 +30,7 @@ extern glPrefsModel *gl_prefs;
 
 
 void          gl_prefs_init                (void);
+void          gl_prefs_init_null           (void);
 
 
 G_END_DECLS
diff --git a/src/template-history-model.c b/src/template-history-model.c
index 9105a8f..e146a44 100644
--- a/src/template-history-model.c
+++ b/src/template-history-model.c
@@ -98,14 +98,6 @@ static void
 gl_template_history_model_init (glTemplateHistoryModel *this)
 {
         this->priv = g_new0 (glTemplateHistoryModelPrivate, 1);
-
-        this->priv->history = g_settings_new ("org.gnome.glabels-3.history");
-
-        g_return_if_fail (this->priv->history != NULL);
-
-        g_signal_connect_swapped (G_OBJECT (this->priv->history),
-                                  "changed::recent-templates",
-                                  G_CALLBACK (history_changed_cb), this);
 }
 
 
@@ -137,6 +129,12 @@ gl_template_history_model_new (guint n)
 
         this = g_object_new (TYPE_GL_TEMPLATE_HISTORY_MODEL, NULL);
 
+        this->priv->history = g_settings_new ("org.gnome.glabels-3.history");
+
+        g_signal_connect_swapped (G_OBJECT (this->priv->history),
+                                  "changed::recent-templates",
+                                  G_CALLBACK (history_changed_cb), this);
+
         this->priv->max_n = n;
 
         return this;
@@ -144,37 +142,56 @@ gl_template_history_model_new (guint n)
 
 
 /*****************************************************************************/
+/** New null Object Generator.                                               */
+/*****************************************************************************/
+glTemplateHistoryModel *
+gl_template_history_model_new_null (void)
+{
+        glTemplateHistoryModel *this;
+
+        this = g_object_new (TYPE_GL_TEMPLATE_HISTORY_MODEL, NULL);
+
+        this->priv->max_n = 0;
+
+        return this;
+}
+
+
+/*****************************************************************************/
 /* Add template to history.                                                  */
 /*****************************************************************************/
 void
 gl_template_history_model_add_name (glTemplateHistoryModel *this,
                                     const gchar            *name)
 {
-        gchar **old;
-        gchar **new;
-        gint    i, j;
+       if ( this->priv->history )
+       {
+               gchar **old;
+               gchar **new;
+               gint    i, j;
 
-        old = g_settings_get_strv (this->priv->history, "recent-templates");
+               old = g_settings_get_strv (this->priv->history, "recent-templates");
                                    
-        new = g_new0 (gchar *, this->priv->max_n+1);
-
-        /* Put in first slot. */
-        new[0] = g_strdup (name);
-
-        /* Push everthing else down, pruning any duplicate found. */
-        for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
-        {
-                if ( lgl_str_utf8_casecmp (name, old[i]) != 0 )
-                {
-                        new[j++] = g_strdup (old[i]);
-                }
-        }
-
-        g_settings_set_strv (this->priv->history, "recent-templates",
-                             (const gchar * const *)new);
-
-        g_strfreev (old);
-        g_strfreev (new);
+               new = g_new0 (gchar *, this->priv->max_n+1);
+
+               /* Put in first slot. */
+               new[0] = g_strdup (name);
+
+               /* Push everthing else down, pruning any duplicate found. */
+               for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
+               {
+                       if ( lgl_str_utf8_casecmp (name, old[i]) != 0 )
+                       {
+                               new[j++] = g_strdup (old[i]);
+                       }
+               }
+
+               g_settings_set_strv (this->priv->history, "recent-templates",
+                                    (const gchar * const *)new);
+
+               g_strfreev (old);
+               g_strfreev (new);
+       }
 }
 
 
@@ -194,24 +211,28 @@ history_changed_cb (glTemplateHistoryModel  *this)
 GList *
 gl_template_history_model_get_name_list (glTemplateHistoryModel *this)
 {
-        gchar **strv;
         GList  *list = NULL;
-        gint    i;
-
-        strv = g_settings_get_strv (this->priv->history, "recent-templates");
-
-        /*
-         * Proof read name list; transfer storage to new list.
-         */
-        for ( i = 0; strv[i]; i++ )
-        {
-                if ( lgl_db_does_template_name_exist (strv[i]) )
-                {
-                        list = g_list_append (list, g_strdup (strv[i]));
-                }
-        }
-        g_strfreev (strv);
 
+        if ( this->priv->history )
+       {
+               gchar **strv;
+               gint    i;
+
+               strv = g_settings_get_strv (this->priv->history, "recent-templates");
+
+               /*
+                * Proof read name list; transfer storage to new list.
+                */
+               for ( i = 0; strv[i]; i++ )
+               {
+                       if ( lgl_db_does_template_name_exist (strv[i]) )
+                       {
+                               list = g_list_append (list, g_strdup (strv[i]));
+                       }
+               }
+               g_strfreev (strv);
+       }
+        
         return list;
 }
 
diff --git a/src/template-history-model.h b/src/template-history-model.h
index 1de9866..6db51f4 100644
--- a/src/template-history-model.h
+++ b/src/template-history-model.h
@@ -65,6 +65,7 @@ struct _glTemplateHistoryModelClass {
 GType                   gl_template_history_model_get_type       (void) G_GNUC_CONST;
 
 glTemplateHistoryModel *gl_template_history_model_new            (guint                   n);
+glTemplateHistoryModel *gl_template_history_model_new_null       (void);
 
 void                    gl_template_history_model_add_name       (glTemplateHistoryModel *this,
                                                                   const gchar            *name);
diff --git a/src/template-history.c b/src/template-history.c
index 166567c..db66fae 100644
--- a/src/template-history.c
+++ b/src/template-history.c
@@ -56,6 +56,16 @@ gl_template_history_init (void)
 }
 
 
+/*****************************************************************************/
+/* Initialize template history with null model.                              */
+/*****************************************************************************/
+void
+gl_template_history_init_null (void)
+{
+        gl_template_history = gl_template_history_model_new_null ();
+}
+
+
 
 /*
  * Local Variables:       -- emacs
diff --git a/src/template-history.h b/src/template-history.h
index 4b0e784..8385920 100644
--- a/src/template-history.h
+++ b/src/template-history.h
@@ -32,6 +32,7 @@ glTemplateHistoryModel *gl_template_history;
 
 
 void            gl_template_history_init (void);
+void            gl_template_history_init_null (void);
 
 
 G_END_DECLS



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