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
This commit is contained in:
parent
8400d3ed81
commit
9183d34947
62 changed files with 953 additions and 1427 deletions
|
@ -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;
|
||||
|
||||
nm_connection_clear_secrets (NM_CONNECTION (connection));
|
||||
|
||||
update_complete (editor, error);
|
||||
}
|
||||
|
||||
static void
|
||||
added_connection_cb (NMRemoteSettings *settings,
|
||||
NMRemoteConnection *connection,
|
||||
GError *error,
|
||||
gpointer data)
|
||||
{
|
||||
NetConnectionEditor *editor = data;
|
||||
|
||||
if (error) {
|
||||
g_warning ("Failed to add connection: %s", error->message);
|
||||
/* Leave the editor open */
|
||||
return;
|
||||
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
|
||||
}
|
||||
|
||||
update_complete (editor, error);
|
||||
nm_connection_clear_secrets (NM_CONNECTION (source_object));
|
||||
|
||||
editor = user_data;
|
||||
update_complete (editor, success);
|
||||
}
|
||||
|
||||
static void
|
||||
added_connection_cb (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
NetConnectionEditor *editor;
|
||||
GError *error = NULL;
|
||||
gboolean success = TRUE;
|
||||
|
||||
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; FIXME return if cancelled
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (info->canceled) {
|
||||
connection = NM_REMOTE_CONNECTION (source_object);
|
||||
variant = nm_remote_connection_get_secrets_finish (connection, res, &error);
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue