From a7d77f6d5eb0e0d73c1029dd751014efc21d95df Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 5 Aug 2006 15:06:23 +0000 Subject: A lib/ephy-print-utils.c: A lib/ephy-print-utils.h: 2006-08-05 Christian Persch * embed/ephy-embed-shell.c: (ephy_embed_shell_set_page_setup), (ephy_embed_shell_get_page_setup), (ephy_embed_shell_set_print_settings), (ephy_embed_shell_get_print_settings): A lib/ephy-print-utils.c: A lib/ephy-print-utils.h: * lib/ephy-string.c: (ephy_string_flags_from_string), (ephy_string_flags_to_string), (ephy_string_enum_from_string), (ephy_string_enum_to_string): * lib/ephy-string.h: Persist print settings and page setup. --- lib/ephy-string.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'lib/ephy-string.c') diff --git a/lib/ephy-string.c b/lib/ephy-string.c index 3eb991573..baec076b1 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -182,3 +182,107 @@ ephy_string_collate_key_for_domain (const char *str, return g_string_free (result, FALSE); } + +guint +ephy_string_flags_from_string (GType type, + const char *flags_string) +{ + GFlagsClass *flags_class; + const GFlagsValue *value; + gchar **flags; + guint retval = 0, i; + + g_return_val_if_fail (flags_string != NULL, 0); + + flags = g_strsplit (flags_string, "|", -1); + if (!flags) return 0; + + flags_class = g_type_class_ref (type); + + for (i = 0; flags[i] != NULL; ++i) + { + value = g_flags_get_value_by_nick (flags_class, flags[i]); + if (value != NULL) + { + retval |= value->value; + } + } + + g_type_class_unref (flags_class); + + return retval; +} + +char * +ephy_string_flags_to_string (GType type, + guint flags_value) +{ + GFlagsClass *flags_class; + GString *string; + gboolean first = TRUE; + guint i; + + string = g_string_sized_new (128); + + flags_class = g_type_class_ref (type); + + for (i = 0; i < flags_class->n_values; ++i) + { + if (flags_value & flags_class->values[i].value) + { + if (!first) + { + g_string_append_c (string, '|'); + } + first = FALSE; + g_string_append (string, flags_class->values[i].value_nick); + } + } + + g_type_class_unref (flags_class); + + return g_string_free (string, FALSE); +} + +guint +ephy_string_enum_from_string (GType type, + const char *enum_string) +{ + GEnumClass *enum_class; + const GEnumValue *value; + guint retval = 0; + + g_return_val_if_fail (enum_string != NULL, 0); + + enum_class = g_type_class_ref (type); + value = g_enum_get_value_by_nick (enum_class, enum_string); + if (value != NULL) + { + retval = value->value; + } + + g_type_class_unref (enum_class); + + return retval; +} + +char * +ephy_string_enum_to_string (GType type, + guint enum_value) +{ + GEnumClass *enum_class; + GEnumValue *value; + char *retval = NULL; + + enum_class = g_type_class_ref (type); + + value = g_enum_get_value (enum_class, enum_value); + if (value) + { + retval = g_strdup (value->value_nick); + } + + g_type_class_unref (enum_class); + + return retval; +} -- cgit v1.2.3