gnome-utils r8292 - trunk/logview



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

Log:
First rough cut at implementing day selection in the buffer.

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

Modified: trunk/logview/logview-loglist.c
==============================================================================
--- trunk/logview/logview-loglist.c	(original)
+++ trunk/logview/logview-loglist.c	Tue Dec 23 13:27:25 2008
@@ -28,6 +28,7 @@
 struct _LogviewLoglistPrivate {
   GtkTreeStore *model;
   LogviewManager *manager;
+  GDate *selection;
 };
 
 G_DEFINE_TYPE (LogviewLoglist, logview_loglist, GTK_TYPE_TREE_VIEW);
@@ -43,6 +44,27 @@
   LOG_DAY
 };
 
+enum {
+  DAY_SELECTED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void
+save_day_selection (LogviewLoglist *loglist, Day *day)
+{
+  GDate *date;
+
+  if (loglist->priv->selection) {
+    g_date_free (loglist->priv->selection);
+    loglist->priv->selection = NULL;
+  }
+
+  date = g_date_new_julian (g_date_get_julian (day->date));
+  loglist->priv->selection = date;
+}
+
 static void
 update_days_and_lines_for_log (LogviewLoglist *loglist,
                                GtkTreeIter *log, GSList *days)
@@ -133,24 +155,40 @@
 {
   LogviewLoglist *list = user_data;
   GtkTreeModel *model;
-  GtkTreeIter iter;
+  GtkTreeIter iter, parent;
   LogviewLog *log;
   gboolean is_bold;
+  Day *day;
 
   if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
       return;
   }
 
   gtk_tree_model_get (model, &iter, LOG_OBJECT, &log,
-                      LOG_WEIGHT_SET, &is_bold, -1);
-  logview_manager_set_active_log (list->priv->manager, log);
+                      LOG_WEIGHT_SET, &is_bold,
+                      LOG_DAY, &day, -1);
+  if (log) {
+    logview_manager_set_active_log (list->priv->manager, log);
+  } else {
+    gtk_tree_model_iter_parent (model, &parent, &iter);
+    gtk_tree_model_get (model, &parent, LOG_OBJECT, &log, -1);
+
+    if (!logview_manager_log_is_active (list->priv->manager, log)) {
+      save_day_selection (list, day);
+      logview_manager_set_active_log (list->priv->manager, log);
+    } else {
+      g_signal_emit (list, signals[DAY_SELECTED], 0, day, NULL);
+    }
+  }
 
   if (is_bold) {
     gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
                         LOG_WEIGHT_SET, FALSE, -1);
   }
 
-  g_object_unref (log);
+  if (log) {
+    g_object_unref (log);
+  }
 }
 
 static void
@@ -315,6 +353,15 @@
   GObjectClass *oclass = G_OBJECT_CLASS (klass);
   oclass->finalize = do_finalize;
 
+  signals[DAY_SELECTED] = g_signal_new ("day-selected",
+                                        G_OBJECT_CLASS_TYPE (oclass),
+                                        G_SIGNAL_RUN_LAST,
+                                        G_STRUCT_OFFSET (LogviewLoglistClass, day_selected),
+                                        NULL, NULL,
+                                        g_cclosure_marshal_VOID__POINTER,
+                                        G_TYPE_NONE, 1,
+                                        G_TYPE_POINTER);
+
   g_type_class_add_private (klass, sizeof (LogviewLoglistPrivate));
 }
 
@@ -341,3 +388,20 @@
   parent = logview_loglist_find_log (loglist, log);
   update_days_and_lines_for_log (loglist, parent, days);
 }
+
+GDate *
+logview_loglist_get_date_selection (LogviewLoglist *loglist)
+{
+  g_assert (LOGVIEW_IS_LOGLIST (loglist));
+
+  return loglist->priv->selection;
+}
+
+void
+logview_loglist_clear_date (LogviewLoglist *loglist)
+{
+  g_assert (LOGVIEW_IS_LOGLIST (loglist));
+
+  g_date_free (loglist->priv->selection);
+  loglist->priv->selection = NULL;
+}
\ No newline at end of file

Modified: trunk/logview/logview-loglist.h
==============================================================================
--- trunk/logview/logview-loglist.h	(original)
+++ trunk/logview/logview-loglist.h	Tue Dec 23 13:27:25 2008
@@ -36,6 +36,7 @@
 #include <glib-object.h>
 
 #include "logview-log.h"
+#include "logview-utils.h"
 
 typedef struct _LogviewLoglist LogviewLoglist;
 typedef struct _LogviewLoglistClass LogviewLoglistClass;
@@ -48,13 +49,18 @@
 
 struct _LogviewLoglistClass {
 	GtkTreeViewClass parent_class;
+
+  void (* day_selected) (LogviewLoglist *loglist,
+                         Day *day);
 };
 
 GType logview_loglist_get_type (void);
 
 /* public methods */
-GtkWidget * logview_loglist_new          (void);
-void        logview_loglist_update_lines (LogviewLoglist *loglist,
-                                          LogviewLog *log);
+GtkWidget * logview_loglist_new                (void);
+void        logview_loglist_update_lines       (LogviewLoglist *loglist,
+                                                LogviewLog *log);
+GDate *     logview_loglist_get_date_selection (LogviewLoglist *loglist);
+void        logview_loglist_clear_date         (LogviewLoglist *loglist);
 
 #endif /* __LOGVIEW_LOGLIST_H__ */

