[gnome-control-center] network: Share a NMClient instance between NetObjects
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Share a NMClient instance between NetObjects
- Date: Thu, 12 Jul 2012 16:01:29 +0000 (UTC)
commit eeecc61d0583023dd40fcc295432cab1e50a3ca0
Author: Richard Hughes <richard hughsie com>
Date: Thu Jul 12 16:35:06 2012 +0100
network: Share a NMClient instance between NetObjects
Creating a NMClient is expensive and slow. This will be used in future code.
panels/network/cc-network-panel.c | 1 +
panels/network/net-object.c | 31 +++++++++++++++++++++++++++++++
panels/network/net-object.h | 4 ++++
3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index c7a335f..f74e2bd 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -581,6 +581,7 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
"liststore_devices"));
net_device = net_device_new ();
+ net_object_set_client (NET_OBJECT (net_device), panel->priv->client);
net_device_set_nm_device (net_device, device);
net_object_set_id (NET_OBJECT (net_device), nm_device_get_udi (device));
register_object_interest (panel, NET_OBJECT (net_device));
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index deba1cf..eeb2c1b 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -33,6 +33,7 @@ struct _NetObjectPrivate
gchar *id;
gchar *title;
gboolean removable;
+ NMClient *client;
};
enum {
@@ -40,6 +41,7 @@ enum {
PROP_ID,
PROP_TITLE,
PROP_REMOVABLE,
+ PROP_CLIENT,
PROP_LAST
};
@@ -110,6 +112,20 @@ net_object_set_title (NetObject *object, const gchar *title)
object->priv->title = g_strdup (title);
}
+NMClient *
+net_object_get_client (NetObject *object)
+{
+ g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
+ return object->priv->client;
+}
+
+void
+net_object_set_client (NetObject *object, NMClient *client)
+{
+ g_return_if_fail (NET_IS_OBJECT (object));
+ object->priv->client = g_object_ref (client);
+}
+
GtkWidget *
net_object_add_to_notebook (NetObject *object,
GtkNotebook *notebook,
@@ -152,6 +168,9 @@ net_object_get_property (GObject *object_,
case PROP_REMOVABLE:
g_value_set_boolean (value, priv->removable);
break;
+ case PROP_CLIENT:
+ g_value_set_object (value, priv->client);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -182,6 +201,11 @@ net_object_set_property (GObject *object_,
case PROP_REMOVABLE:
priv->removable = g_value_get_boolean (value);
break;
+ case PROP_CLIENT:
+ if (priv->client != NULL)
+ g_object_unref (priv->client);
+ priv->client = g_object_ref (g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -196,6 +220,8 @@ net_object_finalize (GObject *object)
g_free (priv->id);
g_free (priv->title);
+ if (priv->client != NULL)
+ g_object_unref (priv->client);
G_OBJECT_CLASS (net_object_parent_class)->finalize (object);
}
@@ -224,6 +250,11 @@ net_object_class_init (NetObjectClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_REMOVABLE, pspec);
+ pspec = g_param_spec_object ("client", NULL, NULL,
+ NM_TYPE_CLIENT,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_CLIENT, pspec);
+
signals[SIGNAL_CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/panels/network/net-object.h b/panels/network/net-object.h
index ad8c22c..f42ecb2 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -24,6 +24,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <nm-client.h>
G_BEGIN_DECLS
@@ -66,6 +67,9 @@ void net_object_set_id (NetObject *object,
const gchar *net_object_get_title (NetObject *object);
void net_object_set_title (NetObject *object,
const gchar *title);
+NMClient *net_object_get_client (NetObject *object);
+void net_object_set_client (NetObject *object,
+ NMClient *client);
void net_object_emit_changed (NetObject *object);
void net_object_emit_removed (NetObject *object);
GtkWidget *net_object_add_to_notebook (NetObject *object,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]