diff options
author | Bastien Nocera <hadess@hadess.net> | 2016-04-29 16:05:54 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2016-05-27 18:23:33 +0200 |
commit | 9183d3494788486600856df5115f11486ecb20a8 (patch) | |
tree | f76225fbaafa71646a2a6f078908292e838797c4 /panels/network | |
parent | 8400d3ed81d15c7406e14908437033a72348fd95 (diff) | |
download | gnome-control-center-9183d3494788486600856df5115f11486ecb20a8.tar.gz |
network: Port to libnm 1.2
We also remove support for WiMAX (now unsupported by NetworkManager),
and InfiniBand (Enterprise feature), and the use of
the deprecated NM_SETTING_WIRELESS_SEC property.
With help from network-manager-applet patches by Jiří Klimeš and
Dan Winship.
https://bugzilla.gnome.org/show_bug.cgi?id=765910
Diffstat (limited to 'panels/network')
61 files changed, 944 insertions, 1416 deletions
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c index 46409996e..0a29c927f 100644 --- a/panels/network/cc-network-panel.c +++ b/panels/network/cc-network-panel.c @@ -26,11 +26,7 @@ #include "cc-network-panel.h" #include "cc-network-resources.h" -#include "nm-remote-settings.h" -#include "nm-client.h" -#include "nm-device.h" -#include "nm-device-modem.h" -#include "nm-ui-utils.h" +#include <NetworkManager.h> #include "net-device.h" #include "net-device-mobile.h" @@ -68,7 +64,6 @@ struct _CcNetworkPanelPrivate GtkWidget *treeview; NMClient *client; MMManager *modem_manager; - NMRemoteSettings *remote_settings; gboolean updating_device; /* Killswitch stuff */ @@ -231,7 +226,6 @@ cc_network_panel_dispose (GObject *object) g_clear_object (&priv->builder); g_clear_object (&priv->client); g_clear_object (&priv->modem_manager); - g_clear_object (&priv->remote_settings); g_clear_object (&priv->kill_switch_header); priv->rfkill_switch = NULL; @@ -534,7 +528,7 @@ panel_refresh_device_titles (CcNetworkPanel *panel) nm_devices = (NMDevice **)nmdarray->pdata; num_devices = ndarray->len; - titles = nma_utils_disambiguate_device_names (nm_devices, num_devices); + titles = nm_device_disambiguate_names (nm_devices, num_devices); for (i = 0; i < num_devices; i++) { net_object_set_title (NET_OBJECT (devices[i]), titles[i]); g_free (titles[i]); @@ -565,21 +559,21 @@ handle_argv_for_device (CcNetworkPanel *panel, select_tree_iter (panel, iter); if (priv->arg_operation == OPERATION_CREATE_WIFI) - cc_network_panel_create_wifi_network (toplevel, priv->client, priv->remote_settings); + cc_network_panel_create_wifi_network (toplevel, priv->client); else - cc_network_panel_connect_to_hidden_network (toplevel, priv->client, priv->remote_settings); + cc_network_panel_connect_to_hidden_network (toplevel, priv->client); reset_command_line_args (panel); /* done */ return TRUE; } else if (g_strcmp0 (nm_object_get_path (NM_OBJECT (device)), priv->arg_device) == 0) { if (priv->arg_operation == OPERATION_CONNECT_MOBILE) { - cc_network_panel_connect_to_3g_network (toplevel, priv->client, priv->remote_settings, device); + cc_network_panel_connect_to_3g_network (toplevel, priv->client, device); reset_command_line_args (panel); /* done */ select_tree_iter (panel, iter); return TRUE; } else if (priv->arg_operation == OPERATION_CONNECT_8021X) { - cc_network_panel_connect_to_8021x_network (toplevel, priv->client, priv->remote_settings, device, priv->arg_access_point); + cc_network_panel_connect_to_8021x_network (toplevel, priv->client, device, priv->arg_access_point); reset_command_line_args (panel); /* done */ select_tree_iter (panel, iter); return TRUE; @@ -736,7 +730,6 @@ panel_add_device (CcNetworkPanel *panel, NMDevice *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), NULL); @@ -992,7 +985,7 @@ active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_d for (j = 0; devices && j < devices->len; j++) g_debug (" %s", nm_device_get_udi (g_ptr_array_index (devices, j))); if (NM_IS_VPN_CONNECTION (connection)) - g_debug (" VPN base connection: %s", nm_active_connection_get_specific_object (connection)); + g_debug (" VPN base connection: %s", nm_active_connection_get_specific_object_path (connection)); if (g_object_get_data (G_OBJECT (connection), "has-state-changed-handler") == NULL) { g_signal_connect_object (connection, "notify::state", @@ -1029,7 +1022,7 @@ manager_running (NMClient *client, GParamSpec *pspec, gpointer user_data) CcNetworkPanel *panel = CC_NETWORK_PANEL (user_data); /* clear all devices we added */ - if (!nm_client_get_manager_running (client)) { + if (!nm_client_get_nm_running (client)) { g_debug ("NM disappeared"); liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder, "liststore_devices")); @@ -1118,7 +1111,6 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection) "id", id, "connection", connection, "client", panel->priv->client, - "remote-settings", panel->priv->remote_settings, NULL); g_signal_connect_object (net_vpn, "removed", G_CALLBACK (object_removed_cb), panel, 0); @@ -1158,7 +1150,7 @@ add_connection (CcNetworkPanel *panel, s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); type = nm_setting_connection_get_connection_type (s_con); - iface = nm_connection_get_virtual_iface_name (connection); + iface = nm_connection_get_interface_name (connection); if (g_strcmp0 (type, "vpn") != 0 && iface == NULL) return; @@ -1174,35 +1166,14 @@ add_connection (CcNetworkPanel *panel, } static void -notify_new_connection_cb (NMRemoteSettings *settings, - NMRemoteConnection *connection, - CcNetworkPanel *panel) +notify_connection_added_cb (NMClient *client, + NMRemoteConnection *connection, + CcNetworkPanel *panel) { add_connection (panel, NM_CONNECTION (connection)); } static void -notify_connections_read_cb (NMRemoteSettings *settings, - CcNetworkPanel *panel) -{ - GSList *list, *iter; - NMConnection *connection; - - list = nm_remote_settings_list_connections (settings); - g_debug ("%p has %i remote connections", - panel, g_slist_length (list)); - for (iter = list; iter; iter = g_slist_next (iter)) { - connection = NM_CONNECTION (iter->data); - add_connection (panel, connection); - } - g_slist_free (list); - - - g_debug ("Calling handle_argv() after cold-plugging connections"); - handle_argv (panel); -} - -static void panel_check_network_manager_version (CcNetworkPanel *panel) { GtkWidget *box; @@ -1256,8 +1227,7 @@ add_connection_cb (GtkToolButton *button, CcNetworkPanel *panel) toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))); editor = net_connection_editor_new (toplevel, NULL, NULL, NULL, - panel->priv->client, - panel->priv->remote_settings); + panel->priv->client); g_signal_connect (editor, "done", G_CALLBACK (editor_done), panel); net_connection_editor_run (editor); } @@ -1289,7 +1259,6 @@ on_toplevel_map (GtkWidget *widget, static void cc_network_panel_init (CcNetworkPanel *panel) { - DBusGConnection *bus = NULL; GError *error = NULL; GtkStyleContext *context; GtkTreeSelection *selection; @@ -1297,6 +1266,8 @@ cc_network_panel_init (CcNetworkPanel *panel) GtkWidget *toplevel; GDBusConnection *system_bus; GtkCssProvider *provider; + const GPtrArray *connections; + guint i; panel->priv = NETWORK_PANEL_PRIVATE (panel); g_resources_register (cc_network_get_resource ()); @@ -1336,10 +1307,10 @@ cc_network_panel_init (CcNetworkPanel *panel) panel_add_proxy_device (panel); /* use NetworkManager client */ - panel->priv->client = nm_client_new (); - g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_MANAGER_RUNNING, + panel->priv->client = nm_client_new (NULL, NULL); + g_signal_connect (panel->priv->client, "notify::nm-running" , G_CALLBACK (manager_running), panel); - g_signal_connect (panel->priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS, + g_signal_connect (panel->priv->client, "notify::active-connections", G_CALLBACK (active_connections_changed), panel); g_signal_connect (panel->priv->client, "device-added", G_CALLBACK (device_added_cb), panel); @@ -1377,17 +1348,8 @@ cc_network_panel_init (CcNetworkPanel *panel) G_CALLBACK (remove_connection), panel); /* add remote settings such as VPN settings as virtual devices */ - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (bus == NULL) { - g_warning ("Error connecting to system D-Bus: %s", - error->message); - g_error_free (error); - } - panel->priv->remote_settings = nm_remote_settings_new (bus); - g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ, - G_CALLBACK (notify_connections_read_cb), panel); - g_signal_connect (panel->priv->remote_settings, NM_REMOTE_SETTINGS_NEW_CONNECTION, - G_CALLBACK (notify_new_connection_cb), panel); + g_signal_connect (panel->priv->client, NM_CLIENT_CONNECTION_ADDED, + G_CALLBACK (notify_connection_added_cb), panel); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (panel)); g_signal_connect_after (toplevel, "map", G_CALLBACK (on_toplevel_map), panel); @@ -1408,4 +1370,11 @@ cc_network_panel_init (CcNetworkPanel *panel) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref (provider); + /* Cold-plug existing connections */ + connections = nm_client_get_connections (panel->priv->client); + for (i = 0; i < connections->len; i++) + add_connection (panel, connections->pdata[i]); + + g_debug ("Calling handle_argv() after cold-plugging connections"); + handle_argv (panel); } diff --git a/panels/network/connection-editor/ce-page-8021x-security.c b/panels/network/connection-editor/ce-page-8021x-security.c index 8a41120e1..2a7d2ca99 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.c +++ b/panels/network/connection-editor/ce-page-8021x-security.c @@ -28,11 +28,6 @@ #include <glib/gi18n.h> #include <NetworkManager.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-8021x.h> -#include <nm-setting-wireless.h> -#include <nm-utils.h> #include "wireless-security.h" #include "ce-page-ethernet.h" @@ -95,15 +90,13 @@ finish_setup (CEPage8021xSecurity *page, gpointer unused, GError *error, gpointe CEPage * ce_page_8021x_security_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPage8021xSecurity *page; page = CE_PAGE_8021X_SECURITY (ce_page_new (CE_TYPE_PAGE_8021X_SECURITY, connection, client, - settings, "/org/gnome/control-center/network/8021x-security-page.ui", _("Security"))); @@ -136,7 +129,7 @@ validate (CEPage *cepage, NMConnection *connection, GError **error) NMSetting *s_con; /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs wireless setting. */ - tmp_connection = nm_connection_new (); + tmp_connection = nm_simple_connection_new (); nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ()); /* temp connection needs a 'connection' setting too, since most of @@ -152,7 +145,7 @@ validate (CEPage *cepage, NMConnection *connection, GError **error) g_object_unref (tmp_connection); } else - g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_UNKNOWN, "Invalid 802.1x security"); + g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING, "Invalid 802.1x security"); } else { nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X); valid = TRUE; diff --git a/panels/network/connection-editor/ce-page-8021x-security.h b/panels/network/connection-editor/ce-page-8021x-security.h index f61de9e6f..3bbac2a05 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.h +++ b/panels/network/connection-editor/ce-page-8021x-security.h @@ -23,7 +23,7 @@ #ifndef __CE_PAGE_8021X_SECURITY_H #define __CE_PAGE_8021X_SECURITY_H -#include <nm-connection.h> +#include <NetworkManager.h> #include "wireless-security.h" #include <glib.h> @@ -58,7 +58,6 @@ struct CEPage8021xSecurityClass { GType ce_page_8021x_security_get_type (void); CEPage *ce_page_8021x_security_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); #endif /* __CE_PAGE_8021X_SECURITY_H */ diff --git a/panels/network/connection-editor/ce-page-details.c b/panels/network/connection-editor/ce-page-details.c index 92b2126c2..d08a526b3 100644 --- a/panels/network/connection-editor/ce-page-details.c +++ b/panels/network/connection-editor/ce-page-details.c @@ -24,9 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-utils.h> -#include <nm-device-wifi.h> -#include <nm-device-ethernet.h> +#include <NetworkManager.h> #include "../panel-common.h" #include "ce-page-details.h" @@ -141,8 +139,8 @@ connect_details_page (CEPageDetails *page) const gchar *p1, *p2; ac = nm_device_get_active_connection (page->device); - p1 = ac ? nm_active_connection_get_connection (ac) : NULL; - p2 = nm_connection_get_path (CE_PAGE (page)->connection); + p1 = ac ? nm_active_connection_get_uuid (ac) : NULL; + p2 = nm_connection_get_uuid (CE_PAGE (page)->connection); if (g_strcmp0 (p1, p2) == 0) { device_is_active = TRUE; if (NM_IS_DEVICE_WIFI (page->device)) @@ -226,7 +224,6 @@ ce_page_details_class_init (CEPageDetailsClass *class) CEPage * ce_page_details_new (NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, NMDevice *device, NMAccessPoint *ap) { @@ -235,7 +232,6 @@ ce_page_details_new (NMConnection *connection, page = CE_PAGE_DETAILS (ce_page_new (CE_TYPE_PAGE_DETAILS, connection, client, - settings, "/org/gnome/control-center/network/details-page.ui", _("Details"))); diff --git a/panels/network/connection-editor/ce-page-details.h b/panels/network/connection-editor/ce-page-details.h index 5cb8f561b..036aedcf2 100644 --- a/panels/network/connection-editor/ce-page-details.h +++ b/panels/network/connection-editor/ce-page-details.h @@ -56,7 +56,6 @@ GType ce_page_details_get_type (void); CEPage *ce_page_details_new (NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, NMDevice *device, NMAccessPoint *ap); diff --git a/panels/network/connection-editor/ce-page-ethernet.c b/panels/network/connection-editor/ce-page-ethernet.c index c34478778..75ee32463 100644 --- a/panels/network/connection-editor/ce-page-ethernet.c +++ b/panels/network/connection-editor/ce-page-ethernet.c @@ -23,11 +23,10 @@ #include <glib-object.h> #include <glib/gi18n.h> +#include <net/if_arp.h> -#include <nm-utils.h> -#include <nm-device-ethernet.h> +#include <NetworkManager.h> -#include <net/if_arp.h> #include "firewall-helpers.h" #include "ce-page-ethernet.h" @@ -65,11 +64,11 @@ connect_ethernet_page (CEPageEthernet *page) NMSettingConnection *sc; int mtu_def; char **mac_list; - const GByteArray *s_mac; - char *s_mac_str; + const char *s_mac_str; GtkWidget *widget; GtkWidget *heading; const gchar *name; + const gchar *cloned_mac; name = nm_setting_connection_get_id (page->setting_connection); gtk_entry_set_text (page->name, name); @@ -77,16 +76,14 @@ connect_ethernet_page (CEPageEthernet *page) /* Device MAC address */ mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_ETHERNET, NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS); - s_mac = nm_setting_wired_get_mac_address (setting); - s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL; + s_mac_str = nm_setting_wired_get_mac_address (setting); ce_page_setup_mac_combo (page->device_mac, s_mac_str, mac_list); - g_free (s_mac_str); g_strfreev (mac_list); g_signal_connect_swapped (page->device_mac, "changed", G_CALLBACK (ce_page_changed), page); /* Cloned MAC address */ - ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting), - ARPHRD_ETHER, page->cloned_mac); + cloned_mac = nm_setting_wired_get_cloned_mac_address (setting); + gtk_entry_set_text (GTK_ENTRY (page->cloned_mac), cloned_mac ? cloned_mac : ""); g_signal_connect_swapped (page->cloned_mac, "changed", G_CALLBACK (ce_page_changed), page); /* MTU */ @@ -122,20 +119,23 @@ connect_ethernet_page (CEPageEthernet *page) heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_zone")); firewall_ui_setup (sc, widget, heading, CE_PAGE (page)->cancellable); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); - } static void ui_to_setting (CEPageEthernet *page) { - GByteArray *device_mac = NULL; - GByteArray *cloned_mac = NULL; + gchar *device_mac = NULL; + gchar *cloned_mac; + const gchar *text; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (page->device_mac)); - if (entry) - device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); - cloned_mac = ce_page_entry_to_mac (page->cloned_mac, ARPHRD_ETHER, NULL); + if (entry) { + text = gtk_entry_get_text (GTK_ENTRY (entry)); + device_mac = ce_page_trim_address (text); + } + text = gtk_entry_get_text (GTK_ENTRY (entry)); + cloned_mac = ce_page_trim_address (text); g_object_set (page->setting_wired, NM_SETTING_WIRED_MAC_ADDRESS, device_mac, @@ -143,11 +143,6 @@ ui_to_setting (CEPageEthernet *page) NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (page->mtu), NULL); - if (device_mac) - g_byte_array_free (device_mac, TRUE); - if (cloned_mac) - g_byte_array_free (cloned_mac, TRUE); - g_object_set (page->setting_connection, NM_SETTING_CONNECTION_ID, gtk_entry_get_text (page->name), NULL); @@ -155,6 +150,8 @@ ui_to_setting (CEPageEthernet *page) entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone")); firewall_ui_to_setting (page->setting_connection, entry); + g_free (cloned_mac); + g_free (device_mac); } static gboolean @@ -163,31 +160,23 @@ validate (CEPage *page, GError **error) { CEPageEthernet *self = CE_PAGE_ETHERNET (page); - gboolean invalid = FALSE; - GByteArray *ignore; GtkWidget *entry; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (self->device_mac)); if (entry) { - ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); - if (invalid) { + if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) { widget_set_error (entry); ret = FALSE; } else { - if (ignore) - g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } } - ignore = ce_page_entry_to_mac (self->cloned_mac, ARPHRD_ETHER, &invalid); - if (invalid) { + if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (self->cloned_mac)))) { widget_set_error (GTK_WIDGET (self->cloned_mac)); ret = FALSE; } else { - if (ignore) - g_byte_array_free (ignore, TRUE); widget_unset_error (GTK_WIDGET (self->cloned_mac)); } @@ -215,15 +204,13 @@ ce_page_ethernet_class_init (CEPageEthernetClass *class) CEPage * ce_page_ethernet_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageEthernet *page; page = CE_PAGE_ETHERNET (ce_page_new (CE_TYPE_PAGE_ETHERNET, connection, client, - settings, "/org/gnome/control-center/network/ethernet-page.ui", _("Identity"))); diff --git a/panels/network/connection-editor/ce-page-ethernet.h b/panels/network/connection-editor/ce-page-ethernet.h index daa24a2f3..9c7c07d0d 100644 --- a/panels/network/connection-editor/ce-page-ethernet.h +++ b/panels/network/connection-editor/ce-page-ethernet.h @@ -24,7 +24,7 @@ #include <glib-object.h> -#include <nm-setting-wired.h> +#include <NetworkManager.h> #include <gtk/gtk.h> #include "ce-page.h" @@ -63,8 +63,7 @@ struct _CEPageEthernetClass GType ce_page_ethernet_get_type (void); CEPage *ce_page_ethernet_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-ip4.c b/panels/network/connection-editor/ce-page-ip4.c index f3d3fc602..264560307 100644 --- a/panels/network/connection-editor/ce-page-ip4.c +++ b/panels/network/connection-editor/ce-page-ip4.c @@ -23,13 +23,14 @@ #include <errno.h> #include <stdlib.h> +#include <arpa/inet.h> #include <glib-object.h> #include <glib/gi18n.h> +#include <NetworkManager.h> #include "shell/list-box-helper.h" #include "ce-page-ip4.h" #include "ui-helpers.h" -#include <nm-utils.h> G_DEFINE_TYPE (CEPageIP4, ce_page_ip4, CE_TYPE_PAGE) @@ -298,29 +299,24 @@ add_address_section (CEPageIP4 *page) add_section_toolbar (page, widget, G_CALLBACK (add_empty_address_row)); - for (i = 0; i < nm_setting_ip4_config_get_num_addresses (page->setting); i++) { - NMIP4Address *addr; + for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) { + NMIPAddress *addr; struct in_addr tmp_addr; - gchar address[INET_ADDRSTRLEN + 1]; gchar network[INET_ADDRSTRLEN + 1]; - gchar gateway[INET_ADDRSTRLEN + 1]; - addr = nm_setting_ip4_config_get_address (page->setting, i); + addr = nm_setting_ip_config_get_address (page->setting, i); if (!addr) continue; - tmp_addr.s_addr = nm_ip4_address_get_address (addr); - (void) inet_ntop (AF_INET, &tmp_addr, &address[0], sizeof (address)); - - tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (addr)); + tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_address_get_prefix (addr)); (void) inet_ntop (AF_INET, &tmp_addr, &network[0], sizeof (network)); - tmp_addr.s_addr = nm_ip4_address_get_gateway (addr); - (void) inet_ntop (AF_INET, &tmp_addr, &gateway[0], sizeof (gateway)); - - add_address_row (page, address, network, gateway); + add_address_row (page, + nm_ip_address_get_address (addr), + network, + nm_setting_ip_config_get_gateway (page->setting)); } - if (nm_setting_ip4_config_get_num_addresses (page->setting) == 0) + if (nm_setting_ip_config_get_num_addresses (page->setting) == 0) add_empty_address_row (page); gtk_widget_show_all (widget); @@ -399,21 +395,18 @@ add_dns_section (CEPageIP4 *page) gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), list); page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch")); - gtk_switch_set_active (page->auto_dns, !nm_setting_ip4_config_get_ignore_auto_dns (page->setting)); + gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting)); g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page); add_section_toolbar (page, widget, G_CALLBACK (add_empty_dns_row)); - for (i = 0; i < nm_setting_ip4_config_get_num_dns (page->setting); i++) { - struct in_addr tmp_addr; - gchar address[INET_ADDRSTRLEN + 1]; - - tmp_addr.s_addr = nm_setting_ip4_config_get_dns (page->setting, i); - (void) inet_ntop (AF_INET, &tmp_addr, &address[0], sizeof (address)); + for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) { + const char *address; + address = nm_setting_ip_config_get_dns (page->setting, i); add_dns_row (page, address); } - if (nm_setting_ip4_config_get_num_dns (page->setting) == 0) + if (nm_setting_ip_config_get_num_dns (page->setting) == 0) add_empty_dns_row (page); gtk_widget_show_all (widget); @@ -483,7 +476,7 @@ add_route_row (CEPageIP4 *page, gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); g_object_set_data (G_OBJECT (row), "metric", widget); - if (metric > 0) { + if (metric >= 0) { gchar *s = g_strdup_printf ("%d", metric); gtk_entry_set_text (GTK_ENTRY (widget), s); g_free (s); @@ -521,7 +514,7 @@ add_route_row (CEPageIP4 *page, static void add_empty_route_row (CEPageIP4 *page) { - add_route_row (page, "", "", "", 0); + add_route_row (page, "", "", "", -1); } static void @@ -542,47 +535,36 @@ add_routes_section (CEPageIP4 *page) gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), list); page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch")); - gtk_switch_set_active (page->auto_routes, !nm_setting_ip4_config_get_ignore_auto_routes (page->setting)); + gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting)); g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page); add_section_toolbar (page, widget, G_CALLBACK (add_empty_route_row)); - for (i = 0; i < nm_setting_ip4_config_get_num_routes (page->setting); i++) { - NMIP4Route *route; + for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) { + NMIPRoute *route; struct in_addr tmp_addr; - gchar address[INET_ADDRSTRLEN + 1]; gchar netmask[INET_ADDRSTRLEN + 1]; - gchar gateway[INET_ADDRSTRLEN + 1]; - gint metric; - route = nm_setting_ip4_config_get_route (page->setting, i); + route = nm_setting_ip_config_get_route (page->setting, i); if (!route) continue; - tmp_addr.s_addr = nm_ip4_route_get_dest (route); - (void) inet_ntop (AF_INET, &tmp_addr, &address[0], sizeof (address)); - - tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_route_get_prefix (route)); + tmp_addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip_route_get_prefix (route)); (void) inet_ntop (AF_INET, &tmp_addr, &netmask[0], sizeof (netmask)); - tmp_addr.s_addr = nm_ip4_route_get_next_hop (route); - (void) inet_ntop (AF_INET, &tmp_addr, &gateway[0], sizeof (gateway)); - metric = nm_ip4_route_get_metric (route); - add_route_row (page, address, netmask, gateway, metric); + add_route_row (page, + nm_ip_route_get_dest (route), + netmask, + nm_ip_route_get_next_hop (route), + nm_ip_route_get_metric (route)); } - if (nm_setting_ip4_config_get_num_routes (page->setting) == 0) + if (nm_setting_ip_config_get_num_routes (page->setting) == 0) add_empty_route_row (page); gtk_widget_show_all (widget); } static void -free_addr (gpointer addr) -{ - g_array_free ((GArray *)addr, TRUE); -} - -static void connect_ip4_page (CEPageIP4 *page) { GtkWidget *content; @@ -599,7 +581,7 @@ connect_ip4_page (CEPageIP4 *page) page->enabled = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "switch_enable")); g_signal_connect (page->enabled, "notify::active", G_CALLBACK (switch_toggled), page); - str_method = nm_setting_ip4_config_get_method (page->setting); + str_method = nm_setting_ip_config_get_method (page->setting); disabled = g_strcmp0 (str_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0; gtk_switch_set_active (page->enabled, !disabled); g_signal_connect_swapped (page->enabled, "notify::active", G_CALLBACK (ce_page_changed), page); @@ -640,7 +622,7 @@ connect_ip4_page (CEPageIP4 *page) page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default), - nm_setting_ip4_config_get_never_default (page->setting)); + nm_setting_ip_config_get_never_default (page->setting)); g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page); g_signal_connect (page->method, "changed", G_CALLBACK (method_changed), page); @@ -682,7 +664,7 @@ ui_to_setting (CEPageIP4 *page) gboolean ignore_auto_routes; gboolean never_default; GPtrArray *addresses = NULL; - GArray *dns_servers = NULL; + GPtrArray *dns_servers = NULL; GPtrArray *routes = NULL; GList *children, *l; gboolean ret = TRUE; @@ -704,7 +686,7 @@ ui_to_setting (CEPageIP4 *page) } } - addresses = g_ptr_array_new_with_free_func (free_addr); + addresses = g_ptr_array_new_with_free_func (g_object_unref); if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); else @@ -716,11 +698,8 @@ ui_to_setting (CEPageIP4 *page) const gchar *text_address; const gchar *text_netmask; const gchar *text_gateway; - struct in_addr tmp_addr; - struct in_addr tmp_gateway = { 0 }; + NMIPAddress *addr; guint32 prefix; - guint32 empty_val = 0; - GArray *addr; entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); if (!entry) @@ -729,6 +708,8 @@ ui_to_setting (CEPageIP4 *page) text_address = gtk_entry_get_text (entry); text_netmask = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "network"))); text_gateway = gtk_entry_get_text (GTK_ENTRY (g_object_get_data (G_OBJECT (row), "gateway"))); + /* FIXME handle gateway + * https://bugzilla.gnome.org/show_bug.cgi?id=765969 */ if (!*text_address && !*text_netmask && !*text_gateway) { /* ignore empty rows */ @@ -738,7 +719,7 @@ ui_to_setting (CEPageIP4 *page) continue; } - if (inet_pton (AF_INET, text_address, &tmp_addr) <= 0) { + if (!text_address || !nm_utils_ipaddr_valid (AF_INET, text_address)) { widget_set_error (GTK_WIDGET (entry)); ret = FALSE; } else { @@ -752,7 +733,7 @@ ui_to_setting (CEPageIP4 *page) widget_unset_error (g_object_get_data (G_OBJECT (row), "network")); } - if (text_gateway && *text_gateway && inet_pton (AF_INET, text_gateway, &tmp_gateway) <= 0) { + if (text_gateway && !nm_utils_ipaddr_valid (AF_INET, text_gateway)) { widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); ret = FALSE; } else { @@ -762,14 +743,9 @@ ui_to_setting (CEPageIP4 *page) if (!ret) continue; - addr = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); - g_array_append_val (addr, tmp_addr.s_addr); - g_array_append_val (addr, prefix); - if (tmp_gateway.s_addr) - g_array_append_val (addr, tmp_gateway.s_addr); - else - g_array_append_val (addr, empty_val); - g_ptr_array_add (addresses, addr); + addr = nm_ip_address_new (AF_INET, text_address, prefix, NULL); + if (addr) + g_ptr_array_add (addresses, addr); } g_list_free (children); @@ -778,7 +754,7 @@ ui_to_setting (CEPageIP4 *page) addresses = NULL; } - dns_servers = g_array_new (FALSE, FALSE, sizeof (guint)); + dns_servers = g_ptr_array_new_with_free_func (g_free); if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) || g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) children = gtk_container_get_children (GTK_CONTAINER (page->dns_list)); @@ -789,7 +765,6 @@ ui_to_setting (CEPageIP4 *page) GtkWidget *row = l->data; GtkEntry *entry; const gchar *text; - struct in_addr tmp_addr; entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); if (!entry) @@ -802,17 +777,17 @@ ui_to_setting (CEPageIP4 *page) continue; } - if (inet_pton (AF_INET, text, &tmp_addr) <= 0) { + if (text && !nm_utils_ipaddr_valid (AF_INET, text)) { widget_set_error (GTK_WIDGET (entry)); ret = FALSE; } else { widget_unset_error (GTK_WIDGET (entry)); - g_array_append_val (dns_servers, tmp_addr.s_addr); + g_ptr_array_add (dns_servers, g_strdup (text)); } } g_list_free (children); - routes = g_ptr_array_new_with_free_func (free_addr); + routes = g_ptr_array_new_with_free_func (g_object_unref); if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) || g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) children = gtk_container_get_children (GTK_CONTAINER (page->routes_list)); @@ -826,9 +801,9 @@ ui_to_setting (CEPageIP4 *page) const gchar *text_netmask; const gchar *text_gateway; const gchar *text_metric; - struct in_addr tmp_addr = { 0 }; - guint32 address, netmask, gateway, metric; - GArray *route; + gint64 metric; + guint32 netmask; + NMIPRoute *route; entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); if (!entry) @@ -844,12 +819,11 @@ ui_to_setting (CEPageIP4 *page) continue; } - if (inet_pton (AF_INET, text_address, &tmp_addr) <= 0) { + if (text_address && !nm_utils_ipaddr_valid (AF_INET, text_address)) { widget_set_error (GTK_WIDGET (entry)); ret = FALSE; } else { widget_unset_error (GTK_WIDGET (entry)); - address = tmp_addr.s_addr; } if (!parse_netmask (text_netmask, &netmask)) { @@ -859,19 +833,18 @@ ui_to_setting (CEPageIP4 *page) widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "netmask"))); } - if (inet_pton (AF_INET, text_gateway, &tmp_addr) <= 0) { + if (text_gateway && !nm_utils_ipaddr_valid (AF_INET, text_gateway)) { widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway"))); ret = FALSE; } else { widget_unset_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "gateway"))); - gateway = tmp_addr.s_addr; } - metric = 0; + metric = -1; if (*text_metric) { errno = 0; - metric = strtoul (text_metric, NULL, 10); - if (errno) { + metric = g_ascii_strtoull (text_metric, NULL, 10); + if (errno || metric < 0 || metric > G_MAXUINT32) { widget_set_error (GTK_WIDGET (g_object_get_data (G_OBJECT (row), "metric"))); ret = FALSE; } else { @@ -884,12 +857,9 @@ ui_to_setting (CEPageIP4 *page) if (!ret) continue; - route = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4); - g_array_append_val (route, address); - g_array_append_val (route, netmask); - g_array_append_val (route, gateway); - g_array_append_val (route, metric); - g_ptr_array_add (routes, route); + route = nm_ip_route_new (AF_INET, text_address, netmask, text_gateway, metric, NULL); + if (route) + g_ptr_array_add (routes, route); } g_list_free (children); @@ -906,13 +876,13 @@ ui_to_setting (CEPageIP4 *page) never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default)); g_object_set (page->setting, - NM_SETTING_IP4_CONFIG_METHOD, method, - NM_SETTING_IP4_CONFIG_ADDRESSES, addresses, - NM_SETTING_IP4_CONFIG_DNS, dns_servers, - NM_SETTING_IP4_CONFIG_ROUTES, routes, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, - NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_ADDRESSES, addresses, + NM_SETTING_IP_CONFIG_DNS, dns_servers->pdata, + NM_SETTING_IP_CONFIG_ROUTES, routes, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL); out: @@ -920,7 +890,7 @@ out: g_ptr_array_free (addresses, TRUE); if (dns_servers) - g_array_free (dns_servers, TRUE); + g_ptr_array_free (dns_servers, TRUE); if (routes) g_ptr_array_free (routes, TRUE); @@ -954,21 +924,19 @@ ce_page_ip4_class_init (CEPageIP4Class *class) CEPage * ce_page_ip4_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageIP4 *page; page = CE_PAGE_IP4 (ce_page_new (CE_TYPE_PAGE_IP4, connection, client, - settings, "/org/gnome/control-center/network/ip4-page.ui", _("IPv4"))); page->setting = nm_connection_get_setting_ip4_config (connection); if (!page->setting) { - page->setting = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ()); + page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ()); nm_connection_add_setting (connection, NM_SETTING (page->setting)); } diff --git a/panels/network/connection-editor/ce-page-ip4.h b/panels/network/connection-editor/ce-page-ip4.h index ca38d3e9a..3dbca5d09 100644 --- a/panels/network/connection-editor/ce-page-ip4.h +++ b/panels/network/connection-editor/ce-page-ip4.h @@ -43,7 +43,7 @@ struct _CEPageIP4 { CEPage parent; - NMSettingIP4Config *setting; + NMSettingIPConfig *setting; GtkSwitch *enabled; GtkComboBox *method; @@ -63,8 +63,7 @@ struct _CEPageIP4Class GType ce_page_ip4_get_type (void); CEPage *ce_page_ip4_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-ip6.c b/panels/network/connection-editor/ce-page-ip6.c index 16deb0058..51ad03e36 100644 --- a/panels/network/connection-editor/ce-page-ip6.c +++ b/panels/network/connection-editor/ce-page-ip6.c @@ -23,13 +23,14 @@ #include <errno.h> #include <stdlib.h> +#include <arpa/inet.h> #include <glib-object.h> #include <glib/gi18n.h> +#include <NetworkManager.h> #include "shell/list-box-helper.h" #include "ce-page-ip6.h" #include "ui-helpers.h" -#include <nm-utils.h> G_DEFINE_TYPE (CEPageIP6, ce_page_ip6, CE_TYPE_PAGE) @@ -299,31 +300,17 @@ add_address_section (CEPageIP6 *page) add_section_toolbar (page, widget, G_CALLBACK (add_empty_address_row)); - for (i = 0; i < nm_setting_ip6_config_get_num_addresses (page->setting); i++) { - NMIP6Address *addr; - const struct in6_addr *tmp_addr; - gchar address[INET6_ADDRSTRLEN + 1]; - gchar network[INET6_ADDRSTRLEN + 1]; - gchar gateway[INET6_ADDRSTRLEN + 1]; + for (i = 0; i < nm_setting_ip_config_get_num_addresses (page->setting); i++) { + NMIPAddress *addr; + char *netmask; - addr = nm_setting_ip6_config_get_address (page->setting, i); - if (!addr) - continue; - - tmp_addr = nm_ip6_address_get_address (addr); - (void) inet_ntop (AF_INET6, tmp_addr, &address[0], sizeof (address)); - - snprintf (network, sizeof (network), "%u", nm_ip6_address_get_prefix (addr)); - - tmp_addr = nm_ip6_address_get_gateway (addr); - if (tmp_addr && !IN6_IS_ADDR_UNSPECIFIED (tmp_addr)) - (void) inet_ntop (AF_INET6, tmp_addr, &gateway[0], sizeof (gateway)); - else - gateway[0] = '\0'; - - add_address_row (page, address, network, gateway); + addr = nm_setting_ip_config_get_address (page->setting, i); + netmask = g_strdup_printf ("%u", nm_ip_address_get_prefix (addr)); + add_address_row (page, nm_ip_address_get_address (addr), netmask, + i == 0 ? nm_setting_ip_config_get_gateway (page->setting) : NULL); + g_free (netmask); } - if (nm_setting_ip6_config_get_num_addresses (page->setting) == 0) + if (nm_setting_ip_config_get_num_addresses (page->setting) == 0) add_empty_address_row (page); gtk_widget_show_all (widget); @@ -403,21 +390,18 @@ add_dns_section (CEPageIP6 *page) gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), list); page->auto_dns = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_dns_switch")); - gtk_switch_set_active (page->auto_dns, !nm_setting_ip6_config_get_ignore_auto_dns (page->setting)); + gtk_switch_set_active (page->auto_dns, !nm_setting_ip_config_get_ignore_auto_dns (page->setting)); g_signal_connect (page->auto_dns, "notify::active", G_CALLBACK (switch_toggled), page); add_section_toolbar (page, widget, G_CALLBACK (add_empty_dns_row)); - for (i = 0; i < nm_setting_ip6_config_get_num_dns (page->setting); i++) { - const struct in6_addr *tmp_addr; - gchar address[INET6_ADDRSTRLEN + 1]; - - tmp_addr = nm_setting_ip6_config_get_dns (page->setting, i); - (void) inet_ntop (AF_INET, tmp_addr, &address[0], sizeof (address)); + for (i = 0; i < nm_setting_ip_config_get_num_dns (page->setting); i++) { + const char *address; + address = nm_setting_ip_config_get_dns (page->setting, i); add_dns_row (page, address); } - if (nm_setting_ip6_config_get_num_dns (page->setting) == 0) + if (nm_setting_ip_config_get_num_dns (page->setting) == 0) add_empty_dns_row (page); gtk_widget_show_all (widget); @@ -426,9 +410,9 @@ add_dns_section (CEPageIP6 *page) static void add_route_row (CEPageIP6 *page, const gchar *address, - gint prefix, + const gchar *prefix, const gchar *gateway, - gint metric) + const gchar *metric) { GtkWidget *row; GtkWidget *row_grid; @@ -460,11 +444,7 @@ add_route_row (CEPageIP6 *page, gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); g_object_set_data (G_OBJECT (row), "prefix", widget); - if (prefix > 0) { - gchar *s = g_strdup_printf ("%d", prefix); - gtk_entry_set_text (GTK_ENTRY (widget), s); - g_free (s); - } + gtk_entry_set_text (GTK_ENTRY (widget), prefix ? prefix : ""); gtk_widget_set_margin_start (widget, 10); gtk_widget_set_margin_end (widget, 10); gtk_widget_set_hexpand (widget, TRUE); @@ -491,11 +471,7 @@ add_route_row (CEPageIP6 *page, gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); g_object_set_data (G_OBJECT (row), "metric", widget); - if (metric > 0) { - gchar *s = g_strdup_printf ("%d", metric); - gtk_entry_set_text (GTK_ENTRY (widget), s); - g_free (s); - } + gtk_entry_set_text (GTK_ENTRY (widget), metric ? metric : ""); gtk_widget_set_margin_start (widget, 10); gtk_widget_set_margin_end (widget, 10); gtk_widget_set_hexpand (widget, TRUE); @@ -529,7 +505,7 @@ add_route_row (CEPageIP6 *page, static void add_empty_route_row (CEPageIP6 *page) { - add_route_row (page, "", 0, "", 0); + add_route_row (page, "", NULL, "", NULL); } static void @@ -550,31 +526,26 @@ add_routes_section (CEPageIP6 *page) gtk_list_box_set_sort_func (GTK_LIST_BOX (list), (GtkListBoxSortFunc)sort_first_last, NULL, NULL); gtk_container_add (GTK_CONTAINER (frame), list); page->auto_routes = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "auto_routes_switch")); - gtk_switch_set_active (page->auto_routes, !nm_setting_ip6_config_get_ignore_auto_routes (page->setting)); + gtk_switch_set_active (page->auto_routes, !nm_setting_ip_config_get_ignore_auto_routes (page->setting)); g_signal_connect (page->auto_routes, "notify::active", G_CALLBACK (switch_toggled), page); add_section_toolbar (page, widget, G_CALLBACK (add_empty_route_row)); - for (i = 0; i < nm_setting_ip6_config_get_num_routes (page->setting); i++) { - NMIP6Route *route; - const struct in6_addr *tmp_addr; - gchar address[INET6_ADDRSTRLEN + 1]; - gchar gateway[INET6_ADDRSTRLEN + 1]; - gint prefix, metric; - - route = nm_setting_ip6_config_get_route (page->setting, i); - if (!route) - continue; - - tmp_addr = nm_ip6_route_get_dest (route); - (void) inet_ntop (AF_INET6, tmp_addr, &address[0], sizeof (address)); - prefix = nm_ip6_route_get_prefix (route); - tmp_addr = nm_ip6_route_get_next_hop (route); - (void) inet_ntop (AF_INET6, tmp_addr, &gateway[0], sizeof (gateway)); - metric = nm_ip6_route_get_metric (route); - add_route_row (page, address, prefix, gateway, metric); + for (i = 0; i < nm_setting_ip_config_get_num_routes (page->setting); i++) { + NMIPRoute *route; + char *prefix, *metric; + + route = nm_setting_ip_config_get_route (page->setting, i); + prefix = g_strdup_printf ("%u", nm_ip_route_get_prefix (route)); + metric = g_strdup_printf ("%u", (guint32) MIN (0, nm_ip_route_get_metric (route))); + add_route_row (page, nm_ip_route_get_dest (route), + prefix, + nm_ip_route_get_next_hop (route), + metric); + g_free (prefix); + g_free (metric); } - if (nm_setting_ip6_config_get_num_routes (page->setting) == 0) + if (nm_setting_ip_config_get_num_routes (page->setting) == 0) add_empty_route_row (page); gtk_widget_show_all (widget); @@ -597,7 +568,7 @@ connect_ip6_page (CEPageIP6 *page) page->enabled = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "switch_enable")); g_signal_connect (page->enabled, "notify::active", G_CALLBACK (switch_toggled), page); - str_method = nm_setting_ip6_config_get_method (page->setting); + str_method = nm_setting_ip_config_get_method (page->setting); disabled = g_strcmp0 (str_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0; gtk_switch_set_active (page->enabled, !disabled); g_signal_connect_swapped (page->enabled, "notify::active", G_CALLBACK (ce_page_changed), page); @@ -644,7 +615,7 @@ connect_ip6_page (CEPageIP6 *page) page->never_default = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "never_default_check")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page->never_default), - nm_setting_ip6_config_get_never_default (page->setting)); + nm_setting_ip_config_get_never_default (page->setting)); g_signal_connect_swapped (page->never_default, "toggled", G_CALLBACK (ce_page_changed), page); g_signal_connect (page->method, "changed", G_CALLBACK (method_changed), page); @@ -682,7 +653,7 @@ ui_to_setting (CEPageIP6 *page) } } - nm_setting_ip6_config_clear_addresses (page->setting); + nm_setting_ip_config_clear_addresses (page->setting); if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) children = gtk_container_get_children (GTK_CONTAINER (page->address_list)); else @@ -694,11 +665,9 @@ ui_to_setting (CEPageIP6 *page) const gchar *text_address; const gchar *text_prefix; const gchar *text_gateway; - struct in6_addr tmp_addr; - struct in6_addr tmp_gateway; guint32 prefix; gchar *end; - NMIP6Address *addr; + NMIPAddress *addr; gboolean have_gateway = FALSE; entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); @@ -717,7 +686,7 @@ ui_to_setting (CEPageIP6 *page) continue; } - if (inet_pton (AF_INET6, text_address, &tmp_addr) <= 0) { + if (!text_address || !nm_utils_ipaddr_valid (AF_INET6, text_address)) { widget_set_error (GTK_WIDGET (entry)); ret = FALSE; } else { @@ -732,15 +701,9 @@ ui_to_setting (CEPageIP6 *page) widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); } - if (text_gateway && *text_gateway) { - if (inet_pton (AF_INET6, text_gateway, &tmp_gateway) <= 0) { - widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); - ret = FALSE; - } else { - if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_gateway)) - have_gateway = TRUE; - widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); - } + if (text_gateway && !nm_utils_ipaddr_valid (AF_INET6, text_gateway)) { + widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); + ret = FALSE; } else { widget_unset_error (g_object_get_data (G_OBJECT (row), "gateway")); } @@ -748,16 +711,16 @@ ui_to_setting (CEPageIP6 *page) if (!ret) continue; - addr = nm_ip6_address_new (); - nm_ip6_address_set_address (addr, &tmp_addr); - nm_ip6_address_set_prefix (addr, prefix); + addr = nm_ip_address_new (AF_INET6, text_address, prefix, NULL); if (have_gateway) - nm_ip6_address_set_gateway (addr, &tmp_gateway); - nm_setting_ip6_config_add_address (page->setting, addr); + g_object_set (G_OBJECT (page->setting), + NM_SETTING_IP_CONFIG_GATEWAY, text_gateway, + NULL); + nm_setting_ip_config_add_address (page->setting, addr); } g_list_free (children); - nm_setting_ip6_config_clear_dns (page->setting); + nm_setting_ip_config_clear_dns (page->setting); if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) || g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) @@ -787,12 +750,12 @@ ui_to_setting (CEPageIP6 *page) ret = FALSE; } else { widget_unset_error (GTK_WIDGET (entry)); - nm_setting_ip6_config_add_dns (page->setting, &tmp_addr); + nm_setting_ip_config_add_dns (page->setting, text); } } g_list_free (children); - nm_setting_ip6_config_clear_routes (page->setting); + nm_setting_ip_config_clear_routes (page->setting); if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) || g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) || g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) @@ -807,10 +770,9 @@ ui_to_setting (CEPageIP6 *page) const gchar *text_prefix; const gchar *text_gateway; const gchar *text_metric; - struct in6_addr dest, gateway; guint32 prefix, metric; gchar *end; - NMIP6Route *route; + NMIPRoute *route; entry = GTK_ENTRY (g_object_get_data (G_OBJECT (row), "address")); if (!entry) @@ -830,7 +792,7 @@ ui_to_setting (CEPageIP6 *page) continue; } - if (inet_pton (AF_INET6, text_address, &dest) <= 0) { + if (!nm_utils_ipaddr_valid (AF_INET6, text_address)) { widget_set_error (GTK_WIDGET (entry)); ret = FALSE; } else { @@ -845,7 +807,7 @@ ui_to_setting (CEPageIP6 *page) widget_unset_error (g_object_get_data (G_OBJECT (row), "prefix")); } - if (inet_pton (AF_INET6, text_gateway, &gateway) <= 0) { + if (!nm_utils_ipaddr_valid (AF_INET6, text_gateway)) { widget_set_error (g_object_get_data (G_OBJECT (row), "gateway")); ret = FALSE; } else { @@ -869,13 +831,9 @@ ui_to_setting (CEPageIP6 *page) if (!ret) continue; - route = nm_ip6_route_new (); - nm_ip6_route_set_dest (route, &dest); - nm_ip6_route_set_prefix (route, prefix); - nm_ip6_route_set_next_hop (route, &gateway); - nm_ip6_route_set_metric (route, metric); - nm_setting_ip6_config_add_route (page->setting, route); - nm_ip6_route_unref (route); + route = nm_ip_route_new (AF_INET6, text_address, prefix, text_gateway, metric, NULL); + nm_setting_ip_config_add_route (page->setting, route); + nm_ip_route_unref (route); } g_list_free (children); @@ -887,10 +845,10 @@ ui_to_setting (CEPageIP6 *page) never_default = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->never_default)); g_object_set (page->setting, - NM_SETTING_IP6_CONFIG_METHOD, method, - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, - NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, - NM_SETTING_IP6_CONFIG_NEVER_DEFAULT, never_default, + NM_SETTING_IP_CONFIG_METHOD, method, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, ignore_auto_routes, + NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default, NULL); out: @@ -924,21 +882,19 @@ ce_page_ip6_class_init (CEPageIP6Class *class) CEPage * ce_page_ip6_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageIP6 *page; page = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6, connection, client, - settings, "/org/gnome/control-center/network/ip6-page.ui", _("IPv6"))); page->setting = nm_connection_get_setting_ip6_config (connection); if (!page->setting) { - page->setting = NM_SETTING_IP6_CONFIG (nm_setting_ip6_config_new ()); + page->setting = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ()); nm_connection_add_setting (connection, NM_SETTING (page->setting)); } diff --git a/panels/network/connection-editor/ce-page-ip6.h b/panels/network/connection-editor/ce-page-ip6.h index 71d882112..bda432bb1 100644 --- a/panels/network/connection-editor/ce-page-ip6.h +++ b/panels/network/connection-editor/ce-page-ip6.h @@ -43,7 +43,7 @@ struct _CEPageIP6 { CEPage parent; - NMSettingIP6Config *setting; + NMSettingIPConfig *setting; GtkSwitch *enabled; GtkComboBox *method; @@ -63,8 +63,7 @@ struct _CEPageIP6Class GType ce_page_ip6_get_type (void); CEPage *ce_page_ip6_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-reset.c b/panels/network/connection-editor/ce-page-reset.c index 2744689e9..5b24bdc37 100644 --- a/panels/network/connection-editor/ce-page-reset.c +++ b/panels/network/connection-editor/ce-page-reset.c @@ -78,7 +78,6 @@ ce_page_reset_class_init (CEPageResetClass *class) CEPage * ce_page_reset_new (NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, NetConnectionEditor *editor) { CEPageReset *page; @@ -86,7 +85,6 @@ ce_page_reset_new (NMConnection *connection, page = CE_PAGE_RESET (ce_page_new (CE_TYPE_PAGE_RESET, connection, client, - settings, "/org/gnome/control-center/network/reset-page.ui", _("Reset"))); page->editor = editor; diff --git a/panels/network/connection-editor/ce-page-reset.h b/panels/network/connection-editor/ce-page-reset.h index be221c7e6..4915d0a3c 100644 --- a/panels/network/connection-editor/ce-page-reset.h +++ b/panels/network/connection-editor/ce-page-reset.h @@ -56,7 +56,6 @@ GType ce_page_reset_get_type (void); CEPage *ce_page_reset_new (NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, NetConnectionEditor *editor); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-security.c b/panels/network/connection-editor/ce-page-security.c index 80714d5ba..8e64c7a93 100644 --- a/panels/network/connection-editor/ce-page-security.c +++ b/panels/network/connection-editor/ce-page-security.c @@ -24,8 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-utils.h> -#include <nm-connection.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "ce-page-security.h" @@ -211,7 +210,6 @@ finish_setup (CEPageSecurity *page) GtkListStore *sec_model; GtkTreeIter iter; const gchar *mode; - const gchar *security; guint32 dev_caps = 0; NMUtilsSecurityType default_type = NMU_SEC_NONE; int active = -1; @@ -240,9 +238,6 @@ finish_setup (CEPageSecurity *page) page->adhoc = is_adhoc; sws = nm_connection_get_setting_wireless_security (connection); - security = nm_setting_wireless_get_security (sw); - if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) != 0) - sws = NULL; if (sws) default_type = get_default_type_for_security (sws); @@ -390,7 +385,7 @@ validate (CEPage *page, sec = security_combo_get_active (CE_PAGE_SECURITY (page)); if (sec) { - const GByteArray *ssid = nm_setting_wireless_get_ssid (sw); + GBytes *ssid = nm_setting_wireless_get_ssid (sw); if (ssid) { /* FIXME: get failed property and error out of wifi security objects */ @@ -398,15 +393,15 @@ validate (CEPage *page, if (valid) wireless_security_fill_connection (sec, connection); else - g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_UNKNOWN, "Invalid Wi-Fi security"); + g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING, "Invalid Wi-Fi security"); } else { - g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_UNKNOWN, "Missing SSID"); + g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_SETTING, "Missing SSID"); valid = FALSE; } if (CE_PAGE_SECURITY (page)->adhoc) { if (!wireless_security_adhoc_compatible (sec)) { - g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_UNKNOWN, "Security not compatible with Ad-Hoc mode"); + g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING, "Security not compatible with Ad-Hoc mode"); valid = FALSE; } } @@ -414,7 +409,6 @@ validate (CEPage *page, wireless_security_unref (sec); } else { /* No security, unencrypted */ - g_object_set (sw, NM_SETTING_WIRELESS_SEC, NULL, NULL); nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X); valid = TRUE; @@ -453,38 +447,32 @@ ce_page_security_class_init (CEPageSecurityClass *class) CEPage * ce_page_security_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageSecurity *page; - const gchar *security; NMUtilsSecurityType default_type = NMU_SEC_NONE; NMSettingWirelessSecurity *sws; page = CE_PAGE_SECURITY (ce_page_new (CE_TYPE_PAGE_SECURITY, connection, client, - settings, "/org/gnome/control-center/network/security-page.ui", _("Security"))); sws = nm_connection_get_setting_wireless_security (connection); - security = nm_setting_wireless_get_security (nm_connection_get_setting_wireless (connection)); - if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) != 0) - sws = NULL; if (sws) default_type = get_default_type_for_security (sws); - if (default_type == NMU_SEC_STATIC_WEP - || default_type == NMU_SEC_LEAP - || default_type == NMU_SEC_WPA_PSK - || default_type == NMU_SEC_WPA2_PSK) { + if (default_type == NMU_SEC_STATIC_WEP || + default_type == NMU_SEC_LEAP || + default_type == NMU_SEC_WPA_PSK || + default_type == NMU_SEC_WPA2_PSK) { CE_PAGE (page)->security_setting = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME; } - if (default_type == NMU_SEC_DYNAMIC_WEP - || default_type == NMU_SEC_WPA_ENTERPRISE - || default_type == NMU_SEC_WPA2_ENTERPRISE) { + if (default_type == NMU_SEC_DYNAMIC_WEP || + default_type == NMU_SEC_WPA_ENTERPRISE || + default_type == NMU_SEC_WPA2_ENTERPRISE) { CE_PAGE (page)->security_setting = NM_SETTING_802_1X_SETTING_NAME; } diff --git a/panels/network/connection-editor/ce-page-security.h b/panels/network/connection-editor/ce-page-security.h index d76b6b48d..6f692a23d 100644 --- a/panels/network/connection-editor/ce-page-security.h +++ b/panels/network/connection-editor/ce-page-security.h @@ -59,8 +59,7 @@ struct _CEPageSecurityClass GType ce_page_security_get_type (void); CEPage *ce_page_security_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-vpn.c b/panels/network/connection-editor/ce-page-vpn.c index 12ca27db3..56cba0731 100644 --- a/panels/network/connection-editor/ce-page-vpn.c +++ b/panels/network/connection-editor/ce-page-vpn.c @@ -24,7 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-utils.h> +#include <NetworkManager.h> #include "ce-page-vpn.h" #include "vpn-helpers.h" @@ -94,14 +94,9 @@ load_vpn_plugin (CEPageVpn *page, NMConnection *connection) CEPage *parent = CE_PAGE (page); GtkWidget *ui_widget, *failure; - page->ui = nm_vpn_plugin_ui_interface_ui_factory (page->plugin, connection, NULL); - if (!page->ui) { - page->plugin = NULL; - return; - } - ui_widget = GTK_WIDGET (nm_vpn_plugin_ui_widget_interface_get_widget (page->ui)); + ui_widget = GTK_WIDGET (nm_vpn_editor_get_widget (page->editor)); if (!ui_widget) { - g_clear_object (&page->ui); + g_clear_object (&page->editor); page->plugin = NULL; return; } @@ -113,7 +108,7 @@ load_vpn_plugin (CEPageVpn *page, NMConnection *connection) gtk_box_pack_start (page->box, ui_widget, TRUE, TRUE, 0); gtk_widget_show_all (ui_widget); - g_signal_connect_swapped (page->ui, "changed", G_CALLBACK (ce_page_changed), page); + g_signal_connect_swapped (page->editor, "changed", G_CALLBACK (ce_page_changed), page); } static void @@ -158,10 +153,10 @@ validate (CEPage *page, if (!nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error)) return FALSE; - if (!self->ui) + if (!self->editor) return TRUE; - return nm_vpn_plugin_ui_widget_interface_update_connection (self->ui, connection, error); + return nm_vpn_editor_update_connection (self->editor, connection, error); } static void @@ -174,7 +169,7 @@ dispose (GObject *object) { CEPageVpn *page = CE_PAGE_VPN (object); - g_clear_object (&page->ui); + g_clear_object (&page->editor); G_OBJECT_CLASS (ce_page_vpn_parent_class)->dispose (object); } @@ -209,15 +204,13 @@ finish_setup (CEPageVpn *page, gpointer unused, GError *error, gpointer user_dat CEPage * ce_page_vpn_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageVpn *page; page = CE_PAGE_VPN (ce_page_new (CE_TYPE_PAGE_VPN, connection, client, - settings, "/org/gnome/control-center/network/vpn-page.ui", _("Identity"))); diff --git a/panels/network/connection-editor/ce-page-vpn.h b/panels/network/connection-editor/ce-page-vpn.h index dfed60a36..9fa706656 100644 --- a/panels/network/connection-editor/ce-page-vpn.h +++ b/panels/network/connection-editor/ce-page-vpn.h @@ -24,9 +24,7 @@ #include <glib-object.h> -#include <nm-setting-wired.h> -#define NM_VPN_API_SUBJECT_TO_CHANGE -#include <nm-vpn-plugin-ui-interface.h> +#include <NetworkManager.h> #include <gtk/gtk.h> #include "ce-page.h" @@ -48,13 +46,13 @@ struct _CEPageVpn CEPage parent; NMSettingConnection *setting_connection; - NMSettingVPN *setting_vpn; + NMSettingVpn *setting_vpn; GtkEntry *name; GtkBox *box; - NMVpnPluginUiInterface *plugin; - NMVpnPluginUiWidgetInterface *ui; + NMVpnEditorPlugin *plugin; + NMVpnEditor *editor; }; struct _CEPageVpnClass @@ -65,8 +63,7 @@ struct _CEPageVpnClass GType ce_page_vpn_get_type (void); CEPage *ce_page_vpn_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page-wifi.c b/panels/network/connection-editor/ce-page-wifi.c index b6df7f22f..d08a3ea95 100644 --- a/panels/network/connection-editor/ce-page-wifi.c +++ b/panels/network/connection-editor/ce-page-wifi.c @@ -24,9 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-setting-wireless.h> -#include <nm-utils.h> -#include <nm-device-wifi.h> +#include <NetworkManager.h> #include <net/if_arp.h> @@ -54,15 +52,14 @@ connect_wifi_page (CEPageWifi *page) { NMSettingConnection *sc; GtkWidget *widget; - const GByteArray *ssid; + GBytes *ssid; gchar *utf8_ssid; GPtrArray *bssid_array; gchar **bssid_list; - const GByteArray *s_bssid; - gchar *s_bssid_str; + const char *s_bssid_str; gchar **mac_list; - const GByteArray *s_mac; - gchar *s_mac_str; + const gchar *s_mac_str; + const gchar *cloned_mac; gint i; widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, @@ -70,7 +67,7 @@ connect_wifi_page (CEPageWifi *page) ssid = nm_setting_wireless_get_ssid (page->setting); if (ssid) - utf8_ssid = nm_utils_ssid_to_utf8 (ssid); + utf8_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); else utf8_ssid = g_strdup (""); gtk_entry_set_text (GTK_ENTRY (widget), utf8_ssid); @@ -87,10 +84,8 @@ connect_wifi_page (CEPageWifi *page) } g_ptr_array_add (bssid_array, NULL); bssid_list = (gchar **) g_ptr_array_free (bssid_array, FALSE); - s_bssid = nm_setting_wireless_get_bssid (page->setting); - s_bssid_str = s_bssid ? nm_utils_hwaddr_ntoa (s_bssid->data, ARPHRD_ETHER) : NULL; + s_bssid_str = nm_setting_wireless_get_bssid (page->setting); ce_page_setup_mac_combo (GTK_COMBO_BOX_TEXT (widget), s_bssid_str, bssid_list); - g_free (s_bssid_str); g_strfreev (bssid_list); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); @@ -98,18 +93,16 @@ connect_wifi_page (CEPageWifi *page) "combo_mac")); mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_WIFI, NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS); - s_mac = nm_setting_wireless_get_mac_address (page->setting); - s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL; + s_mac_str = nm_setting_wireless_get_mac_address (page->setting); ce_page_setup_mac_combo (GTK_COMBO_BOX_TEXT (widget), s_mac_str, mac_list); - g_free (s_mac_str); g_strfreev (mac_list); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac")); - ce_page_mac_to_entry (nm_setting_wireless_get_cloned_mac_address (page->setting), - ARPHRD_ETHER, GTK_ENTRY (widget)); + cloned_mac = nm_setting_wireless_get_cloned_mac_address (page->setting); + gtk_entry_set_text (GTK_ENTRY (widget), cloned_mac ? cloned_mac : ""); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), page); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, @@ -134,27 +127,24 @@ connect_wifi_page (CEPageWifi *page) static void ui_to_setting (CEPageWifi *page) { - GByteArray *ssid; - GByteArray *bssid = NULL; - GByteArray *device_mac = NULL; - GByteArray *cloned_mac = NULL; + GBytes *ssid; + const gchar *utf8_ssid, *bssid; GtkWidget *entry; - const gchar *utf8_ssid; + char *device_mac, *cloned_mac; entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_ssid")); utf8_ssid = gtk_entry_get_text (GTK_ENTRY (entry)); if (!utf8_ssid || !*utf8_ssid) ssid = NULL; else { - ssid = g_byte_array_sized_new (strlen (utf8_ssid)); - g_byte_array_append (ssid, (const guint8*)utf8_ssid, strlen (utf8_ssid)); + ssid = g_bytes_new_static (utf8_ssid, strlen (utf8_ssid)); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_bssid"))); - bssid = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); + bssid = gtk_entry_get_text (GTK_ENTRY (entry)); entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_mac"))); - device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); + device_mac = ce_page_trim_address (gtk_entry_get_text (GTK_ENTRY (entry))); entry = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "entry_cloned_mac")); - cloned_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL); + cloned_mac = ce_page_trim_address (gtk_entry_get_text (GTK_ENTRY (entry))); g_object_set (page->setting, NM_SETTING_WIRELESS_SSID, ssid, @@ -164,13 +154,9 @@ ui_to_setting (CEPageWifi *page) NULL); if (ssid) - g_byte_array_free (ssid, TRUE); - if (bssid) - g_byte_array_free (bssid, TRUE); - if (device_mac) - g_byte_array_free (device_mac, TRUE); - if (cloned_mac) - g_byte_array_free (cloned_mac, TRUE); + g_bytes_unref (ssid); + g_free (cloned_mac); + g_free (device_mac); } static gboolean @@ -179,42 +165,29 @@ validate (CEPage *page, GError **error) { GtkWidget *entry; - GByteArray *ignore; - gboolean invalid; - gchar *security; - NMSettingWireless *setting; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_bssid"))); - ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); - if (invalid) { + if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) { widget_set_error (entry); ret = FALSE; } else { - if (ignore) - g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_mac"))); - ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); - if (invalid) { + if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) { widget_set_error (entry); ret = FALSE; } else { - if (ignore) - g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = GTK_WIDGET (gtk_builder_get_object (page->builder, "entry_cloned_mac")); - ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); - if (invalid) { + if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) { widget_set_error (entry); ret = FALSE; } else { - if (ignore) - g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } @@ -223,14 +196,6 @@ validate (CEPage *page, ui_to_setting (CE_PAGE_WIFI (page)); - /* A hack to not check the wifi security here */ - setting = CE_PAGE_WIFI (page)->setting; - security = g_strdup (nm_setting_wireless_get_security (setting)); - g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); - ret = nm_setting_verify (NM_SETTING (setting), NULL, error); - g_object_set (setting, NM_SETTING_WIRELESS_SEC, security, NULL); - g_free (security); - return ret; } @@ -249,15 +214,13 @@ ce_page_wifi_class_init (CEPageWifiClass *class) CEPage * ce_page_wifi_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { CEPageWifi *page; page = CE_PAGE_WIFI (ce_page_new (CE_TYPE_PAGE_WIFI, connection, client, - settings, "/org/gnome/control-center/network/wifi-page.ui", _("Identity"))); diff --git a/panels/network/connection-editor/ce-page-wifi.h b/panels/network/connection-editor/ce-page-wifi.h index 88087e710..28c3024f0 100644 --- a/panels/network/connection-editor/ce-page-wifi.h +++ b/panels/network/connection-editor/ce-page-wifi.h @@ -54,8 +54,7 @@ struct _CEPageWifiClass GType ce_page_wifi_get_type (void); CEPage *ce_page_wifi_new (NMConnection *connection, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); G_END_DECLS diff --git a/panels/network/connection-editor/ce-page.c b/panels/network/connection-editor/ce-page.c index 59a6df6c2..1b4e08215 100644 --- a/panels/network/connection-editor/ce-page.c +++ b/panels/network/connection-editor/ce-page.c @@ -26,7 +26,7 @@ #include <net/if_arp.h> #include <netinet/ether.h> -#include <nm-utils.h> +#include <NetworkManager.h> #include <glib/gi18n.h> @@ -218,7 +218,6 @@ CEPage * ce_page_new (GType type, NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, const gchar *ui_resource, const gchar *title) { @@ -230,7 +229,6 @@ ce_page_new (GType type, NULL)); page->title = g_strdup (title); page->client = client; - page->settings= settings; if (ui_resource) { if (!gtk_builder_add_from_resource (page->builder, ui_resource, &error)) { @@ -258,50 +256,60 @@ emit_initialized (CEPage *page, { page->initialized = TRUE; g_signal_emit (page, signals[INITIALIZED], 0, error); + g_clear_error (&error); } void ce_page_complete_init (CEPage *page, const gchar *setting_name, - GHashTable *secrets, + GVariant *secrets, GError *error) { - GHashTable *setting_hash; - GError *update_error = NULL; - - if (error - && !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.InvalidSetting") - && !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.AgentManager.NoSecrets")) { - emit_initialized (page, error); - return; - } else if (!setting_name || !secrets || !g_hash_table_size (secrets)) { - /* Success, no secrets */ - emit_initialized (page, NULL); - return; - } - - setting_hash = g_hash_table_lookup (secrets, setting_name); - if (!setting_hash) { - /* Success, no secrets */ - emit_initialized (page, NULL); - return; - } - - if (nm_connection_update_secrets (page->connection, - setting_name, - secrets, - &update_error)) { - emit_initialized (page, NULL); - return; - } - - if (!update_error) { - g_set_error_literal (&update_error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_UNKNOWN, - "Failed to update connection secrets due to an unknown error."); - } - - emit_initialized (page, update_error); - g_clear_error (&update_error); + GError *update_error = NULL; + GVariant *setting_dict; + gboolean ignore_error = FALSE; + + g_return_if_fail (page != NULL); + g_return_if_fail (CE_IS_PAGE (page)); + + if (error) { + ignore_error = g_error_matches (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND) || + g_error_matches (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NO_SECRETS); + } + + /* Ignore missing settings errors */ + if (error && !ignore_error) { + emit_initialized (page, error); + return; + } else if (!setting_name || !secrets || g_variant_n_children (secrets) == 0) { + /* Success, no secrets */ + emit_initialized (page, NULL); + return; + } + + g_assert (setting_name); + g_assert (secrets); + + setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING); + if (!setting_dict) { + /* Success, no secrets */ + emit_initialized (page, NULL); + return; + } + g_variant_unref (setting_dict); + + /* Update the connection with the new secrets */ + if (nm_connection_update_secrets (page->connection, + setting_name, + secrets, + &update_error)) { + /* Success */ + emit_initialized (page, NULL); + return; + } + + g_warning ("Failed to update connection secrets due to an unknown error."); + emit_initialized (page, NULL); } gchar ** @@ -367,94 +375,60 @@ ce_page_setup_mac_combo (GtkComboBoxText *combo, } } -void -ce_page_mac_to_entry (const GByteArray *mac, - gint type, - GtkEntry *entry) +gchar * +ce_page_trim_address (const gchar *addr) { - char *str_addr; - - g_return_if_fail (entry != NULL); - g_return_if_fail (GTK_IS_ENTRY (entry)); - - if (!mac || !mac->len) - return; + char *space; - if (mac->len != nm_utils_hwaddr_len (type)) - return; + if (!addr || *addr == '\0') + return NULL; - str_addr = nm_utils_hwaddr_ntoa (mac->data, type); - gtk_entry_set_text (entry, str_addr); - g_free (str_addr); + space = strchr (addr, ' '); + if (space != NULL) + return g_strndup (addr, space - addr); + return g_strdup (addr); } -static gboolean -utils_ether_addr_valid (const struct ether_addr *test_addr) +gboolean +ce_page_address_is_valid (const gchar *addr) { - guint8 invalid_addr1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - guint8 invalid_addr2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - guint8 invalid_addr3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44}; - guint8 invalid_addr4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */ - - g_return_val_if_fail (test_addr != NULL, FALSE); - - /* Compare the AP address the card has with invalid ethernet MAC addresses. */ - if (!memcmp (test_addr->ether_addr_octet, &invalid_addr1, ETH_ALEN)) + guint8 invalid_addr[4][ETH_ALEN] = { + {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, + {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}, /* prism54 dummy MAC */ + }; + guint8 addr_bin[ETH_ALEN]; + char *trimmed_addr; + guint i; + + if (!addr || *addr == '\0') + return TRUE; + + trimmed_addr = ce_page_trim_address (addr); + + if (!nm_utils_hwaddr_valid (trimmed_addr, -1)) { + g_free (trimmed_addr); return FALSE; + } - if (!memcmp (test_addr->ether_addr_octet, &invalid_addr2, ETH_ALEN)) + if (!nm_utils_hwaddr_aton (trimmed_addr, addr_bin, ETH_ALEN)) { + g_free (trimmed_addr); return FALSE; + } - if (!memcmp (test_addr->ether_addr_octet, &invalid_addr3, ETH_ALEN)) - return FALSE; - if (!memcmp (test_addr->ether_addr_octet, &invalid_addr4, ETH_ALEN)) - return FALSE; + g_free (trimmed_addr); - if (test_addr->ether_addr_octet[0] & 1) /* Multicast addresses */ + /* Check for multicast address */ + if ((((guint8 *) addr_bin)[0]) & 0x01) return FALSE; - - return TRUE; -} -GByteArray * -ce_page_entry_to_mac (GtkEntry *entry, - gint type, - gboolean *invalid) -{ - const char *temp, *sp; - char *buf = NULL; - GByteArray *mac; - - g_return_val_if_fail (entry != NULL, NULL); - g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL); - - if (invalid) - *invalid = FALSE; - - temp = gtk_entry_get_text (entry); - if (!temp || !strlen (temp)) - return NULL; - - sp = strchr (temp, ' '); - if (sp) - temp = buf = g_strndup (temp, sp - temp); - - mac = nm_utils_hwaddr_atoba (temp, type); - g_free (buf); - if (!mac) { - if (invalid) - *invalid = TRUE; - return NULL; + for (i = 0; i < G_N_ELEMENTS (invalid_addr); i++) { + if (nm_utils_hwaddr_matches (addr_bin, ETH_ALEN, invalid_addr[i], ETH_ALEN)) + return FALSE; } - if (type == ARPHRD_ETHER && !utils_ether_addr_valid ((struct ether_addr *)mac->data)) { - g_byte_array_free (mac, TRUE); - if (invalid) - *invalid = TRUE; - return NULL; - } - - return mac; + return TRUE; } const gchar * @@ -516,18 +490,20 @@ ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data) } gchar * -ce_page_get_next_available_name (GSList *connections, +ce_page_get_next_available_name (const GPtrArray *connections, NameFormat format, const gchar *type_name) { GSList *names = NULL, *l; gchar *cname = NULL; gint i = 0; + guint con_idx; - for (l = connections; l; l = l->next) { + for (con_idx = 0; con_idx < connections->len; con_idx++) { + NMConnection *connection = g_ptr_array_index (connections, con_idx); const gchar *id; - id = nm_connection_get_id (NM_CONNECTION (l->data)); + id = nm_connection_get_id (connection); g_assert (id); names = g_slist_append (names, (gpointer) id); } diff --git a/panels/network/connection-editor/ce-page.h b/panels/network/connection-editor/ce-page.h index 2d064bb11..34cf4afa4 100644 --- a/panels/network/connection-editor/ce-page.h +++ b/panels/network/connection-editor/ce-page.h @@ -24,9 +24,7 @@ #include <glib-object.h> -#include <nm-connection.h> -#include <nm-client.h> -#include <nm-remote-settings.h> +#include <NetworkManager.h> #include <gtk/gtk.h> @@ -54,7 +52,6 @@ struct _CEPage NMConnection *connection; NMClient *client; - NMRemoteSettings *settings; GCancellable *cancellable; }; @@ -80,12 +77,11 @@ void ce_page_changed (CEPage *page); CEPage *ce_page_new (GType type, NMConnection *connection, NMClient *client, - NMRemoteSettings *settings, const gchar *ui_resource, const gchar *title); void ce_page_complete_init (CEPage *page, const gchar *setting_name, - GHashTable *secrets, + GVariant *variant, GError *error); gchar **ce_page_get_mac_list (NMClient *client, @@ -94,23 +90,19 @@ gchar **ce_page_get_mac_list (NMClient *client, void ce_page_setup_mac_combo (GtkComboBoxText *combo, const gchar *current_mac, gchar **mac_list); -void ce_page_mac_to_entry (const GByteArray *mac, - gint type, - GtkEntry *entry); -GByteArray *ce_page_entry_to_mac (GtkEntry *entry, - gint type, - gboolean *invalid); gint ce_get_property_default (NMSetting *setting, const gchar *property_name); gint ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data); +gboolean ce_page_address_is_valid (const gchar *addr); +gchar *ce_page_trim_address (const gchar *addr); typedef enum { NAME_FORMAT_TYPE, NAME_FORMAT_PROFILE } NameFormat; -gchar * ce_page_get_next_available_name (GSList *connections, +gchar * ce_page_get_next_available_name (const GPtrArray *connections, NameFormat format, const gchar *type_name); diff --git a/panels/network/connection-editor/firewall-helpers.h b/panels/network/connection-editor/firewall-helpers.h index 74473bdc6..213c515e8 100644 --- a/panels/network/connection-editor/firewall-helpers.h +++ b/panels/network/connection-editor/firewall-helpers.h @@ -19,7 +19,7 @@ #ifndef _FIREWALL_HELPERS_H_ #define _FIREWALL_HELPERS_H_ -#include <nm-setting-connection.h> +#include <NetworkManager.h> #include <gtk/gtk.h> void firewall_ui_setup (NMSettingConnection *setting, diff --git a/panels/network/connection-editor/net-connection-editor.c b/panels/network/connection-editor/net-connection-editor.c index 0ea348686..930d631f3 100644 --- a/panels/network/connection-editor/net-connection-editor.c +++ b/panels/network/connection-editor/net-connection-editor.c @@ -24,8 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-utils.h> -#include <nm-device-wifi.h> +#include <NetworkManager.h> #include "shell/list-box-helper.h" #include "net-connection-editor.h" @@ -79,47 +78,63 @@ cancel_editing (NetConnectionEditor *editor) static void update_connection (NetConnectionEditor *editor) { - GHashTable *settings; + GVariant *settings; - settings = nm_connection_to_hash (editor->connection, NM_SETTING_HASH_FLAG_ALL); + settings = nm_connection_to_dbus (editor->connection, NM_CONNECTION_SERIALIZE_ALL); nm_connection_replace_settings (editor->orig_connection, settings, NULL); - g_hash_table_destroy (settings); + g_variant_unref (settings); } static void -update_complete (NetConnectionEditor *editor, GError *error) +update_complete (NetConnectionEditor *editor, + gboolean success) { gtk_widget_hide (editor->window); - g_signal_emit (editor, signals[DONE], 0, !error); + g_signal_emit (editor, signals[DONE], 0, success); } static void -updated_connection_cb (NMRemoteConnection *connection, - GError *error, - gpointer data) +updated_connection_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - NetConnectionEditor *editor = data; + NetConnectionEditor *editor; + GError *error = NULL; + gboolean success = TRUE; + + if (!nm_remote_connection_commit_changes_finish (NM_REMOTE_CONNECTION (source_object), + res, &error)) { + g_warning ("Failed to commit changes: %s", error->message); + success = FALSE; + g_error_free (error); + //return; FIXME return if cancelled + } - nm_connection_clear_secrets (NM_CONNECTION (connection)); + nm_connection_clear_secrets (NM_CONNECTION (source_object)); - update_complete (editor, error); + editor = user_data; + update_complete (editor, success); } static void -added_connection_cb (NMRemoteSettings *settings, - NMRemoteConnection *connection, - GError *error, - gpointer data) +added_connection_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - NetConnectionEditor *editor = data; + NetConnectionEditor *editor; + GError *error = NULL; + gboolean success = TRUE; - if (error) { + if (!nm_client_add_connection_finish (NM_CLIENT (source_object), res, &error)) { g_warning ("Failed to add connection: %s", error->message); + success = FALSE; + g_error_free (error); /* Leave the editor open */ - return; + // return; FIXME return if cancelled } - update_complete (editor, error); + editor = user_data; + update_complete (editor, success); } static void @@ -128,13 +143,17 @@ apply_edits (NetConnectionEditor *editor) update_connection (editor); if (editor->is_new_connection) { - nm_remote_settings_add_connection (editor->settings, - editor->orig_connection, - added_connection_cb, - editor); + nm_client_add_connection_async (editor->client, + editor->orig_connection, + TRUE, + NULL, + added_connection_cb, + editor); } else { - nm_remote_connection_commit_changes (NM_REMOTE_CONNECTION (editor->orig_connection), - updated_connection_cb, editor); + nm_remote_connection_commit_changes_async (NM_REMOTE_CONNECTION (editor->orig_connection), + TRUE, + NULL, + updated_connection_cb, editor); } } @@ -200,7 +219,6 @@ net_connection_editor_finalize (GObject *object) g_clear_object (&editor->parent_window); g_clear_object (&editor->builder); g_clear_object (&editor->device); - g_clear_object (&editor->settings); g_clear_object (&editor->client); g_clear_object (&editor->ap); @@ -299,9 +317,9 @@ net_connection_editor_update_title (NetConnectionEditor *editor) NMSettingWireless *sw; sw = nm_connection_get_setting_wireless (editor->connection); if (sw) { - const GByteArray *ssid; + GBytes *ssid; ssid = nm_setting_wireless_get_ssid (sw); - id = nm_utils_ssid_to_utf8 (ssid); + id = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); } else { id = g_strdup (nm_connection_get_id (editor->connection)); } @@ -437,23 +455,29 @@ typedef struct { NetConnectionEditor *editor; CEPage *page; const gchar *setting_name; - gboolean canceled; } GetSecretsInfo; static void -get_secrets_cb (NMRemoteConnection *connection, - GHashTable *secrets, - GError *error, - gpointer user_data) +get_secrets_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { + NMRemoteConnection *connection; GetSecretsInfo *info = user_data; + GError *error = NULL; + GVariant *variant; + + connection = NM_REMOTE_CONNECTION (source_object); + variant = nm_remote_connection_get_secrets_finish (connection, res, &error); - if (info->canceled) { + if (!variant && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); g_free (info); return; } - ce_page_complete_init (info->page, info->setting_name, secrets, error); + ce_page_complete_init (info->page, info->setting_name, variant, error); + g_variant_unref (variant); g_free (info); } @@ -469,10 +493,11 @@ get_secrets_for_page (NetConnectionEditor *editor, info->page = page; info->setting_name = setting_name; - nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (editor->orig_connection), - setting_name, - get_secrets_cb, - info); + nm_remote_connection_get_secrets_async (NM_REMOTE_CONNECTION (editor->orig_connection), + setting_name, + NULL, //FIXME + get_secrets_cb, + info); } static void @@ -508,8 +533,8 @@ net_connection_editor_set_connection (NetConnectionEditor *editor, GtkTreeSelection *selection; GtkTreePath *path; - editor->is_new_connection = !nm_remote_settings_get_connection_by_uuid (editor->settings, - nm_connection_get_uuid (connection)); + editor->is_new_connection = !nm_client_get_connection_by_uuid (editor->client, + nm_connection_get_uuid (connection)); if (editor->is_new_connection) { GtkWidget *button; @@ -519,7 +544,7 @@ net_connection_editor_set_connection (NetConnectionEditor *editor, editor->is_changed = TRUE; } - editor->connection = nm_connection_duplicate (connection); + editor->connection = nm_simple_connection_new_clone (connection); editor->orig_connection = g_object_ref (connection); net_connection_editor_update_title (editor); @@ -528,30 +553,30 @@ net_connection_editor_set_connection (NetConnectionEditor *editor, type = nm_setting_connection_get_connection_type (sc); if (!editor->is_new_connection) - add_page (editor, ce_page_details_new (editor->connection, editor->client, editor->settings, editor->device, editor->ap)); + add_page (editor, ce_page_details_new (editor->connection, editor->client, editor->device, editor->ap)); if (strcmp (type, NM_SETTING_WIRELESS_SETTING_NAME) == 0) - add_page (editor, ce_page_security_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_security_new (editor->connection, editor->client)); else if (strcmp (type, NM_SETTING_WIRED_SETTING_NAME) == 0) - add_page (editor, ce_page_8021x_security_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_8021x_security_new (editor->connection, editor->client)); if (strcmp (type, NM_SETTING_WIRELESS_SETTING_NAME) == 0) - add_page (editor, ce_page_wifi_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_wifi_new (editor->connection, editor->client)); else if (strcmp (type, NM_SETTING_WIRED_SETTING_NAME) == 0) - add_page (editor, ce_page_ethernet_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_ethernet_new (editor->connection, editor->client)); else if (strcmp (type, NM_SETTING_VPN_SETTING_NAME) == 0) - add_page (editor, ce_page_vpn_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_vpn_new (editor->connection, editor->client)); else { /* Unsupported type */ net_connection_editor_do_fallback (editor, type); return; } - add_page (editor, ce_page_ip4_new (editor->connection, editor->client, editor->settings)); - add_page (editor, ce_page_ip6_new (editor->connection, editor->client, editor->settings)); + add_page (editor, ce_page_ip4_new (editor->connection, editor->client)); + add_page (editor, ce_page_ip6_new (editor->connection, editor->client)); if (!editor->is_new_connection) - add_page (editor, ce_page_reset_new (editor->connection, editor->client, editor->settings, editor)); + add_page (editor, ce_page_reset_new (editor->connection, editor->client, editor)); pages = g_slist_copy (editor->initializing_pages); for (l = pages; l; l = l->next) { @@ -593,7 +618,7 @@ complete_connection_for_type (NetConnectionEditor *editor, NMConnection *connect GType connection_gtype; if (!connection) - connection = nm_connection_new (); + connection = nm_simple_connection_new (); s_con = nm_connection_get_setting_connection (connection); if (!s_con) { @@ -610,16 +635,15 @@ complete_connection_for_type (NetConnectionEditor *editor, NMConnection *connect } if (!nm_setting_connection_get_id (s_con)) { - GSList *connections; + const GPtrArray *connections; gchar *id; - connections = nm_remote_settings_list_connections (editor->settings); + connections = nm_client_get_connections (editor->client); id = ce_page_get_next_available_name (connections, NAME_FORMAT_TYPE, _(connection_type->name)); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL); g_free (id); - g_slist_free (connections); } connection_gtype = connection_type->type_func (); @@ -638,25 +662,6 @@ complete_connection_for_type (NetConnectionEditor *editor, NMConnection *connect return connection; } -static gint -sort_vpn_plugins (gconstpointer a, gconstpointer b) -{ - NMVpnPluginUiInterface *aa = NM_VPN_PLUGIN_UI_INTERFACE (a); - NMVpnPluginUiInterface *bb = NM_VPN_PLUGIN_UI_INTERFACE (b); - char *aa_desc = NULL, *bb_desc = NULL; - int ret; - - g_object_get (aa, NM_VPN_PLUGIN_UI_INTERFACE_NAME, &aa_desc, NULL); - g_object_get (bb, NM_VPN_PLUGIN_UI_INTERFACE_NAME, &bb_desc, NULL); - - ret = g_strcmp0 (aa_desc, bb_desc); - - g_free (aa_desc); - g_free (bb_desc); - - return ret; -} - static void finish_add_connection (NetConnectionEditor *editor, NMConnection *connection) { @@ -694,7 +699,7 @@ vpn_type_activated (GtkListBox *list, GtkWidget *row, NetConnectionEditor *edito { const char *service_name = g_object_get_data (G_OBJECT (row), "service_name"); NMConnection *connection; - NMSettingVPN *s_vpn; + NMSettingVpn *s_vpn; NMSettingConnection *s_con; if (!strcmp (service_name, "import")) { @@ -717,38 +722,22 @@ vpn_type_activated (GtkListBox *list, GtkWidget *row, NetConnectionEditor *edito static void select_vpn_type (NetConnectionEditor *editor, GtkListBox *list) { - GHashTable *vpn_plugins; - GHashTableIter vpn_iter; - gpointer service_name, vpn_plugin; - GList *children, *plugin_list, *iter; + GSList *vpn_plugins, *iter; + GList *l; + GList *children; GtkWidget *row, *row_box; GtkWidget *name_label, *desc_label; - GError *error = NULL; /* Get the available VPN types */ - vpn_plugins = vpn_get_plugins (&error); - if (!vpn_plugins) { - net_connection_editor_error_dialog (editor, - _("Could not load VPN plugins"), - error->message); - g_error_free (error); - finish_add_connection (editor, NULL); - g_signal_emit (editor, signals[DONE], 0, FALSE); - return; - } - plugin_list = NULL; - g_hash_table_iter_init (&vpn_iter, vpn_plugins); - while (g_hash_table_iter_next (&vpn_iter, &service_name, &vpn_plugin)) - plugin_list = g_list_prepend (plugin_list, vpn_plugin); - plugin_list = g_list_sort (plugin_list, sort_vpn_plugins); + vpn_plugins = vpn_get_plugins (); /* Remove the previous menu contents */ children = gtk_container_get_children (GTK_CONTAINER (list)); - for (iter = children; iter; iter = iter->next) - gtk_widget_destroy (iter->data); + for (l = children; l != NULL; l = l->next) + gtk_widget_destroy (l->data); /* Add the VPN types */ - for (iter = plugin_list; iter; iter = iter->next) { + for (iter = vpn_plugins; iter; iter = iter->next) { char *name, *desc, *desc_markup, *service_name; GtkStyleContext *context; @@ -894,8 +883,7 @@ net_connection_editor_new (GtkWindow *parent_window, NMConnection *connection, NMDevice *device, NMAccessPoint *ap, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { NetConnectionEditor *editor; @@ -911,7 +899,6 @@ net_connection_editor_new (GtkWindow *parent_window, if (device) editor->device = g_object_ref (device); editor->client = g_object_ref (client); - editor->settings = g_object_ref (settings); editor->can_modify = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM); editor->permission_id = g_signal_connect (editor->client, "permission-changed", @@ -936,16 +923,21 @@ net_connection_editor_present (NetConnectionEditor *editor) } static void -forgotten_cb (NMRemoteConnection *connection, - GError *error, - gpointer data) +forgotten_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - NetConnectionEditor *editor = data; + NMRemoteConnection *connection = NM_REMOTE_CONNECTION (source_object); + NetConnectionEditor *editor = user_data; + GError *error = NULL; - if (error != NULL) { - g_warning ("Failed to delete conneciton %s: %s", - nm_connection_get_id (NM_CONNECTION (connection)), - error->message); + if (!nm_remote_connection_delete_finish (connection, res, &error)) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to delete conneciton %s: %s", + nm_connection_get_id (NM_CONNECTION (connection)), + error->message); + g_error_free (error); + return; } cancel_editing (editor); @@ -954,17 +946,18 @@ forgotten_cb (NMRemoteConnection *connection, void net_connection_editor_forget (NetConnectionEditor *editor) { - nm_remote_connection_delete (NM_REMOTE_CONNECTION (editor->orig_connection), forgotten_cb, editor); + nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (editor->orig_connection), + NULL, forgotten_cb, editor); } void net_connection_editor_reset (NetConnectionEditor *editor) { - GHashTable *settings; + GVariant *settings; - settings = nm_connection_to_hash (editor->orig_connection, NM_SETTING_HASH_FLAG_ALL); + settings = nm_connection_to_dbus (editor->orig_connection, NM_CONNECTION_SERIALIZE_ALL); nm_connection_replace_settings (editor->connection, settings, NULL); - g_hash_table_destroy (settings); + g_variant_unref (settings); } void diff --git a/panels/network/connection-editor/net-connection-editor.h b/panels/network/connection-editor/net-connection-editor.h index d3fdd9afb..431edf2d4 100644 --- a/panels/network/connection-editor/net-connection-editor.h +++ b/panels/network/connection-editor/net-connection-editor.h @@ -25,9 +25,7 @@ #include <glib-object.h> #include <gtk/gtk.h> -#include <nm-client.h> -#include <nm-access-point.h> -#include <nm-remote-settings.h> +#include <NetworkManager.h> G_BEGIN_DECLS @@ -48,7 +46,6 @@ struct _NetConnectionEditor GtkWidget *parent_window; NMClient *client; NMDevice *device; - NMRemoteSettings *settings; NMConnection *connection; NMConnection *orig_connection; @@ -81,8 +78,7 @@ NetConnectionEditor *net_connection_editor_new (GtkWindow *parent_wi NMConnection *connection, NMDevice *device, NMAccessPoint *ap, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); void net_connection_editor_set_title (NetConnectionEditor *editor, const gchar *title); void net_connection_editor_run (NetConnectionEditor *editor); diff --git a/panels/network/connection-editor/vpn-helpers.c b/panels/network/connection-editor/vpn-helpers.c index b000a7efb..320f8cbaa 100644 --- a/panels/network/connection-editor/vpn-helpers.c +++ b/panels/network/connection-editor/vpn-helpers.c @@ -27,144 +27,75 @@ #include <gmodule.h> #include <gtk/gtk.h> #include <glib/gi18n.h> - -#include <nm-connection.h> -#include <nm-setting-connection.h> -#include <nm-setting-vpn.h> +#include <NetworkManager.h> #include "vpn-helpers.h" -#define NM_VPN_API_SUBJECT_TO_CHANGE -#include "nm-vpn-plugin-ui-interface.h" - -static GHashTable *plugins = NULL; - -NMVpnPluginUiInterface * +NMVpnEditorPlugin * vpn_get_plugin_by_service (const char *service) { - g_return_val_if_fail (service != NULL, NULL); + NMVpnPluginInfo *plugin_info; - if (!plugins) { - vpn_get_plugins (NULL); - if (!plugins) - return NULL; - } - return g_hash_table_lookup (plugins, service); + g_return_val_if_fail (service != NULL, NULL); + + plugin_info = nm_vpn_plugin_info_list_find_by_service (vpn_get_plugins (), service); + if (plugin_info) + return nm_vpn_plugin_info_get_editor_plugin (plugin_info); + return NULL; } -GHashTable * -vpn_get_plugins (GError **error) +static gint +_sort_vpn_plugins (NMVpnPluginInfo *aa, NMVpnPluginInfo *bb) { - GDir *dir; - const char *f; + return strcmp (nm_vpn_plugin_info_get_name (aa), nm_vpn_plugin_info_get_name (bb)); +} - if (error) - g_return_val_if_fail (*error == NULL, NULL); +GSList * +vpn_get_plugins (void) +{ + static gboolean plugins_loaded = FALSE; + static GSList *plugins = NULL; + GSList *p; - if (plugins) + if (G_LIKELY (plugins_loaded)) return plugins; - - dir = g_dir_open (NM_VPN_CONFIG_DIR, 0, error); - if (!dir) - return NULL; - - plugins = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); - - while ((f = g_dir_read_name (dir))) { - char *path = NULL, *service = NULL; - char *so_path = NULL, *so_name = NULL; - GKeyFile *keyfile = NULL; - GModule *module = NULL; - NMVpnPluginUiFactory factory = NULL; - - if (!g_str_has_suffix (f, ".name")) - continue; - - path = g_strdup_printf ("%s/%s", NM_VPN_CONFIG_DIR, f); - - keyfile = g_key_file_new (); - if (!g_key_file_load_from_file (keyfile, path, 0, NULL)) - goto next; - - service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL); - if (!service) - goto next; - - so_path = g_key_file_get_string (keyfile, "GNOME", "properties", NULL); - if (!so_path) - goto next; - - if (g_path_is_absolute (so_path)) - module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - - if (!module) { - /* Remove any path and extension components, then reconstruct path - * to the SO in LIBDIR - */ - so_name = g_path_get_basename (so_path); - g_free (so_path); - so_path = g_build_filename (NM_VPN_MODULE_DIR, so_name, NULL); - g_free (so_name); - - module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - if (!module) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot load the VPN plugin which provides the " - "service '%s'.", service); - goto next; - } - } - - if (g_module_symbol (module, "nm_vpn_plugin_ui_factory", (gpointer) &factory)) { - NMVpnPluginUiInterface *plugin; - GError *factory_error = NULL; - gboolean success = FALSE; - - plugin = factory (&factory_error); - if (plugin) { - char *plug_name = NULL, *plug_service = NULL; - - /* Validate plugin properties */ - g_object_get (G_OBJECT (plugin), - NM_VPN_PLUGIN_UI_INTERFACE_NAME, &plug_name, - NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, &plug_service, - NULL); - if (!plug_name || !strlen (plug_name)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': missing plugin name", - g_module_name (module)); - } else if (!plug_service || strcmp (plug_service, service)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': invalid service name", - g_module_name (module)); - } else { - /* Success! */ - g_object_set_data_full (G_OBJECT (plugin), "gmodule", module, - (GDestroyNotify) g_module_close); - g_hash_table_insert (plugins, g_strdup (service), plugin); - success = TRUE; - } - g_free (plug_name); - g_free (plug_service); + plugins_loaded = TRUE; + + p = nm_vpn_plugin_info_list_load (); + plugins = NULL; + while (p) { + NMVpnPluginInfo *plugin_info = NM_VPN_PLUGIN_INFO (p->data); + GError *error = NULL; + + /* load the editor plugin, and preserve only those NMVpnPluginInfo that can + * successfully load the plugin. */ + if (nm_vpn_plugin_info_load_editor_plugin (plugin_info, &error)) + plugins = g_slist_prepend (plugins, plugin_info); + else { + if ( !nm_vpn_plugin_info_get_plugin (plugin_info) + && nm_vpn_plugin_info_lookup_property (plugin_info, NM_VPN_PLUGIN_INFO_KF_GROUP_GNOME, "properties")) { + g_message ("vpn: (%s,%s) cannot load legacy-only plugin", + nm_vpn_plugin_info_get_name (plugin_info), + nm_vpn_plugin_info_get_filename (plugin_info)); + } else if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + g_message ("vpn: (%s,%s) file \"%s\" not found. Did you install the client package?", + nm_vpn_plugin_info_get_name (plugin_info), + nm_vpn_plugin_info_get_filename (plugin_info), + nm_vpn_plugin_info_get_plugin (plugin_info)); } else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot load VPN plugin in '%s': %s", - g_module_name (module), g_module_error ()); + g_warning ("vpn: (%s,%s) could not load plugin: %s", + nm_vpn_plugin_info_get_name (plugin_info), + nm_vpn_plugin_info_get_filename (plugin_info), + error->message); } - - if (!success) - g_module_close (module); - } else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "cannot locate nm_vpn_plugin_ui_factory() in '%s': %s", - g_module_name (module), g_module_error ()); - g_module_close (module); + g_clear_error (&error); + g_object_unref (plugin_info); } - - next: - g_free (so_path); - g_free (service); - g_key_file_free (keyfile); - g_free (path); + p = g_slist_delete_link (p, p); } - g_dir_close (dir); + /* sort the list of plugins alphabetically. */ + plugins = g_slist_sort (plugins, (GCompareFunc) _sort_vpn_plugins); return plugins; } @@ -178,11 +109,9 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data) { char *filename = NULL; ActionInfo *info = (ActionInfo *) user_data; - GHashTableIter iter; - gpointer key; - NMVpnPluginUiInterface *plugin; NMConnection *connection = NULL; GError *error = NULL; + GSList *iter; if (response != GTK_RESPONSE_ACCEPT) goto out; @@ -193,10 +122,12 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data) goto out; } - g_hash_table_iter_init (&iter, plugins); - while (!connection && g_hash_table_iter_next (&iter, &key, (gpointer *)&plugin)) { + for (iter = vpn_get_plugins (); !connection && iter; iter = iter->next) { + NMVpnEditorPlugin *plugin; + + plugin = nm_vpn_plugin_info_get_editor_plugin (iter->data); g_clear_error (&error); - connection = nm_vpn_plugin_ui_interface_import (plugin, filename, &error); + connection = nm_vpn_editor_plugin_import (plugin, filename, &error); } if (!connection) { @@ -270,9 +201,9 @@ export_vpn_to_file_cb (GtkWidget *dialog, gint response, gpointer user_data) NMConnection *connection = NM_CONNECTION (user_data); char *filename = NULL; GError *error = NULL; - NMVpnPluginUiInterface *plugin; + NMVpnEditorPlugin *plugin; NMSettingConnection *s_con = NULL; - NMSettingVPN *s_vpn = NULL; + NMSettingVpn *s_vpn = NULL; const char *service_type; const char *id = NULL; gboolean success = FALSE; @@ -325,7 +256,7 @@ export_vpn_to_file_cb (GtkWidget *dialog, gint response, gpointer user_data) plugin = vpn_get_plugin_by_service (service_type); if (plugin) - success = nm_vpn_plugin_ui_interface_export (plugin, filename, connection, &error); + success = nm_vpn_editor_plugin_export (plugin, filename, connection, &error); done: if (!success) { @@ -360,8 +291,8 @@ void vpn_export (NMConnection *connection) { GtkWidget *dialog; - NMVpnPluginUiInterface *plugin; - NMSettingVPN *s_vpn = NULL; + NMVpnEditorPlugin *plugin; + NMSettingVpn *s_vpn = NULL; const char *service_type; const char *home_folder; @@ -386,7 +317,7 @@ vpn_export (NMConnection *connection) if (plugin) { char *suggested = NULL; - suggested = nm_vpn_plugin_ui_interface_get_suggested_name (plugin, connection); + suggested = nm_vpn_editor_plugin_get_suggested_filename (plugin, connection); if (suggested) { gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested); g_free (suggested); @@ -402,9 +333,9 @@ vpn_export (NMConnection *connection) gboolean vpn_supports_ipv6 (NMConnection *connection) { - NMSettingVPN *s_vpn; + NMSettingVpn *s_vpn; const char *service_type; - NMVpnPluginUiInterface *plugin; + NMVpnEditorPlugin *plugin; guint32 capabilities; s_vpn = nm_connection_get_setting_vpn (connection); @@ -416,6 +347,6 @@ vpn_supports_ipv6 (NMConnection *connection) plugin = vpn_get_plugin_by_service (service_type); g_return_val_if_fail (plugin != NULL, FALSE); - capabilities = nm_vpn_plugin_ui_interface_get_capabilities (plugin); - return (capabilities & NM_VPN_PLUGIN_UI_CAPABILITY_IPV6) != 0; + capabilities = nm_vpn_editor_plugin_get_capabilities (plugin); + return (capabilities & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6) != 0; } diff --git a/panels/network/connection-editor/vpn-helpers.h b/panels/network/connection-editor/vpn-helpers.h index d1a8c5ed1..6bd102c5d 100644 --- a/panels/network/connection-editor/vpn-helpers.h +++ b/panels/network/connection-editor/vpn-helpers.h @@ -25,14 +25,11 @@ #include <glib.h> #include <gtk/gtk.h> -#include <nm-connection.h> +#include <NetworkManager.h> -#define NM_VPN_API_SUBJECT_TO_CHANGE -#include <nm-vpn-plugin-ui-interface.h> +GSList *vpn_get_plugins (void); -GHashTable *vpn_get_plugins (GError **error); - -NMVpnPluginUiInterface *vpn_get_plugin_by_service (const char *service); +NMVpnEditorPlugin *vpn_get_plugin_by_service (const char *service); typedef void (*VpnImportCallback) (NMConnection *connection, gpointer user_data); void vpn_import (GtkWindow *parent, VpnImportCallback callback, gpointer user_data); diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c index ed3f0a549..f8db331a0 100644 --- a/panels/network/net-device-ethernet.c +++ b/panels/network/net-device-ethernet.c @@ -24,11 +24,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-client.h> -#include <nm-device.h> -#include <nm-device-ethernet.h> -#include <nm-remote-connection.h> -#include <nm-utils.h> +#include <NetworkManager.h> #include "panel-common.h" @@ -134,8 +130,8 @@ out: static void add_details (GtkWidget *details, NMDevice *device, NMConnection *connection) { - NMIP4Config *ip4_config = NULL; - NMIP6Config *ip6_config = NULL; + NMIPConfig *ip4_config = NULL; + NMIPConfig *ip6_config = NULL; gchar *ip4_address = NULL; gchar *ip4_route = NULL; gchar *ip4_dns = NULL; @@ -251,7 +247,6 @@ show_details (GtkButton *button, NetDeviceEthernet *device, const gchar *title) GtkWidget *window; NetConnectionEditor *editor; NMClient *client; - NMRemoteSettings *settings; NMDevice *nmdev; window = gtk_widget_get_toplevel (GTK_WIDGET (button)); @@ -261,8 +256,7 @@ show_details (GtkButton *button, NetDeviceEthernet *device, const gchar *title) nmdev = net_device_get_nm_device (NET_DEVICE (device)); client = net_object_get_client (NET_OBJECT (device)); - settings = net_object_get_remote_settings (NET_OBJECT (device)); - editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings); + editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client); if (title) net_connection_editor_set_title (editor, title); g_signal_connect (editor, "done", G_CALLBACK (editor_done), device); @@ -303,10 +297,10 @@ add_row (NetDeviceEthernet *device, NMConnection *connection) nmdev = net_device_get_nm_device (NET_DEVICE (device)); aconn = nm_device_get_active_connection (nmdev); if (aconn) { - const gchar *path1, *path2; - path1 = nm_active_connection_get_connection (aconn); - path2 = nm_connection_get_path (connection); - active = g_strcmp0 (path1, path2) == 0; + const gchar *uuid1, *uuid2; + uuid1 = nm_active_connection_get_uuid (aconn); + uuid2 = nm_connection_get_uuid (connection); + active = g_strcmp0 (uuid1, uuid2) == 0; } row = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); @@ -366,11 +360,12 @@ add_row (NetDeviceEthernet *device, NMConnection *connection) } static void -connection_removed (NMRemoteConnection *connection, +connection_removed (NMClient *client, + NMRemoteConnection *connection, NetDeviceEthernet *device) { - g_hash_table_remove (device->connections, connection); - device_ethernet_refresh_ui (device); + if (g_hash_table_remove (device->connections, connection)) + device_ethernet_refresh_ui (device); } static void @@ -398,8 +393,6 @@ populate_ui (NetDeviceEthernet *device) NMConnection *connection = l->data; if (!g_hash_table_contains (device->connections, connection)) { g_hash_table_add (device->connections, connection); - g_signal_connect_object (connection, "removed", - G_CALLBACK (connection_removed), device, 0); } } n_connections = g_slist_length (connections); @@ -443,8 +436,9 @@ populate_ui (NetDeviceEthernet *device) } static void -remote_settings_read_cb (NMRemoteSettings *settings, - NetDeviceEthernet *device) +client_connection_added_cb (NMClient *client, + NMRemoteConnection *connection, + NetDeviceEthernet *device) { device_ethernet_refresh_ui (device); } @@ -452,7 +446,6 @@ remote_settings_read_cb (NMRemoteSettings *settings, static void add_profile (GtkButton *button, NetDeviceEthernet *device) { - NMRemoteSettings *settings; NMConnection *connection; NMSettingConnection *sc; gchar *uuid, *id; @@ -460,18 +453,17 @@ add_profile (GtkButton *button, NetDeviceEthernet *device) GtkWidget *window; NMClient *client; NMDevice *nmdev; - GSList *connections; + const GPtrArray *connections; - connection = nm_connection_new (); + connection = nm_simple_connection_new (); sc = NM_SETTING_CONNECTION (nm_setting_connection_new ()); nm_connection_add_setting (connection, NM_SETTING (sc)); uuid = nm_utils_uuid_generate (); - settings = net_object_get_remote_settings (NET_OBJECT (device)); - connections = nm_remote_settings_list_connections (settings); + client = net_object_get_client (NET_OBJECT (device)); + connections = nm_client_get_connections (client); id = ce_page_get_next_available_name (connections, NAME_FORMAT_PROFILE, NULL); - g_slist_free (connections); g_object_set (sc, NM_SETTING_CONNECTION_UUID, uuid, @@ -488,8 +480,7 @@ add_profile (GtkButton *button, NetDeviceEthernet *device) window = gtk_widget_get_toplevel (GTK_WIDGET (button)); nmdev = net_device_get_nm_device (NET_DEVICE (device)); - client = net_object_get_client (NET_OBJECT (device)); - editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings); + editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client); g_signal_connect (editor, "done", G_CALLBACK (editor_done), device); net_connection_editor_run (editor); } @@ -512,10 +503,10 @@ device_off_toggled (GtkSwitch *sw, if (gtk_switch_get_active (sw)) { connection = net_device_get_find_connection (NET_DEVICE (device)); if (connection != NULL) { - nm_client_activate_connection (client, - connection, - nm_device, - NULL, NULL, NULL); + nm_client_activate_connection_async (client, + connection, + nm_device, + NULL, NULL, NULL, NULL); } } else { nm_device_disconnect (nm_device, NULL, NULL); @@ -538,17 +529,17 @@ connection_activated (GtkListBox *list, GtkListBoxRow *row, NetDeviceEthernet *d connection = NM_CONNECTION (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "connection")); - nm_client_activate_connection (client, - connection, - nm_device, - NULL, NULL, NULL); + nm_client_activate_connection_async (client, + connection, + nm_device, + NULL, NULL, NULL, NULL); } static void device_ethernet_constructed (GObject *object) { NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object); - NMRemoteSettings *settings; + NMClient *client; GtkWidget *list; GtkWidget *swin; GtkWidget *widget; @@ -567,19 +558,23 @@ device_ethernet_constructed (GObject *object) G_CALLBACK (connection_activated), device); gtk_widget_show (list); - device->details = GTK_WIDGET (gtk_builder_get_object (NET_DEVICE_ETHERNET (object)->builder, "details")); + device->details = GTK_WIDGET (gtk_builder_get_object (device->builder, "details")); - device->details_button = GTK_WIDGET (gtk_builder_get_object (NET_DEVICE_ETHERNET (object)->builder, "details_button")); + device->details_button = GTK_WIDGET (gtk_builder_get_object (device->builder, "details_button")); g_signal_connect (device->details_button, "clicked", G_CALLBACK (show_details_for_wired), device); - device->add_profile_button = GTK_WIDGET (gtk_builder_get_object (NET_DEVICE_ETHERNET (object)->builder, "add_profile_button")); + device->add_profile_button = GTK_WIDGET (gtk_builder_get_object (device->builder, "add_profile_button")); g_signal_connect (device->add_profile_button, "clicked", G_CALLBACK (add_profile), device); - settings = net_object_get_remote_settings (NET_OBJECT (object)); - g_signal_connect (settings, "connections-read", - G_CALLBACK (remote_settings_read_cb), object); + client = net_object_get_client (NET_OBJECT (object)); + g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED, + G_CALLBACK (client_connection_added_cb), object); + g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED, + G_CALLBACK (connection_removed), device, 0); + + device_ethernet_refresh_ui (device); } static void diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c index 71379f909..408b2dc99 100644 --- a/panels/network/net-device-mobile.c +++ b/panels/network/net-device-mobile.c @@ -25,17 +25,12 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-client.h> -#include <nm-device.h> -#include <nm-device-modem.h> -#include <nm-remote-connection.h> -#include <nm-mobile-providers.h> +#include <NetworkManager.h> +#include <libmm-glib.h> +#include <nma-mobile-providers.h> #include "panel-common.h" #include "network-dialogs.h" - -#include <libmm-glib.h> - #include "net-device-mobile.h" #define NET_DEVICE_MOBILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_DEVICE_MOBILE, NetDeviceMobilePrivate)) @@ -95,16 +90,16 @@ device_mobile_proxy_add_to_notebook (NetObject *object, } static void -connection_activate_cb (NMClient *client, - NMActiveConnection *connection, - GError *error, +connection_activate_cb (GObject *source_object, + GAsyncResult *res, gpointer user_data) { - NetDeviceMobile *device_mobile = NET_DEVICE_MOBILE (user_data); + GError *error = NULL; - if (connection == NULL) { + if (!nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error)) { /* failed to activate */ - nm_device_mobile_refresh_ui (device_mobile); + nm_device_mobile_refresh_ui (user_data); + g_error_free (error); } } @@ -118,7 +113,6 @@ mobile_connection_changed_cb (GtkComboBox *combo_box, NetDeviceMobile *device_mo NMConnection *connection; NMDevice *device; NMClient *client; - NMRemoteSettings *remote_settings; CcNetworkPanel *panel; GtkWidget *toplevel; @@ -133,7 +127,6 @@ mobile_connection_changed_cb (GtkComboBox *combo_box, NetDeviceMobile *device_mo if (device == NULL) goto out; client = net_object_get_client (NET_OBJECT (device_mobile)); - remote_settings = net_object_get_remote_settings (NET_OBJECT (device_mobile)); /* get entry */ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); @@ -145,22 +138,20 @@ mobile_connection_changed_cb (GtkComboBox *combo_box, NetDeviceMobile *device_mo toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel))); cc_network_panel_connect_to_3g_network (toplevel, client, - remote_settings, device); goto out; } /* activate the connection */ g_debug ("try to switch to connection %s", object_path); - connection = (NMConnection*) nm_remote_settings_get_connection_by_path (remote_settings, - object_path); + connection = (NMConnection*) nm_client_get_connection_by_path (client, object_path); if (connection != NULL) { nm_device_disconnect (device, NULL, NULL); - nm_client_activate_connection (client, - connection, - device, NULL, - connection_activate_cb, - device_mobile); + nm_client_activate_connection_async (client, + connection, + device, NULL, NULL, + connection_activate_cb, + device_mobile); goto out; } out: @@ -216,8 +207,8 @@ device_add_device_connections (NetDeviceMobile *device_mobile, /* is this already activated? */ if (active_connection != NULL && - g_strcmp0 (nm_connection_get_path (connection), - nm_active_connection_get_connection (active_connection)) == 0) { + g_strcmp0 (nm_connection_get_uuid (connection), + nm_active_connection_get_uuid (active_connection)) == 0) { priv->updating_device = TRUE; gtk_combo_box_set_active_iter (combobox, &treeiter); priv->updating_device = FALSE; @@ -434,7 +425,6 @@ device_off_toggled (GtkSwitch *sw, GParamSpec *pspec, NetDeviceMobile *device_mobile) { - const gchar *path; const GPtrArray *acs; gboolean active; gint i; @@ -451,21 +441,23 @@ device_off_toggled (GtkSwitch *sw, connection = net_device_get_find_connection (NET_DEVICE (device_mobile)); if (connection == NULL) return; - nm_client_activate_connection (client, - connection, - net_device_get_nm_device (NET_DEVICE (device_mobile)), - NULL, NULL, NULL); + nm_client_activate_connection_async (client, + connection, + net_device_get_nm_device (NET_DEVICE (device_mobile)), + NULL, NULL, NULL, NULL); } else { + const gchar *uuid; + connection = net_device_get_find_connection (NET_DEVICE (device_mobile)); if (connection == NULL) return; - path = nm_connection_get_path (connection); + uuid = nm_connection_get_uuid (connection); client = net_object_get_client (NET_OBJECT (device_mobile)); acs = nm_client_get_active_connections (client); for (i = 0; acs && i < acs->len; i++) { a = (NMActiveConnection*)acs->pdata[i]; - if (strcmp (nm_active_connection_get_connection (a), path) == 0) { - nm_client_deactivate_connection (client, a); + if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) { + nm_client_deactivate_connection (client, a, NULL, NULL); break; } } diff --git a/panels/network/net-device-mobile.h b/panels/network/net-device-mobile.h index 9b24fdb2f..4dd2bd8d4 100644 --- a/panels/network/net-device-mobile.h +++ b/panels/network/net-device-mobile.h @@ -23,9 +23,9 @@ #define __NET_DEVICE_MOBILE_H #include <glib-object.h> +#include <NetworkManager.h> #include "net-device.h" -#include "nm-connection.h" G_BEGIN_DECLS diff --git a/panels/network/net-device-simple.c b/panels/network/net-device-simple.c index f57618dee..3a3c2c92f 100644 --- a/panels/network/net-device-simple.c +++ b/panels/network/net-device-simple.c @@ -25,9 +25,7 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <nm-client.h> -#include <nm-device.h> -#include <nm-remote-connection.h> +#include <NetworkManager.h> #include "panel-common.h" @@ -143,7 +141,6 @@ device_off_toggled (GtkSwitch *sw, GParamSpec *pspec, NetDeviceSimple *device_simple) { - const gchar *path; const GPtrArray *acs; gboolean active; gint i; @@ -160,21 +157,23 @@ device_off_toggled (GtkSwitch *sw, connection = net_device_get_find_connection (NET_DEVICE (device_simple)); if (connection == NULL) return; - nm_client_activate_connection (client, - connection, - net_device_get_nm_device (NET_DEVICE (device_simple)), - NULL, NULL, NULL); + nm_client_activate_connection_async (client, + connection, + net_device_get_nm_device (NET_DEVICE (device_simple)), + NULL, NULL, NULL, NULL); } else { + const gchar *uuid; + connection = net_device_get_find_connection (NET_DEVICE (device_simple)); if (connection == NULL) return; - path = nm_connection_get_path (connection); + uuid = nm_connection_get_uuid (connection); client = net_object_get_client (NET_OBJECT (device_simple)); acs = nm_client_get_active_connections (client); for (i = 0; acs && i < acs->len; i++) { a = (NMActiveConnection*)acs->pdata[i]; - if (strcmp (nm_active_connection_get_connection (a), path) == 0) { - nm_client_deactivate_connection (client, a); + if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) { + nm_client_deactivate_connection (client, a, NULL, NULL); break; } } diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c index ca55d9441..390043aaa 100644 --- a/panels/network/net-device-wifi.c +++ b/panels/network/net-device-wifi.c @@ -26,14 +26,7 @@ #include <netinet/ether.h> -#include <nm-client.h> -#include <nm-utils.h> -#include <nm-device.h> -#include <nm-device-wifi.h> -#include <nm-device-ethernet.h> -#include <nm-setting-wireless-security.h> -#include <nm-remote-connection.h> -#include <nm-setting-wireless.h> +#include <NetworkManager.h> #include <polkit/polkit.h> #include "shell/list-box-helper.h" @@ -139,8 +132,7 @@ get_access_point_security (NMAccessPoint *ap) static GPtrArray * panel_get_strongest_unique_aps (const GPtrArray *aps) { - const GByteArray *ssid; - const GByteArray *ssid_tmp; + GBytes *ssid, *ssid_tmp; GPtrArray *aps_unique = NULL; gboolean add_ap; guint i; @@ -169,18 +161,20 @@ panel_get_strongest_unique_aps (const GPtrArray *aps) g_assert (ssid_tmp); /* is this the same type and data? */ - if (nm_utils_same_ssid (ssid, ssid_tmp, TRUE)) { + if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), + g_bytes_get_data (ssid_tmp, NULL), g_bytes_get_size (ssid_tmp), + TRUE)) { g_debug ("found duplicate: %s", - nm_utils_escape_ssid (ssid_tmp->data, - ssid_tmp->len)); + nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL), + g_bytes_get_size (ssid_tmp))); /* the new access point is stronger */ if (nm_access_point_get_strength (ap) > nm_access_point_get_strength (ap_tmp)) { g_debug ("removing %s", - nm_utils_escape_ssid (ssid_tmp->data, - ssid_tmp->len)); + nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL), + g_bytes_get_size (ssid_tmp))); g_ptr_array_remove (aps_unique, ap_tmp); add_ap = TRUE; } else { @@ -192,8 +186,8 @@ panel_get_strongest_unique_aps (const GPtrArray *aps) } if (add_ap) { g_debug ("adding %s", - nm_utils_escape_ssid (ssid->data, - ssid->len)); + nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL), + g_bytes_get_size (ssid))); g_ptr_array_add (aps_unique, g_object_ref (ap)); } } @@ -279,14 +273,11 @@ find_connection_for_device (NetDeviceWifi *device_wifi, { NetDevice *tmp; NMConnection *connection; - NMRemoteSettings *remote_settings; NMClient *client; client = net_object_get_client (NET_OBJECT (device_wifi)); - remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi)); tmp = g_object_new (NET_TYPE_DEVICE, "client", client, - "remote-settings", remote_settings, "nm-device", device, NULL); connection = net_device_get_find_connection (tmp); @@ -297,10 +288,10 @@ find_connection_for_device (NetDeviceWifi *device_wifi, static gboolean connection_is_shared (NMConnection *c) { - NMSettingIP4Config *s_ip4; + NMSettingIPConfig *s_ip4; s_ip4 = nm_connection_get_setting_ip4_config (c); - if (g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4), + if (g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_SHARED) != 0) { return FALSE; } @@ -325,7 +316,7 @@ device_is_hotspot (NetDeviceWifi *device_wifi) return connection_is_shared (c); } -static const GByteArray * +static GBytes * device_get_hotspot_ssid (NetDeviceWifi *device_wifi, NMDevice *device) { @@ -342,18 +333,23 @@ device_get_hotspot_ssid (NetDeviceWifi *device_wifi, } static void -get_secrets_cb (NMRemoteConnection *c, - GHashTable *secrets, - GError *error, +get_secrets_cb (GObject *source_object, + GAsyncResult *res, gpointer data) { NetDeviceWifi *device_wifi = data; - NMSettingWireless *sw; + GVariant *secrets; + GError *error = NULL; - sw = nm_connection_get_setting_wireless (NM_CONNECTION (c)); + secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (source_object), res, &error); + if (!secrets) { + g_error_free (error); + //FIXME ignore cancelled + return; + } - nm_connection_update_secrets (NM_CONNECTION (c), - nm_setting_wireless_get_security (sw), + nm_connection_update_secrets (NM_CONNECTION (source_object), + NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, secrets, NULL); nm_device_wifi_refresh_ui (device_wifi); @@ -366,7 +362,6 @@ device_get_hotspot_security_details (NetDeviceWifi *device_wifi, gchar **security) { NMConnection *c; - NMSettingWireless *sw; NMSettingWirelessSecurity *sws; const gchar *key_mgmt; const gchar *tmp_secret; @@ -376,9 +371,8 @@ device_get_hotspot_security_details (NetDeviceWifi *device_wifi, if (c == NULL) return; - sw = nm_connection_get_setting_wireless (c); sws = nm_connection_get_setting_wireless_security (c); - if (sw == NULL || sws == NULL) + if (sws == NULL) return; tmp_secret = NULL; @@ -406,10 +400,11 @@ device_get_hotspot_security_details (NetDeviceWifi *device_wifi, * We'll refresh the UI when secrets arrive. */ if (tmp_secret == NULL) { - nm_remote_connection_get_secrets ((NMRemoteConnection*)c, - nm_setting_wireless_get_security (sw), - get_secrets_cb, - device_wifi); + nm_remote_connection_get_secrets_async ((NMRemoteConnection*)c, + NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, + NULL, + get_secrets_cb, + device_wifi); return; } @@ -422,7 +417,7 @@ device_get_hotspot_security_details (NetDeviceWifi *device_wifi, static void nm_device_wifi_refresh_hotspot (NetDeviceWifi *device_wifi) { - const GByteArray *ssid; + GBytes *ssid; gchar *hotspot_secret = NULL; gchar *hotspot_security = NULL; gchar *hotspot_ssid = NULL; @@ -432,7 +427,7 @@ nm_device_wifi_refresh_hotspot (NetDeviceWifi *device_wifi) nm_device = net_device_get_nm_device (NET_DEVICE (device_wifi)); ssid = device_get_hotspot_ssid (device_wifi, nm_device); if (ssid) - hotspot_ssid = nm_utils_ssid_to_utf8 (ssid); + hotspot_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); device_get_hotspot_security_details (device_wifi, nm_device, &hotspot_secret, @@ -635,49 +630,54 @@ device_off_toggled (GtkSwitch *sw, static void connect_to_hidden_network (NetDeviceWifi *device_wifi) { - NMRemoteSettings *remote_settings; NMClient *client; CcNetworkPanel *panel; GtkWidget *toplevel; - remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi)); client = net_object_get_client (NET_OBJECT (device_wifi)); panel = net_object_get_panel (NET_OBJECT (device_wifi)); toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel))); - cc_network_panel_connect_to_hidden_network (toplevel, client, remote_settings); + cc_network_panel_connect_to_hidden_network (toplevel, client); } static void -connection_add_or_activate_cb (NMActiveConnection *connection, - GError *error, - NetDeviceWifi *device_wifi) +connection_add_activate_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - if (connection == NULL) { + NMActiveConnection *conn; + GError *error = NULL; + + conn = nm_client_add_and_activate_connection_finish (NM_CLIENT (source_object), res, &error); + if (!conn) { + //FIXME cancelled + nm_device_wifi_refresh_ui (user_data); /* failed to activate */ - g_debug ("Failed to add and/or activate connection '%d': %s", + g_debug ("Failed to add and activate connection '%d': %s", error->code, error->message); - nm_device_wifi_refresh_ui (device_wifi); + g_error_free (error); + return; } } static void -connection_add_activate_cb (NMClient *client, - NMActiveConnection *connection, - const char *path, - GError *error, - gpointer user_data) -{ - connection_add_or_activate_cb (connection, error, user_data); -} - -static void -connection_activate_cb (NMClient *client, - NMActiveConnection *connection, - GError *error, +connection_activate_cb (GObject *source_object, + GAsyncResult *res, gpointer user_data) { - connection_add_or_activate_cb (connection, error, user_data); + GError *error = NULL; + + if (!nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error)) { + //FIXME cancelled + nm_device_wifi_refresh_ui (user_data); + /* failed to activate */ + g_debug ("Failed to add and activate connection '%d': %s", + error->code, + error->message); + g_error_free (error); + return; + } } static gboolean @@ -707,7 +707,7 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi, const gchar *ssid_target, const gchar *ap_object_path) { - const GByteArray *ssid; + GBytes *ssid; const gchar *ssid_tmp; GSList *list, *l; NMConnection *connection_activate = NULL; @@ -741,7 +741,7 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi, ssid = nm_setting_wireless_get_ssid (setting_wireless); if (ssid == NULL) continue; - ssid_tmp = nm_utils_escape_ssid (ssid->data, ssid->len); + ssid_tmp = nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); if (g_strcmp0 (ssid_target, ssid_tmp) == 0) { g_debug ("we found an existing connection %s to activate!", nm_connection_get_id (connection)); @@ -755,10 +755,13 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi, /* activate the connection */ client = net_object_get_client (NET_OBJECT (device_wifi)); if (connection_activate != NULL) { - nm_client_activate_connection (client, - connection_activate, - device, NULL, - connection_activate_cb, device_wifi); + nm_client_activate_connection_async (client, + connection_activate, + device, + NULL, + NULL, + connection_activate_cb, + device_wifi); goto out; } @@ -782,14 +785,18 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi, s_con = (NMSettingConnection *)nm_setting_connection_new (); nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL); - partial = nm_connection_new (); + partial = nm_simple_connection_new (); nm_connection_add_setting (partial, NM_SETTING (s_con)); } g_debug ("no existing connection found for %s, creating and activating one", ssid_target); - nm_client_add_and_activate_connection (client, partial, - device, ap_object_path, - connection_add_activate_cb, device_wifi); + nm_client_add_and_activate_connection_async (client, + partial, + device, + ap_object_path, + NULL, + connection_add_activate_cb, + device_wifi); if (!allowed_to_share) g_object_unref (partial); } else { @@ -947,7 +954,8 @@ is_hotspot_connection (NMConnection *connection) { NMSettingConnection *sc; NMSettingWireless *sw; - NMSettingIP4Config *sip; + NMSettingIPConfig *sip; + NMSetting *setting; sc = nm_connection_get_setting_connection (connection); if (g_strcmp0 (nm_setting_connection_get_connection_type (sc), "802-11-wireless") != 0) { @@ -958,11 +966,12 @@ is_hotspot_connection (NMConnection *connection) g_strcmp0 (nm_setting_wireless_get_mode (sw), "ap") != 0) { return FALSE; } - if (g_strcmp0 (nm_setting_wireless_get_security (sw), "802-11-wireless-security") != 0) { + setting = nm_connection_get_setting_by_name (connection, NM_SETTING_WIRELESS_SETTING_NAME); + if (!setting) return FALSE; - } + sip = nm_connection_get_setting_ip4_config (connection); - if (g_strcmp0 (nm_setting_ip4_config_get_method (sip), "shared") != 0) { + if (g_strcmp0 (nm_setting_ip_config_get_method (sip), "shared") != 0) { return FALSE; } @@ -985,31 +994,46 @@ show_hotspot_ui (NetDeviceWifi *device_wifi) } static void -activate_cb (NMClient *client, - NMActiveConnection *connection, - GError *error, - NetDeviceWifi *device_wifi) +activate_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - if (error != NULL) { + GError *error = NULL; + + if (nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error) == NULL) { g_warning ("Failed to add new connection: (%d) %s", error->code, error->message); + g_error_free (error); return; } /* show hotspot tab */ - nm_device_wifi_refresh_ui (device_wifi); - show_hotspot_ui (device_wifi); + nm_device_wifi_refresh_ui (user_data); + show_hotspot_ui (user_data); } static void -activate_new_cb (NMClient *client, - NMActiveConnection *connection, - const gchar *path, - GError *error, - NetDeviceWifi *device_wifi) +activate_new_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - activate_cb (client, connection, error, device_wifi); + NMActiveConnection *conn; + GError *error = NULL; + + conn = nm_client_add_and_activate_connection_finish (NM_CLIENT (source_object), + res, &error); + if (!conn) { + g_warning ("Failed to add new connection: (%d) %s", + error->code, + error->message); + g_error_free (error); + return; + } + + /* show hotspot tab */ + nm_device_wifi_refresh_ui (user_data); + show_hotspot_ui (user_data); } static void @@ -1048,17 +1072,18 @@ start_shared_connection (NetDeviceWifi *device_wifi) client = net_object_get_client (NET_OBJECT (device_wifi)); if (c != NULL) { g_debug ("activate existing hotspot connection\n"); - nm_client_activate_connection (client, - c, - device, - NULL, - (NMClientActivateFn)activate_cb, - device_wifi); + nm_client_activate_connection_async (client, + c, + device, + NULL, + NULL, + activate_cb, + device_wifi); return; } g_debug ("create new hotspot connection\n"); - c = nm_connection_new (); + c = nm_simple_connection_new (); sc = (NMSettingConnection *)nm_setting_connection_new (); g_object_set (sc, @@ -1128,12 +1153,13 @@ start_shared_connection (NetDeviceWifi *device_wifi) nm_connection_add_setting (c, (NMSetting *)sws); - nm_client_add_and_activate_connection (client, - c, - device, - NULL, - (NMClientAddActivateFn)activate_new_cb, - device_wifi); + nm_client_add_and_activate_connection_async (client, + c, + device, + NULL, + NULL, + activate_new_cb, + device_wifi); g_object_unref (c); } @@ -1173,8 +1199,10 @@ start_hotspot (GtkButton *button, NetDeviceWifi *device_wifi) devices = nm_active_connection_get_devices (c); if (devices && devices->pdata[0] == device) { NMAccessPoint *ap; + GBytes *ssid; ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)); - active_ssid = nm_utils_ssid_to_utf8 (nm_access_point_get_ssid (ap)); + ssid = nm_access_point_get_ssid (ap); + active_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); break; } } @@ -1227,7 +1255,7 @@ stop_shared_connection (NetDeviceWifi *device_wifi) devices = nm_active_connection_get_devices (c); if (devices && devices->pdata[0] == device) { - nm_client_deactivate_connection (client, c); + nm_client_deactivate_connection (client, c, NULL, NULL); found = TRUE; break; } @@ -1295,8 +1323,9 @@ show_wifi_list (NetDeviceWifi *device_wifi) } static void -remote_settings_read_cb (NMRemoteSettings *remote_settings, - NetDeviceWifi *device_wifi) +client_connection_added_cb (NMClient *client, + NMRemoteConnection *connection, + NetDeviceWifi *device_wifi) { gboolean is_hotspot; @@ -1315,7 +1344,6 @@ net_device_wifi_constructed (GObject *object) { NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (object); NMClient *client; - NMRemoteSettings *remote_settings; NMClientPermissionResult perm; NMDevice *nm_device; NMDeviceWifiCapabilities caps; @@ -1351,9 +1379,8 @@ net_device_wifi_constructed (GObject *object) } else gtk_widget_set_sensitive (widget, TRUE); - remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi)); - g_signal_connect (remote_settings, "connections-read", - G_CALLBACK (remote_settings_read_cb), device_wifi); + g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED, + G_CALLBACK (client_connection_added_cb), device_wifi); widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder, "heading_list")); g_object_bind_property (device_wifi, "title", widget, "label", 0); @@ -1384,11 +1411,11 @@ device_wifi_edit (NetObject *object) gchar *cmdline; GError *error = NULL; NetDeviceWifi *device = NET_DEVICE_WIFI (object); - NMRemoteSettings *settings; + NMClient *client; NMRemoteConnection *connection; - settings = net_object_get_remote_settings (object); - connection = nm_remote_settings_get_connection_by_path (settings, device->priv->selected_connection_id); + client = net_object_get_client (object); + connection = nm_client_get_connection_by_path (client, device->priv->selected_connection_id); if (connection == NULL) { g_warning ("failed to get remote connection"); return; @@ -1419,21 +1446,22 @@ net_device_wifi_class_init (NetDeviceWifiClass *klass) } static void -really_forgotten (NMRemoteConnection *connection, - GError *error, +really_forgotten (GObject *source_object, + GAsyncResult *res, gpointer user_data) { - NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (user_data); + GError *error = NULL; - if (error != NULL) { + if (!nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (source_object), res, &error)) { g_warning ("failed to delete connection %s: %s", - nm_object_get_path (NM_OBJECT (connection)), + nm_object_get_path (NM_OBJECT (source_object)), error->message); + g_error_free (error); return; } /* remove the entry from the list */ - populate_ap_list (device_wifi); + populate_ap_list (user_data); } static void @@ -1456,7 +1484,8 @@ really_forget (GtkDialog *dialog, gint response, gpointer data) for (r = rows; r; r = r->next) { row = r->data; connection = g_object_get_data (G_OBJECT (row), "connection"); - nm_remote_connection_delete (connection, really_forgotten, device_wifi); + //FIXME cancellable + nm_remote_connection_delete_async (connection, NULL, really_forgotten, device_wifi); gtk_widget_destroy (row); } g_list_free (rows); @@ -1542,7 +1571,7 @@ make_row (GtkSizeGroup *rows, gboolean connecting; guint security; guint strength; - const GByteArray *ssid; + GBytes *ssid; const gchar *icon_name; guint64 timestamp; NMDeviceState state; @@ -1563,7 +1592,7 @@ make_row (GtkSizeGroup *rows, timestamp = 0; } - title = nm_utils_escape_ssid (ssid->data, ssid->len); + title = nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); if (ap != NULL) { in_range = TRUE; @@ -1748,7 +1777,6 @@ show_details_for_row (GtkButton *button, NetDeviceWifi *device_wifi) GtkWidget *window; NetConnectionEditor *editor; NMClient *client; - NMRemoteSettings *settings; NMDevice *device; window = gtk_widget_get_toplevel (GTK_WIDGET (button)); @@ -1759,8 +1787,7 @@ show_details_for_row (GtkButton *button, NetDeviceWifi *device_wifi) device = net_device_get_nm_device (NET_DEVICE (device_wifi)); client = net_object_get_client (NET_OBJECT (device_wifi)); - settings = net_object_get_remote_settings (NET_OBJECT (device_wifi)); - editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, client, settings); + editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, client); g_signal_connect (editor, "done", G_CALLBACK (editor_done), device_wifi); net_connection_editor_run (editor); } @@ -1845,17 +1872,19 @@ open_history (NetDeviceWifi *device_wifi) NMConnection *connection = l->data; NMAccessPoint *ap = NULL; NMSetting *setting; - const GByteArray *ssid; + GBytes *ssid; if (connection_is_shared (connection)) continue; setting = nm_connection_get_setting_by_name (connection, NM_SETTING_WIRELESS_SETTING_NAME); ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (setting)); for (i = 0; i < aps_unique->len; i++) { - const GByteArray *ssid_ap; + GBytes *ssid_ap; ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i)); ssid_ap = nm_access_point_get_ssid (ap); - if (nm_utils_same_ssid (ssid, ssid_ap, TRUE)) + if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), + g_bytes_get_data (ssid_ap, NULL), g_bytes_get_size (ssid_ap), + TRUE)) break; ap = NULL; } @@ -1914,7 +1943,7 @@ populate_ap_list (NetDeviceWifi *device_wifi) active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device)); for (i = 0; i < aps_unique->len; i++) { - const GByteArray *ssid_ap; + GBytes *ssid_ap; NMAccessPoint *ap; NMConnection *connection = NULL; ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i)); @@ -1922,7 +1951,7 @@ populate_ap_list (NetDeviceWifi *device_wifi) for (l = connections; l; l = l->next) { connection = l->data; NMSetting *setting; - const GByteArray *ssid; + GBytes *ssid; if (connection_is_shared (connection)) { connection = NULL; @@ -1931,7 +1960,9 @@ populate_ap_list (NetDeviceWifi *device_wifi) setting = nm_connection_get_setting_by_name (connection, NM_SETTING_WIRELESS_SETTING_NAME); ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (setting)); - if (nm_utils_same_ssid (ssid, ssid_ap, TRUE)) + if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid), + g_bytes_get_data (ssid_ap, NULL), g_bytes_get_size (ssid_ap), + TRUE)) break; connection = NULL; } @@ -1970,19 +2001,19 @@ ap_activated (GtkListBox *list, GtkListBoxRow *row, NetDeviceWifi *device_wifi) gtk_widget_hide (edit); client = net_object_get_client (NET_OBJECT (device_wifi)); nm_device = net_device_get_nm_device (NET_DEVICE (device_wifi)); - nm_client_activate_connection (client, - connection, - nm_device, NULL, - connection_activate_cb, device_wifi); + nm_client_activate_connection_async (client, + connection, + nm_device, NULL, NULL, + connection_activate_cb, device_wifi); } else { - const GByteArray *ssid; + GBytes *ssid; gchar *ssid_text; const gchar *object_path; gtk_stack_set_visible_child_name (GTK_STACK (stack), "spinner"); ssid = nm_access_point_get_ssid (ap); - ssid_text = g_markup_escape_text (nm_utils_escape_ssid (ssid->data, ssid->len), -1); + ssid_text = g_markup_escape_text (nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)), -1); object_path = nm_object_get_path (NM_OBJECT (ap)); wireless_try_to_connect (device_wifi, ssid_text, object_path); g_free (ssid_text); diff --git a/panels/network/net-device.c b/panels/network/net-device.c index d96551ab8..b98e6860b 100644 --- a/panels/network/net-device.c +++ b/panels/network/net-device.c @@ -26,12 +26,7 @@ #include <arpa/inet.h> #include <netinet/ether.h> -#include <nm-device-ethernet.h> -#include <nm-device-modem.h> -#include <nm-device-wifi.h> -#include <nm-device-wimax.h> -#include <nm-device-infiniband.h> -#include <nm-utils.h> +#include <NetworkManager.h> #include "net-device.h" @@ -58,8 +53,6 @@ get_mac_address_of_connection (NMConnection *connection) if (!connection) return NULL; - const GByteArray *mac = NULL; - /* check the connection type */ if (nm_connection_is_type (connection, NM_SETTING_WIRELESS_SETTING_NAME)) { @@ -67,38 +60,14 @@ get_mac_address_of_connection (NMConnection *connection) NMSettingWireless *s_wireless = nm_connection_get_setting_wireless (connection); if (!s_wireless) return NULL; - mac = nm_setting_wireless_get_mac_address (s_wireless); - if (mac) - return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); + return g_strdup (nm_setting_wireless_get_mac_address (s_wireless)); } else if (nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) { /* check wired settings */ NMSettingWired *s_wired = nm_connection_get_setting_wired (connection); if (!s_wired) return NULL; - mac = nm_setting_wired_get_mac_address (s_wired); - if (mac) - return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - } else if (nm_connection_is_type (connection, - NM_SETTING_WIMAX_SETTING_NAME)) { - /* check wimax settings */ - NMSettingWimax *s_wimax = nm_connection_get_setting_wimax (connection); - if (!s_wimax) - return NULL; - mac = nm_setting_wimax_get_mac_address (s_wimax); - if (mac) - return nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); - } else if (nm_connection_is_type (connection, - NM_SETTING_INFINIBAND_SETTING_NAME)) { - /* check infiniband settings */ - NMSettingInfiniband *s_infiniband = \ - nm_connection_get_setting_infiniband (connection); - if (!s_infiniband) - return NULL; - mac = nm_setting_infiniband_get_mac_address (s_infiniband); - if (mac) - return nm_utils_hwaddr_ntoa (mac->data, - ARPHRD_INFINIBAND); + return g_strdup (nm_setting_wired_get_mac_address (s_wired)); } /* no MAC address found */ return NULL; @@ -122,19 +91,6 @@ get_mac_address_of_device (NMDevice *device) mac = nm_device_ethernet_get_hw_address (device_ethernet); break; } - case NM_DEVICE_TYPE_WIMAX: - { - NMDeviceWimax *device_wimax = NM_DEVICE_WIMAX (device); - mac = nm_device_wimax_get_hw_address (device_wimax); - break; - } - case NM_DEVICE_TYPE_INFINIBAND: - { - NMDeviceInfiniband *device_infiniband = \ - NM_DEVICE_INFINIBAND (device); - mac = nm_device_infiniband_get_hw_address (device_infiniband); - break; - } default: break; } @@ -171,15 +127,11 @@ net_device_real_get_find_connection (NetDevice *device) GSList *list, *iterator; NMConnection *connection = NULL; NMActiveConnection *ac; - NMRemoteSettings *remote_settings; /* is the device available in a active connection? */ - remote_settings = net_object_get_remote_settings (NET_OBJECT (device)); ac = nm_device_get_active_connection (device->priv->nm_device); - if (ac) { - return (NMConnection*)nm_remote_settings_get_connection_by_path (remote_settings, - nm_active_connection_get_connection (ac)); - } + if (ac) + return (NMConnection*) nm_active_connection_get_connection (ac); /* not found in active connections - check all available connections */ list = net_device_get_valid_connections (device); @@ -362,22 +314,24 @@ net_device_new (void) GSList * net_device_get_valid_connections (NetDevice *device) { - GSList *all, *filtered, *iterator, *valid; + GSList *valid; NMConnection *connection; NMSettingConnection *s_con; NMActiveConnection *active_connection; const char *active_uuid; + const GPtrArray *all; + GPtrArray *filtered; + guint i; - all = nm_remote_settings_list_connections (net_object_get_remote_settings (NET_OBJECT (device))); + all = nm_client_get_connections (net_object_get_client (NET_OBJECT (device))); filtered = nm_device_filter_connections (net_device_get_nm_device (device), all); - g_slist_free (all); active_connection = nm_device_get_active_connection (net_device_get_nm_device (device)); active_uuid = active_connection ? nm_active_connection_get_uuid (active_connection) : NULL; valid = NULL; - for (iterator = filtered; iterator; iterator = iterator->next) { - connection = iterator->data; + for (i = 0; i < filtered->len; i++) { + connection = g_ptr_array_index (filtered, i); s_con = nm_connection_get_setting_connection (connection); if (!s_con) continue; @@ -388,7 +342,7 @@ net_device_get_valid_connections (NetDevice *device) valid = g_slist_prepend (valid, connection); } - g_slist_free (filtered); + g_ptr_array_free (filtered, FALSE); return g_slist_reverse (valid); } diff --git a/panels/network/net-device.h b/panels/network/net-device.h index 03fde5eb0..136459555 100644 --- a/panels/network/net-device.h +++ b/panels/network/net-device.h @@ -24,8 +24,8 @@ #include <glib-object.h> +#include <NetworkManager.h> #include "net-object.h" -#include "nm-device.h" G_BEGIN_DECLS diff --git a/panels/network/net-object.c b/panels/network/net-object.c index 6e59d9721..ef9452377 100644 --- a/panels/network/net-object.c +++ b/panels/network/net-object.c @@ -35,7 +35,6 @@ struct _NetObjectPrivate gboolean removable; GCancellable *cancellable; NMClient *client; - NMRemoteSettings *remote_settings; CcNetworkPanel *panel; }; @@ -45,7 +44,6 @@ enum { PROP_TITLE, PROP_REMOVABLE, PROP_CLIENT, - PROP_REMOTE_SETTINGS, PROP_CANCELLABLE, PROP_PANEL, PROP_LAST @@ -122,13 +120,6 @@ net_object_get_client (NetObject *object) return object->priv->client; } -NMRemoteSettings * -net_object_get_remote_settings (NetObject *object) -{ - g_return_val_if_fail (NET_IS_OBJECT (object), NULL); - return object->priv->remote_settings; -} - GCancellable * net_object_get_cancellable (NetObject *object) { @@ -213,9 +204,6 @@ net_object_get_property (GObject *object_, case PROP_CLIENT: g_value_set_pointer (value, priv->client); break; - case PROP_REMOTE_SETTINGS: - g_value_set_pointer (value, priv->remote_settings); - break; case PROP_CANCELLABLE: g_value_set_object (value, priv->cancellable); break; @@ -257,11 +245,6 @@ net_object_set_property (GObject *object_, if (priv->client) g_object_add_weak_pointer (G_OBJECT (priv->client), (gpointer *) (&priv->client)); break; - case PROP_REMOTE_SETTINGS: - priv->remote_settings = g_value_get_pointer (value); - if (priv->remote_settings) - g_object_add_weak_pointer (G_OBJECT (priv->remote_settings), (gpointer *) (&priv->remote_settings)); - break; case PROP_CANCELLABLE: g_assert (!priv->cancellable); priv->cancellable = g_value_dup_object (value); @@ -291,8 +274,6 @@ net_object_finalize (GObject *object) if (priv->client) g_object_remove_weak_pointer (G_OBJECT (priv->client), (gpointer *) (&priv->client)); - if (priv->remote_settings) - g_object_remove_weak_pointer (G_OBJECT (priv->remote_settings), (gpointer *) (&priv->remote_settings)); if (priv->panel) g_object_remove_weak_pointer (G_OBJECT (priv->panel), (gpointer *) (&priv->panel)); @@ -327,10 +308,6 @@ net_object_class_init (NetObjectClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT); g_object_class_install_property (object_class, PROP_CLIENT, pspec); - pspec = g_param_spec_pointer ("remote-settings", NULL, NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT); - g_object_class_install_property (object_class, PROP_REMOTE_SETTINGS, pspec); - pspec = g_param_spec_object ("cancellable", NULL, NULL, G_TYPE_CANCELLABLE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT); diff --git a/panels/network/net-object.h b/panels/network/net-object.h index fb3bb6b87..e372f78f8 100644 --- a/panels/network/net-object.h +++ b/panels/network/net-object.h @@ -24,8 +24,7 @@ #include <glib-object.h> #include <gtk/gtk.h> -#include <nm-client.h> -#include <nm-remote-settings.h> +#include <NetworkManager.h> #include "cc-network-panel.h" @@ -73,7 +72,6 @@ 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); -NMRemoteSettings *net_object_get_remote_settings (NetObject *object); GCancellable *net_object_get_cancellable (NetObject *object); CcNetworkPanel *net_object_get_panel (NetObject *object); void net_object_emit_changed (NetObject *object); diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c index 94c1c1017..1fd7c9316 100644 --- a/panels/network/net-vpn.c +++ b/panels/network/net-vpn.c @@ -23,13 +23,11 @@ #include <glib-object.h> #include <glib/gi18n.h> +#include <NetworkManager.h> #include "panel-common.h" #include "net-vpn.h" -#include "nm-client.h" -#include "nm-remote-connection.h" -#include "nm-setting-vpn.h" #include "connection-editor/net-connection-editor.h" @@ -54,9 +52,9 @@ enum { G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT) static void -connection_vpn_state_changed_cb (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason, +connection_vpn_state_changed_cb (NMVpnConnection *connection, + NMVpnConnectionState state, + NMVpnConnectionStateReason reason, NetVpn *vpn) { net_object_emit_changed (NET_OBJECT (vpn)); @@ -73,7 +71,10 @@ static void connection_removed_cb (NMConnection *connection, NetVpn *vpn) { - net_object_emit_removed (NET_OBJECT (vpn)); + NetVpnPrivate *priv = vpn->priv; + + if (priv->connection == connection) + net_object_emit_removed (NET_OBJECT (vpn)); } static char * @@ -91,6 +92,8 @@ static void net_vpn_set_connection (NetVpn *vpn, NMConnection *connection) { NetVpnPrivate *priv = vpn->priv; + NMClient *client; + /* * vpnc config exmaple: * key=IKE DH Group, value=dh2 @@ -102,14 +105,17 @@ net_vpn_set_connection (NetVpn *vpn, NMConnection *connection) * key=Xauth username, value=rhughes */ priv->connection = g_object_ref (connection); - g_signal_connect (priv->connection, - NM_REMOTE_CONNECTION_REMOVED, + + client = net_object_get_client (NET_OBJECT (vpn)); + g_signal_connect (client, + NM_CLIENT_CONNECTION_REMOVED, G_CALLBACK (connection_removed_cb), vpn); - g_signal_connect (priv->connection, - NM_REMOTE_CONNECTION_UPDATED, + g_signal_connect (connection, + NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), vpn); + if (NM_IS_VPN_CONNECTION (priv->connection)) { g_signal_connect (priv->connection, NM_VPN_CONNECTION_VPN_STATE, @@ -120,7 +126,7 @@ net_vpn_set_connection (NetVpn *vpn, NMConnection *connection) priv->service_type = net_vpn_connection_to_type (priv->connection); } -static NMVPNConnectionState +static NMVpnConnectionState net_vpn_get_state (NetVpn *vpn) { NetVpnPrivate *priv = vpn->priv; @@ -225,8 +231,8 @@ static void vpn_proxy_delete (NetObject *object) { NetVpn *vpn = NET_VPN (object); - nm_remote_connection_delete (NM_REMOTE_CONNECTION (vpn->priv->connection), - NULL, vpn); + nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (vpn->priv->connection), + NULL, NULL, vpn); } static GtkWidget * @@ -258,9 +264,7 @@ nm_device_refresh_vpn_ui (NetVpn *vpn) const GPtrArray *acs; NMActiveConnection *a; gint i; - const gchar *path; - const gchar *apath; - NMVPNConnectionState state; + NMVpnConnectionState state; gchar *title; NMClient *client; @@ -293,12 +297,16 @@ nm_device_refresh_vpn_ui (NetVpn *vpn) client = net_object_get_client (NET_OBJECT (vpn)); acs = nm_client_get_active_connections (client); if (acs != NULL) { - path = nm_connection_get_path (vpn->priv->connection); + const gchar *uuid; + + uuid = nm_connection_get_uuid (vpn->priv->connection); for (i = 0; i < acs->len; i++) { + const gchar *auuid; + a = (NMActiveConnection*)acs->pdata[i]; - apath = nm_active_connection_get_connection (a); - if (NM_IS_VPN_CONNECTION (a) && strcmp (apath, path) == 0) { + auuid = nm_active_connection_get_uuid (a); + if (NM_IS_VPN_CONNECTION (a) && strcmp (auuid, uuid) == 0) { priv->active_connection = g_object_ref (a); g_signal_connect_swapped (a, "notify::vpn-state", G_CALLBACK (nm_device_refresh_vpn_ui), @@ -363,7 +371,6 @@ device_off_toggled (GtkSwitch *sw, GParamSpec *pspec, NetVpn *vpn) { - const gchar *path; const GPtrArray *acs; gboolean active; gint i; @@ -376,17 +383,19 @@ device_off_toggled (GtkSwitch *sw, active = gtk_switch_get_active (sw); if (active) { client = net_object_get_client (NET_OBJECT (vpn)); - nm_client_activate_connection (client, - vpn->priv->connection, NULL, NULL, - NULL, NULL); + nm_client_activate_connection_async (client, + vpn->priv->connection, NULL, NULL, + NULL, NULL, NULL); } else { - path = nm_connection_get_path (vpn->priv->connection); + const gchar *uuid; + + uuid = nm_connection_get_uuid (vpn->priv->connection); client = net_object_get_client (NET_OBJECT (vpn)); acs = nm_client_get_active_connections (client); for (i = 0; acs && i < acs->len; i++) { a = (NMActiveConnection*)acs->pdata[i]; - if (strcmp (nm_active_connection_get_connection (a), path) == 0) { - nm_client_deactivate_connection (client, a); + if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) { + nm_client_deactivate_connection (client, a, NULL, NULL); break; } } @@ -416,7 +425,6 @@ vpn_proxy_edit (NetObject *object) GtkWidget *button, *window; NetConnectionEditor *editor; NMClient *client; - NMRemoteSettings *settings; gchar *title; button = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder, @@ -424,11 +432,10 @@ vpn_proxy_edit (NetObject *object) window = gtk_widget_get_toplevel (button); client = net_object_get_client (object); - settings = net_object_get_remote_settings (object); editor = net_connection_editor_new (GTK_WINDOW (window), vpn->priv->connection, - NULL, NULL, client, settings); + NULL, NULL, client); title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (vpn->priv->connection)); net_connection_editor_set_title (editor, title); g_free (title); diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h index 4ed0a3a6b..6ca1910e8 100644 --- a/panels/network/net-vpn.h +++ b/panels/network/net-vpn.h @@ -23,11 +23,9 @@ #define __NET_VPN_H #include <glib-object.h> +#include <NetworkManager.h> -#include "NetworkManagerVPN.h" #include "net-object.h" -#include "nm-connection.h" -#include "nm-vpn-connection.h" G_BEGIN_DECLS diff --git a/panels/network/network-dialogs.c b/panels/network/network-dialogs.c index b2f83764f..23a9a832d 100644 --- a/panels/network/network-dialogs.c +++ b/panels/network/network-dialogs.c @@ -20,26 +20,18 @@ * Copyright 2008 - 2011 Red Hat, Inc. */ -#include <nm-utils.h> -#include <nm-connection.h> -#include <nm-setting-gsm.h> -#include <nm-setting-cdma.h> -#include <nm-setting-serial.h> -#include <nm-device-modem.h> -#include <nm-device-wifi.h> +#include <NetworkManager.h> +#include <nma-wifi-dialog.h> +#include <nma-mobile-wizard.h> #include "network-dialogs.h" -#include "nm-wifi-dialog.h" -#include "nm-mobile-wizard.h" typedef struct { NMClient *client; - NMRemoteSettings *settings; } WirelessDialogClosure; typedef struct { NMClient *client; - NMRemoteSettings *settings; NMDevice *device; } MobileDialogClosure; @@ -49,7 +41,6 @@ wireless_dialog_closure_closure_notify (gpointer data, { WirelessDialogClosure *closure = data; g_object_unref (closure->client); - g_object_unref (closure->settings); g_slice_free (WirelessDialogClosure, data); } @@ -59,7 +50,6 @@ mobile_dialog_closure_free (gpointer data) { MobileDialogClosure *closure = data; g_object_unref (closure->client); - g_object_unref (closure->settings); g_object_unref (closure->device); g_slice_free (MobileDialogClosure, data); @@ -82,24 +72,29 @@ wifi_can_create_wifi_network (NMClient *client) } static void -activate_existing_cb (NMClient *client, - NMActiveConnection *active, - GError *error, +activate_existing_cb (GObject *source_object, + GAsyncResult *res, gpointer user_data) { - if (error) + GError *error = NULL; + + if (!nm_client_activate_connection_finish (NM_CLIENT (source_object), res, &error)) { g_warning ("Failed to activate connection: (%d) %s", error->code, error->message); + g_error_free (error); + } } static void -activate_new_cb (NMClient *client, - NMActiveConnection *active, - const char *connection_path, - GError *error, +activate_new_cb (GObject *source_object, + GAsyncResult *res, gpointer user_data) { - if (error) + GError *error = NULL; + + if (!nm_client_add_and_activate_connection_finish (NM_CLIENT (source_object), res, &error)) { g_warning ("Failed to add new connection: (%d) %s", error->code, error->message); + g_error_free (error); + } } static void @@ -125,7 +120,8 @@ wireless_dialog_response_cb (GtkDialog *foo, NMConnection *connection, *fuzzy_match = NULL; NMDevice *device; NMAccessPoint *ap; - GSList *all, *iter; + const GPtrArray *all; + guint i; if (response != GTK_RESPONSE_OK) goto done; @@ -154,24 +150,24 @@ wireless_dialog_response_cb (GtkDialog *foo, g_assert (device); /* Find a similar connection and use that instead */ - all = nm_remote_settings_list_connections (closure->settings); - for (iter = all; iter; iter = g_slist_next (iter)) { + all = nm_client_get_connections (closure->client); + for (i = 0; i < all->len; i++) { if (nm_connection_compare (connection, - NM_CONNECTION (iter->data), + NM_CONNECTION (g_ptr_array_index (all, i)), (NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) { - fuzzy_match = NM_CONNECTION (iter->data); + fuzzy_match = NM_CONNECTION (g_ptr_array_index (all, i)); break; } } - g_slist_free (all); if (fuzzy_match) { - nm_client_activate_connection (closure->client, - fuzzy_match, - device, - ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, - activate_existing_cb, - NULL); + nm_client_activate_connection_async (closure->client, + fuzzy_match, + device, + ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, + NULL, + activate_existing_cb, + NULL); } else { NMSetting *s_con; NMSettingWireless *s_wifi; @@ -192,12 +188,13 @@ wireless_dialog_response_cb (GtkDialog *foo, g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL); } - nm_client_add_and_activate_connection (closure->client, - connection, - device, - ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, - activate_new_cb, - NULL); + nm_client_add_and_activate_connection_async (closure->client, + connection, + device, + ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, + NULL, + activate_new_cb, + NULL); } /* Balance nma_wifi_dialog_get_connection() */ @@ -211,7 +208,6 @@ done: static void show_wireless_dialog (GtkWidget *toplevel, NMClient *client, - NMRemoteSettings *settings, GtkWidget *dialog) { WirelessDialogClosure *closure; @@ -226,7 +222,6 @@ show_wireless_dialog (GtkWidget *toplevel, closure = g_slice_new (WirelessDialogClosure); closure->client = g_object_ref (client); - closure->settings = g_object_ref (settings); g_signal_connect_data (dialog, "response", G_CALLBACK (wireless_dialog_response_cb), closure, wireless_dialog_closure_closure_notify, 0); @@ -238,29 +233,26 @@ show_wireless_dialog (GtkWidget *toplevel, void cc_network_panel_create_wifi_network (GtkWidget *toplevel, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { if (wifi_can_create_wifi_network (client)) { - show_wireless_dialog (toplevel, client, settings, - nma_wifi_dialog_new_for_create (client, settings)); + show_wireless_dialog (toplevel, client, + nma_wifi_dialog_new_for_create (client)); } } void cc_network_panel_connect_to_hidden_network (GtkWidget *toplevel, - NMClient *client, - NMRemoteSettings *settings) + NMClient *client) { g_debug ("connect to hidden wifi"); - show_wireless_dialog (toplevel, client, settings, - nma_wifi_dialog_new_for_other (client, settings)); + show_wireless_dialog (toplevel, client, + nma_wifi_dialog_new_for_hidden (client)); } void cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel, NMClient *client, - NMRemoteSettings *settings, NMDevice *device, const gchar *arg_access_point) { @@ -293,7 +285,7 @@ cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel, return; } - connection = nm_connection_new (); + connection = nm_simple_connection_new (); /* Need a UUID for the "always ask" stuff in the Dialog of Doom */ s_con = (NMSettingConnection *) nm_setting_connection_new (); @@ -306,7 +298,6 @@ cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel, nm_connection_add_setting (connection, NM_SETTING (s_wifi)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid (ap), - NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -318,8 +309,8 @@ cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel, g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); - dialog = nma_wifi_dialog_new (client, settings, connection, device, ap, FALSE); - show_wireless_dialog (toplevel, client, settings, dialog); + dialog = nma_wifi_dialog_new (client, connection, device, ap, FALSE); + show_wireless_dialog (toplevel, client, dialog); } static void @@ -335,12 +326,13 @@ connect_3g (NMConnection *connection, /* Ask NM to add the new connection and activate it; NM will fill in the * missing details based on the specific object and the device. */ - nm_client_add_and_activate_connection (closure->client, - connection, - closure->device, - "/", - activate_new_cb, - NULL); + nm_client_add_and_activate_connection_async (closure->client, + connection, + closure->device, + "/", + NULL, + activate_new_cb, + NULL); } mobile_dialog_closure_free (closure); @@ -364,7 +356,7 @@ cdma_mobile_wizard_done (NMAMobileWizard *wizard, goto done; } - connection = nm_connection_new (); + connection = nm_simple_connection_new (); setting = nm_setting_cdma_new (); g_object_set (setting, @@ -426,7 +418,7 @@ gsm_mobile_wizard_done (NMAMobileWizard *wizard, goto done; } - connection = nm_connection_new (); + connection = nm_simple_connection_new (); setting = nm_setting_gsm_new (); g_object_set (setting, @@ -493,7 +485,6 @@ show_wizard_idle_cb (NMAMobileWizard *wizard) void cc_network_panel_connect_to_3g_network (GtkWidget *toplevel, NMClient *client, - NMRemoteSettings *settings, NMDevice *device) { MobileDialogClosure *closure; @@ -510,7 +501,6 @@ cc_network_panel_connect_to_3g_network (GtkWidget *toplevel, closure = g_slice_new (MobileDialogClosure); closure->client = g_object_ref (client); - closure->settings = g_object_ref (settings); closure->device = g_object_ref (device); caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); diff --git a/panels/network/network-dialogs.h b/panels/network/network-dialogs.h index ddbf3926a..0f02a520a 100644 --- a/panels/network/network-dialogs.h +++ b/panels/network/network-dialogs.h @@ -20,29 +20,22 @@ #ifndef _NETWORK_DIALOGS_H #define _NETWORK_DIALOGS_H -#include <nm-client.h> -#include <nm-remote-settings.h> -#include <nm-device.h> -#include <nm-access-point.h> +#include <NetworkManager.h> #include <gtk/gtk.h> void cc_network_panel_create_wifi_network (GtkWidget *toplevel, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); void cc_network_panel_connect_to_hidden_network (GtkWidget *toplevel, - NMClient *client, - NMRemoteSettings *settings); + NMClient *client); void cc_network_panel_connect_to_8021x_network (GtkWidget *toplevel, NMClient *client, - NMRemoteSettings *settings, NMDevice *device, const gchar *arg_access_point); void cc_network_panel_connect_to_3g_network (GtkWidget *toplevel, NMClient *client, - NMRemoteSettings *settings, NMDevice *device); #endif /* _NETWORK_DIALOGS_H */ diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c index c4a521e4f..087429033 100644 --- a/panels/network/panel-common.c +++ b/panels/network/panel-common.c @@ -25,11 +25,7 @@ #include <glib.h> #include <glib/gi18n.h> #include <gtk/gtk.h> - -#include <nm-device-ethernet.h> -#include <nm-device-infiniband.h> -#include <nm-device-modem.h> -#include <nm-utils.h> +#include <NetworkManager.h> #include "panel-common.h" @@ -196,7 +192,7 @@ device_state_to_localized_string (NMDeviceState state) * panel_vpn_state_to_localized_string: **/ const gchar * -panel_vpn_state_to_localized_string (NMVPNConnectionState type) +panel_vpn_state_to_localized_string (NMVpnConnectionState type) { const gchar *value = NULL; switch (type) { @@ -245,7 +241,7 @@ device_state_reason_to_localized_string (NMDevice *device) * (eg, NM_DEVICE_STATE_REASON_CARRIER). */ - nm_device_get_state_reason (device, &state_reason); + state_reason = nm_device_get_state_reason (device); switch (state_reason) { case NM_DEVICE_STATE_REASON_CONFIG_FAILED: /* TRANSLATORS: device status reason */ @@ -407,10 +403,6 @@ device_state_reason_to_localized_string (NMDevice *device) /* TRANSLATORS: device status reason */ value = _("SIM wrong"); break; - case NM_DEVICE_STATE_REASON_INFINIBAND_MODE: - /* TRANSLATORS: device status reason */ - value = _("InfiniBand device does not support connected mode"); - break; case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED: /* TRANSLATORS: device status reason */ value = _("Connection dependency failed"); @@ -420,6 +412,7 @@ device_state_reason_to_localized_string (NMDevice *device) value = ""; break; } + return value; } @@ -442,9 +435,6 @@ device_status_to_localized_string (NMDevice *nm_device, !nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (nm_device))) { /* TRANSLATORS: device status */ state_str = _("Cable unplugged"); - } else if (NM_IS_DEVICE_INFINIBAND (nm_device) && - !nm_device_infiniband_get_carrier (NM_DEVICE_INFINIBAND (nm_device))) { - state_str = _("Cable unplugged"); } } if (!state_str) @@ -543,94 +533,53 @@ panel_set_device_widget_header (GtkBuilder *builder, } gchar * -panel_get_ip4_address_as_string (NMIP4Config *ip4_config, const char *what) +panel_get_ip4_address_as_string (NMIPConfig *ip4_config, const char *what) { - const GSList *list; - struct in_addr addr; - gchar *str = NULL; - gchar tmp[INET_ADDRSTRLEN]; - NMIP4Address *address; - - /* get address */ - list = nm_ip4_config_get_addresses (ip4_config); - if (list == NULL) - goto out; + const gchar *str = NULL; /* we only care about one address */ - address = list->data; - if (!strcmp (what, "address")) - addr.s_addr = nm_ip4_address_get_address (address); - else if (!strcmp (what, "gateway")) - addr.s_addr = nm_ip4_address_get_gateway (address); - else if (!strcmp (what, "netmask")) - addr.s_addr = nm_utils_ip4_prefix_to_netmask (nm_ip4_address_get_prefix (address)); - else - goto out; - - if (!inet_ntop (AF_INET, &addr, tmp, sizeof(tmp))) - goto out; - if (g_strcmp0 (tmp, "0.0.0.0") == 0) - goto out; - str = g_strdup (tmp); + if (!strcmp (what, "address")) { + GPtrArray *array; + NMIPAddress *address; + + array = nm_ip_config_get_addresses (ip4_config); + if (array->len < 1) + goto out; + address = array->pdata[0]; + str = nm_ip_address_get_address (address); + } else if (!strcmp (what, "gateway")) { + str = nm_ip_config_get_gateway (ip4_config); + } + out: - return str; + return g_strdup (str); } gchar * -panel_get_ip4_dns_as_string (NMIP4Config *ip4_config) +panel_get_ip4_dns_as_string (NMIPConfig *ip4_config) { - const GArray *array; - GString *dns; - struct in_addr addr; - gchar tmp[INET_ADDRSTRLEN]; - int i; - gchar *str = NULL; - - array = nm_ip4_config_get_nameservers (ip4_config); - if (array == NULL || array->len == 0) - goto out; - - dns = g_string_new (NULL); - for (i = 0; i < array->len; i++) { - addr.s_addr = g_array_index (array, guint32, i); - if (inet_ntop (AF_INET, &addr, tmp, sizeof(tmp))) - g_string_append_printf (dns, "%s ", tmp); - } - str = g_string_free (dns, FALSE); -out: - return str; + return g_strjoinv (" ", + (char **) nm_ip_config_get_nameservers (ip4_config)); } gchar * -panel_get_ip6_address_as_string (NMIP6Config *ip6_config) +panel_get_ip6_address_as_string (NMIPConfig *ip6_config) { - const GSList *list; - const struct in6_addr *addr; - gchar *str = NULL; - gchar tmp[INET6_ADDRSTRLEN]; - NMIP6Address *address; - - /* get address */ - list = nm_ip6_config_get_addresses (ip6_config); - if (list == NULL) - goto out; - - /* we only care about one address */ - address = list->data; - addr = nm_ip6_address_get_address (address); - if (addr == NULL) - goto out; - inet_ntop (AF_INET6, addr, tmp, sizeof(tmp)); - str = g_strdup (tmp); -out: - return str; + GPtrArray *array; + NMIPAddress *address; + + array = nm_ip_config_get_addresses (ip6_config); + if (array->len < 1) + return NULL; + address = array->pdata[0]; + return g_strdup (nm_ip_address_get_address (address)); } void panel_set_device_widgets (GtkBuilder *builder, NMDevice *device) { - NMIP4Config *ip4_config = NULL; - NMIP6Config *ip6_config = NULL; + NMIPConfig *ip4_config = NULL; + NMIPConfig *ip6_config = NULL; gboolean has_ip4; gboolean has_ip6; gchar *str_tmp; diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h index 866c4e7e6..5953f3faf 100644 --- a/panels/network/panel-common.h +++ b/panels/network/panel-common.h @@ -24,8 +24,6 @@ #include <glib-object.h> #include <NetworkManager.h> -#include <NetworkManagerVPN.h> -#include <nm-device.h> #include <gtk/gtk.h> G_BEGIN_DECLS @@ -34,7 +32,7 @@ const gchar *panel_device_to_icon_name (NMDevice *device gboolean symbolic); const gchar *panel_device_to_sortable_string (NMDevice *device); const gchar *panel_ap_mode_to_localized_string (NM80211Mode mode); -const gchar *panel_vpn_state_to_localized_string (NMVPNConnectionState type); +const gchar *panel_vpn_state_to_localized_string (NMVpnConnectionState type); void panel_set_device_status (GtkBuilder *builder, const gchar *label_name, NMDevice *nm_device, @@ -48,9 +46,9 @@ gboolean panel_set_device_widget_header (GtkBuilder *buil void panel_set_device_widgets (GtkBuilder *builder, NMDevice *device); void panel_unset_device_widgets (GtkBuilder *builder); -gchar *panel_get_ip4_address_as_string (NMIP4Config *config, const gchar *what); -gchar *panel_get_ip4_dns_as_string (NMIP4Config *config); -gchar *panel_get_ip6_address_as_string (NMIP6Config *config); +gchar *panel_get_ip4_address_as_string (NMIPConfig *config, const gchar *what); +gchar *panel_get_ip4_dns_as_string (NMIPConfig *config); +gchar *panel_get_ip6_address_as_string (NMIPConfig *config); G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index 20bbf2f21..f148fdada 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -26,8 +26,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-connection.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index bcfc2050a..f6baefb1a 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -22,7 +22,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index 2a63991d6..3d9d750b6 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -25,9 +25,7 @@ #include <glib/gi18n.h> #include <ctype.h> #include <string.h> - -#include <nm-setting-connection.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index f3b843d05..24a6cddf6 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -22,8 +22,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-8021x.h> -#include <nm-setting-connection.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index 2069ccb3e..0fbb58c97 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -26,8 +26,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-connection.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index c21744a22..ef9405884 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -25,9 +25,7 @@ #include <glib/gi18n.h> #include <ctype.h> #include <string.h> - -#include <nm-setting-connection.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "eap-method.h" #include "wireless-security.h" diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 3da36766b..62ac4e8d5 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -31,11 +31,9 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> +#include <NetworkManager.h> -#include <nm-setting-connection.h> -#include <nm-setting-8021x.h> #include "eap-method.h" -#include "nm-utils.h" GType eap_method_get_g_type (void) diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index d2933c77f..61cc1f7f7 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -25,9 +25,7 @@ #include <glib.h> #include <gtk/gtk.h> - -#include <nm-connection.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> typedef struct _EAPMethod EAPMethod; diff --git a/panels/network/wireless-security/helpers.h b/panels/network/wireless-security/helpers.h index 8945ff9ed..dbcc33244 100644 --- a/panels/network/wireless-security/helpers.h +++ b/panels/network/wireless-security/helpers.h @@ -25,8 +25,7 @@ #include <glib.h> #include <gtk/gtk.h> -#include <nm-connection.h> -#include <nm-setting.h> +#include <NetworkManager.h> typedef const char * (*HelperSecretFunc)(NMSetting *); diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index a8468bc0f..2b3a2be93 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -28,11 +28,7 @@ #include <gtk/gtk.h> #include <glib/gi18n.h> -#include <nm-setting-connection.h> -#include <nm-setting-wired.h> -#include <nm-setting-wireless.h> -#include <nm-setting-wireless-security.h> -#include <nm-setting-8021x.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "wireless-security-resources.h" @@ -83,7 +79,7 @@ wireless_security_changed_cb (GtkWidget *ignored, gpointer user_data) } gboolean -wireless_security_validate (WirelessSecurity *sec, const GByteArray *ssid) +wireless_security_validate (WirelessSecurity *sec, GBytes *ssid) { g_return_val_if_fail (sec != NULL, FALSE); @@ -472,18 +468,12 @@ ws_802_1x_fill_connection (WirelessSecurity *sec, NMConnection *connection) { GtkWidget *widget; - NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; NMSetting8021x *s_8021x; EAPMethod *eap = NULL; GtkTreeModel *model; GtkTreeIter iter; - s_wireless = nm_connection_get_setting_wireless (connection); - g_assert (s_wireless); - - g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); - /* Blow away the old wireless security setting by adding a clear one */ s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 23a725b0d..0a585531f 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -25,8 +25,7 @@ #include <glib.h> #include <gtk/gtk.h> - -#include <nm-connection.h> +#include <NetworkManager.h> typedef struct _WirelessSecurity WirelessSecurity; @@ -36,7 +35,7 @@ typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection); typedef void (*WSUpdateSecretsFunc) (WirelessSecurity *sec, NMConnection *connection); typedef void (*WSDestroyFunc) (WirelessSecurity *sec); -typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, const GByteArray *ssid); +typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GBytes *ssid); typedef GtkWidget * (*WSNagUserFunc) (WirelessSecurity *sec); struct _WirelessSecurity { @@ -66,7 +65,7 @@ void wireless_security_set_changed_notify (WirelessSecurity *sec, WSChangedFunc func, gpointer user_data); -gboolean wireless_security_validate (WirelessSecurity *sec, const GByteArray *ssid); +gboolean wireless_security_validate (WirelessSecurity *sec, GBytes *ssid); void wireless_security_add_to_size_group (WirelessSecurity *sec, GtkSizeGroup *group); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 481196aa7..0ccc28a96 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -23,7 +23,7 @@ #include <glib/gi18n.h> #include <ctype.h> #include <string.h> -#include <nm-setting-wireless.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "eap-method.h" @@ -44,7 +44,7 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent, const GByteArray *ssid) +validate (WirelessSecurity *parent, GBytes *ssid) { return ws_802_1x_validate (parent, "dynamic_wep_auth_combo"); } diff --git a/panels/network/wireless-security/ws-dynamic-wep.h b/panels/network/wireless-security/ws-dynamic-wep.h index 54979f474..03b2d6811 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.h +++ b/panels/network/wireless-security/ws-dynamic-wep.h @@ -23,7 +23,7 @@ #ifndef WS_DYNAMIC_WEP_H #define WS_DYNAMIC_WEP_H -#include <nm-connection.h> +#include <NetworkManager.h> typedef struct _WirelessSecurityDynamicWEP WirelessSecurityDynamicWEP; diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index 370a55ab3..23357da33 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -21,7 +21,7 @@ */ #include <string.h> -#include <nm-setting-wireless.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "helpers.h" @@ -45,7 +45,7 @@ show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec) } static gboolean -validate (WirelessSecurity *parent, const GByteArray *ssid) +validate (WirelessSecurity *parent, GBytes *ssid) { GtkWidget *entry; const char *text; @@ -90,16 +90,10 @@ static void fill_connection (WirelessSecurity *parent, NMConnection *connection) { WirelessSecurityLEAP *sec = (WirelessSecurityLEAP *) parent; - NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; GtkWidget *widget; const char *leap_password = NULL, *leap_username = NULL; - s_wireless = nm_connection_get_setting_wireless (connection); - g_assert (s_wireless); - - g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); - /* Blow away the old security setting by adding a clear one */ s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); diff --git a/panels/network/wireless-security/ws-leap.h b/panels/network/wireless-security/ws-leap.h index 6f1d7050b..d6319fe3f 100644 --- a/panels/network/wireless-security/ws-leap.h +++ b/panels/network/wireless-security/ws-leap.h @@ -23,7 +23,7 @@ #ifndef WS_LEAP_H #define WS_LEAP_H -#include <nm-connection.h> +#include <NetworkManager.h> typedef struct _WirelessSecurityLEAP WirelessSecurityLEAP; diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c index 1cb4febbb..a49ae7497 100644 --- a/panels/network/wireless-security/ws-wep-key.c +++ b/panels/network/wireless-security/ws-wep-key.c @@ -23,8 +23,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-wireless.h> -#include <nm-setting-wireless-security.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "helpers.h" @@ -88,7 +87,7 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent, const GByteArray *ssid) +validate (WirelessSecurity *parent, GBytes *ssid) { WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent; GtkWidget *entry; @@ -153,7 +152,6 @@ static void fill_connection (WirelessSecurity *parent, NMConnection *connection) { WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent; - NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; GtkWidget *widget; gint auth_alg; @@ -167,11 +165,6 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) key = gtk_entry_get_text (GTK_ENTRY (widget)); strcpy (sec->keys[sec->cur_index], key); - s_wireless = nm_connection_get_setting_wireless (connection); - g_assert (s_wireless); - - g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); - /* Blow away the old security setting by adding a clear one */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wsec); diff --git a/panels/network/wireless-security/ws-wep-key.h b/panels/network/wireless-security/ws-wep-key.h index fdd70da09..097f7a163 100644 --- a/panels/network/wireless-security/ws-wep-key.h +++ b/panels/network/wireless-security/ws-wep-key.h @@ -23,7 +23,7 @@ #ifndef WS_WEP_KEY_H #define WS_WEP_KEY_H -#include <nm-setting-wireless-security.h> +#include <NetworkManager.h> typedef struct _WirelessSecurityWEPKey WirelessSecurityWEPKey; diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 313c4836e..0450c4b58 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -23,7 +23,7 @@ #include <glib/gi18n.h> #include <ctype.h> #include <string.h> -#include <nm-setting-wireless.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "eap-method.h" @@ -45,7 +45,7 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent, const GByteArray *ssid) +validate (WirelessSecurity *parent, GBytes *ssid) { return ws_802_1x_validate (parent, "wpa_eap_auth_combo"); } diff --git a/panels/network/wireless-security/ws-wpa-eap.h b/panels/network/wireless-security/ws-wpa-eap.h index 5c8faeaba..095772cc5 100644 --- a/panels/network/wireless-security/ws-wpa-eap.h +++ b/panels/network/wireless-security/ws-wpa-eap.h @@ -23,7 +23,7 @@ #ifndef WS_WPA_EAP_H #define WS_WPA_EAP_H -#include <nm-connection.h> +#include <NetworkManager.h> typedef struct _WirelessSecurityWPAEAP WirelessSecurityWPAEAP; diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c index 1c91f13ff..cbf546199 100644 --- a/panels/network/wireless-security/ws-wpa-psk.c +++ b/panels/network/wireless-security/ws-wpa-psk.c @@ -22,7 +22,7 @@ #include <ctype.h> #include <string.h> -#include <nm-setting-wireless.h> +#include <NetworkManager.h> #include "wireless-security.h" #include "helpers.h" @@ -47,7 +47,7 @@ show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec) } static gboolean -validate (WirelessSecurity *parent, const GByteArray *ssid) +validate (WirelessSecurity *parent, GBytes *ssid) { GtkWidget *entry; const char *key; @@ -110,8 +110,6 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) if (mode && !strcmp (mode, "adhoc")) is_adhoc = TRUE; - g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); - /* Blow away the old security setting by adding a clear one */ s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); |