Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright 2024 Red Hat Inc |
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 3 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-3.0-or-later |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#undef G_LOG_DOMAIN |
21 |
|
|
#define G_LOG_DOMAIN "cc-desktop-sharing-page" |
22 |
|
|
|
23 |
|
|
#include "cc-desktop-sharing-page.h" |
24 |
|
|
#include "cc-encryption-fingerprint-dialog.h" |
25 |
|
|
#include "cc-gnome-remote-desktop.h" |
26 |
|
|
#include "cc-hostname.h" |
27 |
|
|
#include "cc-password-utils.h" |
28 |
|
|
#include "cc-list-row.h" |
29 |
|
|
#include "cc-tls-certificate.h" |
30 |
|
|
#include "cc-systemd-service.h" |
31 |
|
|
|
32 |
|
|
#ifdef HAVE_CONFIG_H |
33 |
|
|
# include "config.h" |
34 |
|
|
#endif |
35 |
|
|
|
36 |
|
|
#include <errno.h> |
37 |
|
|
#include <glib/gi18n.h> |
38 |
|
|
#include <gio/gio.h> |
39 |
|
|
#include <gtk/gtk.h> |
40 |
|
|
#include <locale.h> |
41 |
|
|
|
42 |
|
|
#ifdef GDK_WINDOWING_WAYLAND |
43 |
|
|
#include <gdk/wayland/gdkwayland.h> |
44 |
|
|
#endif |
45 |
|
|
|
46 |
|
|
#include <pwd.h> |
47 |
|
|
#include <pwquality.h> |
48 |
|
|
#include <unistd.h> |
49 |
|
|
|
50 |
|
|
#include "org.gnome.RemoteDesktop.h" |
51 |
|
|
|
52 |
|
|
#define GNOME_REMOTE_DESKTOP_SCHEMA_ID "org.gnome.desktop.remote-desktop" |
53 |
|
|
#define GNOME_REMOTE_DESKTOP_RDP_SCHEMA_ID "org.gnome.desktop.remote-desktop.rdp" |
54 |
|
|
#define REMOTE_DESKTOP_STORE_CREDENTIALS_TIMEOUT_S 1 |
55 |
|
|
#define REMOTE_DESKTOP_SERVICE "gnome-remote-desktop.service" |
56 |
|
|
#define RDP_SERVER_DBUS_SERVICE "org.gnome.RemoteDesktop.User" |
57 |
|
|
#define RDP_SERVER_OBJECT_PATH "/org/gnome/RemoteDesktop/Rdp/Server" |
58 |
|
|
|
59 |
|
|
struct _CcDesktopSharingPage { |
60 |
|
|
AdwBin parent_instance; |
61 |
|
|
|
62 |
|
|
GtkWidget *toast_overlay; |
63 |
|
|
|
64 |
|
|
GsdRemoteDesktopRdpServer *rdp_server; |
65 |
|
|
|
66 |
|
|
AdwSwitchRow *desktop_sharing_row; |
67 |
|
|
AdwSwitchRow *remote_control_row; |
68 |
|
|
AdwActionRow *hostname_row; |
69 |
|
|
AdwActionRow *port_row; |
70 |
|
|
GtkWidget *username_entry; |
71 |
|
|
GtkWidget *password_entry; |
72 |
|
|
GtkWidget *generate_password_button; |
73 |
|
|
GtkWidget *verify_encryption_button; |
74 |
|
|
|
75 |
|
|
guint desktop_sharing_name_watch; |
76 |
|
|
guint store_credentials_id; |
77 |
|
|
GTlsCertificate *certificate; |
78 |
|
|
|
79 |
|
|
GSettings *rdp_settings; |
80 |
|
|
GCancellable *cancellable; |
81 |
|
|
}; |
82 |
|
|
|
83 |
|
✗ |
G_DEFINE_TYPE (CcDesktopSharingPage, cc_desktop_sharing_page, ADW_TYPE_BIN) |
84 |
|
|
|
85 |
|
|
static void |
86 |
|
✗ |
on_generate_password_button_clicked (CcDesktopSharingPage *self) |
87 |
|
|
{ |
88 |
|
✗ |
g_autofree char *new_password = cc_generate_password (); |
89 |
|
|
|
90 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->password_entry), new_password); |
91 |
|
✗ |
} |
92 |
|
|
|
93 |
|
|
static void |
94 |
|
✗ |
on_verify_encryption_button_clicked (CcDesktopSharingPage *self) |
95 |
|
|
{ |
96 |
|
|
CcEncryptionFingerprintDialog *dialog; |
97 |
|
|
|
98 |
|
✗ |
g_return_if_fail (self->certificate); |
99 |
|
|
|
100 |
|
✗ |
dialog = g_object_new (CC_TYPE_ENCRYPTION_FINGERPRINT_DIALOG, NULL); |
101 |
|
✗ |
cc_encryption_fingerprint_dialog_set_certificate (dialog, self->certificate); |
102 |
|
✗ |
adw_dialog_present (ADW_DIALOG (dialog), GTK_WIDGET (self)); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
static char * |
106 |
|
✗ |
get_hostname (void) |
107 |
|
|
{ |
108 |
|
✗ |
return cc_hostname_get_display_hostname (cc_hostname_get_default ()); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
static gboolean |
112 |
|
✗ |
check_schema_available (CcDesktopSharingPage *self, |
113 |
|
|
const gchar *schema_id) |
114 |
|
|
{ |
115 |
|
|
GSettingsSchemaSource *source; |
116 |
|
✗ |
g_autoptr(GSettingsSchema) schema = NULL; |
117 |
|
|
|
118 |
|
✗ |
source = g_settings_schema_source_get_default (); |
119 |
|
✗ |
if (!source) |
120 |
|
✗ |
return FALSE; |
121 |
|
|
|
122 |
|
✗ |
schema = g_settings_schema_source_lookup (source, schema_id, TRUE); |
123 |
|
✗ |
if (!schema) |
124 |
|
✗ |
return FALSE; |
125 |
|
|
|
126 |
|
✗ |
return TRUE; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
static gboolean |
130 |
|
✗ |
store_credentials_timeout (gpointer user_data) |
131 |
|
|
{ |
132 |
|
✗ |
CcDesktopSharingPage *self = (CcDesktopSharingPage*) user_data; |
133 |
|
|
const char *username, *password; |
134 |
|
|
|
135 |
|
✗ |
username = gtk_editable_get_text (GTK_EDITABLE (self->username_entry)); |
136 |
|
✗ |
password = gtk_editable_get_text (GTK_EDITABLE (self->password_entry)); |
137 |
|
|
|
138 |
|
✗ |
if (username && password) |
139 |
|
|
{ |
140 |
|
✗ |
cc_grd_store_rdp_credentials (username, password, self->cancellable); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
✗ |
self->store_credentials_id = 0; |
144 |
|
|
|
145 |
|
✗ |
return G_SOURCE_REMOVE; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
static gboolean |
149 |
|
✗ |
is_desktop_sharing_enabled (CcDesktopSharingPage *self) |
150 |
|
|
{ |
151 |
|
✗ |
if (!g_settings_get_boolean (self->rdp_settings, "enable")) |
152 |
|
✗ |
return FALSE; |
153 |
|
|
|
154 |
|
✗ |
return cc_is_service_active (REMOTE_DESKTOP_SERVICE, G_BUS_TYPE_SESSION); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
static void |
158 |
|
✗ |
disable_gnome_desktop_sharing_service (CcDesktopSharingPage *self) |
159 |
|
|
{ |
160 |
|
✗ |
g_autoptr(GError) error = NULL; |
161 |
|
|
|
162 |
|
✗ |
g_settings_set_boolean (self->rdp_settings, "enable", FALSE); |
163 |
|
|
|
164 |
|
✗ |
if (!cc_disable_service (REMOTE_DESKTOP_SERVICE, |
165 |
|
|
G_BUS_TYPE_SESSION, |
166 |
|
|
&error)) |
167 |
|
✗ |
g_warning ("Failed to enable remote desktop service: %s", error->message); |
168 |
|
✗ |
} |
169 |
|
|
|
170 |
|
|
static void |
171 |
|
✗ |
enable_gnome_desktop_sharing_service (CcDesktopSharingPage *self) |
172 |
|
|
{ |
173 |
|
✗ |
g_autoptr(GError) error = NULL; |
174 |
|
|
|
175 |
|
✗ |
if (is_desktop_sharing_enabled (self)) |
176 |
|
✗ |
return; |
177 |
|
|
|
178 |
|
✗ |
if (!cc_enable_service (REMOTE_DESKTOP_SERVICE, G_BUS_TYPE_SESSION, &error)) |
179 |
|
|
{ |
180 |
|
✗ |
g_warning ("Failed to enable remote desktop service: %s", error->message); |
181 |
|
✗ |
disable_gnome_desktop_sharing_service (self); |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
static void |
186 |
|
✗ |
on_credentials_changed (CcDesktopSharingPage *self) |
187 |
|
|
{ |
188 |
|
✗ |
g_clear_handle_id (&self->store_credentials_id, |
189 |
|
|
g_source_remove); |
190 |
|
|
|
191 |
|
✗ |
self->store_credentials_id = |
192 |
|
✗ |
g_timeout_add_seconds (REMOTE_DESKTOP_STORE_CREDENTIALS_TIMEOUT_S, |
193 |
|
|
store_credentials_timeout, |
194 |
|
|
self); |
195 |
|
✗ |
} |
196 |
|
|
|
197 |
|
|
static void |
198 |
|
✗ |
calc_default_tls_paths (char **out_dir_path, |
199 |
|
|
char **out_cert_path, |
200 |
|
|
char **out_key_path) |
201 |
|
|
{ |
202 |
|
✗ |
g_autofree char *dir_path = NULL; |
203 |
|
|
|
204 |
|
✗ |
dir_path = g_build_filename (g_get_user_data_dir(), "gnome-remote-desktop", "certificates", NULL); |
205 |
|
|
|
206 |
|
✗ |
if (out_cert_path) |
207 |
|
✗ |
*out_cert_path = g_build_filename(dir_path, "rdp-tls.crt", NULL); |
208 |
|
✗ |
if (out_key_path) |
209 |
|
✗ |
*out_key_path = g_build_filename(dir_path, "rdp-tls.key", NULL); |
210 |
|
|
|
211 |
|
✗ |
if (out_dir_path) |
212 |
|
✗ |
*out_dir_path = g_steal_pointer (&dir_path); |
213 |
|
✗ |
} |
214 |
|
|
|
215 |
|
|
static void |
216 |
|
✗ |
set_tls_certificate (CcDesktopSharingPage *self, |
217 |
|
|
GTlsCertificate *tls_certificate) |
218 |
|
|
{ |
219 |
|
✗ |
g_set_object (&self->certificate, tls_certificate); |
220 |
|
✗ |
gtk_widget_set_sensitive (self->verify_encryption_button, TRUE); |
221 |
|
✗ |
} |
222 |
|
|
|
223 |
|
|
static void |
224 |
|
✗ |
on_certificate_generated (GObject *source_object, |
225 |
|
|
GAsyncResult *res, |
226 |
|
|
gpointer user_data) |
227 |
|
|
{ |
228 |
|
|
CcDesktopSharingPage *self; |
229 |
|
✗ |
g_autoptr(GTlsCertificate) tls_certificate = NULL; |
230 |
|
✗ |
g_autoptr(GError) error = NULL; |
231 |
|
✗ |
g_autofree char *cert_path = NULL; |
232 |
|
✗ |
g_autofree char *key_path = NULL; |
233 |
|
|
|
234 |
|
✗ |
tls_certificate = bonsai_tls_certificate_new_generate_finish (res, &error); |
235 |
|
✗ |
if (!tls_certificate) |
236 |
|
|
{ |
237 |
|
✗ |
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
238 |
|
✗ |
return; |
239 |
|
|
|
240 |
|
✗ |
g_warning ("Failed to generate TLS certificate: %s", error->message); |
241 |
|
✗ |
return; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
✗ |
self = (CcDesktopSharingPage *)user_data; |
245 |
|
|
|
246 |
|
✗ |
calc_default_tls_paths (NULL, &cert_path, &key_path); |
247 |
|
|
|
248 |
|
✗ |
g_settings_set_string (self->rdp_settings, "tls-cert", cert_path); |
249 |
|
✗ |
g_settings_set_string (self->rdp_settings, "tls-key", key_path); |
250 |
|
|
|
251 |
|
✗ |
set_tls_certificate (self, tls_certificate); |
252 |
|
|
|
253 |
|
✗ |
enable_gnome_desktop_sharing_service (self); |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
static void |
257 |
|
✗ |
enable_gnome_desktop_sharing (CcDesktopSharingPage *self) |
258 |
|
|
{ |
259 |
|
✗ |
g_autofree char *dir_path = NULL; |
260 |
|
✗ |
g_autofree char *cert_path = NULL; |
261 |
|
✗ |
g_autofree char *key_path = NULL; |
262 |
|
✗ |
g_autoptr(GFile) dir = NULL; |
263 |
|
✗ |
g_autoptr(GFile) cert_file = NULL; |
264 |
|
✗ |
g_autoptr(GFile) key_file = NULL; |
265 |
|
✗ |
g_autoptr(GError) error = NULL; |
266 |
|
|
|
267 |
|
✗ |
g_settings_set_boolean (self->rdp_settings, "enable", TRUE); |
268 |
|
|
|
269 |
|
✗ |
cert_path = g_settings_get_string (self->rdp_settings, "tls-cert"); |
270 |
|
✗ |
key_path = g_settings_get_string (self->rdp_settings, "tls-key"); |
271 |
|
✗ |
if (strlen (cert_path) > 0 && |
272 |
|
✗ |
strlen (key_path) > 0) |
273 |
|
|
{ |
274 |
|
✗ |
g_autoptr(GTlsCertificate) tls_certificate = NULL; |
275 |
|
|
|
276 |
|
✗ |
tls_certificate = g_tls_certificate_new_from_file (cert_path, &error); |
277 |
|
✗ |
if (tls_certificate) |
278 |
|
|
{ |
279 |
|
✗ |
set_tls_certificate (self, tls_certificate); |
280 |
|
|
|
281 |
|
✗ |
enable_gnome_desktop_sharing_service (self); |
282 |
|
✗ |
return; |
283 |
|
|
} |
284 |
|
|
|
285 |
|
✗ |
g_warning ("Configured TLS certificate invalid: %s", error->message); |
286 |
|
✗ |
return; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
✗ |
calc_default_tls_paths (&dir_path, &cert_path, &key_path); |
290 |
|
|
|
291 |
|
✗ |
dir = g_file_new_for_path (dir_path); |
292 |
|
✗ |
if (!g_file_query_exists (dir, NULL)) |
293 |
|
|
{ |
294 |
|
✗ |
if (!g_file_make_directory_with_parents (dir, NULL, &error)) |
295 |
|
|
{ |
296 |
|
✗ |
g_warning ("Failed to create remote desktop certificate directory: %s", |
297 |
|
|
error->message); |
298 |
|
✗ |
return; |
299 |
|
|
} |
300 |
|
|
} |
301 |
|
|
|
302 |
|
✗ |
cert_file = g_file_new_for_path (cert_path); |
303 |
|
✗ |
key_file = g_file_new_for_path (key_path); |
304 |
|
|
|
305 |
|
✗ |
if (g_file_query_exists (cert_file, NULL) && |
306 |
|
✗ |
g_file_query_exists (key_file, NULL)) |
307 |
|
|
{ |
308 |
|
✗ |
g_autoptr(GTlsCertificate) tls_certificate = NULL; |
309 |
|
|
|
310 |
|
✗ |
tls_certificate = g_tls_certificate_new_from_file (cert_path, &error); |
311 |
|
✗ |
if (tls_certificate) |
312 |
|
|
{ |
313 |
|
✗ |
g_settings_set_string (self->rdp_settings, "tls-cert", cert_path); |
314 |
|
✗ |
g_settings_set_string (self->rdp_settings, "tls-key", key_path); |
315 |
|
|
|
316 |
|
✗ |
set_tls_certificate (self, tls_certificate); |
317 |
|
|
|
318 |
|
✗ |
enable_gnome_desktop_sharing_service (self); |
319 |
|
✗ |
return; |
320 |
|
|
} |
321 |
|
|
|
322 |
|
✗ |
g_warning ("Existing TLS certificate invalid: %s", error->message); |
323 |
|
✗ |
return; |
324 |
|
|
} |
325 |
|
|
|
326 |
|
✗ |
bonsai_tls_certificate_new_generate_async (cert_path, |
327 |
|
|
key_path, |
328 |
|
|
"US", |
329 |
|
|
"GNOME", |
330 |
|
|
self->cancellable, |
331 |
|
|
on_certificate_generated, |
332 |
|
|
self); |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
static void |
336 |
|
✗ |
on_desktop_sharing_active_changed (CcDesktopSharingPage *self) |
337 |
|
|
{ |
338 |
|
✗ |
if (adw_switch_row_get_active (self->desktop_sharing_row)) |
339 |
|
✗ |
enable_gnome_desktop_sharing (self); |
340 |
|
|
else |
341 |
|
✗ |
disable_gnome_desktop_sharing_service (self); |
342 |
|
✗ |
} |
343 |
|
|
|
344 |
|
|
static void |
345 |
|
✗ |
add_toast (CcDesktopSharingPage *self, |
346 |
|
|
const char *message) |
347 |
|
|
{ |
348 |
|
✗ |
adw_toast_overlay_add_toast (ADW_TOAST_OVERLAY (self->toast_overlay), |
349 |
|
|
adw_toast_new (message)); |
350 |
|
✗ |
} |
351 |
|
|
|
352 |
|
|
static void |
353 |
|
✗ |
on_address_copy_clicked (CcDesktopSharingPage *self, |
354 |
|
|
GtkButton *button) |
355 |
|
|
{ |
356 |
|
✗ |
gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)), |
357 |
|
|
adw_action_row_get_subtitle (self->hostname_row)); |
358 |
|
✗ |
add_toast (self, _("Device address copied to clipboard")); |
359 |
|
✗ |
} |
360 |
|
|
|
361 |
|
|
static void |
362 |
|
✗ |
on_port_copy_clicked (CcDesktopSharingPage *self, |
363 |
|
|
GtkButton *button) |
364 |
|
|
{ |
365 |
|
✗ |
gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)), |
366 |
|
|
adw_action_row_get_subtitle (self->port_row)); |
367 |
|
✗ |
add_toast (self, _("Port number copied to clipboard")); |
368 |
|
✗ |
} |
369 |
|
|
|
370 |
|
|
static void |
371 |
|
✗ |
on_username_copy_clicked (CcDesktopSharingPage *self, |
372 |
|
|
GtkButton *button) |
373 |
|
|
{ |
374 |
|
✗ |
GtkEditable *editable = GTK_EDITABLE (self->username_entry); |
375 |
|
|
|
376 |
|
✗ |
gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)), |
377 |
|
|
gtk_editable_get_text (editable)); |
378 |
|
✗ |
add_toast (self, _("Username copied to clipboard")); |
379 |
|
✗ |
} |
380 |
|
|
|
381 |
|
|
static void |
382 |
|
✗ |
on_password_copy_clicked (CcDesktopSharingPage *self, |
383 |
|
|
GtkButton *button) |
384 |
|
|
{ |
385 |
|
✗ |
GtkEditable *editable = GTK_EDITABLE (self->password_entry); |
386 |
|
|
|
387 |
|
✗ |
gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)), |
388 |
|
|
gtk_editable_get_text (editable)); |
389 |
|
✗ |
add_toast (self, _("Password copied to clipboard")); |
390 |
|
✗ |
} |
391 |
|
|
|
392 |
|
|
static void |
393 |
|
✗ |
setup_desktop_sharing_page (CcDesktopSharingPage *self) |
394 |
|
|
{ |
395 |
|
✗ |
const gchar *username = NULL; |
396 |
|
✗ |
const gchar *password = NULL; |
397 |
|
✗ |
g_autofree char *hostname = NULL; |
398 |
|
|
|
399 |
|
✗ |
self->rdp_settings = g_settings_new (GNOME_REMOTE_DESKTOP_RDP_SCHEMA_ID); |
400 |
|
|
|
401 |
|
✗ |
hostname = get_hostname (); |
402 |
|
✗ |
adw_action_row_set_subtitle (self->hostname_row, hostname); |
403 |
|
|
|
404 |
|
✗ |
username = cc_grd_lookup_rdp_username (self->cancellable); |
405 |
|
✗ |
password = cc_grd_lookup_rdp_password (self->cancellable); |
406 |
|
✗ |
if (username != NULL) |
407 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->username_entry), username); |
408 |
|
✗ |
if (password != NULL) |
409 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->password_entry), password); |
410 |
|
|
|
411 |
|
✗ |
g_signal_connect_swapped (self->username_entry, |
412 |
|
|
"notify::text", |
413 |
|
|
G_CALLBACK (on_credentials_changed), |
414 |
|
|
self); |
415 |
|
✗ |
g_signal_connect_swapped (self->password_entry, |
416 |
|
|
"notify::text", |
417 |
|
|
G_CALLBACK (on_credentials_changed), |
418 |
|
|
self); |
419 |
|
✗ |
if (username == NULL) |
420 |
|
|
{ |
421 |
|
✗ |
struct passwd *pw = getpwuid (getuid ()); |
422 |
|
✗ |
if (pw != NULL) |
423 |
|
✗ |
username = g_strdup (pw->pw_name); |
424 |
|
|
else |
425 |
|
✗ |
g_warning ("Failed to get username: %s", g_strerror (errno)); |
426 |
|
|
} |
427 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->username_entry), username); |
428 |
|
|
|
429 |
|
✗ |
if (password == NULL) |
430 |
|
|
{ |
431 |
|
✗ |
g_autofree gchar *pw = cc_generate_password (); |
432 |
|
✗ |
if (pw != NULL) |
433 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->password_entry), pw); |
434 |
|
|
} |
435 |
|
|
|
436 |
|
✗ |
g_signal_connect_object (self->desktop_sharing_row, "notify::active", |
437 |
|
|
G_CALLBACK (on_desktop_sharing_active_changed), self, |
438 |
|
|
G_CONNECT_SWAPPED); |
439 |
|
|
|
440 |
|
✗ |
adw_switch_row_set_active (self->desktop_sharing_row, is_desktop_sharing_enabled (self)); |
441 |
|
|
|
442 |
|
✗ |
g_settings_bind (self->rdp_settings, |
443 |
|
|
"enable", |
444 |
|
✗ |
self->desktop_sharing_row, |
445 |
|
|
"active", |
446 |
|
|
G_SETTINGS_BIND_DEFAULT); |
447 |
|
✗ |
g_settings_bind (self->rdp_settings, |
448 |
|
|
"view-only", |
449 |
|
✗ |
self->remote_control_row, |
450 |
|
|
"active", |
451 |
|
|
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN); |
452 |
|
✗ |
g_object_bind_property (self->desktop_sharing_row, "active", |
453 |
|
✗ |
self->remote_control_row, "sensitive", |
454 |
|
|
G_BINDING_SYNC_CREATE); |
455 |
|
✗ |
g_object_bind_property (self->password_entry, "sensitive", |
456 |
|
✗ |
self->generate_password_button, "sensitive", |
457 |
|
|
G_BINDING_SYNC_CREATE); |
458 |
|
✗ |
} |
459 |
|
|
|
460 |
|
|
static void |
461 |
|
✗ |
desktop_sharing_name_appeared (GDBusConnection *connection, |
462 |
|
|
const gchar *name, |
463 |
|
|
const gchar *name_owner, |
464 |
|
|
gpointer user_data) |
465 |
|
|
{ |
466 |
|
✗ |
CcDesktopSharingPage *self = (CcDesktopSharingPage *)user_data; |
467 |
|
|
|
468 |
|
✗ |
g_clear_handle_id (&self->desktop_sharing_name_watch, g_bus_unwatch_name); |
469 |
|
|
|
470 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self), TRUE); |
471 |
|
|
|
472 |
|
✗ |
setup_desktop_sharing_page (self); |
473 |
|
✗ |
} |
474 |
|
|
|
475 |
|
|
static void |
476 |
|
✗ |
check_desktop_sharing_available (CcDesktopSharingPage *self) |
477 |
|
|
{ |
478 |
|
✗ |
if (!check_schema_available (self, GNOME_REMOTE_DESKTOP_SCHEMA_ID) || |
479 |
|
✗ |
!check_schema_available (self, GNOME_REMOTE_DESKTOP_RDP_SCHEMA_ID)) |
480 |
|
|
{ |
481 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self), FALSE); |
482 |
|
✗ |
return; |
483 |
|
|
} |
484 |
|
|
|
485 |
|
✗ |
self->desktop_sharing_name_watch = g_bus_watch_name (G_BUS_TYPE_SESSION, |
486 |
|
|
"org.gnome.Mutter.RemoteDesktop", |
487 |
|
|
G_BUS_NAME_WATCHER_FLAGS_NONE, |
488 |
|
|
desktop_sharing_name_appeared, |
489 |
|
|
NULL, |
490 |
|
|
self, |
491 |
|
|
NULL); |
492 |
|
|
} |
493 |
|
|
|
494 |
|
|
static void |
495 |
|
✗ |
cc_desktop_sharing_page_dispose (GObject *object) |
496 |
|
|
{ |
497 |
|
✗ |
CcDesktopSharingPage *self = (CcDesktopSharingPage *)object; |
498 |
|
|
|
499 |
|
✗ |
g_cancellable_cancel (self->cancellable); |
500 |
|
✗ |
g_clear_object (&self->cancellable); |
501 |
|
|
|
502 |
|
✗ |
g_clear_handle_id (&self->store_credentials_id, g_source_remove); |
503 |
|
|
|
504 |
|
✗ |
g_clear_object (&self->rdp_server); |
505 |
|
✗ |
g_clear_object (&self->rdp_settings); |
506 |
|
|
|
507 |
|
✗ |
G_OBJECT_CLASS (cc_desktop_sharing_page_parent_class)->dispose (object); |
508 |
|
✗ |
} |
509 |
|
|
|
510 |
|
|
static void |
511 |
|
✗ |
cc_desktop_sharing_page_class_init (CcDesktopSharingPageClass * klass) |
512 |
|
|
{ |
513 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
514 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
515 |
|
|
|
516 |
|
✗ |
object_class->dispose = cc_desktop_sharing_page_dispose; |
517 |
|
|
|
518 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/remote-desktop/cc-desktop-sharing-page.ui"); |
519 |
|
|
|
520 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, toast_overlay); |
521 |
|
|
|
522 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, desktop_sharing_row); |
523 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, remote_control_row); |
524 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, hostname_row); |
525 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, port_row); |
526 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, username_entry); |
527 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, password_entry); |
528 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, generate_password_button); |
529 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcDesktopSharingPage, verify_encryption_button); |
530 |
|
|
|
531 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_address_copy_clicked); |
532 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_port_copy_clicked); |
533 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_username_copy_clicked); |
534 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_password_copy_clicked); |
535 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_generate_password_button_clicked); |
536 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_verify_encryption_button_clicked); |
537 |
|
✗ |
} |
538 |
|
|
|
539 |
|
|
static gboolean |
540 |
|
✗ |
format_port_for_row (GBinding *binding, |
541 |
|
|
const GValue *from_value, |
542 |
|
|
GValue *to_value, |
543 |
|
|
gpointer user_data) |
544 |
|
|
{ |
545 |
|
✗ |
int port = g_value_get_int (from_value); |
546 |
|
|
|
547 |
|
✗ |
if (port <= 0) |
548 |
|
✗ |
g_value_set_string (to_value, " "); |
549 |
|
|
else |
550 |
|
✗ |
g_value_take_string (to_value, g_strdup_printf ("%u", port)); |
551 |
|
|
|
552 |
|
✗ |
return TRUE; |
553 |
|
|
} |
554 |
|
|
|
555 |
|
|
static gboolean |
556 |
|
✗ |
sensitize_row_from_port (GBinding *binding, |
557 |
|
|
const GValue *from_value, |
558 |
|
|
GValue *to_value, |
559 |
|
|
gpointer user_data) |
560 |
|
|
{ |
561 |
|
✗ |
int port = g_value_get_int (from_value); |
562 |
|
|
|
563 |
|
✗ |
g_value_set_boolean (to_value, port > 0); |
564 |
|
|
|
565 |
|
✗ |
return TRUE; |
566 |
|
|
} |
567 |
|
|
|
568 |
|
|
static void |
569 |
|
✗ |
on_connected_to_remote_desktop_rdp_server (GObject *source_object, |
570 |
|
|
GAsyncResult *result, |
571 |
|
|
gpointer user_data) |
572 |
|
|
{ |
573 |
|
✗ |
CcDesktopSharingPage *self = user_data; |
574 |
|
✗ |
g_autoptr (GError) error = NULL; |
575 |
|
|
|
576 |
|
✗ |
g_clear_object (&self->rdp_server); |
577 |
|
✗ |
self->rdp_server = gsd_remote_desktop_rdp_server_proxy_new_finish (result, &error); |
578 |
|
|
|
579 |
|
✗ |
if (error) |
580 |
|
|
{ |
581 |
|
✗ |
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
582 |
|
✗ |
g_warning ("Failed to create remote desktop proxy: %s", error->message); |
583 |
|
✗ |
return; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
✗ |
g_object_bind_property_full (self->rdp_server, "port", |
587 |
|
✗ |
self->port_row, "subtitle", |
588 |
|
|
G_BINDING_SYNC_CREATE, |
589 |
|
|
format_port_for_row, |
590 |
|
|
NULL, |
591 |
|
|
NULL, |
592 |
|
|
NULL); |
593 |
|
✗ |
g_object_bind_property_full (self->rdp_server, "port", |
594 |
|
✗ |
self->port_row, "sensitive", |
595 |
|
|
G_BINDING_SYNC_CREATE, |
596 |
|
|
sensitize_row_from_port, |
597 |
|
|
NULL, |
598 |
|
|
NULL, |
599 |
|
|
NULL); |
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
static void |
603 |
|
✗ |
connect_to_remote_desktop_rdp_server (CcDesktopSharingPage *self) |
604 |
|
|
{ |
605 |
|
✗ |
g_autoptr (GError) error = NULL; |
606 |
|
✗ |
g_autoptr (GDBusConnection) connection = NULL; |
607 |
|
|
|
608 |
|
✗ |
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, self->cancellable, &error); |
609 |
|
|
|
610 |
|
✗ |
if (error) |
611 |
|
✗ |
g_warning ("Could not connect to system message bus: %s", error->message); |
612 |
|
|
|
613 |
|
✗ |
if (!connection) |
614 |
|
✗ |
return; |
615 |
|
|
|
616 |
|
✗ |
gsd_remote_desktop_rdp_server_proxy_new (connection, |
617 |
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION, |
618 |
|
|
RDP_SERVER_DBUS_SERVICE, |
619 |
|
|
RDP_SERVER_OBJECT_PATH, |
620 |
|
|
self->cancellable, |
621 |
|
|
(GAsyncReadyCallback) |
622 |
|
|
on_connected_to_remote_desktop_rdp_server, |
623 |
|
|
self); |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
static void |
627 |
|
✗ |
cc_desktop_sharing_page_init (CcDesktopSharingPage *self) |
628 |
|
|
{ |
629 |
|
✗ |
g_autoptr(GtkCssProvider) provider = NULL; |
630 |
|
|
|
631 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
632 |
|
|
|
633 |
|
✗ |
self->cancellable = g_cancellable_new (); |
634 |
|
✗ |
check_desktop_sharing_available (self); |
635 |
|
✗ |
connect_to_remote_desktop_rdp_server (self); |
636 |
|
|
|
637 |
|
✗ |
provider = gtk_css_provider_new (); |
638 |
|
✗ |
gtk_css_provider_load_from_resource (provider, |
639 |
|
|
"/org/gnome/control-center/system/remote-desktop/remote-desktop.css"); |
640 |
|
✗ |
gtk_style_context_add_provider_for_display (gdk_display_get_default (), |
641 |
|
✗ |
GTK_STYLE_PROVIDER (provider), |
642 |
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
643 |
|
✗ |
} |
644 |
|
|
|