[gnome-control-center/T20818: 49/54] panels: Add content sharing options to sharing dialog



commit 50e21349aecc6dbd8c24948f96490a866153ae64
Author: Sam Spilsbury <sam endlessm com>
Date:   Wed Jan 3 16:23:53 2018 +0800

    panels: Add content sharing options to sharing dialog
    
    https://phabricator.endlessm.com/T20381

 configure.ac                      |    2 +-
 panels/sharing/cc-sharing-panel.c |  151 +++++++++++++++++++++++++++++++++++++
 panels/sharing/sharing.ui         |  101 +++++++++++++++++++++++++
 3 files changed, 253 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 14e0807..8a017c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -183,7 +183,7 @@ PKG_CHECK_MODULES(USER_ACCOUNTS_PANEL, $COMMON_MODULES
                   gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION
                   pwquality >= $PWQUALITY_REQUIRED_VERSION
                   accountsservice >= $ACCOUNTSSERVICE_REQUIRED_VERSION)
-PKG_CHECK_MODULES(SHARING_PANEL, $COMMON_MODULES)
+PKG_CHECK_MODULES(SHARING_PANEL, $COMMON_MODULES flatpak)
 PKG_CHECK_MODULES(REMOTE_LOGIN_HELPER, glib-2.0 >= $GLIB_REQUIRED_VERSION gio-2.0)
 
 PKG_CHECK_MODULES(GVC, gobject-2.0 libpulse libpulse-mainloop-glib)
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index c83cea2..8547490 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -32,6 +32,8 @@
 #include "cc-sharing-switch.h"
 #include "org.gnome.SettingsDaemon.Sharing.h"
 
+#include <flatpak.h>
+
 #ifdef GDK_WINDOWING_WAYLAND
 #include <gdk/gdkwayland.h>
 #endif
@@ -76,10 +78,12 @@ struct _CcSharingPanelPrivate
 
   GCancellable *sharing_proxy_cancellable;
   GDBusProxy *sharing_proxy;
+  GDBusProxy *companion_app_avahi_helper_proxy;
 
   GtkWidget *media_sharing_switch;
   GtkWidget *personal_file_sharing_switch;
   GtkWidget *screen_sharing_switch;
+  GtkWidget *content_sharing_switch;
 
   GtkWidget *media_sharing_dialog;
   GtkWidget *personal_file_sharing_dialog;
@@ -87,6 +91,7 @@ struct _CcSharingPanelPrivate
   GCancellable *remote_login_cancellable;
   GCancellable *hostname_cancellable;
   GtkWidget *screen_sharing_dialog;
+  GtkWidget  *content_sharing_dialog;
 
   guint remote_desktop_name_watch;
 };
@@ -109,6 +114,7 @@ cc_sharing_panel_master_switch_notify (GtkSwitch      *gtkswitch,
       OFF_IF_VISIBLE(priv->media_sharing_switch);
       OFF_IF_VISIBLE(priv->personal_file_sharing_switch);
       OFF_IF_VISIBLE(priv->screen_sharing_switch);
+      OFF_IF_VISIBLE(priv->content_sharing_switch);
 
       gtk_switch_set_active (GTK_SWITCH (WID ("remote-login-switch")), FALSE);
     }
@@ -175,9 +181,16 @@ cc_sharing_panel_dispose (GObject *object)
       priv->screen_sharing_dialog = NULL;
     }
 
+  if (priv->content_sharing_dialog)
+    {
+      gtk_widget_destroy (priv->content_sharing_dialog);
+      priv->content_sharing_dialog = NULL;
+    }
+
   g_cancellable_cancel (priv->sharing_proxy_cancellable);
   g_clear_object (&priv->sharing_proxy_cancellable);
   g_clear_object (&priv->sharing_proxy);
+  g_clear_object (&priv->companion_app_avahi_helper_proxy);
 
   G_OBJECT_CLASS (cc_sharing_panel_parent_class)->dispose (object);
 }
@@ -653,6 +666,136 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
                                            WID ("media-sharing-status-label"));
 }
 
