[sysprof] profiler-menu-button: simplify filtering code



commit bcb43d39bbaefb2845dbba9174e6d4b205495fa1
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 24 22:00:20 2017 -0800

    profiler-menu-button: simplify filtering code
    
    Instead of fetching the text from the filter func, we can just
    reset the filter func with custom data.

 lib/widgets/sp-profiler-menu-button.c |   54 ++++++++++++++++----------------
 1 files changed, 27 insertions(+), 27 deletions(-)
---
diff --git a/lib/widgets/sp-profiler-menu-button.c b/lib/widgets/sp-profiler-menu-button.c
index 942d241..f0c77fa 100644
--- a/lib/widgets/sp-profiler-menu-button.c
+++ b/lib/widgets/sp-profiler-menu-button.c
@@ -356,42 +356,44 @@ sp_profiler_menu_button_clicked (GtkButton *button)
   GTK_BUTTON_CLASS (sp_profiler_menu_button_parent_class)->clicked (button);
 }
 
-static void
-sp_profiler_menu_button_filter_changed (SpProfilerMenuButton *self,
-                                        GtkEntry             *entry)
-{
-  SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
-
-  g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
-  g_assert (GTK_IS_ENTRY (entry));
-
-  sp_model_filter_invalidate (priv->process_filter);
-}
-
 static gboolean
 sp_profiler_menu_button_filter_func (GObject  *object,
                                      gpointer  user_data)
 {
-  SpProfilerMenuButton *self = user_data;
-  SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
-  const gchar *cmdline;
-  const gchar *text;
-  gboolean ret;
+  const gchar *needle = user_data;
+  const gchar *haystack;
 
-  g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
   g_assert (SP_IS_PROCESS_MODEL_ITEM (object));
 
-  text = gtk_entry_get_text (priv->process_filter_entry);
-  if (!text || !*text)
+  if (needle == NULL)
     return TRUE;
 
-  cmdline = sp_process_model_item_get_command_line (SP_PROCESS_MODEL_ITEM (object));
-  if (!cmdline)
+  haystack = sp_process_model_item_get_command_line (SP_PROCESS_MODEL_ITEM (object));
+
+  if (haystack == NULL)
     return FALSE;
 
-  ret = (strstr (cmdline, text) != NULL);
+  return strstr (haystack, needle) != NULL;
+}
+
+static void
+sp_profiler_menu_button_filter_changed (SpProfilerMenuButton *self,
+                                        GtkEntry             *entry)
+{
+  SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
+  const gchar *text;
 
-  return ret;
+  g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
+  g_assert (GTK_IS_ENTRY (entry));
+
+  text = gtk_entry_get_text (entry);
+  if (text && *text == 0)
+    text = NULL;
+
+  sp_model_filter_set_filter_func (priv->process_filter,
+                                   sp_profiler_menu_button_filter_func,
+                                   g_strdup (text),
+                                   g_free);
 }
 
 static void
@@ -403,9 +405,7 @@ sp_profiler_menu_button_constructed (GObject *object)
   g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
 
   priv->process_filter = sp_model_filter_new (G_LIST_MODEL (priv->process_model));
-  sp_model_filter_set_filter_func (priv->process_filter,
-                                   sp_profiler_menu_button_filter_func,
-                                   self, NULL);
+
   gtk_list_box_bind_model (priv->process_list_box,
                            G_LIST_MODEL (priv->process_filter),
                            sp_profiler_menu_button_create_row,


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