[gnome-control-center] network: teach the network panel about IPv6



commit c1fc40050afaa9e77dfefe32fd3a61c2482f603d
Author: Richard Hughes <richard hughsie com>
Date:   Thu Dec 16 20:42:40 2010 +0000

    network: teach the network panel about IPv6

 panels/network/cc-network-panel.c |  354 ++++++++++++++++++++++++++++++++++---
 panels/network/network.ui         |  108 +++++++++++-
 panels/network/panel-common.c     |   58 ++++++
 panels/network/panel-common.h     |    2 +
 4 files changed, 486 insertions(+), 36 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 32daca4..91db9e1 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -46,11 +46,16 @@ typedef struct {
 	CcNetworkPanel	*panel;
 	gchar		*active_access_point;
 	gchar		*device_id;
+	gchar		*ip4_config;
+	gchar		*ip6_config;
 	gchar		*modem_imei;
 	gchar		*operator_name;
 	gchar		*udi;
 	GDBusProxy	*proxy;
 	GDBusProxy	*proxy_additional;
+	GDBusProxy	*proxy_ip4;
+	GDBusProxy	*proxy_ip6;
+	guint		 device_add_refcount;
 	guint		 type;
 } PanelDeviceItem;
 
@@ -268,10 +273,16 @@ panel_free_device_item (PanelDeviceItem *item)
 	g_object_unref (item->proxy);
 	if (item->proxy_additional != NULL)
 		g_object_unref (item->proxy_additional);
+	if (item->proxy_ip4 != NULL)
+		g_object_unref (item->proxy_ip4);
+	if (item->proxy_ip6 != NULL)
+		g_object_unref (item->proxy_ip6);
 	g_free (item->device_id);
 	g_free (item->active_access_point);
 	g_free (item->udi);
 	g_free (item->operator_name);
+	g_free (item->ip4_config);
+	g_free (item->ip6_config);
 	g_free (item->modem_imei);
 	g_free (item);
 }
@@ -500,7 +511,9 @@ panel_got_device_proxy_additional_cb (GObject *source_object, GAsyncResult *res,
 				   item);
 	}
 
-	panel_add_device_to_listview (item);
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
 out:
 	if (result != NULL)
 		g_variant_unref (result);
