Skip to content

Commit

Permalink
plugins/adrv9009: fix reparent logic
Browse files Browse the repository at this point in the history
get current parent of widget and hide the widget to be reparented
add reference to widget before removing from existing container
remove widget from container
add widget to new container and show widget

Signed-off-by: Cristina Suteu <cristina.suteu@analog.com>
  • Loading branch information
cristina-suteu committed Jan 29, 2024
1 parent 8699c9d commit 51f0e81
Showing 1 changed file with 57 additions and 52 deletions.
109 changes: 57 additions & 52 deletions plugins/adrv9009.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static void multichip_sync()
}

static void update_label_from(GtkWidget *label, struct iio_device *dev, const char *channel,
const char *attribute, bool output, const char *unit, int scale)
const char *attribute, bool output, const char *unit, int scale)
{
char buf[80];
long long val = 0;
Expand Down Expand Up @@ -332,7 +332,7 @@ int load_tal_profile(const char *file_name,

if (!strncmp(file_name, "@FILTERS@/", sizeof("@FILTERS@/") - 1))
path = g_build_filename(OSC_FILTER_FILE_PATH,
file_name + sizeof("@FILTERS@/") - 1, NULL);
file_name + sizeof("@FILTERS@/") - 1, NULL);
else
path = g_strdup(file_name);

Expand Down Expand Up @@ -378,10 +378,10 @@ int load_tal_profile(const char *file_name,
toplevel = NULL;

GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(toplevel),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"\nFailed to load profile using the selected file.");
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"\nFailed to load profile using the selected file.");
gtk_window_set_title(GTK_WINDOW(dialog), "Profile Configuration Failed");

if (gtk_dialog_run(GTK_DIALOG(dialog)))
Expand Down Expand Up @@ -520,7 +520,7 @@ static void rx_freq_info_update(void)

if (cap) {
rx_update_device_sampling_freq(CAP_DEVICE,
USE_INTERN_SAMPLING_FREQ);
USE_INTERN_SAMPLING_FREQ);
lo_freq = mhz_scale * gtk_spin_button_get_value(
GTK_SPIN_BUTTON(subcomponents[0].glb_widgets[subcomponents[0].trx_lo].widget));

Expand Down Expand Up @@ -845,7 +845,7 @@ static void rx_phase_rotation_set(GtkSpinButton *spinbutton, gpointer user_data)

void mcs_sync_button_clicked(GtkButton *btn, gpointer data)
{
multichip_sync();
multichip_sync();
}

