sysprof: add an embedded files section

This seems more discoverable than the dialog, which we can drop now.
This commit is contained in:
Christian Hergert
2023-07-09 15:35:06 -07:00
parent 3accd82af2
commit 68b538bce6
7 changed files with 333 additions and 0 deletions

View File

@ -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',

View File

@ -0,0 +1,143 @@
/* sysprof-files-section.c
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include <glib/gi18n.h>
#include <adwaita.h>
#include <sysprof-gtk.h>
#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));
}

View File

@ -0,0 +1,31 @@
/* sysprof-files-section.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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

View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="SysprofFilesSection" parent="SysprofSection">
<property name="title" translatable="yes">Files</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="vexpand">true</property>
<child>
<object class="GtkColumnView" id="column_view">
<signal name="activate" handler="sysprof_files_section_activate_cb" swapped="true"/>
<property name="show-row-separators">true</property>
<style>
<class name="data-table"/>
</style>
<property name="model">
<object class="GtkSingleSelection">
<property name="model">
<object class="GtkSortListModel">
<binding name="sorter">
<lookup name="sorter">column_view</lookup>
</binding>
<binding name="model">
<lookup name="files" type="SysprofDocument">
<lookup name="document" type="SysprofSession">
<lookup name="session">SysprofFilesSection</lookup>
</lookup>
</lookup>
</binding>
</object>
</property>
</object>
</property>
<child>
<object class="GtkColumnViewColumn" id="path_column">
<property name="title" translatable="yes">Path</property>
<property name="expand">true</property>
<property name="sorter">
<object class="GtkStringSorter">
<property name="expression">
<lookup name="path" type="SysprofDocumentFile"/>
</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<lookup name="path" type="SysprofDocumentFile">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]>
</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="compressed_column">
<property name="title" translatable="yes">Compressed</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="is-compressed" type="SysprofDocumentFile"/>
</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkImage">
<property name="icon-name">object-select-symbolic</property>
<binding name="visible">
<lookup name="is-compressed" type="SysprofDocumentFile">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]>
</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="size_column">
<property name="title" translatable="yes">Size</property>
<property name="sorter">
<object class="GtkNumericSorter">
<property name="expression">
<lookup name="size" type="SysprofDocumentFile"/>
</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="format_size">
<lookup name="size" type="SysprofDocumentFile">
<lookup name="item">GtkListItem</lookup>
</lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -25,6 +25,7 @@
#include <sysprof-gtk.h>
#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);

View File

@ -109,6 +109,13 @@
</binding>
</object>
</child>
<child>
<object class="SysprofFilesSection">
<binding name="session">
<lookup name="session">SysprofWindow</lookup>
</binding>
</object>
</child>
</object>
</property>
</object>

View File

@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">sysprof-files-dialog.ui</file>
<file preprocess="xml-stripblanks">sysprof-files-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-greeter.ui</file>
<file preprocess="xml-stripblanks">sysprof-logs-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-marks-section.ui</file>