[gnome-builder/wip/gtk4-port] plugins/sysprof: implement opening of sysprof captures



commit f399ffa489372162708f9b7b1272d7b9d31dde76
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 17 15:20:22 2022 -0700

    plugins/sysprof: implement opening of sysprof captures
    
    This adds a new page type which just displays the capture contents. We
    still need something to do the actual recording widget though (or at least
    show the number of events recorded in the status bar or something).

 src/plugins/sysprof/gbp-sysprof-page.c            | 155 ++++++++++++++++++++++
 src/plugins/sysprof/gbp-sysprof-page.h            |  33 +++++
 src/plugins/sysprof/gbp-sysprof-workspace-addin.c |  21 ++-
 src/plugins/sysprof/meson.build                   |   1 +
 4 files changed, 203 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/sysprof/gbp-sysprof-page.c b/src/plugins/sysprof/gbp-sysprof-page.c
new file mode 100644
index 000000000..9b61ca296
--- /dev/null
+++ b/src/plugins/sysprof/gbp-sysprof-page.c
@@ -0,0 +1,155 @@
+/* gbp-sysprof-page.c
+ *
+ * Copyright 2022 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
+ */
+
+#define G_LOG_DOMAIN "gbp-sysprof-page"
+
+#include "config.h"
+
+#include <sysprof-ui.h>
+
+#include "gbp-sysprof-page.h"
+
+struct _GbpSysprofPage
+{
+  IdePage         parent_instance;
+
+  GFile          *file;
+
+  SysprofDisplay *display;
+};
+
+enum {
+  PROP_0,
+  PROP_FILE,
+  N_PROPS
+};
+
+G_DEFINE_TYPE (GbpSysprofPage, gbp_sysprof_page, IDE_TYPE_PAGE)
+
+static GParamSpec *properties [N_PROPS];
+
+static GFile *
+gbp_sysprof_page_get_file (GbpSysprofPage *self)
+{
+  g_assert (GBP_IS_SYSPROF_PAGE (self));
+
+  return self->file;
+}
+
+static void
+gbp_sysprof_page_set_file (GbpSysprofPage *self,
+                           GFile          *file)
+{
+  g_assert (GBP_IS_SYSPROF_PAGE (self));
+  g_assert (!file || G_IS_FILE (file));
+  g_assert (self->file == NULL);
+
+  if (file == NULL)
+    return;
+
+  g_set_object (&self->file, file);
+  sysprof_display_open (self->display, file);
+}
+
+static void
+gbp_sysprof_page_dispose (GObject *object)
+{
+  GbpSysprofPage *self = (GbpSysprofPage *)object;
+
+  g_clear_object (&self->file);
+
+  G_OBJECT_CLASS (gbp_sysprof_page_parent_class)->dispose (object);
+}
+
+static void
+gbp_sysprof_page_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GbpSysprofPage *self = GBP_SYSPROF_PAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      g_value_set_object (value, gbp_sysprof_page_get_file (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_sysprof_page_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GbpSysprofPage *self = GBP_SYSPROF_PAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      gbp_sysprof_page_set_file (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_sysprof_page_class_init (GbpSysprofPageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_sysprof_page_dispose;
+  object_class->get_property = gbp_sysprof_page_get_property;
+  object_class->set_property = gbp_sysprof_page_set_property;
+
+  properties [PROP_FILE] =
+    g_param_spec_object ("file", NULL, NULL,
+                         G_TYPE_FILE,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gbp_sysprof_page_init (GbpSysprofPage *self)
+{
+  self->display = SYSPROF_DISPLAY (sysprof_display_new ());
+  g_object_bind_property (self->display, "title", self, "title", 0);
+  ide_page_add_content_widget (IDE_PAGE (self), GTK_WIDGET (self->display));
+
+  panel_widget_set_icon_name (PANEL_WIDGET (self), "builder-profiler-symbolic");
+}
+
+GbpSysprofPage *
+gbp_sysprof_page_new_for_file (GFile *file)
+{
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
+  g_return_val_if_fail (g_file_is_native (file), NULL);
+
+  return g_object_new (GBP_TYPE_SYSPROF_PAGE,
+                       "file", file,
+                       NULL);
+}
diff --git a/src/plugins/sysprof/gbp-sysprof-page.h b/src/plugins/sysprof/gbp-sysprof-page.h
new file mode 100644
index 000000000..a668f0fac
--- /dev/null
+++ b/src/plugins/sysprof/gbp-sysprof-page.h
@@ -0,0 +1,33 @@
+/* gbp-sysprof-page.h
+ *
+ * Copyright 2022 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 <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SYSPROF_PAGE (gbp_sysprof_page_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpSysprofPage, gbp_sysprof_page, GBP, SYSPROF_PAGE, IdePage)
+
+GbpSysprofPage *gbp_sysprof_page_new_for_file (GFile *file);
+
+G_END_DECLS
diff --git a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c 
b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
index db405b24a..fd69067d9 100644
--- a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
+++ b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
@@ -23,8 +23,10 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+
 #include <sysprof-ui.h>
 
+#include "gbp-sysprof-page.h"
 #include "gbp-sysprof-workspace-addin.h"
 
 struct _GbpSysprofWorkspaceAddin
@@ -215,6 +217,9 @@ static void
 gbp_sysprof_workspace_addin_open (GbpSysprofWorkspaceAddin *self,
                                   GFile                    *file)
 {
+  g_autoptr(IdePanelPosition) position = NULL;
+  GbpSysprofPage *page;
+
   IDE_ENTRY;
 
   g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
@@ -224,13 +229,15 @@ gbp_sysprof_workspace_addin_open (GbpSysprofWorkspaceAddin *self,
     IDE_EXIT;
 
   if (!g_file_is_native (file))
-    g_warning ("Can only open local sysprof capture files.");
-  else
-#if 0
-    gbp_sysprof_surface_open (self->surface, file);
-#else
-  g_printerr ("TODO: Open %s with GbpSysprofPage\n", g_file_peek_path (file));
-#endif
+    {
+      g_warning ("Can only open local sysprof capture files.");
+      return;
+    }
+
+  position = ide_panel_position_new ();
+  page = gbp_sysprof_page_new_for_file (file);
+
+  ide_workspace_add_page (self->workspace, IDE_PAGE (page), position);
 
   IDE_EXIT;
 }
diff --git a/src/plugins/sysprof/meson.build b/src/plugins/sysprof/meson.build
index d6775a047..802c76be5 100644
--- a/src/plugins/sysprof/meson.build
+++ b/src/plugins/sysprof/meson.build
@@ -7,6 +7,7 @@ plugins_deps += [
 
 plugins_sources += files([
   'sysprof-plugin.c',
+  'gbp-sysprof-page.c',
   'gbp-sysprof-workspace-addin.c',
 ])
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]