]> git.sur5r.net Git - glabels/commitdiff
Refactored glPrefsModel; Added Units module to libglabels
authorJim Evins <evins@snaught.com>
Mon, 26 Oct 2009 01:06:25 +0000 (21:06 -0400)
committerJim Evins <evins@snaught.com>
Mon, 26 Oct 2009 01:06:25 +0000 (21:06 -0400)
Refactored glPrefsModel, reconciling its style with glFontsHistory, etc.

Added Units module to libglabels, consolidating most utilities associated
with units into this module.  Also created a units-util module in
glabels for utilities that do not belong in libglabels.

45 files changed:
docs/libglabels/libglabels-decl-list.txt
docs/libglabels/libglabels-docs.sgml
docs/libglabels/libglabels-sections.txt
docs/libglabels/libglabels-undocumented.txt [deleted file]
docs/libglabels/tmpl/enums.sgml [deleted file]
docs/libglabels/tmpl/libglabels-unused.sgml
docs/libglabels/tmpl/paper.sgml
docs/libglabels/tmpl/units.sgml [new file with mode: 0644]
libglabels/Makefile.am
libglabels/enums.h [deleted file]
libglabels/libglabels.h
libglabels/units.c [new file with mode: 0644]
libglabels/units.h [new file with mode: 0644]
libglabels/xml.c
libglabels/xml.h
po/POTFILES.in
src/Makefile.am
src/cairo-label-path.c
src/font-combo-menu.c
src/font-history-model.c
src/glabels.c
src/object-editor-bc-page.c
src/object-editor-fill-page.c
src/object-editor-line-page.c
src/object-editor-lsize-page.c
src/object-editor-position-page.c
src/object-editor-shadow-page.c
src/object-editor-size-page.c
src/object-editor-text-page.c
src/prefs-dialog.c
src/prefs-model.c
src/prefs-model.h
src/prefs.c
src/prefs.h
src/recent.c
src/template-designer.c
src/ui-commands.c
src/ui-property-bar.c
src/ui.c
src/units-util.c [new file with mode: 0644]
src/units-util.h [new file with mode: 0644]
src/view.c
src/wdgt-media-select.c
src/window.c
src/xml-label.c

index d3e6343c1b158c1b8e031df63f6ed35de95a8a43..b86ecf0f7c0b5783d0dc78e2b80f2e19d0ac7080 100644 (file)
@@ -5,11 +5,6 @@ lgl_xml_paper_parse_papers_doc
 lgl_xml_paper_parse_paper_node
 </SECTION>
 
-<SECTION>
-<FILE>enums</FILE>
-lglUnitsType
-</SECTION>
-
 <SECTION>
 <FILE>xml-category</FILE>
 lgl_xml_category_read_categories_from_file
@@ -59,6 +54,17 @@ lgl_db_print_known_templates
 lgl_db_print_aliases
 </SECTION>
 
+<SECTION>
+<FILE>units</FILE>
+lglUnits
+lgl_units_get_id
+lgl_units_from_id
+lgl_units_get_name
+lgl_units_from_name
+lgl_units_get_points_per_unit
+lgl_units_get_units_per_point
+</SECTION>
+
 <SECTION>
 <FILE>str</FILE>
 lgl_str_utf8_casecmp
index a4b5b38106385a6c674f6542eb76925c3d827cae..a246139fd2f6168d31e915d535a5e5861cb0f9df 100644 (file)
@@ -26,7 +26,7 @@
 
   <chapter>
     <title>Miscellaneous</title>
-    <xi:include href="xml/enums.xml"/>
+    <xi:include href="xml/units.xml"/>
     <xi:include href="xml/str.xml"/>
   </chapter>
 
index 658d109cacf6371fdb4da5f489e240d86da7ae4d..3039050c7e704a461a1e2554842157c2c471932f 100644 (file)
@@ -181,9 +181,15 @@ lgl_xml_set_default_units
 </SECTION>
 
 <SECTION>
-<FILE>enums</FILE>
-<INCLUDE>libglabels/enums.h</INCLUDE>
-lglUnitsType
+<FILE>units</FILE>
+<INCLUDE>libglabels/units.h</INCLUDE>
+lglUnits
+lgl_units_get_id
+lgl_units_from_id
+lgl_units_get_name
+lgl_units_from_name
+lgl_units_get_points_per_unit
+lgl_units_get_units_per_point
 </SECTION>
 
 <SECTION>
diff --git a/docs/libglabels/libglabels-undocumented.txt b/docs/libglabels/libglabels-undocumented.txt
deleted file mode 100644 (file)
index 0c4f3ab..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-99% symbol docs coverage.
-141 symbols documented.
-1 symbols incomplete.
-1 not documented.
-
-
-LGL_XML_NAME_SPACE
-lglPaper (pwg_size)
-
-
diff --git a/docs/libglabels/tmpl/enums.sgml b/docs/libglabels/tmpl/enums.sgml
deleted file mode 100644 (file)
index b74f00d..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<!-- ##### SECTION Title ##### -->
-Enumerations
-
-<!-- ##### SECTION Short_Description ##### -->
-Common enumerations used by libglabels
-
-<!-- ##### SECTION Long_Description ##### -->
-<para>
-This section defines enumerations used to interact with libglabels.
-</para>
-
-<!-- ##### SECTION See_Also ##### -->
-<para>
-
-</para>
-
-<!-- ##### SECTION Stability_Level ##### -->
-
-
-<!-- ##### ENUM lglUnitsType ##### -->
-<para>
-This enumeration defines a set of units of distance supported by the libglabels XML distance
-attributes.
-</para>
-
-@LGL_UNITS_POINT: Points.  Encoded as "pt" in XML distance attributes.
-@LGL_UNITS_INCH: Inches.  Encoded as "in" in XML distance attributes.
-@LGL_UNITS_MM: Millmeters.  Encoded as "mm" in XML distance attributes.
-@LGL_UNITS_CM: Centimeters.  Encoded as "cm" in XML distance attributes.
-@LGL_UNITS_PICA: Picas.  Encoded as "pc" in XML distance attributes.
-@LGL_UNITS_FIRST: First enumeration.  Used for generic iteration through supported units..
-@LGL_UNITS_LAST: Last enumeration.  Used for generic iteration through supported units.
-
index dc089b4261119ae8b385355b81b357921ac79207..628b4aee2503f63f069e822ae4b01b627d7a0c02 100644 (file)
@@ -1,3 +1,27 @@
+<!-- ##### SECTION ./tmpl/enums.sgml:Long_Description ##### -->
+<para>
+This section defines enumerations used to interact with libglabels.
+</para>
+
+
+<!-- ##### SECTION ./tmpl/enums.sgml:See_Also ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### SECTION ./tmpl/enums.sgml:Short_Description ##### -->
+Common enumerations used by libglabels
+
+
+<!-- ##### SECTION ./tmpl/enums.sgml:Stability_Level ##### -->
+
+
+
+<!-- ##### SECTION ./tmpl/enums.sgml:Title ##### -->
+Enumerations
+
+
 <!-- ##### SECTION ./tmpl/init.sgml:Long_Description ##### -->
 <para>
 
@@ -1248,6 +1272,20 @@ the CSS2 Specification (Section 4.3.2).
 @templates: 
 @utf8_filename: 
 
+<!-- ##### ENUM lglUnitsType ##### -->
+<para>
+This enumeration defines a set of units of distance supported by the libglabels XML distance
+attributes.
+</para>
+
+@LGL_UNITS_POINT: Points.  Encoded as "pt" in XML distance attributes.
+@LGL_UNITS_INCH: Inches.  Encoded as "in" in XML distance attributes.
+@LGL_UNITS_MM: Millmeters.  Encoded as "mm" in XML distance attributes.
+@LGL_UNITS_CM: Centimeters.  Encoded as "cm" in XML distance attributes.
+@LGL_UNITS_PICA: Picas.  Encoded as "pc" in XML distance attributes.
+@LGL_UNITS_FIRST: First enumeration.  Used for generic iteration through supported units..
+@LGL_UNITS_LAST: Last enumeration.  Used for generic iteration through supported units.
+
 <!-- ##### FUNCTION lgl_category_free_id_list ##### -->
 <para>
 
index fab9ee67ab4fb9441815dd7edbe440a5f7f1eb3b..448b1196e699c1df2f4aa396efafa841a89fbf43 100644 (file)
@@ -27,7 +27,7 @@ This structure defines a paper (page) size.
 @name: Localized paper size name.
 @width: Width of paper in points.
 @height: Height of paper in points.
-@pwg_size: 
+@pwg_size: Paper size string as defined in PWG 5101.1-2002.
 
 <!-- ##### FUNCTION lgl_paper_new ##### -->
 <para>
diff --git a/docs/libglabels/tmpl/units.sgml b/docs/libglabels/tmpl/units.sgml
new file mode 100644 (file)
index 0000000..bcb7b29
--- /dev/null
@@ -0,0 +1,89 @@
+<!-- ##### SECTION Title ##### -->
+Units
+
+<!-- ##### SECTION Short_Description ##### -->
+Type to represent units of distance supported by libglabels
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+This section defines a type to represent the varios units of distance
+supported by libglabels.  It also defines a set of related functions.
+
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### ENUM lglUnits ##### -->
+<para>
+This enumeration defines supported units of distance.
+</para>
+
+@LGL_UNITS_POINT: Points.
+@LGL_UNITS_INCH: Inches.
+@LGL_UNITS_MM: Millimeters
+@LGL_UNITS_CM: Centimeters
+@LGL_UNITS_PICA: Picas
+@LGL_UNITS_FIRST: First supported unit.  (Used for bounds checking and iteration through supported units.)
+@LGL_UNITS_LAST: Last supported unit.  (Used for bounds checking and iteration through supported units.)
+@LGL_UNITS_INVALID: Invalid unit.  (Returned by libglabels units functions when a supported unit cannot be determined.)
+
+<!-- ##### FUNCTION lgl_units_get_id ##### -->
+<para>
+
+</para>
+
+@units: 
+@Returns: 
+
+
+<!-- ##### FUNCTION lgl_units_from_id ##### -->
+<para>
+
+</para>
+
+@id: 
+@Returns: 
+
+
+<!-- ##### FUNCTION lgl_units_get_name ##### -->
+<para>
+
+</para>
+
+@units: 
+@Returns: 
+
+
+<!-- ##### FUNCTION lgl_units_from_name ##### -->
+<para>
+
+</para>
+
+@name: 
+@Returns: 
+
+
+<!-- ##### FUNCTION lgl_units_get_points_per_unit ##### -->
+<para>
+
+</para>
+
+@units: 
+@Returns: 
+
+
+<!-- ##### FUNCTION lgl_units_get_units_per_point ##### -->
+<para>
+
+</para>
+
+@units: 
+@Returns: 
+
+
index 2d1228ab9119a6905d46ed11710744c7de999512..af5e663ea554a6a4356cd309198bb81001559aec 100644 (file)
@@ -19,7 +19,8 @@ libglabels_la_SOURCES =               \
        libglabels-private.h    \
        db.h                    \
        db.c                    \
-       enums.h                 \
+       units.h                 \
+       units.c                 \
        paper.h                 \
        paper.c                 \
        category.h              \
@@ -40,7 +41,7 @@ libglabels_la_SOURCES =               \
 libglabelsinclude_HEADERS =    \
        libglabels.h            \
        db.h                    \
-       enums.h                 \
+       units.h                 \
        paper.h                 \
        category.h              \
        template.h              \
diff --git a/libglabels/enums.h b/libglabels/enums.h
deleted file mode 100644 (file)
index 6ebcc1d..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  enums.h
- *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
- *
- *  This file is part of libglabels.
- *
- *  libglabels is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  libglabels is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with libglabels.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __ENUMS_H__
-#define __ENUMS_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/* Units of distance */
-typedef enum {
-       LGL_UNITS_POINT, /* encoded as "pt" */
-       LGL_UNITS_INCH,  /* encoded as "in" */
-       LGL_UNITS_MM,    /* encoded as "mm" */
-       LGL_UNITS_CM,    /* encoded as "cm" */
-       LGL_UNITS_PICA,  /* encoded as "pc" */
-
-       LGL_UNITS_FIRST = LGL_UNITS_POINT,
-       LGL_UNITS_LAST  = LGL_UNITS_PICA,
-} lglUnitsType;
-
-
-G_END_DECLS
-
-
-#endif /* __ENUMS_H__ */
-
-
-
-/*
- * Local Variables:       -- emacs
- * mode: C                -- emacs
- * c-basic-offset: 8      -- emacs
- * tab-width: 8           -- emacs
- * indent-tabs-mode: nil  -- emacs
- * End:                   -- emacs
- */
index bd46b19de08a014d0167d727347ad5417bc48624..6d456700b133ff7256a93bb9590e5f38d6624c67 100644 (file)
@@ -25,7 +25,7 @@
 #include <libglabels/paper.h>
 #include <libglabels/category.h>
 #include <libglabels/template.h>
-#include <libglabels/enums.h>
+#include <libglabels/units.h>
 #include <libglabels/str.h>
 #include <libglabels/xml-paper.h>
 #include <libglabels/xml-category.h>
