diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 92c24a14..e14790fe 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -2,6 +2,7 @@ sysprof_sources = [ 'main.c', 'sysprof-application.c', 'sysprof-files-dialog.c', + 'sysprof-files-section.c', 'sysprof-greeter.c', 'sysprof-logs-section.c', 'sysprof-marks-section.c', diff --git a/src/sysprof/sysprof-files-section.c b/src/sysprof/sysprof-files-section.c new file mode 100644 index 00000000..a0479bf8 --- /dev/null +++ b/src/sysprof/sysprof-files-section.c @@ -0,0 +1,143 @@ +/* sysprof-files-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 + +#include "sysprof-files-section.h" + +struct _SysprofFilesSection +{ + SysprofSection parent_instance; + + GtkColumnView *column_view; +}; + +G_DEFINE_FINAL_TYPE (SysprofFilesSection, sysprof_files_section, SYSPROF_TYPE_SECTION) + +static void +sysprof_files_section_activate_cb (SysprofFilesSection *self, + guint position, + GtkColumnView *view) +{ + g_autoptr(SysprofDocumentFile) file = NULL; + g_autoptr(GtkTextBuffer) buffer = NULL; + g_autoptr(GBytes) bytes = NULL; + GtkSelectionModel *model; + GtkNative *toplevel; + GtkWidget *toolbar; + GtkWidget *header_bar; + GtkWidget *scroller; + GtkWidget *text_view; + const char *str; + const char *endptr; + GtkWindow *window; + gsize len; + + g_assert (SYSPROF_IS_FILES_SECTION (self)); + g_assert (GTK_IS_COLUMN_VIEW (view)); + + model = gtk_column_view_get_model (view); + file = g_list_model_get_item (G_LIST_MODEL (model), position); + bytes = sysprof_document_file_dup_bytes (file); + str = (const char *)g_bytes_get_data (bytes, &len); + endptr = str; + + if (!g_utf8_validate_len (str, len, &endptr) && endptr == str) + return; + + buffer = gtk_text_buffer_new (NULL); + gtk_text_buffer_set_text (buffer, str, endptr - str); + + toplevel = gtk_widget_get_native (GTK_WIDGET (self)); + + window = g_object_new (ADW_TYPE_WINDOW, + "transient-for", toplevel, + "default-width", 800, + "default-height", 600, + "title", sysprof_document_file_get_path (file), + NULL); + header_bar = g_object_new (ADW_TYPE_HEADER_BAR, NULL); + toolbar = g_object_new (ADW_TYPE_TOOLBAR_VIEW, + "top-bar-style", ADW_TOOLBAR_RAISED, + NULL); + scroller = g_object_new (GTK_TYPE_SCROLLED_WINDOW, NULL); + text_view = g_object_new (GTK_TYPE_TEXT_VIEW, + "editable", FALSE, + "left-margin", 6, + "right-margin", 6, + "top-margin", 6, + "bottom-margin", 6, + "monospace", TRUE, + "buffer", buffer, + NULL); + + adw_window_set_content (ADW_WINDOW (window), toolbar); + adw_toolbar_view_add_top_bar (ADW_TOOLBAR_VIEW (toolbar), header_bar); + adw_toolbar_view_set_content (ADW_TOOLBAR_VIEW (toolbar), scroller); + gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroller), text_view); + + gtk_window_present (window); +} + +static char * +format_size (gpointer unused, + guint64 size) +{ + return g_format_size (size); +} + +static void +sysprof_files_section_dispose (GObject *object) +{ + SysprofFilesSection *self = (SysprofFilesSection *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_FILES_SECTION); + + G_OBJECT_CLASS (sysprof_files_section_parent_class)->dispose (object); +} + +static void +sysprof_files_section_class_init (SysprofFilesSectionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_files_section_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-files-section.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofFilesSection, column_view); + gtk_widget_class_bind_template_callback (widget_class, sysprof_files_section_activate_cb); + gtk_widget_class_bind_template_callback (widget_class, format_size); + + g_type_ensure (SYSPROF_TYPE_DOCUMENT_LOG); + g_type_ensure (SYSPROF_TYPE_TIME_LABEL); +} + +static void +sysprof_files_section_init (SysprofFilesSection *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + diff --git a/src/sysprof/sysprof-files-section.h b/src/sysprof/sysprof-files-section.h new file mode 100644 index 00000000..beab1d5c --- /dev/null +++ b/src/sysprof/sysprof-files-section.h @@ -0,0 +1,31 @@ +/* sysprof-files-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_FILES_SECTION (sysprof_files_section_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofFilesSection, sysprof_files_section, SYSPROF, FILES_SECTION, SysprofSection) + +G_END_DECLS diff --git a/src/sysprof/sysprof-files-section.ui b/src/sysprof/sysprof-files-section.ui new file mode 100644 index 00000000..8af1159d --- /dev/null +++ b/src/sysprof/sysprof-files-section.ui @@ -0,0 +1,148 @@ + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index 4bfe9865..ee387b95 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -25,6 +25,7 @@ #include #include "sysprof-files-dialog.h" +#include "sysprof-files-section.h" #include "sysprof-greeter.h" #include "sysprof-logs-section.h" #include "sysprof-marks-section.h" @@ -200,6 +201,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_FILES_SECTION); g_type_ensure (SYSPROF_TYPE_LOGS_SECTION); g_type_ensure (SYSPROF_TYPE_MARKS_SECTION); g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION); diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index ab6c910c..ec226cbe 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -109,6 +109,13 @@ + + + + SysprofWindow + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 42d19d66..c60a116e 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -4,6 +4,7 @@ gtk/help-overlay.ui gtk/menus.ui sysprof-files-dialog.ui + sysprof-files-section.ui sysprof-greeter.ui sysprof-logs-section.ui sysprof-marks-section.ui