r15710 - gnucash/trunk - Make the new check printing code compile on systems that don't have

David Hampton hampton at cvs.gnucash.org
Tue Mar 13 11:18:12 EDT 2007


Author: hampton
Date: 2007-03-13 11:18:11 -0400 (Tue, 13 Mar 2007)
New Revision: 15710
Trac: http://svn.gnucash.org/trac/changeset/15710

Modified:
   gnucash/trunk/configure.in
   gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
   gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
   gnucash/trunk/src/gnome/dialog-print-check.c
Log:
Make the new check printing code compile on systems that don't have
glib 2.12.


Modified: gnucash/trunk/configure.in
===================================================================
--- gnucash/trunk/configure.in	2007-03-13 03:43:24 UTC (rev 15709)
+++ gnucash/trunk/configure.in	2007-03-13 15:18:11 UTC (rev 15710)
@@ -247,6 +247,18 @@
 else
   AC_MSG_RESULT(no)
 fi
+
+AC_MSG_CHECKING(for GLIB - version >= 2.12.0)
+if $PKG_CONFIG 'glib-2.0 >= 2.12.0'
+then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_GLIB_2_12,1,[System has glib 2.12.0 or better])
+  HAVE_GLIB_2_12=yes
+else
+  AC_MSG_RESULT(no)
+fi
+AM_CONDITIONAL(HAVE_GLIB_2_8, test "x$HAVE_GLIB_2_8" = "xyes")
+
 AC_MSG_CHECKING([for untested GLIB versions (glib >= 2.11.0)])
 if $PKG_CONFIG 'glib-2.0 >= 2.11.0'
 then

Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c	2007-03-13 03:43:24 UTC (rev 15709)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.c	2007-03-13 15:18:11 UTC (rev 15710)
@@ -37,6 +37,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <string.h>
 #include <errno.h>
@@ -45,6 +46,180 @@
 
 #include "gnc-gkeyfile-utils.h"
 
