[sysprof] libsysprof-ui: stub out SysprofAid



commit 82a5c684762bb0dca3d05121d7a29065d8fa4574
Author: Christian Hergert <chergert redhat com>
Date:   Sat May 18 14:50:39 2019 -0700

    libsysprof-ui: stub out SysprofAid
    
    This will be used as a high-level object that knows how to deal with
    both the SysprofSource (data collector) and various views for the user.

 src/libsysprof-ui/meson.build   |   2 +
 src/libsysprof-ui/sysprof-aid.c | 171 ++++++++++++++++++++++++++++++++++++++++
 src/libsysprof-ui/sysprof-aid.h |  50 ++++++++++++
 src/libsysprof-ui/sysprof-ui.h  |   1 +
 4 files changed, 224 insertions(+)
---
diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build
index ddafd97..eff755b 100644
--- a/src/libsysprof-ui/meson.build
+++ b/src/libsysprof-ui/meson.build
@@ -1,4 +1,5 @@
 libsysprof_ui_public_sources = [
+  'sysprof-aid.c',
   'sysprof-capture-view.c',
   'sysprof-callgraph-view.c',
   'sysprof-color-cycle.c',
@@ -40,6 +41,7 @@ libsysprof_ui_private_sources = [
 ]
 
 libsysprof_ui_public_headers = [
+  'sysprof-aid.h',
   'sysprof-capture-view.h',
   'sysprof-callgraph-view.h',
   'sysprof-cell-renderer-percent.h',
diff --git a/src/libsysprof-ui/sysprof-aid.c b/src/libsysprof-ui/sysprof-aid.c
new file mode 100644
index 0000000..e56d2a6
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-aid.c
@@ -0,0 +1,171 @@
+/* sysprof-aid.c
+ *
+ * Copyright 2019 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 "sysprof-aid"
+
+#include "config.h"
+
+#include "sysprof-aid.h"
+
+typedef struct
+{
+  gchar *display_name;
+  GIcon *icon;
+} SysprofAidPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SysprofAid, sysprof_aid, G_TYPE_OBJECT)
+
+enum {
+  PROP_0,
+  PROP_DISPLAY_NAME,
+  PROP_ICON,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+sysprof_aid_finalize (GObject *object)
+{
+  SysprofAid *self = (SysprofAid *)object;
+  SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self);
+
+  g_clear_pointer (&priv->display_name, g_free);
+  g_clear_object (&priv->icon);
+
+  G_OBJECT_CLASS (sysprof_aid_parent_class)->finalize (object);
+}
+
+static void
+sysprof_aid_get_property (GObject    *object,
+                          guint       prop_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  SysprofAid *self = SYSPROF_AID (object);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY_NAME:
+      g_value_set_string (value, sysprof_aid_get_display_name (self));
+      break;
+
+    case PROP_ICON:
+      g_value_set_object (value, sysprof_aid_get_icon (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sysprof_aid_set_property (GObject      *object,
+                          guint         prop_id,
+                          const GValue *value,
+                          GParamSpec   *pspec)
+{
+  SysprofAid *self = SYSPROF_AID (object);
+  SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY_NAME:
+      priv->display_name = g_value_dup_string (value);
+      break;
+
+    case PROP_ICON:
+      priv->icon = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sysprof_aid_class_init (SysprofAidClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = sysprof_aid_finalize;
+  object_class->get_property = sysprof_aid_get_property;
+  object_class->set_property = sysprof_aid_set_property;
+
+  properties [PROP_DISPLAY_NAME] =
+    g_param_spec_string ("display-name",
+                         "Display Name",
+                         "Display Name",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_ICON] =
+    g_param_spec_object ("icon",
+                         "Icon",
+                         "The icon to display",
+                         G_TYPE_ICON,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+sysprof_aid_init (SysprofAid *self)
+{
+}
+
+/**
+ * sysprof_aid_get_display_name:
+ * @self: a #SysprofAid
+ *
+ * Gets the display name as it should be shown to the user.
+ *
+ * Returns: a string containing the display name
+ *
+ * Since: 3.34
+ */
+const gchar *
+sysprof_aid_get_display_name (SysprofAid *self)
+{
+  SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self);
+
+  g_return_val_if_fail (SYSPROF_IS_AID (self), NULL);
+
+  return priv->display_name;
+}
+
+/**
+ * sysprof_aid_get_icon:
+ *
+ * Gets the icon for the aid.
+ *
+ * Returns: (transfer none) (nullable): a #GIcon or %NULL
+ *
+ * Since: 3.34
+ */
+GIcon *
+sysprof_aid_get_icon (SysprofAid *self)
+{
+  SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self);
+
+  g_return_val_if_fail (SYSPROF_IS_AID (self), NULL);
+
+  return priv->icon;
+}
diff --git a/src/libsysprof-ui/sysprof-aid.h b/src/libsysprof-ui/sysprof-aid.h
new file mode 100644
index 0000000..6b5a5da
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-aid.h
@@ -0,0 +1,50 @@
+/* sysprof-aid.h
+ *
+ * Copyright 2019 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
+
+#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION)
+# error "Only <sysprof-ui.h> can be included directly."
+#endif
+
+#include <gio/gio.h>
+#include <sysprof.h>
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_AID (sysprof_aid_get_type())
+
+SYSPROF_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (SysprofAid, sysprof_aid, SYSPROF, AID, GObject)
+
+struct _SysprofAidClass
+{
+  GObjectClass parent_class;
+
+  /*< gpointer >*/
+  gpointer _reserved[16];
+};
+
+SYSPROF_AVAILABLE_IN_ALL
+const gchar *sysprof_aid_get_display_name (SysprofAid *self);
+SYSPROF_AVAILABLE_IN_ALL
+GIcon       *sysprof_aid_get_icon         (SysprofAid *self);
+
+G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-ui.h b/src/libsysprof-ui/sysprof-ui.h
index fa112af..fda84ee 100644
--- a/src/libsysprof-ui/sysprof-ui.h
+++ b/src/libsysprof-ui/sysprof-ui.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 
 #define SYSPROF_UI_INSIDE
 
+# include "sysprof-aid.h"
 # include "sysprof-callgraph-view.h"
 # include "sysprof-capture-view.h"
 # include "sysprof-cell-renderer-percent.h"


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