diff --git a/libglabels/units.c b/libglabels/units.c
new file mode 100644 (file)
index 0000000..e585962
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ *  units.c
+ *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of libglabels.
+ *
+ *  libglabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  libglabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with libglabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "units.h"
+
+#include <glib/gi18n.h>
+#include <glib.h>
+#include <string.h>
+
+#include "libglabels-private.h"
+
+
+/*========================================================*/
+/* Private macros and constants.                          */
+/*========================================================*/
+
+#define POINTS_PER_POINT    1.0 /* internal units are points. */
+#define POINTS_PER_INCH    72.0
+#define POINTS_PER_MM       2.83464566929
+#define POINTS_PER_CM       (10.0*POINTS_PER_MM)
+#define POINTS_PER_PICA     (1.0/12.0)
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+typedef struct {
+       gchar       *id;
+       gchar       *name;
+       gdouble      points_per_unit;
+} UnitTableEntry;
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static UnitTableEntry unit_table[] = {
+
+       /* The ids are identical to the absolute length units supported in
+          the CSS2 Specification (Section 4.3.2) */
+
+       /* This table must be sorted exactly as the enumerations in lglUnits */
+
+       /* [LGL_UNITS_POINT] */   {"pt", N_("points"), POINTS_PER_POINT},
+       /* [LGL_UNITS_INCH]  */   {"in", N_("inches"), POINTS_PER_INCH},
+       /* [LGL_UNITS_MM]    */   {"mm", N_("mm"),     POINTS_PER_MM},
+       /* [LGL_UNITS_CM]    */   {"cm", N_("cm"),     POINTS_PER_CM},
+       /* [LGL_UNITS_PICA]  */   {"pc", N_("picas"),  POINTS_PER_PICA},
+
+};
+
+
+
+/**
+ * lgl_units_get_id:
+ * @units:       Units (#lglUnits)
+ *
+ * Return a unique ID string for the given units.  This ID is how units
+ * are encoded in libglabels XML files and will remain constant across
+ * all locales.  IDs are identical to the absolute length units supported
+ * in the CSS2 Specification (Section 4.3.2). 
+ *
+ * Returns: ID string.
+ *
+ */
+const gchar *
+lgl_units_get_id (lglUnits     units)
+{
+        if ( (units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST) )
+        {
+                return unit_table[units].id;
+        }
+        else
+        {
+                /* Default to "pt", if invalid. */
+                return unit_table[LGL_UNITS_POINT].id;
+        }
+}
+
+
+/**
+ * lgl_units_from_id:
+ * @id:       ID string
+ *
+ * Return the unique #lglUnits for the given ID string.
+ * This ID is how units are encoded in libglabels XML files and will remain
+ * constant across all locales.  IDs are identical to the absolute length
+ * units supported in the CSS2 Specification (Section 4.3.2). 
+ *
+ * Returns: units (#lglUnits).
+ *
+ */
+lglUnits
+lgl_units_from_id (const gchar *id)
+{
+        lglUnits units;
+
+        /* An empty or missing id defaults to points. */
+        if ( (id == NULL) || (strlen (id) == 0) )
+        {
+                return LGL_UNITS_POINT;
+        }
+
+        for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
+                if (g_ascii_strcasecmp (id, unit_table[units].id) == 0) {
+                        return units;
+                }
+        }
+
+        /* Try name as a fallback. (Will catch some legacy preferences.) */
+        for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
+                if (g_ascii_strcasecmp (id, unit_table[units].name) == 0) {
+                        return units;
+                }
+        }
+
+        /* For compatibility with old preferences. */
+        if (g_ascii_strcasecmp (id, "Millimeters") == 0) {
+                return LGL_UNITS_MM;
+        }
+
+        return LGL_UNITS_INVALID;
+}
+
+
+/**
+ * lgl_units_get_name:
+ * @units:       Units (#lglUnits)
+ *
+ * Return a unique name string for the given units.  This name is human
+ * readable and will be translated to the current locale.
+ *
+ * Returns: name string.
+ *
+ */
+const gchar *
+lgl_units_get_name (lglUnits     units)
+{
+        if ( (units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST) )
+        {
+                return gettext ((char *)unit_table[units].name);
+        }
+        else
+        {
+                /* Default to "points", if invalid. */
+                return gettext ((char *)unit_table[LGL_UNITS_POINT].name);
+        }
+}
+
+
+/**
+ * lgl_units_from_name:
+ * @name:       NAME string
+ *
+ * Return the unique #lglUnits for the given name string.  This name is
+ * human readable and is expected to be translated to the current locale.
+ *
+ * Returns: units (#lglUnits).
+ *
+ */
+lglUnits
+lgl_units_from_name (const gchar *name)
+{
+        lglUnits units;
+
+        for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
+                if (g_ascii_strcasecmp (name, gettext ((char *)unit_table[units].name) ) == 0) {
+                        return units;
+                }
+        }
+
+        return LGL_UNITS_INVALID;
+}
+
+
+/**
+ * lgl_units_get_points_per_unit:
+ * @units:       Units (#lglUnits)
+ *
+ * Return a scale factor for the given units in points/unit.
+ *
+ * Returns: scale factor.
+ *
+ */
+gdouble
+lgl_units_get_points_per_unit (lglUnits     units)
+{
+        if ( (units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST) )
+        {
+                return unit_table[units].points_per_unit;
+        }
+        else
+        {
+                /* Default to "points", if invalid. */
+                return 1.0;
+        }
+}
+
+
+/**
+ * lgl_units_get_units_per_point:
+ * @units:       Units (#lglUnits)
+ *
+ * Return a scale factor for the given units in units/point.
+ *
+ * Returns: scale factor.
+ *
+ */
+gdouble
+lgl_units_get_units_per_point (lglUnits     units)
+{
+        if ( (units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST) )
+        {
+                return 1.0 / unit_table[units].points_per_unit;
+        }
+        else
+        {
+                /* Default to "points", if invalid. */
+                return 1.0;
+        }
+}
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/libglabels/units.h b/libglabels/units.h
new file mode 100644 (file)
index 0000000..ac3bb0c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  units.h
+ *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of libglabels.
+ *
+ *  libglabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  libglabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with libglabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LGL_UNITS_H__
+#define __LGL_UNITS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+
+/*
+ * Units of distance
+ */
+typedef enum {
+       LGL_UNITS_POINT, /* encoded as "pt" */
+       LGL_UNITS_INCH,  /* encoded as "in" */
+       LGL_UNITS_MM,    /* encoded as "mm" */
+       LGL_UNITS_CM,    /* encoded as "cm" */
+       LGL_UNITS_PICA,  /* encoded as "pc" */
+
+       LGL_UNITS_FIRST = LGL_UNITS_POINT,
+       LGL_UNITS_LAST  = LGL_UNITS_PICA,
+
+        LGL_UNITS_INVALID = -1,
+} lglUnits;
+
+
+const gchar *lgl_units_get_id               (lglUnits     units);
+lglUnits     lgl_units_from_id              (const gchar *id);
+
+const gchar *lgl_units_get_name             (lglUnits     units);
+lglUnits     lgl_units_from_name            (const gchar *name);
+
+gdouble      lgl_units_get_points_per_unit  (lglUnits     units);
+gdouble      lgl_units_get_units_per_point  (lglUnits     units);
+
+
+G_END_DECLS
+
+
+#endif /* __LGL_UNITS_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index 91cbb20524374615c0312da23fb2bba9b4653852..4bce17e2107be85fef2a9e86c3fa23083bd00e85 100644 (file)
 /* Private macros and constants.                          */
 /*========================================================*/
 
-#define POINTS_PER_POINT    1.0 /* internal units are points. */
-#define POINTS_PER_INCH    72.0
-#define POINTS_PER_MM       2.83464566929
-#define POINTS_PER_CM       (10.0*POINTS_PER_MM)
-#define POINTS_PER_PICA     (1.0/12.0)
-
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
 
-typedef struct {
-       xmlChar     *name;
-       gdouble      points_per_unit;
-} UnitTableEntry;
-
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
 
-static UnitTableEntry unit_table[] = {
-
-       /* These names are identical to the absolute length units supported in
-          the CSS2 Specification (Section 4.3.2) */
-
-       /* This table must be sorted exactly as the enumerations in lglUnitsType */
-
-       /* [LGL_UNITS_POINT] */   {(xmlChar *)"pt",      POINTS_PER_POINT},
-       /* [LGL_UNITS_INCH]  */   {(xmlChar *)"in",      POINTS_PER_INCH},
-       /* [LGL_UNITS_MM]    */   {(xmlChar *)"mm",      POINTS_PER_MM},
-       /* [LGL_UNITS_CM]    */   {(xmlChar *)"cm",      POINTS_PER_CM},
-       /* [LGL_UNITS_PICA]  */   {(xmlChar *)"pc",      POINTS_PER_PICA},
-
-};
-
-static lglUnitsType  default_units        = LGL_UNITS_POINT;
+static lglUnits  default_units        = LGL_UNITS_POINT;
 
 
 /****************************************************************************/
@@ -299,29 +273,26 @@ lgl_xml_get_prop_length (xmlNodePtr   node,
 {
        gdouble  val;
        xmlChar *string;
-       xmlChar *unit;
-       gint     i;
+       xmlChar *unit_id;
+        lglUnits units;
 
        string = xmlGetProp (node, (xmlChar *)property);
        if ( string != NULL ) {
 
-               val = g_strtod ((gchar *)string, (gchar **)&unit);
-
-               if (unit != string) {
-                       unit = (xmlChar *)g_strchug ((gchar *)unit);
-                       if (strlen ((char *)unit) > 0 ) {
-                               for (i=LGL_UNITS_FIRST; i<=LGL_UNITS_LAST; i++) {
-                                       if (xmlStrcasecmp (unit, unit_table[i].name) == 0) {
-                                               val *= unit_table[i].points_per_unit;
-                                               break;
-                                       }
-                               }
-                               if (i>LGL_UNITS_LAST) {
-                                       g_message ("Line %ld, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
-                                                  xmlGetLineNo (node), node->name, property,
-                                                  unit);
-                               }
-                       }
+               val = g_strtod ((gchar *)string, (gchar **)&unit_id);
+
+               if (unit_id != string) {
+                       unit_id = (xmlChar *)g_strchug ((gchar *)unit_id);
+                        units = lgl_units_from_id ((gchar *)unit_id);
+                        if (units != LGL_UNITS_INVALID)
+                        {
+                                val *= lgl_units_get_points_per_unit (units);
+                        }
+                        else
+                        {
+                                g_message ("Line %ld, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
+                                           xmlGetLineNo (node), node->name, property, unit_id);
+                        }
                }
                else {
                        val = 0.0;
@@ -458,12 +429,12 @@ lgl_xml_set_prop_length (xmlNodePtr    node,
        gchar  *string_unit;
 
        /* Convert to default units */
-       val /= unit_table[default_units].points_per_unit;
+       val *= lgl_units_get_units_per_point (default_units);
 
        /* Guarantee "C" locale by use of g_ascii_formatd */
        string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
 
-       string_unit = g_strdup_printf ("%s%s", string, unit_table[default_units].name);
+       string_unit = g_strdup_printf ("%s%s", string, lgl_units_get_id (default_units));
        xmlSetProp (node, (xmlChar *)property, (xmlChar *)string_unit);
         g_free (string_unit);
 }
@@ -517,14 +488,14 @@ lgl_xml_get_node_content (xmlNodePtr   node)
 
 /**
  * lgl_xml_set_default_units:
- * @units:       default units selection (#lglUnitsType)
+ * @units:       default units selection (#lglUnits)
  *
  * Set the default units when formatting lengths.  See
  * lgl_xml_set_prop_length().
  *
  */
 void
-lgl_xml_set_default_units (lglUnitsType   units)
+lgl_xml_set_default_units (lglUnits   units)
 {
        g_return_if_fail ((units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST));
 
index 257ee4554ffa470bc3235406e12634d8c5c2d13f..7b49c8fc530b382616ff5edf1c3b27195cdb0ff4 100644 (file)
@@ -24,7 +24,7 @@
 #include <glib.h>
 #include <libxml/tree.h>
 
-#include "enums.h"
+#include "units.h"
 
 #define LGL_XML_NAME_SPACE "http://snaught.com/glabels/2.2/"
 
@@ -100,7 +100,7 @@ gchar *  lgl_xml_get_node_content  (xmlNodePtr    node);
 /*
  * Misc functions
  */
-void     lgl_xml_set_default_units (lglUnitsType   units);
+void     lgl_xml_set_default_units (lglUnits      units);
 
 G_END_DECLS
 
index 69435c32426caf0483ef09a3bf41b73915666933..8afc6d40a34140a6b817950b454271b7cb87ca2c 100644 (file)
@@ -157,6 +157,8 @@ src/ui-sidebar.c
 src/ui-sidebar.h
 src/ui-util.c
 src/ui-util.h
+src/units-util.c
+src/units-util.h
 src/view.c
 src/view.h
 src/view-barcode.c
@@ -190,7 +192,6 @@ libglabels/category.c
 libglabels/category.h
 libglabels/db.c
 libglabels/db.h
-libglabels/enums.h
 libglabels/libglabels-private.h
 libglabels/paper.c
 libglabels/paper.h
@@ -198,6 +199,8 @@ libglabels/str.c
 libglabels/str.h
 libglabels/template.c
 libglabels/template.h
+libglabels/units.c
+libglabels/units.h
 libglabels/xml.c
 libglabels/xml.h
 libglabels/xml-category.c
index 55e5e2fc0bb140994192b60c4975f08aea5a45c2..0db025296a9aafed00aa82882b99bb07ef2fa78a 100644 (file)
@@ -223,6 +223,8 @@ glabels_SOURCES =                   \
        combo-util.h                    \
        builder-util.c                  \
        builder-util.h                  \
+       units-util.c                    \
+       units-util.h                    \
        str-util.c                      \
        str-util.h                      \
        color.c                         \
index 59b8db13db28f56001662d7c51718a653a9247ce..0d7e4b78ca0a0f576f24a4b4612a7150a322e635 100644 (file)
@@ -187,6 +187,7 @@ gl_cairo_round_label_path (cairo_t           *cr,
                 waste = 0.0;
         }
 
+       cairo_new_path (cr);
         cairo_arc (cr, w/2, h/2, w/2+waste, 0.0, 2*G_PI);
        cairo_close_path (cr);
 
index 2a0a7c59fa80b94ee851b86969d720debf25a77b..6df363af8251769bfe4c13970e292d600ebd9754 100644 (file)
@@ -118,7 +118,6 @@ gl_font_combo_menu_init (glFontComboMenu *this)
         GtkWidget    *menu_item;
         GtkWidget    *sub_menu;
         const GList  *list;
-        GList        *p;
 
        this->priv = g_new0 (glFontComboMenuPrivate, 1);
 
index 29471d7e2fcbbb6de2a6b9768f70a1a58ed3ff06..0e18b9cb63e752f0ade04de0b4df7e4facb452fc 100644 (file)
@@ -25,6 +25,7 @@
 #include <gconf/gconf-client.h>
 
 #include <libglabels/libglabels.h>
+#include "font-util.h"
 #include "marshal.h"
 
 
index 43d1290919d86a488e24bfe90be1130e43e8399c..d3a107d64d8b42331e7ae76a2cc70b7a29089a7e 100644 (file)
@@ -31,6 +31,7 @@
 #include "mini-preview-pixbuf-cache.h"
 #include "prefs.h"
 #include "font-history.h"
+#include "template-history.h"
 #include "debug.h"
 #include "window.h"
 #include "file.h"
index 3d6f155b23a6b10b2d044582a8893090cf99ece6..4c80ac6c7bd20d6af769bd4c4babc239f400bb56 100644 (file)
@@ -90,7 +90,7 @@ gl_object_editor_prepare_bc_page (glObjectEditor       *editor)
 
        editor->priv->bc_color_combo = gl_color_combo_new (_("Default"),
                                                            GL_COLOR_BC_DEFAULT,
-                                                           gl_prefs->default_line_color);
+                                                           gl_prefs_model_get_default_line_color (gl_prefs));
         gtk_box_pack_start (GTK_BOX (editor->priv->bc_color_hbox),
                             editor->priv->bc_color_combo,
                             FALSE, FALSE, 0);
@@ -376,7 +376,7 @@ gl_object_editor_get_bc_color (glObjectEditor      *editor)
        
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_key_radio))) {
                color_node->field_flag = TRUE;
-               color_node->color = gl_prefs->default_line_color;
+               color_node->color = gl_prefs_model_get_default_line_color (gl_prefs);
                color_node->key = 
                        gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->bc_key_combo));
        } else {
@@ -386,7 +386,7 @@ gl_object_editor_get_bc_color (glObjectEditor      *editor)
                                                   &is_default);
 
                if (is_default) {
-                       color_node->color = gl_prefs->default_line_color;
+                       color_node->color = gl_prefs_model_get_default_line_color (gl_prefs);
                } else {
                        color_node->color = color;
                }
