mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-09 22:50:54 +00:00
sysprof-ui: add missing filtering of processes
The search implementation here is pretty barebones, but at least it gets things working again after the fallout from the redesign. Fixes #15
This commit is contained in:
@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
#define G_LOG_DOMAIN "sysprof-profiler-assistant"
|
#define G_LOG_DOMAIN "sysprof-profiler-assistant"
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <sysprof.h>
|
#include <sysprof.h>
|
||||||
@ -28,6 +32,7 @@
|
|||||||
|
|
||||||
#include "sysprof-aid-icon.h"
|
#include "sysprof-aid-icon.h"
|
||||||
#include "sysprof-environ-editor.h"
|
#include "sysprof-environ-editor.h"
|
||||||
|
#include "sysprof-model-filter.h"
|
||||||
#include "sysprof-profiler-assistant.h"
|
#include "sysprof-profiler-assistant.h"
|
||||||
#include "sysprof-process-model-row.h"
|
#include "sysprof-process-model-row.h"
|
||||||
#include "sysprof-ui-private.h"
|
#include "sysprof-ui-private.h"
|
||||||
@ -44,10 +49,13 @@ struct _SysprofProfilerAssistant
|
|||||||
{
|
{
|
||||||
GtkBin parent_instance;
|
GtkBin parent_instance;
|
||||||
|
|
||||||
|
SysprofProcessModel *process_model;
|
||||||
|
|
||||||
/* Template Objects */
|
/* Template Objects */
|
||||||
GtkSwitch *allow_throttling;
|
GtkSwitch *allow_throttling;
|
||||||
GtkButton *record_button;
|
GtkButton *record_button;
|
||||||
GtkEntry *command_line;
|
GtkEntry *command_line;
|
||||||
|
GtkSearchEntry *search_entry;
|
||||||
GtkRevealer *process_revealer;
|
GtkRevealer *process_revealer;
|
||||||
GtkListBox *process_list_box;
|
GtkListBox *process_list_box;
|
||||||
SysprofEnvironEditor *environ_editor;
|
SysprofEnvironEditor *environ_editor;
|
||||||
@ -112,16 +120,14 @@ sysprof_profiler_assistant_notify_reveal_child_cb (SysprofProfilerAssistant *sel
|
|||||||
g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self));
|
g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self));
|
||||||
g_assert (GTK_IS_REVEALER (revealer));
|
g_assert (GTK_IS_REVEALER (revealer));
|
||||||
|
|
||||||
if (gtk_revealer_get_reveal_child (revealer))
|
if (self->process_model == NULL)
|
||||||
{
|
{
|
||||||
g_autoptr(SysprofProcessModel) model = NULL;
|
self->process_model = sysprof_process_model_new ();
|
||||||
|
|
||||||
model = sysprof_process_model_new ();
|
|
||||||
gtk_list_box_bind_model (self->process_list_box,
|
gtk_list_box_bind_model (self->process_list_box,
|
||||||
G_LIST_MODEL (model),
|
G_LIST_MODEL (self->process_model),
|
||||||
create_process_row_cb,
|
create_process_row_cb,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
sysprof_process_model_reload (model);
|
sysprof_process_model_reload (self->process_model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,11 +277,91 @@ sysprof_profiler_assistant_record_clicked_cb (SysprofProfilerAssistant *self,
|
|||||||
g_signal_emit (self, signals [START_RECORDING], 0, profiler);
|
g_signal_emit (self, signals [START_RECORDING], 0, profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
filter_by_search_text (GObject *object,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
SysprofProcessModelItem *item = SYSPROF_PROCESS_MODEL_ITEM (object);
|
||||||
|
const gchar *haystack;
|
||||||
|
const gchar * const *argv;
|
||||||
|
const gchar *text = user_data;
|
||||||
|
|
||||||
|
haystack = sysprof_process_model_item_get_command_line (item);
|
||||||
|
|
||||||
|
if (haystack)
|
||||||
|
{
|
||||||
|
if (strcasestr (haystack, text) != NULL)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
argv = sysprof_process_model_item_get_argv (item);
|
||||||
|
|
||||||
|
if (argv)
|
||||||
|
{
|
||||||
|
for (guint i = 0; argv[i]; i++)
|
||||||
|
{
|
||||||
|
if (strcasestr (argv[i], text) != NULL)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_profiler_assistant_search_changed_cb (SysprofProfilerAssistant *self,
|
||||||
|
GtkSearchEntry *search_entry)
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofModelFilter) filter = NULL;
|
||||||
|
const gchar *text;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self));
|
||||||
|
g_assert (GTK_IS_SEARCH_ENTRY (search_entry));
|
||||||
|
|
||||||
|
if (self->process_model == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sysprof_process_model_queue_reload (self->process_model);
|
||||||
|
|
||||||
|
text = gtk_entry_get_text (GTK_ENTRY (search_entry));
|
||||||
|
|
||||||
|
if (text[0] == 0)
|
||||||
|
{
|
||||||
|
gtk_list_box_bind_model (self->process_list_box,
|
||||||
|
G_LIST_MODEL (self->process_model),
|
||||||
|
create_process_row_cb,
|
||||||
|
NULL, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
filter = sysprof_model_filter_new (G_LIST_MODEL (self->process_model));
|
||||||
|
sysprof_model_filter_set_filter_func (filter,
|
||||||
|
filter_by_search_text,
|
||||||
|
g_strdup (text),
|
||||||
|
g_free);
|
||||||
|
gtk_list_box_bind_model (self->process_list_box,
|
||||||
|
G_LIST_MODEL (filter),
|
||||||
|
create_process_row_cb,
|
||||||
|
NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_profiler_assistant_destroy (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
SysprofProfilerAssistant *self = (SysprofProfilerAssistant *)widget;
|
||||||
|
|
||||||
|
g_clear_object (&self->process_model);
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (sysprof_profiler_assistant_parent_class)->destroy (widget);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass)
|
sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass)
|
||||||
{
|
{
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
|
widget_class->destroy = sysprof_profiler_assistant_destroy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SysprofProfilerAssistant::start-recording:
|
* SysprofProfilerAssistant::start-recording:
|
||||||
* @self: a #SysprofProfilerAssistant
|
* @self: a #SysprofProfilerAssistant
|
||||||
@ -302,6 +388,7 @@ sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass)
|
|||||||
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, whole_system_switch);
|
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, whole_system_switch);
|
||||||
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, launch_switch);
|
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, launch_switch);
|
||||||
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, inherit_switch);
|
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, inherit_switch);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, search_entry);
|
||||||
|
|
||||||
g_type_ensure (SYSPROF_TYPE_AID_ICON);
|
g_type_ensure (SYSPROF_TYPE_AID_ICON);
|
||||||
g_type_ensure (SYSPROF_TYPE_BATTERY_AID);
|
g_type_ensure (SYSPROF_TYPE_BATTERY_AID);
|
||||||
@ -352,6 +439,12 @@ sysprof_profiler_assistant_init (SysprofProfilerAssistant *self)
|
|||||||
self,
|
self,
|
||||||
G_CONNECT_SWAPPED);
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_signal_connect_object (self->search_entry,
|
||||||
|
"changed",
|
||||||
|
G_CALLBACK (sysprof_profiler_assistant_search_changed_cb),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
sysprof_environ_editor_set_environ (self->environ_editor, environ);
|
sysprof_environ_editor_set_environ (self->environ_editor, environ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -245,7 +245,7 @@
|
|||||||
<class name="linked"/>
|
<class name="linked"/>
|
||||||
</style>
|
</style>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSearchEntry">
|
<object class="GtkSearchEntry" id="search_entry">
|
||||||
<property name="placeholder-text" translatable="yes">Search Processes…</property>
|
<property name="placeholder-text" translatable="yes">Search Processes…</property>
|
||||||
<property name="visible">true</property>
|
<property name="visible">true</property>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
Reference in New Issue
Block a user