gnome-utils r8389 - trunk/logview



Author: cosimoc
Date: Fri Jan 30 10:43:30 2009
New Revision: 8389
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8389&view=rev

Log:
2009-01-30  Cosimo Cecchi  <cosimoc gnome org>

        * logview-log.c:
        (logview_log_init):
        (log_load):
        (logview_log_get_has_days):
        * logview-log.h:
        * logview-loglist.c:
        (update_days_and_lines_for_log):
        (manager_log_added_cb):
        * logview-window.c:
	Check if there are some lines before actually adding an entry
	to the loglist. This implies adding some API to LogviewLog.
	Closes bug #567170.


Modified:
   trunk/logview/ChangeLog
   trunk/logview/logview-log.c
   trunk/logview/logview-log.h
   trunk/logview/logview-loglist.c
   trunk/logview/logview-window.c

Modified: trunk/logview/logview-log.c
==============================================================================
--- trunk/logview/logview-log.c	(original)
+++ trunk/logview/logview-log.c	Fri Jan 30 10:43:30 2009
@@ -54,6 +54,7 @@
   time_t file_time;
   goffset file_size;
   char *display_name;
+  gboolean has_days;
 
   /* lines and relative days */
   GSList *days;
@@ -157,6 +158,7 @@
   self->priv->file = NULL;
   self->priv->mon = NULL;
   self->priv->has_new_lines = FALSE;
+  self->priv->has_days = FALSE;
 }
 
 static void
@@ -608,8 +610,10 @@
   GFile *f = log->priv->file;
   GFileInfo *info;
   GInputStream *is;
+  const char *peeked_buffer;
+  const char * parse_data[2];
+  GSList *days;
   const char *content_type;
-  char *buffer;
   GFileType type;
   GError *err = NULL;
   GTimeVal timeval;
@@ -738,6 +742,29 @@
   }
 
   log->priv->stream = g_data_input_stream_new (is);
+
+  /* sniff into the stream for a timestamped line */
+  g_buffered_input_stream_fill (G_BUFFERED_INPUT_STREAM (log->priv->stream),
+                                (gssize) g_buffered_input_stream_get_buffer_size (G_BUFFERED_INPUT_STREAM (log->priv->stream)),
+                                NULL, &err);
+  if (err == NULL) {
+    peeked_buffer = g_buffered_input_stream_peek_buffer
+        (G_BUFFERED_INPUT_STREAM (log->priv->stream), NULL);
+    parse_data[0] = peeked_buffer;
+    parse_data[1] = NULL;
+
+    if ((days = log_read_dates (parse_data, time (NULL))) != NULL) {
+      log->priv->has_days = TRUE;
+      g_slist_foreach (days, (GFunc) logview_utils_day_free, NULL);
+      g_slist_free (days);
+    } else {
+      log->priv->has_days = FALSE;
+    }
+  } else {
+    log->priv->has_days = FALSE;
+    g_clear_error (&err);
+  }
+
   g_object_unref (is);
 
 out:
@@ -893,5 +920,11 @@
   return g_object_ref (log->priv->file);
 }
 
+gboolean
+logview_log_get_has_days (LogviewLog *log)
+{
+  g_assert (LOGVIEW_IS_LOG (log));
 
+  return log->priv->has_days;
+}
 

Modified: trunk/logview/logview-log.h
==============================================================================
--- trunk/logview/logview-log.h	(original)
+++ trunk/logview/logview-log.h	Fri Jan 30 10:43:30 2009
@@ -102,8 +102,8 @@
 gboolean      logview_log_has_new_lines             (LogviewLog *log);
 char *        logview_log_get_uri                   (LogviewLog *log);
 GFile *       logview_log_get_gfile                 (LogviewLog *log);
-
+gboolean      logview_log_get_has_days              (LogviewLog *log);
 
 G_END_DECLS
 
-#endif /* __LOGVIEW_LOG_H__ */
\ No newline at end of file
+#endif /* __LOGVIEW_LOG_H__ */

Modified: trunk/logview/logview-loglist.c
==============================================================================
--- trunk/logview/logview-loglist.c	(original)
+++ trunk/logview/logview-loglist.c	Fri Jan 30 10:43:30 2009
@@ -78,16 +78,14 @@
   char date[200];
   Day *day;
 
-  /* we can't remove all the items immediately, otherwise, if the row
-   * is expanded, it will be collapsed because there are no items, so
-   * we create a dummy entry, remove all the others and then remove the dummy
-   * one.
+  /* if we have some days, we can't remove all the items immediately, otherwise,
+   * if the row is expanded, it will be collapsed because there are no items,
+   * so we create a dummy entry, remove all the others and then remove the
+   * dummy one.
    */
   res = gtk_tree_model_iter_children (GTK_TREE_MODEL (loglist->priv->model),
                                       &iter, log);
-  if (!res) {
-    /* this isn't quite possible */
-  } else {
+  if (res) {
     gtk_tree_store_insert_before (loglist->priv->model, &dummy, log, &iter);
     gtk_tree_store_set (loglist->priv->model, &dummy,
                         LOG_NAME, "", -1);
@@ -109,7 +107,9 @@
     i++;
   }
 
-  gtk_tree_store_remove (loglist->priv->model, &dummy);
+  if (res) {
+    gtk_tree_store_remove (loglist->priv->model, &dummy);
+  }
 }
 
 static GtkTreeIter *
@@ -302,11 +302,12 @@
   gtk_tree_store_set (list->priv->model, &iter,
                       LOG_OBJECT, g_object_ref (log),
                       LOG_NAME, logview_log_get_display_name (log), -1);
-
-  gtk_tree_store_insert (list->priv->model,
-                         &child, &iter, 0);
-  gtk_tree_store_set (list->priv->model, &child,
-                      LOG_NAME, _("Loading..."), -1);
+  if (logview_log_get_has_days (log)) {
+    gtk_tree_store_insert (list->priv->model,
+                           &child, &iter, 0);
+    gtk_tree_store_set (list->priv->model, &child,
+                        LOG_NAME, _("Loading..."), -1);
+  }
 
   g_signal_connect (log, "log-changed",
                     G_CALLBACK (log_changed_cb), list);
@@ -488,3 +489,4 @@
 
   gtk_tree_iter_free (parent);
 }
+

Modified: trunk/logview/logview-window.c
==============================================================================
--- trunk/logview/logview-window.c	(original)
+++ trunk/logview/logview-window.c	Fri Jan 30 10:43:30 2009
@@ -802,6 +802,8 @@
   int i, old_line_count;
   GtkTextIter iter, start;
   GtkTextMark *mark;
+  char *converted;
+  gsize len;
 
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->priv->text_view));
   old_line_count = gtk_text_buffer_get_line_count (buffer);
@@ -817,7 +819,15 @@
   }
 
   for (i = 0; lines[i]; i++) {
-    gtk_text_buffer_insert (buffer, &iter, lines[i], strlen (lines[i]));
+    len = strlen (lines[i]);
+
+    if (!g_utf8_validate (lines[i], len, NULL)) {
+      converted = g_locale_to_utf8 (lines[i], (gssize) len, NULL, &len, NULL);
+      gtk_text_buffer_insert (buffer, &iter, lines[i], len);
+    } else {
+      gtk_text_buffer_insert (buffer, &iter, lines[i], strlen (lines[i]));
+    }
+
     gtk_text_iter_forward_to_end (&iter);
     gtk_text_buffer_insert (buffer, &iter, "\n", 1);
     gtk_text_iter_forward_char (&iter);



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