[gnome-flashback/wip/segeiger/inputmethods: 1/5] input-sources: initial implementation for GfInputSource
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback/wip/segeiger/inputmethods: 1/5] input-sources: initial implementation for GfInputSource
- Date: Sun, 20 Sep 2015 18:03:41 +0000 (UTC)
commit 88c4d9e2b43ef29566a1400f1bb1378e204c3d45
Author: Sebastian Geiger <sbastig gmx net>
Date: Fri Sep 18 02:47:12 2015 +0200
input-sources: initial implementation for GfInputSource
gnome-flashback/libinput-sources/Makefile.am | 2 +
gnome-flashback/libinput-sources/gf-input-source.c | 335 ++++++++++++++++++++
gnome-flashback/libinput-sources/gf-input-source.h | 56 ++++
3 files changed, 393 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/Makefile.am b/gnome-flashback/libinput-sources/Makefile.am
index 2231201..cad3cc4 100644
--- a/gnome-flashback/libinput-sources/Makefile.am
+++ b/gnome-flashback/libinput-sources/Makefile.am
@@ -18,6 +18,8 @@ libinput_sources_la_SOURCES = \
gf-candidate-popup.h \
gf-ibus-manager.c \
gf-ibus-manager.h \
+ gf-input-source.c \
+ gf-input-source.h \
gf-input-sources.c \
gf-input-sources.h \
gf-input-source-manager.c \
diff --git a/gnome-flashback/libinput-sources/gf-input-source.c
b/gnome-flashback/libinput-sources/gf-input-source.c
new file mode 100644
index 0000000..b7bfa76
--- /dev/null
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -0,0 +1,335 @@
+/*
+ * Copyright (C) 2015 Sebastian Geiger
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <ibus-1.0/ibus.h>
+#include <string.h>
+
+#include "gf-ibus-manager.h"
+#include "gf-input-source.h"
+
+struct _GfInputSource
+{
+ GObject parent;
+
+ gchar *id;
+ gchar *display_name;
+ gchar *short_name;
+ gint index;
+
+ IBusPropList *properties;
+ GfIBusManager *ibus_manager;
+
+ gchar *xkb_id;
+};
+
+G_DEFINE_TYPE (GfInputSource, gf_input_source, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+
+ PROP_ID,
+ PROP_DISPLAY_NAME,
+ PROP_SHORT_NAME,
+ PROP_INDEX,
+ PROP_IBUS_MANAGER,
+
+ LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP] = { NULL };
+
+enum
+{
+ SIGNAL_CHANGED,
+ SIGNAL_ACTIVATE,
+ SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST] = { 0 };
+
+/**
+ * gf_input_source_initialize_xkb_id:
+ * @input_source: The input source for which the xkb_id is retrieved.
+ *
+ * Returns: The xkb_id of the @input_source. The result must be freed.
+ */
+static gchar *
+gf_input_source_initialize_xkb_id (GfInputSource *input_source)
+{
+ IBusEngineDesc *engine_desc;
+ const gchar *layout_variant;
+ const gchar *layout;
+
+ engine_desc = gf_ibus_manager_get_engine_description (input_source->ibus_manager,
+ input_source->id);
+
+ if (!engine_desc)
+ {
+ return g_strdup (input_source->id);
+ }
+
+ layout = ibus_engine_desc_get_layout (engine_desc);
+ layout_variant = ibus_engine_desc_get_layout_variant (engine_desc);
+
+ if (layout_variant && strlen (layout_variant) > 0)
+ {
+ return g_strdup_printf ("%s+%s", layout, layout_variant);
+ }
+ else
+ {
+ return g_strdup (layout);
+ }
+}
+
+static void
+gf_input_source_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GfInputSource *input_source;
+
+ input_source = GF_INPUT_SOURCE (object);
+
+ switch (prop_id) {
+ case PROP_ID:
+ g_value_set_string (value, input_source->id);
+ break;
+
+ case PROP_DISPLAY_NAME:
+ g_value_set_string (value, input_source->display_name);
+ break;
+
+ case PROP_SHORT_NAME:
+ g_value_set_string (value, input_source->short_name);
+ break;
+
+ case PROP_INDEX:
+ g_value_set_int (value, input_source->index);
+ break;
+
+ case PROP_IBUS_MANAGER:
+ g_value_set_object (value, input_source->ibus_manager);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_input_source_set_ibus_manager (GfInputSource *input_source,
+ GfIBusManager *ibus_manager)
+{
+ input_source->ibus_manager = ibus_manager;
+}
+
+static void
+gf_input_source_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GfInputSource *input_source;
+
+ input_source = GF_INPUT_SOURCE (object);
+
+ switch (prop_id) {
+ case PROP_ID:
+ gf_input_source_set_id (input_source, g_value_get_string (value));
+ break;
+
+ case PROP_DISPLAY_NAME:
+ gf_input_source_set_display_name (input_source,
+ g_value_get_string (value));
+ break;
+
+ case PROP_SHORT_NAME:
+ gf_input_source_set_short_name (input_source, g_value_get_string (value));
+ break;
+
+ case PROP_INDEX:
+ gf_input_source_set_index (input_source, g_value_get_int (value));
+ break;
+
+ case PROP_IBUS_MANAGER:
+ gf_input_source_set_ibus_manager (input_source, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_input_source_finalize (GObject *object)
+{
+ GfInputSource *input_source;
+
+ input_source = GF_INPUT_SOURCE (object);
+
+ g_free ((gpointer) input_source->xkb_id);
+}
+
+static void
+gf_input_source_class_init (GfInputSourceClass *input_source_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (input_source_class);
+
+ object_class->get_property = gf_input_source_get_property;
+ object_class->set_property = gf_input_source_set_property;
+ object_class->finalize = gf_input_source_finalize;
+
+ properties[PROP_ID] =
+ g_param_spec_string ("id", "ID", "The ID of the input source",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_DISPLAY_NAME] =
+ g_param_spec_string ("display-name", "Display name",
+ "The display name of the input source",
+ NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_SHORT_NAME] =
+ g_param_spec_string ("short-name", "Short name",
+ "The short name of the input source",
+ NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_INDEX] =
+ g_param_spec_int ("index", "Index", "The index of the input source",
+ -1, G_MAXINT, -1,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_IBUS_MANAGER] =
+ g_param_spec_object ("ibus-manager", "IBus Manager",
+ "The instance of IBus Manager used by the input-sources module",
+ GF_TYPE_IBUS_MANAGER,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ signals[SIGNAL_CHANGED] =
+ g_signal_new ("changed",
+ G_OBJECT_CLASS_TYPE (input_source_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 1, G_TYPE_STRV);
+}
+
+static void
+gf_input_source_init (GfInputSource *inputSources)
+{
+ inputSources->xkb_id = gf_input_source_initialize_xkb_id (inputSources);
+}
+
+
+GfInputSource *
+gf_input_source_new (const char *id,
+ const char *display_name,
+ const char *short_name,
+ guint index,
+ GfIBusManager *ibus_manager)
+{
+ return g_object_new (GF_TYPE_INPUT_SOURCE,
+ "id", id,
+ "display-name", display_name,
+ "short-name", short_name,
+ "index", index,
+ "ibus-manager", ibus_manager,
+ NULL);
+}
+
+void
+gf_input_source_set_id (GfInputSource *input_source,
+ const char *const id)
+{
+ g_free (input_source->id);
+ input_source->id = g_strdup (id);
+}
+
+void
+gf_input_source_set_display_name (GfInputSource *input_source,
+ const char *const display_name)
+{
+ g_free (input_source->display_name);
+ input_source->display_name = g_strdup (display_name);
+}
+
+void
+gf_input_source_set_short_name (GfInputSource *input_source,
+ const char *const short_name)
+{
+ g_free (input_source->short_name);
+ input_source->short_name = g_strdup (short_name);
+ g_signal_emit (input_source, SIGNAL_CHANGED, 0, short_name);
+}
+
+void
+gf_input_source_set_index (GfInputSource *input_source,
+ gint index)
+{
+ input_source->index = index;
+}
+
+gchar *
+gf_input_source_get_id (GfInputSource *input_source)
+{
+ return input_source->id;
+}
+
+gchar *
+gf_input_source_get_display_name (GfInputSource *input_source)
+{
+ return input_source->display_name;
+}
+
+gchar *
+gf_input_source_get_short_name (GfInputSource *input_source)
+{
+ return input_source->short_name;
+}
+
+gint
+gf_input_source_get_index (GfInputSource *input_source)
+{
+ return input_source->index;
+}
+
+void
+gf_input_source_activate (GfInputSource *input_source)
+{
+ g_signal_emit (input_source, SIGNAL_ACTIVATE, 0);
+}
+
+gchar*
+gf_input_source_get_xkb_id (GfInputSource *input_source)
+{
+ return g_strdup (input_source->xkb_id);
+}
diff --git a/gnome-flashback/libinput-sources/gf-input-source.h
b/gnome-flashback/libinput-sources/gf-input-source.h
new file mode 100644
index 0000000..48ebff4
--- /dev/null
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2015 Sebastian Geiger
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_INPUT_SOURCE_H
+#define GF_INPUT_SOURCE_H
+
+#include <glib-object.h>
+#include "gf-ibus-manager.h"
+
+#define GF_TYPE_INPUT_SOURCE gf_input_source_get_type ()
+G_DECLARE_FINAL_TYPE (GfInputSource, gf_input_source, GF, INPUT_SOURCE, GObject)
+
+GfInputSource *gf_input_source_new (const char *id,
+ const char *display_name,
+ const char *short_name,
+ guint index,
+ GfIBusManager *ibus_manager);
+
+void gf_input_source_set_id (GfInputSource *input_source,
+ const char* const id);
+
+void gf_input_source_set_display_name (GfInputSource *input_source,
+ const char* const display_name);
+
+void gf_input_source_set_short_name (GfInputSource *input_source,
+ const char* const short_name);
+
+void gf_input_source_set_index (GfInputSource *input_source,
+ gint index);
+
+
+gchar * gf_input_source_get_id (GfInputSource *inputSource);
+
+gchar * gf_input_source_get_display_name (GfInputSource *input_source);
+
+gchar * gf_input_source_get_short_name (GfInputSource *input_source);
+
+gint gf_input_source_get_index (GfInputSource *input_source);
+
+void gf_input_source_activate (GfInputSource *input_source);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]