+static void
+content_sharing_switch_active_changed_cb (GtkSwitch *widget,
+                                          GParamSpec *pspec,
+                                          CcSharingPanel *self)
+{
+  g_autoptr(GError) error = NULL;
+
+  if (gtk_switch_get_active (widget))
+    {
+      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);
+    }
+  else
+    {
+      g_dbus_proxy_call_sync (self->priv->companion_app_avahi_helper_proxy,
+                              "ExitDiscoverableMode",
+                              NULL,
+                              G_DBUS_CALL_FLAGS_NONE, -1,
+                              NULL, &error);
+    }
+
+  if (error)
+    g_critical ("Unable to set the enabled state of content sharing: %s", error->message);
+}
+
+static void
+on_content_sharing_proxy_properties_changed (GDBusProxy *proxy,
+                                             GVariant *changed_properties,
+                                             GStrv invalidated_properties,
+                                             CcSharingPanel *self)
+{
+  g_autoptr(GVariant) discoverable_prop = NULL;
+  gboolean content_sharing_enabled;
+
+  discoverable_prop = g_variant_lookup_value (changed_properties, "Discoverable", G_VARIANT_TYPE_BOOLEAN);
+  if (!discoverable_prop)
+    return;
+
+  content_sharing_enabled = g_variant_get_boolean (discoverable_prop);
+
+  gtk_switch_set_active (GTK_SWITCH (self->priv->content_sharing_switch), content_sharing_enabled);
+}
+
+static gboolean
+cc_sharing_panel_check_content_sharing_available (void)
+{
+  g_autoptr(GError)              error = NULL;
+  g_autoptr(FlatpakInstallation) installation = flatpak_installation_new_system (NULL, &error);
+  g_autoptr(FlatpakInstalledRef) ref = NULL;
+  gboolean ret = TRUE;
+
+  if (!installation)
+    {
+      g_message ("Unexpected error occurred when loading flatpak installation: %s", error->message);
+      return FALSE;
+    }
+
+  ref = flatpak_installation_get_installed_ref (installation,
+                                                FLATPAK_REF_KIND_APP,
+                                                "com.endlessm.CompanionAppService",
+                                                NULL,
+                                                NULL,
+                                                NULL,
+                                                &error);
+
+  if (!ref)
+    {
+      if (!g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED))
+        g_message ("Unexpected error occurred when checking flatpak installation: %s", error->message);
+
+      ret = FALSE;
+    }
+
+  return ret;
+}
+
+static void
+cc_sharing_panel_setup_content_sharing_dialog (CcSharingPanel *self)
+{
+  CcSharingPanelPrivate *priv = self->priv;
+  gboolean content_sharing_enabled;
+  g_autoptr(GVariant) value = NULL;
+  g_autoptr(GError) error = NULL;
+  GtkWidget *content_sharing_button = GTK_WIDGET (WID ("content-sharing-button"));
+
+  self->priv->companion_app_avahi_helper_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                                                G_DBUS_PROXY_FLAGS_NONE,
+                                                                                NULL,
+                                                                                
"com.endlessm.CompanionAppServiceAvahiHelper",
+                                                                                
"/com/endlessm/CompanionAppServiceAvahiHelper",
+                                                                                
"com.endlessm.CompanionApp.AvahiHelper",
+                                                                                NULL, &error);
+  if (error)
+    {
+      g_critical ("Unable to create a DBus proxy for the companion app avahi helper: %s", error->message);
+
+      /* Return early, since there's no way we can set up the dialog from here */
+      return;
+    }
+
+  g_signal_connect (self->priv->companion_app_avahi_helper_proxy, "g-properties-changed",
+                    G_CALLBACK (on_content_sharing_proxy_properties_changed), self);
+
+  value = g_dbus_proxy_get_cached_property (self->priv->companion_app_avahi_helper_proxy, "Discoverable");
+  content_sharing_enabled = g_variant_get_boolean (value);
+
+  /* Set up the switch */
+  self->priv->content_sharing_switch = gtk_switch_new ();
+  gtk_widget_set_can_focus (self->priv->content_sharing_switch, TRUE);
+  gtk_widget_set_halign (self->priv->content_sharing_switch, GTK_ALIGN_END);
+  gtk_widget_set_valign (self->priv->content_sharing_switch, GTK_ALIGN_CENTER);
+  gtk_header_bar_pack_start (GTK_HEADER_BAR (WID ("content-sharing-headerbar")),
+                             self->priv->content_sharing_switch);
+  gtk_widget_show (self->priv->content_sharing_switch);
+
+  cc_sharing_panel_bind_switch_to_label (self,
+                                         self->priv->content_sharing_switch,
+                                         WID ("content-sharing-status-label"));
+
+  /* If everything was successful, show the row */
+  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);
+}
+
 static gboolean
 cc_sharing_panel_label_activate_link (GtkLabel *label,
                                       gchar    *uri,
@@ -1183,6 +1326,7 @@ cc_sharing_panel_init (CcSharingPanel *self)
       "personal-file-sharing-dialog",
       "remote-login-dialog",
       "screen-sharing-dialog",
+      "content-sharing-dialog",
       NULL };
 
   g_resources_register (cc_sharing_get_resource ());
