Skip to content

Commit

Permalink
Fix control window overwrite issue:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
spsvihla committed Aug 9, 2022
1 parent a0a5636 commit 1b79e0b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mod-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions src/sat-pref-rig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions src/sat-pref-rot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1b79e0b

Please sign in to comment.