]> git.sur5r.net Git - glabels/commitdiff
Removed laste vestiges of windowing system or dbus dependencies from glabels-batch.
authorJim Evins <evins@snaught.com>
Fri, 4 Mar 2016 03:55:49 +0000 (22:55 -0500)
committerJim Evins <evins@snaught.com>
Fri, 4 Mar 2016 04:01:15 +0000 (23:01 -0500)
12 files changed:
src/font-history-model.c
src/font-history-model.h
src/font-history.c
src/font-history.h
src/glabels-batch.c
src/prefs-model.c
src/prefs.c
src/prefs.h
src/template-history-model.c
src/template-history-model.h
src/template-history.c
src/template-history.h

index 3ae9a8696376152b29a751cb8c908f64f36edb9c..65d135b44e7655e4d9e2aa8d98d61f4f8037c94c 100644 (file)
@@ -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,12 +130,34 @@ 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;
 }
 
 
+/*****************************************************************************/
+/** 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.                                                      */
 /*****************************************************************************/
@@ -151,31 +165,34 @@ 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;
 }
index 690c3c77b4e6987ca068761ee8e5ea51a396ea66..4cda3129f7515c33790d5ed81c589da0e26f8abd 100644 (file)
@@ -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);
index ec076fc2d7d3d91a27b4548679b39ee1fb65358e..354f7db77abb71c975e07aee573b3b6dc4aff5c0 100644 (file)
@@ -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
index c877c7b9c58e19dc2ae1d76fbb3de2c33768645d..ffbc11386eabf0678d02337b81f693ecf9a36b02 100644 (file)
@@ -32,6 +32,7 @@ glFontHistoryModel *gl_font_history;
 
 
 void            gl_font_history_init (void);
+void            gl_font_history_init_null (void);
 
 
 G_END_DECLS
index fb5cc7afa376253b3ebf099579dd5edc3f401667..64dbb0caf69dc216d0b077cbb8cdff56df60f030 100644 (file)
@@ -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) {
index b9232a797228b08de33b2568146c0a4275cd225a..b4ff709492fc094ea126401f67c28b8bb2e05867 100644 (file)
@@ -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;
 }
index dc58f7da22ab1e61960ef08953cd01b041046cfa..3e8aa502fe84c58f9e8d7568b24c5210ed696982 100644 (file)
@@ -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
index 7cabea1e4cc1144441313ab6e9705d9f66aa82ec..96277e223e049f4053d24d287fc5a653f340ab8e 100644 (file)
@@ -30,6 +30,7 @@ extern glPrefsModel *gl_prefs;
 
 
 void          gl_prefs_init                (void);
+void          gl_prefs_init_null           (void);
 
 
 G_END_DECLS
index 9105a8ff751a87fbfd5a9e2db87a3b5f79c5c111..e146a44f59f7a22870236adc3a5c890b84e007e4 100644 (file)
@@ -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,12 +129,34 @@ 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;
 }
 
 
+/*****************************************************************************/
+/** 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.                                                  */
 /*****************************************************************************/
@@ -150,31 +164,34 @@ 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;
 }
 
index 1de986650582a6a5bb033ba94880aa946906f1fc..6db51f421f500ea5162a3c3100c9265eb3c7b469 100644 (file)
@@ -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);
index 166567c9e0b4d712ecb8ff6cccfb5e5afdf79bc5..db66faea801c0c56046acc4c3b7cffb98c216c8a 100644 (file)
@@ -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
index 4b0e784ec15755cdeccad40a290d7b91ca19f715..8385920204dd6c61b10133597af1899e7b8e886d 100644 (file)
@@ -32,6 +32,7 @@ glTemplateHistoryModel *gl_template_history;
 
 
 void            gl_template_history_init (void);
+void            gl_template_history_init_null (void);
 
 
 G_END_DECLS