From 64ec182d44ff01562e4948cf5bcc7281299b0988 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sat, 8 Jul 2023 17:38:20 -0700 Subject: [PATCH] sysprof: start on section abstraction --- src/sysprof/meson.build | 2 + src/sysprof/sysprof-samples-section.c | 64 +++++++++ src/sysprof/sysprof-samples-section.h | 31 +++++ src/sysprof/sysprof-samples-section.ui | 16 +++ src/sysprof/sysprof-section.c | 182 +++++++++++++++++++++++++ src/sysprof/sysprof-section.h | 43 ++++++ src/sysprof/sysprof-window.c | 2 + src/sysprof/sysprof-window.ui | 7 +- src/sysprof/sysprof.gresource.xml | 1 + 9 files changed, 346 insertions(+), 2 deletions(-) create mode 100644 src/sysprof/sysprof-samples-section.c create mode 100644 src/sysprof/sysprof-samples-section.h create mode 100644 src/sysprof/sysprof-samples-section.ui create mode 100644 src/sysprof/sysprof-section.c create mode 100644 src/sysprof/sysprof-section.h diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 10504714..ca3bb557 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -5,6 +5,8 @@ sysprof_sources = [ 'sysprof-greeter.c', 'sysprof-recording-pad.c', 'sysprof-metadata-dialog.c', + 'sysprof-samples-section.c', + 'sysprof-section.c', 'sysprof-window.c', ] diff --git a/src/sysprof/sysprof-samples-section.c b/src/sysprof/sysprof-samples-section.c new file mode 100644 index 00000000..d8efb01b --- /dev/null +++ b/src/sysprof/sysprof-samples-section.c @@ -0,0 +1,64 @@ +/* sysprof-samples-section.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include + +#include "sysprof-samples-section.h" + +struct _SysprofSamplesSection +{ + SysprofSection parent_instance; + + SysprofWeightedCallgraphView *callgraph_view; +}; + +G_DEFINE_FINAL_TYPE (SysprofSamplesSection, sysprof_samples_section, SYSPROF_TYPE_SECTION) + +static void +sysprof_samples_section_dispose (GObject *object) +{ + SysprofSamplesSection *self = (SysprofSamplesSection *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_SAMPLES_SECTION); + + G_OBJECT_CLASS (sysprof_samples_section_parent_class)->dispose (object); +} + +static void +sysprof_samples_section_class_init (SysprofSamplesSectionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_samples_section_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-samples-section.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofSamplesSection, callgraph_view); + + g_type_ensure (SYSPROF_TYPE_WEIGHTED_CALLGRAPH_VIEW); +} + +static void +sysprof_samples_section_init (SysprofSamplesSection *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/sysprof/sysprof-samples-section.h b/src/sysprof/sysprof-samples-section.h new file mode 100644 index 00000000..320f3216 --- /dev/null +++ b/src/sysprof/sysprof-samples-section.h @@ -0,0 +1,31 @@ +/* sysprof-samples-section.h + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "sysprof-section.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_SAMPLES_SECTION (sysprof_samples_section_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofSamplesSection, sysprof_samples_section, SYSPROF, SAMPLES_SECTION, SysprofSection) + +G_END_DECLS diff --git a/src/sysprof/sysprof-samples-section.ui b/src/sysprof/sysprof-samples-section.ui new file mode 100644 index 00000000..5bf2c236 --- /dev/null +++ b/src/sysprof/sysprof-samples-section.ui @@ -0,0 +1,16 @@ + + + + diff --git a/src/sysprof/sysprof-section.c b/src/sysprof/sysprof-section.c new file mode 100644 index 00000000..085908dd --- /dev/null +++ b/src/sysprof/sysprof-section.c @@ -0,0 +1,182 @@ +/* sysprof-section.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-section.h" +#include "sysprof-window.h" + +typedef struct +{ + char *title; +} SysprofSectionPrivate; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SysprofSection, sysprof_section, GTK_TYPE_WIDGET) + +enum { + PROP_0, + PROP_SESSION, + PROP_TITLE, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_section_root (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (sysprof_section_parent_class)->root (widget); + + g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SESSION]); +} + +static void +sysprof_section_unroot (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (sysprof_section_parent_class)->unroot (widget); + + g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SESSION]); +} + +static void +sysprof_section_dispose (GObject *object) +{ + SysprofSection *self = (SysprofSection *)object; + SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self); + GtkWidget *child; + + g_clear_pointer (&priv->title, g_free); + + while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) + gtk_widget_unparent (child); + + G_OBJECT_CLASS (sysprof_section_parent_class)->dispose (object); +} + +static void +sysprof_section_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofSection *self = SYSPROF_SECTION (object); + + switch (prop_id) + { + case PROP_SESSION: + g_value_set_object (value, sysprof_section_get_session (self)); + break; + + case PROP_TITLE: + g_value_set_string (value, sysprof_section_get_title (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_section_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofSection *self = SYSPROF_SECTION (object); + + switch (prop_id) + { + case PROP_TITLE: + sysprof_section_set_title (self, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_section_class_init (SysprofSectionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_section_dispose; + object_class->get_property = sysprof_section_get_property; + object_class->set_property = sysprof_section_set_property; + + widget_class->root = sysprof_section_root; + widget_class->unroot = sysprof_section_unroot; + + properties[PROP_SESSION] = + g_param_spec_object ("session", NULL, NULL, + SYSPROF_TYPE_SESSION, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_TITLE] = + g_param_spec_string ("title", NULL, NULL, + NULL, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); +} + +static void +sysprof_section_init (SysprofSection *self) +{ +} + +SysprofSession * +sysprof_section_get_session (SysprofSection *self) +{ + GtkRoot *root; + + if ((root = gtk_widget_get_root (GTK_WIDGET (self)))) + { + if (SYSPROF_IS_WINDOW (root)) + return sysprof_window_get_session (SYSPROF_WINDOW (root)); + } + + return NULL; +} + +const char * +sysprof_section_get_title (SysprofSection *self) +{ + SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self); + + g_return_val_if_fail (SYSPROF_IS_SECTION (self), NULL); + + return priv->title; +} + +void +sysprof_section_set_title (SysprofSection *self, + const char *title) +{ + SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self); + + g_return_if_fail (SYSPROF_IS_SECTION (self)); + + if (g_set_str (&priv->title, title)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]); +} diff --git a/src/sysprof/sysprof-section.h b/src/sysprof/sysprof-section.h new file mode 100644 index 00000000..1be34793 --- /dev/null +++ b/src/sysprof/sysprof-section.h @@ -0,0 +1,43 @@ +/* sysprof-section.h + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_SECTION (sysprof_section_get_type()) + +G_DECLARE_DERIVABLE_TYPE (SysprofSection, sysprof_section, SYSPROF, SECTION, GtkWidget) + +struct _SysprofSectionClass +{ + GtkWidgetClass parent_class; +}; + +SysprofSession *sysprof_section_get_session (SysprofSection *self); +const char *sysprof_section_get_title (SysprofSection *self); +void sysprof_section_set_title (SysprofSection *self, + const char *title); + +G_END_DECLS diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index da87a2f2..46de4c76 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -27,6 +27,7 @@ #include "sysprof-files-dialog.h" #include "sysprof-greeter.h" #include "sysprof-metadata-dialog.h" +#include "sysprof-samples-section.h" #include "sysprof-window.h" struct _SysprofWindow @@ -195,6 +196,7 @@ sysprof_window_class_init (SysprofWindowClass *klass) g_type_ensure (SYSPROF_TYPE_DOCUMENT); g_type_ensure (SYSPROF_TYPE_SESSION); + g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION); } static void diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index 93760f8e..3a5e06c2 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -94,9 +94,12 @@ - - vertical + true + + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index dfd45854..ad6af707 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -7,6 +7,7 @@ sysprof-greeter.ui sysprof-metadata-dialog.ui sysprof-recording-pad.ui + sysprof-samples-section.ui sysprof-window.ui