gnome-utils r8297 - trunk/logview



Author: cosimoc
Date: Tue Dec 23 13:27:41 2008
New Revision: 8297
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8297&view=rev

Log:
Prepare for days highlighting in the main logview window.

Modified:
   trunk/logview/logview-log.c
   trunk/logview/logview-log.h
   trunk/logview/logview-prefs.c
   trunk/logview/logview-utils.c
   trunk/logview/logview-utils.h
   trunk/logview/logview-window.c

Modified: trunk/logview/logview-log.c
==============================================================================
--- trunk/logview/logview-log.c	(original)
+++ trunk/logview/logview-log.c	Tue Dec 23 13:27:41 2008
@@ -70,6 +70,7 @@
   LogviewLog *log;
   GError *err;
   const char **lines;
+  GSList *new_days;
   LogviewNewLinesCallback callback;
   gpointer user_data;
 } NewLinesJob;
@@ -180,7 +181,7 @@
                     G_CALLBACK (monitor_changed_cb), log);
 }
 
-static void
+static GSList *
 add_new_days_to_cache (LogviewLog *log, const char **new_lines, guint lines_offset)
 {
   GSList *new_days, *l, *last_cached;
@@ -196,8 +197,8 @@
 
   if (!last_cached) {
     /* this means the day list is empty (i.e. we're on the first read */
-    log->priv->days = new_days;
-    return;
+    log->priv->days = logview_utils_day_list_copy (new_days);
+    return new_days;
   }
 
   for (l = new_days; l; l = l->next) {
@@ -210,20 +211,16 @@
        */
       day->first_line += lines_offset;
       day->last_line += lines_offset;
-      log->priv->days = g_slist_append (log->priv->days, l->data);
+      log->priv->days = g_slist_append (log->priv->days, logview_utils_day_copy (day));
     } else if (res == 0) {
       last = last_cached->data;
  
       /* update the lines number */
       last->last_line += day->last_line;
-      logview_utils_day_free (l->data);
-    } else {
-      /* if the day is a day before, free it */
-      logview_utils_day_free (l->data);
     }
   }
 
-  g_slist_free (new_days);
+  return new_days;
 }
 
 static gboolean
@@ -232,14 +229,17 @@
   NewLinesJob *job = data;
 
   if (job->err) {
-    job->callback (job->log, NULL, job->err, job->user_data);
+    job->callback (job->log, NULL, NULL, job->err, job->user_data);
     g_error_free (job->err);
   } else {
-    job->callback (job->log, job->lines, job->err, job->user_data);
+    job->callback (job->log, job->lines, job->new_days, job->err, job->user_data);
   }
 
+  g_slist_foreach (job->new_days, (GFunc) logview_utils_day_free, NULL);
+  g_slist_free (job->new_days);
+
   /* drop the reference we acquired before */
-  g_object_unref (job->log);  
+  g_object_unref (job->log);
 
   g_slice_free (NewLinesJob, job);
 
@@ -292,7 +292,7 @@
   job->lines = (const char **) lines->pdata + log->priv->lines_no;
 
   /* save the new number of days and lines */
-  add_new_days_to_cache (log, job->lines, log->priv->lines_no);
+  job->new_days = add_new_days_to_cache (log, job->lines, log->priv->lines_no);
   log->priv->lines_no = (lines->len - 1);
 
 out:
@@ -425,6 +425,7 @@
   job->log = g_object_ref (log);
   job->err = NULL;
   job->lines = NULL;
+  job->new_days = NULL;
 
   /* push the fetching job into another thread */
   g_io_scheduler_push_job (do_read_new_lines,

Modified: trunk/logview/logview-log.h
==============================================================================
--- trunk/logview/logview-log.h	(original)
+++ trunk/logview/logview-log.h	Tue Dec 23 13:27:41 2008
@@ -52,6 +52,7 @@
                                         gpointer user_data);
 typedef void (* LogviewNewLinesCallback) (LogviewLog *log,
                                           const char **lines,
+                                          GSList *new_days,
                                           GError *error,
                                           gpointer user_data);
 

Modified: trunk/logview/logview-prefs.c
==============================================================================
--- trunk/logview/logview-prefs.c	(original)
+++ trunk/logview/logview-prefs.c	Tue Dec 23 13:27:41 2008
@@ -190,7 +190,7 @@
   /* reset the source id */
   prefs->priv->size_store_timeout = 0;
 
-  g_slice_free (WindowSize, data);
+  g_free (size);
 
   return FALSE;
 }
@@ -335,7 +335,7 @@
 
   g_assert (LOGVIEW_IS_PREFS (prefs));
 
-  size = g_slice_new0 (WindowSize);
+  size = g_new0 (WindowSize, 1);
   size->width = width;
   size->height = height;
 

