[Gpredict-svn] SF.net SVN: gpredict:[756] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <aa...@us...> - 2011-02-02 17:54:54
|
Revision: 756
http://gpredict.svn.sourceforge.net/gpredict/?rev=756&view=rev
Author: aa1vs
Date: 2011-02-02 17:54:48 +0000 (Wed, 02 Feb 2011)
Log Message:
-----------
Sort Satellites Groups alphabetically in combo box.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/gtk-sat-selector.c
trunk/src/mod-cfg.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-02-02 17:06:24 UTC (rev 755)
+++ trunk/ChangeLog 2011-02-02 17:54:48 UTC (rev 756)
@@ -3,6 +3,9 @@
* src/mod-cfg.c
Sort QTH list alphabetically when configuring module.
+ * src/gtk-sat-selector.c
+ Sort Satellites Groups alphabetically in combo box.
+
2011-02-01 Alexandru Csete <oz9aec at gmail.com>
* src/gtk-rig-ctrl.c:
Modified: trunk/src/gtk-sat-selector.c
===================================================================
--- trunk/src/gtk-sat-selector.c 2011-02-02 17:06:24 UTC (rev 755)
+++ trunk/src/gtk-sat-selector.c 2011-02-02 17:54:48 UTC (rev 756)
@@ -67,6 +67,7 @@
GtkTreeIter *iter,
gpointer column);
+static gint cat_file_compare (const gchar *a, const gchar *b);
static GtkVBoxClass *parent_class = NULL;
@@ -379,12 +380,14 @@
gchar **buffv;
const gchar *fname;
+ gchar *nfname;
guint num = 0;
+ gint i,n;
+ GSList *cats = NULL;
-
/* load all satellites into selector->models[0] */
store = gtk_list_store_new (GTK_SAT_SELECTOR_COL_NUM,
G_TYPE_STRING, // name
@@ -447,11 +450,20 @@
g_dir_rewind (dir);
while ((fname = g_dir_read_name (dir))) {
if (g_str_has_suffix (fname, ".cat")) {
+ cats = g_slist_insert_sorted(cats,g_strdup(fname),(GCompareFunc)cat_file_compare);
+ }
+ }
- load_cat_file (selector, fname);
-
+ /*now load them into the combo box*/
+ n = g_slist_length (cats);
+ for (i = 0; i < n; i++) {
+ nfname = g_slist_nth_data (cats, i);
+ if (nfname) {
+ load_cat_file (selector, nfname);
}
+ g_free(nfname);
}
+ g_slist_free (cats);
g_dir_close (dir);
g_free (dirname);
@@ -806,3 +818,59 @@
return epoch;
}
+
+
+/** \brief Load category name from a .cat file
+ * \param fname The name of the .cat file (name only, no path)
+ * This function is a stripped down version of load_cat_file. It
+ * is needed to load the category name to created a sorted list
+ * of category names. With the existing user base already having
+ * .cat files in their directories, use of the file name directly
+ * for sorting will have problems.
+ */
+static gchar *load_cat_file_cat (const gchar *fname)
+{
+ GIOChannel *catfile;
+ GError *error = NULL;
+
+ gchar *path;
+ gchar *buff;
+
+ /* .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:%s: Failed to open %s: %s"),
+ __FILE__, __FUNCTION__, fname, error->message);
+ g_clear_error (&error);
+ }
+ else {
+ /* read first line => category name */
+
+ if (g_io_channel_read_line (catfile, &buff, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {
+ g_strstrip (buff); /* removes trailing newline */
+ }
+ }
+
+ g_free (path);
+ g_io_channel_shutdown (catfile, TRUE, NULL);
+ return buff;
+}
+
+/* this is a quick function that loads the category name from two cat
+ files and compares them.
+*/
+gint cat_file_compare (const gchar *a,const gchar *b){
+ gchar *cat_a, *cat_b;
+ gint temp;
+
+ cat_a=load_cat_file_cat(a);
+ cat_b=load_cat_file_cat(b);
+ temp = g_ascii_strcasecmp(cat_a,cat_b);
+ g_free (cat_a);
+ g_free (cat_b);
+ return(temp);
+
+}
Modified: trunk/src/mod-cfg.c
===================================================================
--- trunk/src/mod-cfg.c 2011-02-02 17:06:24 UTC (rev 755)
+++ trunk/src/mod-cfg.c 2011-02-02 17:54:48 UTC (rev 756)
@@ -876,7 +876,7 @@
if (g_str_has_suffix (filename, ".qth")) {
buffv = g_strsplit (filename, ".qth", 0);
- qths=g_slist_insert_sorted(qths,g_strdup(buffv[0]),(GCompareFunc) qth_name_compare);
+ qths = g_slist_insert_sorted(qths,g_strdup(buffv[0]),(GCompareFunc) qth_name_compare);
g_strfreev (buffv);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|