[gnome-control-center] network: Remove net_object_get_client
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Remove net_object_get_client
- Date: Tue, 5 Nov 2019 23:06:24 +0000 (UTC)
commit 29734b599c24e2bd8b21ce2bb995c0834b595240
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 23 14:45:52 2019 +1300
network: Remove net_object_get_client
Better handled inside each object.
panels/network/net-device-bluetooth.c | 37 +++----
panels/network/net-device-ethernet.c | 97 ++++++++----------
panels/network/net-device-mobile.c | 148 +++++++++++++--------------
panels/network/net-device-wifi.c | 185 ++++++++++++++--------------------
panels/network/net-object.c | 26 -----
panels/network/net-object.h | 1 -
panels/network/net-vpn.c | 158 ++++++-----------------------
7 files changed, 236 insertions(+), 416 deletions(-)
---
diff --git a/panels/network/net-device-bluetooth.c b/panels/network/net-device-bluetooth.c
index c83721f47..432b92c13 100644
--- a/panels/network/net-device-bluetooth.c
+++ b/panels/network/net-device-bluetooth.c
@@ -42,7 +42,8 @@ struct _NetDeviceBluetooth
GtkButton *options_button;
GtkSeparator *separator;
- gboolean updating_device;
+ NMClient *client;
+ gboolean updating_device;
};
G_DEFINE_TYPE (NetDeviceBluetooth, net_device_bluetooth, NET_TYPE_DEVICE)
@@ -122,19 +123,17 @@ device_off_toggled (NetDeviceBluetooth *self)
gint i;
NMActiveConnection *a;
NMConnection *connection;
- NMClient *client;
if (self->updating_device)
return;
- client = net_object_get_client (NET_OBJECT (self));
- connection = net_device_get_find_connection (client, net_device_get_nm_device (NET_DEVICE (self)));
+ connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
if (connection == NULL)
return;
active = gtk_switch_get_active (self->device_off_switch);
if (active) {
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
net_device_get_nm_device (NET_DEVICE (self)),
NULL, NULL, NULL, NULL);
@@ -142,11 +141,11 @@ device_off_toggled (NetDeviceBluetooth *self)
const gchar *uuid;
uuid = nm_connection_get_uuid (connection);
- acs = nm_client_get_active_connections (client);
+ acs = nm_client_get_active_connections (self->client);
for (i = 0; acs && i < acs->len; i++) {
a = (NMActiveConnection*)acs->pdata[i];
if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) {
- nm_client_deactivate_connection (client, a, NULL, NULL);
+ nm_client_deactivate_connection (self->client, a, NULL, NULL);
break;
}
}
@@ -161,7 +160,7 @@ edit_connection (NetDeviceBluetooth *self)
g_autoptr(GError) error = NULL;
NMConnection *connection;
- connection = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)),
net_device_get_nm_device (NET_DEVICE (self)));
+ connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
uuid = nm_connection_get_uuid (connection);
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
g_debug ("Launching '%s'\n", cmdline);
@@ -169,22 +168,13 @@ edit_connection (NetDeviceBluetooth *self)
g_warning ("Failed to launch nm-connection-editor: %s", error->message);
}
-static void
-net_device_bluetooth_constructed (GObject *object)
-{
- NetDeviceBluetooth *self = NET_DEVICE_BLUETOOTH (object);
-
- G_OBJECT_CLASS (net_device_bluetooth_parent_class)->constructed (object);
-
- net_object_refresh (NET_OBJECT (self));
-}
-
static void
net_device_bluetooth_finalize (GObject *object)
{
NetDeviceBluetooth *self = NET_DEVICE_BLUETOOTH (object);
g_clear_object (&self->builder);
+ g_clear_object (&self->client);
G_OBJECT_CLASS (net_device_bluetooth_parent_class)->finalize (object);
}
@@ -196,7 +186,6 @@ net_device_bluetooth_class_init (NetDeviceBluetoothClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->finalize = net_device_bluetooth_finalize;
- object_class->constructed = net_device_bluetooth_constructed;
parent_class->get_widget = device_bluetooth_get_widget;
parent_class->refresh = device_bluetooth_refresh;
}
@@ -232,8 +221,14 @@ net_device_bluetooth_init (NetDeviceBluetooth *self)
NetDeviceBluetooth *
net_device_bluetooth_new (NMClient *client, NMDevice *device)
{
- return g_object_new (NET_TYPE_DEVICE_BLUETOOTH,
- "client", client,
+ NetDeviceBluetooth *self;
+
+ self = g_object_new (NET_TYPE_DEVICE_BLUETOOTH,
"nm-device", device,
NULL);
+ self->client = g_object_ref (client);
+
+ net_object_refresh (NET_OBJECT (self));
+
+ return self;
}
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index fa4168129..0844e51e1 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -49,10 +49,10 @@ struct _NetDeviceEthernet
GtkSwitch *device_off_switch;
GtkScrolledWindow *scrolled_window;
- GtkListBox *list;
- gboolean updating_device;
-
- GHashTable *connections;
+ NMClient *client;
+ GtkListBox *list;
+ gboolean updating_device;
+ GHashTable *connections;
};
G_DEFINE_TYPE (NetDeviceEthernet, net_device_ethernet, NET_TYPE_DEVICE)
@@ -237,7 +237,6 @@ show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title)
NMConnection *connection;
GtkWidget *window;
NetConnectionEditor *editor;
- NMClient *client;
NMDevice *nmdev;
window = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
@@ -246,8 +245,7 @@ show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title)
connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection"));
nmdev = net_device_get_nm_device (NET_DEVICE (self));
- client = net_object_get_client (NET_OBJECT (self));
- editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client);
+ editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, self->client);
if (title)
net_connection_editor_set_title (editor, title);
g_signal_connect_swapped (editor, "done", G_CALLBACK (editor_done), self);
@@ -370,7 +368,7 @@ populate_ui (NetDeviceEthernet *self)
}
g_list_free (children);
- connections = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)),
net_device_get_nm_device (NET_DEVICE (self)));
+ connections = net_device_get_valid_connections (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
for (l = connections; l; l = l->next) {
NMConnection *connection = l->data;
if (!g_hash_table_contains (self->connections, connection)) {
@@ -416,7 +414,6 @@ add_profile (NetDeviceEthernet *self)
g_autofree gchar *id = NULL;
NetConnectionEditor *editor;
GtkWidget *window;
- NMClient *client;
NMDevice *nmdev;
const GPtrArray *connections;
@@ -426,8 +423,7 @@ add_profile (NetDeviceEthernet *self)
uuid = nm_utils_uuid_generate ();
- client = net_object_get_client (NET_OBJECT (self));
- connections = nm_client_get_connections (client);
+ connections = nm_client_get_connections (self->client);
id = ce_page_get_next_available_name (connections, NAME_FORMAT_PROFILE, NULL);
g_object_set (sc,
@@ -442,7 +438,7 @@ add_profile (NetDeviceEthernet *self)
window = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
nmdev = net_device_get_nm_device (NET_DEVICE (self));
- editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client);
+ editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, self->client);
g_signal_connect_swapped (editor, "done", G_CALLBACK (editor_done), self);
net_connection_editor_run (editor);
}
@@ -450,20 +446,18 @@ add_profile (NetDeviceEthernet *self)
static void
device_off_toggled (NetDeviceEthernet *self)
{
- NMClient *client;
NMDevice *nm_device;
NMConnection *connection;
if (self->updating_device)
return;
- client = net_object_get_client (NET_OBJECT (self));
nm_device = net_device_get_nm_device (NET_DEVICE (self));
if (gtk_switch_get_active (self->device_off_switch)) {
- connection = net_device_get_find_connection (client, nm_device);
+ connection = net_device_get_find_connection (self->client, nm_device);
if (connection != NULL) {
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
nm_device,
NULL, NULL, NULL, NULL);
@@ -482,11 +476,9 @@ device_title_changed (NetDeviceEthernet *self)
static void
connection_activated (NetDeviceEthernet *self, GtkListBoxRow *row)
{
- NMClient *client;
NMDevice *nm_device;
NMConnection *connection;
- client = net_object_get_client (NET_OBJECT (self));
nm_device = net_device_get_nm_device (NET_DEVICE (self));
if (!NM_IS_DEVICE_ETHERNET (nm_device) ||
@@ -495,50 +487,19 @@ connection_activated (NetDeviceEthernet *self, GtkListBoxRow *row)
connection = NM_CONNECTION (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))),
"connection"));
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
nm_device,
NULL, NULL, NULL, NULL);
}
-static void
-device_ethernet_constructed (GObject *object)
-{
- NetDeviceEthernet *self = NET_DEVICE_ETHERNET (object);
- NMClient *client;
-
- g_signal_connect_swapped (self->device_off_switch, "notify::active",
- G_CALLBACK (device_off_toggled), self);
-
- self->list = GTK_LIST_BOX (gtk_list_box_new ());
- gtk_list_box_set_selection_mode (self->list, GTK_SELECTION_NONE);
- gtk_list_box_set_header_func (self->list, cc_list_box_update_header_func, NULL, NULL);
- gtk_container_add (GTK_CONTAINER (self->scrolled_window), GTK_WIDGET (self->list));
- g_signal_connect_swapped (self->list, "row-activated",
- G_CALLBACK (connection_activated), self);
- gtk_widget_show (GTK_WIDGET (self->list));
-
- g_signal_connect_swapped (self->details_button, "clicked",
- G_CALLBACK (show_details_for_wired), self);
-
- g_signal_connect_swapped (self->add_profile_button, "clicked",
- G_CALLBACK (add_profile), self);
-
- client = net_object_get_client (NET_OBJECT (object));
- g_signal_connect_object (client, NM_CLIENT_CONNECTION_ADDED,
- G_CALLBACK (client_connection_added_cb), object, G_CONNECT_SWAPPED);
- g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED,
- G_CALLBACK (connection_removed), self, G_CONNECT_SWAPPED);
-
- device_ethernet_refresh_ui (self);
-}
-
static void
device_ethernet_finalize (GObject *object)
{
NetDeviceEthernet *self = NET_DEVICE_ETHERNET (object);
g_clear_object (&self->builder);
+ g_clear_object (&self->client);
g_hash_table_destroy (self->connections);
G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
@@ -559,7 +520,6 @@ net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
obj_class->refresh = device_ethernet_refresh;
obj_class->get_widget = device_ethernet_get_widget;
- object_class->constructed = device_ethernet_constructed;
object_class->finalize = device_ethernet_finalize;
}
@@ -588,14 +548,41 @@ net_device_ethernet_init (NetDeviceEthernet *self)
self->connections = g_hash_table_new (NULL, NULL);
- g_signal_connect (self, "notify::title", G_CALLBACK (device_title_changed), NULL);
+ self->list = GTK_LIST_BOX (gtk_list_box_new ());
+ gtk_list_box_set_selection_mode (self->list, GTK_SELECTION_NONE);
+ gtk_list_box_set_header_func (self->list, cc_list_box_update_header_func, NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (self->scrolled_window), GTK_WIDGET (self->list));
+ g_signal_connect_swapped (self->list, "row-activated",
+ G_CALLBACK (connection_activated), self);
+ gtk_widget_show (GTK_WIDGET (self->list));
+
+ g_signal_connect_swapped (self->device_off_switch, "notify::active",
+ G_CALLBACK (device_off_toggled), self);
+
+ g_signal_connect_swapped (self->details_button, "clicked",
+ G_CALLBACK (show_details_for_wired), self);
+
+ g_signal_connect_swapped (self->add_profile_button, "clicked",
+ G_CALLBACK (add_profile), self);
}
NetDeviceEthernet *
net_device_ethernet_new (NMClient *client, NMDevice *device)
{
- return g_object_new (NET_TYPE_DEVICE_ETHERNET,
- "client", client,
+ NetDeviceEthernet *self;
+
+ self = g_object_new (NET_TYPE_DEVICE_ETHERNET,
"nm-device", device,
NULL);
+ self->client = g_object_ref (client);
+
+ g_signal_connect_object (client, NM_CLIENT_CONNECTION_ADDED,
+ G_CALLBACK (client_connection_added_cb), self, G_CONNECT_SWAPPED);
+ g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED,
+ G_CALLBACK (connection_removed), self, G_CONNECT_SWAPPED);
+
+ g_signal_connect (self, "notify::title", G_CALLBACK (device_title_changed), NULL);
+ device_ethernet_refresh_ui (self);
+
+ return self;
}
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index a0c3a1ee3..d3696d7ff 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -61,6 +61,7 @@ struct _NetDeviceMobile
GtkLabel *route_label;
GtkLabel *status_label;
+ NMClient *client;
GCancellable *cancellable;
gboolean updating_device;
@@ -125,7 +126,6 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
GtkTreeModel *model;
NMConnection *connection;
NMDevice *device;
- NMClient *client;
GtkWidget *toplevel;
if (self->updating_device)
@@ -138,7 +138,6 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
device = net_device_get_nm_device (NET_DEVICE (self));
if (device == NULL)
return;
- client = net_object_get_client (NET_OBJECT (self));
/* get entry */
model = gtk_combo_box_get_model (self->network_combo);
@@ -148,17 +147,17 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
if (g_strcmp0 (object_path, NULL) == 0) {
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
cc_network_panel_connect_to_3g_network (toplevel,
- client,
+ self->client,
device);
return;
}
/* activate the connection */
g_debug ("try to switch to connection %s", object_path);
- connection = (NMConnection*) nm_client_get_connection_by_path (client, object_path);
+ connection = (NMConnection*) nm_client_get_connection_by_path (self->client, object_path);
if (connection != NULL) {
nm_device_disconnect (device, NULL, NULL);
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
device, NULL, NULL,
connection_activate_cb,
@@ -177,7 +176,7 @@ mobilebb_enabled_toggled (NetDeviceMobile *self)
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
return;
- if (nm_client_wwan_get_enabled (net_object_get_client (NET_OBJECT (self)))) {
+ if (nm_client_wwan_get_enabled (self->client)) {
NMDeviceState state;
state = nm_device_get_state (device);
@@ -210,7 +209,7 @@ device_add_device_connections (NetDeviceMobile *self,
NMConnection *connection;
/* get the list of available connections for this device */
- list = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)), nm_device);
+ list = net_device_get_valid_connections (self->client, nm_device);
gtk_list_store_clear (liststore);
active_connection = nm_device_get_active_connection (nm_device);
for (l = list; l; l = g_slist_next (l)) {
@@ -398,7 +397,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
gtk_label_set_label (self->status_label, status);
/* sensitive for other connection types if the device is currently connected */
- is_connected = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), nm_device)
!= NULL;
+ is_connected = net_device_get_find_connection (self->client, nm_device) != NULL;
gtk_widget_set_sensitive (GTK_WIDGET (self->options_button), is_connected);
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device));
@@ -490,19 +489,17 @@ device_off_toggled (NetDeviceMobile *self)
gint i;
NMActiveConnection *a;
NMConnection *connection;
- NMClient *client;
if (self->updating_device)
return;
- client = net_object_get_client (NET_OBJECT (self));
- connection = net_device_get_find_connection (client, net_device_get_nm_device (NET_DEVICE (self)));
+ connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
if (connection == NULL)
return;
active = gtk_switch_get_active (self->device_off_switch);
if (active) {
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
net_device_get_nm_device (NET_DEVICE (self)),
NULL, NULL, NULL, NULL);
@@ -510,11 +507,11 @@ device_off_toggled (NetDeviceMobile *self)
const gchar *uuid;
uuid = nm_connection_get_uuid (connection);
- acs = nm_client_get_active_connections (client);
+ acs = nm_client_get_active_connections (self->client);
for (i = 0; acs && i < acs->len; i++) {
a = (NMActiveConnection*)acs->pdata[i];
if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) {
- nm_client_deactivate_connection (client, a, NULL, NULL);
+ nm_client_deactivate_connection (self->client, a, NULL, NULL);
break;
}
}
@@ -529,7 +526,7 @@ edit_connection (NetDeviceMobile *self)
g_autoptr(GError) error = NULL;
NMConnection *connection;
- connection = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)),
net_device_get_nm_device (NET_DEVICE (self)));
+ connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
uuid = nm_connection_get_uuid (connection);
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
g_debug ("Launching '%s'\n", cmdline);
@@ -748,68 +745,6 @@ device_mobile_device_got_modem_manager_cdma_cb (GObject *source_object,
self);
}
-static void
-net_device_mobile_constructed (GObject *object)
-{
- NetDeviceMobile *self = NET_DEVICE_MOBILE (object);
- NMClient *client;
- NMDevice *device;
- NMDeviceModemCapabilities caps;
-
- G_OBJECT_CLASS (net_device_mobile_parent_class)->constructed (object);
-
- device = net_device_get_nm_device (NET_DEVICE (self));
-
- caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
-
- /* Only load proxies if we have broadband modems of the OLD ModemManager interface */
- if (g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager/") &&
- ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
- (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) ||
- (caps & NM_DEVICE_MODEM_CAPABILITY_LTE))) {
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.ModemManager",
- nm_device_get_udi (device),
- "org.freedesktop.ModemManager.Modem",
- self->cancellable,
- device_mobile_device_got_modem_manager_cb,
- self);
-
- if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
- (caps & NM_DEVICE_MODEM_CAPABILITY_LTE)) {
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.ModemManager",
- nm_device_get_udi (device),
- "org.freedesktop.ModemManager.Modem.Gsm.Network",
- self->cancellable,
- device_mobile_device_got_modem_manager_gsm_cb,
- self);
- }
-
- if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.ModemManager",
- nm_device_get_udi (device),
- "org.freedesktop.ModemManager.Modem.Cdma",
- self->cancellable,
- device_mobile_device_got_modem_manager_cdma_cb,
- self);
- }
- }
-
- client = net_object_get_client (NET_OBJECT (self));
- g_signal_connect_object (client, "notify::wwan-enabled",
- G_CALLBACK (mobilebb_enabled_toggled),
- self, G_CONNECT_SWAPPED);
- nm_device_mobile_refresh_ui (self);
-}
-
static void
operator_name_updated (NetDeviceMobile *self)
{
@@ -885,6 +820,7 @@ net_device_mobile_dispose (GObject *object)
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->builder);
+ g_clear_object (&self->client);
g_clear_object (&self->cancellable);
g_clear_object (&self->gsm_proxy);
g_clear_object (&self->cdma_proxy);
@@ -907,7 +843,6 @@ net_device_mobile_class_init (NetDeviceMobileClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->dispose = net_device_mobile_dispose;
- object_class->constructed = net_device_mobile_constructed;
object_class->get_property = net_device_mobile_get_property;
object_class->set_property = net_device_mobile_set_property;
parent_class->get_widget = device_mobile_get_widget;
@@ -983,8 +918,61 @@ net_device_mobile_init (NetDeviceMobile *self)
NetDeviceMobile *
net_device_mobile_new (NMClient *client, NMDevice *device)
{
- return g_object_new (NET_TYPE_DEVICE_MOBILE,
- "client", client,
+ NetDeviceMobile *self;
+ NMDeviceModemCapabilities caps;
+
+ self = g_object_new (NET_TYPE_DEVICE_MOBILE,
"nm-device", device,
NULL);
+ self->client = g_object_ref (client);
+
+ caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
+
+ /* Only load proxies if we have broadband modems of the OLD ModemManager interface */
+ if (g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager/") &&
+ ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
+ (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) ||
+ (caps & NM_DEVICE_MODEM_CAPABILITY_LTE))) {
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.ModemManager",
+ nm_device_get_udi (device),
+ "org.freedesktop.ModemManager.Modem",
+ self->cancellable,
+ device_mobile_device_got_modem_manager_cb,
+ self);
+
+ if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
+ (caps & NM_DEVICE_MODEM_CAPABILITY_LTE)) {
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.ModemManager",
+ nm_device_get_udi (device),
+ "org.freedesktop.ModemManager.Modem.Gsm.Network",
+ self->cancellable,
+ device_mobile_device_got_modem_manager_gsm_cb,
+ self);
+ }
+
+ if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.ModemManager",
+ nm_device_get_udi (device),
+ "org.freedesktop.ModemManager.Modem.Cdma",
+ self->cancellable,
+ device_mobile_device_got_modem_manager_cdma_cb,
+ self);
+ }
+ }
+
+ g_signal_connect_object (client, "notify::wwan-enabled",
+ G_CALLBACK (mobilebb_enabled_toggled),
+ self, G_CONNECT_SWAPPED);
+ nm_device_mobile_refresh_ui (self);
+
+ return self;
}
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index fc34a8cf9..e4ced1204 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -78,6 +78,7 @@ struct _NetDeviceWifi
GtkLabel *title_label;
CcPanel *panel;
+ NMClient *client;
gboolean updating_device;
gchar *selected_ssid_title;
gchar *selected_connection_id;
@@ -100,29 +101,6 @@ enum {
G_DEFINE_TYPE (NetDeviceWifi, net_device_wifi, NET_TYPE_DEVICE)
-NetDeviceWifi *
-net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
-{
- NetDeviceWifi *self = g_object_new (NET_TYPE_DEVICE_WIFI,
- "client", client,
- "nm-device", device,
- NULL);
- self->panel = panel;
- return self;
-}
-
-GtkWidget *
-net_device_wifi_get_header_widget (NetDeviceWifi *self)
-{
- return GTK_WIDGET (self->header_box);
-}
-
-GtkWidget *
-net_device_wifi_get_title_widget (NetDeviceWifi *self)
-{
- return GTK_WIDGET (self->center_box);
-}
-
static GtkWidget *
device_wifi_proxy_get_widget (NetObject *object,
GtkSizeGroup *heading_size_group)
@@ -156,7 +134,7 @@ wireless_enabled_toggled (NetDeviceWifi *self)
if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI)
return;
- enabled = nm_client_wireless_get_enabled (net_object_get_client (NET_OBJECT (self)));
+ enabled = nm_client_wireless_get_enabled (self->client);
self->updating_device = TRUE;
gtk_switch_set_active (self->device_off_switch, enabled);
@@ -169,7 +147,7 @@ static NMConnection *
find_connection_for_device (NetDeviceWifi *self,
NMDevice *device)
{
- return net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), device);
+ return net_device_get_find_connection (self->client, device);
}
static gboolean
@@ -399,7 +377,6 @@ static void
nm_device_wifi_refresh_ui (NetDeviceWifi *self)
{
NMDevice *nm_device;
- NMClient *client;
g_autofree gchar *status = NULL;
if (device_is_hotspot (self)) {
@@ -409,10 +386,8 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *self)
return;
}
- client = net_object_get_client (NET_OBJECT (self));
-
if (self->scan_id == 0 &&
- nm_client_wireless_get_enabled (client)) {
+ nm_client_wireless_get_enabled (self->client)) {
self->scan_id = g_timeout_add_seconds (PERIODIC_WIFI_SCAN_TIMEOUT,
request_scan, self);
request_scan (self);
@@ -440,15 +415,13 @@ device_wifi_refresh (NetObject *object)
static void
device_off_toggled (NetDeviceWifi *self)
{
- NMClient *client;
gboolean active;
if (self->updating_device)
return;
- client = net_object_get_client (NET_OBJECT (self));
active = gtk_switch_get_active (self->device_off_switch);
- nm_client_wireless_set_enabled (client, active);
+ nm_client_wireless_set_enabled (self->client, active);
if (!active)
disable_scan_timeout (self);
}
@@ -456,12 +429,10 @@ device_off_toggled (NetDeviceWifi *self)
static void
connect_to_hidden_network (NetDeviceWifi *self)
{
- NMClient *client;
GtkWidget *toplevel;
- client = net_object_get_client (NET_OBJECT (self));
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
- cc_network_panel_connect_to_hidden_network (toplevel, client);
+ cc_network_panel_connect_to_hidden_network (toplevel, self->client);
}
static void
@@ -533,7 +504,6 @@ wireless_try_to_connect (NetDeviceWifi *self,
{
const gchar *ssid_target;
NMDevice *device;
- NMClient *client;
if (self->updating_device)
return;
@@ -550,8 +520,6 @@ wireless_try_to_connect (NetDeviceWifi *self,
ssid_target, ap_object_path);
/* activate the connection */
- client = net_object_get_client (NET_OBJECT (self));
-
if (!is_8021x (device, ap_object_path)) {
g_autoptr(GPermission) permission = NULL;
gboolean allowed_to_share = FALSE;
@@ -572,7 +540,7 @@ wireless_try_to_connect (NetDeviceWifi *self,
}
g_debug ("no existing connection found for %s, creating and activating one", ssid_target);
- nm_client_add_and_activate_connection_async (client,
+ nm_client_add_and_activate_connection_async (self->client,
partial,
device,
ap_object_path,
@@ -716,7 +684,7 @@ net_device_wifi_get_hotspot_connection (NetDeviceWifi *self)
GSList *connections, *l;
NMConnection *c = NULL;
- connections = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)),
net_device_get_nm_device (NET_DEVICE (self)));
+ connections = net_device_get_valid_connections (self->client, net_device_get_nm_device (NET_DEVICE
(self)));
for (l = connections; l; l = l->next) {
NMConnection *tmp = l->data;
if (is_hotspot_connection (tmp)) {
@@ -735,7 +703,6 @@ overwrite_ssid_cb (GObject *source_object,
gpointer user_data)
{
g_autoptr(GError) error = NULL;
- NMClient *client;
NMRemoteConnection *connection;
NMDevice *device;
NMConnection *c;
@@ -752,11 +719,10 @@ overwrite_ssid_cb (GObject *source_object,
self = user_data;
device = net_device_get_nm_device (NET_DEVICE (self));
- client = net_object_get_client (NET_OBJECT (self));
c = net_device_wifi_get_hotspot_connection (self);
g_debug ("activate existing hotspot connection\n");
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
c,
device,
NULL,
@@ -770,14 +736,12 @@ start_hotspot (NetDeviceWifi *self)
{
NMDevice *device;
g_autofree gchar *active_ssid = NULL;
- NMClient *client;
GtkWidget *window;
NMConnection *c;
g_autofree gchar *hostname = NULL;
g_autofree gchar *ssid = NULL;
gint response;
- client = net_object_get_client (NET_OBJECT (self));
device = net_device_get_nm_device (NET_DEVICE (self));
window = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
@@ -805,7 +769,7 @@ start_hotspot (NetDeviceWifi *self)
overwrite_ssid_cb,
self);
else
- nm_client_add_and_activate_connection_async (client,
+ nm_client_add_and_activate_connection_async (self->client,
connection,
device,
NULL,
@@ -825,18 +789,16 @@ stop_shared_connection (NetDeviceWifi *self)
NMDevice *device;
gint i;
NMActiveConnection *c;
- NMClient *client;
gboolean found = FALSE;
device = net_device_get_nm_device (NET_DEVICE (self));
- client = net_object_get_client (NET_OBJECT (self));
- connections = nm_client_get_active_connections (client);
+ connections = nm_client_get_active_connections (self->client);
for (i = 0; connections && i < connections->len; i++) {
c = (NMActiveConnection *)connections->pdata[i];
devices = nm_active_connection_get_devices (c);
if (devices && devices->pdata[0] == device) {
- nm_client_deactivate_connection (client, c, NULL, NULL);
+ nm_client_deactivate_connection (self->client, c, NULL, NULL);
found = TRUE;
break;
}
@@ -896,55 +858,6 @@ show_wifi_list (NetDeviceWifi *self)
gtk_notebook_set_current_page (self->notebook, 0);
}
-static void
-net_device_wifi_constructed (GObject *object)
-{
- NetDeviceWifi *self = NET_DEVICE_WIFI (object);
- NMClient *client;
- NMClientPermissionResult perm;
- NMDevice *nm_device;
- NMDeviceWifiCapabilities caps;
- GtkWidget *list;
-
- G_OBJECT_CLASS (net_device_wifi_parent_class)->constructed (object);
-
- client = net_object_get_client (NET_OBJECT (self));
- g_signal_connect_object (client, "notify::wireless-enabled",
- G_CALLBACK (wireless_enabled_toggled), self, G_CONNECT_SWAPPED);
-
- nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
- list = GTK_WIDGET (cc_wifi_connection_list_new (client, NM_DEVICE_WIFI (nm_device), TRUE, TRUE,
FALSE));
- gtk_widget_show (list);
- gtk_container_add (GTK_CONTAINER (self->listbox_box), list);
-
- gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
- gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)ap_sort, NULL, NULL);
-
- g_signal_connect_swapped (list, "row-activated",
- G_CALLBACK (ap_activated), self);
- g_signal_connect_swapped (list, "configure",
- G_CALLBACK (show_details_for_row),
- self);
-
- /* only enable the button if the user can create a hotspot */
- perm = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
- caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (nm_device));
- if (perm != NM_CLIENT_PERMISSION_RESULT_YES &&
- perm != NM_CLIENT_PERMISSION_RESULT_AUTH) {
- gtk_widget_set_tooltip_text (GTK_WIDGET (self->start_hotspot_button), _("System policy
prohibits use as a Hotspot"));
- gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), FALSE);
- } else if (!(caps & (NM_WIFI_DEVICE_CAP_AP | NM_WIFI_DEVICE_CAP_ADHOC))) {
- gtk_widget_set_tooltip_text (GTK_WIDGET (self->start_hotspot_button), _("Wireless device
does not support Hotspot mode"));
- gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), FALSE);
- } else
- gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), TRUE);
-
- g_object_bind_property (self, "title", self->title_label, "label", 0);
-
- nm_device_wifi_refresh_ui (self);
-}
-
static void
net_device_wifi_finalize (GObject *object)
{
@@ -955,6 +868,7 @@ net_device_wifi_finalize (GObject *object)
disable_scan_timeout (self);
g_clear_object (&self->builder);
+ g_clear_object (&self->client);
g_clear_pointer (&self->selected_ssid_title, g_free);
g_clear_pointer (&self->selected_connection_id, g_free);
g_clear_pointer (&self->selected_ap_id, g_free);
@@ -987,7 +901,6 @@ net_device_wifi_class_init (NetDeviceWifiClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->finalize = net_device_wifi_finalize;
- object_class->constructed = net_device_wifi_constructed;
object_class->get_property = net_device_wifi_get_property;
parent_class->get_widget = device_wifi_proxy_get_widget;
parent_class->refresh = device_wifi_refresh;
@@ -1152,7 +1065,6 @@ show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row, CcWifiConne
NMAccessPoint *ap;
GtkWidget *window;
NetConnectionEditor *editor;
- NMClient *client;
NMDevice *device;
window = gtk_widget_get_toplevel (GTK_WIDGET (row));
@@ -1161,8 +1073,7 @@ show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row, CcWifiConne
ap = cc_wifi_connection_row_best_access_point (row);
device = net_device_get_nm_device (NET_DEVICE (self));
- client = net_object_get_client (NET_OBJECT (self));
- editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, client);
+ editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, self->client);
net_connection_editor_run (editor);
}
@@ -1250,7 +1161,7 @@ open_history (NetDeviceWifi *self)
nm_device = net_device_get_nm_device (NET_DEVICE (self));
- list = GTK_WIDGET (cc_wifi_connection_list_new (net_object_get_client (NET_OBJECT (self)),
+ list = GTK_WIDGET (cc_wifi_connection_list_new (self->client,
NM_DEVICE_WIFI (nm_device),
FALSE, FALSE, TRUE));
gtk_widget_show (list);
@@ -1312,7 +1223,6 @@ ap_activated (NetDeviceWifi *self, GtkListBoxRow *row)
CcWifiConnectionRow *c_row;
NMConnection *connection;
NMAccessPoint *ap;
- NMClient *client;
NMDevice *nm_device;
/* The mockups want a row to connecto hidden networks; this could
@@ -1327,9 +1237,8 @@ ap_activated (NetDeviceWifi *self, GtkListBoxRow *row)
if (ap != NULL) {
if (connection != NULL) {
- client = net_object_get_client (NET_OBJECT (self));
nm_device = net_device_get_nm_device (NET_DEVICE (self));
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
connection,
nm_device, NULL, self->cancellable,
connection_activate_cb, self);
@@ -1398,3 +1307,65 @@ net_device_wifi_init (NetDeviceWifi *self)
g_signal_connect_swapped (self->hotspot_off_switch, "notify::active",
G_CALLBACK (switch_hotspot_changed_cb), self);
}
+
+NetDeviceWifi *
+net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
+{
+ NetDeviceWifi *self;
+ NMClientPermissionResult perm;
+ NMDeviceWifiCapabilities caps;
+ GtkWidget *list;
+
+ self = g_object_new (NET_TYPE_DEVICE_WIFI,
+ "nm-device", device,
+ NULL);
+ self->panel = panel;
+ self->client = g_object_ref (client);
+
+ g_signal_connect_object (client, "notify::wireless-enabled",
+ G_CALLBACK (wireless_enabled_toggled), self, G_CONNECT_SWAPPED);
+
+ list = GTK_WIDGET (cc_wifi_connection_list_new (client, NM_DEVICE_WIFI (device), TRUE, TRUE, FALSE));
+ gtk_widget_show (list);
+ gtk_container_add (GTK_CONTAINER (self->listbox_box), list);
+
+ gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)ap_sort, NULL, NULL);
+
+ g_signal_connect_swapped (list, "row-activated",
+ G_CALLBACK (ap_activated), self);
+ g_signal_connect_swapped (list, "configure",
+ G_CALLBACK (show_details_for_row),
+ self);
+
+ /* only enable the button if the user can create a hotspot */
+ perm = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
+ caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));
+ if (perm != NM_CLIENT_PERMISSION_RESULT_YES &&
+ perm != NM_CLIENT_PERMISSION_RESULT_AUTH) {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (self->start_hotspot_button), _("System policy
prohibits use as a Hotspot"));
+ gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), FALSE);
+ } else if (!(caps & (NM_WIFI_DEVICE_CAP_AP | NM_WIFI_DEVICE_CAP_ADHOC))) {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (self->start_hotspot_button), _("Wireless device
does not support Hotspot mode"));
+ gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), FALSE);
+ } else
+ gtk_widget_set_sensitive (GTK_WIDGET (self->start_hotspot_button), TRUE);
+
+ g_object_bind_property (self, "title", self->title_label, "label", 0);
+
+ nm_device_wifi_refresh_ui (self);
+
+ return self;
+}
+
+GtkWidget *
+net_device_wifi_get_header_widget (NetDeviceWifi *self)
+{
+ return GTK_WIDGET (self->header_box);
+}
+
+GtkWidget *
+net_device_wifi_get_title_widget (NetDeviceWifi *self)
+{
+ return GTK_WIDGET (self->center_box);
+}
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index f24f188f7..00aea2d7c 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -29,13 +29,11 @@
typedef struct
{
gchar *title;
- NMClient *client;
} NetObjectPrivate;
enum {
PROP_0,
PROP_TITLE,
- PROP_CLIENT,
PROP_LAST
};
@@ -82,15 +80,6 @@ net_object_set_title (NetObject *self, const gchar *title)
g_object_notify (G_OBJECT (self), "title");
}
-NMClient *
-net_object_get_client (NetObject *self)
-{
- NetObjectPrivate *priv = net_object_get_instance_private (self);
-
- g_return_val_if_fail (NET_IS_OBJECT (self), NULL);
- return priv->client;
-}
-
GtkWidget *
net_object_get_widget (NetObject *self,
GtkSizeGroup *heading_size_group)
@@ -124,9 +113,6 @@ net_object_get_property (GObject *object,
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
- case PROP_CLIENT:
- g_value_set_pointer (value, priv->client);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -150,11 +136,6 @@ net_object_set_property (GObject *object,
g_free (priv->title);
priv->title = g_strdup (g_value_get_string (value));
break;
- case PROP_CLIENT:
- priv->client = g_value_get_pointer (value);
- if (priv->client)
- g_object_add_weak_pointer (G_OBJECT (priv->client), (gpointer *) (&priv->client));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -169,9 +150,6 @@ net_object_finalize (GObject *object)
g_clear_pointer (&priv->title, g_free);
- if (priv->client)
- g_object_remove_weak_pointer (G_OBJECT (priv->client), (gpointer *) (&priv->client));
-
G_OBJECT_CLASS (net_object_parent_class)->finalize (object);
}
@@ -189,10 +167,6 @@ net_object_class_init (NetObjectClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property (object_class, PROP_TITLE, pspec);
- pspec = g_param_spec_pointer ("client", NULL, NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
- 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 ad23c0045..94ec05593 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -46,7 +46,6 @@ struct _NetObjectClass
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_emit_changed (NetObject *object);
void net_object_emit_removed (NetObject *object);
void net_object_refresh (NetObject *object);
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 75a42fa5d..da542a6c7 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -43,6 +43,7 @@ struct _NetVpn
GtkButton *options_button;
GtkSeparator *separator;
+ NMClient *client;
NMConnection *connection;
NMActiveConnection *active_connection;
gchar *service_type;
@@ -50,12 +51,6 @@ struct _NetVpn
gboolean updating_device;
};
-enum {
- PROP_0,
- PROP_CONNECTION,
- PROP_LAST
-};
-
G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT)
static void nm_device_refresh_vpn_ui (NetVpn *self);
@@ -85,36 +80,6 @@ net_vpn_connection_to_type (NMConnection *connection)
return g_strdup (p ? p + 1 : type);
}
-static void
-net_vpn_set_connection (NetVpn *self, NMConnection *connection)
-{
- NMClient *client;
-
- /*
- * vpnc config exmaple:
- * key=IKE DH Group, value=dh2
- * key=xauth-password-type, value=ask
- * key=ipsec-secret-type, value=save
- * key=IPSec gateway, value=66.187.233.252
- * key=NAT Traversal Mode, value=natt
- * key=IPSec ID, value=rh-vpn
- * key=Xauth username, value=rhughes
- */
- self->connection = g_object_ref (connection);
-
- client = net_object_get_client (NET_OBJECT (self));
- g_signal_connect_object (client,
- NM_CLIENT_CONNECTION_REMOVED,
- G_CALLBACK (connection_removed_cb),
- self, G_CONNECT_SWAPPED);
- g_signal_connect_object (connection,
- NM_CONNECTION_CHANGED,
- G_CALLBACK (connection_changed_cb),
- self, G_CONNECT_SWAPPED);
-
- self->service_type = net_vpn_connection_to_type (self->connection);
-}
-
static GtkWidget *
vpn_proxy_get_widget (NetObject *object,
GtkSizeGroup *heading_size_group)
@@ -132,7 +97,6 @@ nm_device_refresh_vpn_ui (NetVpn *self)
gint i;
NMVpnConnectionState state;
g_autofree gchar *title = NULL;
- NMClient *client;
/* update title */
/* Translators: this is the title of the connection details
@@ -153,8 +117,7 @@ nm_device_refresh_vpn_ui (NetVpn *self)
/* Default to disconnected if there is no active connection */
state = NM_VPN_CONNECTION_STATE_DISCONNECTED;
- client = net_object_get_client (NET_OBJECT (self));
- acs = nm_client_get_active_connections (client);
+ acs = nm_client_get_active_connections (self->client);
if (acs != NULL) {
const gchar *uuid;
uuid = nm_connection_get_uuid (self->connection);
@@ -203,27 +166,24 @@ device_off_toggled (NetVpn *self)
gboolean active;
gint i;
NMActiveConnection *a;
- NMClient *client;
if (self->updating_device)
return;
active = gtk_switch_get_active (self->device_off_switch);
if (active) {
- client = net_object_get_client (NET_OBJECT (self));
- nm_client_activate_connection_async (client,
+ nm_client_activate_connection_async (self->client,
self->connection, NULL, NULL,
NULL, NULL, NULL);
} else {
const gchar *uuid;
uuid = nm_connection_get_uuid (self->connection);
- client = net_object_get_client (NET_OBJECT (self));
- acs = nm_client_get_active_connections (client);
+ acs = nm_client_get_active_connections (self->client);
for (i = 0; acs && i < acs->len; i++) {
a = (NMActiveConnection*)acs->pdata[i];
if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) {
- nm_client_deactivate_connection (client, a, NULL, NULL);
+ nm_client_deactivate_connection (self->client, a, NULL, NULL);
break;
}
}
@@ -242,16 +202,13 @@ edit_connection (NetVpn *self)
{
GtkWidget *window;
NetConnectionEditor *editor;
- NMClient *client;
g_autofree gchar *title = NULL;
window = gtk_widget_get_toplevel (GTK_WIDGET (self->options_button));
- client = net_object_get_client (NET_OBJECT (self));
-
editor = net_connection_editor_new (GTK_WINDOW (window),
self->connection,
- NULL, NULL, client);
+ NULL, NULL, self->client);
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (self->connection));
net_connection_editor_set_title (editor, title);
@@ -259,81 +216,18 @@ edit_connection (NetVpn *self)
net_connection_editor_run (editor);
}
-/**
- * net_vpn_get_property:
- **/
-static void
-net_vpn_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NetVpn *self = NET_VPN (object);
-
- switch (prop_id) {
- case PROP_CONNECTION:
- g_value_set_object (value, self->connection);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
- break;
- }
-}
-
-/**
- * net_vpn_set_property:
- **/
-static void
-net_vpn_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NetVpn *self = NET_VPN (object);
-
- switch (prop_id) {
- case PROP_CONNECTION:
- net_vpn_set_connection (self, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
- break;
- }
-}
-
-static void
-net_vpn_constructed (GObject *object)
-{
- NetVpn *self = NET_VPN (object);
- NMClient *client = net_object_get_client (NET_OBJECT (object));
-
- G_OBJECT_CLASS (net_vpn_parent_class)->constructed (object);
-
- nm_device_refresh_vpn_ui (self);
-
- g_signal_connect_swapped (client,
- "notify::active-connections",
- G_CALLBACK (nm_active_connections_changed),
- self);
-
-}
-
static void
net_vpn_finalize (GObject *object)
{
NetVpn *self = NET_VPN (object);
- NMClient *client = net_object_get_client (NET_OBJECT (object));
- if (client)
- g_signal_handlers_disconnect_by_func (client,
- nm_active_connections_changed,
- self);
if (self->active_connection)
g_signal_handlers_disconnect_by_func (self->active_connection,
nm_device_refresh_vpn_ui,
self);
g_clear_object (&self->active_connection);
+ g_clear_object (&self->client);
g_clear_object (&self->connection);
g_clear_pointer (&self->service_type, g_free);
g_clear_object (&self->builder);
@@ -344,21 +238,12 @@ net_vpn_finalize (GObject *object)
static void
net_vpn_class_init (NetVpnClass *klass)
{
- GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
- object_class->get_property = net_vpn_get_property;
- object_class->set_property = net_vpn_set_property;
- object_class->constructed = net_vpn_constructed;
object_class->finalize = net_vpn_finalize;
parent_class->get_widget = vpn_proxy_get_widget;
parent_class->refresh = vpn_proxy_refresh;
-
- pspec = g_param_spec_object ("connection", NULL, NULL,
- NM_TYPE_CONNECTION,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
- g_object_class_install_property (object_class, PROP_CONNECTION, pspec);
}
static void
@@ -392,10 +277,31 @@ NetVpn *
net_vpn_new (NMConnection *connection,
NMClient *client)
{
- return g_object_new (NET_TYPE_VPN,
- "connection", connection,
- "client", client,
- NULL);
+ NetVpn *self;
+
+ self = g_object_new (NET_TYPE_VPN, NULL);
+ self->client = g_object_ref (client);
+ self->connection = g_object_ref (connection);
+
+ g_signal_connect_object (self->client,
+ NM_CLIENT_CONNECTION_REMOVED,
+ G_CALLBACK (connection_removed_cb),
+ self, G_CONNECT_SWAPPED);
+ g_signal_connect_object (connection,
+ NM_CONNECTION_CHANGED,
+ G_CALLBACK (connection_changed_cb),
+ self, G_CONNECT_SWAPPED);
+
+ self->service_type = net_vpn_connection_to_type (self->connection);
+
+ nm_device_refresh_vpn_ui (self);
+
+ g_signal_connect_object (client,
+ "notify::active-connections",
+ G_CALLBACK (nm_active_connections_changed),
+ self, G_CONNECT_SWAPPED);
+
+ return self;
}
NMConnection *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]