From b48ff9d0141288b10a1987da9f3564bbeb964b07 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 7 Jul 2023 17:12:34 -0700 Subject: [PATCH] sysprof: add dialog to show files embedded in capture This will likely need search and the ability to open the files and/or display their content. --- src/sysprof/meson.build | 1 + src/sysprof/sysprof-files-dialog.c | 126 ++++++++++++++++++++++++++++ src/sysprof/sysprof-files-dialog.h | 35 ++++++++ src/sysprof/sysprof-files-dialog.ui | 65 ++++++++++++++ src/sysprof/sysprof-window.c | 18 ++++ src/sysprof/sysprof-window.ui | 1 + src/sysprof/sysprof.gresource.xml | 1 + 7 files changed, 247 insertions(+) create mode 100644 src/sysprof/sysprof-files-dialog.c create mode 100644 src/sysprof/sysprof-files-dialog.h create mode 100644 src/sysprof/sysprof-files-dialog.ui diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index dee2c4f1..fb21b295 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -1,6 +1,7 @@ sysprof_sources = [ 'main.c', 'sysprof-application.c', + 'sysprof-files-dialog.c', 'sysprof-greeter.c', 'sysprof-recording-pad.c', 'sysprof-window.c', diff --git a/src/sysprof/sysprof-files-dialog.c b/src/sysprof/sysprof-files-dialog.c new file mode 100644 index 00000000..37dab782 --- /dev/null +++ b/src/sysprof/sysprof-files-dialog.c @@ -0,0 +1,126 @@ +/* sysprof-files-dialog.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-files-dialog.h" + +struct _SysprofFilesDialog +{ + AdwWindow parent_instance; + + SysprofDocument *document; +}; + +enum { + PROP_0, + PROP_DOCUMENT, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofFilesDialog, sysprof_files_dialog, ADW_TYPE_WINDOW) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_files_dialog_dispose (GObject *object) +{ + SysprofFilesDialog *self = (SysprofFilesDialog *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_FILES_DIALOG); + + g_clear_object (&self->document); + + G_OBJECT_CLASS (sysprof_files_dialog_parent_class)->dispose (object); +} + +static void +sysprof_files_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofFilesDialog *self = SYSPROF_FILES_DIALOG (object); + + switch (prop_id) + { + case PROP_DOCUMENT: + g_value_set_object (value, self->document); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_files_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofFilesDialog *self = SYSPROF_FILES_DIALOG (object); + + switch (prop_id) + { + case PROP_DOCUMENT: + self->document = g_value_dup_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_files_dialog_class_init (SysprofFilesDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_files_dialog_dispose; + object_class->get_property = sysprof_files_dialog_get_property; + object_class->set_property = sysprof_files_dialog_set_property; + + properties[PROP_DOCUMENT] = + g_param_spec_object ("document", NULL, NULL, + SYSPROF_TYPE_DOCUMENT, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-files-dialog.ui"); +} + +static void +sysprof_files_dialog_init (SysprofFilesDialog *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +GtkWidget * +sysprof_files_dialog_new (SysprofDocument *document) +{ + g_return_val_if_fail (SYSPROF_IS_DOCUMENT (document), NULL); + + return g_object_new (SYSPROF_TYPE_FILES_DIALOG, + "document", document, + NULL); +} diff --git a/src/sysprof/sysprof-files-dialog.h b/src/sysprof/sysprof-files-dialog.h new file mode 100644 index 00000000..6a9f535d --- /dev/null +++ b/src/sysprof/sysprof-files-dialog.h @@ -0,0 +1,35 @@ +/* sysprof-files-dialog.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_FILES_DIALOG (sysprof_files_dialog_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofFilesDialog, sysprof_files_dialog, SYSPROF, FILES_DIALOG, AdwWindow) + +GtkWidget *sysprof_files_dialog_new (SysprofDocument *document); + +G_END_DECLS diff --git a/src/sysprof/sysprof-files-dialog.ui b/src/sysprof/sysprof-files-dialog.ui new file mode 100644 index 00000000..96288ef7 --- /dev/null +++ b/src/sysprof/sysprof-files-dialog.ui @@ -0,0 +1,65 @@ + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index bb0c2b49..29226395 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -24,6 +24,7 @@ #include +#include "sysprof-files-dialog.h" #include "sysprof-window.h" struct _SysprofWindow @@ -93,6 +94,22 @@ sysprof_window_open_capture_action (GtkWidget *widget, g_object_ref (widget)); } +static void +sysprof_window_show_embedded_files_action (GtkWidget *widget, + const char *action_name, + GVariant *param) +{ + SysprofWindow *self = (SysprofWindow *)widget; + GtkWidget *dialog; + + g_assert (SYSPROF_IS_WINDOW (self)); + g_assert (SYSPROF_IS_DOCUMENT (self->document)); + + dialog = sysprof_files_dialog_new (self->document); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self)); + gtk_window_present (GTK_WINDOW (dialog)); +} + static void sysprof_window_set_document (SysprofWindow *self, SysprofDocument *document) @@ -187,6 +204,7 @@ sysprof_window_class_init (SysprofWindowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-window.ui"); gtk_widget_class_install_action (widget_class, "win.open-capture", NULL, sysprof_window_open_capture_action); + gtk_widget_class_install_action (widget_class, "capture.show-embedded-files", NULL, sysprof_window_show_embedded_files_action); g_type_ensure (SYSPROF_TYPE_DOCUMENT); g_type_ensure (SYSPROF_TYPE_SESSION); diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index 563124ca..d6c78c2a 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -138,6 +138,7 @@
Show Embedded Files… + capture.show-embedded-files Show Embedded Metadata… diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 1243ffcb..53f801ac 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -3,6 +3,7 @@ gtk/help-overlay.ui gtk/menus.ui + sysprof-files-dialog.ui sysprof-greeter.ui sysprof-recording-pad.ui sysprof-window.ui