index b1143d2c4fe97c3a351d3c099aa528ea572712e9..b9ea1ac10329278f53f8b5c1c8b04c9dae4fcf79 100644 (file)
@@ -78,7 +78,7 @@ gl_object_editor_prepare_fill_page (glObjectEditor *editor)
        
        editor->priv->fill_color_combo = gl_color_combo_new (_("No Fill"),
                                                              GL_COLOR_NO_FILL,
-                                                             gl_prefs->default_fill_color);
+                                                             gl_prefs_model_get_default_fill_color (gl_prefs));
         gtk_box_pack_start (GTK_BOX (editor->priv->fill_color_hbox),
                             editor->priv->fill_color_combo,
                             FALSE, FALSE, 0);
@@ -90,7 +90,7 @@ gl_object_editor_prepare_fill_page (glObjectEditor *editor)
        gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE);
        gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE);
        gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo),
-                                  gl_prefs->default_fill_color);
+                                  gl_prefs_model_get_default_fill_color (gl_prefs));
 
        /* Un-hide */
        gtk_widget_show_all (editor->priv->fill_page_vbox);
index a7c2f582903d98b039409072e761cafe31030a0c..11869695780c524b41424cb55bdb48231b8ee939 100644 (file)
@@ -78,7 +78,7 @@ gl_object_editor_prepare_line_page (glObjectEditor *editor)
 
        editor->priv->line_color_combo = gl_color_combo_new (_("No Line"),
                                                              GL_COLOR_NO_LINE,
-                                                             gl_prefs->default_line_color);
+                                                             gl_prefs_model_get_default_line_color (gl_prefs));
         gtk_box_pack_start (GTK_BOX (editor->priv->line_color_hbox),
                             editor->priv->line_color_combo,
                             FALSE, FALSE, 0);
@@ -90,9 +90,9 @@ gl_object_editor_prepare_line_page (glObjectEditor *editor)
        gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
     gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);    
        gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
-                                  gl_prefs->default_line_width);
+                                  gl_prefs_model_get_default_line_width (gl_prefs));
        gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
-                                  gl_prefs->default_line_color);
+                                  gl_prefs_model_get_default_line_color (gl_prefs));
 
        /* Un-hide */
        gtk_widget_show_all (editor->priv->line_page_vbox);
index a832f09423043fc7de6172ea5694316f0dcdf6cd..a1b8365c86bf07f295dddcc87f59fce5f1780637 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "prefs.h"
 #include "builder-util.h"
+#include "units-util.h"
 
 #include "object-editor-private.h"
 
@@ -65,6 +66,7 @@
 void
 gl_object_editor_prepare_lsize_page (glObjectEditor       *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -80,10 +82,11 @@ gl_object_editor_prepare_lsize_page (glObjectEditor       *editor)
                                      NULL);
 
        /* Get configuration information */
-       units_string = gl_prefs_get_units_string ();
-       editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-       climb_rate = gl_prefs_get_units_step_size ();
-       digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       units_string = lgl_units_get_name (units);
+       editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+       climb_rate = gl_units_util_get_step_size (units);
+       digits = gl_units_util_get_precision (units);
 
        /* Modify widgets based on configuration */
        gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), digits);
@@ -223,6 +226,7 @@ gl_object_editor_get_lsize (glObjectEditor      *editor,
 void
 lsize_prefs_changed_cb (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -230,10 +234,11 @@ lsize_prefs_changed_cb (glObjectEditor *editor)
        gl_debug (DEBUG_EDITOR, "START");
 
         /* Get new configuration information */
-        units_string = gl_prefs_get_units_string ();
-        editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-        climb_rate = gl_prefs_get_units_step_size ();
-        digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+        units_string = lgl_units_get_name (units);
+        editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+        climb_rate = gl_units_util_get_step_size (units);
+        digits = gl_units_util_get_precision (units);
 
        /* Update characteristics of r_spin */
         editor->priv->stop_signals = TRUE;
index 6ea9a8693b96047acd8c1d4e86f1e360ef3aa5e4..de180a0e48c932438c7fc7636afc8fd7b2ed9eed 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "prefs.h"
 #include "builder-util.h"
+#include "units-util.h"
 
 #include "object-editor-private.h"
 
@@ -60,6 +61,7 @@
 void
 gl_object_editor_prepare_position_page (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -76,10 +78,11 @@ gl_object_editor_prepare_position_page (glObjectEditor *editor)
                                      NULL);
 
        /* Get configuration information */
-       units_string = gl_prefs_get_units_string ();
-       editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-       climb_rate = gl_prefs_get_units_step_size ();
-       digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       units_string = lgl_units_get_name (units);
+       editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+       climb_rate = gl_units_util_get_step_size (units);
+       digits = gl_units_util_get_precision (units);
 
        /* Modify widgets based on configuration */
        gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
@@ -212,6 +215,7 @@ gl_object_editor_get_position (glObjectEditor      *editor,
 void
 position_prefs_changed_cb (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -219,10 +223,11 @@ position_prefs_changed_cb (glObjectEditor *editor)
        gl_debug (DEBUG_EDITOR, "START");
 
         /* Get new configuration information */
-        units_string = gl_prefs_get_units_string ();
-        editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-        climb_rate = gl_prefs_get_units_step_size ();
-        digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+        units_string = lgl_units_get_name (units);
+        editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+        climb_rate = gl_units_util_get_step_size (units);
+        digits = gl_units_util_get_precision (units);
 
        /* Update characteristics of x_spin/y_spin */
         editor->priv->stop_signals = TRUE;
index 4a3cc2e2417e669918590347b1eac58bd52275e8..d10a1590db4231e49e769df075d65d02b82b881f 100644 (file)
@@ -31,6 +31,7 @@
 #include "color.h"
 #include "combo-util.h"
 #include "builder-util.h"
+#include "units-util.h"
 
 #include "object-editor-private.h"
 
@@ -66,6 +67,7 @@ static void shadow_color_radio_toggled_cb  (glObjectEditor        *editor);
 void
 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -97,10 +99,11 @@ gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
        gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->shadow_key_combo));
 
        /* Get configuration information */
-       units_string = gl_prefs_get_units_string ();
-       editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-       climb_rate = gl_prefs_get_units_step_size ();
-       digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       units_string = lgl_units_get_name (units);
+       editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+       climb_rate = gl_units_util_get_step_size (units);
+       digits = gl_units_util_get_precision (units);
 
        /* Modify widgets based on configuration */
        gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin), digits);
@@ -403,6 +406,7 @@ gl_object_editor_get_shadow_opacity (glObjectEditor      *editor)
 void
 shadow_prefs_changed_cb (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -410,10 +414,11 @@ shadow_prefs_changed_cb (glObjectEditor *editor)
        gl_debug (DEBUG_EDITOR, "START");
 
         /* Get new configuration information */
-        units_string = gl_prefs_get_units_string ();
-        editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-        climb_rate = gl_prefs_get_units_step_size ();
-        digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+        units_string = lgl_units_get_name (units);
+        editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+        climb_rate = gl_units_util_get_step_size (units);
+        digits = gl_units_util_get_precision (units);
 
        /* Update characteristics of x_spin/y_spin */
         editor->priv->stop_signals = TRUE;
index c6821ea16dfa6520bb763de023122d9898a3e78c..34d7ad6684f2c488186bd64407b8fdde9d71d908 100644 (file)
@@ -29,6 +29,7 @@
 #include "prefs.h"
 #include "wdgt-chain-button.h"
 #include "builder-util.h"
+#include "units-util.h"
 
 #include "object-editor-private.h"
 
@@ -67,6 +68,7 @@ void
 gl_object_editor_prepare_size_page (glObjectEditor       *editor,
                                    glObjectEditorOption  option)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -93,10 +95,11 @@ gl_object_editor_prepare_size_page (glObjectEditor       *editor,
 
 
        /* Get configuration information */
-       units_string = gl_prefs_get_units_string ();
-       editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-       climb_rate = gl_prefs_get_units_step_size ();
-       digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       units_string = lgl_units_get_name (units);
+       editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+       climb_rate = gl_units_util_get_step_size (units);
+       digits = gl_units_util_get_precision (units);
 
        /* Modify widgets based on configuration */
        gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->size_w_spin), digits);
@@ -423,6 +426,7 @@ gl_object_editor_get_size (glObjectEditor      *editor,
 void
 size_prefs_changed_cb (glObjectEditor *editor)
 {
+        lglUnits      units;
        const gchar  *units_string;
        gdouble       climb_rate;
        gint          digits;
@@ -430,10 +434,11 @@ size_prefs_changed_cb (glObjectEditor *editor)
        gl_debug (DEBUG_EDITOR, "START");
 
         /* Get new configuration information */
-        units_string = gl_prefs_get_units_string ();
-        editor->priv->units_per_point = gl_prefs_get_units_per_point ();
-        climb_rate = gl_prefs_get_units_step_size ();
-        digits = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+        units_string = lgl_units_get_name (units);
+        editor->priv->units_per_point = lgl_units_get_units_per_point (units);
+        climb_rate = gl_units_util_get_step_size (units);
+        digits = gl_units_util_get_precision (units);
 
        /* Update characteristics of w_spin/h_spin */
         editor->priv->stop_signals = TRUE;
index 615668eaebfd4cd36c1bdbea852681057ab9aa83..3c196327bdde772482af5e093801d9d9f90b5c42 100644 (file)
@@ -96,7 +96,7 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
 
        editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
                                                              GL_COLOR_TEXT_DEFAULT,
-                                                             gl_prefs->default_text_color);
+                                                             gl_prefs_model_get_default_text_color (gl_prefs));
         gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
                             editor->priv->text_color_combo,
                             FALSE, FALSE, 0);
@@ -504,7 +504,7 @@ gl_object_editor_get_text_color (glObjectEditor      *editor)
        
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
                color_node->field_flag = TRUE;
-               color_node->color = gl_prefs->default_text_color;
+               color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
                color_node->key = 
                        gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
         } else {
@@ -514,7 +514,7 @@ gl_object_editor_get_text_color (glObjectEditor      *editor)
                                                   &is_default);
 
                 if (is_default) {
-                        color_node->color = gl_prefs->default_text_color;
+                        color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
                 } else {
                         color_node->color = color;
                 }
index 7deff673582b442538ed327db317b599002bec23..d05f4680d0a458361c169658a89009499947e464 100644 (file)
@@ -208,7 +208,6 @@ gl_prefs_dialog_new (GtkWindow *parent)
        GtkWidget *dialog;
 
        gl_debug (DEBUG_PREFS, "START");
-       gl_debug (DEBUG_PREFS, "page size = \"%s\"", gl_prefs->default_page_size);
 
        dialog = GTK_WIDGET (g_object_new (GL_TYPE_PREFS_DIALOG, NULL));
 
@@ -339,13 +338,13 @@ construct_object_page (glPrefsDialog *dialog)
 
        dialog->priv->text_color_combo = gl_color_combo_new (_("Default"),
                                                              GL_COLOR_TEXT_DEFAULT,
-                                                             gl_prefs->default_text_color);
+                                                             gl_prefs_model_get_default_text_color (gl_prefs));
        dialog->priv->line_color_combo = gl_color_combo_new (_("No Line"),
                                                              GL_COLOR_NO_LINE,
-                                                             gl_prefs->default_line_color);
+                                                             gl_prefs_model_get_default_line_color (gl_prefs));
        dialog->priv->fill_color_combo = gl_color_combo_new (_("No Fill"),
                                                              GL_COLOR_NO_FILL,
-                                                             gl_prefs->default_fill_color);
+                                                             gl_prefs_model_get_default_fill_color (gl_prefs));
 
         gtk_box_pack_start (GTK_BOX (dialog->priv->text_family_hbox),
                             dialog->priv->text_family_combo,
@@ -467,7 +466,7 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
 {
        dialog->priv->stop_signals = TRUE;
 
-       switch (gl_prefs->units) {
+       switch (gl_prefs_model_get_units (gl_prefs)) {
        case LGL_UNITS_POINT:
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dialog->priv->units_points_radio),
@@ -488,12 +487,12 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
                break;
        }
 
-       if ( g_ascii_strcasecmp(gl_prefs->default_page_size, US_LETTER_ID) == 0)
+       if ( g_ascii_strcasecmp(gl_prefs_model_get_default_page_size (gl_prefs), US_LETTER_ID) == 0)
         {
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dialog->priv->page_size_us_letter_radio), TRUE);
        }
