[gnome-control-center] network: add support for showing bond slaves
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: add support for showing bond slaves
- Date: Mon, 22 Oct 2012 12:55:13 +0000 (UTC)
commit 8ba8f2e033326acbc234a2c0848921aa342b8a0c
Author: Dan Winship <danw gnome org>
Date: Thu Oct 18 07:23:42 2012 -0400
network: add support for showing bond slaves
https://bugzilla.gnome.org/show_bug.cgi?id=677147
panels/network/Makefile.am | 2 +
panels/network/cc-network-panel.c | 49 +++++++----
panels/network/cc-network-panel.h | 2 +
panels/network/net-device-bond.c | 170 ++++++++++++++++++++++++++++++++++++
panels/network/net-device-bond.h | 58 ++++++++++++
panels/network/net-device-simple.c | 33 +++++++
panels/network/net-device-simple.h | 4 +
panels/network/network-simple.ui | 3 +-
8 files changed, 303 insertions(+), 18 deletions(-)
---
diff --git a/panels/network/Makefile.am b/panels/network/Makefile.am
index 28071a1..4b93b7d 100644
--- a/panels/network/Makefile.am
+++ b/panels/network/Makefile.am
@@ -28,6 +28,8 @@ libnetwork_la_SOURCES = \
net-device-ethernet.h \
net-device-mobile.c \
net-device-mobile.h \
+ net-device-bond.c \
+ net-device-bond.h \
net-vpn.c \
net-vpn.h \
net-proxy.c \
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 4fa7479..3139a57 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -35,6 +35,7 @@
#include "net-device-mobile.h"
#include "net-device-wifi.h"
#include "net-device-ethernet.h"
+#include "net-device-bond.h"
#include "net-object.h"
#include "net-proxy.h"
#include "net-vpn.h"
@@ -383,40 +384,51 @@ panel_refresh_killswitch_visibility (CcNetworkPanel *panel)
show_flight_toggle);
}
-static void
-panel_refresh_device_titles (CcNetworkPanel *panel)
+GPtrArray *
+cc_network_panel_get_devices (CcNetworkPanel *panel)
{
- GPtrArray *ndarray, *nmdarray;
- NetDevice **devices;
- NMDevice **nm_devices;
- gchar **titles;
- gint i, num_devices;
- NetObject *object;
- GtkTreeIter iter;
+ GPtrArray *devices;
GtkTreeModel *model;
+ GtkTreeIter iter;
+ NetObject *object;
+
+ devices = g_ptr_array_new_with_free_func (g_object_unref);
model = GTK_TREE_MODEL (gtk_builder_get_object (panel->priv->builder,
"liststore_devices"));
if (!gtk_tree_model_get_iter_first (model, &iter))
- return;
- ndarray = g_ptr_array_new_with_free_func (g_object_unref);
- nmdarray = g_ptr_array_new ();
+ return devices;
+
do {
gtk_tree_model_get (model, &iter,
PANEL_DEVICES_COLUMN_OBJECT, &object,
-1);
- if (NET_IS_DEVICE (object)) {
- g_ptr_array_add (ndarray, object);
- g_ptr_array_add (nmdarray, net_device_get_nm_device (NET_DEVICE (object)));
- }
+ if (NET_IS_DEVICE (object))
+ g_ptr_array_add (devices, object);
} while (gtk_tree_model_iter_next (model, &iter));
+ return devices;
+}
+
+static void
+panel_refresh_device_titles (CcNetworkPanel *panel)
+{
+ GPtrArray *ndarray, *nmdarray;
+ NetDevice **devices;
+ NMDevice **nm_devices;
+ gchar **titles;
+ gint i, num_devices;
+
+ ndarray = cc_network_panel_get_devices (panel);
if (!ndarray->len) {
g_ptr_array_free (ndarray, TRUE);
- g_ptr_array_free (nmdarray, TRUE);
return;
}
+ nmdarray = g_ptr_array_new ();
+ for (i = 0; i < ndarray->len; i++)
+ g_ptr_array_add (nmdarray, net_device_get_nm_device (ndarray->pdata[i]));
+
devices = (NetDevice **)ndarray->pdata;
nm_devices = (NMDevice **)nmdarray->pdata;
num_devices = ndarray->len;
@@ -550,6 +562,9 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
case NM_DEVICE_TYPE_WIFI:
device_g_type = NET_TYPE_DEVICE_WIFI;
break;
+ case NM_DEVICE_TYPE_BOND:
+ device_g_type = NET_TYPE_DEVICE_BOND;
+ break;
default:
device_g_type = NET_TYPE_DEVICE_SIMPLE;
break;
diff --git a/panels/network/cc-network-panel.h b/panels/network/cc-network-panel.h
index d9b08fb..a9bbd8a 100644
--- a/panels/network/cc-network-panel.h
+++ b/panels/network/cc-network-panel.h
@@ -67,6 +67,8 @@ GType cc_network_panel_get_type (void) G_GNUC_CONST;
void cc_network_panel_register (GIOModule *module);
+GPtrArray *cc_network_panel_get_devices (CcNetworkPanel *panel);
+
G_END_DECLS
#endif /* _CC_NETWORK_PANEL_H */
diff --git a/panels/network/net-device-bond.c b/panels/network/net-device-bond.c
new file mode 100644
index 0000000..9df0538
--- /dev/null
+++ b/panels/network/net-device-bond.c
@@ -0,0 +1,170 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include <nm-client.h>
+#include <nm-device.h>
+#include <nm-device-bond.h>
+#include <nm-remote-connection.h>
+
+#include "panel-common.h"
+#include "cc-network-panel.h"
+
+#include "net-device-bond.h"
+
+#define NET_DEVICE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_DEVICE_BOND, NetDeviceBondPrivate))
+
+struct _NetDeviceBondPrivate {
+ char *slaves;
+};
+
+enum {
+ PROP_0,
+ PROP_SLAVES,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (NetDeviceBond, net_device_bond, NET_TYPE_DEVICE_SIMPLE)
+
+static void
+net_device_bond_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NetDeviceBond *device_bond = NET_DEVICE_BOND (object);
+ NetDeviceBondPrivate *priv = device_bond->priv;
+
+ switch (prop_id) {
+ case PROP_SLAVES:
+ g_value_set_string (value, priv->slaves);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (device_bond, prop_id, pspec);
+ break;
+
+ }
+}
+
+static void
+nm_device_slaves_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ NetDeviceBond *device_bond = NET_DEVICE_BOND (user_data);
+ NetDeviceBondPrivate *priv = device_bond->priv;
+ NMDeviceBond *nm_device = NM_DEVICE_BOND (object);
+ CcNetworkPanel *panel;
+ GPtrArray *net_devices;
+ NetDevice *net_device;
+ NMDevice *slave;
+ const GPtrArray *slaves;
+ int i, j;
+ GString *str;
+
+ g_free (priv->slaves);
+
+ slaves = nm_device_bond_get_slaves (nm_device);
+ if (!slaves) {
+ priv->slaves = g_strdup ("(none)");
+ g_object_notify (G_OBJECT (device_bond), "slaves");
+ return;
+ }
+
+ panel = net_object_get_panel (NET_OBJECT (device_bond));
+ net_devices = cc_network_panel_get_devices (panel);
+
+ str = g_string_new (NULL);
+ for (i = 0; i < slaves->len; i++) {
+ if (i > 0)
+ g_string_append (str, ", ");
+ slave = slaves->pdata[i];
+
+ for (j = 0; j < net_devices->len; j++) {
+ net_device = net_devices->pdata[j];
+ if (slave == net_device_get_nm_device (net_device)) {
+ g_string_append (str, net_object_get_title (NET_OBJECT (net_device)));
+ break;
+ }
+ }
+ if (j == net_devices->len)
+ g_string_append (str, nm_device_get_iface (slave));
+ }
+ priv->slaves = g_string_free (str, FALSE);
+ g_object_notify (G_OBJECT (device_bond), "slaves");
+}
+
+static void
+net_device_bond_constructed (GObject *object)
+{
+ NetDeviceBond *device_bond = NET_DEVICE_BOND (object);
+ NMDevice *nm_device;
+
+ nm_device = net_device_get_nm_device (NET_DEVICE (device_bond));
+ if (nm_device) {
+ g_signal_connect (nm_device, "notify::slaves",
+ G_CALLBACK (nm_device_slaves_changed), device_bond);
+ nm_device_slaves_changed (G_OBJECT (nm_device), NULL, device_bond);
+ net_device_simple_add_row (NET_DEVICE_SIMPLE (device_bond),
+ _("Bond slaves"), "slaves");
+ }
+
+ G_OBJECT_CLASS (net_device_bond_parent_class)->constructed (object);
+}
+
+static void
+net_device_bond_finalize (GObject *object)
+{
+ NetDeviceBond *device_bond = NET_DEVICE_BOND (object);
+ NetDeviceBondPrivate *priv = device_bond->priv;
+
+ g_free (priv->slaves);
+
+ G_OBJECT_CLASS (net_device_bond_parent_class)->finalize (object);
+}
+
+static void
+net_device_bond_class_init (NetDeviceBondClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
+
+ object_class->constructed = net_device_bond_constructed;
+ object_class->finalize = net_device_bond_finalize;
+ object_class->get_property = net_device_bond_get_property;
+
+ pspec = g_param_spec_string ("slaves", NULL, NULL,
+ NULL,
+ G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_SLAVES, pspec);
+
+ g_type_class_add_private (klass, sizeof (NetDeviceBondPrivate));
+}
+
+static void
+net_device_bond_init (NetDeviceBond *device_bond)
+{
+ device_bond->priv = NET_DEVICE_BOND_GET_PRIVATE (device_bond);
+}
diff --git a/panels/network/net-device-bond.h b/panels/network/net-device-bond.h
new file mode 100644
index 0000000..f79689e
--- /dev/null
+++ b/panels/network/net-device-bond.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __NET_DEVICE_BOND_H
+#define __NET_DEVICE_BOND_H
+
+#include <glib-object.h>
+
+#include "net-device-simple.h"
+
+G_BEGIN_DECLS
+
+#define NET_TYPE_DEVICE_BOND (net_device_bond_get_type ())
+#define NET_DEVICE_BOND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NET_TYPE_DEVICE_BOND, NetDeviceBond))
+#define NET_DEVICE_BOND_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NET_TYPE_DEVICE_BOND, NetDeviceBondClass))
+#define NET_IS_DEVICE_BOND(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NET_TYPE_DEVICE_BOND))
+#define NET_IS_DEVICE_BOND_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NET_TYPE_DEVICE_BOND))
+#define NET_DEVICE_BOND_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NET_TYPE_DEVICE_BOND, NetDeviceBondClass))
+
+typedef struct _NetDeviceBondPrivate NetDeviceBondPrivate;
+typedef struct _NetDeviceBond NetDeviceBond;
+typedef struct _NetDeviceBondClass NetDeviceBondClass;
+
+struct _NetDeviceBond
+{
+ NetDeviceSimple parent;
+ NetDeviceBondPrivate *priv;
+};
+
+struct _NetDeviceBondClass
+{
+ NetDeviceSimpleClass parent_class;
+};
+
+GType net_device_bond_get_type (void);
+
+G_END_DECLS
+
+#endif /* __NET_DEVICE_BOND_H */
+
diff --git a/panels/network/net-device-simple.c b/panels/network/net-device-simple.c
index 0057070..fbd9a1e 100644
--- a/panels/network/net-device-simple.c
+++ b/panels/network/net-device-simple.c
@@ -278,3 +278,36 @@ net_device_simple_get_speed (NetDeviceSimple *device_simple)
return klass->get_speed (device_simple);
}
+
+void
+net_device_simple_add_row (NetDeviceSimple *device_simple,
+ const char *label_string,
+ const char *property_name)
+{
+ NetDeviceSimplePrivate *priv = device_simple->priv;
+ GtkGrid *grid;
+ GtkWidget *label, *value;
+ GtkStyleContext *context;
+ gint top_attach;
+
+ grid = GTK_GRID (gtk_builder_get_object (priv->builder, "grid"));
+
+ label = gtk_label_new (label_string);
+ gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+ gtk_container_add (GTK_CONTAINER (grid), label);
+
+ context = gtk_widget_get_style_context (label);
+ gtk_style_context_add_class (context, "dim-label");
+ gtk_widget_show (label);
+
+ gtk_container_child_get (GTK_CONTAINER (grid), label,
+ "top-attach", &top_attach,
+ NULL);
+
+ value = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (value), 0.0, 0.5);
+ g_object_bind_property (device_simple, property_name, value, "label", 0);
+ gtk_grid_attach (grid, value, 1, top_attach, 1, 1);
+ gtk_widget_show (value);
+}
+
diff --git a/panels/network/net-device-simple.h b/panels/network/net-device-simple.h
index 678d2dd..806755d 100644
--- a/panels/network/net-device-simple.h
+++ b/panels/network/net-device-simple.h
@@ -57,6 +57,10 @@ GType net_device_simple_get_type (void);
char *net_device_simple_get_speed (NetDeviceSimple *device_simple);
+void net_device_simple_add_row (NetDeviceSimple *device_simple,
+ const char *label,
+ const char *property_name);
+
G_END_DECLS
#endif /* __NET_DEVICE_SIMPLE_H */
diff --git a/panels/network/network-simple.ui b/panels/network/network-simple.ui
index 2f4228c..76e6655 100644
--- a/panels/network/network-simple.ui
+++ b/panels/network/network-simple.ui
@@ -10,10 +10,11 @@
<property name="border_width">12</property>
<property name="spacing">6</property>
<child>
- <object class="GtkGrid" id="grid1">
+ <object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
+ <property name="orientation">vertical</property>
<property name="row_spacing">10</property>
<property name="column_spacing">6</property>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]