GCC Code Coverage Report


Directory: ./
File: panels/system/secure-shell/cc-secure-shell-page.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 37 0.0%
Functions: 0 8 0.0%
Branches: 0 9 0.0%

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-secure-shell-page"
22
23 #include <glib/gi18n.h>
24
25 #include "cc-hostname.h"
26 #include "cc-list-row.h"
27 #include "cc-secure-shell.h"
28 #include "cc-secure-shell-page.h"
29 #include "cc-systemd-service.h"
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 struct _CcSecureShellPage {
36 AdwDialog parent_instance;
37
38 AdwActionRow *hostname_row;
39 AdwSwitchRow *secure_shell_row;
40 AdwToastOverlay *toast_overlay;
41
42 GCancellable *cancellable;
43 };
44
45 G_DEFINE_TYPE (CcSecureShellPage, cc_secure_shell_page, ADW_TYPE_DIALOG)
46
47 static void
48 on_copy_ssh_command_button_clicked (CcSecureShellPage *self)
49 {
50 gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (self)),
51 adw_action_row_get_subtitle (ADW_ACTION_ROW (self->hostname_row)));
52
53 adw_toast_overlay_add_toast (self->toast_overlay, adw_toast_new (_("Command copied to clipboard")));
54 }
55
56 static void
57 secure_shell_row_activate (CcSecureShellPage *self)
58 {
59 cc_secure_shell_set_enabled (self->cancellable, self->secure_shell_row);
60 }
61
62 static void
63 cc_secure_shell_page_dispose (GObject *object)
64 {
65 CcSecureShellPage *self = (CcSecureShellPage *) object;
66
67 g_cancellable_cancel (self->cancellable);
68 g_clear_object (&self->cancellable);
69
70 G_OBJECT_CLASS (cc_secure_shell_page_parent_class)->dispose (object);
71 }
72
73 static void
74 cc_secure_shell_page_class_init (CcSecureShellPageClass * klass)
75 {
76 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
77 GObjectClass *object_class = G_OBJECT_CLASS (klass);
78
79 object_class->dispose = cc_secure_shell_page_dispose;
80
81 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/system/secure-shell/cc-secure-shell-page.ui");
82
83 gtk_widget_class_bind_template_child (widget_class, CcSecureShellPage, hostname_row);
84 gtk_widget_class_bind_template_child (widget_class, CcSecureShellPage, secure_shell_row);
85 gtk_widget_class_bind_template_child (widget_class, CcSecureShellPage, toast_overlay);
86
87 gtk_widget_class_bind_template_callback (widget_class, on_copy_ssh_command_button_clicked);
88 gtk_widget_class_bind_template_callback (widget_class, secure_shell_row_activate);
89 }
90
91 static void
92 cc_secure_shell_page_init (CcSecureShellPage *self)
93 {
94 g_autofree gchar *hostname = NULL;
95 g_autofree gchar *command = NULL;
96
97 gtk_widget_init_template (GTK_WIDGET (self));
98
99 self->cancellable = g_cancellable_new ();
100
101 cc_secure_shell_get_enabled (self->secure_shell_row);
102 g_signal_connect_object (self->secure_shell_row,
103 "notify::active",
104 G_CALLBACK (secure_shell_row_activate),
105 self,
106 G_CONNECT_SWAPPED);
107
108 hostname = cc_hostname_get_display_hostname (cc_hostname_get_default ());
109 command = g_strdup_printf ("ssh %s", hostname);
110 adw_action_row_set_subtitle (self->hostname_row, command);
111 }
112