static void make_widget_update_signal_based(struct iio_widget *widgets,
	unsigned int num_widgets)
{
	char signal_name[25];
	unsigned int i;

	for (i = 0; i < num_widgets; i++) {
		if (GTK_IS_CHECK_BUTTON(widgets[i].widget))
			sprintf(signal_name, "%s", "toggled");
		else if (GTK_IS_TOGGLE_BUTTON(widgets[i].widget))
			sprintf(signal_name, "%s", "toggled");
		else if (GTK_IS_SPIN_BUTTON(widgets[i].widget))
			sprintf(signal_name, "%s", "value-changed");
		else if (GTK_IS_COMBO_BOX_TEXT(widgets[i].widget))
			sprintf(signal_name, "%s", "changed");
		else
			printf("unhandled widget type, attribute: %s\n", widgets[i].attr_name);

		if (GTK_IS_SPIN_BUTTON(widgets[i].widget) &&
			widgets[i].priv_progress != NULL) {
				iio_spin_button_progress_activate(&widgets[i]);
		} else {
			g_signal_connect(G_OBJECT(widgets[i].widget), signal_name, G_CALLBACK(save_widget_value), &widgets[i]);
		}
	}
}
Esempio n. 2
0
static void up_down_converter_toggled_cb(GtkToggleButton *button, gpointer data)
{
	static gint rx_updn_hid, tx_updn_hid;
	static gdouble lo_min, lo_max;
	static void (*rx_lo_update_value)(struct iio_widget *, const char *, size_t);
	static void (*tx_lo_update_value)(struct iio_widget *, const char *, size_t);

	if (gtk_toggle_button_get_active(button)) {
		iio_spin_button_progress_deactivate(&rx_widgets[rx_lo]);
		iio_spin_button_progress_deactivate(&tx_widgets[tx_lo]);
		rx_updn_hid = g_signal_connect(rx_widgets[rx_lo].widget, "value-changed",
			G_CALLBACK(updn_converter_lo_freq_changed_cb), (gpointer)UPDN_RX);
		tx_updn_hid = g_signal_connect(tx_widgets[tx_lo].widget, "value-changed",
			G_CALLBACK(updn_converter_lo_freq_changed_cb), (gpointer)UPDN_TX);
		gtk_spin_button_get_range(GTK_SPIN_BUTTON(rx_widgets[rx_lo].widget), &lo_min, &lo_max);
		gtk_spin_button_set_range(GTK_SPIN_BUTTON(rx_widgets[rx_lo].widget), 1, 100);
		gtk_spin_button_set_range(GTK_SPIN_BUTTON(tx_widgets[tx_lo].widget), 1, 100);
		rx_lo_update_value = rx_widgets[rx_lo].update_value;
		tx_lo_update_value = tx_widgets[tx_lo].update_value;
		rx_widgets[rx_lo].update_value = NULL;
		tx_widgets[tx_lo].update_value = NULL;
	} else {
		g_signal_handler_disconnect(rx_widgets[rx_lo].widget, rx_updn_hid);
		g_signal_handler_disconnect(tx_widgets[tx_lo].widget, tx_updn_hid);
		rx_widgets[rx_lo].update_value = rx_lo_update_value;
		tx_widgets[tx_lo].update_value = tx_lo_update_value;
		iio_spin_button_progress_activate(&rx_widgets[rx_lo]);
		iio_spin_button_progress_activate(&tx_widgets[tx_lo]);
		g_signal_emit_by_name(rx_widgets[rx_lo].widget,
			"value-changed", NULL);
		g_signal_emit_by_name(tx_widgets[tx_lo].widget,
			"value-changed", NULL);
		gtk_spin_button_set_range(GTK_SPIN_BUTTON(rx_widgets[rx_lo].widget), lo_min, lo_max);
		gtk_spin_button_set_range(GTK_SPIN_BUTTON(tx_widgets[tx_lo].widget), lo_min, lo_max);
	}
}