Modified: trunk/logview/logview-window.c
==============================================================================
--- trunk/logview/logview-window.c	(original)
+++ trunk/logview/logview-window.c	Tue Dec 23 13:27:25 2008
@@ -35,6 +35,8 @@
 #define APP_NAME _("System Log Viewer")
 #define SEARCH_START_MARK "lw-search-start-mark"
 #define SEARCH_END_MARK "lw-search-end-mark"
+#define VISIBLE_AREA_START_MARK "lw-visible-start"
+#define VISIBLE_AREA_END_MARK "lw-visible-end"
 
 struct _LogviewWindowPrivate {
   GtkWidget *statusbar;
@@ -129,6 +131,16 @@
                 "weight-set", TRUE, NULL);
 
   gtk_text_tag_table_add (tag_table, tag);
+
+  tag = gtk_text_tag_new ("invisible");
+  g_object_set (tag, "invisible", TRUE, "invisible-set", TRUE, NULL);
+
+  gtk_text_tag_table_add (tag_table, tag);
+
+  tag = gtk_text_tag_new ("visible");
+  g_object_set (tag, "invisible", FALSE, "invisible-set", FALSE, NULL);
+
+  gtk_text_tag_table_add (tag_table, tag);
 }
 
 static void
@@ -654,6 +666,62 @@
   return FALSE;
 }
 
+static void
+real_select_day (LogviewWindow *logview,
+                 GDate *date, int first_line, int last_line)
+{
+  GtkTextBuffer *buffer;
+  GtkTextIter start_iter, end_iter, start_vis, end_vis;
+
+  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logview->priv->text_view));
+
+  gtk_text_buffer_get_start_iter (buffer, &start_iter);
+  gtk_text_buffer_get_iter_at_line (buffer, &start_vis, first_line);
+  gtk_text_buffer_get_iter_at_line (buffer, &end_vis, last_line);
+  gtk_text_buffer_get_end_iter (buffer, &end_iter);
+
+  gtk_text_buffer_remove_tag_by_name (buffer, "invisible",
+                                      &start_iter, &end_iter);
+
+  gtk_text_buffer_apply_tag_by_name (buffer, "invisible",
+                                     &start_iter, &start_vis);
+  gtk_text_buffer_apply_tag_by_name (buffer, "invisible",
+                                     &end_vis, &end_iter);
+}
+
+static void
+loglist_day_selected_cb (LogviewLoglist *loglist,
+                         Day *day,
+                         gpointer user_data)
+{
+  LogviewWindow *logview = user_data;
+
+  real_select_day (logview, day->date, day->first_line, day->last_line);
+}
+
+static void
+logview_window_select_date (LogviewWindow *logview, GDate *date)
+{
+  LogviewLog *log;
+  GSList *days, *l;
+  Day *day;
+  gboolean found = FALSE;
+
+  log = logview_manager_get_active_log (logview->priv->manager);
+
+  for (l = days; l; l = l->next) {
+    day = l->data;
+    if (g_date_compare (date, day->date) == 0) {
+      found = TRUE;
+      break;
+    }
+  }
+
+  if (found) {
+    real_select_day (logview, day->date, day->first_line, day->last_line);
+  }   
+}
+
 static void read_new_lines_cb (LogviewLog *log,
                                const char **lines,
                                GError **error,
@@ -680,6 +748,7 @@
   int i;
   GtkTextIter iter, start;
   GtkTextMark *mark;
+  GDate *date;
 
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->priv->text_view));
 
@@ -713,6 +782,11 @@
 
   logview_update_statusbar (window, log);
   logview_loglist_update_lines (LOGVIEW_LOGLIST (window->priv->loglist), log);
+
+  if (date = logview_loglist_get_date_selection (LOGVIEW_LOGLIST (window->priv->loglist))) {
+    logview_window_select_date (window, date);
+    logview_loglist_clear_date (LOGVIEW_LOGLIST (window->priv->loglist));
+  }
 }
 
 static void
@@ -751,22 +825,29 @@
     }
   }
 
-  /* we set the buffer to the view anyway;
-   * if there are no lines it will be empty for the duration of the thread
-   * and will help us to distinguish the two cases of the following if
-   * cause in the callback.
-   */
-  gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->priv->text_view), buffer);
-  g_object_unref (buffer);
-
   if (lines == NULL || logview_log_has_new_lines (log)) {
     /* read the new lines */
     logview_log_read_new_lines (log, (LogviewNewLinesCallback) read_new_lines_cb, window);
   } else {
+    GDate *date;
+
     /* start now monitoring the log for changes */
     window->priv->monitor_id = g_signal_connect (log, "log-changed",
                                                  G_CALLBACK (log_monitor_changed_cb), window);
+
+    if (date = logview_loglist_get_date_selection (LOGVIEW_LOGLIST (window->priv->loglist))) {
+      logview_window_select_date (window, date);
+      logview_loglist_clear_date (LOGVIEW_LOGLIST (window->priv->loglist));
+    }
   }
+
+  /* we set the buffer to the view anyway;
+   * if there are no lines it will be empty for the duration of the thread
+   * and will help us to distinguish the two cases of the following if
+   * cause in the callback.
+   */
+  gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->priv->text_view), buffer);
+  g_object_unref (buffer);
 }
 
 static void
@@ -878,6 +959,9 @@
   gtk_widget_show (w);
   gtk_widget_show (priv->loglist);
 
+  g_signal_connect (priv->loglist, "day_selected",
+                    G_CALLBACK (loglist_day_selected_cb), logview);
+
   /* second pane : log */
   main_view = gtk_vbox_new (FALSE, 0);
   gtk_paned_pack2 (GTK_PANED (hpaned), main_view, TRUE, TRUE);



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