[gnome-control-center] universal-access: Split sound keys dialog into its own widget



commit 828a2bee45ca8b30e32e6dca028593390acaafad
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Nov 2 16:44:04 2020 +1300

    universal-access: Split sound keys dialog into its own widget

 panels/universal-access/cc-sound-keys-dialog.c     | 76 ++++++++++++++++++++
 panels/universal-access/cc-sound-keys-dialog.h     | 29 ++++++++
 panels/universal-access/cc-sound-keys-dialog.ui    | 74 ++++++++++++++++++++
 panels/universal-access/cc-ua-panel.c              | 16 +----
 panels/universal-access/cc-ua-panel.ui             | 80 ----------------------
 panels/universal-access/meson.build                |  2 +
 .../universal-access.gresource.xml                 |  1 +
 po/POTFILES.in                                     |  1 +
 8 files changed, 185 insertions(+), 94 deletions(-)
---
diff --git a/panels/universal-access/cc-sound-keys-dialog.c b/panels/universal-access/cc-sound-keys-dialog.c
new file mode 100644
index 000000000..4cbf5835c
--- /dev/null
+++ b/panels/universal-access/cc-sound-keys-dialog.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2020 Canonical Ltd.
+ *
+ * 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.1 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 Lesser 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
+ */
+
+#include "cc-sound-keys-dialog.h"
+
+#define KEYBOARD_SETTINGS            "org.gnome.desktop.a11y.keyboard"
+#define KEY_TOGGLEKEYS_ENABLED       "togglekeys-enable"
+
+struct _CcSoundKeysDialog
+{
+  GtkDialog parent;
+
+  GtkSwitch *enable_switch;
+
+  GSettings *keyboard_settings;
+};
+
+G_DEFINE_TYPE (CcSoundKeysDialog, cc_sound_keys_dialog, GTK_TYPE_DIALOG);
+
+static void
+cc_sound_keys_dialog_dispose (GObject *object)
+{
+  CcSoundKeysDialog *self = CC_SOUND_KEYS_DIALOG (object);
+
+  g_clear_object (&self->keyboard_settings);
+
+  G_OBJECT_CLASS (cc_sound_keys_dialog_parent_class)->dispose (object);
+}
+
+static void
+cc_sound_keys_dialog_class_init (CcSoundKeysDialogClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = cc_sound_keys_dialog_dispose;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/universal-access/cc-sound-keys-dialog.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcSoundKeysDialog, enable_switch);
+}
+
+static void
+cc_sound_keys_dialog_init (CcSoundKeysDialog *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->keyboard_settings = g_settings_new (KEYBOARD_SETTINGS);
+
+  g_settings_bind (self->keyboard_settings, KEY_TOGGLEKEYS_ENABLED,
+                   self->enable_switch, "active",
+                   G_SETTINGS_BIND_DEFAULT);
+}
+
+CcSoundKeysDialog *
+cc_sound_keys_dialog_new (void)
+{
+  return g_object_new (cc_sound_keys_dialog_get_type (),
+                       "use-header-bar", TRUE,
+                       NULL);
+}
diff --git a/panels/universal-access/cc-sound-keys-dialog.h b/panels/universal-access/cc-sound-keys-dialog.h
new file mode 100644
index 000000000..4a3297753
--- /dev/null
+++ b/panels/universal-access/cc-sound-keys-dialog.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2020 Canonical Ltd.
+ *
+ * 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.1 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 Lesser 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
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+G_DECLARE_FINAL_TYPE (CcSoundKeysDialog, cc_sound_keys_dialog, CC, SOUND_KEYS_DIALOG, GtkDialog)
+
+CcSoundKeysDialog *cc_sound_keys_dialog_new (void);
+
+G_END_DECLS
diff --git a/panels/universal-access/cc-sound-keys-dialog.ui b/panels/universal-access/cc-sound-keys-dialog.ui
new file mode 100644
index 000000000..59a708ce1
--- /dev/null
+++ b/panels/universal-access/cc-sound-keys-dialog.ui
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="CcSoundKeysDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Sound Keys</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="use_header_bar">1</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">6</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Beep when Num Lock or Caps Lock are turned on or 
off.</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Sound Keys</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">enable_switch</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSwitch" id="enable_switch">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="halign">end</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/panels/universal-access/cc-ua-panel.c b/panels/universal-access/cc-ua-panel.c
index a15bb29cf..6dc6ed299 100644
--- a/panels/universal-access/cc-ua-panel.c
+++ b/panels/universal-access/cc-ua-panel.c
@@ -31,6 +31,7 @@
 #include "cc-ua-panel.h"
 #include "cc-ua-resources.h"
 #include "cc-cursor-size-dialog.h"
+#include "cc-sound-keys-dialog.h"
 #include "cc-screen-reader-dialog.h"
 #include "cc-zoom-options-dialog.h"
 
@@ -143,8 +144,6 @@ struct _CcUaPanel
   GtkWidget *scale_double_click_delay;
   GtkWidget *screen_keyboard_switch;
   GtkWidget *section_status;
-  GtkDialog *sound_keys_dialog;
-  GtkWidget *sound_keys_switch;
   GtkWidget *switch_status;
   GtkWidget *typing_bouncekeys_beep_rejected_check;
   GtkWidget *typing_bouncekeys_delay_box;
