First of all, GtkTable is deprecated in Gtk3, so you should use a GtkGrid instead.
Second, you don’t really need to store those widgets in an array, so simply iterating through the values list and create two buttons in each steps is a bit better approach:
GtkWidget *ip_button,
*status_button;
gchar *values[] = {
"127.0.0.1", "Idle",
"192.168.73.129", "Idle",
"192.168.73.130", "Idle",
"192.168.73.131", "Idle",
"192.168.73.132", "Idle",
"192.168.73.129", "Idle",
"192.168.73.131", "Idle",
};
for (i = 0; i < value_count; i += 2) {
ip_button = gtk_button_new_with_label(values[i]);
gtk_grid_attach(grid, button, i, 0, 1, 1);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(ip_button_callback), NULL);
status_button = gtk_button_new_with_label(values[i + 1]);
gtk_grid_attach(grid, button, i, 1, 1, 1);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(status_button_callback), ip_button);
}
In the ip_button_callback()
function you can use gtk_button_get_label()
to get the IP address associated with the button, while in status_button_callback()
you can get the label of the button passed as user_param
.
A much elegant solution may be to store these buttons in a GHashTable using the IP addresses as table keys, but that takes a bit more thinking on the design (and needs a lot more background information).