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);