-        else if ( g_ascii_strcasecmp(gl_prefs->default_page_size, A4_ID) == 0)
+        else if ( g_ascii_strcasecmp(gl_prefs_model_get_default_page_size (gl_prefs), A4_ID) == 0)
         {
                gtk_toggle_button_set_active (
                        GTK_TOGGLE_BUTTON(dialog->priv->page_size_a4_radio), TRUE);
@@ -501,6 +500,8 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
         else
         {
                g_message ("Unknown default page size"); /* Shouldn't happen */
+               gtk_toggle_button_set_active (
+                       GTK_TOGGLE_BUTTON(dialog->priv->page_size_a4_radio), TRUE);
        }
 
        dialog->priv->stop_signals = FALSE;
@@ -517,39 +518,39 @@ update_object_page_from_prefs (glPrefsDialog *dialog)
        dialog->priv->stop_signals = TRUE;
 
        gl_font_combo_set_family (GL_FONT_COMBO (dialog->priv->text_family_combo),
-                                  gl_prefs->default_font_family);
+                                  gl_prefs_model_get_default_font_family (gl_prefs));
 
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->text_size_spin),
-                                   gl_prefs->default_font_size);
+                                   gl_prefs_model_get_default_font_size (gl_prefs));
  
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_bold_toggle),
-                                      (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
+                                      (gl_prefs_model_get_default_font_weight (gl_prefs) == PANGO_WEIGHT_BOLD));
  
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_italic_toggle),
-                                      gl_prefs->default_font_italic_flag);
+                                      gl_prefs_model_get_default_font_italic_flag (gl_prefs));
  
         gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->text_color_combo),
-                                  gl_prefs->default_text_color);
+                                  gl_prefs_model_get_default_text_color (gl_prefs));
 
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_left_toggle),
-                                 (gl_prefs->default_text_alignment == GTK_JUSTIFY_LEFT));
+                                 (gl_prefs_model_get_default_text_alignment (gl_prefs) == GTK_JUSTIFY_LEFT));
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_center_toggle),
-                                 (gl_prefs->default_text_alignment == GTK_JUSTIFY_CENTER));
+                                 (gl_prefs_model_get_default_text_alignment (gl_prefs) == GTK_JUSTIFY_CENTER));
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_right_toggle),
-                                 (gl_prefs->default_text_alignment == GTK_JUSTIFY_RIGHT));
+                                 (gl_prefs_model_get_default_text_alignment (gl_prefs) == GTK_JUSTIFY_RIGHT));
 
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->text_line_spacing_spin),
-                                   gl_prefs->default_text_line_spacing);
+                                   gl_prefs_model_get_default_text_line_spacing (gl_prefs));
 
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->line_width_spin),
-                                   gl_prefs->default_line_width);
+                                   gl_prefs_model_get_default_line_width (gl_prefs));
  
         gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->line_color_combo),
-                gl_prefs->default_line_color);
+                                  gl_prefs_model_get_default_line_color (gl_prefs));
 
 
         gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->fill_color_combo),
-                                  gl_prefs->default_fill_color);
+                                  gl_prefs_model_get_default_fill_color (gl_prefs));
 
 
        dialog->priv->stop_signals = FALSE;
@@ -567,33 +568,29 @@ update_prefs_from_locale_page (glPrefsDialog *dialog)
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dialog->priv->units_points_radio)))
         {
-               gl_prefs->units = LGL_UNITS_POINT;
+               gl_prefs_model_set_units  (gl_prefs, LGL_UNITS_POINT);
        }
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dialog->priv->units_inches_radio)))
         {
-               gl_prefs->units = LGL_UNITS_INCH;
+               gl_prefs_model_set_units  (gl_prefs, LGL_UNITS_INCH);
        }
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dialog->priv->units_mm_radio)))
         {
-               gl_prefs->units = LGL_UNITS_MM;
+               gl_prefs_model_set_units  (gl_prefs, LGL_UNITS_MM);
        }
 
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dialog->priv->page_size_us_letter_radio)))
         {
-               g_free (gl_prefs->default_page_size);
-               gl_prefs->default_page_size = g_strdup (US_LETTER_ID);
+               gl_prefs_model_set_default_page_size  (gl_prefs, US_LETTER_ID);
        }
        if (gtk_toggle_button_get_active (
                    GTK_TOGGLE_BUTTON(dialog->priv->page_size_a4_radio)))
         {
-               g_free (gl_prefs->default_page_size);
-               gl_prefs->default_page_size = g_strdup (A4_ID);
+               gl_prefs_model_set_default_page_size  (gl_prefs, A4_ID);
        }
-
-       gl_prefs_model_save_settings (gl_prefs);
 }
 
 
@@ -608,66 +605,65 @@ update_prefs_from_object_page (glPrefsDialog *dialog)
 
        if (dialog->priv->stop_signals) return;
 
-        g_free (gl_prefs->default_font_family);
-        gl_prefs->default_font_family =
-               gl_font_combo_get_family (GL_FONT_COMBO (dialog->priv->text_family_combo));
-        gl_prefs->default_font_size =
-                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_size_spin));
+        gl_prefs_model_set_default_font_family (gl_prefs,
+                gl_font_combo_get_family (GL_FONT_COMBO (dialog->priv->text_family_combo)));
+        gl_prefs_model_set_default_font_size (gl_prefs,
+                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_size_spin)));
 
         if (gtk_toggle_button_get_active
             (GTK_TOGGLE_BUTTON (dialog->priv->text_bold_toggle)))
         {
-                gl_prefs->default_font_weight = PANGO_WEIGHT_BOLD;
+                gl_prefs_model_set_default_font_weight (gl_prefs, PANGO_WEIGHT_BOLD);
         }
         else
         {
-                gl_prefs->default_font_weight = PANGO_WEIGHT_NORMAL;
+                gl_prefs_model_set_default_font_weight (gl_prefs, PANGO_WEIGHT_NORMAL);
         }
 
-        gl_prefs->default_font_italic_flag =
+        gl_prefs_model_set_default_font_italic_flag (gl_prefs,
                 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
-                                              (dialog->priv->text_italic_toggle));
+                                              (dialog->priv->text_italic_toggle)));
 
         color = gl_color_combo_get_color (GL_COLOR_COMBO(dialog->priv->text_color_combo),
                                           &is_default);
         if (!is_default)
         {
-                gl_prefs->default_text_color = color;
+                gl_prefs_model_set_default_text_color (gl_prefs, color);
         }
 
         if (gtk_toggle_button_get_active
             (GTK_TOGGLE_BUTTON (dialog->priv->text_left_toggle)))
         {
-                gl_prefs->default_text_alignment = GTK_JUSTIFY_LEFT;
+                gl_prefs_model_set_default_text_alignment (gl_prefs, GTK_JUSTIFY_LEFT);
         }
         else if (gtk_toggle_button_get_active
                  (GTK_TOGGLE_BUTTON (dialog->priv->text_right_toggle)))
         {
-                gl_prefs->default_text_alignment = GTK_JUSTIFY_RIGHT;
+                gl_prefs_model_set_default_text_alignment (gl_prefs, GTK_JUSTIFY_RIGHT);
         }
         else if (gtk_toggle_button_get_active
                  (GTK_TOGGLE_BUTTON (dialog->priv->text_center_toggle)))
         {
-                gl_prefs->default_text_alignment = GTK_JUSTIFY_CENTER;
+                gl_prefs_model_set_default_text_alignment (gl_prefs, GTK_JUSTIFY_CENTER);
         }
         else
         {
                /* Should not happen. */
-                gl_prefs->default_text_alignment = GTK_JUSTIFY_LEFT;
+                gl_prefs_model_set_default_text_alignment (gl_prefs, GTK_JUSTIFY_LEFT);
         }
                                                                                 
 
-        gl_prefs->default_text_line_spacing =
-                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_line_spacing_spin));
+        gl_prefs_model_set_default_text_line_spacing (gl_prefs,
+                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_line_spacing_spin)));
 
-        gl_prefs->default_line_width =
-                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->line_width_spin));
+        gl_prefs_model_set_default_line_width (gl_prefs,
+                gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->line_width_spin)));
 
         color = gl_color_combo_get_color (GL_COLOR_COMBO(dialog->priv->line_color_combo),
                                           &is_default);
         if (!is_default)
         {
-                gl_prefs->default_line_color = color;
+                gl_prefs_model_set_default_line_color (gl_prefs, color);
         }
 
 
@@ -675,10 +671,8 @@ update_prefs_from_object_page (glPrefsDialog *dialog)
                                           &is_default);
         if (!is_default)
         {
-                gl_prefs->default_fill_color = color;
+                gl_prefs_model_set_default_fill_color (gl_prefs, color);
         }
-
-       gl_prefs_model_save_settings (gl_prefs);
 }
 
 
index 3aefa08af986eb7ecee13da206917147f5da045b..ed83c8b9d6e4e05ed6891afd95439ee37cc5d0dd 100644 (file)
@@ -25,6 +25,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <string.h>
+#include <gconf/gconf-client.h>
 
 #include <libglabels/libglabels.h>
 #include "marshal.h"
@@ -58,7 +59,6 @@
 #define PREF_DEFAULT_FILL_COLOR             "/default-fill-color"
 
 #define PREF_MAIN_TOOLBAR_VISIBLE           "/main-toolbar-visible"
-#define PREF_MAIN_TOOLBAR_BUTTONS_STYLE     "/main-toolbar-buttons-style"
 
 #define PREF_DRAWING_TOOLBAR_VISIBLE        "/drawing-toolbar-visible"
 
 
 
 /* Default values */
-#define DEFAULT_UNITS_STRING_US    units_to_string (LGL_UNITS_INCH)
-#define DEFAULT_PAGE_SIZE_US       "US-Letter"
+#define DEFAULT_UNITS_STRING_US     lgl_units_get_id (LGL_UNITS_INCH)
+#define DEFAULT_PAGE_SIZE_US        "US-Letter"
 
-#define DEFAULT_UNITS_STRING_METRIC units_to_string (LGL_UNITS_MM)
-#define DEFAULT_PAGE_SIZE_METRIC   "A4"
+#define DEFAULT_UNITS_STRING_METRIC lgl_units_get_id (LGL_UNITS_MM)
+#define DEFAULT_PAGE_SIZE_METRIC    "A4"
 
 #define DEFAULT_FONT_FAMILY        "Sans"
 #define DEFAULT_FONT_SIZE          14.0
 /* Private types.                                         */
 /*========================================================*/
 
