From 1b79e0b624312df1b4c51db615c08a001f3f3e79 Mon Sep 17 00:00:00 2001 From: Sean Svihla Date: Thu, 21 Jul 2022 13:45:38 -0600 Subject: [PATCH] Fix control window overwrite issue: - allow sat-pref-rig and sat-pref-rot to access nbook as an extern variable - added functions conf_open_in_rigctrlwin and conf_open_in_rotctrlwin - added dailog boxes displaying when the error occurs - prevent user from editing rig/rot configurations when a control window is open This is in response to an issue where, if the user opens an editor while the respective control window is also open, then the call to the radio/rotor_conf_save function when the control window is closed overwrites changes made in the editor. --- src/mod-mgr.c | 2 +- src/sat-pref-rig.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ src/sat-pref-rot.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/mod-mgr.c b/src/mod-mgr.c index 6e9a8977..cb71d784 100644 --- a/src/mod-mgr.c +++ b/src/mod-mgr.c @@ -71,7 +71,7 @@ static GSList *modules = NULL; /* The notebook widget for docked modules */ -static GtkWidget *nbook = NULL; +GtkWidget *nbook = NULL; static void update_window_title(void); diff --git a/src/sat-pref-rig.c b/src/sat-pref-rig.c index d98d6e1d..17f7ad8f 100644 --- a/src/sat-pref-rig.c +++ b/src/sat-pref-rig.c @@ -31,9 +31,12 @@ #include "sat-pref-rig.h" #include "sat-pref-rig-data.h" #include "sat-pref-rig-editor.h" +#include "gtk-sat-module.h" +#include "gtk-rig-ctrl.h" extern GtkWidget *window; /* dialog window defined in sat-pref.c */ +extern GtkWidget *nbook; /* from mod-mgr.c */ static GtkWidget *addbutton; static GtkWidget *editbutton; static GtkWidget *delbutton; @@ -364,6 +367,35 @@ static void render_signal(GtkTreeViewColumn * col, GtkCellRenderer * renderer, g_object_set(renderer, "text", signal_enabled ? "YES" : "NO", NULL); } +/** + * Returns whether conf has been opened by a radio control window, + * in which case any values saved by the sat-pref-rig-editor will be + * overwritten when the rigctrlwin is closed. + * + * @param radio_conf_t conf - the conf struct in question + * + * @return gboolean - whether conf has been opened in a rigctrlwin + */ +static gboolean conf_open_in_rigctrlwin(radio_conf_t * conf) +{ + gint n, i; + GtkWidget *module; + + n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(nbook)); + for (i = 0; i < n; i++) { + module = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nbook), i); + + if (GTK_SAT_MODULE(module)->rigctrlwin != NULL && + strcmp(GTK_RIG_CTRL(GTK_SAT_MODULE(module)->rigctrl)->conf->name, + conf->name) == 0) { + + return TRUE; + } + } + + return FALSE; +} + /** * Add a new radio configuration * @@ -444,6 +476,25 @@ static void edit_cb(GtkWidget * button, gpointer data) return; } + + if (conf_open_in_rigctrlwin(&conf)) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new(GTK_WINDOW(window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + _("Close Radio Control Window!\n" + "Please close the radio control window\n" + "and attempt again to ensure changes\n" + "are not overwritten.")); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), dialog); + gtk_window_set_title(GTK_WINDOW(dialog), _("WARNING")); + gtk_widget_show_all(dialog); + + return; + } /* run radio configuration editor */ sat_pref_rig_editor_run(&conf); diff --git a/src/sat-pref-rot.c b/src/sat-pref-rot.c index 19db78f5..39725393 100644 --- a/src/sat-pref-rot.c +++ b/src/sat-pref-rot.c @@ -31,9 +31,12 @@ #include "sat-pref-rot.h" #include "sat-pref-rot-data.h" #include "sat-pref-rot-editor.h" +#include "gtk-sat-module.h" +#include "gtk-rot-ctrl.h" extern GtkWidget *window; /* dialog window defined in sat-pref.c */ +extern GtkWidget *nbook; /* from mod-mgr.c */ static GtkWidget *addbutton; static GtkWidget *editbutton; static GtkWidget *delbutton; @@ -87,6 +90,35 @@ static void add_cb(GtkWidget * button, gpointer data) } } +/** + * Returns whether conf has been opened by a rotator control window, + * in which case any values saved by the sat-pref-rot-editor will be + * overwritten when the rotctrlwin is closed. + * + * @param rotor_conf_t conf - the conf struct in question + * + * @return gboolean - whether conf has been opened in a rotctrlwin + */ +static gboolean conf_open_in_rotctrlwin(rotor_conf_t * conf) +{ + gint n, i; + GtkWidget *module; + + n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(nbook)); + for (i = 0; i < n; i++) { + module = gtk_notebook_get_nth_page(GTK_NOTEBOOK(nbook), i); + + if (GTK_SAT_MODULE(module)->rotctrlwin != NULL && + strcmp(GTK_ROT_CTRL(GTK_SAT_MODULE(module)->rotctrl)->conf->name, + conf->name) == 0) { + + return TRUE; + } + } + + return FALSE; +} + static void edit_cb(GtkWidget * button, gpointer data) { GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(rotlist)); @@ -157,6 +189,25 @@ static void edit_cb(GtkWidget * button, gpointer data) return; } + if (conf_open_in_rotctrlwin(&conf)) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new(GTK_WINDOW(window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + _("Close Rotator Control Window!\n" + "Please close the rotator control window\n" + "and attempt again to ensure changes\n" + "are not overwritten.")); + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), dialog); + gtk_window_set_title(GTK_WINDOW(dialog), _("WARNING")); + gtk_widget_show_all(dialog); + + return; + } + /* run radio configuration editor */ sat_pref_rot_editor_run(&conf);