[gnome-control-center/T20818: 50/54] sharing: Use gtk_switch_set_state and state-set signals
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/T20818: 50/54] sharing: Use gtk_switch_set_state and state-set signals
- Date: Tue, 23 Jan 2018 21:34:14 +0000 (UTC)
commit 5c3d2a095b116a0a41a3f58d23fdd3e28fbf8b6a
Author: Sam Spilsbury <sam endlessm com>
Date: Wed Jan 10 03:58:10 2018 +0800
sharing: Use gtk_switch_set_state and state-set signals
https://phabricator.endlessm.com/T20668
panels/sharing/cc-sharing-panel.c | 79 +++++++++++++++++++++++++++---------
1 files changed, 59 insertions(+), 20 deletions(-)
---
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 8547490..bc085a8 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -667,31 +667,70 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
}
static void
-content_sharing_switch_active_changed_cb (GtkSwitch *widget,
- GParamSpec *pspec,
- CcSharingPanel *self)
+enter_discoverable_mode_done_callback (GObject *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
{
+ CcSharingPanel *self = user_data;
g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) return_tuple;
- if (gtk_switch_get_active (widget))
+ return_tuple = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
+
+ if (!return_tuple)
{
- g_dbus_proxy_call_sync (self->priv->companion_app_avahi_helper_proxy,
- "EnterDiscoverableMode",
- g_variant_new ("(s)", "Endless Computer"),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
+ g_critical ("Error when calling EnterDiscoverableMode on Companion App Helper Proxy: %s",
+ error->message);
+ return;
}
- else
+
+ gtk_switch_set_state (GTK_SWITCH (self->priv->content_sharing_switch), TRUE);
+}
+
+static void
+exit_discoverable_mode_done_callback (GObject *proxy,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ CcSharingPanel *self = user_data;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) return_tuple;
+
+ return_tuple = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
+
+ if (!return_tuple)
{
- g_dbus_proxy_call_sync (self->priv->companion_app_avahi_helper_proxy,
- "ExitDiscoverableMode",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
+ g_critical ("Error when calling ExitDiscoverableMode on Companion App Helper Proxy: %s",
+ error->message);
+ return;
}
- if (error)
- g_critical ("Unable to set the enabled state of content sharing: %s", error->message);
+ gtk_switch_set_state (GTK_SWITCH (self->priv->content_sharing_switch), FALSE);
+}
+
+static gboolean
+content_sharing_switch_state_set_cb (GtkSwitch *widget,
+ gboolean state,
+ CcSharingPanel *self)
+{
+ if (state)
+ g_dbus_proxy_call (self->priv->companion_app_avahi_helper_proxy,
+ "EnterDiscoverableMode",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ enter_discoverable_mode_done_callback,
+ self);
+ else
+ g_dbus_proxy_call (self->priv->companion_app_avahi_helper_proxy,
+ "ExitDiscoverableMode",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ exit_discoverable_mode_done_callback,
+ self);
+
+ return TRUE;
}
static void
@@ -792,8 +831,8 @@ cc_sharing_panel_setup_content_sharing_dialog (CcSharingPanel *self)
gtk_widget_show (content_sharing_button);
gtk_switch_set_active (GTK_SWITCH (self->priv->content_sharing_switch),
content_sharing_enabled);
- g_signal_connect (self->priv->content_sharing_switch, "notify::active",
- G_CALLBACK (content_sharing_switch_active_changed_cb), self);
+ g_signal_connect (self->priv->content_sharing_switch, "state-set",
+ G_CALLBACK (content_sharing_switch_state_set_cb), self);
}
static gboolean
@@ -1410,4 +1449,4 @@ CcSharingPanel *
cc_sharing_panel_new (void)
{
return g_object_new (CC_TYPE_SHARING_PANEL, NULL);
-}
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]