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.
This commit is contained in:
Christian Hergert
2019-05-29 18:09:57 -07:00
parent cb4aed73bc
commit 5fd04d9fcb
4 changed files with 71 additions and 22 deletions

View File

@ -157,41 +157,50 @@ notify:
} }
static void static void
sysprof_display_start_recording_cb (SysprofDisplay *self, sysprof_display_set_profiler (SysprofDisplay *self,
SysprofProfiler *profiler, SysprofProfiler *profiler)
SysprofProfilerAssistant *assistant)
{ {
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
g_assert (SYSPROF_IS_DISPLAY (self)); g_assert (SYSPROF_IS_DISPLAY (self));
g_assert (SYSPROF_IS_PROFILER (profiler)); 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)) if (g_set_object (&priv->profiler, profiler))
{ {
sysprof_recording_state_view_set_profiler (priv->recording_view, profiler); sysprof_recording_state_view_set_profiler (priv->recording_view, profiler);
gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->recording_view)); gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->recording_view));
g_signal_connect_object (priv->profiler, g_signal_connect_object (profiler,
"stopped", "stopped",
G_CALLBACK (sysprof_display_profiler_stopped_cb), G_CALLBACK (sysprof_display_profiler_stopped_cb),
self, self,
G_CONNECT_SWAPPED); G_CONNECT_SWAPPED);
g_signal_connect_object (priv->profiler, g_signal_connect_object (profiler,
"failed", "failed",
G_CALLBACK (sysprof_display_profiler_failed_cb), G_CALLBACK (sysprof_display_profiler_failed_cb),
self, self,
G_CONNECT_SWAPPED); 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_RECORDING]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); 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 * gchar *
sysprof_display_dup_title (SysprofDisplay *self) 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); g_return_val_if_fail (SYSPROF_IS_LOCAL_PROFILER (profiler), NULL);
copy = g_object_new (SYSPROF_TYPE_DISPLAY, 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); 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));
}

View File

@ -32,34 +32,38 @@ G_BEGIN_DECLS
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
G_DECLARE_DERIVABLE_TYPE (SysprofDisplay, sysprof_display, SYSPROF, DISPLAY, GtkBin) G_DECLARE_DERIVABLE_TYPE (SysprofDisplay, sysprof_display, SYSPROF, DISPLAY, GtkBin)
SYSPROF_ALIGNED_BEGIN(8)
struct _SysprofDisplayClass struct _SysprofDisplayClass
{ {
GtkBinClass parent_class; GtkBinClass parent_class;
/*< private >*/ /*< private >*/
gpointer _reserved[16]; gpointer _reserved[16];
} __attribute__((aligned(8))); }
SYSPROF_ALIGNED_END(8);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
GtkWidget *sysprof_display_new (void); GtkWidget *sysprof_display_new (void);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gchar *sysprof_display_dup_title (SysprofDisplay *self); GtkWidget *sysprof_display_new_for_profiler (SysprofProfiler *profiler);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofProfiler *sysprof_display_get_profiler (SysprofDisplay *self); gchar *sysprof_display_dup_title (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_display_is_empty (SysprofDisplay *self); SysprofProfiler *sysprof_display_get_profiler (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_display_open (SysprofDisplay *self, gboolean sysprof_display_is_empty (SysprofDisplay *self);
GFile *file);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_display_save (SysprofDisplay *self); void sysprof_display_open (SysprofDisplay *self,
GFile *file);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_display_get_can_save (SysprofDisplay *self); void sysprof_display_save (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_display_stop_recording (SysprofDisplay *self); gboolean sysprof_display_get_can_save (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_display_get_can_replay (SysprofDisplay *self); void sysprof_display_stop_recording (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL 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 G_END_DECLS

View File

@ -360,3 +360,21 @@ sysprof_notebook_replay (SysprofNotebook *self)
page = gtk_notebook_page_num (GTK_NOTEBOOK (self), GTK_WIDGET (replay)); page = gtk_notebook_page_num (GTK_NOTEBOOK (self), GTK_WIDGET (replay));
gtk_notebook_set_current_page (GTK_NOTEBOOK (self), page); 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);
}

View File

@ -21,6 +21,7 @@
#pragma once #pragma once
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <sysprof.h>
#include "sysprof-display.h" #include "sysprof-display.h"
#include "sysprof-version-macros.h" #include "sysprof-version-macros.h"
@ -57,5 +58,8 @@ SYSPROF_AVAILABLE_IN_ALL
void sysprof_notebook_replay (SysprofNotebook *self); void sysprof_notebook_replay (SysprofNotebook *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_notebook_get_can_replay (SysprofNotebook *self); gboolean sysprof_notebook_get_can_replay (SysprofNotebook *self);
SYSPROF_AVAILABLE_IN_ALL
void sysprof_notebook_add_profiler (SysprofNotebook *self,
SysprofProfiler *profiler);
G_END_DECLS G_END_DECLS