[network-manager-applet/general-page: 2/5] editor: add secondary connections to 'General' page



commit c557271d8f611d39686e8da7910c8091827260fb
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date:   Thu Oct 4 16:02:45 2012 -0400

    editor: add secondary connections to 'General' page
    
    We just use a combobox with VPN connections now, even if 'secondaries' support
    multiple  connections and their type is not limited to VPN.  That's because
    connecting to multiple VPNs doesn't work in NM. We should change the UI when
    multiple VPNs or other dependent connection types gets supported.

 src/connection-editor/ce-page-general.ui |   54 +++++++++++++++++-
 src/connection-editor/page-general.c     |   87 +++++++++++++++++++++++++++++-
 2 files changed, 137 insertions(+), 4 deletions(-)
---
diff --git a/src/connection-editor/ce-page-general.ui b/src/connection-editor/ce-page-general.ui
index 72c8e05..461432e 100644
--- a/src/connection-editor/ce-page-general.ui
+++ b/src/connection-editor/ce-page-general.ui
@@ -1,11 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
+  <object class="GtkListStore" id="dependent_vpn_model">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+      <!-- column-name gchararray1 -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkTable" id="GeneralPage">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
-    <property name="n_rows">1</property>
+    <property name="n_rows">3</property>
     <property name="n_columns">2</property>
     <property name="column_spacing">12</property>
     <property name="row_spacing">6</property>
@@ -19,10 +27,11 @@
       </object>
       <packing>
         <property name="right_attach">1</property>
-        <property name="top_attach">0</property>
-        <property name="bottom_attach">1</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
         <property name="x_options">GTK_FILL</property>
         <property name="y_options"></property>
+        <property name="y_padding">12</property>
       </packing>
     </child>
     <child>
@@ -33,8 +42,47 @@
       <packing>
         <property name="left_attach">1</property>
         <property name="right_attach">2</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkCheckButton" id="dependent_vpn_checkbox">
+        <property name="label" translatable="yes">Automatically connect to _VPN when using this connection</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">False</property>
+        <property name="use_underline">True</property>
+        <property name="xalign">0</property>
+        <property name="draw_indicator">True</property>
+      </object>
+      <packing>
+        <property name="right_attach">2</property>
         <property name="top_attach">0</property>
         <property name="bottom_attach">1</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkComboBox" id="dependent_vpn_combo">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">26</property>
+        <property name="model">dependent_vpn_model</property>
+        <child>
+          <object class="GtkCellRendererText" id="renderer1"/>
+          <attributes>
+            <attribute name="text">0</attribute>
+          </attributes>
+        </child>
+      </object>
+      <packing>
+        <property name="right_attach">2</property>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
         <property name="y_options"></property>
       </packing>
     </child>
diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c
index 0cc7dd3..57f6261 100644
--- a/src/connection-editor/page-general.c
+++ b/src/connection-editor/page-general.c
@@ -32,6 +32,7 @@ G_DEFINE_TYPE (CEPageGeneral, ce_page_general, CE_TYPE_PAGE)
 #define CE_PAGE_GENERAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_GENERAL, CEPageGeneralPrivate))
 
 typedef struct {
+	NMRemoteSettings *remote_settings;
 	NMSettingConnection *setting;
 
 #if GTK_CHECK_VERSION(2,24,0)
@@ -39,6 +40,10 @@ typedef struct {
 #else
 	GtkComboBox *firewall_zone;
 #endif
+
+	GtkToggleButton *dependent_vpn_checkbox;
+	GtkComboBox *dependent_vpn;
+	GtkListStore *dependent_vpn_store;
 } CEPageGeneralPrivate;
 
 /* TRANSLATORS: Default zone set for firewall, when no zone is selected */
@@ -46,6 +51,12 @@ typedef struct {
 #define FIREWALL_ZONE_TOOLTIP_AVAILBALE _("The zone defines the trust level of the connection. Default is not a regular zone, selecting it results in the use of the default zone set in the firewall. Only usable if firewalld is active.")
 #define FIREWALL_ZONE_TOOLTIP_UNAVAILBALE _("FirewallD is not running.")
 
+enum {
+	COL_ID,
+	COL_UUID,
+	N_COLUMNS
+};
+
 static void
 general_private_init (CEPageGeneral *self)
 {
@@ -70,6 +81,25 @@ general_private_init (CEPageGeneral *self)
 	/* Set mnemonic widget for device Firewall zone label */
 	label = GTK_LABEL (GTK_WIDGET (gtk_builder_get_object (builder, "firewall_zone_label")));
 	gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->firewall_zone));
+
+	/*-- Dependent VPN connection --*/
+	priv->dependent_vpn_checkbox = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "dependent_vpn_checkbox"));
+	priv->dependent_vpn = GTK_COMBO_BOX (gtk_builder_get_object (builder, "dependent_vpn_combo"));
+	priv->dependent_vpn_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "dependent_vpn_model"));
+}
+
+static void
+dispose (GObject *object)
+{
+	CEPageGeneral *self = CE_PAGE_GENERAL (object);
+	CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
+
+	if (priv->remote_settings) {
+		g_object_unref (priv->remote_settings);
+		priv->remote_settings = NULL;
+	}
+
+	G_OBJECT_CLASS (ce_page_general_parent_class)->dispose (object);
 }
 
 static void
