network: Split up a combined setter into multiple methods

This commit is contained in:
Robert Ancell 2019-11-08 10:10:18 +13:00 committed by Georges Basile Stavracas Neto
parent e5ae62a6a3
commit 131e89e690
4 changed files with 64 additions and 40 deletions

View file

@ -171,11 +171,9 @@ widgets_realized (EAPMethodLEAP *self)
static void
widgets_unrealized (EAPMethodLEAP *self)
{
wireless_security_set_userpass (self->ws_parent,
gtk_entry_get_text (self->username_entry),
gtk_entry_get_text (self->password_entry),
(gboolean) -1,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check)));
wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry));
wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry));
wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check)));
}
static void

View file

@ -271,11 +271,10 @@ widgets_realized (EAPMethodSimple *self)
static void
widgets_unrealized (EAPMethodSimple *self)
{
wireless_security_set_userpass (self->ws_parent,
gtk_entry_get_text (self->username_entry),
gtk_entry_get_text (self->password_entry),
always_ask_selected (self->password_entry),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check)));
wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry));
wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry));
wireless_security_set_always_ask (self->ws_parent, always_ask_selected (self->password_entry));
wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check)));
}
static void

View file

@ -145,6 +145,17 @@ wireless_security_adhoc_compatible (WirelessSecurity *self)
return TRUE;
}
void
wireless_security_set_username (WirelessSecurity *self, const gchar *username)
{
WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self);
g_return_if_fail (WIRELESS_IS_SECURITY (self));
g_clear_pointer (&priv->username, g_free);
priv->username = g_strdup (username);
}
const gchar *
wireless_security_get_username (WirelessSecurity *self)
{
@ -155,6 +166,20 @@ wireless_security_get_username (WirelessSecurity *self)
return priv->username;
}
void
wireless_security_set_password (WirelessSecurity *self, const gchar *password)
{
WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self);
g_return_if_fail (WIRELESS_IS_SECURITY (self));
if (priv->password)
memset (priv->password, 0, strlen (priv->password));
g_clear_pointer (&priv->password, g_free);
priv->password = g_strdup (password);
}
const gchar *
wireless_security_get_password (WirelessSecurity *self)
{
@ -165,6 +190,16 @@ wireless_security_get_password (WirelessSecurity *self)
return priv->password;
}
void
wireless_security_set_always_ask (WirelessSecurity *self, gboolean always_ask)
{
WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self);
g_return_if_fail (WIRELESS_IS_SECURITY (self));
priv->always_ask = always_ask;
}
gboolean
wireless_security_get_always_ask (WirelessSecurity *self)
{
@ -175,6 +210,16 @@ wireless_security_get_always_ask (WirelessSecurity *self)
return priv->always_ask;
}
void
wireless_security_set_show_password (WirelessSecurity *self, gboolean show_password)
{
WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self);
g_return_if_fail (WIRELESS_IS_SECURITY (self));
priv->show_password = show_password;
}
gboolean
wireless_security_get_show_password (WirelessSecurity *self)
{
@ -185,29 +230,6 @@ wireless_security_get_show_password (WirelessSecurity *self)
return priv->show_password;
}
void
wireless_security_set_userpass (WirelessSecurity *self,
const char *user,
const char *password,
gboolean always_ask,
gboolean show_password)
{
WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self);
g_clear_pointer (&priv->username, g_free);
priv->username = g_strdup (user);
if (priv->password)
memset (priv->password, 0, strlen (priv->password));
g_clear_pointer (&priv->password, g_free);
priv->password = g_strdup (password);
if (always_ask != (gboolean) -1)
priv->always_ask = always_ask;
priv->show_password = show_password;
}
void
wireless_security_clear_ciphers (NMConnection *connection)
{
@ -319,7 +341,10 @@ ws_802_1x_auth_combo_init (WirelessSecurity *self,
always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED);
}
}
wireless_security_set_userpass (self, user, password, always_ask, FALSE);
wireless_security_set_username (self, user);
wireless_security_set_password (self, password);
wireless_security_set_always_ask (self, always_ask);
wireless_security_set_show_password (self, FALSE);
auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ());

View file

@ -50,19 +50,21 @@ void wireless_security_fill_connection (WirelessSecurity *sec,
gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec);
void wireless_security_set_username (WirelessSecurity *sec, const gchar *username);
const gchar *wireless_security_get_username (WirelessSecurity *sec);
void wireless_security_set_password (WirelessSecurity *sec, const gchar *password);
const gchar *wireless_security_get_password (WirelessSecurity *sec);
void wireless_security_set_always_ask (WirelessSecurity *sec, gboolean always_ask);
gboolean wireless_security_get_always_ask (WirelessSecurity *sec);
gboolean wireless_security_get_show_password (WirelessSecurity *sec);
void wireless_security_set_show_password (WirelessSecurity *sec, gboolean show_password);
void wireless_security_set_userpass (WirelessSecurity *sec,
const char *user,
const char *password,
gboolean always_ask,
gboolean show_password);
gboolean wireless_security_get_show_password (WirelessSecurity *sec);
/* Below for internal use only */