From ac9a95a92b4b770c7453de55668397b0aa10b417 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 16 Jun 2023 15:52:39 -0700 Subject: [PATCH] libsysprof-gtk: add sysprof_session_select_time() This allows changing the time to a specific section within the document time span. It may also update the visible time to include the selected time. --- src/libsysprof-gtk/sysprof-session.c | 39 +++++++++++++++++++++++++++- src/libsysprof-gtk/sysprof-session.h | 13 ++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/libsysprof-gtk/sysprof-session.c b/src/libsysprof-gtk/sysprof-session.c index 2a4dbbe8..cd87bc92 100644 --- a/src/libsysprof-gtk/sysprof-session.c +++ b/src/libsysprof-gtk/sysprof-session.c @@ -27,7 +27,7 @@ struct _SysprofSession GObject parent_instance; SysprofDocument *document; - GtkCustomFilter *filter; + GtkEveryFilter *filter; SysprofTimeSpan selected_time; SysprofTimeSpan visible_time; @@ -155,6 +155,7 @@ sysprof_session_class_init (SysprofSessionClass *klass) static void sysprof_session_init (SysprofSession *self) { + self->filter = gtk_every_filter_new (); } SysprofSession * @@ -213,3 +214,39 @@ sysprof_session_get_visible_time (SysprofSession *self) return &self->visible_time; } + +void +sysprof_session_select_time (SysprofSession *self, + const SysprofTimeSpan *time_span) +{ + SysprofTimeSpan document_time_span; + gboolean emit_for_visible = FALSE; + + g_return_if_fail (SYSPROF_IS_SESSION (self)); + + g_print ("Select range!\n"); + + document_time_span = *sysprof_document_get_time_span (self->document); + + if (time_span == NULL) + time_span = &document_time_span; + + self->selected_time = *time_span; + + if (self->visible_time.begin_nsec > time_span->begin_nsec) + { + self->visible_time.begin_nsec = time_span->begin_nsec; + emit_for_visible = TRUE; + } + + if (self->visible_time.end_nsec < time_span->end_nsec) + { + self->visible_time.end_nsec = time_span->end_nsec; + emit_for_visible = TRUE; + } + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_TIME]); + + if (emit_for_visible) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VISIBLE_TIME]); +} diff --git a/src/libsysprof-gtk/sysprof-session.h b/src/libsysprof-gtk/sysprof-session.h index a9c27895..c77e1447 100644 --- a/src/libsysprof-gtk/sysprof-session.h +++ b/src/libsysprof-gtk/sysprof-session.h @@ -34,14 +34,17 @@ SYSPROF_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (SysprofSession, sysprof_session, SYSPROF, SESSION, GObject) SYSPROF_AVAILABLE_IN_ALL -SysprofSession *sysprof_session_new (SysprofDocument *document); +SysprofSession *sysprof_session_new (SysprofDocument *document); SYSPROF_AVAILABLE_IN_ALL -SysprofDocument *sysprof_session_get_document (SysprofSession *self); +SysprofDocument *sysprof_session_get_document (SysprofSession *self); SYSPROF_AVAILABLE_IN_ALL -GtkFilter *sysprof_session_get_filter (SysprofSession *self); +GtkFilter *sysprof_session_get_filter (SysprofSession *self); SYSPROF_AVAILABLE_IN_ALL -const SysprofTimeSpan *sysprof_session_get_selected_time (SysprofSession *self); +const SysprofTimeSpan *sysprof_session_get_selected_time (SysprofSession *self); SYSPROF_AVAILABLE_IN_ALL -const SysprofTimeSpan *sysprof_session_get_visible_time (SysprofSession *self); +const SysprofTimeSpan *sysprof_session_get_visible_time (SysprofSession *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_session_select_time (SysprofSession *self, + const SysprofTimeSpan *time_span); G_END_DECLS