GCC Code Coverage Report


Directory: ./
File: panels/system/about/cc-about-page.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 89 0.0%
Functions: 0 11 0.0%
Branches: 0 27 0.0%

Line Branch Exec Source
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 *
3 * Copyright (C) 2019 Purism SPC
4 * Copyright (C) 2017 Mohammed Sadiq <sadiq@sadiqpk.org>
5 * Copyright (C) 2010 Red Hat, Inc
6 * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "cc-about-page.h"
24 #include "cc-hostname-entry.h"
25 #include "cc-list-row.h"
26 #include "cc-system-details-window.h"
27
28 #include <config.h>
29 #include <glib/gi18n.h>
30
31 struct _CcAboutPage
32 {
33 AdwNavigationPage parent_instance;
34
35 AdwActionRow *disk_row;
36 AdwActionRow *hardware_model_row;
37 AdwActionRow *memory_row;
38 GtkPicture *os_logo;
39 AdwActionRow *os_name_row;
40 AdwActionRow *processor_row;
41
42 AdwDialog *system_details_window;
43 guint create_system_details_id;
44 };
45
46 G_DEFINE_TYPE (CcAboutPage, cc_about_page, ADW_TYPE_NAVIGATION_PAGE)
47
48 static void
49 about_page_setup_overview (CcAboutPage *self)
50 {
51 guint64 ram_size;
52 g_autofree char *memory_text = NULL;
53 g_autofree char *cpu_text = NULL;
54 g_autofree char *os_name_text = NULL;
55 g_autofree char *hardware_model_text = NULL;
56 g_autofree gchar *disk_capacity_string = NULL;
57
58 hardware_model_text = get_hardware_model_string ();
59 adw_action_row_set_subtitle (self->hardware_model_row, hardware_model_text);
60 gtk_widget_set_visible (GTK_WIDGET (self->hardware_model_row), hardware_model_text != NULL);
61
62 ram_size = get_ram_size_dmi ();
63 if (ram_size == 0)
64 ram_size = get_ram_size_libgtop ();
65 memory_text = g_format_size_full (ram_size, G_FORMAT_SIZE_IEC_UNITS);
66 adw_action_row_set_subtitle (self->memory_row, memory_text);
67
68 cpu_text = get_cpu_info ();
69 adw_action_row_set_subtitle (self->processor_row, cpu_text);
70
71 disk_capacity_string = get_primary_disk_info ();
72 if (disk_capacity_string == NULL)
73 disk_capacity_string = g_strdup (_("Unknown"));
74 adw_action_row_set_subtitle (self->disk_row, disk_capacity_string);
75
76 os_name_text = get_os_name ();
77 adw_action_row_set_subtitle (self->os_name_row, os_name_text);
78 }
79
80 static gboolean
81 cc_about_page_create_system_details (CcAboutPage *self)
82 {
83 if (!self->system_details_window)
84 {
85 self->system_details_window = ADW_DIALOG (cc_system_details_window_new ());
86 g_object_ref_sink (self->system_details_window);
87 }
88
89 g_clear_handle_id (&self->create_system_details_id, g_source_remove);
90
91 return G_SOURCE_REMOVE;
92 }
93
94 static void
95 cc_about_page_open_system_details (CcAboutPage *self)
96 {
97 cc_about_page_create_system_details (self);
98
99 adw_dialog_present (self->system_details_window, GTK_WIDGET (self));
100 }
101
102 #if !defined(DISTRIBUTOR_LOGO) || defined(DARK_MODE_DISTRIBUTOR_LOGO)
103 static gboolean
104 use_dark_theme (CcAboutPage *self)
105 {
106 AdwStyleManager *style_manager = adw_style_manager_get_default ();
107
108 return adw_style_manager_get_dark (style_manager);
109 }
110 #endif
111
112 static void
113 setup_os_logo (CcAboutPage *self)
114 {
115 #ifdef DISTRIBUTOR_LOGO
116 #ifdef DARK_MODE_DISTRIBUTOR_LOGO
117 if (use_dark_theme (self))
118 {
119 gtk_picture_set_filename (self->os_logo, DARK_MODE_DISTRIBUTOR_LOGO);
120 return;
121 }
122 #endif
123 gtk_picture_set_filename (self->os_logo, DISTRIBUTOR_LOGO);
124 return;
125 #else
126 GtkIconTheme *icon_theme;
127 g_autofree char *logo_name = g_get_os_info ("LOGO");
128 g_autoptr(GtkIconPaintable) icon_paintable = NULL;
129 g_autoptr(GPtrArray) array = NULL;
130 g_autoptr(GIcon) icon = NULL;
131 gboolean dark;
132
133 dark = use_dark_theme (self);
134 if (logo_name == NULL)
135 logo_name = g_strdup ("gnome-logo");
136
137 array = g_ptr_array_new_with_free_func (g_free);
138 if (dark)
139 g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text-dark", logo_name));
140 g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-text", logo_name));
141 if (dark)
142 g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s-dark", logo_name));
143 g_ptr_array_add (array, (gpointer) g_strdup_printf ("%s", logo_name));
144
145 icon = g_themed_icon_new_from_names ((char **) array->pdata, array->len);
146 icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
147 icon_paintable = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,
148 192,
149 gtk_widget_get_scale_factor (GTK_WIDGET (self)),
150 gtk_widget_get_direction (GTK_WIDGET (self)),
151 0);
152 gtk_picture_set_paintable (self->os_logo, GDK_PAINTABLE (icon_paintable));
153 #endif
154 }
155
156 static void
157 cc_about_page_dispose (GObject *object)
158 {
159 CcAboutPage *self = CC_ABOUT_PAGE (object);
160
161 if (self->system_details_window)
162 adw_dialog_close (self->system_details_window);
163 g_clear_object (&self->system_details_window);
164
165 g_clear_handle_id (&self->create_system_details_id, g_source_remove);
166
167 G_OBJECT_CLASS (cc_about_page_parent_class)->dispose (object);
168 }
169
170 static void
171 cc_about_page_class_init (CcAboutPageClass *klass)
172 {
173 GObjectClass *object_class = G_OBJECT_CLASS (klass);
174 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
175
176 object_class->dispose = cc_about_page_dispose;
177
178 g_type_ensure (CC_TYPE_HOSTNAME_ENTRY);
179
180 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/about/cc-about-page.ui");
181
182 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, disk_row);
183 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, hardware_model_row);
184 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, memory_row);
185 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, os_logo);
186 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, os_name_row);
187 gtk_widget_class_bind_template_child (widget_class, CcAboutPage, processor_row);
188
189 gtk_widget_class_bind_template_callback (widget_class, cc_about_page_open_system_details);
190 }
191
192 static void
193 cc_about_page_init (CcAboutPage *self)
194 {
195 AdwStyleManager *style_manager;
196
197 gtk_widget_init_template (GTK_WIDGET (self));
198
199 about_page_setup_overview (self);
200
201 style_manager = adw_style_manager_get_default ();
202 g_signal_connect_object (style_manager, "notify::dark", G_CALLBACK (setup_os_logo), self, G_CONNECT_SWAPPED);
203 setup_os_logo (self);
204
205 self->create_system_details_id = g_idle_add (G_SOURCE_FUNC (cc_about_page_create_system_details), self);
206 }
207