[sysprof/wip/visualizers] visualizer-view: add SpVisualizerView



commit f8a0f2701e1d59adf377e3f52a1505ed1c31ca2f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 27 23:03:12 2016 -0700

    visualizer-view: add SpVisualizerView
    
    This adds a new helper widget SpVisualizerView to simplify using
    visualizers from applications using libsysprof-ui-2 such as
    Builder.
    
    We can manage the view range, zoom, etc from this widget going
    forward.

 lib/Makefile.am                        |    2 +
 lib/resources/libsysprof.gresource.xml |    1 +
 lib/resources/ui/sp-visualizer-view.ui |   29 +++++
 lib/sp-visualizer-ticks.c              |    2 +-
 lib/sp-visualizer-view.c               |  195 ++++++++++++++++++++++++++++++++
 lib/sp-visualizer-view.h               |   59 ++++++++++
 lib/sysprof-ui.h                       |    1 +
 src/resources/theme/shared.css         |    8 +-
 src/resources/ui/sp-window.ui          |   38 ++-----
 src/sp-window.c                        |    9 +-
 10 files changed, 305 insertions(+), 39 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ac7d1c9..3888671 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -152,6 +152,7 @@ uiheaders_DATA = \
        sp-visualizer-list.h \
        sp-visualizer-row.h \
        sp-visualizer-ticks.h \
+       sp-visualizer-view.h \
        sysprof-ui.h \
        $(NULL)
 
@@ -174,6 +175,7 @@ libsysprof_ui_@API_VERSION@_la_SOURCES = \
        sp-visualizer-list.c \
        sp-visualizer-row.c \
        sp-visualizer-ticks.c \
+       sp-visualizer-view.c \
        $(NULL)
 
 libsysprof_ui_@API_VERSION@_la_CFLAGS = \
diff --git a/lib/resources/libsysprof.gresource.xml b/lib/resources/libsysprof.gresource.xml
index 3beeed9..5854eaf 100644
--- a/lib/resources/libsysprof.gresource.xml
+++ b/lib/resources/libsysprof.gresource.xml
@@ -7,5 +7,6 @@
     <file compressed="true">ui/sp-process-model-row.ui</file>
     <file compressed="true">ui/sp-profiler-menu-button.ui</file>
     <file compressed="true">ui/sp-recording-state-view.ui</file>
+    <file compressed="true">ui/sp-visualizer-view.ui</file>
   </gresource>
 </gresources>
