From: Alexandru C. <cs...@us...> - 2002-11-28 20:15:00
|
Update of /cvsroot/groundstation/gpredict/src In directory sc8-pr-cvs1:/tmp/cvs-serv18084 Modified Files: sattree.c Log Message: Added function to recursively load a set of local and web file systems. The local stuff is all right but the web loader is still missing. Index: sattree.c =================================================================== RCS file: /cvsroot/groundstation/gpredict/src/sattree.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sattree.c 27 Nov 2002 23:13:19 -0000 1.4 --- sattree.c 28 Nov 2002 20:14:54 -0000 1.5 *************** *** 40,45 **** #include "sattree.h" - - #ifdef HAVE_CONFIG_H # include <config.h> --- 40,43 ---- *************** *** 49,258 **** extern GtkWidget *app; ! #define TREE_ROWS 3 ! ! static gchar *tree_titles[TREE_ROWS] = { ! N_("Satellite"), N_("Catnum"), N_("Updated") }; GtkWidget * ! sattree_load_dir (const gchar *dir, const gchar *filter) { ! /* This function loads the NASA 2-line TLE files from ! the specified directory and arranges them into a ! GtkCTree. If filter is NULL, the directory will be ! read using *. The catalog number of each satellite ! is attached to the row, in which the satellite is ! listed. */ GtkWidget *tree; GnomeVFSResult result; GnomeVFSDirectoryFilter *vfsfilter; GnomeVFSFileInfo *fileinfo; ! FILE *satfile = NULL; ! gchar *msg,*path,*uri,**file; GList *list,*node; - gint i,x; gchar *text,**vbuf; ! g_return_val_if_fail (dir, NULL); /* create gnome_vfs_uri */ ! uri = gnome_vfs_get_uri_from_local_path (dir); /* create a filter and load the directory */ vfsfilter = gnome_vfs_directory_filter_new (GNOME_VFS_DIRECTORY_FILTER_SHELLPATTERN, - GNOME_VFS_DIRECTORY_FILTER_NODIRS | GNOME_VFS_DIRECTORY_FILTER_NODOTFILES | - GNOME_VFS_DIRECTORY_FILTER_EXTENDEDREGEXP | GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR | GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES, ! filter ? filter : "*"); ! result = gnome_vfs_directory_list_load (&list, uri, GNOME_VFS_FILE_INFO_DEFAULT, vfsfilter); /* free some memory */ ! g_free (uri); gnome_vfs_directory_filter_destroy (vfsfilter); if (result == GNOME_VFS_OK) { - GdkPixmap *dop,*dcp; - GdkBitmap *dob,*dcb; - GtkCTreeNode *treenode,*satnode; - gchar catnum_s[6],*entry,*epoch_s; - guint catnum,j,epochyear, epochday; - GDate *epoch; /* make a log message */ ! msg = g_strconcat (__FUNCTION__, _(": get dir-list: GNOME_VFS_OK"), NULL); satlog_log (SAT_LOG_DEBUG, msg); g_free (msg); - /* Create pixmaps and bitmaps */ - dop = gdk_pixmap_create_from_xpm (app->window, &dob, 0, - "../pixmaps/icons/directory-open.xpm"); - dcp = gdk_pixmap_create_from_xpm (app->window, &dcb, 0, - "../pixmaps/icons/directory-closed.xpm"); - - /* Create the tree */ - tree = gtk_ctree_new_with_titles (TREE_ROWS, 0, tree_titles); - gtk_ctree_set_line_style (GTK_CTREE (tree), GTK_CTREE_LINES_DOTTED); - gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_MULTIPLE); - for (i=0; i<TREE_ROWS; i++) - gtk_clist_set_column_auto_resize (GTK_CLIST (tree), i, TRUE); - /* loop throough the file list */ for (node = list; node != NULL; node = node->next) { - fileinfo = node->data; /* fileinfo->name contains filename */ ! /* Add TLE file to tree */ ! text = g_strconcat (fileinfo->name, "<!SEP>", "", "<!SEP>", "", NULL); ! file = g_strsplit (text, "<!SEP>", TREE_ROWS); ! g_free (text); ! treenode = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, file, 2, ! dcp, dcb, dop, dob, ! FALSE, FALSE); ! ! /* We could disable selection here, but will try to implement ! "click-on-file-to-select-all-sats" instead. ! */ ! ! /* read satellites into tree */ ! path = g_strconcat (dir, G_DIR_SEPARATOR_S, fileinfo->name, NULL); ! ! /* open TLE file */ ! satfile = fopen (path, "r"); ! if (satfile) { ! gchar name[80],line1[80],line2[80]; ! ! i = 0; ! /* avoid reading the last sat twice */ ! fgets (name, 75, satfile); ! while (!feof (satfile)) { ! /* read lines */ ! fgets (line1, 75, satfile); ! fgets (line2, 75, satfile); ! /* fix satname */ ! x = strlen (name); ! while ( name[x]==32 || name[x]==0 || name[x]==10 || name[x]==13 ) { ! name[x] = 0; ! x--; ! } ! ! /* extract catalog number */ ! for (j=0; j<6; j++) ! catnum_s[j] = line1[j+2]; ! catnum_s[5] = 0; ! catnum = (guint) g_strtod (catnum_s, NULL); ! ! /* EPOCH */ ! epochyear = (guint) g_strtod (SubString (line1, 18, 19), NULL); ! epochday = (guint) g_strtod (SubString (line1, 20, 31), NULL); ! epoch = g_date_new_dmy (1, 1, 2000 + epochyear); ! g_date_add_days (epoch, epochday); ! epoch_s = g_malloc (50); ! g_date_strftime (epoch_s, 50, "%e %b %Y", epoch); ! ! /* add satelite to the tree */ ! entry = g_strconcat (name, ! "<!SEP>", catnum_s, ! "<!SEP>", epoch_s, ! NULL); ! vbuf = g_strsplit (entry, "<!SEP>", TREE_ROWS); ! satnode = gtk_ctree_insert_node (GTK_CTREE (tree), ! treenode, NULL, ! vbuf, 5, ! NULL, NULL, NULL, NULL, ! TRUE, FALSE); ! /* attach catalog number; this will provide the same functionality ! as the flat list (pre-0.4). ! */ ! gtk_ctree_node_set_row_data (GTK_CTREE (tree), satnode, ! GUINT_TO_POINTER (catnum)); ! g_free (epoch_s); ! g_date_free (epoch); ! g_free (entry); ! g_strfreev (vbuf); ! i++; ! fgets (name, 75, satfile); ! } ! fclose (satfile); ! text = g_strdup_printf ("%s: read %d satelites from %s", ! __FUNCTION__, i, fileinfo->name); ! satlog_log (SAT_LOG_INFO, text); ! g_free (text); ! } ! else { ! msg = g_strconcat (__FUNCTION__, _(": could not open file"), path, NULL); ! satlog_log (SAT_LOG_WARNING, msg); ! g_free (msg); } - /* free string */ g_free (path); } /* free memory taken up by file list */ gnome_vfs_file_info_list_free (list); - - return tree; } - else { - msg = g_strconcat (__FUNCTION__, _(": get dir-list != GNOME_VFS_OK"), NULL); - satlog_log (SAT_LOG_CRITICAL, msg); - g_free (msg); - return NULL; - } - - } - - - GtkWidget * - sattree_load_url (const gchar *url, const gchar *filter) - { - /* This function loads the NASA 2-line TLE files from - the specified URL and arranges them into a - GtkCTree. If filter is NULL, the directory will be - read using *. The catalog number of each satellite - is attached to the row, in which the satellite is - listed. - */ - GtkWidget *tree; - GnomeVFSResult result; - GnomeVFSDirectoryFilter *vfsfilter; - GnomeVFSFileInfo *fileinfo; - FILE *satfile = NULL; - gchar *msg,*path,**file; - GList *list,*node; - gint i,x; - gchar *text,**vbuf; ! g_return_val_if_fail (url, NULL); /* create gnome_vfs_uri */ ! // uri = gnome_vfs_get_uri_from_local_path (dir); /* create a filter and load the directory */ --- 47,283 ---- extern GtkWidget *app; ! #define TREE_COLS 3 ! static gchar *tree_titles[TREE_COLS] = { ! N_("File/Satellite"), N_("Catnum"), N_("Updated") }; + + /* Private function prototypes */ + static void sattree_add_local_uri (GtkWidget *tree, GtkCTreeNode *parent, + const gchar *uri, const gchar *filter, + gboolean readfiles); + + static void sattree_add_local_file (GtkWidget *tree, GtkCTreeNode *parent, + gchar *file); + + static void sattree_add_web_uri (GtkCTree *tree, GtkCTreeNode *parent, + const gchar *uri, const gchar *filter, + gboolean readfiles); + + static void sattree_select_row_cb (GtkCTree *tree, GtkCTreeNode *node, + gint column, gpointer data); + + static void sattree_unselect_row_cb (GtkCTree *tree, GtkCTreeNode *node, + gint column, gpointer data); + + GtkWidget * ! sattree_load_uris_recursive (gchar **dir, gchar **web, ! const gchar *filter, ! gboolean readfiles) { ! /* This function loads the NORAD 2-line TLE files from the specified ! directories, either on the local file system (listed in locals) or ! from the web (listed in web), and arranges them into a GtkCTree. ! The directories are read using the 'filter' pattern. If filter NULL, ! directories will be read using "*". Subdirectories are listed using ! "*" pattern regardless of what 'filter' is. ! The catalog number of each satellite is attached to the row, in which ! the satellite is. */ GtkWidget *tree; + GtkCTreeNode *localnode,*webnode,*thisdir; + GdkPixmap *pixm; + GdkBitmap *bitm; + guint i; + gchar *buff,**vbuff; + GdkPixmap *pixopen,*pixclosed; + GdkBitmap *bitopen,*bitclosed; + + /* We need either some local or some web folders */ + g_return_val_if_fail (dir || web, NULL); + + /* Create directory pixmaps and bitmaps */ + pixopen = gdk_pixmap_create_from_xpm (app->window, &bitopen, 0, + "../pixmaps/icons/gpredict-dir-open.xpm"); + pixclosed = gdk_pixmap_create_from_xpm (app->window, &bitclosed, 0, + "../pixmaps/icons/gpredict-dir-closed.xpm"); + + /* Create a tree and add two ROOT nodes (Local Files and Network) */ + tree = gtk_ctree_new_with_titles (TREE_COLS, 0, tree_titles); + gtk_ctree_set_line_style (GTK_CTREE (tree), GTK_CTREE_LINES_DOTTED); + gtk_ctree_set_spacing (GTK_CTREE (tree), 5); + gtk_ctree_set_indent (GTK_CTREE (tree), 18); + gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_MULTIPLE); + /* adjust column width automatically */ + for (i=0; i<TREE_COLS; i++) + gtk_clist_set_column_auto_resize (GTK_CLIST (tree), i, TRUE); + /* connect signals */ + gtk_signal_connect (GTK_OBJECT (tree), "tree-select-row", + GTK_SIGNAL_FUNC (sattree_select_row_cb), NULL); + gtk_signal_connect (GTK_OBJECT (tree), "tree-unselect-row", + GTK_SIGNAL_FUNC (sattree_unselect_row_cb), NULL); + + + + /* Local node */ + pixm = gdk_pixmap_create_from_xpm (app->window, &bitm, 0, + "../pixmaps/icons/gpredict-disk-16.xpm"); + buff = g_strconcat (_("Local Folders"), "<!SEP> <!SEP> ", NULL); + vbuff = g_strsplit (buff, "<!SEP>", TREE_COLS); + localnode = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, vbuff, 5, + pixm, bitm, pixm, bitm, + FALSE, FALSE); + g_free (buff); + g_strfreev (vbuff); + + /* add directories recursively */ + if (dir) { + for (i=0; dir[i]; i++) { + /* add the directory node to the tree */ + buff = g_strconcat (dir[i], "<!SEP> <!SEP> ", NULL); + vbuff = g_strsplit (buff, "<!SEP>", TREE_COLS); + g_free (buff); + thisdir = gtk_ctree_insert_node (GTK_CTREE (tree), localnode, NULL, vbuff, 5, + pixclosed, bitclosed, pixopen, bitopen, + FALSE, FALSE); + g_strfreev (vbuff); + + /* don't let users select whole directories */ + gtk_ctree_node_set_selectable (GTK_CTREE (tree), thisdir, FALSE); + + /* load the contents into the tree */ + sattree_add_local_uri (tree, thisdir, dir[i], filter, readfiles); + } + } + + /* Network node */ + pixm = gdk_pixmap_create_from_xpm (app->window, &bitm, 0, + "../pixmaps/icons/gpredict-globe-16.xpm"); + buff = g_strconcat (_("Web Folders"), "<!SEP> <!SEP> ", NULL); + vbuff = g_strsplit (buff, "<!SEP>", TREE_COLS); + webnode = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, vbuff, 5, + pixm, bitm, pixm, bitm, + FALSE, FALSE); + g_free (buff); + g_strfreev (vbuff); + + if (web) { + for (i=0; web[i]; i++) { + /* add the directory node to the tree */ + buff = g_strconcat (web[i], "<!SEP> <!SEP> ", NULL); + vbuff = g_strsplit (buff, "<!SEP>", TREE_COLS); + g_free (buff); + thisdir = gtk_ctree_insert_node (GTK_CTREE (tree), webnode, NULL, vbuff, 5, + pixclosed, bitclosed, pixopen, bitopen, + FALSE, FALSE); + g_strfreev (vbuff); + + /* don't let users select whole directories */ + gtk_ctree_node_set_selectable (GTK_CTREE (tree), thisdir, FALSE); + + /* load the contents into the tree */ + sattree_add_web_uri (GTK_CTREE (tree), thisdir, web[i], filter, readfiles); + } + } + + /* The roots should not be selectable */ + gtk_ctree_node_set_selectable (GTK_CTREE (tree), localnode, FALSE); + gtk_ctree_node_set_selectable (GTK_CTREE (tree), webnode, FALSE); + + + return tree; + } + + + static void + sattree_add_local_uri (GtkWidget *tree, GtkCTreeNode *parent, + const gchar *uri, const gchar *filter, + gboolean readfiles) + { + /* This function loads the specified local directory recursively + into the GtkCTree starting at the specified GtkCTreeNode. + */ GnomeVFSResult result; GnomeVFSDirectoryFilter *vfsfilter; GnomeVFSFileInfo *fileinfo; ! gchar *msg,*path,*vfsuri; GList *list,*node; gchar *text,**vbuf; + GdkPixmap *pixopen,*pixclosed; + GdkBitmap *bitopen,*bitclosed; + GtkCTreeNode *myself; + + /* this shouldn't happen, but... */ + g_return_if_fail (uri); + + /* Create pixmaps and bitmaps */ + pixopen = gdk_pixmap_create_from_xpm (app->window, &bitopen, 0, + "../pixmaps/icons/gpredict-dir-open.xpm"); + pixclosed = gdk_pixmap_create_from_xpm (app->window, &bitclosed, 0, + "../pixmaps/icons/gpredict-dir-closed.xpm"); ! ! /**** Load subdirectories if any ****/ /* create gnome_vfs_uri */ ! vfsuri = gnome_vfs_get_uri_from_local_path (uri); /* create a filter and load the directory */ vfsfilter = gnome_vfs_directory_filter_new (GNOME_VFS_DIRECTORY_FILTER_SHELLPATTERN, GNOME_VFS_DIRECTORY_FILTER_NODOTFILES | GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR | GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES, ! "*"); ! result = gnome_vfs_directory_list_load (&list, vfsuri, GNOME_VFS_FILE_INFO_DEFAULT, vfsfilter); /* free some memory */ ! g_free (vfsuri); gnome_vfs_directory_filter_destroy (vfsfilter); + if (result == GNOME_VFS_OK) { /* make a log message */ ! msg = g_strconcat (__FUNCTION__, _(": loading subdirs from "), uri, ": GNOME_VFS_OK", NULL); satlog_log (SAT_LOG_DEBUG, msg); g_free (msg); /* loop throough the file list */ for (node = list; node != NULL; node = node->next) { fileinfo = node->data; /* fileinfo->name contains filename */ ! path = g_strconcat (uri, G_DIR_SEPARATOR_S, fileinfo->name, NULL); ! if (g_file_test (path, G_FILE_TEST_ISDIR)) { ! /* add this dir to parent */ ! text = g_strconcat (fileinfo->name, "<!SEP> <!SEP> ", NULL); ! vbuf = g_strsplit (text, "<!SEP>", TREE_COLS); ! g_free (text); ! myself = gtk_ctree_insert_node (GTK_CTREE (tree), parent, NULL, vbuf, 5, ! pixclosed, bitclosed, pixopen, bitopen, ! FALSE, FALSE); ! g_strfreev (vbuf); ! /* don't let users select whole directories */ ! gtk_ctree_node_set_selectable (GTK_CTREE (tree), myself, FALSE); ! /* load the contents of this directory (WARNING: RECURSIVE CALL!) */ ! sattree_add_local_uri (tree, myself, path, filter, readfiles); } g_free (path); } + /* free memory taken up by file list */ gnome_vfs_file_info_list_free (list); } ! /**** Load files if any ****/ /* create gnome_vfs_uri */ ! vfsuri = gnome_vfs_get_uri_from_local_path (uri); /* create a filter and load the directory */ *************** *** 260,374 **** GNOME_VFS_DIRECTORY_FILTER_NODIRS | GNOME_VFS_DIRECTORY_FILTER_NODOTFILES | - GNOME_VFS_DIRECTORY_FILTER_EXTENDEDREGEXP | GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR | GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES, filter ? filter : "*"); ! result = gnome_vfs_directory_list_load (&list, url, GNOME_VFS_FILE_INFO_DEFAULT, vfsfilter); gnome_vfs_directory_filter_destroy (vfsfilter); - g_print ("%s\n", gnome_vfs_result_to_string (result)); if (result == GNOME_VFS_OK) { ! GdkPixmap *dop,*dcp; ! GdkBitmap *dob,*dcb; ! GtkCTreeNode *treenode,*satnode; ! gchar catnum_s[6]; ! guint catnum,j; /* make a log message */ ! msg = g_strconcat (__FUNCTION__, _(": get dir-list: GNOME_VFS_OK"), NULL); satlog_log (SAT_LOG_DEBUG, msg); g_free (msg); /* Create pixmaps and bitmaps */ ! dop = gdk_pixmap_create_from_xpm (app->window, &dob, 0, ! "../pixmaps/icons/directory-open.xpm"); ! dcp = gdk_pixmap_create_from_xpm (app->window, &dcb, 0, ! "../pixmaps/icons/directory-closed.xpm"); ! ! tree = gtk_ctree_new (1, 0); /* loop throough the file list */ for (node = list; node != NULL; node = node->next) { - fileinfo = node->data; /* fileinfo->name contains filename */ ! file = g_strsplit (fileinfo->name, ".tle", 1); ! treenode = gtk_ctree_insert_node (GTK_CTREE (tree), NULL, NULL, file, 2, ! dcp, dcb, dop, dob, ! FALSE, FALSE); ! /* read satellites into tree */ ! path = g_strconcat (url, G_DIR_SEPARATOR_S, fileinfo->name, NULL); ! /* open TLE file */ ! satfile = fopen (path, "r"); ! if (satfile) { ! gchar name[80],line1[80],line2[80]; - i = 0; - /* avoid reading the last sat twice */ - fgets (name, 75, satfile); - while (!feof (satfile)) { - /* read lines */ - fgets (line1, 75, satfile); - fgets (line2, 75, satfile); - /* fix satname */ - x = strlen (name); - while ( name[x]==32 || name[x]==0 || name[x]==10 || name[x]==13 ) { - name[x] = 0; - x--; - } - /* extract catalog number */ - for (j=0; j<6; j++) - catnum_s[j] = line1[j+2]; - catnum_s[5] = 0; - catnum = (guint) g_strtod (catnum_s, NULL); - /* add satelite to the tree */ - vbuf = g_strsplit (name, "!", 1); - satnode = gtk_ctree_insert_node (GTK_CTREE (tree), - treenode, NULL, - vbuf, 5, - NULL, NULL, NULL, NULL, - TRUE, FALSE); ! /* attach catalog number; this will provide the same functionality ! as the flat list (pre-0.4). ! */ ! gtk_ctree_node_set_row_data (GTK_CTREE (tree), satnode, ! GUINT_TO_POINTER (catnum)); ! g_strfreev (vbuf); ! i++; ! fgets (name, 75, satfile); } ! fclose (satfile); ! text = g_strdup_printf ("%s: read %d satelites from %s", ! __FUNCTION__, i, fileinfo->name); ! satlog_log (SAT_LOG_INFO, text); ! g_free (text); ! } ! else { ! msg = g_strconcat (__FUNCTION__, _(": could not open file"), path, NULL); ! satlog_log (SAT_LOG_WARNING, msg); ! g_free (msg); } ! /* free string */ ! g_free (path); } ! /* free memory taken up by file list */ ! gnome_vfs_file_info_list_free (list); ! ! return tree; } else { ! msg = g_strconcat (__FUNCTION__, _(": get dir-list != GNOME_VFS_OK"), NULL); ! satlog_log (SAT_LOG_CRITICAL, msg); g_free (msg); - - return NULL; } } --- 285,490 ---- GNOME_VFS_DIRECTORY_FILTER_NODIRS | GNOME_VFS_DIRECTORY_FILTER_NODOTFILES | GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR | GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES, filter ? filter : "*"); ! result = gnome_vfs_directory_list_load (&list, vfsuri, GNOME_VFS_FILE_INFO_DEFAULT, vfsfilter); + /* free some memory */ + g_free (vfsuri); gnome_vfs_directory_filter_destroy (vfsfilter); if (result == GNOME_VFS_OK) { ! GdkPixmap *pixm; ! GdkBitmap *bitm; /* make a log message */ ! msg = g_strconcat (__FUNCTION__, _(": loading files from "), uri, ": GNOME_VFS_OK", NULL); satlog_log (SAT_LOG_DEBUG, msg); g_free (msg); /* Create pixmaps and bitmaps */ ! pixm = gdk_pixmap_create_from_xpm (app->window, &bitm, 0, ! "../pixmaps/icons/gpredict-file-list.xpm"); /* loop throough the file list */ for (node = list; node != NULL; node = node->next) { fileinfo = node->data; /* fileinfo->name contains filename */ ! path = g_strconcat (uri, G_DIR_SEPARATOR_S, fileinfo->name, NULL); ! if (g_file_test (path, G_FILE_TEST_ISFILE)) { ! /* add this file to parent */ ! text = g_strconcat (fileinfo->name, "<!SEP> <!SEP> ", NULL); ! vbuf = g_strsplit (text, "<!SEP>", TREE_COLS); ! g_free (text); ! myself = gtk_ctree_insert_node (GTK_CTREE (tree), parent, NULL, vbuf, 5, ! pixm, bitm, pixm, bitm, ! FALSE, FALSE); ! g_strfreev (vbuf); ! /* don't want users to select this */ ! gtk_ctree_node_set_selectable (GTK_CTREE (tree), myself, FALSE); ! if (readfiles) { ! /* load the contents of this file */ ! sattree_add_local_file (tree, myself, path); ! } ! } ! g_free (path); ! } ! /* free memory taken up by file list */ ! gnome_vfs_file_info_list_free (list); ! } ! } ! static void ! sattree_add_local_file (GtkWidget *tree, GtkCTreeNode *parent, gchar *file) ! { ! /* This function read the satellites from the 'file' into to the ! GtkCTree. It also performs a check whether the file actually ! contains valid TLE data (the same check as with the engine. ! */ ! FILE *satfile = NULL; ! gchar *msg; ! gint i,x; ! gchar *text,**vbuf; ! GtkCTreeNode *satnode; ! gchar catnum_s[6],*entry,*epoch_s; ! guint catnum,j,epochyear, epochday; ! GDate *epoch; ! gchar name[80],line1[80],line2[80]; ! /* Just to prevent unexpected behaviuor */ ! g_return_if_fail (file && tree && parent); ! ! /* open TLE file */ ! satfile = fopen (file, "r"); ! if (satfile) { ! ! i = 0; ! /* avoid reading the last sat twice */ ! fgets (name, 75, satfile); ! while (!feof (satfile)) { ! /* read lines */ ! fgets (line1, 75, satfile); ! fgets (line2, 75, satfile); ! ! if (KepCheck (line1, line2)) { ! ! /* fix satname */ ! x = strlen (name); ! while ( name[x]==32 || name[x]==0 || name[x]==10 || name[x]==13 ) { ! name[x] = 0; ! x--; } ! ! /* extract catalog number */ ! for (j=0; j<6; j++) ! catnum_s[j] = line1[j+2]; ! catnum_s[5] = 0; ! catnum = (guint) g_strtod (catnum_s, NULL); ! ! /* FIXME: check whether we already have a ! satellite with this catalog number. ! */ ! ! /* EPOCH */ ! epochyear = (guint) g_strtod (SubString (line1, 18, 19), NULL); ! epochday = (guint) g_strtod (SubString (line1, 20, 31), NULL); ! epoch = g_date_new_dmy (1, 1, 2000 + epochyear); ! g_date_add_days (epoch, epochday); ! epoch_s = g_malloc (50); ! g_date_strftime (epoch_s, 50, "%e %b %Y", epoch); ! ! /* add satelite to the tree */ ! entry = g_strconcat (name, ! "<!SEP>", catnum_s, ! "<!SEP>", epoch_s, ! NULL); ! vbuf = g_strsplit (entry, "<!SEP>", TREE_COLS); ! satnode = gtk_ctree_insert_node (GTK_CTREE (tree), ! parent, NULL, ! vbuf, 5, ! NULL, NULL, NULL, NULL, ! TRUE, FALSE); ! ! /* attach catalog number; this will provide the same functionality ! as the flat list (pre-0.4). ! */ ! gtk_ctree_node_set_row_data (GTK_CTREE (tree), satnode, ! GUINT_TO_POINTER (catnum)); ! ! g_free (epoch_s); ! g_date_free (epoch); ! g_free (entry); ! g_strfreev (vbuf); ! i++; } ! fgets (name, 75, satfile); } ! fclose (satfile); ! text = g_strdup_printf ("%s: read %d satelites from %s", ! __FUNCTION__, i, file); ! satlog_log (SAT_LOG_INFO, text); ! g_free (text); } else { ! msg = g_strconcat (__FUNCTION__, _(": could not open file "), file, NULL); ! satlog_log (SAT_LOG_WARNING, msg); g_free (msg); } + } + + + + /*********** FIXME: MOVE THIS FURTHER UP WHEN IMPLEMENTED! */ + static void + sattree_add_web_uri (GtkCTree *tree, GtkCTreeNode *parent, + const gchar *uri, const gchar *filter, + gboolean readfiles) + { + /* This function loads the specified web directory recursively + into the GtkCTree starting at the specified GtkCTreeNode. + */ + } + + + + static void + sattree_select_row_cb (GtkCTree *tree, GtkCTreeNode *node, + gint column, gpointer data) + { + GList *sel = tree->clist.selection; + guint length = 0; + gchar *title; + + length = g_list_length (sel); + if (length) + title = g_strdup_printf ("%s (%d selected)", tree_titles[0], length); + else + title = g_strdup_printf ("%s", tree_titles[0]); + gtk_clist_set_column_title (GTK_CLIST (tree), 0, title); + g_free (title); + } + + + + static void + sattree_unselect_row_cb (GtkCTree *tree, GtkCTreeNode *node, + gint column, gpointer data) + { + GList *sel = tree->clist.selection; + guint length = 0; + gchar *title; + + length = g_list_length (sel); + if (length) + title = g_strdup_printf ("%s (%d selected)", tree_titles[0], length); + else + title = g_strdup_printf ("%s", tree_titles[0]); + gtk_clist_set_column_title (GTK_CLIST (tree), 0, title); + g_free (title); } |