[gnome-system-log] window: refactor code that changes currently active log



commit 9485eb4ca34edd2d58805ea69426aa4cd05a01be
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 11 17:31:06 2013 -0400

    window: refactor code that changes currently active log
    
    Refactor code to more elegantly clean the active state log when the
    active one changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697790

 src/logview-window.c |   48 +++++++++++++++++++++++++++---------------------
 1 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/src/logview-window.c b/src/logview-window.c
index 93e5bc5..ab3b85a 100644
--- a/src/logview-window.c
+++ b/src/logview-window.c
@@ -256,13 +256,31 @@ logview_set_fontsize (LogviewWindow *logview, gboolean store)
 }
 
 static void
+logview_set_search_visible (LogviewWindow *window,
+                            gboolean visible)
+{
+  g_action_group_change_action_state (G_ACTION_GROUP (window), "search",
+                                      g_variant_new_boolean (visible));
+}
+
+static void
+logview_clear_active_log_state (LogviewWindow *window,
+                                LogviewLog *old_log)
+{
+  if (window->priv->monitor_id) {
+    g_signal_handler_disconnect (old_log, window->priv->monitor_id);
+    window->priv->monitor_id = 0;
+  }
+
+  logview_set_search_visible (window, FALSE);
+}
+
+static void
 findbar_close_cb (LogviewFindbar *findbar,
                   gpointer user_data)
 {
   LogviewWindow *window = user_data;
-
-  g_action_group_change_action_state (G_ACTION_GROUP (window), "search",
-                                      g_variant_new_boolean (FALSE));
+  logview_set_search_visible (window, FALSE);
 }
 
 static void
@@ -764,11 +782,6 @@ read_new_lines_cb (LogviewLog *log,
 
   paint_timestamps (buffer, old_line_count, new_days);
 
-  if (window->priv->monitor_id == 0) {
-    window->priv->monitor_id = g_signal_connect (log, "log-changed",
-                                                 G_CALLBACK (log_monitor_changed_cb), window);
-  }
-
   logview_update_header (window, log, NULL);
   logview_loglist_update_lines (LOGVIEW_LOGLIST (window->priv->loglist), log);
 }
@@ -783,16 +796,9 @@ active_log_changed_cb (LogviewManager *manager,
   const char **lines;
   GtkTextBuffer *buffer;
 
-  findbar_close_cb (LOGVIEW_FINDBAR (window->priv->find_bar),
-                    window);
-
+  logview_clear_active_log_state (window, old_log);
   logview_update_header (window, log, NULL);
 
-  if (window->priv->monitor_id) {
-    g_signal_handler_disconnect (old_log, window->priv->monitor_id);
-    window->priv->monitor_id = 0;
-  }
-
   lines = logview_log_get_cached_lines (log);
   buffer = gtk_text_buffer_new (window->priv->tag_table);
 
@@ -813,13 +819,13 @@ active_log_changed_cb (LogviewManager *manager,
     paint_timestamps (buffer, 1, logview_log_get_days_for_cached_lines (log));
   }
 
+  window->priv->monitor_id =
+    g_signal_connect (log, "log-changed",
+                      G_CALLBACK (log_monitor_changed_cb), window);
+
   if (lines == NULL || logview_log_has_new_lines (log)) {
     /* read the new lines */
     logview_window_schedule_log_read (window, log);
-  } else {
-    /* start now monitoring the log for changes */
-    window->priv->monitor_id = g_signal_connect (log, "log-changed",
-                                                 G_CALLBACK (log_monitor_changed_cb), window);
   }
 
   /* we set the buffer to the view anyway;
@@ -1053,7 +1059,7 @@ action_close (GSimpleAction *action,
 {
   LogviewWindow *logview = user_data;
 
-  findbar_close_cb (LOGVIEW_FINDBAR (logview->priv->find_bar), logview);
+  logview_set_search_visible (logview, FALSE);
   logview_manager_close_active_log (logview->priv->manager);
 }
 


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