@@ -540,7 +553,9 @@ panel_get_registration_info_cb (GObject *source_object, GAsyncResult *res, gpoin
  * panel_got_device_proxy_modem_manager_gsm_network_cb:
  **/
 static void
-panel_got_device_proxy_modem_manager_gsm_network_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+panel_got_device_proxy_modem_manager_gsm_network_cb (GObject *source_object,
+						     GAsyncResult *res,
+						     gpointer user_data)
 {
 	GError *error = NULL;
 	GVariant *result = NULL;
@@ -566,7 +581,9 @@ panel_got_device_proxy_modem_manager_gsm_network_cb (GObject *source_object, GAs
 			   panel_get_registration_info_cb,
 			   item);
 
-	panel_add_device_to_listview (item);
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
 out:
 	if (result != NULL)
 		g_variant_unref (result);
@@ -577,7 +594,9 @@ out:
  * panel_got_device_proxy_modem_manager_cb:
  **/
 static void
-panel_got_device_proxy_modem_manager_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+panel_got_device_proxy_modem_manager_cb (GObject *source_object,
+					 GAsyncResult *res,
+					 gpointer user_data)
 {
 	GError *error = NULL;
 	GVariant *result = NULL;
@@ -593,6 +612,10 @@ panel_got_device_proxy_modem_manager_cb (GObject *source_object, GAsyncResult *r
 	/* get the IMEI */
 	result = g_dbus_proxy_get_cached_property (item->proxy_additional, "EquipmentIdentifier");
 	item->modem_imei = g_variant_dup_string (result, NULL);
+
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
 out:
 	if (result != NULL)
 		g_variant_unref (result);
@@ -614,16 +637,90 @@ panel_device_properties_changed_cb (GDBusProxy *proxy,
 	/* only refresh the selected device */
 	if (g_strcmp0 (priv->current_device, item->device_id) == 0)
 		panel_device_refresh_item_ui (item);
-//xxx
+}
+
+/**
+ * panel_got_device_proxy_ip4_cb:
+ **/
+static void
+panel_got_device_proxy_ip4_cb (GObject *source_object,
+			       GAsyncResult *res,
+			       gpointer user_data)
+{
+	GError *error = NULL;
+	GVariant *result = NULL;
+	PanelDeviceItem *item = (PanelDeviceItem *) user_data;
+
+	item->proxy_ip4 = g_dbus_proxy_new_for_bus_finish (res, &error);
+	if (item->proxy_ip4 == NULL) {
+		g_printerr ("Error creating ip4 proxy: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* get the Address */
+	result = g_dbus_proxy_get_cached_property (item->proxy_ip4, "Addresses");
+	//Addresses = array of (array of uint32)
+	//Routes =  array of (array of uint32)
+	//Domains =  array of string
+	//Nameservers = array of uint32
+	//WinsServers = array of uint32
+
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return;
+}
+
+/**
+ * panel_got_device_proxy_ip6_cb:
+ **/
+static void
+panel_got_device_proxy_ip6_cb (GObject *source_object,
+			       GAsyncResult *res,
+			       gpointer user_data)
+{
+	GError *error = NULL;
+	GVariant *result = NULL;
+	PanelDeviceItem *item = (PanelDeviceItem *) user_data;
+
+	item->proxy_ip6 = g_dbus_proxy_new_for_bus_finish (res, &error);
+	if (item->proxy_ip6 == NULL) {
+		g_printerr ("Error creating ip6 proxy: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* get the Address */
+	result = g_dbus_proxy_get_cached_property (item->proxy_ip6, "Addresses");
+	//Addresses = array of (struct of (array of (byte), uint32, array of (byte)))
+	//Routes = array of (struct of (array of (byte), uint32, array of (byte)))
+	//Nameservers = array of (array of byte)
+	//Domains = array of string
+
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
+out:
+	if (result != NULL)
+		g_variant_unref (result);
+	return;
 }
 
 /**
  * panel_got_device_proxy_cb:
  **/
 static void
-panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
+panel_got_device_proxy_cb (GObject *source_object,
+			   GAsyncResult *res,
+			   gpointer user_data)
 {
 	GError *error = NULL;
+	GVariant *variant_ip4 = NULL;
+	GVariant *variant_ip6 = NULL;
 	GVariant *variant_type = NULL;
 	GVariant *variant_udi = NULL;
 	PanelDeviceItem *item = (PanelDeviceItem *) user_data;
@@ -639,10 +736,43 @@ panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer u
 	variant_udi = g_dbus_proxy_get_cached_property (item->proxy, "Udi");
 	g_variant_get (variant_udi, "s", &item->udi);
 
+	/* get the IP object paths */
+	variant_ip4 = g_dbus_proxy_get_cached_property (item->proxy, "Ip4Config");
+	g_variant_get (variant_ip4, "o", &item->ip4_config);
+	variant_ip6 = g_dbus_proxy_get_cached_property (item->proxy, "Ip6Config");
+	g_variant_get (variant_ip6, "o", &item->ip6_config);
+
+	/* get the IP information */
+	if (g_strcmp0 (item->ip4_config, "/") != 0) {
+		item->device_add_refcount++;
+		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+					  G_DBUS_PROXY_FLAGS_NONE,
+					  NULL,
+					  "org.freedesktop.NetworkManager",
+					  item->ip4_config,
+					  "org.freedesktop.NetworkManager.IP4Config",
+					  item->panel->priv->cancellable,
+					  panel_got_device_proxy_ip4_cb,
+					  item);
+	}
+	if (g_strcmp0 (item->ip6_config, "/") != 0) {
+		item->device_add_refcount++;
+		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+					  G_DBUS_PROXY_FLAGS_NONE,
+					  NULL,
+					  "org.freedesktop.NetworkManager",
+					  item->ip6_config,
+					  "org.freedesktop.NetworkManager.IP6Config",
+					  item->panel->priv->cancellable,
+					  panel_got_device_proxy_ip6_cb,
+					  item);
+	}
+
 	/* get the additional interface for this device type */
 	variant_type = g_dbus_proxy_get_cached_property (item->proxy, "DeviceType");
 	g_variant_get (variant_type, "u", &item->type);
 	if (item->type == NM_DEVICE_TYPE_ETHERNET) {
+		item->device_add_refcount++;
 		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 					  G_DBUS_PROXY_FLAGS_NONE,
 					  NULL,
@@ -653,6 +783,7 @@ panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer u
 					  panel_got_device_proxy_additional_cb,
 					  item);
 	} else if (item->type == NM_DEVICE_TYPE_WIFI) {
+		item->device_add_refcount++;
 		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 					  G_DBUS_PROXY_FLAGS_NONE,
 					  NULL,
@@ -664,6 +795,7 @@ panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer u
 					  item);
 	} else if (item->type == NM_DEVICE_TYPE_GSM ||
 		   item->type == NM_DEVICE_TYPE_CDMA) {
+		item->device_add_refcount++;
 		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 					  G_DBUS_PROXY_FLAGS_NONE,
 					  NULL,
@@ -673,6 +805,7 @@ panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer u
 					  item->panel->priv->cancellable,
 					  panel_got_device_proxy_modem_manager_cb,
 					  item);
+		item->device_add_refcount++;
 		g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 					  G_DBUS_PROXY_FLAGS_NONE,
 					  NULL,
@@ -682,15 +815,21 @@ panel_got_device_proxy_cb (GObject *source_object, GAsyncResult *res, gpointer u
 					  item->panel->priv->cancellable,
 					  panel_got_device_proxy_modem_manager_gsm_network_cb,
 					  item);
-	} else {
-		panel_add_device_to_listview (item);
 	}
 
+	/* add device if there are no more pending actions */
+	if (--item->device_add_refcount == 0)
+		panel_add_device_to_listview (item);
+
 	/* we want to update the UI */
 	g_signal_connect (item->proxy, "g-properties-changed",
 			  G_CALLBACK (panel_device_properties_changed_cb),
 			  item);
 out:
+	if (variant_ip4 != NULL)
+		g_variant_unref (variant_ip4);
+	if (variant_ip6 != NULL)
+		g_variant_unref (variant_ip6);
 	if (variant_udi != NULL)
 		g_variant_unref (variant_udi);
 	if (variant_type != NULL)
@@ -715,6 +854,7 @@ panel_add_device (CcNetworkPanel *panel, const gchar *device_id)
 	g_ptr_array_add (panel->priv->devices, item);
 
 	/* get initial device state */
+	item->device_add_refcount++;
 	g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 				  G_DBUS_PROXY_FLAGS_NONE,
 				  NULL,
@@ -975,38 +1115,168 @@ static void
 panel_set_label_for_variant_ipv4 (GtkWidget *widget, GVariant *variant)
 {
 	gchar *ip_str;
-	guint32 ip;
-
-	g_variant_get (variant, "u", &ip);
-	ip_str = g_strdup_printf ("%i.%i.%i.%i",
-				    ip & 0x000000ff,
-				   (ip & 0x0000ff00) / 0x100,
-				   (ip & 0x00ff0000) / 0x10000,
-				   (ip & 0xff000000) / 0x1000000);
+	ip_str = panel_ipv4_to_string (variant);
 	gtk_label_set_label (GTK_LABEL (widget), ip_str);
 	g_free (ip_str);
 }
 
 /**
+ * panel_set_label_for_variant_ipv4_array:
+ *
+ * This is some crazy shit. NM sends us the following data type:
+ * "array of [array of [uint32]]"
+ **/
+static void
+panel_set_label_for_variant_ipv4_array (GtkWidget *widget, GVariant *variant)
+{
+	gchar *tmp;
+	gsize len;
+	GString *string;
+	guint i;
+	GVariantIter iter;
+	GVariant *outer;
+	GVariant *value;
+
+	string = g_string_new ("");
+
+	/* get an iter of the outer array */
+	len = g_variant_iter_init (&iter, variant);
+	if (len != 1) {
+		g_warning ("invalid ipv4 address?!");
+		goto out;
+	}
+
+	/* unwrap the outer array */
+	outer = g_variant_iter_next_value (&iter);
+	while (outer != NULL) {
+
+		/* unwrap the inner array */
+		len = g_variant_n_children (outer);
+		if (len == 0) {
+			g_warning ("invalid ipv4 address on inner?!");
+			goto out;
+		}
+		for (i=0; i<len; i++) {
+			value = g_variant_get_child_value (outer, i);
+			tmp = panel_ipv4_to_string (value);
+
+			/* ignore invalid entries: TODO why? */
+			if (g_str_has_suffix (tmp, ".0")) {
+				g_debug ("ignoring IP %s", tmp);
+			} else {
+				g_debug ("got IP %s", tmp);
+				g_string_append_printf (string,
+							"%s, ",
+							tmp);
+			}
+			g_free (tmp);
+			g_variant_unref (value);
+		}
+		outer = g_variant_iter_next_value (&iter);
+	}
+
+	/* remove trailing space comma */
+	if (string->len > 2)
+		g_string_set_size (string, string->len - 2);
+
+	/* set label */
+	gtk_label_set_label (GTK_LABEL (widget), string->str);
+out:
+	g_string_free (string, TRUE);
+}
+
+/**
+ * panel_set_label_for_variant_ipv4_array:
+ *
+ * This is some crazy shit. NM sends us the following data type:
+ * "array of [struct of (array of [byte], uint32, array of [byte])]"
+ **/
+static void
+panel_set_label_for_variant_ipv6_array (GtkWidget *widget, GVariant *variant)
+{
+	GString *string;
+	gchar *tmp;
+	GVariant *outer;
+	GVariantIter iter;
+	gsize len;
+	GVariant *address;
+	guint32 prefix;
+
+	string = g_string_new ("");
+
+	/* get an iter of the outer array */
+	len = g_variant_iter_init (&iter, variant);
+	if (len == 0) {
+		g_warning ("invalid ipv6 address?!");
+		goto out;
+	}
+
+	/* unwrap the outer array */
+	outer = g_variant_iter_next_value (&iter);
+	while (outer != NULL) {
+
+		/* format the address and add to the string */
+		address = g_variant_get_child_value (outer, 0);
+		tmp = panel_ipv6_to_string (address);
+		g_variant_get_child (outer, 1, "u", &prefix);
+		g_string_append_printf (string, "%s/%i, ", tmp, prefix);
+
+		outer = g_variant_iter_next_value (&iter);
+	}
+
+	/* remove trailing space comma */
+	if (string->len > 2)
+		g_string_set_size (string, string->len - 2);
+
+	/* set label */
+	gtk_label_set_label (GTK_LABEL (widget), string->str);
+out:
+	g_string_free (string, TRUE);
+}
+
+/**
  * panel_populate_wired_device:
  **/
 static void
 panel_populate_wired_device (PanelDeviceItem *item)
 {
 	GtkWidget *widget;
-	GVariant *ip4;
+	GVariant *ip4 = NULL;
+	GVariant *ip6 = NULL;
 	GVariant *hw_address;
 	GVariant *speed;
 	CcNetworkPanelPrivate *priv = item->panel->priv;
 
-	/* set IP */
-	ip4 = g_dbus_proxy_get_cached_property (item->proxy, "Ip4Address");
+	/* set IPv6 */
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
-						     "label_wired_ip"));
-	panel_set_label_for_variant_ipv4 (widget, ip4);
+						     "hbox_wired_ip6"));
+	if (item->proxy_ip6 != NULL) {
+		gtk_widget_show (widget);
+		ip6 = g_dbus_proxy_get_cached_property (item->proxy_ip6,
+							"Addresses");
+		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+							     "label_wired_ip6"));
+		panel_set_label_for_variant_ipv6_array (widget, ip6);
+	} else {
+		gtk_widget_hide (widget);
+	}
+
+	/* set IPv4 */
+	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+						     "label_wired_ip4"));
+	if (item->proxy_ip4 != NULL) {
+		ip4 = g_dbus_proxy_get_cached_property (item->proxy_ip4,
+							"Addresses");
+		panel_set_label_for_variant_ipv4_array (widget, ip4);
+	} else {
+		ip4 = g_dbus_proxy_get_cached_property (item->proxy,
+							"Ip4Address");
+		panel_set_label_for_variant_ipv4 (widget, ip4);
+	}
 
 	/* set MAC */