Modified: trunk/logview/logview-utils.c
==============================================================================
--- trunk/logview/logview-utils.c	(original)
+++ trunk/logview/logview-utils.c	Tue Dec 23 13:27:41 2008
@@ -39,6 +39,32 @@
   g_slice_free (Day, day);
 }
 
+Day *
+logview_utils_day_copy (Day *day)
+{
+  Day *retval;
+
+  retval = g_slice_new0 (Day);
+  retval->date = g_date_new_julian (g_date_get_julian (day->date));
+  retval->first_line = day->first_line;
+  retval->last_line = day->last_line;
+  retval->timestamp_len = day->timestamp_len;
+
+  return retval;
+}
+
+GSList *
+logview_utils_day_list_copy (GSList *days)
+{
+  GSList *l, *retval = NULL;
+
+  for (l = days; l; l = l->next) {
+    retval = g_slist_prepend (retval, logview_utils_day_copy (l->data));
+  }
+
+  return g_slist_reverse (retval);
+}
+
 gint 
 days_compare (gconstpointer a, gconstpointer b)
 {
@@ -148,6 +174,7 @@
   day->date = date;
   day->first_line = i;
   day->last_line = -1;
+  day->timestamp_len = strlen (date_string);
 
   /* now scan the logfile to get the last line of the day */
   rangemin = i;
@@ -230,6 +257,7 @@
         day->date = date;
         day->first_line = i;
         day->last_line = -1;
+        day->timestamp_len = strlen (date_string);
         rangemin = i;
         rangemax = n - 1;
       }

Modified: trunk/logview/logview-utils.h
==============================================================================
--- trunk/logview/logview-utils.h	(original)
+++ trunk/logview/logview-utils.h	Tue Dec 23 13:27:41 2008
@@ -27,11 +27,14 @@
   GDate *date;
   int first_line;
   int last_line;
+  int timestamp_len;
 } Day;
 
 GSList * log_read_dates (const char **buffer_lines, time_t current);
 gint     days_compare (gconstpointer a, gconstpointer b);
 void     logview_utils_day_free (Day *day);
+Day *    logview_utils_day_copy (Day *day);
+GSList * logview_utils_day_list_copy (GSList *days);
 
 
 #endif /* __LOGVIEW_UTILS_H__ */
\ No newline at end of file

Modified: trunk/logview/logview-window.c
==============================================================================
--- trunk/logview/logview-window.c	(original)
+++ trunk/logview/logview-window.c	Tue Dec 23 13:27:41 2008
@@ -104,27 +104,15 @@
 	}
 }
 
-static void
-logview_calendar_set_state (LogviewWindow *logview)
-{
-    g_assert (LOGVIEW_IS_WINDOW (logview));
-
-    if (logview->curlog) {
-        if (logview->curlog->days != NULL)
-            calendar_init_data (CALENDAR (logview->calendar), logview);
-        gtk_widget_set_sensitive (logview->calendar, (logview->curlog->days != NULL));
-    } else
-        gtk_widget_set_sensitive (logview->calendar, FALSE);
-}
-
 #endif
 
 /* private helpers */
 
 static void
-populate_tag_table (GtkTextTagTable *tag_table)
+populate_tag_table (LogviewWindow *logview, GtkTextTagTable *tag_table)
 {
   GtkTextTag *tag;
+  GtkStyle *style;
 
   tag = gtk_text_tag_new ("bold");
   g_object_set (tag, "weight", PANGO_WEIGHT_BOLD,
@@ -137,8 +125,9 @@
 
   gtk_text_tag_table_add (tag_table, tag);
 
-  tag = gtk_text_tag_new ("visible");
-  g_object_set (tag, "invisible", FALSE, "invisible-set", FALSE, NULL);
+  tag = gtk_text_tag_new ("gray");
+  style = gtk_widget_get_style (GTK_WIDGET (logview));
+  g_object_set (tag, "foreground-gdk", style->text_aa, "foreground-set", TRUE, NULL);
 
   gtk_text_tag_table_add (tag_table, tag);
 }
@@ -725,6 +714,7 @@
 
 static void read_new_lines_cb (LogviewLog *log,
                                const char **lines,
+                               GSList *new_days,
                                GError **error,
                                gpointer user_data);
 
@@ -740,6 +730,7 @@
 static void
 read_new_lines_cb (LogviewLog *log,
                    const char **lines,
+                   GSList *new_days,
                    GError **error,
                    gpointer user_data)
 {
@@ -962,7 +953,7 @@
   gtk_widget_show (w);
 
   priv->tag_table = gtk_text_tag_table_new ();
-  populate_tag_table (priv->tag_table);
+  populate_tag_table (logview, priv->tag_table);
   priv->text_view = gtk_text_view_new ();
   g_object_set (priv->text_view, "editable", FALSE, NULL);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]