From 5d2b1c06a60c1e4f6c1f2f35d6681675639f8d0b Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 28 Jun 2023 14:53:52 -0700 Subject: [PATCH] libsysprof-gtk: start on SysprofTracksView This is eventually going to contain the list of tracks we have at the top of the analysis view. --- .../libsysprof-gtk.gresource.xml | 2 + src/libsysprof-gtk/meson.build | 6 + src/libsysprof-gtk/sysprof-gtk.h | 1 + src/libsysprof-gtk/sysprof-track-view.c | 148 +++++++++++++ src/libsysprof-gtk/sysprof-track-view.h | 42 ++++ src/libsysprof-gtk/sysprof-track-view.ui | 21 ++ src/libsysprof-gtk/sysprof-track.c | 117 ++++++++++ src/libsysprof-gtk/sysprof-track.h | 35 +++ src/libsysprof-gtk/sysprof-tracks-view.c | 159 ++++++++++++++ src/libsysprof-gtk/sysprof-tracks-view.h | 44 ++++ src/libsysprof-gtk/sysprof-tracks-view.ui | 38 ++++ src/libsysprof-gtk/tests/meson.build | 1 + src/libsysprof-gtk/tests/test-tracks.c | 207 ++++++++++++++++++ src/libsysprof-gtk/tests/test-tracks.ui | 21 ++ src/libsysprof-gtk/tests/tests.gresource.xml | 1 + 15 files changed, 843 insertions(+) create mode 100644 src/libsysprof-gtk/sysprof-track-view.c create mode 100644 src/libsysprof-gtk/sysprof-track-view.h create mode 100644 src/libsysprof-gtk/sysprof-track-view.ui create mode 100644 src/libsysprof-gtk/sysprof-track.c create mode 100644 src/libsysprof-gtk/sysprof-track.h create mode 100644 src/libsysprof-gtk/sysprof-tracks-view.c create mode 100644 src/libsysprof-gtk/sysprof-tracks-view.h create mode 100644 src/libsysprof-gtk/sysprof-tracks-view.ui create mode 100644 src/libsysprof-gtk/tests/test-tracks.c create mode 100644 src/libsysprof-gtk/tests/test-tracks.ui diff --git a/src/libsysprof-gtk/libsysprof-gtk.gresource.xml b/src/libsysprof-gtk/libsysprof-gtk.gresource.xml index eae0adf8..f4a262be 100644 --- a/src/libsysprof-gtk/libsysprof-gtk.gresource.xml +++ b/src/libsysprof-gtk/libsysprof-gtk.gresource.xml @@ -5,6 +5,8 @@ sysprof-mark-chart.ui sysprof-mark-chart-row.ui sysprof-mark-table.ui + sysprof-track-view.ui + sysprof-tracks-view.ui sysprof-weighted-callgraph-view.ui style.css diff --git a/src/libsysprof-gtk/meson.build b/src/libsysprof-gtk/meson.build index df73114b..c43b3e8c 100644 --- a/src/libsysprof-gtk/meson.build +++ b/src/libsysprof-gtk/meson.build @@ -19,6 +19,9 @@ libsysprof_gtk_public_sources = [ 'sysprof-time-span-layer.c', 'sysprof-time-series.c', 'sysprof-time-series-item.c', + 'sysprof-track.c', + 'sysprof-track-view.c', + 'sysprof-tracks-view.c', 'sysprof-value-axis.c', 'sysprof-weighted-callgraph-view.c', 'sysprof-xy-layer.c', @@ -49,6 +52,9 @@ libsysprof_gtk_public_headers = [ 'sysprof-time-series.h', 'sysprof-time-series-item.h', 'sysprof-time-span-layer.h', + 'sysprof-track.h', + 'sysprof-track-view.h', + 'sysprof-tracks-view.h', 'sysprof-weighted-callgraph-view.h', 'sysprof-value-axis.h', 'sysprof-xy-layer.h', diff --git a/src/libsysprof-gtk/sysprof-gtk.h b/src/libsysprof-gtk/sysprof-gtk.h index ea810380..d8a4488b 100644 --- a/src/libsysprof-gtk/sysprof-gtk.h +++ b/src/libsysprof-gtk/sysprof-gtk.h @@ -43,6 +43,7 @@ G_BEGIN_DECLS # include "sysprof-time-series.h" # include "sysprof-time-series-item.h" # include "sysprof-time-span-layer.h" +# include "sysprof-tracks-view.h" # include "sysprof-value-axis.h" # include "sysprof-weighted-callgraph-view.h" # include "sysprof-xy-layer.h" diff --git a/src/libsysprof-gtk/sysprof-track-view.c b/src/libsysprof-gtk/sysprof-track-view.c new file mode 100644 index 00000000..059e9d7f --- /dev/null +++ b/src/libsysprof-gtk/sysprof-track-view.c @@ -0,0 +1,148 @@ +/* sysprof-track-view.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-track-view.h" + +struct _SysprofTrackView +{ + GtkWidget parent_instance; + SysprofTrack *track; +}; + +enum { + PROP_0, + PROP_TRACK, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofTrackView, sysprof_track_view, GTK_TYPE_WIDGET) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_track_view_dispose (GObject *object) +{ + SysprofTrackView *self = (SysprofTrackView *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_TRACK_VIEW); + + g_clear_object (&self->track); + + G_OBJECT_CLASS (sysprof_track_view_parent_class)->dispose (object); +} + +static void +sysprof_track_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofTrackView *self = SYSPROF_TRACK_VIEW (object); + + switch (prop_id) + { + case PROP_TRACK: + g_value_set_object (value, sysprof_track_view_get_track (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_track_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofTrackView *self = SYSPROF_TRACK_VIEW (object); + + switch (prop_id) + { + case PROP_TRACK: + sysprof_track_view_set_track (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_track_view_class_init (SysprofTrackViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_track_view_dispose; + object_class->get_property = sysprof_track_view_get_property; + object_class->set_property = sysprof_track_view_set_property; + + properties[PROP_TRACK] = + g_param_spec_object ("track", NULL, NULL, + SYSPROF_TYPE_TRACK, + (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_template_from_resource (widget_class, "/libsysprof-gtk/sysprof-track-view.ui"); + + g_type_ensure (SYSPROF_TYPE_TRACK); +} + +static void +sysprof_track_view_init (SysprofTrackView *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +GtkWidget * +sysprof_track_view_new (void) +{ + return g_object_new (SYSPROF_TYPE_TRACK_VIEW, NULL); +} + +/** + * sysprof_track_view_get_track: + * @self: a #SysprofTrackView + * + * Returns: (transfer none) (nullable): A #SysprofTrack or %NULL + */ +SysprofTrack * +sysprof_track_view_get_track (SysprofTrackView *self) +{ + g_return_val_if_fail (SYSPROF_IS_TRACK_VIEW (self), NULL); + + return self->track; +} + +void +sysprof_track_view_set_track (SysprofTrackView *self, + SysprofTrack *track) +{ + g_return_if_fail (SYSPROF_IS_TRACK_VIEW (self)); + g_return_if_fail (!track || SYSPROF_IS_TRACK (track)); + + if (g_set_object (&self->track, track)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TRACK]); +} diff --git a/src/libsysprof-gtk/sysprof-track-view.h b/src/libsysprof-gtk/sysprof-track-view.h new file mode 100644 index 00000000..5496f0aa --- /dev/null +++ b/src/libsysprof-gtk/sysprof-track-view.h @@ -0,0 +1,42 @@ +/* sysprof-track-view.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 "sysprof-track.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_TRACK_VIEW (sysprof_track_view_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofTrackView, sysprof_track_view, SYSPROF, TRACK_VIEW, GtkWidget) + +SYSPROF_AVAILABLE_IN_ALL +GtkWidget *sysprof_track_view_new (void); +SYSPROF_AVAILABLE_IN_ALL +SysprofTrack *sysprof_track_view_get_track (SysprofTrackView *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_track_view_set_track (SysprofTrackView *self, + SysprofTrack *track); + +G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-track-view.ui b/src/libsysprof-gtk/sysprof-track-view.ui new file mode 100644 index 00000000..7b2bfa3f --- /dev/null +++ b/src/libsysprof-gtk/sysprof-track-view.ui @@ -0,0 +1,21 @@ + + + + diff --git a/src/libsysprof-gtk/sysprof-track.c b/src/libsysprof-gtk/sysprof-track.c new file mode 100644 index 00000000..644118bd --- /dev/null +++ b/src/libsysprof-gtk/sysprof-track.c @@ -0,0 +1,117 @@ +/* sysprof-track.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-track.h" + +struct _SysprofTrack +{ + GObject parent_instance; + char *title; +}; + +enum { + PROP_0, + PROP_TITLE, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofTrack, sysprof_track, G_TYPE_OBJECT) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_track_dispose (GObject *object) +{ + SysprofTrack *self = (SysprofTrack *)object; + + g_clear_pointer (&self->title, g_free); + + G_OBJECT_CLASS (sysprof_track_parent_class)->dispose (object); +} + +static void +sysprof_track_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofTrack *self = SYSPROF_TRACK (object); + + switch (prop_id) + { + case PROP_TITLE: + g_value_set_string (value, sysprof_track_get_title (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_track_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofTrack *self = SYSPROF_TRACK (object); + + switch (prop_id) + { + case PROP_TITLE: + self->title = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_track_class_init (SysprofTrackClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = sysprof_track_dispose; + object_class->get_property = sysprof_track_get_property; + object_class->set_property = sysprof_track_set_property; + + 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); +} + +static void +sysprof_track_init (SysprofTrack *self) +{ +} + +const char * +sysprof_track_get_title (SysprofTrack *self) +{ + g_return_val_if_fail (SYSPROF_IS_TRACK (self), NULL); + + return self->title; +} diff --git a/src/libsysprof-gtk/sysprof-track.h b/src/libsysprof-gtk/sysprof-track.h new file mode 100644 index 00000000..0ae28f40 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-track.h @@ -0,0 +1,35 @@ +/* sysprof-track.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 + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_TRACK (sysprof_track_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofTrack, sysprof_track, SYSPROF, TRACK, GObject) + +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_track_get_title (SysprofTrack *self); + +G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-tracks-view.c b/src/libsysprof-gtk/sysprof-tracks-view.c new file mode 100644 index 00000000..caa25681 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-tracks-view.c @@ -0,0 +1,159 @@ +/* sysprof-tracks-view.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-css-private.h" +#include "sysprof-track-view.h" +#include "sysprof-tracks-view.h" + +struct _SysprofTracksView +{ + GtkWidget parent_instance; + SysprofSession *session; +}; + +enum { + PROP_0, + PROP_SESSION, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofTracksView, sysprof_tracks_view, GTK_TYPE_WIDGET) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_tracks_view_dispose (GObject *object) +{ + SysprofTracksView *self = (SysprofTracksView *)object; + GtkWidget *child; + + g_clear_object (&self->session); + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_TRACKS_VIEW); + + while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) + gtk_widget_unparent (child); + + G_OBJECT_CLASS (sysprof_tracks_view_parent_class)->dispose (object); +} + +static void +sysprof_tracks_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofTracksView *self = SYSPROF_TRACKS_VIEW (object); + + switch (prop_id) + { + case PROP_SESSION: + g_value_set_object (value, sysprof_tracks_view_get_session (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_tracks_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofTracksView *self = SYSPROF_TRACKS_VIEW (object); + + switch (prop_id) + { + case PROP_SESSION: + sysprof_tracks_view_set_session (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_tracks_view_class_init (SysprofTracksViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_tracks_view_dispose; + object_class->get_property = sysprof_tracks_view_get_property; + object_class->set_property = sysprof_tracks_view_set_property; + + properties[PROP_SESSION] = + g_param_spec_object ("session", NULL, NULL, + SYSPROF_TYPE_SESSION, + (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_template_from_resource (widget_class, "/libsysprof-gtk/sysprof-tracks-view.ui"); + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); + + g_type_ensure (SYSPROF_TYPE_TRACK_VIEW); +} + +static void +sysprof_tracks_view_init (SysprofTracksView *self) +{ + _sysprof_css_init (); + + gtk_widget_init_template (GTK_WIDGET (self)); +} + +GtkWidget * +sysprof_tracks_view_new (void) +{ + return g_object_new (SYSPROF_TYPE_TRACKS_VIEW, NULL); +} + +/** + * sysprof_tracks_view_get_session: + * @self: a #SysprofTracksView + * + * Gets the session for the tracks. + * + * Returns: (transfer none) (nullable): a #SysprofSession or %NULL + */ +SysprofSession * +sysprof_tracks_view_get_session (SysprofTracksView *self) +{ + g_return_val_if_fail (SYSPROF_IS_TRACKS_VIEW (self), NULL); + + return self->session; +} + +void +sysprof_tracks_view_set_session (SysprofTracksView *self, + SysprofSession *session) +{ + g_return_if_fail (SYSPROF_IS_TRACKS_VIEW (self)); + g_return_if_fail (!session || SYSPROF_IS_SESSION (session)); + + if (g_set_object (&self->session, session)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SESSION]); +} diff --git a/src/libsysprof-gtk/sysprof-tracks-view.h b/src/libsysprof-gtk/sysprof-tracks-view.h new file mode 100644 index 00000000..459bb9b9 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-tracks-view.h @@ -0,0 +1,44 @@ +/* sysprof-tracks-view.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 + +#include "sysprof-session.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_TRACKS_VIEW (sysprof_tracks_view_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofTracksView, sysprof_tracks_view, SYSPROF, TRACKS_VIEW, GtkWidget) + +SYSPROF_AVAILABLE_IN_ALL +GtkWidget *sysprof_tracks_view_new (void); +SYSPROF_AVAILABLE_IN_ALL +SysprofSession *sysprof_tracks_view_get_session (SysprofTracksView *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_tracks_view_set_session (SysprofTracksView *self, + SysprofSession *session); + +G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-tracks-view.ui b/src/libsysprof-gtk/sysprof-tracks-view.ui new file mode 100644 index 00000000..c6a9bbc9 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-tracks-view.ui @@ -0,0 +1,38 @@ + + + + diff --git a/src/libsysprof-gtk/tests/meson.build b/src/libsysprof-gtk/tests/meson.build index 091a7ea1..20e8a988 100644 --- a/src/libsysprof-gtk/tests/meson.build +++ b/src/libsysprof-gtk/tests/meson.build @@ -14,6 +14,7 @@ libsysprof_gtk_testsuite_c_args = [ libsysprof_gtk_testsuite = { 'test-callgraph' : {'skip': true}, 'test-charts' : {'skip': true}, + 'test-tracks' : {'skip': true}, 'test-mark-chart' : {'skip': true}, 'test-mark-table' : {'skip': true}, } diff --git a/src/libsysprof-gtk/tests/test-tracks.c b/src/libsysprof-gtk/tests/test-tracks.c new file mode 100644 index 00000000..b7f65182 --- /dev/null +++ b/src/libsysprof-gtk/tests/test-tracks.c @@ -0,0 +1,207 @@ +/* test-tracks.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 + +#include +#include + +static GMainLoop *main_loop; +static char *filename; +static const GOptionEntry entries[] = { + { 0 } +}; + +#define TEST_TYPE_TRACKS (test_tracks_get_type()) +G_DECLARE_FINAL_TYPE (TestTracks, test_tracks, TEST, TRACKS, AdwWindow) + +struct _TestTracks +{ + AdwWindow parent_instance; + + SysprofDocument *document; + SysprofSession *session; +}; + +G_DEFINE_FINAL_TYPE (TestTracks, test_tracks, ADW_TYPE_WINDOW) + +enum { + PROP_0, + PROP_DOCUMENT, + PROP_SESSION, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +static void +test_tracks_set_document (TestTracks *self, + SysprofDocument *document) +{ + if (g_set_object (&self->document, document)) + { + g_clear_object (&self->session); + + self->session = sysprof_session_new (self->document); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DOCUMENT]); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SESSION]); + } +} + +static void +test_tracks_dispose (GObject *object) +{ + TestTracks *self = (TestTracks *)object; + + g_clear_object (&self->document); + g_clear_object (&self->session); + + G_OBJECT_CLASS (test_tracks_parent_class)->dispose (object); +} + +static void +test_tracks_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + TestTracks *self = TEST_TRACKS (object); + + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, self->document); + break; + + case PROP_SESSION: + g_value_set_object (value, self->session); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +test_tracks_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + TestTracks *self = TEST_TRACKS (object); + + switch (prop_id) + { + case PROP_DOCUMENT: + test_tracks_set_document (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +test_tracks_class_init (TestTracksClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = test_tracks_dispose; + object_class->get_property = test_tracks_get_property; + object_class->set_property = test_tracks_set_property; + + properties [PROP_DOCUMENT] = + g_param_spec_object ("document", NULL, NULL, + SYSPROF_TYPE_DOCUMENT, + (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + properties [PROP_SESSION] = + g_param_spec_object ("session", NULL, NULL, + SYSPROF_TYPE_SESSION, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/test-tracks.ui"); + + g_type_ensure (SYSPROF_TYPE_TRACKS_VIEW); +} + +static void +test_tracks_init (TestTracks *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +int +main (int argc, + char *argv[]) +{ + g_autoptr(GOptionContext) context = g_option_context_new ("- test track layout"); + g_autoptr(SysprofDocumentLoader) loader = NULL; + g_autoptr(SysprofDocument) document = NULL; + g_autoptr(GError) error = NULL; + GtkWindow *window; + + sysprof_clock_init (); + + gtk_init (); + adw_init (); + + g_option_context_add_main_entries (context, entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("%s\n", error->message); + return 1; + } + + if (argc != 2) + { + g_print ("usage: %s [OPTIONS] CAPTURE_FILE\n", argv[0]); + return 1; + } + + filename = argv[1]; + + main_loop = g_main_loop_new (NULL, FALSE); + + loader = sysprof_document_loader_new (filename); + if (!(document = sysprof_document_loader_load (loader, NULL, &error))) + g_error ("Failed to load document: %s", error->message); + + window = g_object_new (TEST_TYPE_TRACKS, + "default-width", 800, + "default-height", 600, + "document", document, + NULL); + g_signal_connect_swapped (window, + "close-request", + G_CALLBACK (g_main_loop_quit), + main_loop); + gtk_window_present (window); + g_main_loop_run (main_loop); + + return 0; +} diff --git a/src/libsysprof-gtk/tests/test-tracks.ui b/src/libsysprof-gtk/tests/test-tracks.ui new file mode 100644 index 00000000..7b4730df --- /dev/null +++ b/src/libsysprof-gtk/tests/test-tracks.ui @@ -0,0 +1,21 @@ + + + + diff --git a/src/libsysprof-gtk/tests/tests.gresource.xml b/src/libsysprof-gtk/tests/tests.gresource.xml index a41b9c5c..a3af5faf 100644 --- a/src/libsysprof-gtk/tests/tests.gresource.xml +++ b/src/libsysprof-gtk/tests/tests.gresource.xml @@ -2,5 +2,6 @@ test-charts.ui + test-tracks.ui