@@ -78,6 +108,15 @@ stuff_changed (GtkWidget *w, gpointer user_data)
 	ce_page_changed (CE_PAGE (user_data));
 }
 
+static void
+vpn_checkbox_toggled (GtkToggleButton *button, gpointer user_data)
+{
+	CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (user_data);
+
+	gtk_widget_set_sensitive (GTK_WIDGET (priv->dependent_vpn), gtk_toggle_button_get_active (priv->dependent_vpn_checkbox));
+	ce_page_changed (CE_PAGE (user_data));
+}
+
 /* Get zones from firewalld */
 static char **
 get_zones_from_firewall (void)
@@ -122,8 +161,10 @@ populate_ui (CEPageGeneral *self)
 	NMSettingConnection *setting = priv->setting;
 	char **zones;
 	char **zone_ptr;
-	const char *s_zone;
+	const char *s_zone, *vpn_uuid;
 	guint32 combo_idx = 0, idx;
+	GSList *con_list, *l;
+	GtkTreeIter iter;
 
 	s_zone = nm_setting_connection_get_zone (setting);
 	
@@ -167,12 +208,34 @@ populate_ui (CEPageGeneral *self)
 		gtk_widget_set_sensitive (GTK_WIDGET (priv->firewall_zone), FALSE);
 	}
 	g_strfreev (zones);
+
+	/* Secondary UUID (VPN) */
+	vpn_uuid = nm_setting_connection_get_secondary (setting, 0);
+	con_list = nm_remote_settings_list_connections (priv->remote_settings);
+	for (l = con_list, idx = 0, combo_idx = 0; l; l = l->next) {
+		const char *uuid = nm_connection_get_uuid (l->data);
+		const char *id = nm_connection_get_id (l->data);
+
+		if (!nm_connection_is_type (l->data, NM_SETTING_VPN_SETTING_NAME))
+			continue;
+
+		gtk_list_store_append (priv->dependent_vpn_store, &iter);
+		gtk_list_store_set (priv->dependent_vpn_store, &iter, COL_ID, id, COL_UUID, uuid, -1);
+		if (g_strcmp0 (vpn_uuid, uuid) == 0)
+			combo_idx = idx;
+		idx++;
+	}
+	g_slist_free (con_list);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->dependent_vpn), combo_idx);
+
+	stuff_changed (NULL, self);
 }
 
 static void
 finish_setup (CEPageGeneral *self, gpointer unused, GError *error, gpointer user_data)
 {
 	CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
+	gboolean any_dependent_vpn;
 
 	if (error)
 		return;
@@ -180,6 +243,12 @@ finish_setup (CEPageGeneral *self, gpointer unused, GError *error, gpointer user
 	populate_ui (self);
 
 	g_signal_connect (priv->firewall_zone, "changed", G_CALLBACK (stuff_changed), self);
+
+	any_dependent_vpn = !!nm_setting_connection_get_num_secondaries (priv->setting);
+	gtk_toggle_button_set_active (priv->dependent_vpn_checkbox, any_dependent_vpn);
+	g_signal_connect (priv->dependent_vpn_checkbox, "toggled", G_CALLBACK (vpn_checkbox_toggled), self);
+	gtk_widget_set_sensitive (GTK_WIDGET (priv->dependent_vpn), any_dependent_vpn);
+	g_signal_connect (priv->dependent_vpn, "changed", G_CALLBACK (stuff_changed), self);
 }
 
 CEPage *
@@ -210,6 +279,8 @@ ce_page_general_new (NMConnection *connection,
 	general_private_init (self);
 	priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
 
+	priv->remote_settings = g_object_ref (settings);
+
 	priv->setting = nm_connection_get_setting_connection (connection);
 	if (!priv->setting) {
 		priv->setting = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -226,6 +297,8 @@ ui_to_setting (CEPageGeneral *self)
 {
 	CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
 	char *zone;
+	char *uuid = NULL;
+	GtkTreeIter iter;
 
 #if GTK_CHECK_VERSION (2,24,0)
 	zone = gtk_combo_box_text_get_active_text (priv->firewall_zone);
@@ -238,6 +311,16 @@ ui_to_setting (CEPageGeneral *self)
 	g_object_set (priv->setting, NM_SETTING_CONNECTION_ZONE, zone, NULL);
 
 	g_free (zone);
+
+	if (   gtk_toggle_button_get_active (priv->dependent_vpn_checkbox)
+	    && gtk_combo_box_get_active_iter (priv->dependent_vpn, &iter))
+		gtk_tree_model_get (GTK_TREE_MODEL (priv->dependent_vpn_store), &iter,
+		                                    COL_UUID, &uuid, -1);
+
+	g_object_set (G_OBJECT (priv->setting), NM_SETTING_CONNECTION_SECONDARIES, NULL, NULL);
+	if (uuid)
+		nm_setting_connection_add_secondary (priv->setting, uuid);
+	g_free (uuid);
 }
 
 static gboolean
@@ -264,6 +347,8 @@ ce_page_general_class_init (CEPageGeneralClass *connection_class)
 	g_type_class_add_private (object_class, sizeof (CEPageGeneralPrivate));
 
 	/* virtual methods */
+	object_class->dispose = dispose;
+
 	parent_class->validate = validate;
 }
 



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