[sysprof] libsysprof-ui: be more flexible in creating displays



commit 5fd04d9fcbf0991b68e0505263c98411cffba12f
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 29 18:09:57 2019 -0700

    libsysprof-ui: be more flexible in creating displays
    
    This allows us to create a display for a profiler, which is needed in
    embedding cases like Builder.

 src/libsysprof-ui/sysprof-display.c  | 43 +++++++++++++++++++++++++++---------
 src/libsysprof-ui/sysprof-display.h  | 28 +++++++++++++----------
 src/libsysprof-ui/sysprof-notebook.c | 18 +++++++++++++++
 src/libsysprof-ui/sysprof-notebook.h |  4 ++++
 4 files changed, 71 insertions(+), 22 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c
index 23bae02..7f31a54 100644
--- a/src/libsysprof-ui/sysprof-display.c
+++ b/src/libsysprof-ui/sysprof-display.c
@@ -157,41 +157,50 @@ notify:
 }
 
 static void
-sysprof_display_start_recording_cb (SysprofDisplay           *self,
-                                    SysprofProfiler          *profiler,
-                                    SysprofProfilerAssistant *assistant)
+sysprof_display_set_profiler (SysprofDisplay  *self,
+                              SysprofProfiler *profiler)
 {
   SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
 
   g_assert (SYSPROF_IS_DISPLAY (self));
   g_assert (SYSPROF_IS_PROFILER (profiler));
-  g_assert (!assistant || SYSPROF_IS_PROFILER_ASSISTANT (assistant));
-  g_assert (sysprof_display_is_empty (self));
 
   if (g_set_object (&priv->profiler, profiler))
     {
       sysprof_recording_state_view_set_profiler (priv->recording_view, profiler);
       gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->recording_view));
 
-      g_signal_connect_object (priv->profiler,
+      g_signal_connect_object (profiler,
                                "stopped",
                                G_CALLBACK (sysprof_display_profiler_stopped_cb),
                                self,
                                G_CONNECT_SWAPPED);
 
-      g_signal_connect_object (priv->profiler,
+      g_signal_connect_object (profiler,
                                "failed",
                                G_CALLBACK (sysprof_display_profiler_failed_cb),
                                self,
                                G_CONNECT_SWAPPED);
-
-      sysprof_profiler_start (priv->profiler);
     }
 
   g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RECORDING]);
   g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
 }
 
+static void
+sysprof_display_start_recording_cb (SysprofDisplay           *self,
+                                    SysprofProfiler          *profiler,
+                                    SysprofProfilerAssistant *assistant)
+{
+  g_assert (SYSPROF_IS_DISPLAY (self));
+  g_assert (SYSPROF_IS_PROFILER (profiler));
+  g_assert (!assistant || SYSPROF_IS_PROFILER_ASSISTANT (assistant));
+  g_assert (sysprof_display_is_empty (self));
+
+  sysprof_display_set_profiler (self, profiler);
+  sysprof_profiler_start (profiler);
+}
+
 gchar *
 sysprof_display_dup_title (SysprofDisplay *self)
 {
@@ -649,7 +658,21 @@ sysprof_display_replay (SysprofDisplay *self)
   g_return_val_if_fail (SYSPROF_IS_LOCAL_PROFILER (profiler), NULL);
 
   copy = g_object_new (SYSPROF_TYPE_DISPLAY, NULL);
-  sysprof_display_start_recording_cb (copy, profiler, NULL);
+  sysprof_display_set_profiler (copy, profiler);
+  sysprof_profiler_start (profiler);
 
   return g_steal_pointer (&copy);
 }
+
+GtkWidget *
+sysprof_display_new_for_profiler (SysprofProfiler *profiler)
+{
+  SysprofDisplay *self;
+
+  g_return_val_if_fail (SYSPROF_IS_PROFILER (profiler), NULL);
+
+  self = g_object_new (SYSPROF_TYPE_DISPLAY, NULL);
+  sysprof_display_set_profiler (self, profiler);
+
+  return GTK_WIDGET (g_steal_pointer (&self));
+}
diff --git a/src/libsysprof-ui/sysprof-display.h b/src/libsysprof-ui/sysprof-display.h
index 190f536..96d780b 100644
--- a/src/libsysprof-ui/sysprof-display.h
+++ b/src/libsysprof-ui/sysprof-display.h
@@ -32,34 +32,38 @@ G_BEGIN_DECLS
 SYSPROF_AVAILABLE_IN_ALL
 G_DECLARE_DERIVABLE_TYPE (SysprofDisplay, sysprof_display, SYSPROF, DISPLAY, GtkBin)
 