@@ -277,8 +276,6 @@ cc_ua_panel_class_init (CcUaPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, scale_double_click_delay);
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, screen_keyboard_switch);
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, section_status);
-  gtk_widget_class_bind_template_child (widget_class, CcUaPanel, sound_keys_dialog);
-  gtk_widget_class_bind_template_child (widget_class, CcUaPanel, sound_keys_switch);
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, switch_status);
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, typing_bouncekeys_beep_rejected_check);
   gtk_widget_class_bind_template_child (widget_class, CcUaPanel, typing_bouncekeys_delay_box);
@@ -576,7 +573,7 @@ activate_row (CcUaPanel *self, GtkListBoxRow *row)
     }
   else if (row == self->row_sound_keys)
     {
-      show_dialog (self, self->sound_keys_dialog);
+      run_dialog (self, GTK_DIALOG (cc_sound_keys_dialog_new ()));
     }
   else if (row == self->row_visual_alerts)
     {
@@ -659,15 +656,6 @@ cc_ua_panel_init_seeing (CcUaPanel *self)
                                 G_SETTINGS_BIND_GET,
                                 on_off_label_mapping_get,
                                 NULL, NULL, NULL);
-
-  g_settings_bind (self->kb_settings, KEY_TOGGLEKEYS_ENABLED,
-                   self->sound_keys_switch, "active",
-                   G_SETTINGS_BIND_DEFAULT);
-
-  self->toplevels = g_slist_prepend (self->toplevels, self->sound_keys_dialog);
-
-  g_signal_connect (self->sound_keys_dialog, "delete-event",
-                    G_CALLBACK (gtk_widget_hide_on_delete), NULL);
 }
 
 /* hearing/sound section */
diff --git a/panels/universal-access/cc-ua-panel.ui b/panels/universal-access/cc-ua-panel.ui
index 530942c6a..72e332606 100644
--- a/panels/universal-access/cc-ua-panel.ui
+++ b/panels/universal-access/cc-ua-panel.ui
@@ -1060,86 +1060,6 @@
       <widget name="row_click_assist"/>
     </widgets>
   </object>
-  <object class="GtkDialog" id="sound_keys_dialog">
-    <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Sound Keys</property>
-    <property name="resizable">False</property>
-    <property name="modal">True</property>
-    <property name="type_hint">dialog</property>
-    <property name="use_header_bar">1</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox3">
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child>
-          <object class="GtkLabel" id="sound_keys_blurb">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_start">12</property>
-            <property name="margin_end">6</property>
-            <property name="margin_top">6</property>
-            <property name="xalign">0</property>
-            <property name="label" translatable="yes">Beep when Num Lock or Caps Lock are turned on or 
off.</property>
-            <property name="wrap">True</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="grid4">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_start">12</property>
-            <property name="margin_end">6</property>
-            <property name="margin_top">12</property>
-            <property name="margin_bottom">12</property>
-            <property name="row_spacing">12</property>
-            <property name="column_spacing">6</property>
-            <child>
-              <object class="GtkLabel" id="sound_keys_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">_Sound Keys</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">sound_keys_switch</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkSwitch" id="sound_keys_switch">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="halign">end</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkDialog" id="visual_alerts_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
diff --git a/panels/universal-access/meson.build b/panels/universal-access/meson.build
index 5049cd4e1..fd97ad3aa 100644
--- a/panels/universal-access/meson.build
+++ b/panels/universal-access/meson.build
@@ -19,6 +19,7 @@ i18n.merge_file(
 
 sources = files(
   'cc-cursor-size-dialog.c',
+  'cc-sound-keys-dialog.c',
   'cc-screen-reader-dialog.c',
   'cc-ua-panel.c',
   'cc-zoom-options-dialog.c'
@@ -32,6 +33,7 @@ resource_data = files(
   'left_ptr_64px.png',
   'left_ptr_96px.png',
   'cc-cursor-size-dialog.ui',
+  'cc-sound-keys-dialog.ui',
   'cc-screen-reader-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 2f0aac785..c06079a03 100644
--- a/panels/universal-access/universal-access.gresource.xml
+++ b/panels/universal-access/universal-access.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/control-center/universal-access">
     <file preprocess="xml-stripblanks">cc-cursor-size-dialog.ui</file>
+    <file preprocess="xml-stripblanks">cc-sound-keys-dialog.ui</file>
     <file preprocess="xml-stripblanks">cc-screen-reader-dialog.ui</file>
     <file preprocess="xml-stripblanks">cc-ua-panel.ui</file>
     <file preprocess="xml-stripblanks">cc-zoom-options-dialog.ui</file>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 795ff4ba3..5bffeef8b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -216,6 +216,7 @@ panels/thunderbolt/cc-bolt-panel.c
 panels/thunderbolt/cc-bolt-panel.ui
 panels/thunderbolt/gnome-thunderbolt-panel.desktop.in.in
 panels/universal-access/cc-cursor-size-dialog.ui
+panels/universal-access/cc-sound-keys-dialog.ui
 panels/universal-access/cc-screen-reader-dialog.ui
 panels/universal-access/cc-ua-panel.c
 panels/universal-access/cc-ua-panel.ui


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]