-	hw_address = g_dbus_proxy_get_cached_property (item->proxy_additional, "HwAddress");
+	hw_address = g_dbus_proxy_get_cached_property (item->proxy_additional,
+						       "HwAddress");
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
 						     "label_wired_mac"));
 	panel_set_label_for_variant_string (widget, hw_address);
@@ -1017,7 +1287,10 @@ panel_populate_wired_device (PanelDeviceItem *item)
 						     "label_wired_speed"));
 	panel_set_label_for_variant_speed (widget, speed);
 
-	g_variant_unref (ip4);
+	if (ip4 != NULL)
+		g_variant_unref (ip4);
+	if (ip6 != NULL)
+		g_variant_unref (ip6);
 	g_variant_unref (hw_address);
 	g_variant_unref (speed);
 }
@@ -1032,16 +1305,39 @@ panel_populate_wireless_device (PanelDeviceItem *item)
 	GVariant *bitrate;
 	GVariant *hw_address;
 	GVariant *ip4;
+	GVariant *ip6;
 	CcNetworkPanelPrivate *priv = item->panel->priv;
 
-	/* set IP */
-	ip4 = g_dbus_proxy_get_cached_property (item->proxy, "Ip4Address");
+	/* set IPv6 */
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
-						     "label_wireless_ip"));
-	panel_set_label_for_variant_ipv4 (widget, ip4);
+						     "hbox_wireless_ip6"));
+	if (item->proxy_ip6 != NULL) {
+		gtk_widget_show (widget);
+		ip6 = g_dbus_proxy_get_cached_property (item->proxy_ip6,
+							"Addresses");
+		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+							     "label_wireless_ip6"));
+		panel_set_label_for_variant_ipv6_array (widget, ip6);
+	} else {
+		gtk_widget_hide (widget);
+	}
+
+	/* set IPv4 */
+	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+						     "label_wireless_ip4"));
+	if (item->proxy_ip4 != NULL) {
+		ip4 = g_dbus_proxy_get_cached_property (item->proxy_ip4,
+							"Addresses");
+		panel_set_label_for_variant_ipv4_array (widget, ip4);
+	} else {
+		ip4 = g_dbus_proxy_get_cached_property (item->proxy,
+							"Ip4Address");
+		panel_set_label_for_variant_ipv4 (widget, ip4);
+	}
 
 	/* set MAC */
