Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* cc-system-panel.c |
3 |
|
|
* |
4 |
|
|
* Copyright 2023 Gotam Gorabh <gautamy672@gmail.com> |
5 |
|
|
* |
6 |
|
|
* This program is free software: you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 |
|
|
* |
19 |
|
|
* SPDX-License-Identifier: GPL-3.0-or-later |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <config.h> |
23 |
|
|
|
24 |
|
|
#include <glib/gi18n-lib.h> |
25 |
|
|
|
26 |
|
|
#include "cc-list-row.h" |
27 |
|
|
#include "cc-system-panel.h" |
28 |
|
|
#include "cc-system-resources.h" |
29 |
|
|
|
30 |
|
|
#include "about/cc-about-page.h" |
31 |
|
|
#include "datetime/cc-datetime-page.h" |
32 |
|
|
#include "region/cc-region-page.h" |
33 |
|
|
#include "remote-desktop/cc-remote-desktop-page.h" |
34 |
|
|
#include "secure-shell/cc-secure-shell-page.h" |
35 |
|
|
#include "users/cc-users-page.h" |
36 |
|
|
|
37 |
|
|
struct _CcSystemPanel |
38 |
|
|
{ |
39 |
|
|
CcPanel parent_instance; |
40 |
|
|
|
41 |
|
|
AdwNavigationView *navigation; |
42 |
|
|
|
43 |
|
|
AdwActionRow *about_row; |
44 |
|
|
AdwActionRow *datetime_row; |
45 |
|
|
AdwActionRow *region_row; |
46 |
|
|
AdwActionRow *remote_desktop_row; |
47 |
|
|
AdwActionRow *users_row; |
48 |
|
|
|
49 |
|
|
CcSecureShellPage *secure_shell_dialog; |
50 |
|
|
AdwNavigationPage *software_updates_group; |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
✗ |
CC_PANEL_REGISTER (CcSystemPanel, cc_system_panel) |
54 |
|
|
|
55 |
|
|
static gboolean |
56 |
|
✗ |
gnome_software_allows_updates (void) |
57 |
|
|
{ |
58 |
|
✗ |
const gchar *schema_id = "org.gnome.software"; |
59 |
|
|
GSettingsSchemaSource *source; |
60 |
|
✗ |
g_autoptr(GSettingsSchema) schema = NULL; |
61 |
|
✗ |
g_autoptr(GSettings) settings = NULL; |
62 |
|
|
|
63 |
|
✗ |
source = g_settings_schema_source_get_default (); |
64 |
|
|
|
65 |
|
✗ |
if (source == NULL) |
66 |
|
✗ |
return FALSE; |
67 |
|
|
|
68 |
|
✗ |
schema = g_settings_schema_source_lookup (source, schema_id, FALSE); |
69 |
|
|
|
70 |
|
✗ |
if (schema == NULL) |
71 |
|
✗ |
return FALSE; |
72 |
|
|
|
73 |
|
✗ |
settings = g_settings_new (schema_id); |
74 |
|
✗ |
return g_settings_get_boolean (settings, "allow-updates"); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
static gboolean |
78 |
|
✗ |
gnome_software_exists (void) |
79 |
|
|
{ |
80 |
|
✗ |
g_autofree gchar *path = g_find_program_in_path ("gnome-software"); |
81 |
|
✗ |
return path != NULL; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
static gboolean |
85 |
|
✗ |
gpk_update_viewer_exists (void) |
86 |
|
|
{ |
87 |
|
✗ |
g_autofree gchar *path = g_find_program_in_path ("gpk-update-viewer"); |
88 |
|
✗ |
return path != NULL; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
static gboolean |
92 |
|
✗ |
show_software_updates_group (CcSystemPanel *self) |
93 |
|
|
{ |
94 |
|
✗ |
return (gnome_software_exists () && gnome_software_allows_updates ()) || |
95 |
|
✗ |
gpk_update_viewer_exists (); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
static void |
99 |
|
✗ |
cc_system_page_open_software_update (CcSystemPanel *self) |
100 |
|
|
{ |
101 |
|
✗ |
g_autoptr(GError) error = NULL; |
102 |
|
|
gboolean ret; |
103 |
|
|
char *argv[3]; |
104 |
|
|
|
105 |
|
✗ |
if (gnome_software_exists ()) |
106 |
|
|
{ |
107 |
|
✗ |
argv[0] = "gnome-software"; |
108 |
|
✗ |
argv[1] = "--mode=updates"; |
109 |
|
✗ |
argv[2] = NULL; |
110 |
|
|
} |
111 |
|
|
else |
112 |
|
|
{ |
113 |
|
✗ |
argv[0] = "gpk-update-viewer"; |
114 |
|
✗ |
argv[1] = NULL; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
✗ |
ret = g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); |
118 |
|
✗ |
if (!ret) |
119 |
|
✗ |
g_warning ("Failed to spawn %s: %s", argv[0], error->message); |
120 |
|
✗ |
} |
121 |
|
|
|
122 |
|
|
static void |
123 |
|
✗ |
on_secure_shell_row_clicked (CcSystemPanel *self) |
124 |
|
|
{ |
125 |
|
✗ |
if (self->secure_shell_dialog == NULL) |
126 |
|
|
{ |
127 |
|
✗ |
self->secure_shell_dialog = g_object_new (CC_TYPE_SECURE_SHELL_PAGE, NULL); |
128 |
|
✗ |
g_object_add_weak_pointer (G_OBJECT (self->secure_shell_dialog), |
129 |
|
✗ |
(gpointer *) &self->secure_shell_dialog); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
✗ |
adw_dialog_present (ADW_DIALOG (self->secure_shell_dialog), GTK_WIDGET (self)); |
133 |
|
✗ |
} |
134 |
|
|
|
135 |
|
|
static void |
136 |
|
✗ |
on_subpage_set (CcSystemPanel *self) |
137 |
|
|
{ |
138 |
|
|
AdwNavigationPage *subpage; |
139 |
|
✗ |
g_autofree gchar *tag = NULL; |
140 |
|
✗ |
GType page_type = G_TYPE_INVALID; |
141 |
|
|
|
142 |
|
✗ |
g_object_get (self, "subpage", &tag, NULL); |
143 |
|
✗ |
if (!tag) |
144 |
|
✗ |
return; |
145 |
|
|
|
146 |
|
✗ |
if (g_str_equal (tag, "about")) |
147 |
|
✗ |
page_type = CC_TYPE_ABOUT_PAGE; |
148 |
|
✗ |
else if (g_str_equal (tag, "datetime")) |
149 |
|
✗ |
page_type = CC_TYPE_DATE_TIME_PAGE; |
150 |
|
✗ |
else if (g_str_equal (tag, "region")) |
151 |
|
✗ |
page_type = CC_TYPE_REGION_PAGE; |
152 |
|
✗ |
else if (g_str_equal (tag, "remote-desktop")) |
153 |
|
✗ |
page_type = CC_TYPE_REMOTE_DESKTOP_PAGE; |
154 |
|
✗ |
else if (g_str_equal (tag, "users")) |
155 |
|
✗ |
page_type = CC_TYPE_USERS_PAGE; |
156 |
|
|
|
157 |
|
✗ |
if (page_type == G_TYPE_INVALID) |
158 |
|
✗ |
return; |
159 |
|
|
|
160 |
|
✗ |
subpage = ADW_NAVIGATION_PAGE (g_object_new (page_type, NULL)); |
161 |
|
✗ |
if (subpage) |
162 |
|
✗ |
adw_navigation_view_push (self->navigation, subpage); |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
static void |
166 |
|
✗ |
on_page_activated (AdwActionRow *row, |
167 |
|
|
gpointer user_data) |
168 |
|
|
{ |
169 |
|
✗ |
CcSystemPanel *self = CC_SYSTEM_PANEL (user_data); |
170 |
|
✗ |
GType page_type = G_TYPE_INVALID; |
171 |
|
|
|
172 |
|
✗ |
if (row == self->about_row) |
173 |
|
✗ |
page_type = CC_TYPE_ABOUT_PAGE; |
174 |
|
✗ |
else if (row == self->datetime_row) |
175 |
|
✗ |
page_type = CC_TYPE_DATE_TIME_PAGE; |
176 |
|
✗ |
else if (row == self->region_row) |
177 |
|
✗ |
page_type = CC_TYPE_REGION_PAGE; |
178 |
|
✗ |
else if (row == self->remote_desktop_row) |
179 |
|
✗ |
page_type = CC_TYPE_REMOTE_DESKTOP_PAGE; |
180 |
|
✗ |
else if (row == self->users_row) |
181 |
|
✗ |
page_type = CC_TYPE_USERS_PAGE; |
182 |
|
|
|
183 |
|
✗ |
if (!page_type) |
184 |
|
✗ |
return; |
185 |
|
|
|
186 |
|
✗ |
adw_navigation_view_push (self->navigation, g_object_new (page_type, NULL)); |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
static void |
190 |
|
✗ |
cc_system_panel_class_init (CcSystemPanelClass *klass) |
191 |
|
|
{ |
192 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
193 |
|
|
|
194 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/cc-system-panel.ui"); |
195 |
|
|
|
196 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, about_row); |
197 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, datetime_row); |
198 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, region_row); |
199 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, remote_desktop_row); |
200 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, users_row); |
201 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, navigation); |
202 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcSystemPanel, software_updates_group); |
203 |
|
|
|
204 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, cc_system_page_open_software_update); |
205 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_secure_shell_row_clicked); |
206 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_page_activated); |
207 |
|
|
|
208 |
|
✗ |
g_type_ensure (CC_TYPE_ABOUT_PAGE); |
209 |
|
✗ |
g_type_ensure (CC_TYPE_DATE_TIME_PAGE); |
210 |
|
✗ |
g_type_ensure (CC_TYPE_REGION_PAGE); |
211 |
|
✗ |
g_type_ensure (CC_TYPE_REMOTE_DESKTOP_PAGE); |
212 |
|
✗ |
g_type_ensure (CC_TYPE_SECURE_SHELL_PAGE); |
213 |
|
✗ |
g_type_ensure (CC_TYPE_USERS_PAGE); |
214 |
|
✗ |
} |
215 |
|
|
|
216 |
|
|
static void |
217 |
|
✗ |
cc_system_panel_init (CcSystemPanel *self) |
218 |
|
|
{ |
219 |
|
✗ |
g_resources_register (cc_system_get_resource ()); |
220 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
221 |
|
|
|
222 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->software_updates_group), show_software_updates_group (self)); |
223 |
|
|
|
224 |
|
✗ |
g_signal_connect_object (self, "notify::subpage", G_CALLBACK (on_subpage_set), self, G_CONNECT_SWAPPED); |
225 |
|
✗ |
} |
226 |
|
|
|