+#ifndef HAVE_GLIB_2_12
+/**********************************************************************
+ *
+ * The following functions are copied verbatim from the GLIB 2.12
+ * source code.  If more glib 2.12 functions are included into
+ * gnucash,then they should all be consolidated in a lib/glib212
+ * directory.
+ *
+ **********************************************************************/
+static gchar *
+_g_utf8_make_valid (const gchar *name)
+{
+  GString *string;
+  const gchar *remainder, *invalid;
+  gint remaining_bytes, valid_bytes;
+  
+  string = NULL;
+  remainder = name;
+  remaining_bytes = strlen (name);
+  
+  while (remaining_bytes != 0) 
+    {
+      if (g_utf8_validate (remainder, remaining_bytes, &invalid)) 
+	break;
+      valid_bytes = invalid - remainder;
+    
+      if (string == NULL) 
+	string = g_string_sized_new (remaining_bytes);
+
+      g_string_append_len (string, remainder, valid_bytes);
+      /* append U+FFFD REPLACEMENT CHARACTER */
+      g_string_append (string, "\357\277\275");
+      
+      remaining_bytes -= valid_bytes + 1;
+      remainder = invalid + 1;
+    }
+  
+  if (string == NULL)
+    return g_strdup (name);
+  
+  g_string_append (string, remainder);
+
+  g_assert (g_utf8_validate (string->str, -1, NULL));
+  
+  return g_string_free (string, FALSE);
+}
+
+static gdouble
+g_key_file_parse_value_as_double  (GKeyFile     *key_file,
+                                   const gchar  *value,
+                                   GError      **error)
+{
+  gchar *end_of_valid_d;
+  gdouble double_value = 0;
+
+  double_value = g_ascii_strtod (value, &end_of_valid_d);
+
+  if (*end_of_valid_d != '\0' || end_of_valid_d == value)
+    {
+      gchar *value_utf8 = _g_utf8_make_valid (value);
+      g_set_error (error, G_KEY_FILE_ERROR,
+		   G_KEY_FILE_ERROR_INVALID_VALUE,
+		   _("Value '%s' cannot be interpreted "
+		     "as a float number."), 
+		   value_utf8);
+      g_free (value_utf8);
+    }
+
+  return double_value;
+}
+
+gdouble
+g_key_file_get_double (GKeyFile *key_file, const gchar *group_name,
+                       const gchar *key, GError **error)
+{
+  GError *key_file_error;
+  gchar *value;
+  gdouble double_value;
+
+  g_return_val_if_fail (key_file != NULL, -1);
+  g_return_val_if_fail (group_name != NULL, -1);
+  g_return_val_if_fail (key != NULL, -1);
+
+  key_file_error = NULL;
+
+  value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
+
+  if (key_file_error)
+    {
+      g_propagate_error (error, key_file_error);
+      return 0;
+    }
+
+  double_value = g_key_file_parse_value_as_double (key_file, value,
+                                                  &key_file_error);
+  g_free (value);
+
+  if (key_file_error)
+    {
+      if (g_error_matches (key_file_error,
+                           G_KEY_FILE_ERROR,
+                           G_KEY_FILE_ERROR_INVALID_VALUE))
+        {
+          g_set_error (error, G_KEY_FILE_ERROR,
+                       G_KEY_FILE_ERROR_INVALID_VALUE,
+                       _("Key file contains key '%s' in group '%s' "
+                         "which has value that cannot be interpreted."), key,
+                       group_name);
+          g_error_free (key_file_error);
+        }
+      else
+        g_propagate_error (error, key_file_error);
+    }
+
+  return double_value;
+}
+
+gdouble*
+g_key_file_get_double_list (GKeyFile *key_file,
+                            const gchar *group_name,
+                            const gchar *key,
+                            gsize *length,
+                            GError **error)
+{
+  GError *key_file_error = NULL;
+  gchar **values;
+  gdouble *double_values;
+  gsize i, num_doubles;
+
+  g_return_val_if_fail (key_file != NULL, NULL);
+  g_return_val_if_fail (group_name != NULL, NULL);
+  g_return_val_if_fail (key != NULL, NULL);
+
+  values = g_key_file_get_string_list (key_file, group_name, key,
+                                       &num_doubles, &key_file_error);
+
+  if (key_file_error)
+    g_propagate_error (error, key_file_error);
+
+  if (!values)
+    return NULL;
+
+  double_values = g_new0 (gdouble, num_doubles);
+
+  for (i = 0; i < num_doubles; i++)
+    {
+      double_values[i] = g_key_file_parse_value_as_double (key_file,
+							   values[i],
+							   &key_file_error);
+
+      if (key_file_error)
+        {
+          g_propagate_error (error, key_file_error);
+          g_strfreev (values);
+          g_free (double_values);
+
+          return NULL;
+        }
+    }
+  g_strfreev (values);
+
+  if (length)
+    *length = num_doubles;
+
+  return double_values;
+}
+/**********************************************************************
+ *
+ *                     End of copied functions.
+ *
+ **********************************************************************/
+#endif
+
+
 GKeyFile *
 gnc_key_file_load_from_file (const gchar *filename,
 			     gboolean ignore_error,

Modified: gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h	2007-03-13 03:43:24 UTC (rev 15709)
+++ gnucash/trunk/src/core-utils/gnc-gkeyfile-utils.h	2007-03-13 15:18:11 UTC (rev 15710)
@@ -38,6 +38,17 @@
 #define GNC_GKEYFILE_UTILS_H
 
 
+#ifndef HAVE_GLIB_2_12
+gdouble
+g_key_file_get_double (GKeyFile *key_file, const gchar *group_name,
+                       const gchar *key, GError **error);
+
+gdouble*
+g_key_file_get_double_list (GKeyFile *key_file, const gchar *group_name,
+                            const gchar *key, gsize *length, GError **error);
+#endif
+
+
 /** Open and read a key/value file from disk into memory.
  *
  *  @param file The name of the file to load.  This should be a fully

Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2007-03-13 03:43:24 UTC (rev 15709)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2007-03-13 15:18:11 UTC (rev 15710)
@@ -29,6 +29,8 @@
 #include <libguile.h>
 #include <locale.h>
 
+#include "glib-compat.h"
+
 #include "qof.h"
 #include "gnc-date.h"
 #include "gnc-gconf-utils.h"
@@ -1242,7 +1244,7 @@
         switch (item->type) {
             case DATE:
                 date = g_date_new();
-                g_date_set_time(date, pcd->date);
+                g_date_set_time_t(date, pcd->date);
                 date_format =
                     gnc_date_format_get_custom(GNC_DATE_FORMAT
                                                (pcd->date_format));
@@ -1469,7 +1471,7 @@
     item.x = multip * gtk_spin_button_get_value(pcd->date_x);
     item.y = multip * gtk_spin_button_get_value(pcd->date_y);
     date = g_date_new();
-    g_date_set_time(date, pcd->date);
+    g_date_set_time_t(date, pcd->date);
     date_format = gnc_date_format_get_custom(GNC_DATE_FORMAT(pcd->date_format));
     g_date_strftime(buf, 100, date_format, date);
     draw_text(context, buf, &item, desc);



More information about the gnucash-changes mailing list