-	hw_address = g_dbus_proxy_get_cached_property (item->proxy_additional, "HwAddress");
+	hw_address = g_dbus_proxy_get_cached_property (item->proxy_additional,
+						       "HwAddress");
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
 						     "label_wireless_mac"));
 	panel_set_label_for_variant_string (widget, hw_address);
@@ -1053,6 +1349,8 @@ panel_populate_wireless_device (PanelDeviceItem *item)
 	panel_set_label_for_variant_bitrate (widget, bitrate);
 
 	g_variant_unref (ip4);
+	if (ip6 != NULL)
+		g_variant_unref (ip6);
 	g_variant_unref (hw_address);
 	g_variant_unref (bitrate);
 }
diff --git a/panels/network/network.ui b/panels/network/network.ui
index 68043ac..eaa26e8 100644
--- a/panels/network/network.ui
+++ b/panels/network/network.ui
@@ -240,7 +240,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkHBox" id="hbox19">
+                                  <object class="GtkHBox" id="hbox_wired_speed">
                                     <property name="visible">True</property>
                                     <property name="spacing">9</property>
                                     <child>
@@ -285,7 +285,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkHBox" id="hbox23">
+                                  <object class="GtkHBox" id="hbox_wired_ip4">
                                     <property name="visible">True</property>
                                     <property name="spacing">9</property>
                                     <child>
