mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-gtk: add session object to chart
This commit is contained in:
@ -24,11 +24,13 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
SysprofSession *session;
|
||||||
char *title;
|
char *title;
|
||||||
} SysprofChartPrivate;
|
} SysprofChartPrivate;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
PROP_SESSION,
|
||||||
PROP_TITLE,
|
PROP_TITLE,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
@ -37,12 +39,35 @@ G_DEFINE_TYPE_WITH_PRIVATE (SysprofChart, sysprof_chart, GTK_TYPE_WIDGET)
|
|||||||
|
|
||||||
static GParamSpec *properties [N_PROPS];
|
static GParamSpec *properties [N_PROPS];
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_chart_size_allocate (GtkWidget *widget,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int baseline)
|
||||||
|
{
|
||||||
|
g_assert (SYSPROF_IS_CHART (widget));
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (sysprof_chart_parent_class)->size_allocate (widget, width, height, baseline);
|
||||||
|
|
||||||
|
for (GtkWidget *child = gtk_widget_get_first_child (widget);
|
||||||
|
child != NULL;
|
||||||
|
child = gtk_widget_get_next_sibling (child))
|
||||||
|
gtk_widget_size_allocate (child,
|
||||||
|
&(GtkAllocation) {0, 0, width, height},
|
||||||
|
baseline);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_chart_dispose (GObject *object)
|
sysprof_chart_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
SysprofChart *self = (SysprofChart *)object;
|
SysprofChart *self = (SysprofChart *)object;
|
||||||
SysprofChartPrivate *priv = sysprof_chart_get_instance_private (self);
|
SysprofChartPrivate *priv = sysprof_chart_get_instance_private (self);
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self))))
|
||||||
|
gtk_widget_unparent (child);
|
||||||
|
|
||||||
|
g_clear_object (&priv->session);
|
||||||
g_clear_pointer (&priv->title, g_free);
|
g_clear_pointer (&priv->title, g_free);
|
||||||
|
|
||||||
G_OBJECT_CLASS (sysprof_chart_parent_class)->dispose (object);
|
G_OBJECT_CLASS (sysprof_chart_parent_class)->dispose (object);
|
||||||
@ -58,6 +83,10 @@ sysprof_chart_get_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_SESSION:
|
||||||
|
g_value_set_object (value, sysprof_chart_get_session (self));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
g_value_set_string (value, sysprof_chart_get_title (self));
|
g_value_set_string (value, sysprof_chart_get_title (self));
|
||||||
break;
|
break;
|
||||||
@ -77,6 +106,10 @@ sysprof_chart_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_SESSION:
|
||||||
|
sysprof_chart_set_session (self, g_value_get_object (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
sysprof_chart_set_title (self, g_value_get_string (value));
|
sysprof_chart_set_title (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
@ -90,11 +123,19 @@ static void
|
|||||||
sysprof_chart_class_init (SysprofChartClass *klass)
|
sysprof_chart_class_init (SysprofChartClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
object_class->dispose = sysprof_chart_dispose;
|
object_class->dispose = sysprof_chart_dispose;
|
||||||
object_class->get_property = sysprof_chart_get_property;
|
object_class->get_property = sysprof_chart_get_property;
|
||||||
object_class->set_property = sysprof_chart_set_property;
|
object_class->set_property = sysprof_chart_set_property;
|
||||||
|
|
||||||
|
widget_class->size_allocate = sysprof_chart_size_allocate;
|
||||||
|
|
||||||
|
properties [PROP_SESSION] =
|
||||||
|
g_param_spec_object ("session", NULL, NULL,
|
||||||
|
G_TYPE_OBJECT,
|
||||||
|
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
properties[PROP_TITLE] =
|
properties[PROP_TITLE] =
|
||||||
g_param_spec_string ("title", NULL, NULL,
|
g_param_spec_string ("title", NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@ -118,6 +159,44 @@ sysprof_chart_get_title (SysprofChart *self)
|
|||||||
return priv->title;
|
return priv->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_chart_get_session:
|
||||||
|
* @self: a #SysprofChart
|
||||||
|
*
|
||||||
|
* Gets the #SysprofSession of the chart.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none) (nullable): a #SysprofSession or %NULL
|
||||||
|
*/
|
||||||
|
SysprofSession *
|
||||||
|
sysprof_chart_get_session (SysprofChart *self)
|
||||||
|
{
|
||||||
|
SysprofChartPrivate *priv = sysprof_chart_get_instance_private (self);
|
||||||
|
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_CHART (self), NULL);
|
||||||
|
|
||||||
|
return priv->session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_chart_set_session:
|
||||||
|
* @self: a #SysprofChart
|
||||||
|
* @session: (nullable): a #SysprofSession
|
||||||
|
*
|
||||||
|
* Sets the session for the chart.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sysprof_chart_set_session (SysprofChart *self,
|
||||||
|
SysprofSession *session)
|
||||||
|
{
|
||||||
|
SysprofChartPrivate *priv = sysprof_chart_get_instance_private (self);
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_CHART (self));
|
||||||
|
g_return_if_fail (!session || SYSPROF_IS_SESSION (session));
|
||||||
|
|
||||||
|
if (g_set_object (&priv->session, session))
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SESSION]);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sysprof_chart_set_title (SysprofChart *self,
|
sysprof_chart_set_title (SysprofChart *self,
|
||||||
const char *title)
|
const char *title)
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
#include <sysprof-capture.h>
|
#include <sysprof-capture.h>
|
||||||
|
|
||||||
#include "sysprof-chart-layer.h"
|
#include "sysprof-chart-layer.h"
|
||||||
|
#include "sysprof-session.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -41,17 +42,22 @@ struct _SysprofChartClass
|
|||||||
};
|
};
|
||||||
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GtkWidget *sysprof_chart_new (void);
|
GtkWidget *sysprof_chart_new (void);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
const char *sysprof_chart_get_title (SysprofChart *self);
|
SysprofSession *sysprof_chart_get_session (SysprofChart *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_chart_set_title (SysprofChart *self,
|
void sysprof_chart_set_session (SysprofChart *self,
|
||||||
const char *title);
|
SysprofSession *session);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_chart_add_layer (SysprofChart *self,
|
const char *sysprof_chart_get_title (SysprofChart *self);
|
||||||
SysprofChartLayer *layer);
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_chart_remove_layer (SysprofChart *self,
|
void sysprof_chart_set_title (SysprofChart *self,
|
||||||
SysprofChartLayer *layer);
|
const char *title);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_chart_add_layer (SysprofChart *self,
|
||||||
|
SysprofChartLayer *layer);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_chart_remove_layer (SysprofChart *self,
|
||||||
|
SysprofChartLayer *layer);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user