summaryrefslogtreecommitdiff
path: root/gio/gapplicationimpl-dbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'gio/gapplicationimpl-dbus.c')
-rw-r--r--gio/gapplicationimpl-dbus.c75
1 files changed, 56 insertions, 19 deletions
diff --git a/gio/gapplicationimpl-dbus.c b/gio/gapplicationimpl-dbus.c
index 36f8b0fda..a0778a0b1 100644
--- a/gio/gapplicationimpl-dbus.c
+++ b/gio/gapplicationimpl-dbus.c
@@ -67,8 +67,8 @@ static const gchar org_gtk_Application_xml[] =
"<arg type='a{sv}' name='platform-data' direction='in'/>"
"<arg type='i' name='exit-status' direction='out'/>"
"</method>"
- "<property name='Busy' type='b' access='read'/>"
- "<property name='RestartData' type='sv' access='read'/>"
+ "<property name='Busy' type='b' access='read'/>"
+ "<property name='RestartData' type='sv' access='read'/>"
"</interface>"
"</node>";
@@ -126,14 +126,13 @@ struct _GApplicationImpl
gboolean busy;
gboolean registered;
GApplication *app;
-
- gchar *restart_data_tag; /* (owned) (nullable) */
- GVariant *restart_data; /* (owned) (nullable) */
};
static GApplicationCommandLine *
g_dbus_command_line_new (GDBusMethodInvocation *invocation);
+static GVariant *format_restart_data (const char *restart_data_tag,
+ GVariant *restart_data);
static GVariant *
g_application_impl_get_property (GDBusConnection *connection,
@@ -145,9 +144,32 @@ g_application_impl_get_property (GDBusConnection *connection,
gpointer user_data)
{
GApplicationImpl *impl = user_data;
+ GApplicationClass *class;
+
+ class = G_APPLICATION_GET_CLASS (impl->app);
if (strcmp (property_name, "Busy") == 0)
return g_variant_new_boolean (impl->busy);
+ else if (strcmp (property_name, "RestartData") == 0)
+ {
+ GVariant *restart_data = NULL;
+ char *restart_data_tag = NULL;
+ GVariant *out = NULL;
+
+ /* Interpret a o.fdo.DBus.Properties.Get() call on the property as an
+ * explicit request to update the restart data. */
+ if (class->build_restart_data != NULL)
+ restart_data = class->build_restart_data (impl->app, &restart_data_tag);
+ if (restart_data != NULL)
+ g_variant_take_ref (restart_data);
+
+ out = format_restart_data (restart_data_tag, restart_data);
+
+ g_clear_pointer (&restart_data, g_variant_unref);
+ g_clear_pointer (&restart_data_tag, g_free);
+
+ return g_steal_pointer (&out);
+ }
g_assert_not_reached ();
@@ -604,21 +626,39 @@ g_application_impl_set_busy_state (GApplicationImpl *impl,
}
}
+static GVariant *
+format_restart_data (const char *restart_data_tag,
+ GVariant *restart_data)
+{
+ /* The wire format of ‘no restart data’ is `("", <"">)`, since D-Bus doesn’t
+ * currently support maybe types. */
+ gboolean no_data = (restart_data == NULL);
+ return g_variant_new ("(sv)",
+ (no_data || restart_data_tag == NULL) ? "" : restart_data_tag,
+ no_data ? g_variant_new_string ("") : restart_data);
+}
+
void
-g_application_impl_set_restart_data (GApplicationImpl *impl,
- const gchar *tag,
- GVariant *data)
+g_application_impl_notify_restart_data_changed (GApplicationImpl *impl)
{
- g_clear_pointer (&impl->restart_data_tag, g_free);
- g_clear_pointer (&impl->restart_data, g_variant_unref);
+ GApplicationClass *app_class = G_APPLICATION_GET_CLASS (impl->app);
+ GVariant *restart_data = NULL;
+ char *restart_data_tag = NULL;
+ GVariant *out = NULL;
- if (data != NULL && tag != NULL)
- impl->restart_data_tag = g_strdup (tag);
- if (data != NULL)
- impl->restart_data = g_variant_ref_sink (data);
+ if (app_class->build_restart_data != NULL)
+ restart_data = app_class->build_restart_data (impl->app, &restart_data_tag);
+ if (restart_data != NULL)
+ g_variant_take_ref (restart_data);
- send_property_change (impl, "RestartData",
- g_variant_new ("sv", impl->restart_data_tag, impl->restart_data));
+ out = format_restart_data (restart_data_tag, restart_data);
+
+ g_clear_pointer (&restart_data, g_variant_unref);
+ g_clear_pointer (&restart_data_tag, g_free);
+
+ send_property_change (impl, "RestartData", out);
+
+ g_variant_unref (out);
}
void
@@ -631,9 +671,6 @@ g_application_impl_destroy (GApplicationImpl *impl)
g_free (impl->object_path);
- g_free (impl->restart_data_tag);
- g_clear_pointer (&impl->restart_data, g_variant_unref);
-
g_slice_free (GApplicationImpl, impl);
}