[Gpredict-svn] SF.net SVN: gpredict:[422] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <cs...@us...> - 2009-09-18 15:52:51
|
Revision: 422
http://gpredict.svn.sourceforge.net/gpredict/?rev=422&view=rev
Author: csete
Date: 2009-09-18 15:52:41 +0000 (Fri, 18 Sep 2009)
Log Message:
-----------
Implemented group selector.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/gtk-sat-selector.c
trunk/src/gtk-sat-selector.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-08-23 16:34:15 UTC (rev 421)
+++ trunk/ChangeLog 2009-09-18 15:52:41 UTC (rev 422)
@@ -1,3 +1,9 @@
+2009-09-18 Alexandru Csete <oz9aec at gmail.com>
+
+ * src/gtk-sat-selector.[ch]:
+ Implemented satellite group selector.
+
+
2009-08-23 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-08-23 16:34:15 UTC (rev 421)
+++ trunk/src/gtk-sat-selector.c 2009-09-18 15:52:41 UTC (rev 422)
@@ -52,6 +52,8 @@
static void gtk_sat_selector_destroy (GtkObject *object);
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 gint compare_func (GtkTreeModel *model,
GtkTreeIter *a,
@@ -167,6 +169,15 @@
selector->flags = flags;
+ /* create group selector combo box (needed by create_and_fill_models()) */
+ GTK_SAT_SELECTOR (widget)->groups = gtk_combo_box_new_text ();
+ gtk_widget_set_tooltip_text (GTK_SAT_SELECTOR (widget)->groups,
+ _("Select a satellite group or category to narrow your search."));
+
+ /* combo box signal handler will be connected at the end after it has
+ been populated to avoid false triggering */
+
+
/* create list and model */
selector->tree = gtk_tree_view_new ();
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (selector->tree), TRUE);
@@ -185,6 +196,11 @@
GTK_SAT_SELECTOR_COL_NAME,
GTK_SORT_ASCENDING);
+ /* we can now connect combobox signal handler */
+ g_signal_connect (GTK_SAT_SELECTOR (widget)->groups, "changed",
+ group_selected_cb, widget);
+
+
/* create tree view columns */
/* label column */
renderer = gtk_cell_renderer_text_new ();
@@ -219,10 +235,13 @@
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (GTK_SAT_SELECTOR (widget)->swin),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+
gtk_container_add (GTK_CONTAINER (GTK_SAT_SELECTOR (widget)->swin),
GTK_SAT_SELECTOR (widget)->tree);
+
//gtk_container_add (GTK_CONTAINER (widget), GTK_SAT_TREE (widget)->swin);
+ gtk_box_pack_start (GTK_BOX (widget), GTK_SAT_SELECTOR (widget)->groups, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (widget), GTK_SAT_SELECTOR (widget)->swin, TRUE, TRUE, 0);
@@ -238,17 +257,35 @@
-/** FIXME: flags not needed here */
+/** \brief Create and fill data store models.
+ * \param selector Pointer to the GtkSatSelector widget
+ *
+ * this fuinction scan for satellite data and stores them in tree models
+ * that can be displayed in a tree view. The scan is performed in two iterations:
+ *
+ * (1) First, all .sat files are scanned, read and added to a pseudo-group called
+ * "all" satellites.
+ * (2) After the first scane, the function scans and reads .cat files and creates
+ * the groups accordingly.
+ *
+ * For each group (including the "all" group) and entry is added to the
+ * selector->groups GtkComboBox, where the index of the entry corresponds to
+ * the index of the group model in selector->models.
+ */
static void create_and_fill_models (GtkSatSelector *selector)
{
GtkListStore *store; /* the list store data structure */
GtkTreeIter node; /* new top level node added to the tree store */
GDir *dir;
+ GIOChannel *catfile;
+ GIOStatus status;
+ GError *error = NULL;
gchar *dirname;
sat_t sat;
gint catnum;
gchar *path;
+ gchar *buff;
gchar *nodename;
gchar **buffv;
const gchar *fname;
@@ -265,6 +302,8 @@
G_TYPE_STRING // epoch
);
selector->models = g_slist_append (selector->models, store);
+ gtk_combo_box_append_text (GTK_COMBO_BOX (selector->groups), _("All satellites"));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (selector->groups), 0);
dirname = get_satdata_dir ();
dir = g_dir_open (dirname, 0, NULL);
@@ -278,7 +317,7 @@
return;
}
- /* Scan data directory for .tle files.
+ /* Scan data directory for .sat files.
For each file scan through the file and
add entry to the tree.
*/
@@ -318,95 +357,117 @@
while ((fname = g_dir_read_name (dir))) {
if (g_strrstr (fname, ".cat")) {
+ load_cat_file (selector, fname);
+
}
}
g_dir_close (dir);
g_free (dirname);
+}
-#if 0
- /* create a new tree store */
- store = gtk_tree_store_new (GTK_SAT_SELECTOR_COL_NUM,
- G_TYPE_STRING, // name
- G_TYPE_INT, // catnum
- G_TYPE_STRING // epoch
- );
+/** \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)
+ *
+ * This function is used to encapsulate reading the clear text name and the contents
+ * of a .cat file. It is used for building the satellite tree store models
+ */
+static void load_cat_file (GtkSatSelector *selector, const gchar *fname)
+{
+ GIOChannel *catfile;
+ GError *error = NULL;
+ GtkListStore *store; /* the list store data structure */
+ GtkTreeIter node; /* new top level node added to the tree store */
- dirname = g_strconcat (g_get_home_dir (),
- G_DIR_SEPARATOR_S, ".gpredict2",
- G_DIR_SEPARATOR_S, "tle",
- NULL);
+ gchar *path;
+ gchar *buff;
+ sat_t sat;
+ gint catnum;
+ guint num = 0;
- /* debug message */
- sat_log_log (SAT_LOG_LEVEL_DEBUG,
- _("%s:%d: Directory is: %s"),
- __FILE__, __LINE__, dirname);
-
- dir = g_dir_open (dirname, 0, NULL);
-
- /* no tle files */
- if (!dir) {
+ /* .cat files contains clear text category name in the first line
+ then one satellite catalog number per line */
+ path = sat_file_name (fname);
+ catfile = g_io_channel_new_file (path, "r", &error);
+ if (error != NULL) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%d: No .tle files found in %s."),
- __FILE__, __LINE__, dirname);
+ _("%s:%s: Failed to open %s: %s"),
+ __FILE__, __FUNCTION__, fname, error->message);
+ g_clear_error (&error);
+ }
+ else {
+ /* read first line => category name */
- g_free (dirname);
+ if (g_io_channel_read_line (catfile, &buff, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {
+ g_strstrip (buff); /* removes trailing newline */
+ gtk_combo_box_append_text (GTK_COMBO_BOX (selector->groups), buff);
+ g_free (buff);
- return GTK_TREE_MODEL (store);;
- }
+ /* we can safely create the liststore for this category */
+ store = gtk_list_store_new (GTK_SAT_SELECTOR_COL_NUM,
+ G_TYPE_STRING, // name
+ G_TYPE_INT, // catnum
+ G_TYPE_STRING // epoch
+ );
+ selector->models = g_slist_append (selector->models, store);
- /* Scan data directory for .tle files.
- For each file scan through the file and
- add entry to the tree.
- */
- while ((fname = g_dir_read_name (dir))) {
- if (g_strrstr (fname, ".tle")) {
- buffv = g_strsplit (fname, ".tle", 0);
- nodename = g_strdup (buffv[0]);
- nodename[0] = g_ascii_toupper (nodename[0]);
+ /* Remaining lines are catalog numbers for satellites.
+ Read line by line until the first error, which hopefully is G_IO_STATUS_EOF
+ */
+ while (g_io_channel_read_line (catfile, &buff, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {
- /* create a new top level node in the tree */
- gtk_tree_store_append (store, &node, NULL);
- gtk_tree_store_set (store, &node,
- GTK_SAT_SELECTOR_COL_NAME, nodename,
- -1);
+ /* stip trailing EOL */
+ g_strstrip (buff);
- /* build full path til file and sweep it for sats */
- path = g_strconcat (dirname, G_DIR_SEPARATOR_S,
- fname, NULL);
+ /* catalog number to integer */
+ catnum = (gint) g_ascii_strtoll (buff, NULL, 0);
- num = scan_tle_file (path, store, &node);
+ /* try to read satellite data */
+ if (gtk_sat_data_read_sat (catnum, &sat)) {
+ /* error */
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%s: Error reading satellite %d."),
+ __FILE__, __FUNCTION__, catnum);
+ }
+ else {
+ /* insert satellite into liststore */
+ gtk_list_store_append (store, &node);
+ gtk_list_store_set (store, &node,
+ GTK_SAT_SELECTOR_COL_NAME, sat.nickname,
+ GTK_SAT_SELECTOR_COL_CATNUM, catnum,
+ -1);
+ g_free (sat.name);
+ g_free (sat.nickname);
+ num++;
+ }
- g_free (path);
- g_free (nodename);
- g_strfreev (buffv);
-
+ g_free (buff);
+ }
sat_log_log (SAT_LOG_LEVEL_MSG,
- _("%s:%d: Read %d sats from %s "),
- __FILE__, __LINE__, num, fname);
+ _("%s:%s: Read %d satellites from %s"),
+ __FILE__, __FUNCTION__, num, fname);
}
+ else {
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%s: Failed to read %s"),
+ __FILE__, __FUNCTION__, fname);
+ }
}
- g_dir_close (dir);
- g_free (dirname);
-#endif
-
-
+ g_free (path);
+ g_io_channel_shutdown (catfile, TRUE, NULL);
}
-
-
-
-
/** \brief Compare two rows of the GtkSatSelector.
* \param model The tree model of the GtkSatSelector.
* \param a The first row.
@@ -437,3 +498,27 @@
return ret;
}
+
+/** \brief Signal handler for managing satellite group selections.
+ * \param combobox The GtkcomboBox widget.
+ * \param data Pointer to the GtkSatSelector widget.
+ *
+ * This function is called when the user selects a new satellite group in the
+ * filter. The function is responsible for reloading the conctents of the satellite
+ * list according to the new selection. This task is very simple because the
+ * proper liststore has already been constructed and stored in selector->models[i]
+ * where i corresponds to the index of the newly selected group in the combo box.
+ */
+static void group_selected_cb (GtkComboBox *combobox, gpointer data)
+{
+ GtkSatSelector *selector = GTK_SAT_SELECTOR (data);
+ GtkTreeModel *model;
+ gint sel;
+
+ sel = gtk_combo_box_get_active (combobox);
+
+ model = GTK_TREE_MODEL (g_slist_nth_data (selector->models, sel));
+ gtk_tree_view_set_model (GTK_TREE_VIEW (selector->tree), model);
+ g_object_unref (model);
+
+}
Modified: trunk/src/gtk-sat-selector.h
===================================================================
--- trunk/src/gtk-sat-selector.h 2009-08-23 16:34:15 UTC (rev 421)
+++ trunk/src/gtk-sat-selector.h 2009-09-18 15:52:41 UTC (rev 422)
@@ -86,7 +86,8 @@
GSList *selection; /*!< List of selected satellites. FIXME: remove */
gulong handler_id; /*!< Toggle signale handler ID (FIXME): remove. */
- GSList *models;
+ GtkWidget *groups; /*!< Combo box for selecting satellite group. */
+ GSList *models; /*!< List of models with index corresponding to groups. */
};
struct _GtkSatSelectorClass
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|