summaryrefslogtreecommitdiffstats
path: root/src/gs-info-window.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:57:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:57:27 +0000
commit6f0f7d1b40a8fa8d46a2d6f4317600001cdbbb18 (patch)
treed423850ae901365e582137bdf2b5cbdffd7ca266 /src/gs-info-window.c
parentInitial commit. (diff)
downloadgnome-software-upstream.tar.xz
gnome-software-upstream.zip
Adding upstream version 43.5.upstream/43.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/gs-info-window.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/gs-info-window.c b/src/gs-info-window.c
new file mode 100644
index 0000000..92b755f
--- /dev/null
+++ b/src/gs-info-window.c
@@ -0,0 +1,124 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Purism SPC
+ *
+ * Author: Adrien Plazas <adrien.plazas@puri.sm>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/**
+ * SECTION:gs-info-window
+ * @short_description: A minimalist window designed to present information
+ *
+ * #GsInfoWindow is a window with floating window buttons which can be closed
+ * by pressing the Escape key. It is intended to present information and to not
+ * give the user many interaction possibilities.
+ *
+ * Since: 42
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <adwaita.h>
+#include <locale.h>
+
+#include "gs-common.h"
+#include "gs-info-window.h"
+
+typedef struct
+{
+ GtkWidget *overlay;
+} GsInfoWindowPrivate;
+
+static void gs_info_window_buildable_init (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GsInfoWindow, gs_info_window, ADW_TYPE_WINDOW,
+ G_ADD_PRIVATE (GsInfoWindow)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gs_info_window_buildable_init))
+
+static GtkBuildableIface *parent_buildable_iface;
+
+static void
+gs_info_window_init (GsInfoWindow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+gs_info_window_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const char *type)
+{
+ GsInfoWindow *self = GS_INFO_WINDOW (buildable);
+ GsInfoWindowPrivate *priv = gs_info_window_get_instance_private (self);
+
+ if (!priv->overlay)
+ parent_buildable_iface->add_child (buildable, builder, child, type);
+ else if (GTK_IS_WIDGET (child))
+ gs_info_window_set_child (self, GTK_WIDGET (child));
+ else
+ GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
+}
+
+static void
+gs_info_window_buildable_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+ iface->add_child = gs_info_window_buildable_add_child;
+
+}
+
+static void
+gs_info_window_class_init (GsInfoWindowClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-info-window.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, GsInfoWindow, overlay);
+
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
+}
+
+/**
+ * gs_info_window_new:
+ *
+ * Create a new #GsInfoWindow.
+ *
+ * Returns: (transfer full): a new #GsInfoWindow
+ * Since: 42
+ */
+GsInfoWindow *
+gs_info_window_new (void)
+{
+ return g_object_new (GS_TYPE_INFO_WINDOW, NULL);
+}
+
+/**
+ * gs_info_window_set_child:
+ * @self: a #GsInfoWindow
+ * @widget: (nullable): the new child of @self
+ *
+ * Create a new #GsInfoWindow.
+ *
+ * Since: 42
+ */
+void
+gs_info_window_set_child (GsInfoWindow *self,
+ GtkWidget *widget)
+{
+ GsInfoWindowPrivate *priv;
+ g_return_if_fail (GS_IS_INFO_WINDOW (self));
+ g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
+
+ priv = gs_info_window_get_instance_private (self);
+ gtk_overlay_set_child (GTK_OVERLAY (priv->overlay), widget);
+}