From ee78ec9ef1bf982bf2c9e6b966d6709de26c90eb Mon Sep 17 00:00:00 2001 From: Mohammed Sadiq Date: Fri, 18 Nov 2022 09:36:09 +0530 Subject: [PATCH] a11y: Add cc-ua-hearing-page Implement the new design[0] for Hearing panel [0] https://gitlab.gnome.org/Teams/Design/settings-mockups/-/blob/master/a11y/a11y-wires.png --- panels/universal-access/cc-ua-hearing-page.c | 173 ++++++++++++++++++ panels/universal-access/cc-ua-hearing-page.h | 42 +++++ panels/universal-access/cc-ua-hearing-page.ui | 80 ++++++++ panels/universal-access/meson.build | 2 + .../universal-access.gresource.xml | 1 + 5 files changed, 298 insertions(+) create mode 100644 panels/universal-access/cc-ua-hearing-page.c create mode 100644 panels/universal-access/cc-ua-hearing-page.h create mode 100644 panels/universal-access/cc-ua-hearing-page.ui diff --git a/panels/universal-access/cc-ua-hearing-page.c b/panels/universal-access/cc-ua-hearing-page.c new file mode 100644 index 000000000..3e1ffa6b5 --- /dev/null +++ b/panels/universal-access/cc-ua-hearing-page.c @@ -0,0 +1,173 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * Copyright (C) 2008 William Jon McCann + * Copyright (C) 2010 Intel, Inc + * Copyright 2022 Mohammed Sadiq + * Copyright 2022 Purism SPC + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author(s): + * Thomas Wood + * Rodrigo Moya + * Mohammed Sadiq + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "cc-ua-hearing-page" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "shell/cc-shell.h" +#include "cc-ua-macros.h" +#include "cc-list-row.h" +#include "cc-ua-hearing-page.h" + +struct _CcUaHearingPage +{ + AdwPreferencesPage parent_instance; + + CcListRow *overamplification_row; + GtkLabel *sound_settings_label; + + CcListRow *visual_alerts_row; + AdwComboRow *flash_type_row; + CcListRow *test_flash_row; + + GSettings *sound_settings; + GSettings *wm_settings; +}; + +G_DEFINE_TYPE (CcUaHearingPage, cc_ua_hearing_page, ADW_TYPE_PREFERENCES_PAGE) + +static void +ua_hearing_flash_type_changed_cb (CcUaHearingPage *self) +{ + GDesktopVisualBellType type; + + type = g_settings_get_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE); + adw_combo_row_set_selected (self->flash_type_row, type); +} + +static gboolean +ua_hearing_sound_settings_clicked_cb (CcUaHearingPage *self) +{ + g_autoptr(GError) error = NULL; + CcShell *shell; + CcPanel *panel; + + g_assert (CC_IS_UA_HEARING_PAGE (self)); + + panel = (CcPanel *)gtk_widget_get_ancestor (GTK_WIDGET (self), CC_TYPE_PANEL); + shell = cc_panel_get_shell (CC_PANEL (panel)); + if (!cc_shell_set_active_panel_from_id (shell, "sound", NULL, &error)) + g_warning ("Failed to activate 'sound' panel: %s", error->message); + + return TRUE; +} + +static void +ua_hearing_flash_type_row_changed_cb (CcUaHearingPage *self) +{ + guint selected_index; + + g_assert (CC_IS_UA_HEARING_PAGE (self)); + + selected_index = adw_combo_row_get_selected (self->flash_type_row); + g_settings_set_enum (self->wm_settings, KEY_VISUAL_BELL_TYPE, selected_index); +} + +static void +ua_hearing_test_flash_clicked_cb (CcUaHearingPage *self) +{ + GdkSurface *surface; + GtkNative *native; + + g_assert (CC_IS_UA_HEARING_PAGE (self)); + + native = gtk_widget_get_native (GTK_WIDGET (self)); + surface = gtk_native_get_surface (native); + + gdk_surface_beep (surface); +} + +static void +cc_ua_hearing_page_dispose (GObject *object) +{ + CcUaHearingPage *self = (CcUaHearingPage *)object; + + g_clear_object (&self->sound_settings); + g_clear_object (&self->wm_settings); + + G_OBJECT_CLASS (cc_ua_hearing_page_parent_class)->dispose (object); +} + +static void +cc_ua_hearing_page_class_init (CcUaHearingPageClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = cc_ua_hearing_page_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, + "/org/gnome/control-center/" + "universal-access/cc-ua-hearing-page.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, overamplification_row); + gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, sound_settings_label); + + gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, visual_alerts_row); + gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, flash_type_row); + gtk_widget_class_bind_template_child (widget_class, CcUaHearingPage, test_flash_row); + + gtk_widget_class_bind_template_callback (widget_class, ua_hearing_sound_settings_clicked_cb); + gtk_widget_class_bind_template_callback (widget_class, ua_hearing_flash_type_row_changed_cb); + gtk_widget_class_bind_template_callback (widget_class, ua_hearing_test_flash_clicked_cb); +} + +static void +cc_ua_hearing_page_init (CcUaHearingPage *self) +{ + const char *label; + + gtk_widget_init_template (GTK_WIDGET (self)); + + /* '#' is a dummy target to make 'Sound' clickable */ + /* TRANSLATORS: Don't translate and */ + label = "System volume can be adjusted in Sound settings."; + gtk_label_set_label (self->sound_settings_label, label); + + self->sound_settings = g_settings_new (SOUND_SETTINGS); + self->wm_settings = g_settings_new (WM_SETTINGS); + + g_settings_bind (self->sound_settings, KEY_SOUND_OVERAMPLIFY, + self->overamplification_row, "active", + G_SETTINGS_BIND_DEFAULT); + g_settings_bind (self->wm_settings, KEY_VISUAL_BELL, + self->visual_alerts_row, "active", + G_SETTINGS_BIND_DEFAULT); + + g_signal_connect_object (self->wm_settings, "changed::" KEY_VISUAL_BELL_TYPE, + G_CALLBACK (ua_hearing_flash_type_changed_cb), self, G_CONNECT_SWAPPED); +} diff --git a/panels/universal-access/cc-ua-hearing-page.h b/panels/universal-access/cc-ua-hearing-page.h new file mode 100644 index 000000000..b6c1d10fb --- /dev/null +++ b/panels/universal-access/cc-ua-hearing-page.h @@ -0,0 +1,42 @@ +/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * Copyright (C) 2008 William Jon McCann + * Copyright (C) 2010 Intel, Inc + * Copyright 2022 Mohammed Sadiq + * Copyright 2022 Purism SPC + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Author(s): + * Thomas Wood + * Rodrigo Moya + * Mohammed Sadiq + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define CC_TYPE_UA_HEARING_PAGE (cc_ua_hearing_page_get_type ()) + +G_DECLARE_FINAL_TYPE (CcUaHearingPage, cc_ua_hearing_page, CC, UA_HEARING_PAGE, AdwPreferencesPage) + +G_END_DECLS diff --git a/panels/universal-access/cc-ua-hearing-page.ui b/panels/universal-access/cc-ua-hearing-page.ui new file mode 100644 index 000000000..71d901cb9 --- /dev/null +++ b/panels/universal-access/cc-ua-hearing-page.ui @@ -0,0 +1,80 @@ + + + + diff --git a/panels/universal-access/meson.build b/panels/universal-access/meson.build index 98b14331f..f3ce5c998 100644 --- a/panels/universal-access/meson.build +++ b/panels/universal-access/meson.build @@ -17,6 +17,7 @@ sources = files( 'cc-repeat-keys-dialog.c', 'cc-typing-dialog.c', 'cc-ua-panel.c', + 'cc-ua-hearing-page.c', 'cc-ua-seeing-page.c', 'cc-visual-alerts-dialog.c', 'cc-zoom-options-dialog.c' @@ -34,6 +35,7 @@ resource_data = files( 'cc-pointing-dialog.ui', 'cc-repeat-keys-dialog.ui', 'cc-typing-dialog.ui', + 'cc-ua-hearing-page.ui', 'cc-ua-seeing-page.ui', 'cc-visual-alerts-dialog.ui', 'cc-zoom-options-dialog.ui' diff --git a/panels/universal-access/universal-access.gresource.xml b/panels/universal-access/universal-access.gresource.xml index 7e5c905b0..3e6084e51 100644 --- a/panels/universal-access/universal-access.gresource.xml +++ b/panels/universal-access/universal-access.gresource.xml @@ -7,6 +7,7 @@ cc-repeat-keys-dialog.ui cc-typing-dialog.ui cc-ua-panel.ui + cc-ua-hearing-page.ui cc-ua-seeing-page.ui cc-visual-alerts-dialog.ui cc-zoom-options-dialog.ui