@@ -294,7 +294,7 @@
                                         <child>
                                           <object class="GtkLabel" id="label25">
                                             <property name="visible">True</property>
-                                            <property name="label" translatable="yes">IP Address:</property>
+                                            <property name="label" translatable="yes">IPv4 Address:</property>
                                           </object>
                                           <packing>
                                             <property name="expand">False</property>
@@ -311,7 +311,7 @@
                                       </packing>
                                     </child>
                                     <child>
-                                      <object class="GtkLabel" id="label_wired_ip">
+                                      <object class="GtkLabel" id="label_wired_ip4">
                                         <property name="visible">True</property>
                                         <property name="label">127.0.0.1</property>
                                         <property name="selectable">True</property>
@@ -329,6 +329,51 @@
                                     <property name="position">2</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <object class="GtkHBox" id="hbox_wired_ip6">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">9</property>
+                                    <child>
+                                      <object class="GtkHBox" id="hbox924">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <object class="GtkLabel" id="label925">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">IPv6 Address:</property>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="pack_type">end</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label_wired_ip6">
+                                        <property name="visible">True</property>
+                                        <property name="label">::1</property>
+                                        <property name="selectable">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">3</property>
+                                  </packing>
+                                </child>
                               </object>
                             </child>
                             <child type="tab">
@@ -481,7 +526,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkHBox" id="hbox13">
+                                  <object class="GtkHBox" id="hbox_wireless_ip4">
                                     <property name="visible">True</property>
                                     <property name="spacing">9</property>
                                     <child>
@@ -490,7 +535,7 @@
                                         <child>
                                           <object class="GtkLabel" id="label13">
                                             <property name="visible">True</property>
-                                            <property name="label" translatable="yes">IP Address:</property>
+                                            <property name="label" translatable="yes">IPv4 Address:</property>
                                           </object>
                                           <packing>
                                             <property name="expand">False</property>
@@ -507,7 +552,7 @@
                                       </packing>
                                     </child>
                                     <child>