+SYSPROF_ALIGNED_BEGIN(8)
 struct _SysprofDisplayClass
 {
   GtkBinClass parent_class;
 
   /*< private >*/
   gpointer _reserved[16];
-} __attribute__((aligned(8)));
+}
+SYSPROF_ALIGNED_END(8);
 
 SYSPROF_AVAILABLE_IN_ALL
-GtkWidget       *sysprof_display_new            (void);
+GtkWidget       *sysprof_display_new              (void);
 SYSPROF_AVAILABLE_IN_ALL
-gchar           *sysprof_display_dup_title      (SysprofDisplay *self);
+GtkWidget       *sysprof_display_new_for_profiler (SysprofProfiler *profiler);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofProfiler *sysprof_display_get_profiler   (SysprofDisplay *self);
+gchar           *sysprof_display_dup_title        (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean         sysprof_display_is_empty       (SysprofDisplay *self);
+SysprofProfiler *sysprof_display_get_profiler     (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-void             sysprof_display_open           (SysprofDisplay *self,
-                                                 GFile          *file);
+gboolean         sysprof_display_is_empty         (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-void             sysprof_display_save           (SysprofDisplay *self);
+void             sysprof_display_open             (SysprofDisplay  *self,
+                                                   GFile           *file);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean         sysprof_display_get_can_save   (SysprofDisplay *self);
+void             sysprof_display_save             (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-void             sysprof_display_stop_recording (SysprofDisplay *self);
+gboolean         sysprof_display_get_can_save     (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean         sysprof_display_get_can_replay (SysprofDisplay *self);
+void             sysprof_display_stop_recording   (SysprofDisplay  *self);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofDisplay  *sysprof_display_replay         (SysprofDisplay *self);
+gboolean         sysprof_display_get_can_replay   (SysprofDisplay  *self);
+SYSPROF_AVAILABLE_IN_ALL
+SysprofDisplay  *sysprof_display_replay           (SysprofDisplay  *self);
 
 G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-notebook.c b/src/libsysprof-ui/sysprof-notebook.c
index f11e3ff..bbd905f 100644
--- a/src/libsysprof-ui/sysprof-notebook.c
+++ b/src/libsysprof-ui/sysprof-notebook.c
@@ -360,3 +360,21 @@ sysprof_notebook_replay (SysprofNotebook *self)
   page = gtk_notebook_page_num (GTK_NOTEBOOK (self), GTK_WIDGET (replay));
   gtk_notebook_set_current_page (GTK_NOTEBOOK (self), page);
 }
+
+void
+sysprof_notebook_add_profiler (SysprofNotebook *self,
+                               SysprofProfiler *profiler)
+{
+  GtkWidget *display;
+  gint page;
+
+  g_return_if_fail (SYSPROF_IS_NOTEBOOK (self));
+  g_return_if_fail (SYSPROF_IS_PROFILER (profiler));
+
+  display = sysprof_display_new_for_profiler (profiler);
+
+  gtk_widget_show (display);
+  gtk_container_add (GTK_CONTAINER (self), display);
+  page = gtk_notebook_page_num (GTK_NOTEBOOK (self), display);
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (self), page);
+}
diff --git a/src/libsysprof-ui/sysprof-notebook.h b/src/libsysprof-ui/sysprof-notebook.h
index 36aa1fe..6c9a836 100644
--- a/src/libsysprof-ui/sysprof-notebook.h
+++ b/src/libsysprof-ui/sysprof-notebook.h
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <gtk/gtk.h>
+#include <sysprof.h>
 
 #include "sysprof-display.h"
 #include "sysprof-version-macros.h"
@@ -57,5 +58,8 @@ SYSPROF_AVAILABLE_IN_ALL
 void            sysprof_notebook_replay         (SysprofNotebook *self);
 SYSPROF_AVAILABLE_IN_ALL
 gboolean        sysprof_notebook_get_can_replay (SysprofNotebook *self);
+SYSPROF_AVAILABLE_IN_ALL
+void            sysprof_notebook_add_profiler   (SysprofNotebook *self,
+                                                 SysprofProfiler *profiler);
 
 G_END_DECLS


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