[gnome-control-center] network: Add option for connection sharing



commit dfb54d0cad4dda6bedbabf8f3b750c7e242f2b85
Author: Carlo Caione <carlo endlessm com>
Date:   Wed Jul 11 19:36:54 2018 +0100

    network: Add option for connection sharing
    
    Introduce a new IP{4,6} config method to allow sharing the default
    network (usually the Internet) through the wired interface.
    This is needed because the control-panel is lacking this feature backed
    by nm and currently the only way to enable the connection sharing is by
    using nm-connection-editor.

 panels/network/connection-editor/ce-page-ip4.c | 15 ++++++++++++++-
 panels/network/connection-editor/ce-page-ip6.c | 15 ++++++++++++++-
 panels/network/connection-editor/ip4-page.ui   | 16 +++++++++++++++-
 panels/network/connection-editor/ip6-page.ui   | 14 ++++++++++++++
 4 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-ip4.c b/panels/network/connection-editor/ce-page-ip4.c
index 17d490f05..96742b8d8 100644
--- a/panels/network/connection-editor/ce-page-ip4.c
+++ b/panels/network/connection-editor/ce-page-ip4.c
@@ -53,6 +53,7 @@ struct _CEPageIP4
         GtkBox            *routes_box;
         GtkSizeGroup      *routes_metric_sizegroup;
         GtkSizeGroup      *routes_sizegroup;
+        GtkRadioButton    *shared_radio;
 
         NMSettingIPConfig *setting;
 
@@ -85,7 +86,8 @@ method_changed (CEPageIP4 *self)
         gboolean dns_enabled;
         gboolean routes_enabled;
 
-        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio))) {
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio)) ||
+            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio))) {
                 addr_enabled = FALSE;
                 dns_enabled = FALSE;
                 routes_enabled = FALSE;
@@ -521,6 +523,11 @@ connect_ip4_page (CEPageIP4 *self)
                                 self->content_box, "sensitive",
                                 G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
 
+        g_signal_connect_swapped (self->shared_radio, "notify::active", G_CALLBACK (ce_page_changed), self);
+        g_object_bind_property (self->shared_radio, "active",
+                                self->content_box, "sensitive",
+                                G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
         method = IP4_METHOD_AUTO;
         if (g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0) {
                 method = IP4_METHOD_LINK_LOCAL;
@@ -551,6 +558,9 @@ connect_ip4_page (CEPageIP4 *self)
         case IP4_METHOD_MANUAL:
                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->manual_radio), TRUE);
                 break;
+        case IP4_METHOD_SHARED:
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->shared_radio), TRUE);
+                break;
         case IP4_METHOD_DISABLED:
                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->disabled_radio), TRUE);
                 break;
@@ -612,6 +622,8 @@ ui_to_setting (CEPageIP4 *self)
                 method = NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL;
         else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->manual_radio)))
                 method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
+        else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio)))
+                method = NM_SETTING_IP4_CONFIG_METHOD_SHARED;
 
         addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
         if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
@@ -887,6 +899,7 @@ ce_page_ip4_class_init (CEPageIP4Class *klass)
         gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_box);
         gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_metric_sizegroup);
         gtk_widget_class_bind_template_child (widget_class, CEPageIP4, routes_sizegroup);
+        gtk_widget_class_bind_template_child (widget_class, CEPageIP4, shared_radio);
 }
 
 static void
diff --git a/panels/network/connection-editor/ce-page-ip6.c b/panels/network/connection-editor/ce-page-ip6.c
index 7775f8c95..6a27200c8 100644
--- a/panels/network/connection-editor/ce-page-ip6.c
+++ b/panels/network/connection-editor/ce-page-ip6.c
@@ -55,6 +55,7 @@ struct _CEPageIP6
         GtkBox            *routes_box;
         GtkSizeGroup      *routes_metric_sizegroup;
         GtkSizeGroup      *routes_sizegroup;