@@ -1210,6 +1354,7 @@ cc_sharing_panel_init (CcSharingPanel *self)
   priv->remote_login_dialog = WID ("remote-login-dialog");
   priv->remote_login_cancellable = g_cancellable_new ();
   priv->screen_sharing_dialog = WID ("screen-sharing-dialog");
+  priv->content_sharing_dialog = WID ("content-sharing-dialog");
 
   g_signal_connect (priv->media_sharing_dialog, "response",
                     G_CALLBACK (gtk_widget_hide), NULL);
@@ -1219,6 +1364,8 @@ cc_sharing_panel_init (CcSharingPanel *self)
                     G_CALLBACK (gtk_widget_hide), NULL);
   g_signal_connect (priv->screen_sharing_dialog, "response",
                     G_CALLBACK (gtk_widget_hide), NULL);
+  g_signal_connect (priv->content_sharing_dialog, "response",
+                    G_CALLBACK (gtk_widget_hide), NULL);
 
   gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (WID ("main-list-box")),
                                              TRUE);
@@ -1250,6 +1397,10 @@ cc_sharing_panel_init (CcSharingPanel *self)
                                  sharing_proxy_ready,
                                  self);
 
+  /* content sharing */
+  if (cc_sharing_panel_check_content_sharing_available ())
+    cc_sharing_panel_setup_content_sharing_dialog (self);
+
   /* make sure the hostname entry isn't focused by default */
   g_signal_connect_swapped (self, "map", G_CALLBACK (gtk_widget_grab_focus),
                             WID ("main-list-box"));
diff --git a/panels/sharing/sharing.ui b/panels/sharing/sharing.ui
index 8d10811..6ca58e5 100644
--- a/panels/sharing/sharing.ui
+++ b/panels/sharing/sharing.ui
@@ -256,6 +256,46 @@
                     </child>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkListBoxRow" id="content-sharing-button">
+                    <property name="visible">False</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="border-width">12</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="halign">start</property>
+                            <property name="hexpand">True</property>
+                            <property translatable="yes" name="label">_Content Sharing</property>
+                            <property name="use_underline">True</property>
+                            <property name="mnemonic_widget">content-sharing-button</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="content-sharing-status-label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label">Off</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
@@ -858,4 +898,65 @@
       </object>
     </child>
   </object>
+  <object class="GtkDialog" id="content-sharing-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Content Sharing</property>
+    <property name="resizable">False</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="orientation">horizontal</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Content Sharing allows users to view content 
installed on this computer on Android Devices on the same Network.</property>
+                <property name="max-width-chars">50</property>
+                <property name="wrap">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="content-sharing-headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="title" translatable="yes">Content Sharing</property>
+        <property name="show_close_button">True</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]