network: Use g_autoptr with GList
This commit is contained in:
parent
fbaa9cb607
commit
c9ea93f195
2 changed files with 36 additions and 65 deletions
|
@ -108,11 +108,11 @@ method_changed (CEPageIP4 *self)
|
||||||
static void
|
static void
|
||||||
update_row_sensitivity (CEPageIP4 *self, GtkWidget *list)
|
update_row_sensitivity (CEPageIP4 *self, GtkWidget *list)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
gint rows = 0, i = 0;
|
gint rows = 0, i = 0;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (list));
|
children = gtk_container_get_children (GTK_CONTAINER (list));
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ update_row_sensitivity (CEPageIP4 *self, GtkWidget *list)
|
||||||
if (button != NULL)
|
if (button != NULL)
|
||||||
rows++;
|
rows++;
|
||||||
}
|
}
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
|
@ -128,17 +128,16 @@ update_row_sensitivity (CEPageIP4 *self, GtkWidget *list)
|
||||||
if (button != NULL)
|
if (button != NULL)
|
||||||
gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
|
gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_row_gateway_sensitivity (CEPageIP4 *self)
|
update_row_gateway_sensitivity (CEPageIP4 *self)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
gint rows = 0;
|
gint rows = 0;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkWidget *entry;
|
GtkWidget *entry;
|
||||||
|
|
||||||
|
@ -148,7 +147,6 @@ update_row_gateway_sensitivity (CEPageIP4 *self)
|
||||||
|
|
||||||
rows++;
|
rows++;
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -175,22 +173,20 @@ static gboolean
|
||||||
validate_row (GtkWidget *row)
|
validate_row (GtkWidget *row)
|
||||||
{
|
{
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
gboolean valid;
|
gboolean valid;
|
||||||
|
|
||||||
valid = FALSE;
|
valid = FALSE;
|
||||||
box = gtk_bin_get_child (GTK_BIN (row));
|
box = gtk_bin_get_child (GTK_BIN (row));
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (box));
|
children = gtk_container_get_children (GTK_CONTAINER (box));
|
||||||
|
|
||||||
for (l = children; l != NULL; l = l->next) {
|
for (GList *l = children; l != NULL; l = l->next) {
|
||||||
if (!GTK_IS_ENTRY (l->data))
|
if (!GTK_IS_ENTRY (l->data))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
valid = valid || gtk_entry_get_text_length (l->data) > 0;
|
valid = valid || gtk_entry_get_text_length (l->data) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,19 +257,15 @@ add_address_row (CEPageIP4 *self,
|
||||||
static void
|
static void
|
||||||
ensure_empty_address_row (CEPageIP4 *self)
|
ensure_empty_address_row (CEPageIP4 *self)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
||||||
l = children;
|
l = g_list_last (children);
|
||||||
|
|
||||||
while (l && l->next)
|
|
||||||
l = l->next;
|
|
||||||
|
|
||||||
/* Add the last, stub row if needed*/
|
/* Add the last, stub row if needed*/
|
||||||
if (!l || validate_row (l->data))
|
if (!l || validate_row (l->data))
|
||||||
add_address_row (self, "", "", "");
|
add_address_row (self, "", "", "");
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -421,19 +413,15 @@ add_route_row (CEPageIP4 *self,
|
||||||
static void
|
static void
|
||||||
ensure_empty_routes_row (CEPageIP4 *self)
|
ensure_empty_routes_row (CEPageIP4 *self)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
||||||
l = children;
|
l = g_list_last (children);
|
||||||
|
|
||||||
while (l && l->next)
|
|
||||||
l = l->next;
|
|
||||||
|
|
||||||
/* Add the last, stub row if needed*/
|
/* Add the last, stub row if needed*/
|
||||||
if (!l || validate_row (l->data))
|
if (!l || validate_row (l->data))
|
||||||
add_route_row (self, "", "", "", -1);
|
add_route_row (self, "", "", "", -1);
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -574,7 +562,8 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
GPtrArray *dns_servers = NULL;
|
GPtrArray *dns_servers = NULL;
|
||||||
GPtrArray *routes = NULL;
|
GPtrArray *routes = NULL;
|
||||||
GStrv dns_addresses = NULL;
|
GStrv dns_addresses = NULL;
|
||||||
GList *children, *l;
|
g_autoptr(GList) address_children = NULL;
|
||||||
|
g_autoptr(GList) routes_children = NULL;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
const char *default_gateway = NULL;
|
const char *default_gateway = NULL;
|
||||||
gchar *dns_text = NULL;
|
gchar *dns_text = NULL;
|
||||||
|
@ -593,11 +582,9 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
|
|
||||||
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
|
||||||
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
address_children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
||||||
else
|
|
||||||
children = NULL;
|
|
||||||
|
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = address_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
GtkEntry *entry;
|
||||||
GtkEntry *gateway_entry;
|
GtkEntry *gateway_entry;
|
||||||
|
@ -660,7 +647,6 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
if (!l || !l->next)
|
if (!l || !l->next)
|
||||||
ensure_empty_address_row (self);
|
ensure_empty_address_row (self);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
if (addresses->len == 0) {
|
if (addresses->len == 0) {
|
||||||
g_ptr_array_free (addresses, TRUE);
|
g_ptr_array_free (addresses, TRUE);
|
||||||
|
@ -705,11 +691,9 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
|
||||||
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
|
if (g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) ||
|
||||||
g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
g_str_equal (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
routes_children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
||||||
else
|
|
||||||
children = NULL;
|
|
||||||
|
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = routes_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
GtkEntry *entry;
|
||||||
const gchar *text_address;
|
const gchar *text_address;
|
||||||
|
@ -779,7 +763,6 @@ ui_to_setting (CEPageIP4 *self)
|
||||||
if (!l || !l->next)
|
if (!l || !l->next)
|
||||||
ensure_empty_routes_row (self);
|
ensure_empty_routes_row (self);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
if (routes->len == 0) {
|
if (routes->len == 0) {
|
||||||
g_ptr_array_free (routes, TRUE);
|
g_ptr_array_free (routes, TRUE);
|
||||||
|
|
|
@ -111,11 +111,11 @@ method_changed (CEPageIP6 *self)
|
||||||
static void
|
static void
|
||||||
update_row_sensitivity (CEPageIP6 *self, GtkWidget *list)
|
update_row_sensitivity (CEPageIP6 *self, GtkWidget *list)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
gint rows = 0, i = 0;
|
gint rows = 0, i = 0;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (list));
|
children = gtk_container_get_children (GTK_CONTAINER (list));
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ update_row_sensitivity (CEPageIP6 *self, GtkWidget *list)
|
||||||
if (button != NULL)
|
if (button != NULL)
|
||||||
rows++;
|
rows++;
|
||||||
}
|
}
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
|
@ -131,7 +131,6 @@ update_row_sensitivity (CEPageIP6 *self, GtkWidget *list)
|
||||||
if (button != NULL)
|
if (button != NULL)
|
||||||
gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
|
gtk_widget_set_sensitive (button, rows > 1 && ++i < rows);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -156,22 +155,20 @@ static gboolean
|
||||||
validate_row (GtkWidget *row)
|
validate_row (GtkWidget *row)
|
||||||
{
|
{
|
||||||
GtkWidget *box;
|
GtkWidget *box;
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
gboolean valid;
|
gboolean valid;
|
||||||
|
|
||||||
valid = FALSE;
|
valid = FALSE;
|
||||||
box = gtk_bin_get_child (GTK_BIN (row));
|
box = gtk_bin_get_child (GTK_BIN (row));
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (box));
|
children = gtk_container_get_children (GTK_CONTAINER (box));
|
||||||
|
|
||||||
for (l = children; l != NULL; l = l->next) {
|
for (GList *l = children; l != NULL; l = l->next) {
|
||||||
if (!GTK_IS_ENTRY (l->data))
|
if (!GTK_IS_ENTRY (l->data))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
valid = valid || gtk_entry_get_text_length (l->data) > 0;
|
valid = valid || gtk_entry_get_text_length (l->data) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,19 +238,15 @@ add_address_row (CEPageIP6 *self,
|
||||||
static void
|
static void
|
||||||
ensure_empty_address_row (CEPageIP6 *self)
|
ensure_empty_address_row (CEPageIP6 *self)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
||||||
l = children;
|
l = g_list_last (children);
|
||||||
|
|
||||||
while (l && l->next)
|
|
||||||
l = l->next;
|
|
||||||
|
|
||||||
/* Add the last, stub row if needed*/
|
/* Add the last, stub row if needed*/
|
||||||
if (!l || validate_row (l->data))
|
if (!l || validate_row (l->data))
|
||||||
add_address_row (self, "", "", "");
|
add_address_row (self, "", "", "");
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -391,10 +384,11 @@ add_route_row (CEPageIP6 *self,
|
||||||
static void
|
static void
|
||||||
ensure_empty_routes_row (CEPageIP6 *self)
|
ensure_empty_routes_row (CEPageIP6 *self)
|
||||||
{
|
{
|
||||||
GList *children, *l;
|
g_autoptr(GList) children = NULL;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
||||||
l = children;
|
l = g_list_last (children);
|
||||||
|
|
||||||
while (l && l->next)
|
while (l && l->next)
|
||||||
l = l->next;
|
l = l->next;
|
||||||
|
@ -402,8 +396,6 @@ ensure_empty_routes_row (CEPageIP6 *self)
|
||||||
/* Add the last, stub row if needed*/
|
/* Add the last, stub row if needed*/
|
||||||
if (!l || validate_row (l->data))
|
if (!l || validate_row (l->data))
|
||||||
add_route_row (self, "", NULL, "", NULL);
|
add_route_row (self, "", NULL, "", NULL);
|
||||||
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -522,7 +514,8 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
gboolean ignore_auto_dns;
|
gboolean ignore_auto_dns;
|
||||||
gboolean ignore_auto_routes;
|
gboolean ignore_auto_routes;
|
||||||
gboolean never_default;
|
gboolean never_default;
|
||||||
GList *children, *l;
|
g_autoptr(GList) address_children = NULL;
|
||||||
|
g_autoptr(GList) routes_children = NULL;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
GStrv dns_addresses = NULL;
|
GStrv dns_addresses = NULL;
|
||||||
gchar *dns_text = NULL;
|
gchar *dns_text = NULL;
|
||||||
|
@ -543,15 +536,14 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
|
|
||||||
nm_setting_ip_config_clear_addresses (self->setting);
|
nm_setting_ip_config_clear_addresses (self->setting);
|
||||||
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
|
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) {
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
address_children = gtk_container_get_children (GTK_CONTAINER (self->address_list));
|
||||||
} else {
|
} else {
|
||||||
g_object_set (G_OBJECT (self->setting),
|
g_object_set (G_OBJECT (self->setting),
|
||||||
NM_SETTING_IP_CONFIG_GATEWAY, NULL,
|
NM_SETTING_IP_CONFIG_GATEWAY, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
children = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = address_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
GtkEntry *entry;
|
||||||
const gchar *text_address;
|
const gchar *text_address;
|
||||||
|
@ -615,7 +607,6 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
if (!l || !l->next)
|
if (!l || !l->next)
|
||||||
ensure_empty_address_row (self);
|
ensure_empty_address_row (self);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
nm_setting_ip_config_clear_dns (self->setting);
|
nm_setting_ip_config_clear_dns (self->setting);
|
||||||
dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (self->dns_entry))));
|
dns_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (self->dns_entry))));
|
||||||
|
@ -651,11 +642,9 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
if (g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) ||
|
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_DHCP) ||
|
||||||
g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
|
g_str_equal (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
routes_children = gtk_container_get_children (GTK_CONTAINER (self->routes_list));
|
||||||
else
|
|
||||||
children = NULL;
|
|
||||||
|
|
||||||
for (l = children; l; l = l->next) {
|
for (GList *l = routes_children; l; l = l->next) {
|
||||||
GtkWidget *row = l->data;
|
GtkWidget *row = l->data;
|
||||||
GtkEntry *entry;
|
GtkEntry *entry;
|
||||||
const gchar *text_address;
|
const gchar *text_address;
|
||||||
|
@ -731,7 +720,6 @@ ui_to_setting (CEPageIP6 *self)
|
||||||
if (!l || !l->next)
|
if (!l || !l->next)
|
||||||
ensure_empty_routes_row (self);
|
ensure_empty_routes_row (self);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue