[gtk+/portal: 14/17] print settings: Add api to serialize to a GVariant
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/portal: 14/17] print settings: Add api to serialize to a GVariant
- Date: Wed, 6 Jul 2016 03:08:05 +0000 (UTC)
commit beeffd3cc33bff24ff0ad5207a829d4c4af7c10b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 2 20:29:08 2016 -0400
print settings: Add api to serialize to a GVariant
This will be useful for portalized print support.
docs/reference/gtk/gtk3-sections.txt | 2 +
gtk/gtkprintsettings.c | 69 ++++++++++++++++++++++++++++++++++
gtk/gtkprintsettings.h | 6 +++
3 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 0c072c6..0a4ded3 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -7264,10 +7264,12 @@ GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION
<SUBSECTION Serialization>
gtk_print_settings_new_from_file
gtk_print_settings_new_from_key_file
+gtk_print_settings_new_from_gvariant
gtk_print_settings_load_file
gtk_print_settings_load_key_file
gtk_print_settings_to_file
gtk_print_settings_to_key_file
+gtk_print_settings_to_gvariant
<SUBSECTION Standard>
GTK_TYPE_PRINT_SETTINGS
diff --git a/gtk/gtkprintsettings.c b/gtk/gtkprintsettings.c
index f2cf860..56f9e99 100644
--- a/gtk/gtkprintsettings.c
+++ b/gtk/gtkprintsettings.c
@@ -1941,3 +1941,72 @@ gtk_print_settings_to_key_file (GtkPrintSettings *settings,
(GtkPrintSettingsFunc) add_value_to_key_file,
&data);
}
+
+static void
+add_to_variant (const gchar *key,
+ const gchar *value,
+ gpointer data)
+{
+ GVariantBuilder *builder = data;
+ g_variant_builder_add (builder, "{sv}", key, g_variant_new_string (value));
+}
+
+/**
+ * gtk_print_settings_to_gvariant:
+ * @settings: a #GtkPrintSettings
+ *
+ * Serialize print settings to an a{sv} variant.
+ *
+ * Returns: (transfer none): a new, floating, #GVariant
+ *
+ * Since: 3.22
+ */
+GVariant *
+gtk_print_settings_to_gvariant (GtkPrintSettings *settings)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+ gtk_print_settings_foreach (settings, add_to_variant, &builder);
+
+ return g_variant_builder_end (&builder);
+}
+
+/**
+ * gtk_print_settings_new_from_gvariant:
+ * @variant: an a{sv} #GVariant
+ *
+ * Deserialize print settings from an a{sv} variant in
+ * the format produced by gtk_print_settings_to_gvariant().
+ *
+ * Returns: (transfer full): a new #GtkPrintSettings object
+ *
+ * Since: 3.22
+ */
+GtkPrintSettings *
+gtk_print_settings_new_from_gvariant (GVariant *variant)
+{
+ GtkPrintSettings *settings;
+ int i;
+
+ g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), NULL);
+
+ settings = gtk_print_settings_new ();
+
+ for (i = 0; i < g_variant_n_children (variant); i++)
+ {
+ const char *key;
+ GVariant *v;
+
+ g_variant_get_child (variant, i, "{&sv}", &key, &v);
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
+ {
+ const char *value;
+ g_variant_get (v, "&s", &value);
+ gtk_print_settings_set (settings, key, value);
+ }
+ g_variant_unref (v);
+ }
+
+ return settings;
+}
diff --git a/gtk/gtkprintsettings.h b/gtk/gtkprintsettings.h
index fe47dd2..d97b7a3 100644
--- a/gtk/gtkprintsettings.h
+++ b/gtk/gtkprintsettings.h
@@ -344,6 +344,12 @@ GDK_AVAILABLE_IN_ALL
void gtk_print_settings_set_output_bin (GtkPrintSettings *settings,
const gchar *output_bin);
+GDK_AVAILABLE_IN_3_22
+GVariant *gtk_print_settings_to_gvariant (GtkPrintSettings *settings);
+GDK_AVAILABLE_IN_3_22
+GtkPrintSettings *gtk_print_settings_new_from_gvariant (GVariant *variant);
+
+
G_END_DECLS
#endif /* __GTK_PRINT_SETTINGS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]