GCC Code Coverage Report


Directory: ./
File: panels/privacy/cc-privacy-panel.c
Date: 2024-05-03 09:46:52
Exec Total Coverage
Lines: 0 45 0.0%
Functions: 0 7 0.0%
Branches: 0 17 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2023 Marco Melorio
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * SPDX-License-Identifier: GPL-2.0-or-later
18 */
19
20
21 #include <config.h>
22
23 #include "cc-privacy-panel.h"
24
25 #ifdef BUILD_THUNDERBOLT
26 #include "bolt/cc-bolt-page.h"
27 #endif
28 #include "camera/cc-camera-page.h"
29 #include "diagnostics/cc-diagnostics-page.h"
30 #include "firmware-security/cc-firmware-security-page.h"
31 #include "cc-list-row.h"
32 #include "location/cc-location-page.h"
33 #include "cc-privacy-resources.h"
34 #include "screen/cc-screen-page.h"
35 #include "usage/cc-usage-page.h"
36
37 struct _CcPrivacyPanel
38 {
39 CcPanel parent_instance;
40
41 AdwNavigationView *navigation;
42 CcListRow *bolt_row;
43 CcListRow *location_row;
44 };
45
46 CC_PANEL_REGISTER (CcPrivacyPanel, cc_privacy_panel)
47
48 static const char *
49 cc_privacy_panel_get_help_uri (CcPanel *panel)
50 {
51 AdwNavigationPage *page = adw_navigation_view_get_visible_page (CC_PRIVACY_PANEL (panel)->navigation);
52 const char *page_tag = adw_navigation_page_get_tag (page);
53
54 if (g_strcmp0 (page_tag, "location") == 0)
55 return "help:gnome-help/privacy-location";
56 else if (g_strcmp0 (page_tag, "screenlock") == 0)
57 return "help:gnome-help/privacy-screen-lock";
58 else
59 return "help:gnome-help/privacy";
60 }
61
62 static void
63 cc_privacy_panel_class_init (CcPrivacyPanelClass *klass)
64 {
65 CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
66 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
67
68 panel_class->get_help_uri = cc_privacy_panel_get_help_uri;
69
70 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/privacy/cc-privacy-panel.ui");
71
72 gtk_widget_class_bind_template_child (widget_class, CcPrivacyPanel, navigation);
73 gtk_widget_class_bind_template_child (widget_class, CcPrivacyPanel, bolt_row);
74 gtk_widget_class_bind_template_child (widget_class, CcPrivacyPanel, location_row);
75
76 g_type_ensure (CC_TYPE_CAMERA_PAGE);
77 g_type_ensure (CC_TYPE_DIAGNOSTICS_PAGE);
78 g_type_ensure (CC_TYPE_FIRMWARE_SECURITY_PAGE);
79 g_type_ensure (CC_TYPE_LOCATION_PAGE);
80 g_type_ensure (CC_TYPE_SCREEN_PAGE);
81 g_type_ensure (CC_TYPE_USAGE_PAGE);
82 }
83
84 static void
85 on_subpage_set (CcPrivacyPanel *self)
86 {
87 AdwNavigationPage *subpage;
88 g_autofree gchar *tag = NULL;
89
90 g_object_get (self, "subpage", &tag, NULL);
91 if (!tag)
92 return;
93
94 subpage = adw_navigation_view_find_page (self->navigation, tag);
95 if (subpage)
96 adw_navigation_view_push (self->navigation, subpage);
97 }
98
99 static void
100 cc_privacy_panel_init (CcPrivacyPanel *self)
101 {
102 g_resources_register (cc_privacy_get_resource ());
103
104 gtk_widget_init_template (GTK_WIDGET (self));
105
106 #ifdef BUILD_THUNDERBOLT
107 CcBoltPage* bolt_page = cc_bolt_page_new ();
108
109 adw_navigation_view_add (self->navigation, ADW_NAVIGATION_PAGE (bolt_page));
110
111 g_object_bind_property (bolt_page, "visible",
112 self->bolt_row, "visible", G_BINDING_SYNC_CREATE);
113 #endif
114
115 #ifdef HAVE_LOCATION_SERVICES
116 CcLocationPage *location_page = g_object_new (CC_TYPE_LOCATION_PAGE, NULL);
117
118 adw_navigation_view_add (self->navigation, ADW_NAVIGATION_PAGE (location_page));
119
120 g_object_bind_property (location_page, "visible",
121 self->location_row, "visible", G_BINDING_SYNC_CREATE);
122 #endif
123
124 g_signal_connect_object (self, "notify::subpage", G_CALLBACK (on_subpage_set), self, G_CONNECT_SWAPPED);
125 }
126