Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix control window overwrite issue: #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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