/[xlog]/xlog/src/log.c
ViewVC logotype

Diff of /xlog/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.30 by pa4tu, Sun May 8 21:20:19 2005 UTC revision 1.31 by pa4tu, Mon May 9 07:38:31 2005 UTC
# Line 27  Line 27 
27  #include <stdlib.h>  #include <stdlib.h>
28  #include <errno.h>  #include <errno.h>
29  #include <string.h>  #include <string.h>
30    #include <sys/types.h>
31    #include <sys/wait.h>
32    
33  #include "callbacks_mainwindow_list.h"  #include "callbacks_mainwindow_list.h"
34  #include "gui_utils.h"  #include "gui_utils.h"
# Line 396  openlog (LOGDB * lp, gchar * name, gint Line 398  openlog (LOGDB * lp, gchar * name, gint
398          return (logwindow);          return (logwindow);
399  }  }
400    
401    /* close child process when finished */
402    static gboolean
403    childcheck (void)
404    {
405      gint status, childpid;
406    
407      childpid = waitpid (-1, &status, WNOHANG);
408      return (WIFEXITED(status) == 0);
409    }
410    
411  /* saving of the log */  /* saving of the log */
412  void  void
413  savelog (gpointer arg, gchar * logfile, gint type, gint first, gint last)  savelog (gpointer arg, gchar * logfile, gint type, gint first, gint last)
414  {  {
415          LOGDB *lp;          LOGDB *lp;
416          gint i, j;          gint i, j, pid = 0;
417          G_CONST_RETURN gchar *label;          G_CONST_RETURN gchar *label;
418          gchar **item, *pathstr;          gchar **item, *pathstr;
419          gint fields[QSO_FIELDS], widths[QSO_FIELDS];          gint fields[QSO_FIELDS], widths[QSO_FIELDS];
# Line 410  savelog (gpointer arg, gchar * logfile, Line 422  savelog (gpointer arg, gchar * logfile,
422          GtkTreeModel *model;          GtkTreeModel *model;
423          GtkTreePath *path;          GtkTreePath *path;
424          GtkTreeIter iter;          GtkTreeIter iter;
425            gboolean largelog = FALSE;
426    
427          item = g_new0 (gchar *, QSO_FIELDS);          item = g_new0 (gchar *, QSO_FIELDS);
428    
# Line 429  savelog (gpointer arg, gchar * logfile, Line 442  savelog (gpointer arg, gchar * logfile,
442          }          }
443    
444          lp = log_file_create (logfile, type, logw->columns, fields, widths);          lp = log_file_create (logfile, type, logw->columns, fields, widths);
445            if (last - first > 1000) largelog = TRUE;
446    
447          if (lp)          if (lp)
448          {          {
449                  model = gtk_tree_view_get_model (GTK_TREE_VIEW(logw->treeview));                  if (largelog)
450                  for (i = logw->qsos - first; i >= logw->qsos - last; i--)                          pid = fork (); /* use fork for large log saving */
451                    if (pid == 0)
452                  {                  {
453                          pathstr = g_strdup_printf ("%d", i);                          model = gtk_tree_view_get_model (GTK_TREE_VIEW(logw->treeview));
454                          path = gtk_tree_path_new_from_string (pathstr);                          for (i = logw->qsos - first; i >= logw->qsos - last; i--)
                         gtk_tree_model_get_iter (model, &iter, path);  
                         for (j = 0; j < logw->columns; j++)  
455                          {                          {
456                                  gtk_tree_model_get (model, &iter, logw->logfields[j], &item[fields[j]], -1);                                  pathstr = g_strdup_printf ("%d", i);
457                                  if (fields[j] == DATE || fields[j] == NAME || fields[j] == QTH ||       fields[j] == U1 || fields[j] == U2 || fields[j] == REMARKS)                                  path = gtk_tree_path_new_from_string (pathstr);
458                                          item[fields[j]] = g_locale_from_utf8 (item[fields[j]], -1, NULL, NULL, NULL);                                  gtk_tree_model_get_iter (model, &iter, path);
459                                    for (j = 0; j < logw->columns; j++)
460                                    {
461                                            gtk_tree_model_get
462                                                    (model, &iter, logw->logfields[j], &item[fields[j]], -1);
463                                            if (fields[j] == DATE || fields[j] == NAME ||
464    fields[j] == QTH || fields[j] == U1 || fields[j] == U2 || fields[j] == REMARKS)
465                                                    item[fields[j]] = g_locale_from_utf8
466                                                            (item[fields[j]], -1, NULL, NULL, NULL);
467                                    }
468                                    log_file_qso_append (lp, item);
469                                    gtk_tree_path_free (path);
470                                    g_free (pathstr);
471                          }                          }
472                          log_file_qso_append (lp, item);                          log_file_close (lp);
473                          gtk_tree_path_free (path);                          if (largelog) _exit (0);
                         g_free (pathstr);  
474                  }                  }
475                  log_file_close (lp);                  /* check the child every second */
476                    if (largelog)
477                            g_timeout_add (1000, (GSourceFunc) childcheck, NULL);
478          }          }
479          else          else
480          {          {

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26