From 4d71d3f3e3cc8300be41c58867f9386d53e4b760 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 25 Oct 2009 21:06:25 -0400 Subject: [PATCH] Refactored glPrefsModel; Added Units module to libglabels 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. --- docs/libglabels/libglabels-decl-list.txt | 16 +- docs/libglabels/libglabels-docs.sgml | 2 +- docs/libglabels/libglabels-sections.txt | 12 +- docs/libglabels/libglabels-undocumented.txt | 10 - docs/libglabels/tmpl/enums.sgml | 33 - docs/libglabels/tmpl/libglabels-unused.sgml | 38 + docs/libglabels/tmpl/paper.sgml | 2 +- docs/libglabels/tmpl/units.sgml | 89 +++ libglabels/Makefile.am | 5 +- libglabels/libglabels.h | 2 +- libglabels/units.c | 254 ++++++ libglabels/{enums.h => units.h} | 27 +- libglabels/xml.c | 71 +- libglabels/xml.h | 4 +- po/POTFILES.in | 5 +- src/Makefile.am | 2 + src/cairo-label-path.c | 1 + src/font-combo-menu.c | 1 - src/font-history-model.c | 1 + src/glabels.c | 1 + src/object-editor-bc-page.c | 6 +- src/object-editor-fill-page.c | 4 +- src/object-editor-line-page.c | 6 +- src/object-editor-lsize-page.c | 21 +- src/object-editor-position-page.c | 21 +- src/object-editor-shadow-page.c | 21 +- src/object-editor-size-page.c | 21 +- src/object-editor-text-page.c | 6 +- src/prefs-dialog.c | 94 ++- src/prefs-model.c | 826 +++++++++++++------- src/prefs-model.h | 157 ++-- src/prefs.c | 102 --- src/prefs.h | 14 - src/recent.c | 3 +- src/template-designer.c | 17 +- src/ui-commands.c | 9 +- src/ui-property-bar.c | 31 +- src/ui.c | 18 +- src/units-util.c | 99 +++ src/units-util.h | 48 ++ src/view.c | 20 +- src/wdgt-media-select.c | 10 +- src/window.c | 17 +- src/xml-label.c | 5 + 44 files changed, 1443 insertions(+), 709 deletions(-) delete mode 100644 docs/libglabels/libglabels-undocumented.txt delete mode 100644 docs/libglabels/tmpl/enums.sgml create mode 100644 docs/libglabels/tmpl/units.sgml create mode 100644 libglabels/units.c rename libglabels/{enums.h => units.h} (70%) create mode 100644 src/units-util.c create mode 100644 src/units-util.h diff --git a/docs/libglabels/libglabels-decl-list.txt b/docs/libglabels/libglabels-decl-list.txt index d3e6343c..b86ecf0f 100644 --- a/docs/libglabels/libglabels-decl-list.txt +++ b/docs/libglabels/libglabels-decl-list.txt @@ -5,11 +5,6 @@ lgl_xml_paper_parse_papers_doc lgl_xml_paper_parse_paper_node -
-enums -lglUnitsType -
-
xml-category lgl_xml_category_read_categories_from_file @@ -59,6 +54,17 @@ lgl_db_print_known_templates lgl_db_print_aliases
+
+units +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 +
+
str lgl_str_utf8_casecmp diff --git a/docs/libglabels/libglabels-docs.sgml b/docs/libglabels/libglabels-docs.sgml index a4b5b381..a246139f 100644 --- a/docs/libglabels/libglabels-docs.sgml +++ b/docs/libglabels/libglabels-docs.sgml @@ -26,7 +26,7 @@ Miscellaneous - + diff --git a/docs/libglabels/libglabels-sections.txt b/docs/libglabels/libglabels-sections.txt index 658d109c..3039050c 100644 --- a/docs/libglabels/libglabels-sections.txt +++ b/docs/libglabels/libglabels-sections.txt @@ -181,9 +181,15 @@ lgl_xml_set_default_units
-enums -libglabels/enums.h -lglUnitsType +units +libglabels/units.h +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
diff --git a/docs/libglabels/libglabels-undocumented.txt b/docs/libglabels/libglabels-undocumented.txt deleted file mode 100644 index 0c4f3ab3..00000000 --- a/docs/libglabels/libglabels-undocumented.txt +++ /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 index b74f00d1..00000000 --- a/docs/libglabels/tmpl/enums.sgml +++ /dev/null @@ -1,33 +0,0 @@ - -Enumerations - - -Common enumerations used by libglabels - - - -This section defines enumerations used to interact with libglabels. - - - - - - - - - - - - -This enumeration defines a set of units of distance supported by the libglabels XML distance -attributes. - - -@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. - diff --git a/docs/libglabels/tmpl/libglabels-unused.sgml b/docs/libglabels/tmpl/libglabels-unused.sgml index dc089b42..628b4aee 100644 --- a/docs/libglabels/tmpl/libglabels-unused.sgml +++ b/docs/libglabels/tmpl/libglabels-unused.sgml @@ -1,3 +1,27 @@ + + +This section defines enumerations used to interact with libglabels. + + + + + + + + + + +Common enumerations used by libglabels + + + + + + + +Enumerations + + @@ -1248,6 +1272,20 @@ the CSS2 Specification (Section 4.3.2). @templates: @utf8_filename: + + +This enumeration defines a set of units of distance supported by the libglabels XML distance +attributes. + + +@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. + diff --git a/docs/libglabels/tmpl/paper.sgml b/docs/libglabels/tmpl/paper.sgml index fab9ee67..448b1196 100644 --- a/docs/libglabels/tmpl/paper.sgml +++ b/docs/libglabels/tmpl/paper.sgml @@ -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. diff --git a/docs/libglabels/tmpl/units.sgml b/docs/libglabels/tmpl/units.sgml new file mode 100644 index 00000000..bcb7b292 --- /dev/null +++ b/docs/libglabels/tmpl/units.sgml @@ -0,0 +1,89 @@ + +Units + + +Type to represent units of distance supported by libglabels + + + +This section defines a type to represent the varios units of distance +supported by libglabels. It also defines a set of related functions. + + + + + + + + + + + + + +This enumeration defines supported units of distance. + + +@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.) + + + + + + +@units: +@Returns: + + + + + + + +@id: +@Returns: + + + + + + + +@units: +@Returns: + + + + + + + +@name: +@Returns: + + + + + + + +@units: +@Returns: + + + + + + + +@units: +@Returns: + + diff --git a/libglabels/Makefile.am b/libglabels/Makefile.am index 2d1228ab..af5e663e 100644 --- a/libglabels/Makefile.am +++ b/libglabels/Makefile.am @@ -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/libglabels.h b/libglabels/libglabels.h index bd46b19d..6d456700 100644 --- a/libglabels/libglabels.h +++ b/libglabels/libglabels.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libglabels/units.c b/libglabels/units.c new file mode 100644 index 00000000..e585962b --- /dev/null +++ b/libglabels/units.c @@ -0,0 +1,254 @@ +/* + * units.c + * Copyright (C) 2003-2009 Jim Evins . + * + * 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 . + */ + +#include + +#include "units.h" + +#include +#include +#include + +#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/enums.h b/libglabels/units.h similarity index 70% rename from libglabels/enums.h rename to libglabels/units.h index 6ebcc1d8..ac3bb0c7 100644 --- a/libglabels/enums.h +++ b/libglabels/units.h @@ -1,5 +1,5 @@ /* - * enums.h + * units.h * Copyright (C) 2003-2009 Jim Evins . * * This file is part of libglabels. @@ -18,14 +18,17 @@ * along with libglabels. If not, see . */ -#ifndef __ENUMS_H__ -#define __ENUMS_H__ +#ifndef __LGL_UNITS_H__ +#define __LGL_UNITS_H__ #include G_BEGIN_DECLS -/* Units of distance */ + +/* + * Units of distance + */ typedef enum { LGL_UNITS_POINT, /* encoded as "pt" */ LGL_UNITS_INCH, /* encoded as "in" */ @@ -35,13 +38,25 @@ typedef enum { LGL_UNITS_FIRST = LGL_UNITS_POINT, LGL_UNITS_LAST = LGL_UNITS_PICA, -} lglUnitsType; + + 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 /* __ENUMS_H__ */ +#endif /* __LGL_UNITS_H__ */ diff --git a/libglabels/xml.c b/libglabels/xml.c index 91cbb205..4bce17e2 100644 --- a/libglabels/xml.c +++ b/libglabels/xml.c @@ -33,41 +33,15 @@ /* 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)); diff --git a/libglabels/xml.h b/libglabels/xml.h index 257ee455..7b49c8fc 100644 --- a/libglabels/xml.h +++ b/libglabels/xml.h @@ -24,7 +24,7 @@ #include #include -#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 diff --git a/po/POTFILES.in b/po/POTFILES.in index 69435c32..8afc6d40 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index 55e5e2fc..0db02529 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/cairo-label-path.c b/src/cairo-label-path.c index 59b8db13..0d7e4b78 100644 --- a/src/cairo-label-path.c +++ b/src/cairo-label-path.c @@ -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); diff --git a/src/font-combo-menu.c b/src/font-combo-menu.c index 2a0a7c59..6df363af 100644 --- a/src/font-combo-menu.c +++ b/src/font-combo-menu.c @@ -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); diff --git a/src/font-history-model.c b/src/font-history-model.c index 29471d7e..0e18b9cb 100644 --- a/src/font-history-model.c +++ b/src/font-history-model.c @@ -25,6 +25,7 @@ #include #include +#include "font-util.h" #include "marshal.h" diff --git a/src/glabels.c b/src/glabels.c index 43d12909..d3a107d6 100644 --- a/src/glabels.c +++ b/src/glabels.c @@ -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" diff --git a/src/object-editor-bc-page.c b/src/object-editor-bc-page.c index 3d6f155b..4c80ac6c 100644 --- a/src/object-editor-bc-page.c +++ b/src/object-editor-bc-page.c @@ -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; } diff --git a/src/object-editor-fill-page.c b/src/object-editor-fill-page.c index b1143d2c..b9ea1ac1 100644 --- a/src/object-editor-fill-page.c +++ b/src/object-editor-fill-page.c @@ -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); diff --git a/src/object-editor-line-page.c b/src/object-editor-line-page.c index a7c2f582..11869695 100644 --- a/src/object-editor-line-page.c +++ b/src/object-editor-line-page.c @@ -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); diff --git a/src/object-editor-lsize-page.c b/src/object-editor-lsize-page.c index a832f094..a1b8365c 100644 --- a/src/object-editor-lsize-page.c +++ b/src/object-editor-lsize-page.c @@ -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; diff --git a/src/object-editor-position-page.c b/src/object-editor-position-page.c index 6ea9a869..de180a0e 100644 --- a/src/object-editor-position-page.c +++ b/src/object-editor-position-page.c @@ -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; diff --git a/src/object-editor-shadow-page.c b/src/object-editor-shadow-page.c index 4a3cc2e2..d10a1590 100644 --- a/src/object-editor-shadow-page.c +++ b/src/object-editor-shadow-page.c @@ -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; diff --git a/src/object-editor-size-page.c b/src/object-editor-size-page.c index c6821ea1..34d7ad66 100644 --- a/src/object-editor-size-page.c +++ b/src/object-editor-size-page.c @@ -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; diff --git a/src/object-editor-text-page.c b/src/object-editor-text-page.c index 615668ea..3c196327 100644 --- a/src/object-editor-text-page.c +++ b/src/object-editor-text-page.c @@ -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; } diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 7deff673..d05f4680 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -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); } diff --git a/src/prefs-model.c b/src/prefs-model.c index 3aefa08a..ed83c8b9 100644 --- a/src/prefs-model.c +++ b/src/prefs-model.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #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" @@ -71,11 +71,11 @@ /* 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 @@ -95,6 +95,12 @@ /* 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; - } -} - - diff --git a/src/prefs-model.h b/src/prefs-model.h index e01b0481..72efa845 100644 --- a/src/prefs-model.h +++ b/src/prefs-model.h @@ -22,17 +22,11 @@ #define __PREFS_MODEL_H__ #include -#include #include #include 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 diff --git a/src/prefs.c b/src/prefs.c index 198e8522..f83e0bac 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -49,7 +49,6 @@ glPrefsModel *gl_prefs = NULL; /*========================================================*/ - /*****************************************************************************/ /* 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"); } - -/****************************************************************************/ -/* 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"); - } -} - /* diff --git a/src/prefs.h b/src/prefs.h index 6e389ff2..7cabea1e 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -26,25 +26,11 @@ 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 diff --git a/src/recent.c b/src/recent.c index 38244ab1..295c6661 100644 --- a/src/recent.c +++ b/src/recent.c @@ -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); diff --git a/src/template-designer.c b/src/template-designer.c index d5d6453f..d668265b 100644 --- a/src/template-designer.c +++ b/src/template-designer.c @@ -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); diff --git a/src/ui-commands.c b/src/ui-commands.c index a8e2bbd3..73da051e 100644 --- a/src/ui-commands.c +++ b/src/ui-commands.c @@ -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"); } diff --git a/src/ui-property-bar.c b/src/ui-property-bar.c index 30ae6cbf..7df45436 100644 --- a/src/ui-property-bar.c +++ b/src/ui-property-bar.c @@ -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 { diff --git a/src/ui.c b/src/ui.c index 62b67d4e..5449d28e 100644 --- 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 index 00000000..87d25422 --- /dev/null +++ b/src/units-util.c @@ -0,0 +1,99 @@ +/* + * units-util.c + * Copyright (C) 2001-2009 Jim Evins . + * + * 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 . + */ + +#include + +#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 index 00000000..91e3a86b --- /dev/null +++ b/src/units-util.h @@ -0,0 +1,48 @@ +/* + * units-util.h + * Copyright (C) 2001-2009 Jim Evins . + * + * 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 . + */ + +#ifndef __UNITS_UTIL_H__ +#define __UNITS_UTIL_H__ + +#include + +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 + */ diff --git a/src/view.c b/src/view.c index 3ebfbe08..84b36a1f 100644 --- a/src/view.c +++ b/src/view.c @@ -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"); } diff --git a/src/wdgt-media-select.c b/src/wdgt-media-select.c index c7cb8de0..5aa70412 100644 --- a/src/wdgt-media-select.c +++ b/src/wdgt-media-select.c @@ -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; diff --git a/src/window.c b/src/window.c index 0960d32e..6520c378 100644 --- a/src/window.c +++ b/src/window.c @@ -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, diff --git a/src/xml-label.c b/src/xml-label.c index 12aec421..324169d0 100644 --- a/src/xml-label.c +++ b/src/xml-label.c @@ -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); -- 2.39.5