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.
This commit is contained in:
Jiří Klimeš
2013-09-02 13:20:04 +02:00
parent 0e57603e43
commit 2d9366bcee
3 changed files with 43 additions and 10 deletions

View File

@@ -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);

View File

@@ -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));
}
}

View File

@@ -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);