diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build index 53c5c64d..160ae4b8 100644 --- a/src/libsysprof-ui/meson.build +++ b/src/libsysprof-ui/meson.build @@ -3,6 +3,7 @@ libsysprof_ui_public_sources = [ 'sysprof-capture-view.c', 'sysprof-callgraph-view.c', 'sysprof-color-cycle.c', + 'sysprof-cpu-aid.c', 'sysprof-cpu-visualizer-row.c', 'sysprof-display.c', 'sysprof-empty-state-view.c', @@ -46,6 +47,7 @@ libsysprof_ui_public_headers = [ 'sysprof-capture-view.h', 'sysprof-callgraph-view.h', 'sysprof-cell-renderer-percent.h', + 'sysprof-cpu-aid.h', 'sysprof-cpu-visualizer-row.h', 'sysprof-display.h', 'sysprof-empty-state-view.h', diff --git a/src/libsysprof-ui/sysprof-aid.c b/src/libsysprof-ui/sysprof-aid.c index e56d2a63..3c1cfed2 100644 --- a/src/libsysprof-ui/sysprof-aid.c +++ b/src/libsysprof-ui/sysprof-aid.c @@ -36,6 +36,7 @@ enum { PROP_0, PROP_DISPLAY_NAME, PROP_ICON, + PROP_ICON_NAME, N_PROPS }; @@ -83,16 +84,19 @@ sysprof_aid_set_property (GObject *object, 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); + sysprof_aid_set_display_name (self, g_value_get_object (value)); break; case PROP_ICON: - priv->icon = g_value_dup_object (value); + sysprof_aid_set_icon (self, g_value_get_object (value)); + break; + + case PROP_ICON_NAME: + sysprof_aid_set_icon_name (self, g_value_get_string (value)); break; default: @@ -114,14 +118,21 @@ sysprof_aid_class_init (SysprofAidClass *klass) "Display Name", "Display Name", NULL, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + + properties [PROP_ICON_NAME] = + g_param_spec_string ("icon-name", + "Icon Name", + "Icon Name", + NULL, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | 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_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); g_object_class_install_properties (object_class, N_PROPS, properties); } @@ -169,3 +180,45 @@ sysprof_aid_get_icon (SysprofAid *self) return priv->icon; } + +void +sysprof_aid_set_icon (SysprofAid *self, + GIcon *icon) +{ + SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); + + g_return_if_fail (SYSPROF_IS_AID (self)); + + if (g_set_object (&priv->icon, icon)) + g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON]); +} + +void +sysprof_aid_set_icon_name (SysprofAid *self, + const gchar *icon_name) +{ + g_autoptr(GIcon) icon = NULL; + + g_return_if_fail (SYSPROF_IS_AID (self)); + + if (icon_name != NULL) + icon = g_themed_icon_new (icon_name); + + sysprof_aid_set_icon (self, icon); +} + +void +sysprof_aid_set_display_name (SysprofAid *self, + const gchar *display_name) +{ + SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); + + g_return_if_fail (SYSPROF_IS_AID (self)); + + if (g_strcmp0 (display_name, priv->display_name) != 0) + { + g_free (priv->display_name); + priv->display_name = g_strdup (display_name); + g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DISPLAY_NAME]); + } +} diff --git a/src/libsysprof-ui/sysprof-aid.h b/src/libsysprof-ui/sysprof-aid.h index 6b5a5dad..a6222fae 100644 --- a/src/libsysprof-ui/sysprof-aid.h +++ b/src/libsysprof-ui/sysprof-aid.h @@ -43,8 +43,17 @@ struct _SysprofAidClass }; SYSPROF_AVAILABLE_IN_ALL -const gchar *sysprof_aid_get_display_name (SysprofAid *self); +const gchar *sysprof_aid_get_display_name (SysprofAid *self); SYSPROF_AVAILABLE_IN_ALL -GIcon *sysprof_aid_get_icon (SysprofAid *self); +void sysprof_aid_set_display_name (SysprofAid *self, + const gchar *display_name); +SYSPROF_AVAILABLE_IN_ALL +GIcon *sysprof_aid_get_icon (SysprofAid *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_aid_set_icon (SysprofAid *self, + GIcon *icon); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_aid_set_icon_name (SysprofAid *self, + const gchar *icon_name); G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-cpu-aid.c b/src/libsysprof-ui/sysprof-cpu-aid.c new file mode 100644 index 00000000..e5f1e152 --- /dev/null +++ b/src/libsysprof-ui/sysprof-cpu-aid.c @@ -0,0 +1,61 @@ +/* sysprof-cpu-aid.c + * + * Copyright 2019 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define G_LOG_DOMAIN "sysprof-cpu-aid" + +#include "config.h" + +#include + +#include "sysprof-cpu-aid.h" + +struct _SysprofCpuAid +{ + SysprofAid parent_instance; +}; + +G_DEFINE_TYPE (SysprofCpuAid, sysprof_cpu_aid, SYSPROF_TYPE_AID) + +/** + * sysprof_cpu_aid_new: + * + * Create a new #SysprofCpuAid. + * + * Returns: (transfer full): a newly created #SysprofCpuAid + * + * Since: 3.34 + */ +SysprofAid * +sysprof_cpu_aid_new (void) +{ + return g_object_new (SYSPROF_TYPE_CPU_AID, NULL); +} + +static void +sysprof_cpu_aid_class_init (SysprofCpuAidClass *klass) +{ +} + +static void +sysprof_cpu_aid_init (SysprofCpuAid *self) +{ + sysprof_aid_set_display_name (SYSPROF_AID (self), _("CPU Usage")); + sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); +} diff --git a/src/libsysprof-ui/sysprof-cpu-aid.h b/src/libsysprof-ui/sysprof-cpu-aid.h new file mode 100644 index 00000000..ca5899bc --- /dev/null +++ b/src/libsysprof-ui/sysprof-cpu-aid.h @@ -0,0 +1,35 @@ +/* sysprof-cpu-aid.h + * + * Copyright 2019 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "sysprof-aid.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_CPU_AID (sysprof_cpu_aid_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofCpuAid, sysprof_cpu_aid, SYSPROF, CPU_AID, SysprofAid) + +SYSPROF_AVAILABLE_IN_ALL +SysprofAid *sysprof_cpu_aid_new (void); + +G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c index 37feddae..eef31ae1 100644 --- a/src/libsysprof-ui/sysprof-profiler-assistant.c +++ b/src/libsysprof-ui/sysprof-profiler-assistant.c @@ -25,6 +25,7 @@ #include #include "sysprof-aid-icon.h" +#include "sysprof-cpu-aid.h" #include "sysprof-environ-editor.h" #include "sysprof-profiler-assistant.h" #include "sysprof-process-model-row.h" @@ -149,6 +150,7 @@ sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass) gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, process_revealer); g_type_ensure (SYSPROF_TYPE_AID_ICON); + g_type_ensure (SYSPROF_TYPE_CPU_AID); g_type_ensure (SYSPROF_TYPE_ENVIRON_EDITOR); } diff --git a/src/libsysprof-ui/sysprof-ui.h b/src/libsysprof-ui/sysprof-ui.h index fda84ee3..2744cf98 100644 --- a/src/libsysprof-ui/sysprof-ui.h +++ b/src/libsysprof-ui/sysprof-ui.h @@ -31,6 +31,7 @@ G_BEGIN_DECLS # include "sysprof-callgraph-view.h" # include "sysprof-capture-view.h" # include "sysprof-cell-renderer-percent.h" +# include "sysprof-cpu-aid.h" # include "sysprof-cpu-visualizer-row.h" # include "sysprof-display.h" # include "sysprof-empty-state-view.h" diff --git a/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui index 36282400..1c73beee 100644 --- a/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui +++ b/src/libsysprof-ui/ui/sysprof-profiler-assistant.ui @@ -1,6 +1,7 @@ +