+        GtkRadioButton    *shared_radio;
 
         NMSettingIPConfig *setting;
 
@@ -88,7 +89,8 @@ method_changed (CEPageIP6 *self)
         gboolean dns_enabled;
         gboolean routes_enabled;
 
-        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio))) {
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->disabled_radio)) ||
+            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio))) {
                 addr_enabled = FALSE;
                 dns_enabled = FALSE;
                 routes_enabled = FALSE;
@@ -482,6 +484,11 @@ connect_ip6_page (CEPageIP6 *self)
                                 self->content_box, "sensitive",
                                 G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
 
+        g_signal_connect_swapped (self->shared_radio, "notify::active", G_CALLBACK (ce_page_changed), self);
+        g_object_bind_property (self->shared_radio, "active",
+                                self->content_box, "sensitive",
+                                G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
         method = IP6_METHOD_AUTO;
         if (g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
                 method = IP6_METHOD_DHCP;
@@ -519,6 +526,9 @@ connect_ip6_page (CEPageIP6 *self)
         case IP6_METHOD_MANUAL:
                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->manual_radio), TRUE);
                 break;
+        case IP6_METHOD_SHARED:
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->shared_radio), TRUE);
+                break;
         case IP6_METHOD_IGNORE:
                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->disabled_radio), TRUE);
                 break;
@@ -552,6 +562,8 @@ ui_to_setting (CEPageIP6 *self)
                 method = NM_SETTING_IP6_CONFIG_METHOD_DHCP;
         else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->automatic_radio)))
                 method = NM_SETTING_IP6_CONFIG_METHOD_AUTO;
+        else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->shared_radio)))
+                method = NM_SETTING_IP6_CONFIG_METHOD_SHARED;
 
         nm_setting_ip_config_clear_addresses (self->setting);
         if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
@@ -810,6 +822,7 @@ ce_page_ip6_class_init (CEPageIP6Class *klass)
         gtk_widget_class_bind_template_child (widget_class, CEPageIP6, routes_box);
         gtk_widget_class_bind_template_child (widget_class, CEPageIP6, routes_metric_sizegroup);
         gtk_widget_class_bind_template_child (widget_class, CEPageIP6, routes_sizegroup);
+        gtk_widget_class_bind_template_child (widget_class, CEPageIP6, shared_radio);
 }
 
 static void
diff --git a/panels/network/connection-editor/ip4-page.ui b/panels/network/connection-editor/ip4-page.ui
index fe75410f3..60f9b30c7 100644
--- a/panels/network/connection-editor/ip4-page.ui
+++ b/panels/network/connection-editor/ip4-page.ui
@@ -92,6 +92,20 @@
                 <property name="left-attach">2</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkRadioButton" id="shared_radio">
+                <property name="label" translatable="yes">Shared to other computers</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">automatic_radio</property>
+              </object>
+              <packing>
+                <property name="top-attach">2</property>
+                <property name="left-attach">1</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkBox" id="content_box">
                 <property name="visible">True</property>
@@ -397,7 +411,7 @@
                 </child>
               </object>
               <packing>
-                <property name="top-attach">2</property>
+                <property name="top-attach">3</property>
                 <property name="left-attach">0</property>
                 <property name="width">3</property>
               </packing>
diff --git a/panels/network/connection-editor/ip6-page.ui b/panels/network/connection-editor/ip6-page.ui
index fcee0c7d6..ed3f21141 100644
--- a/panels/network/connection-editor/ip6-page.ui
+++ b/panels/network/connection-editor/ip6-page.ui
@@ -106,6 +106,20 @@
                 <property name="left-attach">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkRadioButton" id="shared_radio">
+                <property name="label" translatable="yes">Shared to other computers</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">automatic_radio</property>
+              </object>
+              <packing>
+                <property name="top-attach">2</property>
+                <property name="left-attach">2</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkBox" id="content_box">
                 <property name="visible">True</property>


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