[Gpredict-svn] SF.net SVN: gpredict:[423] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <cs...@us...> - 2009-09-23 17:03:00
|
Revision: 423
http://gpredict.svn.sourceforge.net/gpredict/?rev=423&view=rev
Author: csete
Date: 2009-09-23 17:02:51 +0000 (Wed, 23 Sep 2009)
Log Message:
-----------
Implemeted custom sat-activated signal for GtkSatSelector.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/gtk-sat-selector.c
trunk/src/gtk-sat-selector.h
trunk/src/mod-cfg.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-09-18 15:52:41 UTC (rev 422)
+++ trunk/ChangeLog 2009-09-23 17:02:51 UTC (rev 423)
@@ -1,3 +1,14 @@
+2009-09-23 Alexandru Csete <oz9aec at gmail.com>
+
+ * src/gtk-sat-selector.[ch]:
+ Changed EPOCH column type to G_TYPE_DOUBLE (consistent with sat_t).
+ Implemented "sat-activated" signal that is triggered when the user
+ double click on a satellite.
+
+ * src/mod-cfg.c:
+ Connect GtkSatSelector's new "sat-activated" signal to signal handler.
+
+
2009-09-18 Alexandru Csete <oz9aec at gmail.com>
* src/gtk-sat-selector.[ch]:
Modified: trunk/src/gtk-sat-selector.c
===================================================================
--- trunk/src/gtk-sat-selector.c 2009-09-18 15:52:41 UTC (rev 422)
+++ trunk/src/gtk-sat-selector.c 2009-09-23 17:02:51 UTC (rev 423)
@@ -54,6 +54,10 @@
static void create_and_fill_models (GtkSatSelector *selector);
static void load_cat_file (GtkSatSelector *selector, const gchar *fname);
static void group_selected_cb (GtkComboBox *combobox, gpointer data);
+static void row_activated_cb (GtkTreeView *view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer data);
static gint compare_func (GtkTreeModel *model,
GtkTreeIter *a,
@@ -63,6 +67,16 @@
static GtkVBoxClass *parent_class = NULL;
+/** \brief GtkSatSelector signal IDs */
+enum {
+ SAT_ACTIVATED_SIGNAL, /*!< "sat-activated" signal */
+ LAST_SIGNAL
+};
+
+/** \brief GtkSatSelector specific signals. */
+static guint gtksatsel_signals[LAST_SIGNAL] = { 0 };
+
+
GType gtk_sat_selector_get_type ()
{
static GType gtk_sat_selector_type = 0;
@@ -108,6 +122,17 @@
object_class->destroy = gtk_sat_selector_destroy;
+ /* create GtkSatSelector specific signals */
+ gtksatsel_signals[SAT_ACTIVATED_SIGNAL] =
+ g_signal_new ("sat-activated",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkSatSelectorClass,gtksatselector),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
}
@@ -198,7 +223,7 @@
/* we can now connect combobox signal handler */
g_signal_connect (GTK_SAT_SELECTOR (widget)->groups, "changed",
- group_selected_cb, widget);
+ G_CALLBACK(group_selected_cb), widget);
/* create tree view columns */
@@ -229,6 +254,10 @@
if (!(flags & GTK_SAT_SELECTOR_FLAG_EPOCH))
gtk_tree_view_column_set_visible (column, FALSE);
+ /* "row-activated" signal is used to catch double click events, which means
+ a satellite has been selected. This propagates to the TBD GtkSatSelector signal */
+ g_signal_connect (selector->tree, "row-activated",
+ G_CALLBACK(row_activated_cb), selector);
/* scrolled window */
GTK_SAT_SELECTOR (widget)->swin = gtk_scrolled_window_new (NULL, NULL);
@@ -299,7 +328,7 @@
store = gtk_list_store_new (GTK_SAT_SELECTOR_COL_NUM,
G_TYPE_STRING, // name
G_TYPE_INT, // catnum
- G_TYPE_STRING // epoch
+ G_TYPE_DOUBLE // epoch
);
selector->models = g_slist_append (selector->models, store);
gtk_combo_box_append_text (GTK_COMBO_BOX (selector->groups), _("All satellites"));
@@ -368,6 +397,7 @@
}
+
/** \brief Load satellites from a .cat file
* \param selector Pointer to the GtkSatSelector
* \param fname The name of the .cat file (name only, no path)
@@ -522,3 +552,74 @@
g_object_unref (model);
}
+
+
+/** \brief Signal handler for managing satellite selection.
+ * \param view Pointer to the GtkTreeView object.
+ * \param path The path of the row that was activated.
+ * \param column The column where the activation occured.
+ * \param data Pointer to the GtkSatselector widget.
+ *
+ * This function is called when the user double clicks on a satellite in the
+ * satellite selector. It is used to trigger the "sat-activated" signal of
+ * the GtkSatSelector widget.
+ */
+static void row_activated_cb (GtkTreeView *view, GtkTreePath *path,
+ GtkTreeViewColumn *column, gpointer data)
+{
+ GtkSatSelector *selector = GTK_SAT_SELECTOR (data);
+
+ /* emit the "sat-activated" signal for the GtkSatSelector */
+ g_signal_emit (G_OBJECT (selector), gtksatsel_signals[SAT_ACTIVATED_SIGNAL], 0);
+
+}
+
+
+/** \brief Get information about the selected satellite.
+ * \param selector Pointer to the GtkSatSelector widget.
+ * \param catnum Location where catnum will be stored (may be NULL).
+ * \param satname Location where the satellite name will be stored. May NOT be NULL. Must be g_freed after use.
+ * \param epoch Location where the satellite Epoch will be stored (may be NULL);
+ *
+ * This function can be used to retrieve information about the currently selected satellite
+ * a GtkSatSelector widget, e.g. after the "sat-activated" signal has been emitted.
+ */
+void gtk_sat_selector_get_selected (GtkSatSelector *selector,
+ gint *catnum, gchar **satname, gdouble *epoch)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean haveselection = FALSE; /* this flag is set to TRUE if there is a selection */
+ gchar *l_satname; /* nickname of the selected satellite */
+ gint l_catnum; /* catalog number of the selected satellite */
+ gdouble l_epoch; /* TLE epoch of the selected satellite */
+
+ /* selector can not be NULL */
+ g_return_if_fail ((selector != NULL) && (satname != NULL));
+
+ /* get the selected row in the treeview */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->tree));
+ haveselection = gtk_tree_selection_get_selected (selection, &model, &iter);
+
+ if (haveselection) {
+ /* get the name and catalog number of the selected saetllite */
+ gtk_tree_model_get (model, &iter,
+ GTK_SAT_SELECTOR_COL_NAME, &l_satname,
+ GTK_SAT_SELECTOR_COL_CATNUM, &l_catnum,
+ GTK_SAT_SELECTOR_COL_EPOCH, &l_epoch,
+ -1);
+
+ if (catnum != NULL)
+ *catnum = l_catnum;
+
+ *satname = g_strdup (l_satname);
+
+ if (epoch != NULL)
+ *epoch = l_epoch;
+
+ g_free (l_satname);
+ }
+
+}
+
Modified: trunk/src/gtk-sat-selector.h
===================================================================
--- trunk/src/gtk-sat-selector.h 2009-09-18 15:52:41 UTC (rev 422)
+++ trunk/src/gtk-sat-selector.h 2009-09-23 17:02:51 UTC (rev 423)
@@ -11,17 +11,17 @@
More details can be found at the project home page:
http://gpredict.oz9aec.net/
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, visit http://www.fsf.org/
*/
@@ -39,18 +39,18 @@
/** \brief Column definitions in the tree. */
typedef enum {
- GTK_SAT_SELECTOR_COL_NAME = 0, /*!< Satellite name. */
- GTK_SAT_SELECTOR_COL_CATNUM, /*!< Catalogue Number. */
- GTK_SAT_SELECTOR_COL_EPOCH, /*!< Element set epoch. */
- GTK_SAT_SELECTOR_COL_NUM /*!< The number of columns. */
+ GTK_SAT_SELECTOR_COL_NAME = 0, /*!< Satellite name. */
+ GTK_SAT_SELECTOR_COL_CATNUM, /*!< Catalogue Number. */
+ GTK_SAT_SELECTOR_COL_EPOCH, /*!< Element set epoch. */
+ GTK_SAT_SELECTOR_COL_NUM /*!< The number of columns. */
} gtk_sat_selector_col_t;
-
+
/** \brief Flags used to indicate which columns should be visible. */
typedef enum {
- GTK_SAT_SELECTOR_FLAG_NAME = 1 << GTK_SAT_SELECTOR_COL_NAME, /*!< Satellite name. */
- GTK_SAT_SELECTOR_FLAG_CATNUM = 1 << GTK_SAT_SELECTOR_COL_CATNUM, /*!< Catalogue Number. */
- GTK_SAT_SELECTOR_FLAG_EPOCH = 1 << GTK_SAT_SELECTOR_COL_EPOCH, /*!< Element set epoch. */
+ GTK_SAT_SELECTOR_FLAG_NAME = 1 << GTK_SAT_SELECTOR_COL_NAME, /*!< Satellite name. */
+ GTK_SAT_SELECTOR_FLAG_CATNUM = 1 << GTK_SAT_SELECTOR_COL_CATNUM, /*!< Catalogue Number. */
+ GTK_SAT_SELECTOR_FLAG_EPOCH = 1 << GTK_SAT_SELECTOR_COL_EPOCH, /*!< Element set epoch. */
} gtk_sat_selector_flag_t;
@@ -78,29 +78,30 @@
/** \brief The GtkSatSelector Structure definition */
struct _gtk_sat_selector
{
- GtkVBox vbox;
+ GtkVBox vbox;
- GtkWidget *tree; /*!< The tree. */
- GtkWidget *swin; /*!< Scrolled window. */
- guint flags; /*!< Column visibility flags. */
- GSList *selection; /*!< List of selected satellites. FIXME: remove */
- gulong handler_id; /*!< Toggle signale handler ID (FIXME): remove. */
+ GtkWidget *tree; /*!< The tree. */
+ GtkWidget *swin; /*!< Scrolled window. */
+ guint flags; /*!< Column visibility flags. */
+ GSList *selection; /*!< List of selected satellites. FIXME: remove */
+ gulong handler_id; /*!< Toggle signale handler ID (FIXME): remove. */
- GtkWidget *groups; /*!< Combo box for selecting satellite group. */
- GSList *models; /*!< List of models with index corresponding to groups. */
+ GtkWidget *groups; /*!< Combo box for selecting satellite group. */
+ GSList *models; /*!< List of models with index corresponding to groups. */
};
struct _GtkSatSelectorClass
{
- GtkVBoxClass parent_class;
+ GtkVBoxClass parent_class;
+
+ void (* gtksatselector) (GtkSatSelector *sel);
};
GtkType gtk_sat_selector_get_type (void);
GtkWidget *gtk_sat_selector_new (guint flags);
guint32 gtk_sat_selector_get_flags (GtkSatSelector *selector);
-//void gtk_sat_selector_select (GtkSatTree *sat_tree, guint catnum);
-guint *gtk_sat_selector_get_selected (GtkSatSelector *selector, gsize *size);
+void gtk_sat_selector_get_selected (GtkSatSelector *selector, gint *catnum, gchar **satname, gdouble *epoch);
#ifdef __cplusplus
}
Modified: trunk/src/mod-cfg.c
===================================================================
--- trunk/src/mod-cfg.c 2009-09-18 15:52:41 UTC (rev 422)
+++ trunk/src/mod-cfg.c 2009-09-23 17:02:51 UTC (rev 423)
@@ -95,7 +95,9 @@
static void edit_advanced_settings (GtkDialog *parent, GKeyFile *cfgdata);
+static void sat_activated_cb (GtkSatSelector *selector, gpointer data);
+
/** \brief Create a new module.
*
* This function creates a new module. The name of the module is
@@ -246,8 +248,7 @@
* mod_cfg_save function.
*
*/
-mod_cfg_status_t
- mod_cfg_edit (gchar *modname, GKeyFile *cfgdata, GtkWidget *toplevel)
+mod_cfg_status_t mod_cfg_edit (gchar *modname, GKeyFile *cfgdata, GtkWidget *toplevel)
{
GtkWidget *dialog;
gint response;
@@ -449,8 +450,7 @@
-static GtkWidget *
- mod_cfg_editor_create (const gchar *modname, GKeyFile *cfgdata, GtkWidget *toplevel)
+static GtkWidget *mod_cfg_editor_create (const gchar *modname, GKeyFile *cfgdata, GtkWidget *toplevel)
{
GtkWidget *dialog;
GtkWidget *add;
@@ -599,8 +599,13 @@
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), tree, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), gtk_sat_selector_new (0), TRUE, TRUE, 0);
+ /*** EXPERIMENTAL CODE ***/
+ GtkWidget *selector = gtk_sat_selector_new (0);
+ g_signal_connect (selector, "sat-activated",
+ G_CALLBACK (sat_activated_cb), NULL);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), selector, TRUE, TRUE, 0);
+
gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
return dialog;
@@ -935,3 +940,29 @@
/* g_key_file_free (data); */
}
}
+
+
+
+/** \brief Signal handkler for "sat-activated" signals from the GtkSatSelector.
+ * \param selector Pointer to the GtkSatSelector widget.
+ * \param data Pointer to the TBD ...
+ *
+ * This function is called when the user has selected (i.e. double clicked) a satellite
+ * in the GtkSatSelector.
+ */
+static void sat_activated_cb (GtkSatSelector *selector, gpointer data)
+{
+ gchar *satname;
+ gint catnum;
+ gdouble epoch;
+
+ /*** FIXME: Change callback to include catnum into callback (for other uses */
+
+ gtk_sat_selector_get_selected (selector, &catnum, &satname, &epoch);
+
+ g_print ("===> %s (%d) updated at %.4f\n", satname, catnum, epoch);
+
+ /* Add satellite to selected list */
+
+ g_free (satname);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|