Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2008 William Jon McCann <jmccann@redhat.com> |
4 |
|
|
* Copyright (C) 2010 Intel, Inc |
5 |
|
|
* Copyright 2022 Mohammed Sadiq <sadiq@sadiqpk.org> |
6 |
|
|
* Copyright 2022 Purism SPC |
7 |
|
|
* |
8 |
|
|
* Licensed under the GNU General Public License Version 2 |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* (at your option) any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
23 |
|
|
* |
24 |
|
|
* Author(s): |
25 |
|
|
* Thomas Wood <thomas.wood@intel.com> |
26 |
|
|
* Rodrigo Moya <rodrigo@gnome.org> |
27 |
|
|
* Mohammed Sadiq <sadiq@sadiqpk.org> |
28 |
|
|
* |
29 |
|
|
* SPDX-License-Identifier: GPL-2.0-or-later |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
#undef G_LOG_DOMAIN |
33 |
|
|
#define G_LOG_DOMAIN "cc-ua-hearing-page" |
34 |
|
|
|
35 |
|
|
#ifdef HAVE_CONFIG_H |
36 |
|
|
# include "config.h" |
37 |
|
|
#endif |
38 |
|
|
|
39 |
|
|
#include <gdesktop-enums.h> |
40 |
|
|
#include <glib/gi18n-lib.h> |
41 |
|
|
|
42 |
|
|
#include "shell/cc-shell.h" |
43 |
|
|
#include "cc-ua-macros.h" |
44 |
|
|
#include "cc-ua-hearing-page.h" |
45 |
|
|
|
46 |
|
|
struct _CcUaHearingPage |
47 |
|
|
{ |
48 |
|
|
AdwNavigationPage parent_instance; |
49 |
|
|
|
50 |
|
|
AdwSwitchRow *overamplification_row; |
51 |
|
|
GtkLabel *sound_settings_label; |
52 |
|
|
|
53 |
|
|
AdwSwitchRow *visual_alerts_row; |
54 |
|
|
AdwComboRow *flash_type_row; |
55 |
|
|
|
56 |
|
|
GSettings *sound_settings; |
57 |
|
|
GSettings *wm_settings; |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
✗ |
G_DEFINE_TYPE (CcUaHearingPage, cc_ua_hearing_page, ADW_TYPE_NAVIGATION_PAGE) |
61 |
|
|
|
62 |
|
|
static void |
63 |
|
✗ |
ua_hearing_flash_type_changed_cb (CcUaHearingPage *self) |
64 |
|
|
{ |
65 |
|
|
GDesktopVisualBellType type; |
66 |
|
|
|
67 |
|
✗ |
type = g_settings_get_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE); |
68 |
|
✗ |
adw_combo_row_set_selected (self->flash_type_row, type); |
69 |
|
✗ |
} |
70 |
|
|
|
71 |
|
|
static gboolean |
72 |
|
✗ |
ua_hearing_sound_settings_clicked_cb (CcUaHearingPage *self) |
73 |
|
|
{ |
74 |
|
✗ |
g_autoptr(GError) error = NULL; |
75 |
|
|
CcShell *shell; |
76 |
|
|
CcPanel *panel; |
77 |
|
|
|
78 |
|
✗ |
g_assert (CC_IS_UA_HEARING_PAGE (self)); |
79 |
|
|
|
80 |
|
✗ |
panel = (CcPanel *)gtk_widget_get_ancestor (GTK_WIDGET (self), CC_TYPE_PANEL); |
81 |
|
✗ |
shell = cc_panel_get_shell (CC_PANEL (panel)); |
82 |
|
✗ |
if (!cc_shell_set_active_panel_from_id (shell, "sound", NULL, &error)) |
83 |
|
✗ |
g_warning ("Failed to activate 'sound' panel: %s", error->message); |
84 |
|
|
|
85 |
|
✗ |
return TRUE; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
static void |
89 |
|
✗ |
ua_hearing_flash_type_row_changed_cb (CcUaHearingPage *self) |
90 |
|
|
{ |
91 |
|
|
guint selected_index; |
92 |
|
|
|
93 |
|
✗ |
g_assert (CC_IS_UA_HEARING_PAGE (self)); |
94 |
|
|
|
95 |
|
✗ |
selected_index = adw_combo_row_get_selected (self->flash_type_row); |
96 |
|
✗ |
g_settings_set_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE, selected_index); |
97 |
|
✗ |
} |
98 |
|
|
|
99 |
|
|
static void |
100 |
|
✗ |
ua_hearing_test_flash_clicked_cb (CcUaHearingPage *self) |
101 |
|
|
{ |
102 |
|
|
GdkSurface *surface; |
103 |
|
|
GtkNative *native; |
104 |
|
|
|
105 |
|
✗ |
g_assert (CC_IS_UA_HEARING_PAGE (self)); |
106 |
|
|
|
107 |
|
✗ |
native = gtk_widget_get_native (GTK_WIDGET (self)); |
108 |
|
✗ |
surface = gtk_native_get_surface (native); |
109 |
|
|
|
110 |
|
✗ |
gdk_surface_beep (surface); |
111 |
|
✗ |
} |
112 |
|
|
|
113 |
|
|
static void |
114 |
|
✗ |
cc_ua_hearing_page_dispose (GObject *object) |
115 |
|
|
{ |
116 |
|
✗ |
CcUaHearingPage *self = (CcUaHearingPage *)object; |
117 |
|
|
|
118 |
|
✗ |
g_clear_object (&self->sound_settings); |
119 |
|
✗ |
g_clear_object (&self->wm_settings); |
120 |
|
|
|
121 |
|
✗ |
G_OBJECT_CLASS (cc_ua_hearing_page_parent_class)->dispose (object); |
122 |
|
✗ |
} |
123 |
|
|
|
124 |
|
|
static void |
125 |
|
✗ |
cc_ua_hearing_page_class_init (CcUaHearingPageClass *klass) |
126 |
|
|
{ |
127 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
128 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
129 |
|
|
|
130 |
|
✗ |
object_class->dispose = cc_ua_hearing_page_dispose; |
131 |
|
|
|
132 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, |
133 |
|
|
"/org/gnome/control-center/" |
134 |
|
|
"universal-access/cc-ua-hearing-page.ui"); |
135 |
|
|
|
136 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, overamplification_row); |
137 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, sound_settings_label); |
138 |
|
|
|
139 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, visual_alerts_row); |
140 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, flash_type_row); |
141 |
|
|
|
142 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, ua_hearing_sound_settings_clicked_cb); |
143 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, ua_hearing_flash_type_row_changed_cb); |
144 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, ua_hearing_test_flash_clicked_cb); |
145 |
|
✗ |
} |
146 |
|
|
|
147 |
|
|
static void |
148 |
|
✗ |
cc_ua_hearing_page_init (CcUaHearingPage *self) |
149 |
|
|
{ |
150 |
|
✗ |
g_autofree gchar *sound_panel_link = NULL; |
151 |
|
✗ |
g_autofree gchar *label = NULL; |
152 |
|
|
|
153 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
154 |
|
|
|
155 |
|
|
/* Translators: This will be presented as the text of a link to the Sound panel */ |
156 |
|
✗ |
sound_panel_link = g_strdup_printf ("<a href='#'>%s</a>", C_("Sound panel name", "Sound")); |
157 |
|
|
/* Translators: %s is a link to the Sound panel with the label "Sound" */ |
158 |
|
✗ |
label = g_strdup_printf (_("System volume can be adjusted in %s settings"), sound_panel_link); |
159 |
|
|
|
160 |
|
✗ |
gtk_label_set_label (self->sound_settings_label, label); |
161 |
|
|
|
162 |
|
✗ |
self->sound_settings = g_settings_new (SOUND_SETTINGS); |
163 |
|
✗ |
self->wm_settings = g_settings_new (WM_SETTINGS); |
164 |
|
|
|
165 |
|
✗ |
g_settings_bind (self->sound_settings, KEY_SOUND_OVERAMPLIFY, |
166 |
|
✗ |
self->overamplification_row, "active", |
167 |
|
|
G_SETTINGS_BIND_DEFAULT); |
168 |
|
✗ |
g_settings_bind (self->wm_settings, KEY_VISUAL_BELL, |
169 |
|
✗ |
self->visual_alerts_row, "active", |
170 |
|
|
G_SETTINGS_BIND_DEFAULT); |
171 |
|
|
|
172 |
|
✗ |
g_signal_connect_object (self->wm_settings, "changed::" KEY_VISUAL_BELL_TYPE, |
173 |
|
|
G_CALLBACK (ua_hearing_flash_type_changed_cb), self, G_CONNECT_SWAPPED); |
174 |
|
✗ |
ua_hearing_flash_type_changed_cb (self); |
175 |
|
✗ |
} |
176 |
|
|
|