From afc88890cec3c881a61c4bf9997cc3d15aaf44ea Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 9 Jul 2023 15:01:18 -0700 Subject: [PATCH] sysprof: add logs section to sidebar --- src/sysprof/meson.build | 5 +- src/sysprof/sysprof-logs-section.c | 93 ++++++++++++++ src/sysprof/sysprof-logs-section.h | 32 +++++ src/sysprof/sysprof-logs-section.ui | 182 ++++++++++++++++++++++++++++ src/sysprof/sysprof-window.c | 2 + src/sysprof/sysprof-window.ui | 7 ++ src/sysprof/sysprof.gresource.xml | 1 + 7 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 src/sysprof/sysprof-logs-section.c create mode 100644 src/sysprof/sysprof-logs-section.h create mode 100644 src/sysprof/sysprof-logs-section.ui diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 246ad412..fa3aa44e 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -3,11 +3,12 @@ sysprof_sources = [ 'sysprof-application.c', 'sysprof-files-dialog.c', 'sysprof-greeter.c', - 'sysprof-recording-pad.c', + 'sysprof-logs-section.c', 'sysprof-metadata-dialog.c', + 'sysprof-recording-pad.c', 'sysprof-samples-section.c', - 'sysprof-sidebar.c', 'sysprof-section.c', + 'sysprof-sidebar.c', 'sysprof-window.c', ] diff --git a/src/sysprof/sysprof-logs-section.c b/src/sysprof/sysprof-logs-section.c new file mode 100644 index 00000000..cdd816be --- /dev/null +++ b/src/sysprof/sysprof-logs-section.c @@ -0,0 +1,93 @@ +/* sysprof-logs-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 + +#include "sysprof-logs-section.h" + +struct _SysprofLogsSection +{ + SysprofSection parent_instance; + + GtkColumnView *column_view; +}; + +G_DEFINE_FINAL_TYPE (SysprofLogsSection, sysprof_logs_section, SYSPROF_TYPE_SECTION) + +static char * +format_severity (gpointer unused, + GLogLevelFlags severity) +{ + if (severity & G_LOG_LEVEL_CRITICAL) + return g_strdup (_("Critical")); + + if (severity & G_LOG_LEVEL_WARNING) + return g_strdup (_("Warning")); + + if (severity & G_LOG_LEVEL_DEBUG) + return g_strdup (_("Debug")); + + if (severity & G_LOG_LEVEL_MESSAGE) + return g_strdup (_("Message")); + + if (severity & G_LOG_LEVEL_INFO) + return g_strdup (_("Info")); + + if (severity & G_LOG_LEVEL_ERROR) + return g_strdup (_("Error")); + + return g_strdup (""); +} + +static void +sysprof_logs_section_dispose (GObject *object) +{ + SysprofLogsSection *self = (SysprofLogsSection *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_LOGS_SECTION); + + G_OBJECT_CLASS (sysprof_logs_section_parent_class)->dispose (object); +} + +static void +sysprof_logs_section_class_init (SysprofLogsSectionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_logs_section_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-logs-section.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofLogsSection, column_view); + gtk_widget_class_bind_template_callback (widget_class, format_severity); + + g_type_ensure (SYSPROF_TYPE_DOCUMENT_LOG); + g_type_ensure (SYSPROF_TYPE_TIME_LABEL); +} + +static void +sysprof_logs_section_init (SysprofLogsSection *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/sysprof/sysprof-logs-section.h b/src/sysprof/sysprof-logs-section.h new file mode 100644 index 00000000..32d9a884 --- /dev/null +++ b/src/sysprof/sysprof-logs-section.h @@ -0,0 +1,32 @@ +/* sysprof-logs-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_LOGS_SECTION (sysprof_logs_section_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofLogsSection, sysprof_logs_section, SYSPROF, LOGS_SECTION, SysprofSection) + +G_END_DECLS + diff --git a/src/sysprof/sysprof-logs-section.ui b/src/sysprof/sysprof-logs-section.ui new file mode 100644 index 00000000..8b36cd21 --- /dev/null +++ b/src/sysprof/sysprof-logs-section.ui @@ -0,0 +1,182 @@ + + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index 5bfee181..31e11c7e 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -26,6 +26,7 @@ #include "sysprof-files-dialog.h" #include "sysprof-greeter.h" +#include "sysprof-logs-section.h" #include "sysprof-metadata-dialog.h" #include "sysprof-samples-section.h" #include "sysprof-sidebar.h" @@ -198,6 +199,7 @@ sysprof_window_class_init (SysprofWindowClass *klass) gtk_widget_class_install_action (widget_class, "capture.show-metadata", NULL, sysprof_window_show_metadata_action); g_type_ensure (SYSPROF_TYPE_DOCUMENT); + g_type_ensure (SYSPROF_TYPE_LOGS_SECTION); g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION); g_type_ensure (SYSPROF_TYPE_SESSION); g_type_ensure (SYSPROF_TYPE_SIDEBAR); diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index 5934773e..fbbfe7b6 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -95,6 +95,13 @@ + + + + SysprofWindow + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index f9959d55..cc248f82 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -5,6 +5,7 @@ gtk/menus.ui sysprof-files-dialog.ui sysprof-greeter.ui + sysprof-logs-section.ui sysprof-metadata-dialog.ui sysprof-recording-pad.ui sysprof-samples-section.ui