[gnome-initial-setup/shell/4765: 336/362] Re-introduce keyboard layout detector
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/shell/4765: 336/362] Re-introduce keyboard layout detector
- Date: Thu, 19 Mar 2015 01:49:20 +0000 (UTC)
commit c3dda65e8638b222934a6f71771afd75e15cbd4a
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Mon Feb 2 12:46:19 2015 +0100
Re-introduce keyboard layout detector
Add the keyboard layout detector in the new keyboard layout page design.
[endlessm/eos-shell#3364]
.../pages/keyboard/cc-keyboard-detector.c | 1 +
.../pages/keyboard/cc-keyboard-query.c | 78 ++------------------
.../pages/keyboard/cc-keyboard-query.h | 3 +-
.../pages/keyboard/gis-keyboard-page.c | 38 ++++++++++
.../pages/keyboard/gis-keyboard-page.ui | 8 ++
5 files changed, 54 insertions(+), 74 deletions(-)
---
diff --git a/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
b/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
index b976269..b6fe8e7 100644
--- a/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
+++ b/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
@@ -22,6 +22,7 @@
#include <config.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include "cc-keyboard-detector.h"
diff --git a/gnome-initial-setup/pages/keyboard/cc-keyboard-query.c
b/gnome-initial-setup/pages/keyboard/cc-keyboard-query.c
index c938b9c..03c6e7e 100644
--- a/gnome-initial-setup/pages/keyboard/cc-keyboard-query.c
+++ b/gnome-initial-setup/pages/keyboard/cc-keyboard-query.c
@@ -51,14 +51,7 @@ enum {
N_SIGNALS,
};
-enum {
- PROP_0,
- XKB_DATA,
- N_PROPS,
-};
-
static guint cc_keyboard_query_signals[N_SIGNALS] = { 0, };
-static GParamSpec *cc_keyboard_query_props[N_PROPS] = { NULL, };
static void
process (CcKeyboardQuery *self,
@@ -164,60 +157,13 @@ cc_keyboard_query_constructed (GObject *object)
}
static void
-cc_keyboard_query_get_property (GObject *object,
- guint id,
- GValue *value,
- GParamSpec *pspec)
-{
- CcKeyboardQuery *self = CC_KEYBOARD_QUERY (object);
- CcKeyboardQueryPrivate *priv = cc_keyboard_query_get_instance_private (self);
-
- switch (id)
- {
- case XKB_DATA:
- g_value_set_object (value, priv->xkb_data);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, id, pspec);
- }
-}
-
-static void
-cc_keyboard_query_set_property (GObject *object,
- guint id,
- const GValue *value,
- GParamSpec *pspec)
-{
- CcKeyboardQuery *self = CC_KEYBOARD_QUERY (object);
- CcKeyboardQueryPrivate *priv = cc_keyboard_query_get_instance_private (self);
-
- switch (id)
- {
- case XKB_DATA:
- priv->xkb_data = g_value_dup_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, id, pspec);
- }
-}
-
-static void
-cc_keyboard_query_dispose (GObject *object)
+cc_keyboard_query_finalize (GObject *object)
{
CcKeyboardQuery *self = CC_KEYBOARD_QUERY (object);
CcKeyboardQueryPrivate *priv = cc_keyboard_query_get_instance_private (self);
g_clear_object (&priv->xkb_data);
- G_OBJECT_CLASS (cc_keyboard_query_parent_class)->dispose (object);
-}
-
-static void
-cc_keyboard_query_finalize (GObject *object)
-{
- CcKeyboardQuery *self = CC_KEYBOARD_QUERY (object);
- CcKeyboardQueryPrivate *priv = cc_keyboard_query_get_instance_private (self);
-
g_clear_pointer (&priv->det, keyboard_detector_free);
g_clear_pointer (&priv->detected_id, g_free);
g_clear_pointer (&priv->detected_display_name, g_free);
@@ -235,9 +181,9 @@ cc_keyboard_query_layout_result (CcKeyboardQuery *self,
const char *display_name = NULL;
priv->detected_id = g_strdup (result);
- if (priv->xkb_data != NULL)
- gnome_xkb_info_get_layout_info (priv->xkb_data, result, &display_name, NULL,
- NULL, NULL);
+
+ gnome_xkb_info_get_layout_info (priv->xkb_data, result, &display_name, NULL,
+ NULL, NULL);
priv->detected_display_name = g_strdup (display_name);
result_message = g_strdup_printf ("%s\n%s",
@@ -329,19 +275,8 @@ cc_keyboard_query_class_init (CcKeyboardQueryClass *klass)
NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING);
- cc_keyboard_query_props[XKB_DATA] =
- g_param_spec_object ("xkb-data", "XKB data",
- "X Keyboard info for looking up display names of keyboard layouts",
- GNOME_TYPE_XKB_INFO,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
object_class->constructed = cc_keyboard_query_constructed;
- object_class->get_property = cc_keyboard_query_get_property;
- object_class->set_property = cc_keyboard_query_set_property;
- object_class->dispose = cc_keyboard_query_dispose;
object_class->finalize = cc_keyboard_query_finalize;
- g_object_class_install_properties (object_class, N_PROPS,
- cc_keyboard_query_props);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/initial-setup/keyboard-detector.ui");
@@ -370,15 +305,14 @@ cc_keyboard_query_init (CcKeyboardQuery *self)
priv->present_string = _("Is the following key present on your keyboard?");
priv->det = keyboard_detector_new ();
+ priv->xkb_data = gnome_xkb_info_new ();
}
GtkWidget *
-cc_keyboard_query_new (GtkWindow *main_window,
- GnomeXkbInfo *xkb_data)
+cc_keyboard_query_new (GtkWindow *main_window)
{
return g_object_new (CC_TYPE_KEYBOARD_QUERY,
"transient-for", main_window,
- "xkb-data", xkb_data,
"use-header-bar", TRUE,
NULL);
}
diff --git a/gnome-initial-setup/pages/keyboard/cc-keyboard-query.h
b/gnome-initial-setup/pages/keyboard/cc-keyboard-query.h
index 1329af1..acf1d86 100644
--- a/gnome-initial-setup/pages/keyboard/cc-keyboard-query.h
+++ b/gnome-initial-setup/pages/keyboard/cc-keyboard-query.h
@@ -54,8 +54,7 @@ struct _CcKeyboardQueryClass
};
GType cc_keyboard_query_get_type (void) G_GNUC_CONST;
-GtkWidget *cc_keyboard_query_new (GtkWindow *main_window,
- GnomeXkbInfo *xkb_info);
+GtkWidget *cc_keyboard_query_new (GtkWindow *main_window);
void cc_keyboard_query_run (CcKeyboardQuery *self);
gboolean cc_keyboard_query_get_selected (CcKeyboardQuery *self,
char **id,
diff --git a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c
b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c
index aa497b3..edf9404 100644
--- a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c
+++ b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c
@@ -33,6 +33,7 @@
#include "gis-keyboard-page.h"
#include "keyboard-resources.h"
#include "cc-input-chooser.h"
+#include "cc-keyboard-query.h"
#define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources"
#define KEY_CURRENT_INPUT_SOURCE "current"
@@ -40,6 +41,7 @@
struct _GisKeyboardPagePrivate {
GtkWidget *input_chooser;
+ GtkWidget *input_auto_detect;
GDBusProxy *localed;
GCancellable *cancellable;
@@ -178,6 +180,38 @@ input_confirmed (CcInputChooser *chooser,
}
static void
+detector_response (GtkDialog *detector,
+ gint response_id,
+ gpointer data)
+{
+ GisKeyboardPage *self = data;
+ GisKeyboardPagePrivate *priv = gis_keyboard_page_get_instance_private (self);
+ char *id;
+
+ if (response_id == GTK_RESPONSE_OK) {
+ if (cc_keyboard_query_get_selected (CC_KEYBOARD_QUERY (detector), &id, NULL)) {
+ cc_input_chooser_set_input (CC_INPUT_CHOOSER (priv->input_chooser), id, "xkb");
+ update_input (self);
+ g_free (id);
+ }
+ }
+ gtk_widget_destroy (GTK_WIDGET (detector));
+}
+
+static void
+show_keyboard_detector (CcInputChooser *chooser,
+ GisKeyboardPage *self)
+{
+ GtkWidget *detector;
+ GtkWidget *toplevel;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+ detector = cc_keyboard_query_new (GTK_WINDOW (toplevel));
+ g_signal_connect (detector, "response", G_CALLBACK (detector_response), self);
+ cc_keyboard_query_run (CC_KEYBOARD_QUERY (detector));
+}
+
+static void
gis_keyboard_page_constructed (GObject *object)
{
GisKeyboardPage *self = GIS_KEYBOARD_PAGE (object);
@@ -190,6 +224,9 @@ gis_keyboard_page_constructed (GObject *object)
g_signal_connect (priv->input_chooser, "confirm",
G_CALLBACK (input_confirmed), self);
+ g_signal_connect (priv->input_auto_detect, "clicked",
+ G_CALLBACK (show_keyboard_detector), self);
+
priv->input_settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR);
g_settings_delay (priv->input_settings);
@@ -228,6 +265,7 @@ gis_keyboard_page_class_init (GisKeyboardPageClass * klass)
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/org/gnome/initial-setup/gis-keyboard-page.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisKeyboardPage,
input_chooser);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisKeyboardPage,
input_auto_detect);
page_class->page_id = PAGE_ID;
page_class->apply = gis_keyboard_page_apply;
diff --git a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.ui
b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.ui
index 063f6de..f4afe2f 100644
--- a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.ui
+++ b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.ui
@@ -54,6 +54,14 @@
<property name="valign">start</property>
</object>
</child>
+ <child>
+ <object class="GtkButton" id="input_auto_detect">
+ <property name="label" translatable="yes">Help detect my keyboard layout</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ </child>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]