[telepathy-glib/master] Expose some GKeyFile helpers

Simon McVittie simon.mcvittie at collabora.co.uk
Tue May 26 10:55:11 PDT 2009


These will probably be useful for Mission Control too.
---
 docs/reference/telepathy-glib-sections.txt |    2 +
 telepathy-glib/connection-manager.c        |   64 -------------------
 telepathy-glib/util.c                      |   92 ++++++++++++++++++++++++++++
 telepathy-glib/util.h                      |    5 ++
 4 files changed, 99 insertions(+), 64 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 122bfa2..355cccb 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -994,6 +994,8 @@ tp_mixin_class_get_offset
 tp_mixin_instance_get_offset
 tp_escape_as_identifier
 tp_strv_contains
+tp_g_key_file_get_int64
+tp_g_key_file_get_uint64
 </SECTION>
 
 <SECTION>
diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c
index 0ff3305..5720613 100644
--- a/telepathy-glib/connection-manager.c
+++ b/telepathy-glib/connection-manager.c
@@ -753,70 +753,6 @@ init_gvalue_from_dbus_sig (const gchar *sig,
   return FALSE;
 }
 
-static gint64
-tp_g_key_file_get_int64 (GKeyFile *key_file,
-                         const gchar *group_name,
-                         const gchar *key,
-                         GError **error)
-{
-  gchar *s, *end;
-  gint64 v;
-
-  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);
-
-  s = g_key_file_get_value (key_file, group_name, key, error);
-
-  if (s == NULL)
-    return 0;
-
-  v = g_ascii_strtoll (s, &end, 10);
-
-  if (*s == '\0' || *end != '\0')
-    {
-      g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE,
-          "Key '%s' in group '%s' has value '%s' where int64 was expected",
-          key, group_name, s);
-      return 0;
-    }
-
-  g_free (s);
-  return v;
-}
-
-static guint64
-tp_g_key_file_get_uint64 (GKeyFile *key_file,
-                          const gchar *group_name,
-                          const gchar *key,
-                          GError **error)
-{
-  gchar *s, *end;
-  guint64 v;
-
-  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);
-
-  s = g_key_file_get_value (key_file, group_name, key, error);
-
-  if (s == NULL)
-    return 0;
-
-  v = g_ascii_strtoull (s, &end, 10);
-
-  if (*s == '\0' || *end != '\0')
-    {
-      g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE,
-          "Key '%s' in group '%s' has value '%s' where uint64 was expected",
-          key, group_name, s);
-      return 0;
-    }
-
-  g_free (s);
-  return v;
-}
-
 static gboolean
 parse_default_value (GValue *value,
                      const gchar *sig,
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 00c81f4..dd01735 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -668,3 +668,95 @@ tp_strv_contains (const gchar * const *strv,
 
   return FALSE;
 }
+
+/**
+ * tp_g_key_file_get_int64:
+ * @key_file: a non-%NULL #GKeyFile
+ * @group_name: a non-%NULL group name
+ * @key: a non-%NULL key
+ * @error: return location for a #GError
+ *
+ * Returns the value associated with @key under @group_name as a signed
+ * 64-bit integer. This is similar to g_key_file_get_integer() but can return
+ * 64-bit results without truncation.
+ *
+ * Returns: the value associated with the key as a signed 64-bit integer, or
+ * 0 if the key was not found or could not be parsed.
+ */
+gint64
+tp_g_key_file_get_int64 (GKeyFile *key_file,
+                         const gchar *group_name,
+                         const gchar *key,
+                         GError **error)
+{
+  gchar *s, *end;
+  gint64 v;
+
+  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);
+
+  s = g_key_file_get_value (key_file, group_name, key, error);
+
+  if (s == NULL)
+    return 0;
+
+  v = g_ascii_strtoll (s, &end, 10);
+
+  if (*s == '\0' || *end != '\0')
+    {
+      g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE,
+          "Key '%s' in group '%s' has value '%s' where int64 was expected",
+          key, group_name, s);
+      return 0;
+    }
+
+  g_free (s);
+  return v;
+}
+
+/**
+ * tp_g_key_file_get_uint64:
+ * @key_file: a non-%NULL #GKeyFile
+ * @group_name: a non-%NULL group name
+ * @key: a non-%NULL key
+ * @error: return location for a #GError
+ *
+ * Returns the value associated with @key under @group_name as an unsigned
+ * 64-bit integer. This is similar to g_key_file_get_integer() but can return
+ * large positive results without truncation.
+ *
+ * Returns: the value associated with the key as an unsigned 64-bit integer,
+ * or 0 if the key was not found or could not be parsed.
+ */
+guint64
+tp_g_key_file_get_uint64 (GKeyFile *key_file,
+                          const gchar *group_name,
+                          const gchar *key,
+                          GError **error)
+{
+  gchar *s, *end;
+  guint64 v;
+
+  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);
+
+  s = g_key_file_get_value (key_file, group_name, key, error);
+
+  if (s == NULL)
+    return 0;
+
+  v = g_ascii_strtoull (s, &end, 10);
+
+  if (*s == '\0' || *end != '\0')
+    {
+      g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE,
+          "Key '%s' in group '%s' has value '%s' where uint64 was expected",
+          key, group_name, s);
+      return 0;
+    }
+
+  g_free (s);
+  return v;
+}
diff --git a/telepathy-glib/util.h b/telepathy-glib/util.h
index d9470ab..f06d099 100644
--- a/telepathy-glib/util.h
+++ b/telepathy-glib/util.h
@@ -63,6 +63,11 @@ gchar *tp_escape_as_identifier (const gchar *name);
 
 gboolean tp_strv_contains (const gchar * const *strv, const gchar *str);
 
+gint64 tp_g_key_file_get_int64 (GKeyFile *key_file, const gchar *group_name,
+    const gchar *key, GError **error);
+guint64 tp_g_key_file_get_uint64 (GKeyFile *key_file, const gchar *group_name,
+    const gchar *key, GError **error);
+
 G_END_DECLS
 
 #endif /* __TP_UTIL_H__ */
-- 
1.5.6.5




More information about the telepathy-commits mailing list