From 2d9366bcee240f53745d4534f24165cc3f306066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Mon, 2 Sep 2013 13:20:04 +0200 Subject: [PATCH] cli: connect IP addresses/method handlers for existing connections (rh #998137) The handlers detecting changes of IP addresses/method in nmcli interactive editor were connected only for newly created connection. That's why the automagic feature of setting 'method' when 'addresses' are changed and vice versa worked just for new connections, but not while editing existing connections. --- cli/src/connections.c | 17 +++++++++++++++++ cli/src/settings.c | 34 ++++++++++++++++++++++++---------- cli/src/settings.h | 2 ++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index 6553052e20..f90f6e3cdc 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -5199,6 +5199,21 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection) } } +static void +editor_init_existing_connection (NMConnection *connection) +{ + NMSettingIP4Config *s_ip4; + NMSettingIP6Config *s_ip6; + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + s_ip6 = nm_connection_get_setting_ip6_config (connection); + + if (s_ip4) + nmc_setting_ip4_connect_handlers (s_ip4); + if (s_ip6) + nmc_setting_ip6_connect_handlers (s_ip6); +} + static NMCResultCode do_connection_edit (NmCli *nmc, int argc, char **argv) { @@ -5302,6 +5317,8 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) /* Load previously saved history commands for the connection */ load_history_cmds (nm_connection_get_uuid (connection)); + + editor_init_existing_connection (connection); } else { /* New connection */ connection_type = check_valid_name (type, nmc_valid_connection_types, &err1); diff --git a/cli/src/settings.c b/cli/src/settings.c index 001a6e6761..6526b9fdf4 100644 --- a/cli/src/settings.c +++ b/cli/src/settings.c @@ -1557,6 +1557,28 @@ ipv6_method_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data) g_signal_handlers_unblock_by_func (object, G_CALLBACK (ipv6_addresses_changed_cb), NULL); } +void +nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting) +{ + g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting)); + + g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_ADDRESSES, + G_CALLBACK (ipv4_addresses_changed_cb), NULL); + g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_METHOD, + G_CALLBACK (ipv4_method_changed_cb), NULL); +} + +void +nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting) +{ + g_return_if_fail (NM_IS_SETTING_IP6_CONFIG (setting)); + + g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_ADDRESSES, + G_CALLBACK (ipv6_addresses_changed_cb), NULL); + g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_METHOD, + G_CALLBACK (ipv6_method_changed_cb), NULL); +} + /* * Customize some properties of the setting so that the setting has sensible * values. @@ -1570,20 +1592,12 @@ nmc_setting_custom_init (NMSetting *setting) g_object_set (NM_SETTING_IP4_CONFIG (setting), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); - - g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_ADDRESSES, - G_CALLBACK (ipv4_addresses_changed_cb), NULL); - g_signal_connect (setting, "notify::" NM_SETTING_IP4_CONFIG_METHOD, - G_CALLBACK (ipv4_method_changed_cb), NULL); + nmc_setting_ip4_connect_handlers (NM_SETTING_IP4_CONFIG (setting)); } else if (NM_IS_SETTING_IP6_CONFIG (setting)) { g_object_set (NM_SETTING_IP6_CONFIG (setting), NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); - - g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_ADDRESSES, - G_CALLBACK (ipv6_addresses_changed_cb), NULL); - g_signal_connect (setting, "notify::" NM_SETTING_IP6_CONFIG_METHOD, - G_CALLBACK (ipv6_method_changed_cb), NULL); + nmc_setting_ip6_connect_handlers (NM_SETTING_IP6_CONFIG (setting)); } } diff --git a/cli/src/settings.h b/cli/src/settings.h index 2aaadb8ac4..84fa3bae22 100644 --- a/cli/src/settings.h +++ b/cli/src/settings.h @@ -53,6 +53,8 @@ void nmc_properties_cleanup (void); NMSetting *nmc_setting_new_for_name (const char *name); void nmc_setting_custom_init (NMSetting *setting); +void nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting); +void nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting); char **nmc_setting_get_valid_properties (NMSetting *setting); char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop);