GCC Code Coverage Report


Directory: ./
File: panels/privacy/firmware-security/cc-firmware-security-boot-dialog.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 40 0.0%
Functions: 0 6 0.0%
Branches: 0 11 0.0%

Line Branch Exec Source
1 /* cc-firmware-security-boot-dialog.c
2 *
3 * Copyright (C) 2021 Red Hat, Inc
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Kate Hsuan <hpa@redhat.com>
19 *
20 * SPDX-License-Identifier: GPL-2.0-or-later
21 */
22
23 #include "config.h"
24
25 #include <glib/gi18n-lib.h>
26
27 #include "cc-firmware-security-boot-dialog.h"
28
29 struct _CcFirmwareSecurityBootDialog
30 {
31 AdwDialog parent;
32
33 GtkWidget *secure_boot_icon;
34 GtkWidget *secure_boot_title;
35 GtkWidget *secure_boot_description;
36 };
37
38 G_DEFINE_TYPE (CcFirmwareSecurityBootDialog, cc_firmware_security_boot_dialog, ADW_TYPE_DIALOG)
39
40 static void
41 cc_firmware_security_boot_dialog_class_init (CcFirmwareSecurityBootDialogClass *klass)
42 {
43 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
44
45 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/privacy/firmware-security/cc-firmware-security-boot-dialog.ui");
46
47 gtk_widget_class_bind_template_child (widget_class, CcFirmwareSecurityBootDialog, secure_boot_title);
48 gtk_widget_class_bind_template_child (widget_class, CcFirmwareSecurityBootDialog, secure_boot_icon);
49 gtk_widget_class_bind_template_child (widget_class, CcFirmwareSecurityBootDialog, secure_boot_description);
50 }
51
52 static void
53 cc_firmware_security_boot_dialog_init (CcFirmwareSecurityBootDialog *dialog)
54 {
55 gtk_widget_init_template (GTK_WIDGET (dialog));
56 load_custom_css ("/org/gnome/control-center/privacy/firmware-security/security-level.css");
57 }
58
59 GtkWidget *
60 cc_firmware_security_boot_dialog_new (SecureBootState secure_boot_state)
61 {
62 CcFirmwareSecurityBootDialog *dialog;
63 g_autofree gchar *status_description = NULL;
64
65 dialog = g_object_new (CC_TYPE_FIRMWARE_SECURITY_BOOT_DIALOG, NULL);
66
67 switch (secure_boot_state)
68 {
69 case SECURE_BOOT_STATE_ACTIVE:
70 /* TRANSLATORS: secure boot refers to the system firmware security mode */
71 gtk_label_set_text (GTK_LABEL(dialog->secure_boot_title), _("Secure Boot is Active"));
72 gtk_image_set_from_icon_name (GTK_IMAGE (dialog->secure_boot_icon), "channel-secure-symbolic");
73 gtk_widget_add_css_class (dialog->secure_boot_icon, "good");
74 status_description = g_strdup_printf ("%s",
75 /* TRANSLATORS: this is the first section of the decription */
76 _("Secure boot prevents malicious software from being loaded when the device starts. "
77 "It is currently turned on and is functioning correctly."));
78 break;
79
80 case SECURE_BOOT_STATE_PROBLEMS:
81 /* TRANSLATORS: secure boot refers to the system firmware security mode */
82 gtk_label_set_text (GTK_LABEL (dialog->secure_boot_title), _("Secure Boot Has Problems"));
83 gtk_widget_add_css_class (dialog->secure_boot_icon, "error");
84 status_description = g_strdup_printf ("%s\n\n%s\n\n%s",
85 /* TRANSLATORS: this is the first section of the decription. */
86 _("Secure boot prevents malicious software from being loaded when the device "
87 "starts. It is currently turned on, but will not work due to having an invalid key."),
88 /* TRANSLATORS: this is the second section of description. */
89 _("Secure boot problems can often be resolved from your device's UEFI firmware settings "
90 "(BIOS) and your hardware manufacturer may provide information on how to do this."),
91 /* TRANSLATORS: this is the third section of description. */
92 _("For help, contact your hardware manufacturer or IT support provider."));
93 break;
94
95 case SECURE_BOOT_STATE_INACTIVE:
96 case SECURE_BOOT_STATE_UNKNOWN:
97 /* TRANSLATORS: secure boot refers to the system firmware security mode */
98 gtk_label_set_text (GTK_LABEL (dialog->secure_boot_title), _("Secure Boot is Turned Off"));
99 gtk_widget_add_css_class (dialog->secure_boot_icon, "error");
100 status_description = g_strdup_printf ("%s\n\n%s",
101 /* TRANSLATORS: this is the first section of the description. */
102 _("Secure boot prevents malicious software from being loaded when the device starts. It is "
103 "currently turned off."),
104 /* TRANSLATORS: this is the second section of the description. */
105 _("Secure boot can often be turned on from your device's UEFI firmware settings (BIOS). "
106 "For help, contact your hardware manufacturer or IT support provider."));
107 break;
108 }
109 gtk_label_set_text (GTK_LABEL(dialog->secure_boot_description), status_description);
110
111 return GTK_WIDGET (dialog);
112 }
113