From 11712643b9367cda322c933c6e1d82df48d363e2 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 17 May 2019 23:41:16 -0700 Subject: [PATCH] libsysprof-ui: start on profiler assistant --- src/libsysprof-ui/libsysprof-ui.gresource.xml | 1 + src/libsysprof-ui/meson.build | 2 + .../sysprof-profiler-assistant.c | 127 ++++++++++ .../sysprof-profiler-assistant.h | 37 +++ src/libsysprof-ui/sysprof-ui.h | 1 + src/libsysprof-ui/ui/sysprof-display.ui | 8 + .../ui/sysprof-process-model-row.ui | 1 + .../ui/sysprof-profiler-assistant.ui | 216 ++++++++++++++++++ 8 files changed, 393 insertions(+) create mode 100644 src/libsysprof-ui/sysprof-profiler-assistant.c create mode 100644 src/libsysprof-ui/sysprof-profiler-assistant.h create mode 100644 src/libsysprof-ui/ui/sysprof-profiler-assistant.ui diff --git a/src/libsysprof-ui/libsysprof-ui.gresource.xml b/src/libsysprof-ui/libsysprof-ui.gresource.xml index 849b877a..3e3df45f 100644 --- a/src/libsysprof-ui/libsysprof-ui.gresource.xml +++ b/src/libsysprof-ui/libsysprof-ui.gresource.xml @@ -17,6 +17,7 @@ ui/sysprof-failed-state-view.ui ui/sysprof-marks-view.ui ui/sysprof-process-model-row.ui + ui/sysprof-profiler-assistant.ui ui/sysprof-profiler-menu-button.ui ui/sysprof-recording-state-view.ui ui/sysprof-tab.ui diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build index 549582b2..f64f7a3b 100644 --- a/src/libsysprof-ui/meson.build +++ b/src/libsysprof-ui/meson.build @@ -13,6 +13,7 @@ libsysprof_ui_public_sources = [ 'sysprof-model-filter.c', 'sysprof-notebook.c', 'sysprof-process-model-row.c', + 'sysprof-profiler-assistant.c', 'sysprof-profiler-menu-button.c', 'sysprof-recording-state-view.c', 'sysprof-visualizer-list.c', @@ -49,6 +50,7 @@ libsysprof_ui_public_headers = [ 'sysprof-model-filter.h', 'sysprof-notebook.h', 'sysprof-process-model-row.h', + 'sysprof-profiler-assistant.h', 'sysprof-profiler-menu-button.h', 'sysprof-recording-state-view.h', 'sysprof-visualizer-list.h', diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c new file mode 100644 index 00000000..79d1c2b3 --- /dev/null +++ b/src/libsysprof-ui/sysprof-profiler-assistant.c @@ -0,0 +1,127 @@ +/* sysprof-profiler-assistant.c + * + * Copyright 2019 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 + */ + +#define G_LOG_DOMAIN "sysprof-profiler-assistant" + +#include "config.h" + +#include + +#include "sysprof-profiler-assistant.h" +#include "sysprof-process-model-row.h" + +struct _SysprofProfilerAssistant +{ + GtkBin parent_instance; + + /* Template Objects */ + GtkRevealer *process_revealer; + GtkListBox *process_list_box; +}; + +G_DEFINE_TYPE (SysprofProfilerAssistant, sysprof_profiler_assistant, GTK_TYPE_BIN) + +/** + * sysprof_profiler_assistant_new: + * + * Create a new #SysprofProfilerAssistant. + * + * Returns: (transfer full): a newly created #SysprofProfilerAssistant + * + * Since: 3.34 + */ +GtkWidget * +sysprof_profiler_assistant_new (void) +{ + return g_object_new (SYSPROF_TYPE_PROFILER_ASSISTANT, NULL); +} + +static GtkWidget * +create_process_row_cb (gpointer item_, + gpointer user_data) +{ + SysprofProcessModelItem *item = item_; + + g_assert (SYSPROF_IS_PROCESS_MODEL_ITEM (item)); + + return sysprof_process_model_row_new (item); +} + +static void +sysprof_profiler_assistant_notify_reveal_child_cb (SysprofProfilerAssistant *self, + GParamSpec *pspec, + GtkRevealer *revealer) +{ + g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); + g_assert (GTK_IS_REVEALER (revealer)); + + if (gtk_revealer_get_reveal_child (revealer)) + { + g_autoptr(SysprofProcessModel) model = NULL; + + model = sysprof_process_model_new (); + gtk_list_box_bind_model (self->process_list_box, + G_LIST_MODEL (model), + create_process_row_cb, + NULL, NULL); + sysprof_process_model_reload (model); + } +} + +static void +sysprof_profiler_assistant_row_activated_cb (SysprofProfilerAssistant *self, + SysprofProcessModelRow *row, + GtkListBox *list_box) +{ + g_assert (SYSPROF_PROFILER_ASSISTANT (self)); + g_assert (SYSPROF_IS_PROCESS_MODEL_ROW (row)); + g_assert (GTK_IS_LIST_BOX (list_box)); + + sysprof_process_model_row_set_selected (row, + !sysprof_process_model_row_get_selected (row)); +} + +static void +sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-profiler-assistant.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, process_list_box); + gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, process_revealer); +} + +static void +sysprof_profiler_assistant_init (SysprofProfilerAssistant *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); + + g_signal_connect_object (self->process_list_box, + "row-activated", + G_CALLBACK (sysprof_profiler_assistant_row_activated_cb), + self, + G_CONNECT_SWAPPED); + + g_signal_connect_object (self->process_revealer, + "notify::reveal-child", + G_CALLBACK (sysprof_profiler_assistant_notify_reveal_child_cb), + self, + G_CONNECT_SWAPPED); +} diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.h b/src/libsysprof-ui/sysprof-profiler-assistant.h new file mode 100644 index 00000000..8bc6df57 --- /dev/null +++ b/src/libsysprof-ui/sysprof-profiler-assistant.h @@ -0,0 +1,37 @@ +/* sysprof-profiler-assistant.h + * + * Copyright 2019 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-version-macros.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_PROFILER_ASSISTANT (sysprof_profiler_assistant_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofProfilerAssistant, sysprof_profiler_assistant, SYSPROF, PROFILER_ASSISTANT, GtkBin) + +SYSPROF_AVAILABLE_IN_ALL +GtkWidget *sysprof_profiler_assistant_new (void); + +G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-ui.h b/src/libsysprof-ui/sysprof-ui.h index 796690e1..fa112afe 100644 --- a/src/libsysprof-ui/sysprof-ui.h +++ b/src/libsysprof-ui/sysprof-ui.h @@ -41,6 +41,7 @@ G_BEGIN_DECLS # include "sysprof-model-filter.h" # include "sysprof-notebook.h" # include "sysprof-process-model-row.h" +# include "sysprof-profiler-assistant.h" # include "sysprof-profiler-menu-button.h" # include "sysprof-recording-state-view.h" # include "sysprof-visualizer-row.h" diff --git a/src/libsysprof-ui/ui/sysprof-display.ui b/src/libsysprof-ui/ui/sysprof-display.ui index df0071ab..7565a5d5 100644 --- a/src/libsysprof-ui/ui/sysprof-display.ui +++ b/src/libsysprof-ui/ui/sysprof-display.ui @@ -5,6 +5,14 @@ false true + + + true + + + assistant + + Welcome to Sysprof diff --git a/src/libsysprof-ui/ui/sysprof-process-model-row.ui b/src/libsysprof-ui/ui/sysprof-process-model-row.ui index 118e3d84..53ed2841 100644 --- a/src/libsysprof-ui/ui/sysprof-process-model-row.ui +++ b/src/libsysprof-ui/ui/sysprof-process-model-row.ui @@ -4,6 +4,7 @@ true + 6 6 diff --git a/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui new file mode 100644 index 00000000..d4993358 --- /dev/null +++ b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui @@ -0,0 +1,216 @@ + + + + +