1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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);
}
|