[Gpredict-svn] SF.net SVN: gpredict:[149] trunk/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <cs...@us...> - 2008-10-11 21:46:14
|
Revision: 149
http://gpredict.svn.sourceforge.net/gpredict/?rev=149&view=rev
Author: csete
Date: 2008-10-11 21:46:06 +0000 (Sat, 11 Oct 2008)
Log Message:
-----------
Fixed bug 2130912: Crash when no rig or no rotator are defined.
Modified Paths:
--------------
trunk/src/gtk-rig-ctrl.c
trunk/src/gtk-rot-ctrl.c
trunk/src/gtk-sat-module-popup.c
Modified: trunk/src/gtk-rig-ctrl.c
===================================================================
--- trunk/src/gtk-rig-ctrl.c 2008-10-11 21:05:07 UTC (rev 148)
+++ trunk/src/gtk-rig-ctrl.c 2008-10-11 21:46:06 UTC (rev 149)
@@ -85,6 +85,7 @@
static gboolean get_freq (GtkRigCtrl *ctrl, gdouble *freq);
static void update_count_down (GtkRigCtrl *ctrl, gdouble t);
+static gboolean have_conf (void);
static GtkVBoxClass *parent_class = NULL;
@@ -191,6 +192,11 @@
{
GtkWidget *widget;
GtkWidget *table;
+
+ /* check that we have rot conf */
+ if (!have_conf()) {
+ return NULL;
+ }
widget = g_object_new (GTK_TYPE_RIG_CTRL, NULL);
@@ -1084,3 +1090,44 @@
g_free (cs);
}
+
+
+/** \brief Check that we have at least one .rig file */
+static gboolean have_conf ()
+{
+ GDir *dir = NULL; /* directory handle */
+ GError *error = NULL; /* error flag and info */
+ gchar *cfgdir;
+ gchar *dirname; /* directory name */
+ const gchar *filename; /* file name */
+ gint i = 0;
+
+
+ /* open configuration directory */
+ cfgdir = get_conf_dir ();
+ dirname = g_strconcat (cfgdir, G_DIR_SEPARATOR_S,
+ "hwconf", NULL);
+ g_free (cfgdir);
+
+ dir = g_dir_open (dirname, 0, &error);
+ if (dir) {
+ /* read each .rig file */
+ while ((filename = g_dir_read_name (dir))) {
+
+ if (g_strrstr (filename, ".rig")) {
+ i++;
+ }
+ }
+ }
+ else {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%d: Failed to open hwconf dir (%s)"),
+ __FILE__, __LINE__, error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (dirname);
+ g_dir_close (dir);
+
+ return (i > 0) ? TRUE : FALSE;
+}
Modified: trunk/src/gtk-rot-ctrl.c
===================================================================
--- trunk/src/gtk-rot-ctrl.c 2008-10-11 21:05:07 UTC (rev 148)
+++ trunk/src/gtk-rot-ctrl.c 2008-10-11 21:46:06 UTC (rev 149)
@@ -85,6 +85,8 @@
static gboolean get_pos (GtkRotCtrl *ctrl, gdouble *az, gdouble *el);
static gboolean set_pos (GtkRotCtrl *ctrl, gdouble az, gdouble el);
+static gboolean have_conf (void);
+
static GtkVBoxClass *parent_class = NULL;
static GdkColor ColBlack = { 0, 0, 0, 0};
@@ -194,6 +196,11 @@
GtkWidget *widget;
GtkWidget *table;
+ /* check that we have rot conf */
+ if (!have_conf()) {
+ return NULL;
+ }
+
widget = g_object_new (GTK_TYPE_ROT_CTRL, NULL);
/* store satellites */
@@ -490,7 +497,7 @@
dir = g_dir_open (dirname, 0, &error);
if (dir) {
- /* read each .rig file */
+ /* read each .rot file */
while ((filename = g_dir_read_name (dir))) {
if (g_strrstr (filename, ".rot")) {
@@ -1188,3 +1195,44 @@
g_free (cs);
}
+
+
+/** \brief Check that we have at least one .rot file */
+static gboolean have_conf ()
+{
+ GDir *dir = NULL; /* directory handle */
+ GError *error = NULL; /* error flag and info */
+ gchar *cfgdir;
+ gchar *dirname; /* directory name */
+ const gchar *filename; /* file name */
+ gint i = 0;
+
+
+ /* open configuration directory */
+ cfgdir = get_conf_dir ();
+ dirname = g_strconcat (cfgdir, G_DIR_SEPARATOR_S,
+ "hwconf", NULL);
+ g_free (cfgdir);
+
+ dir = g_dir_open (dirname, 0, &error);
+ if (dir) {
+ /* read each .rot file */
+ while ((filename = g_dir_read_name (dir))) {
+
+ if (g_strrstr (filename, ".rot")) {
+ i++;
+ }
+ }
+ }
+ else {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%d: Failed to open hwconf dir (%s)"),
+ __FILE__, __LINE__, error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (dirname);
+ g_dir_close (dir);
+
+ return (i > 0) ? TRUE : FALSE;
+}
Modified: trunk/src/gtk-sat-module-popup.c
===================================================================
--- trunk/src/gtk-sat-module-popup.c 2008-10-11 21:05:07 UTC (rev 148)
+++ trunk/src/gtk-sat-module-popup.c 2008-10-11 21:46:06 UTC (rev 149)
@@ -878,6 +878,23 @@
module->rigctrl = gtk_rig_ctrl_new (module);
+ if (module->rigctrl == NULL) {
+ /* gtk_rot_ctrl_new returned NULL becasue no rotators are configured */
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new (GTK_WINDOW (app),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("You have no radio configuration!\n"\
+ "Please configure a radio first.")
+ );
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), dialog);
+ gtk_window_set_title (GTK_WINDOW (dialog), _("ERROR"));
+ gtk_widget_show_all (dialog);
+
+ return;
+ }
+
/* create a window */
module->rigctrlwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
buff = g_strdup_printf (_("Gpredict Radio Control: %s"), module->name);
@@ -934,6 +951,23 @@
module->rotctrl = gtk_rot_ctrl_new (module);
+ if (module->rotctrl == NULL) {
+ /* gtk_rot_ctrl_new returned NULL becasue no rotators are configured */
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new (GTK_WINDOW (app),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("You have no rotator configuration!\n"\
+ "Please configure an antenna rotator first.")
+ );
+ g_signal_connect_swapped (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), dialog);
+ gtk_window_set_title (GTK_WINDOW (dialog), _("ERROR"));
+ gtk_widget_show_all (dialog);
+
+ return;
+ }
+
/* create a window */
module->rotctrlwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
buff = g_strdup_printf (_("Gpredict Rotator Control: %s"), module->name);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|