/* Check for a valid two channels combination (ch0->ch1, ch2->ch3, ...)
Expand Down Expand Up @@ -893,11 +893,11 @@ static int channel_combination_check(struct iio_device *dev, const char **ch_nam

static void save_widget_value(GtkWidget *widget, struct iio_widget *iio_w)
{
iio_w->save(iio_w);
iio_w->save(iio_w);
}

static void make_widget_update_signal_based(struct iio_widget *widgets,
unsigned int num_widgets)
unsigned int num_widgets)
{
char signal_name[25];
unsigned int i;
Expand All @@ -921,7 +921,7 @@ static void make_widget_update_signal_based(struct iio_widget *widgets,
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]);
&widgets[i]);
}
}
}
Expand All @@ -945,8 +945,8 @@ static int adrv9009_handle_driver(struct osc_plugin *plugin, const char *attrib,
if (MATCH_ATTRIB("load_tal_profile_file")) {
if (value[0]) {
load_tal_profile(value, adrv9009_panel,
GTK_FILE_CHOOSER(profile_config),
last_profile);
GTK_FILE_CHOOSER(profile_config),
last_profile);
}
} else if (MATCH_ATTRIB("ensm_mode")) {
if (!plugin_single_device_mode) {
Expand All @@ -957,36 +957,36 @@ static int adrv9009_handle_driver(struct osc_plugin *plugin, const char *attrib,
dac_data_manager_set_dds_mode(dac_tx_manager, DDS_DEVICE, tx, atoi(value));
} else if (MATCH_ATTRIB("global_settings_show")) {
gtk_toggle_tool_button_set_active(
section_toggle[SECTION_GLOBAL], !!atoi(value));
section_toggle[SECTION_GLOBAL], !!atoi(value));
hide_section_cb(section_toggle[SECTION_GLOBAL],
section_setting[SECTION_GLOBAL]);
section_setting[SECTION_GLOBAL]);
} else if (MATCH_ATTRIB("tx_show")) {
gtk_toggle_tool_button_set_active(
section_toggle[SECTION_TX], !!atoi(value));
section_toggle[SECTION_TX], !!atoi(value));
hide_section_cb(section_toggle[SECTION_TX],
section_setting[SECTION_TX]);
section_setting[SECTION_TX]);
} else if (MATCH_ATTRIB("rx_show")) {
gtk_toggle_tool_button_set_active(
section_toggle[SECTION_RX], !!atoi(value));
section_toggle[SECTION_RX], !!atoi(value));
hide_section_cb(section_toggle[SECTION_RX],
section_setting[SECTION_RX]);
section_setting[SECTION_RX]);
} else if (MATCH_ATTRIB("obs_show")) {
gtk_toggle_tool_button_set_active(
section_toggle[SECTION_OBS], !!atoi(value));
section_toggle[SECTION_OBS], !!atoi(value));
hide_section_cb(section_toggle[SECTION_OBS],
section_setting[SECTION_OBS]);
section_setting[SECTION_OBS]);
} else if (MATCH_ATTRIB("fpga_show")) {
gtk_toggle_tool_button_set_active(
section_toggle[SECTION_FPGA], !!atoi(value));
section_toggle[SECTION_FPGA], !!atoi(value));
hide_section_cb(section_toggle[SECTION_FPGA],
section_setting[SECTION_FPGA]);
section_setting[SECTION_FPGA]);
} else if (!strncmp(attrib, "tx_channel_", sizeof("tx_channel_") - 1)) {
int tx = atoi(attrib + sizeof("tx_channel_") - 1);
dac_data_manager_set_tx_channel_state(
dac_tx_manager, tx, !!atoi(value));
dac_tx_manager, tx, !!atoi(value));
} else if (MATCH_ATTRIB("dac_buf_filename")) {
dac_data_manager_set_buffer_chooser_filename(
dac_tx_manager, value);
dac_tx_manager, value);
} else if (MATCH_ATTRIB("SYNC_RELOAD")) {
if (can_update_widgets)
reload_button_clicked(NULL, NULL);
Expand Down Expand Up @@ -1083,7 +1083,12 @@ void buildTabsInContainer(GtkBox *container_box, enum plugin_section section, bo
if (!gtk_widget_get_parent(content_widget)) {
gtk_box_pack_start(GTK_BOX(page_container), content_widget, FALSE, TRUE, 0);
} else {
gtk_container_add(GTK_CONTAINER(page_container), content_widget);
GtkWidget *parent = gtk_widget_get_parent(GTK_WIDGET(content_widget));
gtk_widget_hide(GTK_WIDGET(content_widget));
g_object_ref(GTK_WIDGET(content_widget));
gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET(content_widget));
gtk_container_add(GTK_CONTAINER(page_container), GTK_WIDGET(content_widget));
gtk_widget_show(GTK_WIDGET(content_widget));
}
}

Expand Down Expand Up @@ -1354,32 +1359,32 @@ static GtkWidget *adrv9009_init(struct osc_plugin *plugin, GtkWidget *notebook,
/* Global settings */

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_rx_qec_en", builder,
"calibrate_rx_qec_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_rx_qec_en", builder,
"calibrate_rx_qec_en", 0);

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_tx_qec_en", builder,
"calibrate_tx_qec_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_tx_qec_en", builder,
"calibrate_tx_qec_en", 0);

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_tx_lol_en", builder,
"calibrate_tx_lol_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_tx_lol_en", builder,
"calibrate_tx_lol_en", 0);

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_tx_lol_ext_en", builder,
"calibrate_tx_lol_ext_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_tx_lol_ext_en", builder,
"calibrate_tx_lol_ext_en", 0);

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_rx_phase_correction_en", builder,
"calibrate_rx_phase_correction_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_rx_phase_correction_en", builder,
"calibrate_rx_phase_correction_en", 0);