+struct _glPrefsModelPrivate {
+
+       GConfClient *gconf_client;
+
+};
+
 enum {
        CHANGED,
        LAST_SIGNAL
@@ -135,9 +141,6 @@ static gdouble        get_float                    (GConfClient         *client,
                                                    const gchar         *key,
                                                    gdouble              def);
 
-static lglUnitsType   string_to_units              (const gchar         *string);
-static const gchar   *units_to_string              (lglUnitsType         units);
-
 
 /*****************************************************************************/
 /* Boilerplate object stuff.                                                 */
@@ -171,22 +174,24 @@ gl_prefs_model_class_init (glPrefsModelClass *class)
 
 
 static void
-gl_prefs_model_init (glPrefsModel *prefs_model)
+gl_prefs_model_init (glPrefsModel *this)
 {
        gl_debug (DEBUG_PREFS, "START");
 
-        prefs_model->gconf_client = gconf_client_get_default ();
+        this->priv = g_new0 (glPrefsModelPrivate, 1);
+
+        this->priv->gconf_client = gconf_client_get_default ();
 
-        g_return_if_fail (prefs_model->gconf_client != NULL);
+        g_return_if_fail (this->priv->gconf_client != NULL);
  
-        gconf_client_add_dir (prefs_model->gconf_client,
+        gconf_client_add_dir (this->priv->gconf_client,
                               BASE_KEY,
                               GCONF_CLIENT_PRELOAD_ONELEVEL,
                               NULL);
          
-        gconf_client_notify_add (prefs_model->gconf_client,
+        gconf_client_notify_add (this->priv->gconf_client,
                                  BASE_KEY,
-                                 (GConfClientNotifyFunc)notify_cb, prefs_model,
+                                 (GConfClientNotifyFunc)notify_cb, this,
                                  NULL, NULL);
 
        gl_debug (DEBUG_PREFS, "END");
@@ -196,15 +201,14 @@ gl_prefs_model_init (glPrefsModel *prefs_model)
 static void
 gl_prefs_model_finalize (GObject *object)
 {
-       glPrefsModel *prefs_model = GL_PREFS_MODEL (object);
+       glPrefsModel *this = GL_PREFS_MODEL (object);
 
        gl_debug (DEBUG_PREFS, "START");
 
        g_return_if_fail (object && GL_IS_PREFS_MODEL (object));
 
-       g_object_unref (G_OBJECT(prefs_model->gconf_client));
-       g_free (prefs_model->default_page_size);
-       g_free (prefs_model->default_font_family);
+       g_object_unref (G_OBJECT(this->priv->gconf_client));
+        g_free (this->priv);
 
        G_OBJECT_CLASS (gl_prefs_model_parent_class)->finalize (object);
 
@@ -218,302 +222,614 @@ gl_prefs_model_finalize (GObject *object)
 glPrefsModel *
 gl_prefs_model_new (void)
 {
-       glPrefsModel *prefs_model;
+       glPrefsModel *this;
 
        gl_debug (DEBUG_PREFS, "START");
 
-       prefs_model = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL));
+       this = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL));
 
        gl_debug (DEBUG_PREFS, "END");
 
-       return prefs_model;
+       return this;
 }
 
 
 /*****************************************************************************/
-/* Save all settings.                                                        */
+/* Set units.                                                                */
 /*****************************************************************************/
-void 
-gl_prefs_model_save_settings (glPrefsModel *prefs_model)
+void
+gl_prefs_model_set_units (glPrefsModel     *this,
+                          lglUnits          units)
 {
-       gl_debug (DEBUG_PREFS, "START");
-       
-       g_return_if_fail (prefs_model && GL_IS_PREFS_MODEL(prefs_model));
-       g_return_if_fail (prefs_model->gconf_client != NULL);
-
-       /* We are saving settings because presumably some of them have been changed. */
-       g_signal_emit (G_OBJECT(prefs_model), signals[CHANGED], 0);
-
-       /* Units */
-       gconf_client_set_string (prefs_model->gconf_client,
+       gconf_client_set_string (this->priv->gconf_client,
                                 BASE_KEY PREF_UNITS,
-                                units_to_string(prefs_model->units),
+                                lgl_units_get_id (units),
                                 NULL);
-        lgl_xml_set_default_units (prefs_model->units);
+}
 
-       /* Default page size */
-       gconf_client_set_string (prefs_model->gconf_client,
+
+/*****************************************************************************/
+/* Get units.                                                                */
+/*****************************************************************************/
+lglUnits
+gl_prefs_model_get_units (glPrefsModel     *this)
+{
+        const gchar  *pgsize;
+        const gchar  *default_units_string;
+        gchar        *string;
+        lglUnits      units;
+
+        /* Make educated guess about locale default. */
+        pgsize = gtk_paper_size_get_default ();
+        if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 )
+        {
+                default_units_string = DEFAULT_UNITS_STRING_US;
+        }
+        else
+        {
+                default_units_string = DEFAULT_UNITS_STRING_METRIC;
+        }
+
+       string = get_string (this->priv->gconf_client,
+                             BASE_KEY PREF_UNITS,
+                             default_units_string);
+       units = lgl_units_from_id (string);
+       g_free (string);
+
+        /* If invalid, make an educated guess from locale. */
+        if (units == LGL_UNITS_INVALID)
+        {
+                if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 )
+                {
+                        units = LGL_UNITS_INCH;
+                }
+                else
+                {
+                        units = LGL_UNITS_MM;
+                }
+        }
+
+        return units;
+}
+
+
+/*****************************************************************************/
+/* Set default page size.                                                    */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_page_size (glPrefsModel     *this,
+                                      const gchar      *page_size)
+{
+       gconf_client_set_string (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_PAGE_SIZE,
-                                prefs_model->default_page_size,
+                                page_size,
                                 NULL);
+}
+
 
+/*****************************************************************************/
+/* Get default page size.                                                    */
+/*****************************************************************************/
+gchar *
+gl_prefs_model_get_default_page_size (glPrefsModel     *this)
+{
+        const gchar *pgsize;
+        const gchar *default_page_size;
+        gchar       *page_size;
+       lglPaper    *paper;
 
-       /* Text properties */
-       gconf_client_set_string (prefs_model->gconf_client,
+        /* Make educated guess about locale default. */
+        pgsize = gtk_paper_size_get_default ();
+        if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 )
+        {
+                default_page_size = DEFAULT_PAGE_SIZE_US;
+        }
+        else
+        {
+                default_page_size = DEFAULT_PAGE_SIZE_METRIC;
+        }
+
+       page_size = get_string (this->priv->gconf_client,
+                                BASE_KEY PREF_DEFAULT_PAGE_SIZE,
+                                default_page_size);
+
+       /* Proof read the default page size -- it must be a valid id. */
+       /* (For compatability with older versions.) */
+       paper = lgl_db_lookup_paper_from_id (page_size);
+       if ( paper == NULL ) {
+                g_free (page_size);
+               page_size = g_strdup (DEFAULT_PAGE_SIZE_US);
+       } else {
+               lgl_paper_free (paper);
+       }
+
+        return page_size;
+}
+
+
+/*****************************************************************************/
+/* Set default font family.                                                  */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_font_family (glPrefsModel     *this,
+                                        const gchar      *family)
+{
+       gconf_client_set_string (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_FONT_FAMILY,
-                                prefs_model->default_font_family,
+                                family,
                                 NULL);
+}
 
-       gconf_client_set_float  (prefs_model->gconf_client,
-                                BASE_KEY PREF_DEFAULT_FONT_SIZE,
-                                prefs_model->default_font_size,
-                                NULL);
 
-       gconf_client_set_string (prefs_model->gconf_client,
+/*****************************************************************************/
+/* Get default font family.                                                  */
+/*****************************************************************************/
+gchar *
+gl_prefs_model_get_default_font_family (glPrefsModel     *this)
+{
+        gchar *family;
+
+        family = get_string (this->priv->gconf_client,
+                             BASE_KEY PREF_DEFAULT_FONT_FAMILY,
+                             DEFAULT_FONT_FAMILY);
+
+        return family;
+}
+
+
+/*****************************************************************************/
+/* Set default font size.                                                    */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_font_size (glPrefsModel     *this,
+                                      gdouble           size)
+{
+       gconf_client_set_float (this->priv->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FONT_SIZE,
+                                size,
+                                NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default font size.                                                    */
+/*****************************************************************************/
+gdouble
+gl_prefs_model_get_default_font_size (glPrefsModel     *this)
+{
+        gdouble size;
+
+       size = get_float (this->priv->gconf_client,
+                          BASE_KEY PREF_DEFAULT_FONT_SIZE,
+                          DEFAULT_FONT_SIZE);
+
+        return size;
+}
+
+
+/*****************************************************************************/
+/* Set default font weight.                                                  */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_font_weight (glPrefsModel     *this,
+                                        PangoWeight       weight)
+{
+       gconf_client_set_string (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
-                                gl_str_util_weight_to_string(prefs_model->default_font_weight),
+                                gl_str_util_weight_to_string(weight),
                                 NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default font weight.                                                  */
+/*****************************************************************************/
+PangoWeight
+gl_prefs_model_get_default_font_weight (glPrefsModel     *this)
+{
+        gchar       *string;
+        PangoWeight  weight;
+
+       string = get_string (this->priv->gconf_client,
+                             BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
+                             DEFAULT_FONT_WEIGHT_STRING);
+       weight = gl_str_util_string_to_weight (string);
+       g_free (string);
+
+        return weight;
+}
 
-       gconf_client_set_int    (prefs_model->gconf_client,
+
+/*****************************************************************************/
+/* Set default font italic flag.                                             */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_font_italic_flag (glPrefsModel     *this,
+                                             gboolean          italic_flag)
+{
+       gconf_client_set_bool (this->priv->gconf_client,
+                              BASE_KEY PREF_DEFAULT_FONT_ITALIC_FLAG,
+                              italic_flag,
+                              NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default font italic flag.                                             */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_default_font_italic_flag (glPrefsModel     *this)
+{
+        gboolean italic_flag;
+
+       italic_flag = get_bool (this->priv->gconf_client,
+                                BASE_KEY PREF_DEFAULT_FONT_ITALIC_FLAG,
+                                DEFAULT_FONT_ITALIC_FLAG);
+
+        return italic_flag;
+}
+
+
+/*****************************************************************************/
+/* Set default text color.                                                   */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_text_color (glPrefsModel     *this,
+                                       guint             color)
+{
+       gconf_client_set_int    (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_TEXT_COLOR,
-                                prefs_model->default_text_color,
+                                color,
                                 NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default text color.                                                   */
+/*****************************************************************************/
+guint
+gl_prefs_model_get_default_text_color (glPrefsModel     *this)
+{
+        guint color;
+
+       color = get_int (this->priv->gconf_client,
+                        BASE_KEY PREF_DEFAULT_TEXT_COLOR,
+                        DEFAULT_TEXT_COLOR);
 
-       gconf_client_set_string (prefs_model->gconf_client,
+        return color;
+}
+
+
+/*****************************************************************************/
+/* Set default text alignment.                                               */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_text_alignment (glPrefsModel     *this,
+                                           PangoAlignment    alignment)
+{
+       gconf_client_set_string (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
-                                gl_str_util_align_to_string(prefs_model->default_text_alignment),
+                                gl_str_util_align_to_string(alignment),
                                 NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default text alignment.                                               */
+/*****************************************************************************/
+PangoAlignment
+gl_prefs_model_get_default_text_alignment (glPrefsModel     *this)
+{
+        gchar          *string;
+        PangoAlignment  alignment;
+
+       string = get_string (this->priv->gconf_client,
+                             BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
+                             DEFAULT_TEXT_ALIGN_STRING);
+       alignment = gl_str_util_string_to_align (string);
+       g_free (string);
+
+        return alignment;
+}
+
 
-       gconf_client_set_float  (prefs_model->gconf_client,
+/*****************************************************************************/
+/* Set default text line spacing.                                            */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_text_line_spacing (glPrefsModel     *this,
+                                              gdouble           spacing)
+{
+       gconf_client_set_float  (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_TEXT_LINE_SPACING,
-                                prefs_model->default_text_line_spacing,
+                                spacing,
                                 NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default text line spacing.                                            */
+/*****************************************************************************/
+gdouble
+gl_prefs_model_get_default_text_line_spacing (glPrefsModel     *this)
+{
+        gdouble spacing;
+
+       spacing = get_float (this->priv->gconf_client,
+                             BASE_KEY PREF_DEFAULT_TEXT_LINE_SPACING,
+                             DEFAULT_TEXT_LINE_SPACING);
+
+        return spacing;
+}
 
-       /* Line properties */
-       gconf_client_set_float  (prefs_model->gconf_client,
+
+/*****************************************************************************/
+/* Set default line width.                                                   */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_line_width (glPrefsModel     *this,
+                                       gdouble           width)
+{
+       gconf_client_set_float  (this->priv->gconf_client,
                                 BASE_KEY PREF_DEFAULT_LINE_WIDTH,
-                                prefs_model->default_line_width,
+                                width,
                                 NULL);
+}
 
-       gconf_client_set_int    (prefs_model->gconf_client,
-                                BASE_KEY PREF_DEFAULT_LINE_COLOR,
-                                prefs_model->default_line_color,
-                                NULL);
 
+/*****************************************************************************/
+/* Get default line width.                                                   */
+/*****************************************************************************/
+gdouble
+gl_prefs_model_get_default_line_width (glPrefsModel     *this)
+{
+        gdouble width;
 
-       /* Fill properties */
-       gconf_client_set_int    (prefs_model->gconf_client,
-                                BASE_KEY PREF_DEFAULT_FILL_COLOR,
-                                prefs_model->default_fill_color,
-                                NULL);
+       width = get_float (this->priv->gconf_client,
+                          BASE_KEY PREF_DEFAULT_LINE_WIDTH,
+                          DEFAULT_LINE_WIDTH);
+
+        return width;
+}
+
+
+/*****************************************************************************/
+/* Set default line color.                                                   */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_line_color (glPrefsModel     *this,
+                                       guint             color)
+{
+       gconf_client_set_int (this->priv->gconf_client,
+                              BASE_KEY PREF_DEFAULT_LINE_COLOR,
+                              color,
+                              NULL);
+}
+
+
+/*****************************************************************************/
+/* Get default line color.                                                   */
+/*****************************************************************************/
+guint
+gl_prefs_model_get_default_line_color (glPrefsModel     *this)
+{
+        guint color;
+
+       color = get_int (this->priv->gconf_client,
+                        BASE_KEY PREF_DEFAULT_LINE_COLOR,
+                        DEFAULT_LINE_COLOR);
+
+        return color;
+}
+
+
+/*****************************************************************************/
+/* Set default fill color.                                                   */
+/*****************************************************************************/
+void
+gl_prefs_model_set_default_fill_color (glPrefsModel     *this,
+                                       guint             color)
+{
+       gconf_client_set_int (this->priv->gconf_client,
+                              BASE_KEY PREF_DEFAULT_FILL_COLOR,
+                              color,
+                              NULL);
+}
 
 
-       /* Main Toolbar */
-       gconf_client_set_bool (prefs_model->gconf_client,
+/*****************************************************************************/
+/* Get default fill color.                                                   */
+/*****************************************************************************/
+guint
+gl_prefs_model_get_default_fill_color (glPrefsModel     *this)
+{
+        guint color;
+
+       color = get_int (this->priv->gconf_client,
+                        BASE_KEY PREF_DEFAULT_FILL_COLOR,
+                        DEFAULT_FILL_COLOR);
+
+        return color;
+}
+
+
+/*****************************************************************************/
+/* Set main toolbar visible flag.                                            */
+/*****************************************************************************/
+void
+gl_prefs_model_set_main_toolbar_visible (glPrefsModel     *this,
+                                         gboolean          visible)
+{
+       gconf_client_set_bool (this->priv->gconf_client,
                               BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
-                              prefs_model->main_toolbar_visible,
+                              visible,
                               NULL);
+}
 
-       gconf_client_set_int (prefs_model->gconf_client,
-                             BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
-                             prefs_model->main_toolbar_buttons_style,
-                             NULL);
 
-       /* Drawing Toolbar */
-       gconf_client_set_bool (prefs_model->gconf_client,
-                              BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
-                              prefs_model->drawing_toolbar_visible,
-                              NULL);
+/*****************************************************************************/
+/* Get main toolbar visible flag.                                            */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_main_toolbar_visible (glPrefsModel     *this)
+{
+        gboolean visible;
 
-       /* Property Toolbar */
-       gconf_client_set_bool (prefs_model->gconf_client,
-                              BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE,
-                              prefs_model->property_toolbar_visible,
-                              NULL);
+       visible = get_bool (this->priv->gconf_client,
+                            BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
+                            TRUE);
 
-       /* View properties */
-       gconf_client_set_bool (prefs_model->gconf_client,
-                              BASE_KEY PREF_GRID_VISIBLE,
-                              prefs_model->grid_visible,
-                              NULL);
+        return visible;
+}
 
-       gconf_client_set_bool (prefs_model->gconf_client,
-                              BASE_KEY PREF_MARKUP_VISIBLE,
-                              prefs_model->markup_visible,
+
+/*****************************************************************************/
+/* Set drawing toolbar visible flag.                                         */
+/*****************************************************************************/
+void
+gl_prefs_model_set_drawing_toolbar_visible (glPrefsModel     *this,
+                                            gboolean          visible)
+{
+       gconf_client_set_bool (this->priv->gconf_client,
+                              BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
+                              visible,
                               NULL);
+}
 
-       /* Recent files */
-       gconf_client_set_int (prefs_model->gconf_client,
-                             BASE_KEY PREF_MAX_RECENTS,
-                             prefs_model->max_recents,
-                             NULL);
 
+/*****************************************************************************/
+/* Get drawing toolbar visible flag.                                         */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_drawing_toolbar_visible (glPrefsModel     *this)
+{
+        gboolean visible;
 
-       gconf_client_suggest_sync (prefs_model->gconf_client, NULL);
-       
-       gl_debug (DEBUG_PREFS, "END");
+       visible = get_bool (this->priv->gconf_client,
+                            BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
+                            TRUE);
+
+        return visible;
 }
 
 
 /*****************************************************************************/
-/* Load all settings.                                                        */
+/* Set property toolbar visible flag.                                        */
 /*****************************************************************************/
 void
-gl_prefs_model_load_settings (glPrefsModel *prefs_model)
+gl_prefs_model_set_property_toolbar_visible (glPrefsModel     *this,
+                                             gboolean          visible)
 {
-        const gchar *pgsize, *default_units_string, *default_page_size;
-       gchar    *string;
-       lglPaper *paper;
-        GSList   *p, *p_next;
-
-       gl_debug (DEBUG_PREFS, "START");
-       
-       g_return_if_fail (prefs_model && GL_IS_PREFS_MODEL(prefs_model));
-       g_return_if_fail (prefs_model->gconf_client != NULL);
+       gconf_client_set_bool (this->priv->gconf_client,
+                              BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE,
+                              visible,
+                              NULL);
+}
 
-        /* Make educated guess about locale defaults. */
-        pgsize = gtk_paper_size_get_default ();
-        if ( strcmp (pgsize,GTK_PAPER_NAME_LETTER) == 0 )
-        {
-                default_units_string = DEFAULT_UNITS_STRING_US;
-                default_page_size    = DEFAULT_PAGE_SIZE_US;
-        }
-        else
-        {
-                default_units_string = DEFAULT_UNITS_STRING_METRIC;
-                default_page_size    = DEFAULT_PAGE_SIZE_METRIC;
-        }
 
-       /* Units */
-       string =
-               get_string (prefs_model->gconf_client,
-                           BASE_KEY PREF_UNITS,
-                           default_units_string);
-       prefs_model->units = string_to_units( string );
-       g_free( string );
-        lgl_xml_set_default_units (prefs_model->units);
-
-
-       /* Page size */
-        g_free (prefs_model->default_page_size);
-       prefs_model->default_page_size =
-               get_string (prefs_model->gconf_client,
-                           BASE_KEY PREF_DEFAULT_PAGE_SIZE,
-                           default_page_size);
-
-       /* Text properties */
-        g_free (prefs_model->default_font_family);
-       prefs_model->default_font_family =
-               get_string (prefs_model->gconf_client,
-                           BASE_KEY PREF_DEFAULT_FONT_FAMILY,
-                           DEFAULT_FONT_FAMILY);
-
-       prefs_model->default_font_size =
-               get_float (prefs_model->gconf_client,
-                          BASE_KEY PREF_DEFAULT_FONT_SIZE,
-                          DEFAULT_FONT_SIZE);
-
-       string =
-               get_string (prefs_model->gconf_client,
-                           BASE_KEY PREF_DEFAULT_FONT_WEIGHT,
-                           DEFAULT_FONT_WEIGHT_STRING);
-       prefs_model->default_font_weight = gl_str_util_string_to_weight( string );
-       g_free( string );
-
-       prefs_model->default_text_color =
-               get_int (prefs_model->gconf_client,
-                        BASE_KEY PREF_DEFAULT_TEXT_COLOR,
-                        DEFAULT_TEXT_COLOR);
+/*****************************************************************************/
+/* Get property toolbar visible flag.                                        */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_property_toolbar_visible (glPrefsModel     *this)
+{
+        gboolean visible;
 
-       string =
-               get_string (prefs_model->gconf_client,
-                           BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT,
-                           DEFAULT_TEXT_ALIGN_STRING);
-       prefs_model->default_text_alignment = gl_str_util_string_to_align( string );
-       g_free( string );
+       visible = get_bool (this->priv->gconf_client,
+                            BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE,
+                            TRUE);
 
-       prefs_model->default_text_line_spacing =
-               get_float (prefs_model->gconf_client,
-                          BASE_KEY PREF_DEFAULT_TEXT_LINE_SPACING,
-                          DEFAULT_TEXT_LINE_SPACING);
+        return visible;
+}
 
-       gl_debug (DEBUG_PREFS, "text_line_spacing = %f", prefs_model->default_text_line_spacing);
 
-       /* Line properties */
-       prefs_model->default_line_width =
-               get_float (prefs_model->gconf_client,
-                          BASE_KEY PREF_DEFAULT_LINE_WIDTH,
-                          DEFAULT_LINE_WIDTH);
-       prefs_model->default_line_color =
-               get_int (prefs_model->gconf_client,
-                        BASE_KEY PREF_DEFAULT_LINE_COLOR,
-                        DEFAULT_LINE_COLOR);
+/*****************************************************************************/
+/* Set grid visible flag.                                                    */
+/*****************************************************************************/
+void
+gl_prefs_model_set_grid_visible (glPrefsModel     *this,
+                                 gboolean          visible)
+{
+       gconf_client_set_bool (this->priv->gconf_client,
+                              BASE_KEY PREF_GRID_VISIBLE,
+                              visible,
+                              NULL);
+}
 
-       /* Fill properties */
-       prefs_model->default_fill_color =
-               get_int (prefs_model->gconf_client,
-                        BASE_KEY PREF_DEFAULT_FILL_COLOR,
-                        DEFAULT_FILL_COLOR);
 
+/*****************************************************************************/
+/* Get grid visible flag.                                                    */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_grid_visible (glPrefsModel     *this)
+{
+        gboolean visible;
 
-       /* User Inferface/Main Toolbar */
-       prefs_model->main_toolbar_visible =
-               get_bool (prefs_model->gconf_client,
-                         BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE,
-                         TRUE);
+       visible = get_bool (this->priv->gconf_client,
+                            BASE_KEY PREF_GRID_VISIBLE,
+                            TRUE);
 
-       prefs_model->main_toolbar_buttons_style =
-               get_int (prefs_model->gconf_client,
-                        BASE_KEY PREF_MAIN_TOOLBAR_BUTTONS_STYLE,
-                        GL_TOOLBAR_SYSTEM);
+        return visible;
+}
 
-       /* User Inferface/Drawing Toolbar */
-       prefs_model->drawing_toolbar_visible =
-               get_bool (prefs_model->gconf_client,
-                         BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE,
-                         TRUE);
 
-       /* User Inferface/Property Toolbar */
-       prefs_model->property_toolbar_visible =
-               get_bool (prefs_model->gconf_client,
-                         BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE,
-                         TRUE);
+/*****************************************************************************/
+/* Set markup visible flag.                                                  */
+/*****************************************************************************/
+void
+gl_prefs_model_set_markup_visible (glPrefsModel     *this,
+                                   gboolean          visible)
+{
+       gconf_client_set_bool (this->priv->gconf_client,
+                              BASE_KEY PREF_MARKUP_VISIBLE,
+                              visible,
+                              NULL);
+}
 
-       /* View properties */
-       prefs_model->grid_visible =
-               get_bool (prefs_model->gconf_client,
-                         BASE_KEY PREF_GRID_VISIBLE,
-                         TRUE);
 
-       prefs_model->markup_visible =
-               get_bool (prefs_model->gconf_client,
-                         BASE_KEY PREF_MARKUP_VISIBLE,
-                         TRUE);
+/*****************************************************************************/
+/* Get markup visible flag.                                                  */
+/*****************************************************************************/
+gboolean
+gl_prefs_model_get_markup_visible (glPrefsModel     *this)
+{
+        gboolean visible;
 
-       /* Recent files */
-       prefs_model->max_recents =
-               get_int (prefs_model->gconf_client,
-                        BASE_KEY PREF_MAX_RECENTS,
-                        -1);
+       visible = get_bool (this->priv->gconf_client,
+                            BASE_KEY PREF_MARKUP_VISIBLE,
+                            TRUE);
 
+        return visible;
+}
 
-       /* Proof read the default page size -- it must be a valid id. */
-       /* (For compatability with older versions.) */
-       paper = lgl_db_lookup_paper_from_id (prefs_model->default_page_size);
-       if ( paper == NULL ) {
-               prefs_model->default_page_size = g_strdup (DEFAULT_PAGE_SIZE_US);
-       } else {
-               lgl_paper_free (paper);
-               paper = NULL;
-       }
 
+/*****************************************************************************/
+/* Set max recents.                                                          */
+/*****************************************************************************/
+void
+gl_prefs_model_set_max_recents (glPrefsModel     *this,
+                                gint              max_recents)
+{
+       gconf_client_set_int (this->priv->gconf_client,
+                             BASE_KEY PREF_MAX_RECENTS,
+                             max_recents,
+                             NULL);
+}
 
-       gl_debug (DEBUG_PREFS, "max_recents = %d", prefs_model->max_recents);
 
+/*****************************************************************************/
+/* Get max recents.                                                          */
+/*****************************************************************************/
+gint
+gl_prefs_model_get_max_recents (glPrefsModel     *this)
+{
+        gint max_recents;
 
-       g_signal_emit (G_OBJECT(prefs_model), signals[CHANGED], 0);
+       max_recents = get_int (this->priv->gconf_client,
+                               BASE_KEY PREF_MAX_RECENTS,
+                               -1);
 
-       gl_debug (DEBUG_PREFS, "END");
+        return max_recents;
 }
 
 
@@ -524,11 +840,11 @@ static void
 notify_cb (GConfClient  *client,
           guint         cnxn_id,
           GConfEntry   *entry,
-          glPrefsModel *prefs_model)
+          glPrefsModel *this)
 {
        gl_debug (DEBUG_PREFS, "Key was changed: %s", entry->key);
 
-       gl_prefs_model_load_settings (prefs_model);
+       g_signal_emit (G_OBJECT(this), signals[CHANGED], 0);
 }
 
 
@@ -645,48 +961,6 @@ get_float (GConfClient *client,
 }
 
 
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  Utilities to deal with units.                                   */
-/*---------------------------------------------------------------------------*/
-static lglUnitsType
-string_to_units (const gchar *string)
-{
-       lglUnitsType units;
-
-       if (g_ascii_strcasecmp (string, "Points") == 0) {
-               units = LGL_UNITS_POINT;
-       } else if (g_ascii_strcasecmp (string, "Inches") == 0) {
-               units = LGL_UNITS_INCH;
-       } else if (g_ascii_strcasecmp (string, "Millimeters") == 0) {
-               units = LGL_UNITS_MM;
-       } else {
-               units = LGL_UNITS_INCH;
-       }
-
-       return units;
-}
-
-
-static const
-gchar *units_to_string (lglUnitsType units)
-{
-       switch (units) {
-       case LGL_UNITS_POINT:
-               return "Points";
-               break;
-       case LGL_UNITS_INCH:
-               return "Inches";
-               break;
-       case LGL_UNITS_MM:
-               return "Millimeters";
-               break;
-       default:
-               return "Inches";
-               break;
-       }
-}
-
-
 
 
 
index e01b0481f252cf5ced5de3f5911ec7b895179d6b..72efa845908aa6ad54c45848fa202f90f70b4dbd 100644 (file)
 #define __PREFS_MODEL_H__
 
 #include <glib-object.h>
-#include <gconf/gconf-client.h>
 #include <pango/pango.h>
 #include <libglabels/libglabels.h>
 
 G_BEGIN_DECLS
 
-typedef enum {
-       GL_TOOLBAR_SYSTEM = 0,
-       GL_TOOLBAR_ICONS,
-       GL_TOOLBAR_ICONS_AND_TEXT
-} glToolbarSetting;
 
 #define GL_TYPE_PREFS_MODEL              (gl_prefs_model_get_type ())
 #define GL_PREFS_MODEL(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_PREFS_MODEL, glPrefsModel))
@@ -44,70 +38,135 @@ typedef enum {
 
 typedef struct _glPrefsModel          glPrefsModel;
 typedef struct _glPrefsModelClass     glPrefsModelClass;
-
 typedef struct _glPrefsModelPrivate   glPrefsModelPrivate;
 
 
 struct _glPrefsModel {
-       GObject          *object;
+       GObject              parent;
 
-       GConfClient      *gconf_client;
+        glPrefsModelPrivate *priv;
+};
 
-       /* Units */
-       lglUnitsType      units;
+struct _glPrefsModelClass {
+       GObjectClass         parent_class;
 
-       /* Page size */
-       gchar            *default_page_size;
+        void (*changed) (glPrefsModel *prefs_model,
+                         gpointer      user_data);
+};
 
-       /* Text properties */
-       gchar            *default_font_family;
-       gdouble           default_font_size;
-       PangoWeight       default_font_weight;
-       gboolean          default_font_italic_flag;
-       guint             default_text_color;
-       PangoAlignment    default_text_alignment;
-       gdouble           default_text_line_spacing;
-       
-       /* Line properties */
-       gdouble           default_line_width;
-       guint             default_line_color;
-       
-       /* Fill properties */
-       guint             default_fill_color;
 
-       /* User Interface/Main Toolbar */
-       gboolean          main_toolbar_visible;
-       glToolbarSetting  main_toolbar_buttons_style; 
+GType          gl_prefs_model_get_type                      (void) G_GNUC_CONST;
 
-       /* User Interface/Drawing Toolbar */
-       gboolean          drawing_toolbar_visible;
+glPrefsModel  *gl_prefs_model_new                           (void);
 
-       /* User Interface/Property Toolbar */
-       gboolean          property_toolbar_visible;
 
-       /* View properties */
-       gboolean          grid_visible;
-       gboolean          markup_visible;
+void           gl_prefs_model_set_units                     (glPrefsModel     *this,
+                                                             lglUnits          units);
 
-       /* Recent files */
-       gint              max_recents;
+lglUnits       gl_prefs_model_get_units                     (glPrefsModel     *this);
 
-};
 
-struct _glPrefsModelClass {
-       GObjectClass     parent_class;
+void           gl_prefs_model_set_default_page_size         (glPrefsModel     *this,
+                                                             const gchar      *page_size);
 
-        void (*changed)          (glPrefsModel *prefs_model, gpointer user_data);
-};
+gchar         *gl_prefs_model_get_default_page_size         (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_font_family       (glPrefsModel     *this,
+                                                             const gchar      *family);
+
+gchar         *gl_prefs_model_get_default_font_family       (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_font_size         (glPrefsModel     *this,
+                                                             gdouble           size);
+
+gdouble        gl_prefs_model_get_default_font_size         (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_font_weight       (glPrefsModel     *this,
+                                                             PangoWeight       weight);
+
+PangoWeight    gl_prefs_model_get_default_font_weight       (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_font_italic_flag  (glPrefsModel     *this,
+                                                             gboolean          italic_flag);
+
+gboolean       gl_prefs_model_get_default_font_italic_flag  (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_text_color        (glPrefsModel     *this,
+                                                             guint             color);
+
+guint          gl_prefs_model_get_default_text_color        (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_text_alignment    (glPrefsModel     *this,
+                                                             PangoAlignment    alignment);
+
+PangoAlignment gl_prefs_model_get_default_text_alignment    (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_text_line_spacing (glPrefsModel     *this,
+                                                             gdouble           spacing);
+
+gdouble        gl_prefs_model_get_default_text_line_spacing (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_line_width        (glPrefsModel     *this,
+                                                             gdouble           width);
+
+gdouble        gl_prefs_model_get_default_line_width        (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_line_color        (glPrefsModel     *this,
+                                                             guint             color);
+
+guint          gl_prefs_model_get_default_line_color        (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_default_fill_color        (glPrefsModel     *this,
+                                                             guint             color);
+
+guint          gl_prefs_model_get_default_fill_color        (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_main_toolbar_visible      (glPrefsModel     *this,
+                                                             gboolean          visible);
+
+gboolean       gl_prefs_model_get_main_toolbar_visible      (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_drawing_toolbar_visible   (glPrefsModel     *this,
+                                                             gboolean          visible);
+
+gboolean       gl_prefs_model_get_drawing_toolbar_visible   (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_property_toolbar_visible  (glPrefsModel     *this,
+                                                             gboolean          visible);
+
+gboolean       gl_prefs_model_get_property_toolbar_visible  (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_grid_visible              (glPrefsModel     *this,
+                                                             gboolean          visible);
+
+gboolean       gl_prefs_model_get_grid_visible              (glPrefsModel     *this);
+
+
+void           gl_prefs_model_set_markup_visible            (glPrefsModel     *this,
+                                                             gboolean          visible);
 
+gboolean       gl_prefs_model_get_markup_visible            (glPrefsModel     *this);
 
-GType         gl_prefs_model_get_type            (void) G_GNUC_CONST;
 
-glPrefsModel *gl_prefs_model_new                 (void);
+void           gl_prefs_model_set_max_recents               (glPrefsModel     *this,
+                                                             gint              max_recents);
 
-void          gl_prefs_model_save_settings       (glPrefsModel   *prefs_model);
+gint           gl_prefs_model_get_max_recents               (glPrefsModel     *this);
 
-void          gl_prefs_model_load_settings       (glPrefsModel   *prefs_model);
 
 G_END_DECLS
 
index 198e852294e290c0c0330c2ab9f5e3165263008f..f83e0bacdc08d9f5f9b9733eb4bdf110854ce528 100644 (file)
@@ -49,7 +49,6 @@ glPrefsModel      *gl_prefs     = NULL;
 /*========================================================*/
 
 
-\f
 /*****************************************************************************/
 /* Initialize preferences module.                                            */
 /*****************************************************************************/
@@ -60,110 +59,9 @@ gl_prefs_init (void)
 
        gl_prefs = gl_prefs_model_new ();
 
-       gl_prefs_model_load_settings (gl_prefs);
-
        gl_debug (DEBUG_PREFS, "END");
 }
 
-\f
-/****************************************************************************/
-/* Get string representing desired units.                                   */
-/****************************************************************************/
-const gchar *
-gl_prefs_get_page_size (void)
-{
-       return (gl_prefs->default_page_size);
-}
-
-/****************************************************************************/
-/* Get desired units.                                                       */
-/****************************************************************************/
-lglUnitsType
-gl_prefs_get_units (void)
-{
-       return gl_prefs->units;
-}
-
-/****************************************************************************/
-/* Get desired units per point.                                             */
-/****************************************************************************/
-gdouble
-gl_prefs_get_units_per_point (void)
-{
-
-       switch (gl_prefs->units) {
-       case LGL_UNITS_POINT:
-               return 1.0;     /* points */
-       case LGL_UNITS_INCH:
-               return 1.0 / 72.0;      /* inches */
-       case LGL_UNITS_MM:
-               return 0.35277778;      /* mm */
-       default:
-               g_message ("Illegal units");    /* Should not happen */
-               return 1.0;
-       }
-}
-
-/****************************************************************************/
-/* Get precision for desired units.                                         */
-/****************************************************************************/
-gint
-gl_prefs_get_units_precision (void)
-{
-
-       switch (gl_prefs->units) {
-       case LGL_UNITS_POINT:
-               return 1;       /* points */
-       case LGL_UNITS_INCH:
-               return 3;       /* inches */
-       case LGL_UNITS_MM:
-               return 1;       /* mm */
-       default:
-               g_message ("Illegal units");    /* Should not happen */
-               return 1.0;
-       }
-}
-
-/****************************************************************************/
-/* Get step size for desired units.                                         */
-/****************************************************************************/
-gdouble
-gl_prefs_get_units_step_size (void)
-{
-
-       switch (gl_prefs->units) {
-       case LGL_UNITS_POINT:
-               return 0.1;     /* points */
-       case LGL_UNITS_INCH:
-               return 0.001;   /* inches */
-       case LGL_UNITS_MM:
-               return 0.1;     /* mm */
-       default:
-               g_message ("Illegal units");    /* Should not happen */
-               return 1.0;
-       }
-}
-
-/****************************************************************************/
-/* Get string representing desired units.                                   */
-/****************************************************************************/
-const gchar *
-gl_prefs_get_units_string (void)
-{
-
-       switch (gl_prefs->units) {
-       case LGL_UNITS_POINT:
-               return _("points");
-       case LGL_UNITS_INCH:
-               return _("inches");
-       case LGL_UNITS_MM:
-               return _("mm");
-       default:
-               g_message ("Illegal units");    /* Should not happen */
-               return _("points");
-       }
-}
-
 
 
 /*
index 6e389ff22d120d09e2dfb867fe5e862eba6b390e..7cabea1e4cc1144441313ab6e9705d9f66aa82ec 100644 (file)
 G_BEGIN_DECLS
 
 
-
 extern glPrefsModel *gl_prefs;
 
 
-
 void          gl_prefs_init                (void);
 
-const gchar  *gl_prefs_get_page_size       (void);
-
-lglUnitsType  gl_prefs_get_units           (void);
-
-const gchar  *gl_prefs_get_units_string    (void);
-
-gdouble       gl_prefs_get_units_per_point (void);
-
-gdouble       gl_prefs_get_units_step_size (void);
-
-gint          gl_prefs_get_units_precision (void);
-
 
 G_END_DECLS
 
index 38244ab1e05d255950458b65fec8d39f6f8559c2..295c6661b529af1eae9e4de92fa50b62dcc991d8 100644 (file)
@@ -139,7 +139,8 @@ gl_recent_create_menu (void)
                 gtk_recent_chooser_menu_new_for_manager (model);
         gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), FALSE);
         gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu), TRUE);
-        gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent_menu), gl_prefs->max_recents);
+        gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent_menu),
+                                      gl_prefs_model_get_max_recents (gl_prefs));
         gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu), GTK_RECENT_SORT_MRU);
         gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu), TRUE);
 
index d5d6453fad9a10cffca74ee9021addbf7556455e..d668265b89e01e01249567dc6fb9454f37696f63 100644 (file)
@@ -34,6 +34,7 @@
 #include "print-op-dialog.h"
 #include "combo-util.h"
 #include "builder-util.h"
+#include "units-util.h"
 
 #include "debug.h"
 
@@ -385,6 +386,7 @@ gl_template_designer_new (GtkWindow *parent)
 static void
 gl_template_designer_construct (glTemplateDesigner *dialog)
 {
+        lglUnits    units;
        GdkPixbuf  *logo;
 
        gl_debug (DEBUG_TEMPLATE, "START");
@@ -393,10 +395,11 @@ gl_template_designer_construct (glTemplateDesigner *dialog)
        g_return_if_fail (dialog->priv != NULL);
 
        /* Initialize units stuff from prefs */
-       dialog->priv->units_string    = gl_prefs_get_units_string ();
-        dialog->priv->units_per_point = gl_prefs_get_units_per_point ();
-        dialog->priv->climb_rate      = gl_prefs_get_units_step_size ();
-        dialog->priv->digits          = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       dialog->priv->units_string    = lgl_units_get_name (units);
+        dialog->priv->units_per_point = lgl_units_get_units_per_point (units);
+        dialog->priv->climb_rate      = gl_units_util_get_step_size (units);
+        dialog->priv->digits          = gl_units_util_get_precision (units);
 
        gtk_window_set_title (GTK_WINDOW(dialog), _("gLabels Template Designer"));
 
@@ -552,7 +555,7 @@ construct_pg_size_page (glTemplateDesigner      *dialog,
        page_sizes = lgl_db_get_paper_name_list ();
        gl_combo_util_set_strings (GTK_COMBO_BOX (dialog->priv->pg_size_combo), page_sizes);
        lgl_db_free_paper_name_list (page_sizes);
-       default_page_size_id = gl_prefs_get_page_size ();
+       default_page_size_id = gl_prefs_model_get_default_page_size (gl_prefs);
        default_page_size_name = lgl_db_lookup_paper_name_from_id (default_page_size_id);
        gl_combo_util_set_active_text (GTK_COMBO_BOX (dialog->priv->pg_size_combo), default_page_size_name);
        g_free (default_page_size_name);
@@ -1116,8 +1119,12 @@ cancel_cb (glTemplateDesigner *dialog)
 static void
 apply_cb (glTemplateDesigner *dialog)
 {
+        lglUnits     units;
        lglTemplate *template;
         gchar       *name;
+
+        units = gl_prefs_model_get_units (gl_prefs);
+        lgl_xml_set_default_units (units);
        
        template = build_template (dialog);
        lgl_db_register_template (template);
index a8e2bbd3b2f8ab5ff588e5603e390ed11650db35..73da051edfa67abed91d1436d8ede7eb79e71b9c 100644 (file)
@@ -409,13 +409,12 @@ gl_ui_cmd_view_property_bar_toggle (GtkToggleAction *action,
 
         state =  gtk_toggle_action_get_active (action);
 
-        gl_prefs->property_toolbar_visible = state;
+        gl_prefs_model_set_property_toolbar_visible (gl_prefs, state);
         if (state) {
                 gtk_widget_show (GTK_WIDGET (window->property_bar));
         } else {
                 gtk_widget_hide (GTK_WIDGET (window->property_bar));
         }
-        gl_prefs_model_save_settings (gl_prefs);
 
         gl_debug (DEBUG_COMMANDS, "END");
 }
@@ -446,8 +445,7 @@ gl_ui_cmd_view_grid_toggle (GtkToggleAction *action,
                 }
         }
 
-        gl_prefs->grid_visible = state;
-        gl_prefs_model_save_settings (gl_prefs);
+        gl_prefs_model_set_grid_visible (gl_prefs, state);
 
         gl_debug (DEBUG_COMMANDS, "END");
 }
@@ -478,8 +476,7 @@ gl_ui_cmd_view_markup_toggle (GtkToggleAction *action,
                 }
         }
 
-        gl_prefs->markup_visible = state;
-        gl_prefs_model_save_settings (gl_prefs);
+        gl_prefs_model_set_markup_visible (gl_prefs, state);
 
         gl_debug (DEBUG_COMMANDS, "END");
 }
index 30ae6cbf08615228847934aba8702ab2690d8d96..7df4543648e852a8360859c391127255d9687e6f 100644 (file)
@@ -268,7 +268,8 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
 
        gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
 
-        this->priv->font_family_combo = gl_font_combo_new (gl_prefs->default_font_family);
+        this->priv->font_family_combo =
+                gl_font_combo_new (gl_prefs_model_get_default_font_family (gl_prefs));
         gtk_container_add (GTK_CONTAINER (this->priv->font_family_eventbox),
                            this->priv->font_family_combo);
 
@@ -277,7 +278,7 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
                 gl_color_combo_button_new (pixbuf,
                                            _("Default"),
                                            GL_COLOR_TEXT_DEFAULT,
-                                           gl_prefs->default_text_color);
+                                           gl_prefs_model_get_default_text_color (gl_prefs));
         gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
                                           GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
@@ -289,7 +290,7 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
                 gl_color_combo_button_new (pixbuf,
                                            _("No Fill"),
                                            GL_COLOR_NO_FILL,
-                                           gl_prefs->default_fill_color);
+                                           gl_prefs_model_get_default_fill_color (gl_prefs));
         gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
                                           GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
@@ -301,7 +302,7 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
                 gl_color_combo_button_new (pixbuf,
                                            _("No Line"),
                                            GL_COLOR_NO_LINE,
-                                           gl_prefs->default_line_color);
+                                           gl_prefs_model_get_default_line_color (gl_prefs));
        gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
                                           GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
@@ -319,7 +320,7 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
 
        /* Font size entry widget */
        gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
-                                  gl_prefs->default_font_size);
+                                  gl_prefs_model_get_default_font_size (gl_prefs));
 
        g_signal_connect (G_OBJECT (this->priv->font_size_spin),
                          "changed", G_CALLBACK (font_size_changed_cb), this);
@@ -327,46 +328,46 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
 
        /* Bold and Italic toggles */
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
-                                          (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
+                                          (gl_prefs_model_get_default_font_weight (gl_prefs) == PANGO_WEIGHT_BOLD));
        g_signal_connect (G_OBJECT (this->priv->font_bold_toggle),
                          "toggled", G_CALLBACK (font_bold_toggled_cb), this);
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
-                                          gl_prefs->default_font_italic_flag);
+                                          gl_prefs_model_get_default_font_italic_flag (gl_prefs));
        g_signal_connect (G_OBJECT (this->priv->font_italic_toggle),
                          "toggled", G_CALLBACK (font_italic_toggled_cb), this);
 
 
        /* Text alignment radio group */
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
-                                          (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
+                                          (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_LEFT));
        g_signal_connect (G_OBJECT (this->priv->text_align_left_radio),
                          "toggled", G_CALLBACK (text_align_toggled_cb), this);
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
-                                          (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
+                                          (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_CENTER));
        g_signal_connect (G_OBJECT (this->priv->text_align_center_radio),
                          "toggled", G_CALLBACK (text_align_toggled_cb), this);
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
-                                          (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
+                                          (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_RIGHT));
        g_signal_connect (G_OBJECT (this->priv->text_align_right_radio),
                          "toggled", G_CALLBACK (text_align_toggled_cb), this);
 
        /* Text color widget */
        gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
-                                         gl_prefs->default_text_color);
+                                         gl_prefs_model_get_default_text_color (gl_prefs));
        g_signal_connect (G_OBJECT (this->priv->text_color_button),
                          "color_changed",
                          G_CALLBACK (text_color_changed_cb), this);
 
        /* Fill color widget */
        gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
-                                         gl_prefs->default_fill_color);
+                                         gl_prefs_model_get_default_fill_color (gl_prefs));
        g_signal_connect (G_OBJECT (this->priv->fill_color_button),
                          "color_changed",
                          G_CALLBACK (fill_color_changed_cb), this);
 
        /* Line color widget */
        gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
-                                         gl_prefs->default_line_color);
+                                         gl_prefs_model_get_default_line_color (gl_prefs));
        g_signal_connect (G_OBJECT (this->priv->line_color_button),
                          "color_changed",
                          G_CALLBACK (line_color_changed_cb), this);
@@ -918,11 +919,11 @@ text_color_changed_cb (glColorComboButton   *cc,
 
        if (is_default)
         {
-               text_color_node->color = gl_prefs->default_text_color;
+               text_color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
                gl_view_set_selection_text_color (this->priv->view,
                                                  text_color_node);
                gl_view_set_default_text_color   (this->priv->view,
-                                                 gl_prefs->default_text_color);
+                                                 text_color_node->color);
        }
         else
         {
index 62b67d4ecc56a87d56b837be2da05e7f1172e8c6..5449d28e505f5f2dffb30405680e436f4f9c4bec 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -946,16 +946,14 @@ view_ui_item_toggled_cb (GtkToggleAction *action,
 
        if (strcmp (name, "ViewMainToolBar") == 0)
        {
-               gl_prefs->main_toolbar_visible = state;
+                gl_prefs_model_set_main_toolbar_visible (gl_prefs, state);
                set_app_main_toolbar_style (ui);
-               gl_prefs_model_save_settings (gl_prefs);
        }
 
        if (strcmp (name, "ViewDrawingToolBar") == 0)
        {
-               gl_prefs->drawing_toolbar_visible = state;
+               gl_prefs_model_set_drawing_toolbar_visible (gl_prefs, state);
                set_app_drawing_toolbar_style (ui);
-               gl_prefs_model_save_settings (gl_prefs);
        }
 
        gl_debug (DEBUG_UI, "");
@@ -976,11 +974,11 @@ set_app_main_toolbar_style (GtkUIManager *ui)
                        
        /* Updated view menu */
        gl_ui_util_set_verb_state (ui, "/ui/ViewMenu/ViewMainToolBar",
-                                  gl_prefs->main_toolbar_visible);
+                                  gl_prefs_model_get_main_toolbar_visible (gl_prefs));
 
        toolbar = gtk_ui_manager_get_widget (ui, "/MainToolBar");
 
-       if (gl_prefs->main_toolbar_visible) {
+       if (gl_prefs_model_get_main_toolbar_visible (gl_prefs)) {
                gtk_widget_show_all (toolbar);
        } else {
                gtk_widget_hide (toolbar);
@@ -1004,13 +1002,13 @@ set_app_drawing_toolbar_style (GtkUIManager *ui)
                        
        /* Updated view menu */
        gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewDrawingToolBar",
-                                  gl_prefs->drawing_toolbar_visible);
+                                  gl_prefs_model_get_drawing_toolbar_visible (gl_prefs));
 
        toolbar = gtk_ui_manager_get_widget (ui, "/DrawingToolBar");
 
        gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
 
-       if (gl_prefs->drawing_toolbar_visible) {
+       if (gl_prefs_model_get_drawing_toolbar_visible (gl_prefs)) {
                gtk_widget_show_all (toolbar);
        } else {
                gtk_widget_hide (toolbar);
@@ -1031,10 +1029,10 @@ set_view_style (GtkUIManager *ui)
        g_return_if_fail (ui && GTK_IS_UI_MANAGER(ui));
                        
        gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewGrid",
-                                  gl_prefs->grid_visible);
+                                  gl_prefs_model_get_grid_visible (gl_prefs));
 
        gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewMarkup",
-                                  gl_prefs->markup_visible);
+                                  gl_prefs_model_get_markup_visible (gl_prefs));
 
        gl_debug (DEBUG_UI, "END");
 }
diff --git a/src/units-util.c b/src/units-util.c
new file mode 100644 (file)
index 0000000..87d2542
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *  units-util.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "units-util.h"
+
+#include "debug.h"
+
+
+/*========================================================*/
+/* Private macros and constants.                          */
+/*========================================================*/
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+
+/****************************************************************************/
+/* Get step size for desired units.                                         */
+/****************************************************************************/
+gdouble
+gl_units_util_get_step_size (lglUnits units)
+{
+
+       switch (units) {
+       case LGL_UNITS_POINT:
+               return 0.1;     /* points */
+       case LGL_UNITS_INCH:
+               return 0.001;   /* inches */
+       case LGL_UNITS_MM:
+               return 0.1;     /* mm */
+       default:
+               g_message ("Illegal units");    /* Should not happen */
+               return 1.0;
+       }
+}
+
+
+/****************************************************************************/
+/* Get precision for desired units.                                         */
+/****************************************************************************/
+gint
+gl_units_util_get_precision (lglUnits units)
+{
+
+       switch (units) {
+       case LGL_UNITS_POINT:
+               return 1;       /* points */
+       case LGL_UNITS_INCH:
+               return 3;       /* inches */
+       case LGL_UNITS_MM:
+               return 1;       /* mm */
+       default:
+               g_message ("Illegal units");    /* Should not happen */
+               return 1.0;
+       }
+}
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/src/units-util.h b/src/units-util.h
new file mode 100644 (file)
index 0000000..91e3a86
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  units-util.h
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UNITS_UTIL_H__
+#define __UNITS_UTIL_H__
+
+#include <libglabels/libglabels.h>
+
+G_BEGIN_DECLS
+
+
+gdouble       gl_units_util_get_step_size (lglUnits units);
+
+gint          gl_units_util_get_precision (lglUnits units);
+
+
+G_END_DECLS
+
+#endif /* __UNITS_UTIL_H__ */
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index 3ebfbe085818e1e08b32ac0fdac922274e1b165d..84b36a1f8167c8a2a1c8d675d13eb32a549a00bc 100644 (file)
@@ -387,16 +387,16 @@ gl_view_init (glView *view)
         /*
          * Defaults from preferences
          */
-       gl_view_set_default_font_family       (view, gl_prefs->default_font_family);
-       gl_view_set_default_font_size         (view, gl_prefs->default_font_size);
-       gl_view_set_default_font_weight       (view, gl_prefs->default_font_weight);
-       gl_view_set_default_font_italic_flag  (view, gl_prefs->default_font_italic_flag);
-       gl_view_set_default_text_color        (view, gl_prefs->default_text_color);
-       gl_view_set_default_text_alignment    (view, gl_prefs->default_text_alignment);
-       gl_view_set_default_text_line_spacing (view, gl_prefs->default_text_line_spacing);
-       gl_view_set_default_line_width        (view, gl_prefs->default_line_width);
-       gl_view_set_default_line_color        (view, gl_prefs->default_line_color);
-       gl_view_set_default_fill_color        (view, gl_prefs->default_fill_color);
+       gl_view_set_default_font_family       (view, gl_prefs_model_get_default_font_family (gl_prefs));
+       gl_view_set_default_font_size         (view, gl_prefs_model_get_default_font_size (gl_prefs));
+       gl_view_set_default_font_weight       (view, gl_prefs_model_get_default_font_weight (gl_prefs));
+       gl_view_set_default_font_italic_flag  (view, gl_prefs_model_get_default_font_italic_flag (gl_prefs));
+       gl_view_set_default_text_color        (view, gl_prefs_model_get_default_text_color (gl_prefs));
+       gl_view_set_default_text_alignment    (view, gl_prefs_model_get_default_text_alignment (gl_prefs));
+       gl_view_set_default_text_line_spacing (view, gl_prefs_model_get_default_text_line_spacing (gl_prefs));
+       gl_view_set_default_line_width        (view, gl_prefs_model_get_default_line_width (gl_prefs));
+       gl_view_set_default_line_color        (view, gl_prefs_model_get_default_line_color (gl_prefs));
+       gl_view_set_default_fill_color        (view, gl_prefs_model_get_default_fill_color (gl_prefs));
 
        gl_debug (DEBUG_VIEW, "END");
 }
index c7cb8de0ce46247b09c6d7b64e888d45f1a1e753..5aa70412d60376f8110c81a384f880c1e900b9f7 100644 (file)
@@ -286,7 +286,7 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
         recent_list = gl_template_history_model_get_name_list (gl_template_history);
         load_recent_list (media_select->priv->recent_store, recent_selection, recent_list);
 
-        page_size_id = gl_prefs_get_page_size ();
+        page_size_id = gl_prefs_model_get_default_page_size (gl_prefs);
         page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id);
 
         /* Brand selection control */
@@ -668,15 +668,15 @@ get_layout_desc (const lglTemplate *template)
 static gchar *
 get_label_size_desc (const lglTemplate *template)
 {
-        lglUnitsType               units;
+        lglUnits                   units;
         const gchar               *units_string;
         gdouble                    units_per_point;
         const lglTemplateFrame    *frame;
         gchar                     *string = NULL;
 
-        units           = gl_prefs_get_units ();
-        units_string    = gl_prefs_get_units_string ();
-        units_per_point = gl_prefs_get_units_per_point ();
+        units           = gl_prefs_model_get_units (gl_prefs);
+        units_string    = lgl_units_get_name (units);
+        units_per_point = lgl_units_get_units_per_point (units);
 
         frame = (lglTemplateFrame *)template->frames->data;
 
index 0960d32e5972534145a31320420bb0f237a1a9e9..6520c378c4d02ae1cea378535b58eb46ed5ea16b 100644 (file)
@@ -31,6 +31,7 @@
 #include "xml-label.h"
 #include "prefs.h"
 #include "file.h"
+#include "units-util.h"
 
 #include "debug.h"
 
@@ -355,13 +356,13 @@ gl_window_set_label (glWindow    *window,
 
        gl_view_zoom_to_fit (GL_VIEW(window->view));
 
-       if (gl_prefs->grid_visible) {
+       if (gl_prefs_model_get_grid_visible (gl_prefs)) {
                gl_view_show_grid (GL_VIEW(window->view));
        } else {
                gl_view_hide_grid (GL_VIEW(window->view));
        }
 
-       if (gl_prefs->markup_visible) {
+       if (gl_prefs_model_get_markup_visible (gl_prefs)) {
                gl_view_show_markup (GL_VIEW(window->view));
        } else {
                gl_view_hide_markup (GL_VIEW(window->view));
@@ -548,17 +549,19 @@ pointer_moved_cb (glView   *view,
                  gdouble   y,
                  glWindow *window)
 {
-       gchar *string;
-       gdouble units_per_point;
-       gint    units_precision;
+       gchar    *string;
+        lglUnits  units;
+       gdouble   units_per_point;
+       gint      units_precision;
 
        gl_debug (DEBUG_WINDOW, "START");
 
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (window && GL_IS_WINDOW (window));
 
-       units_per_point = gl_prefs_get_units_per_point ();
-       units_precision = gl_prefs_get_units_precision ();
+        units = gl_prefs_model_get_units (gl_prefs);
+       units_per_point = lgl_units_get_units_per_point (units);
+       units_precision = gl_units_util_get_precision (units);
 
        string = g_strdup_printf ("%.*f, %.*f",
                                  units_precision, x*units_per_point,
index 12aec42136e994c85246f80835e6b2ca766684bf..324169d0e3856ac586f4f03b766d5e8add037979 100644 (file)
@@ -40,6 +40,7 @@
 #include "label-barcode.h"
 #include "xml-label-04.h"
 #include "str-util.h"
+#include "prefs.h"
 
 #include "debug.h"
 
@@ -1145,6 +1146,7 @@ static xmlDocPtr
 xml_label_to_doc (glLabel          *label,
                  glXMLLabelStatus *status)
 {
+        lglUnits    units;
        xmlDocPtr   doc;
        xmlNsPtr    ns;
        glMerge    *merge;
@@ -1153,6 +1155,9 @@ xml_label_to_doc (glLabel          *label,
 
        LIBXML_TEST_VERSION;
 
+        units = gl_prefs_model_get_units (gl_prefs);
+        lgl_xml_set_default_units (units);
+
        doc = xmlNewDoc ((xmlChar *)"1.0");
        doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-document", NULL);