From 5c65ddf0b23c81feb56781e9d33c8373594675dd Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 7 Jul 2023 15:08:46 -0700 Subject: [PATCH] sysprof: start on greeter window --- src/sysprof/meson.build | 1 + src/sysprof/sysprof-application.c | 7 +- src/sysprof/sysprof-greeter.c | 120 +++++++++++++ src/sysprof/sysprof-greeter.h | 33 ++++ src/sysprof/sysprof-greeter.ui | 284 ++++++++++++++++++++++++++++++ src/sysprof/sysprof.gresource.xml | 4 +- 6 files changed, 445 insertions(+), 4 deletions(-) create mode 100644 src/sysprof/sysprof-greeter.c create mode 100644 src/sysprof/sysprof-greeter.h create mode 100644 src/sysprof/sysprof-greeter.ui diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index facc30af..aaac94a8 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -1,6 +1,7 @@ sysprof_sources = [ 'main.c', 'sysprof-application.c', + 'sysprof-greeter.c', 'sysprof-window.c', ] diff --git a/src/sysprof/sysprof-application.c b/src/sysprof/sysprof-application.c index fda46796..a09422ef 100644 --- a/src/sysprof/sysprof-application.c +++ b/src/sysprof/sysprof-application.c @@ -23,6 +23,7 @@ #include "sysprof-application.h" #include "sysprof-credits.h" +#include "sysprof-greeter.h" #include "sysprof-window.h" struct _SysprofApplication @@ -35,6 +36,8 @@ G_DEFINE_TYPE (SysprofApplication, sysprof_application, ADW_TYPE_APPLICATION) static void sysprof_application_activate (GApplication *app) { + GtkWidget *greeter; + g_assert (GTK_IS_APPLICATION (app)); for (const GList *iter = gtk_application_get_windows (GTK_APPLICATION (app)); @@ -48,7 +51,9 @@ sysprof_application_activate (GApplication *app) } } - g_warning ("TODO: show greeter window"); + greeter = sysprof_greeter_new (); + gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (greeter)); + gtk_window_present (GTK_WINDOW (greeter)); } static void diff --git a/src/sysprof/sysprof-greeter.c b/src/sysprof/sysprof-greeter.c new file mode 100644 index 00000000..47c2d37c --- /dev/null +++ b/src/sysprof/sysprof-greeter.c @@ -0,0 +1,120 @@ +/* sysprof-greeter.c + * + * Copyright 2023 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 + */ + +#include "config.h" + +#include "sysprof-greeter.h" + +struct _SysprofGreeter +{ + AdwWindow parent_instance; + + GtkBox *toolbar; + AdwPreferencesPage *record_page; +}; + +enum { + PROP_0, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofGreeter, sysprof_greeter, ADW_TYPE_WINDOW) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_greeter_view_stack_notify_visible_child (SysprofGreeter *self, + GParamSpec *pspec, + AdwViewStack *stack) +{ + g_assert (SYSPROF_IS_GREETER (self)); + g_assert (ADW_IS_VIEW_STACK (stack)); + + gtk_widget_set_visible (GTK_WIDGET (self->toolbar), + GTK_WIDGET (self->record_page) == adw_view_stack_get_visible_child (stack)); +} + +static void +sysprof_greeter_dispose (GObject *object) +{ + SysprofGreeter *self = (SysprofGreeter *)object; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_GREETER); + + G_OBJECT_CLASS (sysprof_greeter_parent_class)->dispose (object); +} + +static void +sysprof_greeter_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofGreeter *self = SYSPROF_GREETER (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_greeter_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofGreeter *self = SYSPROF_GREETER (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_greeter_class_init (SysprofGreeterClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = sysprof_greeter_dispose; + object_class->get_property = sysprof_greeter_get_property; + object_class->set_property = sysprof_greeter_set_property; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-greeter.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, toolbar); + gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, record_page); + gtk_widget_class_bind_template_callback (widget_class, sysprof_greeter_view_stack_notify_visible_child); +} + +static void +sysprof_greeter_init (SysprofGreeter *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +GtkWidget * +sysprof_greeter_new (void) +{ + return g_object_new (SYSPROF_TYPE_GREETER, NULL); +} diff --git a/src/sysprof/sysprof-greeter.h b/src/sysprof/sysprof-greeter.h new file mode 100644 index 00000000..1021d18e --- /dev/null +++ b/src/sysprof/sysprof-greeter.h @@ -0,0 +1,33 @@ +/* sysprof-greeter.h + * + * Copyright 2023 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 + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_GREETER (sysprof_greeter_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofGreeter, sysprof_greeter, SYSPROF, GREETER, AdwWindow) + +GtkWidget *sysprof_greeter_new (void); + +G_END_DECLS diff --git a/src/sysprof/sysprof-greeter.ui b/src/sysprof/sysprof-greeter.ui new file mode 100644 index 00000000..2fdedab6 --- /dev/null +++ b/src/sysprof/sysprof-greeter.ui @@ -0,0 +1,284 @@ + + + + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 85ebf08b..141202a9 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -3,9 +3,7 @@ gtk/help-overlay.ui gtk/menus.ui - - - + sysprof-greeter.ui sysprof-window.ui