-                                      <object class="GtkLabel" id="label_wireless_ip">
+                                      <object class="GtkLabel" id="label_wireless_ip4">
                                         <property name="visible">True</property>
                                         <property name="label">127.0.0.1</property>
                                         <property name="selectable">True</property>
@@ -526,6 +571,51 @@
                                   </packing>
                                 </child>
                                 <child>
+                                  <object class="GtkHBox" id="hbox_wireless_ip6">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">9</property>
+                                    <child>
+                                      <object class="GtkHBox" id="hbox914">
+                                        <property name="visible">True</property>
+                                        <child>
+                                          <object class="GtkLabel" id="label913">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">IPv6 Address:</property>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="pack_type">end</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label_wireless_ip6">
+                                        <property name="visible">True</property>
+                                        <property name="label">::1</property>
+                                        <property name="selectable">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">4</property>
+                                  </packing>
+                                </child>
+                                <child>
                                   <object class="GtkHBox" id="hbox15">
                                     <property name="visible">True</property>
                                     <property name="spacing">9</property>
@@ -567,7 +657,7 @@
                                   <packing>
                                     <property name="expand">False</property>
                                     <property name="fill">False</property>
-                                    <property name="position">4</property>
+                                    <property name="position">5</property>
                                   </packing>
                                 </child>
                               </object>
@@ -1468,6 +1558,7 @@
       <widget name="hbox41"/>
       <widget name="hbox39"/>
       <widget name="hbox24"/>
+      <widget name="hbox924"/>
       <widget name="hbox20"/>
       <widget name="hbox18"/>
       <widget name="hbox16"/>
@@ -1475,6 +1566,7 @@
       <widget name="hbox9"/>
       <widget name="hbox10"/>
       <widget name="hbox14"/>
+      <widget name="hbox914"/>
       <widget name="hbox22"/>
       <widget name="hbox26"/>
       <widget name="hbox28"/>
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index 07bac6c..2af8a35 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -205,3 +205,61 @@ panel_device_state_to_localized_string (guint type)
 	return value;
 }
 
+/**
+ * panel_ipv4_to_string:
+ **/
+gchar *
+panel_ipv4_to_string (GVariant *variant)
+{
+	gchar *ip_str;
+	guint32 ip;
+
+	g_variant_get (variant, "u", &ip);
+	ip_str = g_strdup_printf ("%i.%i.%i.%i",
+				    ip & 0x000000ff,
+				   (ip & 0x0000ff00) / 0x100,
+				   (ip & 0x00ff0000) / 0x10000,
+				   (ip & 0xff000000) / 0x1000000);
+	return ip_str;
+}
+
+/**
+ * panel_ipv6_to_string:
+ *
+ * Formats an 'ay' variant into a IPv6 address you recognise, e.g.
+ * "fe80::21c:bfff:fe81:e8de"
+ **/
+gchar *
+panel_ipv6_to_string (GVariant *variant)
+{
+	gchar tmp1;
+	gchar tmp2;
+	guint i = 0;
+	gboolean ret = FALSE;
+	GString *string;
+
+	if (g_variant_n_children (variant) != 16)
+		return NULL;
+
+	string = g_string_new ("");
+	for (i=0; i<16; i+=2) {
+		g_variant_get_child (variant, i+0, "y", &tmp1);
+		g_variant_get_child (variant, i+1, "y", &tmp2);
+		if (tmp1 == 0 && tmp2 == 0) {
+			if (!ret) {
+				g_string_append (string, ":");
+				ret = TRUE;
+			}
+		} else {
+			g_string_append_printf (string,
+						"%x%x%x%x:",
+						(tmp1 & 0xf0) / 16,
+						 tmp1 & 0x0f,
+						(tmp2 & 0xf0) / 16,
+						 tmp2 & 0x0f);
+			ret = FALSE;
+		}
+	}
+	g_string_set_size (string, string->len - 1);
+	return g_string_free (string, FALSE);
+}
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index 57a7c17..f903af1 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -60,6 +60,8 @@ const gchar	*panel_device_type_to_localized_string		(guint type);
 const gchar	*panel_device_type_to_sortable_string		(guint type);
 const gchar	*panel_ap_mode_to_localized_string		(guint mode);
 const gchar	*panel_device_state_to_localized_string		(guint type);
+gchar		*panel_ipv4_to_string				(GVariant *variant);
+gchar		*panel_ipv6_to_string				(GVariant *variant);
 
 G_END_DECLS
 



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