iio_toggle_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate_fhm_en", builder,
"calibrate_fhm_en", 0);
subcomponents[i].iio_dev, NULL, "calibrate_fhm_en", builder,
"calibrate_fhm_en", 0);

iio_button_init_from_builder(&subcomponents[i].glb_widgets[subcomponents[i].num_glb++],
subcomponents[i].iio_dev, NULL, "calibrate", builder,
"calibrate");
subcomponents[i].iio_dev, NULL, "calibrate", builder,
"calibrate");

subcomponents[i].trx_lo = subcomponents[i].num_glb;

Expand Down Expand Up @@ -1593,40 +1598,40 @@ static GtkWidget *adrv9009_init(struct osc_plugin *plugin, GtkWidget *notebook,
/* Connect signals */

g_builder_connect_signal(builder, "rx1_phase_rotation", "value-changed",
G_CALLBACK(rx_phase_rotation_set), (gpointer *)0);
G_CALLBACK(rx_phase_rotation_set), (gpointer *)0);

g_builder_connect_signal(builder, "rx2_phase_rotation", "value-changed",
G_CALLBACK(rx_phase_rotation_set), (gpointer *)2);
G_CALLBACK(rx_phase_rotation_set), (gpointer *)2);

g_builder_connect_signal(builder, "sampling_freq_tx", "value-changed",
G_CALLBACK(tx_sample_rate_changed), NULL);
G_CALLBACK(tx_sample_rate_changed), NULL);

g_builder_connect_signal(builder, "adrv9009_settings_reload", "clicked",
G_CALLBACK(reload_button_clicked), NULL);
G_CALLBACK(reload_button_clicked), NULL);

g_builder_connect_signal(builder, "mcs_sync", "clicked",
G_CALLBACK(mcs_sync_button_clicked), NULL);
G_CALLBACK(mcs_sync_button_clicked), NULL);

g_builder_connect_signal(builder, "profile_config", "file-set",
G_CALLBACK(profile_config_file_set_cb), NULL);
G_CALLBACK(profile_config_file_set_cb), NULL);

g_signal_connect_after(section_toggle[SECTION_GLOBAL], "clicked",
G_CALLBACK(hide_section_cb), section_setting[SECTION_GLOBAL]);
G_CALLBACK(hide_section_cb), section_setting[SECTION_GLOBAL]);

g_signal_connect_after(section_toggle[SECTION_TX], "clicked",
G_CALLBACK(hide_section_cb), section_setting[SECTION_TX]);
G_CALLBACK(hide_section_cb), section_setting[SECTION_TX]);

g_signal_connect_after(section_toggle[SECTION_RX], "clicked",
G_CALLBACK(hide_section_cb), section_setting[SECTION_RX]);
G_CALLBACK(hide_section_cb), section_setting[SECTION_RX]);

g_signal_connect_after(section_toggle[SECTION_OBS], "clicked",
G_CALLBACK(hide_section_cb), section_setting[SECTION_OBS]);
G_CALLBACK(hide_section_cb), section_setting[SECTION_OBS]);

g_signal_connect_after(section_toggle[SECTION_FPGA], "clicked",
G_CALLBACK(hide_section_cb), section_setting[SECTION_FPGA]);
G_CALLBACK(hide_section_cb), section_setting[SECTION_FPGA]);

g_signal_connect_after(ensm_mode_available, "changed",
G_CALLBACK(on_ensm_mode_available_changed), NULL);
G_CALLBACK(on_ensm_mode_available_changed), NULL);

g_signal_connect_after(fpga_rx_frequency_available, "changed",
G_CALLBACK(int_dec_update_cb), NULL);
Expand Down

0 comments on commit 51f0e81

Please sign in to comment.