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);
}
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. */
/*****************************************************************************/
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);
+ }
}
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;
}
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");
}
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;
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));
+ }
}
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;
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);
+ }
}
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;
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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));
+ }
}
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;
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);
+ }
}
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;
}
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));
+ }
}
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;
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));
+ }
}
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;
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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));
+ }
}
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;
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));
+ }
}
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;
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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);
+ }
}
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;
}
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);
}
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. */
/*****************************************************************************/
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);
+ }
}
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;
}