network: Set the device properties at construct time

We need this for more complicated devices that need to contact other daemons,
for instance ModemManager.
This commit is contained in:
Richard Hughes 2012-07-16 17:34:24 +01:00
parent cd765a1267
commit 3c2a09294c
7 changed files with 22 additions and 67 deletions

View file

@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2010-2012 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2012 Thomas Bechtold <thomasbechtold@jpberlin.de>
*
* This program is free software; you can redistribute it and/or modify
@ -528,9 +528,9 @@ panel_refresh_killswitch_visibility (CcNetworkPanel *panel)
static gboolean
panel_add_device (CcNetworkPanel *panel, NMDevice *device)
{
const gchar *title;
GtkListStore *liststore_devices;
GtkTreeIter iter;
gchar *title = NULL;
NMDeviceType type;
NetDevice *net_device;
CcNetworkPanelPrivate *priv = panel->priv;
@ -573,15 +573,20 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
device);
}
/* make title a bit bigger */
title = g_strdup_printf ("%s", panel_device_to_localized_string (device));
/* create device */
title = panel_device_to_localized_string (device);
net_device = g_object_new (NET_TYPE_DEVICE,
"removable", FALSE,
"cancellable", panel->priv->cancellable,
"client", panel->priv->client,
"remote-settings", panel->priv->remote_settings,
"nm-device", device,
"id", nm_device_get_udi (device),
"title", title,
NULL);
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));
gtk_list_store_append (liststore_devices, &iter);
gtk_list_store_set (liststore_devices,
@ -628,7 +633,6 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *device)
}
out:
g_free (title);
return FALSE;
}
@ -2222,10 +2226,11 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
return;
/* add as a virtual object */
net_vpn = net_vpn_new ();
net_vpn_set_connection (net_vpn, connection);
net_object_set_client (NET_OBJECT (net_vpn), panel->priv->client);
net_object_set_id (NET_OBJECT (net_vpn), id);
net_vpn = g_object_new (NET_TYPE_VPN,
"removable", TRUE,
"id", id,
"client", panel->priv->client,
NULL);
register_object_interest (panel, NET_OBJECT (net_vpn));
/* add as a panel */

View file

@ -219,16 +219,6 @@ state_changed_cb (NMDevice *device,
net_object_refresh (NET_OBJECT (net_device));
}
void
net_device_set_nm_device (NetDevice *device, NMDevice *nm_device)
{
device->priv->nm_device = g_object_ref (nm_device);
g_signal_connect (nm_device,
"state-changed",
G_CALLBACK (state_changed_cb),
device);
}
NMDevice *
net_device_get_nm_device (NetDevice *device)
{

View file

@ -53,8 +53,6 @@ struct _NetDeviceClass
GType net_device_get_type (void);
NetDevice *net_device_new (void);
void net_device_set_nm_device (NetDevice *device,
NMDevice *nm_device);
NMDevice *net_device_get_nm_device (NetDevice *device);
NMConnection *net_device_get_find_connection (NetDevice *device);

View file

@ -95,13 +95,6 @@ net_object_get_removable (NetObject *object)
return object->priv->removable;
}
void
net_object_set_removable (NetObject *object, gboolean removable)
{
g_return_if_fail (NET_IS_OBJECT (object));
object->priv->removable = removable;
}
const gchar *
net_object_get_title (NetObject *object)
{
@ -123,13 +116,6 @@ net_object_get_client (NetObject *object)
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);
}
NMRemoteSettings *
net_object_get_remote_settings (NetObject *object)
{
@ -161,6 +147,7 @@ net_object_add_to_notebook (NetObject *object,
g_free);
return widget;
}
g_debug ("no klass->add_to_notebook for %s", object->priv->id);
return NULL;
}
@ -242,9 +229,7 @@ net_object_set_property (GObject *object_,
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));
priv->client = g_value_dup_object (value);
break;
case PROP_REMOTE_SETTINGS:
priv->remote_settings = g_value_dup_object (value);
@ -296,12 +281,12 @@ net_object_class_init (NetObjectClass *klass)
pspec = g_param_spec_boolean ("removable", NULL, NULL,
TRUE,
G_PARAM_READWRITE);
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
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_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property (object_class, PROP_CLIENT, pspec);
pspec = g_param_spec_object ("remote-settings", NULL, NULL,
@ -336,11 +321,3 @@ net_object_init (NetObject *object)
object->priv = NET_OBJECT_GET_PRIVATE (object);
}
NetObject *
net_object_new (void)
{
NetObject *object;
object = g_object_new (NET_TYPE_OBJECT, NULL);
return NET_OBJECT (object);
}

View file

@ -63,7 +63,6 @@ struct _NetObjectClass
};
GType net_object_get_type (void);
NetObject *net_object_new (void);
const gchar *net_object_get_id (NetObject *object);
void net_object_set_id (NetObject *object,
const gchar *id);
@ -72,8 +71,6 @@ void net_object_set_title (NetObject *object,
const gchar *title);
NMClient *net_object_get_client (NetObject *object);
NMRemoteSettings *net_object_get_remote_settings (NetObject *object);
void net_object_set_client (NetObject *object,
NMClient *client);
GCancellable *net_object_get_cancellable (NetObject *object);
void net_object_emit_changed (NetObject *object);
void net_object_emit_removed (NetObject *object);

View file

@ -483,14 +483,3 @@ net_vpn_init (NetVpn *vpn)
nm_device_refresh_vpn_ui (vpn);
}
NetVpn *
net_vpn_new (void)
{
NetVpn *vpn;
vpn = g_object_new (NET_TYPE_VPN,
"removable", TRUE,
NULL);
return NET_VPN (vpn);
}

View file

@ -54,7 +54,6 @@ struct _NetVpnClass
};
GType net_vpn_get_type (void);
NetVpn *net_vpn_new (void);
void net_vpn_set_connection (NetVpn *vpn,
NMConnection *connection);