Commit e8a16438 authored by Beniamino Galvani's avatar Beniamino Galvani

editor: allow specifying IPv4 address for shared method

parent 68654ab9
......@@ -104,9 +104,15 @@ typedef CEPage* (*CEPageNewFunc)(NMConnectionEditor *editor,
"configured in addition to the automatic ones.")
#define CE_TOOLTIP_ADDR_MANUAL _("IP addresses identify your computer on the network. " \
"Click the \"Add\" button to add an IP address.")
#define CE_TOOLTIP_ADDR_SHARED _("The IP address identify your computer on the network and " \
"determines the address range distributed to other computers. " \
"Click the \"Add\" button to add an IP address. "\
"If no address is provided, one in the 10.42.x.x range will " \
"be used.")
#define CE_LABEL_ADDR_AUTO _("Additional static addresses")
#define CE_LABEL_ADDR_MANUAL _("Addresses")
#define CE_LABEL_ADDR_SHARED _("Address (optional)")
GType ce_page_get_type (void);
......
......@@ -60,6 +60,7 @@ typedef struct {
GtkTreeView *addr_list;
GtkCellRenderer *addr_cells[COL_LAST + 1];
GtkTreeModel *addr_saved;
guint32 addr_method;
/* DNS servers */
GtkWidget *dns_servers_label;
......@@ -235,6 +236,22 @@ ip4_private_init (CEPageIP4 *self, NMConnection *connection)
priv->routes_button = GTK_BUTTON (gtk_builder_get_object (builder, "ip4_routes_button"));
}
static void
address_list_changed (CEPageIP4 *self)
{
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
GtkTreeModel *model;
int num_rows;
if (priv->addr_method != IP4_METHOD_SHARED)
return;
/* Only one address is allowed in shared mode */
model = gtk_tree_view_get_model (priv->addr_list);
num_rows = gtk_tree_model_iter_n_children (model, NULL);
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_add), num_rows == 0);
}
static void
method_changed (GtkComboBox *combo, gpointer user_data)
{
......@@ -276,6 +293,10 @@ method_changed (GtkComboBox *combo, gpointer user_data)
label = CE_LABEL_ADDR_MANUAL;
break;
case IP4_METHOD_SHARED:
addr_enabled = TRUE;
tooltip = CE_TOOLTIP_ADDR_SHARED;
label = CE_LABEL_ADDR_SHARED;
break;
case IP4_METHOD_DISABLED:
addr_enabled = dns_enabled = dhcp_enabled = routes_enabled = ip4_required_enabled = FALSE;
break;
......@@ -283,6 +304,7 @@ method_changed (GtkComboBox *combo, gpointer user_data)
break;
}
priv->addr_method = method;
gtk_widget_set_tooltip_text (GTK_WIDGET (priv->addr_list), tooltip);
gtk_label_set_text (GTK_LABEL (priv->addr_label), label);
......@@ -316,6 +338,24 @@ method_changed (GtkComboBox *combo, gpointer user_data)
}
}
if (method == IP4_METHOD_SHARED) {
GtkTreeModel *model;
gboolean iter_valid;
int i;
/* Remove all rows except first */
model = gtk_tree_view_get_model (priv->addr_list);
iter_valid = gtk_tree_model_get_iter_first (model, &iter);
for (i = 0; iter_valid; i++) {
if (i > 0)
iter_valid = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
else
iter_valid = gtk_tree_model_iter_next (model, &iter);
}
}
address_list_changed (user_data);
gtk_widget_set_sensitive (priv->dns_servers_label, dns_enabled);
if (method_auto)
gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->dns_servers_label), _("Additional DNS ser_vers:"));
......@@ -494,12 +534,14 @@ addr_add_clicked (GtkButton *button, gpointer user_data)
g_list_free (cells);
gtk_tree_path_free (path);
address_list_changed (user_data);
}
static void
addr_delete_clicked (GtkButton *button, gpointer user_data)
{
GtkTreeView *treeview = GTK_TREE_VIEW (user_data);
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (user_data);
GtkTreeView *treeview = priv->addr_list;
GtkTreeSelection *selection;
GList *selected_rows;
GtkTreeModel *model = NULL;
......@@ -525,6 +567,8 @@ addr_delete_clicked (GtkButton *button, gpointer user_data)
selection = gtk_tree_view_get_selection (treeview);
gtk_tree_selection_select_iter (selection, &iter);
}
address_list_changed (user_data);
}
static void
......@@ -1142,7 +1186,7 @@ finish_setup (CEPageIP4 *self, gpointer unused, GError *error, gpointer user_dat
gtk_widget_set_sensitive (GTK_WIDGET (priv->addr_delete), FALSE);
g_signal_connect (priv->addr_add, "clicked", G_CALLBACK (addr_add_clicked), self);
g_signal_connect (priv->addr_delete, "clicked", G_CALLBACK (addr_delete_clicked), priv->addr_list);
g_signal_connect (priv->addr_delete, "clicked", G_CALLBACK (addr_delete_clicked), self);
selection = gtk_tree_view_get_selection (priv->addr_list);
g_signal_connect (selection, "changed", G_CALLBACK (list_selection_changed), priv->addr_delete);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment