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



commit 598bcd76c6a40671e474144b2334508e2e3b7bb0
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 more connections and their type is not limited.  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 |   44 ++++++++++++++++++
 src/connection-editor/page-general.c     |   73 +++++++++++++++++++++++++++++-
 2 files changed, 116 insertions(+), 1 deletions(-)
---
diff --git a/src/connection-editor/ce-page-general.ui b/src/connection-editor/ce-page-general.ui
index dcd8b6b..bb6c684 100644
--- a/src/connection-editor/ce-page-general.ui
+++ b/src/connection-editor/ce-page-general.ui
@@ -1,6 +1,14 @@
 <?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>
@@ -38,5 +46,41 @@
         <property name="y_options"></property>
       </packing>
     </child>
+    <child>
+      <object class="GtkLabel" id="dependent_vpn_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Dependent VPN connection:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">dependent_vpn_combo</property>
+      </object>
+      <packing>
+        <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="GtkComboBox" id="dependent_vpn_combo">
+        <property name="visible">True</property>
+        <property name="can_focus">False</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="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">2</property>
+        <property name="bottom_attach">3</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
   </object>
 </interface>
diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c
index 0cc7dd3..db3d9a8 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,9 @@ typedef struct {
 #else
 	GtkComboBox *firewall_zone;
 #endif
+
+	GtkComboBox *dependent_vpn;
+	GtkListStore *dependent_vpn_store;
 } CEPageGeneralPrivate;
 
 /* TRANSLATORS: Default zone set for firewall, when no zone is selected */
@@ -46,6 +50,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 +80,24 @@ 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 = 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
@@ -122,8 +150,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,6 +197,31 @@ populate_ui (CEPageGeneral *self)
 		gtk_widget_set_sensitive (GTK_WIDGET (priv->firewall_zone), FALSE);
 	}
 	g_strfreev (zones);
+
+	/* Add 'None' item, so that user can choose no VPN */
+	gtk_list_store_append (priv->dependent_vpn_store, &iter);
+	gtk_list_store_set (priv->dependent_vpn_store, &iter, COL_ID, _("(None)"), COL_UUID, NULL, -1);
+
+	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);
+		idx++;
+
+		if (g_strcmp0 (vpn_uuid, uuid) == 0)
+			combo_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
@@ -180,6 +235,7 @@ 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);
+	g_signal_connect (priv->dependent_vpn, "changed", G_CALLBACK (stuff_changed), self);
 }
 
 CEPage *
@@ -210,6 +266,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 +284,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 +298,15 @@ ui_to_setting (CEPageGeneral *self)
 	g_object_set (priv->setting, NM_SETTING_CONNECTION_ZONE, zone, NULL);
 
 	g_free (zone);
+
+	if (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 +333,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]