diff --git a/lib/resources/ui/sp-visualizer-view.ui b/lib/resources/ui/sp-visualizer-view.ui
new file mode 100644
index 0000000..da545bb
--- /dev/null
+++ b/lib/resources/ui/sp-visualizer-view.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="SpVisualizerView" parent="GtkBin">
+    <child>
+      <object class="GtkOverlay">
+        <property name="visible">true</property>
+        <child type="overlay">
+          <object class="SpVisualizerTicks" id="ticks">
+            <property name="valign">start</property>
+            <property name="hexpand">true</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="visible">true</property>
+            <property name="min-content-height">75</property>
+            <property name="propagate-natural-height">true</property>
+            <child>
+              <object class="SpVisualizerList" id="list">
+                <property name="visible">true</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/lib/sp-visualizer-ticks.c b/lib/sp-visualizer-ticks.c
index 855aff8..ac25e2f 100644
--- a/lib/sp-visualizer-ticks.c
+++ b/lib/sp-visualizer-ticks.c
@@ -198,7 +198,7 @@ sp_visualizer_ticks_set_time_range (SpVisualizerTicks *self,
 {
   g_return_if_fail (SP_IS_VISUALIZER_TICKS (self));
 
-  if (begin_time < end_time)
+  if (begin_time > end_time)
     {
       gint64 tmp = begin_time;
       begin_time = end_time;
diff --git a/lib/sp-visualizer-view.c b/lib/sp-visualizer-view.c
new file mode 100644
index 0000000..6856d7d
--- /dev/null
+++ b/lib/sp-visualizer-view.c
@@ -0,0 +1,195 @@
+/* sp-visualizer-view.c
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#define G_LOG_DOMAIN "sp-visualizer-view"
+
+#include <glib/gi18n.h>
+
+#include "sp-visualizer-list.h"
+#include "sp-visualizer-ticks.h"
+#include "sp-visualizer-view.h"
+
+typedef struct
+{
+  SpCaptureReader   *reader;
+
+  SpVisualizerList  *list;
+  SpVisualizerTicks *ticks;
+} SpVisualizerViewPrivate;
+
+enum {
+  PROP_0,
+  PROP_READER,
+  N_PROPS
+};
+
+static void buildable_iface_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (SpVisualizerView, sp_visualizer_view, GTK_TYPE_BIN, 0,
+                        G_ADD_PRIVATE (SpVisualizerView)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
+
+static GParamSpec *properties [N_PROPS];
+static GtkBuildableIface *parent_buildable;
+
+static void
+sp_visualizer_view_finalize (GObject *object)
+{
+  SpVisualizerView *self = (SpVisualizerView *)object;
+  SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
+
+  g_clear_pointer (&priv->reader, sp_capture_reader_unref);
+
+  G_OBJECT_CLASS (sp_visualizer_view_parent_class)->finalize (object);
+}
+
+static void
+sp_visualizer_view_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  SpVisualizerView *self = (SpVisualizerView *)object;
+
+  switch (prop_id)
+    {
+    case PROP_READER:
+      g_value_set_boxed (value, sp_visualizer_view_get_reader (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sp_visualizer_view_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  SpVisualizerView *self = (SpVisualizerView *)object;
+
+  switch (prop_id)
+    {
+    case PROP_READER:
+      sp_visualizer_view_set_reader (self, g_value_get_boxed (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sp_visualizer_view_class_init (SpVisualizerViewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = sp_visualizer_view_finalize;
+  object_class->get_property = sp_visualizer_view_get_property;
+  object_class->set_property = sp_visualizer_view_set_property;
+
+  properties [PROP_READER] =
+    g_param_spec_boxed ("reader",
+                        "Reader",
+                        "The reader for the visualizers",
+                        SP_TYPE_CAPTURE_READER,
+                        (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sp-visualizer-view.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, list);
+  gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, ticks);
+
+  gtk_widget_class_set_css_name (widget_class, "visualizers");
+}
+
+static void
+sp_visualizer_view_init (SpVisualizerView *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+/**
+ * sp_visualizer_view_get_reader:
+ *
+ * Returns: (transfer none): An #SpCaptureReader
+ */
+SpCaptureReader *
+sp_visualizer_view_get_reader (SpVisualizerView *self)
+{
+  SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
+
+  g_return_val_if_fail (SP_IS_VISUALIZER_VIEW (self), NULL);
+
+  return priv->reader;
+}
+
+void
+sp_visualizer_view_set_reader (SpVisualizerView *self,
+                               SpCaptureReader  *reader)
+{
+  SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
+  gint64 begin_time = 0;
+  gint64 end_time = 0;
+
+  g_return_if_fail (SP_IS_VISUALIZER_VIEW (self));
+
+  if (reader != NULL)
+    {
+      begin_time = sp_capture_reader_get_start_time (reader);
+      end_time = begin_time + (G_GINT64_CONSTANT (1000000000) * 60);
+    }
+
+  sp_visualizer_list_set_reader (priv->list, reader);
+  sp_visualizer_list_set_time_range (priv->list, begin_time, end_time);
+
+  sp_visualizer_ticks_set_time_range (priv->ticks, 0, end_time - begin_time);
+}
+
+static void
+sp_visualizer_view_add_child (GtkBuildable *buildable,
+                              GtkBuilder   *builder,
+                              GObject      *child,
+                              const gchar  *type)
+{
+  SpVisualizerView *self = (SpVisualizerView *)buildable;
+  SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
+
+  g_assert (SP_IS_VISUALIZER_VIEW (self));
+  g_assert (GTK_IS_BUILDER (builder));
+  g_assert (G_IS_OBJECT (child));
+
+  if (g_strcmp0 (type, "visualizer") == 0 && GTK_IS_WIDGET (child))
+    {
+      gtk_container_add (GTK_CONTAINER (priv->list), GTK_WIDGET (child));
+      return;
+    }
+
+  parent_buildable->add_child (buildable, builder, child, type);
+}
+
+static void
+buildable_iface_init (GtkBuildableIface *iface)
+{
+  parent_buildable = g_type_interface_peek_parent (iface);
+  iface->add_child = sp_visualizer_view_add_child;
+}
diff --git a/lib/sp-visualizer-view.h b/lib/sp-visualizer-view.h
new file mode 100644
index 0000000..1050fc8
--- /dev/null
+++ b/lib/sp-visualizer-view.h
@@ -0,0 +1,59 @@
+/* sp-visualizer-view.h
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+#ifndef SP_VISUALIZER_VIEW_H
+#define SP_VISUALIZER_VIEW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_VISUALIZER_VIEW (sp_visualizer_view_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (SpVisualizerView, sp_visualizer_view, SP, VISUALIZER_VIEW, GtkBin)
+
+struct _SpVisualizerViewClass
+{
+  GtkBinClass parent_class;
+
+  gpointer _reserved1;
+  gpointer _reserved2;
+  gpointer _reserved3;
+  gpointer _reserved4;
+  gpointer _reserved5;
+  gpointer _reserved6;
+  gpointer _reserved7;
+  gpointer _reserved8;
+  gpointer _reserved9;
+  gpointer _reserved10;
+  gpointer _reserved11;
+  gpointer _reserved12;
+  gpointer _reserved13;
+  gpointer _reserved14;
+  gpointer _reserved15;
+  gpointer _reserved16;
+};
+
+GtkWidget       *sp_visualizer_view_new        (void);
+SpCaptureReader *sp_visualizer_view_get_reader (SpVisualizerView *self);
+void             sp_visualizer_view_set_reader (SpVisualizerView *self,
+                                                SpCaptureReader  *reader);
+
+G_END_DECLS
+
+#endif /* SP_VISUALIZER_VIEW_H */
diff --git a/lib/sysprof-ui.h b/lib/sysprof-ui.h
index 6e31a66..af8f2d5 100644
--- a/lib/sysprof-ui.h
+++ b/lib/sysprof-ui.h
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
 # include "sp-visualizer-list.h"
 # include "sp-visualizer-row.h"
 # include "sp-visualizer-ticks.h"
+# include "sp-visualizer-view.h"
 #undef SYSPROF_INSIDE
 
 G_END_DECLS
diff --git a/src/resources/theme/shared.css b/src/resources/theme/shared.css
index b17bb15..94da589 100644
--- a/src/resources/theme/shared.css
+++ b/src/resources/theme/shared.css
@@ -11,17 +11,17 @@ popover scrolledwindow {
   border-top: 1px solid alpha(@borders, 0.75);
 }
 
-list.visualizers {
+visualizers list {
   background: @theme_bg_color;
 }
 
-list.visualizers row {
+visualizers list row {
   background: @content_view_bg;
   border-bottom: 1px solid alpha(@borders, 0.2);
 }
 
-list.visualizers row:backdrop,
-list.visualizers row:last-child {
+visualizers list row:backdrop,
+visualizers list row:last-child {
   border-bottom: none;
 }
 
diff --git a/src/resources/ui/sp-window.ui b/src/resources/ui/sp-window.ui
index 656eee2..569ce90 100644
--- a/src/resources/ui/sp-window.ui
+++ b/src/resources/ui/sp-window.ui
@@ -164,38 +164,16 @@
                 <property name="orientation">vertical</property>
                 <property name="visible">true</property>
                 <child>
-                  <object class="GtkOverlay" id="visualizer_overlay">
+                  <object class="SpVisualizerView" id="visualizers">
                     <property name="visible">true</property>
-                    <child type="overlay">
-                      <object class="SpVisualizerTicks">
-                        <property name="valign">start</property>
-                        <property name="hexpand">true</property>
-                        <property name="visible">true</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkScrolledWindow">
-                        <property name="min-content-height">75</property>
-                        <property name="max-content-height">225</property>
+                    <child type="visualizer">
+                      <object class="SpCpuVisualizerRow" id="cpu_row">
+                        <property name="title" translatable="yes">CPU</property>
+                        <property name="height-request">75</property>
+                        <property name="selectable">false</property>
                         <property name="visible">true</property>
-                        <child>
-                          <object class="SpVisualizerList" id="visualizer_rows">
-                            <property name="visible">true</property>
-                            <style>
-                              <class name="visualizers"/>
-                            </style>
-                            <child>
-                              <object class="SpCpuVisualizerRow" id="cpu_row">
-                                <property name="title" translatable="yes">CPU</property>
-                                <property name="height-request">75</property>
-                                <property name="selectable">false</property>
-                                <property name="visible">true</property>
-                                <property name="y-lower">0.0</property>
-                                <property name="y-upper">100.0</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
+                        <property name="y-lower">0.0</property>
+                        <property name="y-upper">100.0</property>
                       </object>
                     </child>
                   </object>
diff --git a/src/sp-window.c b/src/sp-window.c
index a3c4109..493cda7 100644
--- a/src/sp-window.c
+++ b/src/sp-window.c
@@ -22,7 +22,7 @@
 #include <sysprof-ui.h>
 
 #include "sp-application.h"
-#include "sp-visualizer-list.h"
+#include "sp-visualizer-view.h"
 #include "sp-window.h"
 #include "sp-window-settings.h"
 
@@ -49,7 +49,7 @@ struct _SpWindow
   GtkLabel             *stat_label;
   GtkLabel             *title;
   GtkStack             *view_stack;
-  SpVisualizerList     *visualizer_rows;
+  SpVisualizerView     *visualizers;
 
   guint                 stats_handler;
 
@@ -200,6 +200,7 @@ sp_window_build_profile_cb (GObject      *object,
   SpProfile *profile = (SpProfile *)object;
   g_autoptr(SpWindow) self = user_data;
   g_autoptr(GError) error = NULL;
+  gint64 begin_time;
 
   g_assert (SP_IS_CALLGRAPH_PROFILE (profile));
   g_assert (SP_IS_WINDOW (self));
@@ -218,7 +219,7 @@ sp_window_build_profile_cb (GObject      *object,
                            GTK_MESSAGE_WARNING,
                            _("Not enough samples were collected to generate a callgraph"));
 
-  sp_visualizer_list_set_reader (self->visualizer_rows, self->reader);
+  sp_visualizer_view_set_reader (self->visualizers, self->reader);
 
   sp_window_set_state (self, SP_WINDOW_STATE_BROWSING);
 }
@@ -768,7 +769,7 @@ sp_window_class_init (SpWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, SpWindow, subtitle);
   gtk_widget_class_bind_template_child (widget_class, SpWindow, title);
   gtk_widget_class_bind_template_child (widget_class, SpWindow, view_stack);
-  gtk_widget_class_bind_template_child (widget_class, SpWindow, visualizer_rows);
+  gtk_widget_class_bind_template_child (widget_class, SpWindow, visualizers);
 }
 
 static void


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