[gnome-flashback/wip/segeiger/inputmethods] input-source: implement gf-input-source
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback/wip/segeiger/inputmethods] input-source: implement gf-input-source
- Date: Fri, 18 Sep 2015 01:01:13 +0000 (UTC)
commit 4e8c4fa66bf705dd99adc5b7708ec8dc1515f4e4
Author: Sebastian Geiger <sbastig gmx net>
Date: Fri Sep 18 02:47:12 2015 +0200
input-source: implement gf-input-source
gnome-flashback/libinput-sources/Makefile.am | 2 +
gnome-flashback/libinput-sources/gf-input-source.c | 276 ++++++++++++++++++++
gnome-flashback/libinput-sources/gf-input-source.h | 54 ++++
3 files changed, 332 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/Makefile.am b/gnome-flashback/libinput-sources/Makefile.am
index 8e7722c..8cb942e 100644
--- a/gnome-flashback/libinput-sources/Makefile.am
+++ b/gnome-flashback/libinput-sources/Makefile.am
@@ -16,6 +16,8 @@ libinput_sources_la_SOURCES = \
gf-input-sources.h \
gf-ibus-manager.c \
gf-ibus-manager.h \
+ gf-input-source.c \
+ gf-input-source.h \
$(NULL)
libinput_sources_la_LDFLAGS = \
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..571cb30
--- /dev/null
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -0,0 +1,276 @@
+/*
+ * 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 <ibus-1.0/ibus.h>
+#include <string.h>
+#include "gf-input-source.h"
+#include "gf-ibus-manager.h"
+
+struct _GfInputSource
+{
+ GObject parent;
+
+ gchar *id;
+ gchar *displayName;
+ gchar *shortName;
+ gint index;
+
+ IBusPropList properties;
+
+ const gchar *xkbId;
+};
+
+G_DEFINE_TYPE (GfInputSource, gf_input_source, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+
+ PROP_ID,
+ PROP_DISPLAY_NAME,
+ PROP_SHORT_NAME,
+ PROP_INDEX
+};
+
+enum
+{
+ SIGNAL_CHANGED,
+ SIGNAL_ACTIVATE,
+ SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST] = {0};
+
+/**
+ * gf_input_source_get_xkb_id:
+ * @inputSource: The input source for which the xkbId is retrieved.
+ *
+ * Returns: The xkbId of the @inputSource. The result must be freed.
+ */
+static const gchar *
+gf_input_source_get_xkb_id (GfInputSource *inputSource)
+{
+ IBusEngineDesc *engineDesc;
+ GfIBusManager *iBusManager;
+ const gchar* layoutVariant; /* Must not be freed */
+ const gchar* layout; /* Must not be freed */
+
+ iBusManager = gf_ibus_manager_get_ibus_manager ();
+ engineDesc = gf_ibus_manager_get_engine_description (iBusManager, inputSource->id);
+
+ if (!engineDesc) {
+ return inputSource->id;
+ }
+
+ layout = ibus_engine_desc_get_layout (engineDesc);
+ layoutVariant = ibus_engine_desc_get_layout_variant (engineDesc);
+
+ if (layoutVariant && strlen (layoutVariant) > 0) {
+ return g_strdup_printf ("%s+%s", layout, layoutVariant);
+ } else {
+ return g_strdup (layout);
+ }
+}
+
+static void
+gf_input_source_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GfInputSource *inputSource;
+
+ inputSource = GF_INPUT_SOURCE (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ g_value_set_boxed (value, inputSource->id);
+ break;
+
+ case PROP_DISPLAY_NAME:
+ g_value_set_boxed (value, inputSource->displayName);
+ break;
+
+ case PROP_SHORT_NAME:
+ g_value_set_boxed (value, inputSource->shortName);
+ break;
+
+ case PROP_INDEX:
+ g_value_set_int (value, inputSource->index);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_input_source_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GfInputSource *inputSource;
+
+ inputSource = GF_INPUT_SOURCE (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ gf_input_source_set_id (inputSource, g_value_get_boxed (value));
+ break;
+
+ case PROP_DISPLAY_NAME:
+ gf_input_source_set_display_name (inputSource, g_value_get_boxed (value));
+ break;
+
+ case PROP_SHORT_NAME:
+ gf_input_source_set_short_name (inputSource, g_value_get_boxed (value));
+ break;
+
+ case PROP_INDEX:
+ gf_input_source_set_index (inputSource, g_value_get_int (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_input_source_finalize (GObject *object)
+{
+ GfInputSource *inputSource;
+
+ inputSource = GF_INPUT_SOURCE (object);
+
+ g_free ((gpointer) inputSource->xkbId);
+}
+
+static void
+gf_input_source_class_init (GfInputSourceClass *input_source_class)
+{
+ GObjectClass *objectClass;
+
+ objectClass = G_OBJECT_CLASS (input_source_class);
+
+ objectClass->get_property = gf_input_source_get_property;
+ objectClass->set_property = gf_input_source_set_property;
+ objectClass->finalize = gf_input_source_finalize;
+
+ g_object_class_install_property (objectClass, PROP_ID,
+ g_param_spec_boxed ("id", "id", "id",
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
+
+ g_object_class_install_property (objectClass, PROP_DISPLAY_NAME,
+ g_param_spec_boxed ("displayName", "displayName", "displayName",
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
+
+ g_object_class_install_property (objectClass, PROP_SHORT_NAME,
+ g_param_spec_boxed ("shortName", "shortName", "shortName",
+ G_TYPE_STRV,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
+
+ g_object_class_install_property (objectClass, PROP_INDEX,
+ g_param_spec_int ("index", "index", "index",
+ -1, G_MAXINT, -1,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
+
+ 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->xkbId = gf_input_source_get_xkb_id (inputSources);
+}
+
+
+GfInputSource *
+gf_input_source_new (const char *id, const char *displayName, const char *shortName, guint index)
+{
+ return g_object_new (GF_TYPE_INPUT_SOURCE,
+ "id", id,
+ "displayName", displayName,
+ "shortName", shortName,
+ "index", index,
+ NULL);
+}
+
+void
+gf_input_source_set_id (GfInputSource *inputSource, const char *const id)
+{
+ inputSource->id = (gchar *) id;
+}
+
+void
+gf_input_source_set_display_name (GfInputSource *inputSource, const char *const displayName)
+{
+ inputSource->displayName = (gchar *) displayName;
+}
+
+void
+gf_input_source_set_short_name (GfInputSource *inputSource, const char *const shortName)
+{
+ inputSource->shortName = (gchar *) shortName;
+ g_signal_emit (inputSource, SIGNAL_CHANGED, 0, shortName);
+}
+
+void
+gf_input_source_set_index (GfInputSource *inputSource, gint index)
+{
+ inputSource->index = index;
+}
+
+gchar
+*gf_input_source_get_id (GfInputSource *inputSource)
+{
+ return inputSource->id;
+}
+
+gchar
+*gf_input_source_get_display_name (GfInputSource *inputSource)
+{
+ return inputSource->displayName;
+}
+
+gchar
+*gf_input_source_get_short_name (GfInputSource *inputSource)
+{
+ return inputSource->shortName;
+}
+
+gint
+gf_input_source_get_index (GfInputSource *inputSource)
+{
+ return inputSource->index;
+}
+
+void gf_input_source_activate (GfInputSource *inputSource)
+{
+ g_signal_emit (inputSource, SIGNAL_ACTIVATE, 0);
+}
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..483f59d
--- /dev/null
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -0,0 +1,54 @@
+/*
+ * 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>
+
+#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* displayName,
+ const char* shortName,
+ guint index);
+
+void gf_input_source_set_id (GfInputSource *inputSource,
+ const char* const id);
+
+void gf_input_source_set_display_name (GfInputSource *inputSource,
+ const char* const displayName);
+
+void gf_input_source_set_short_name (GfInputSource *inputSource,
+ const char* const shortName);
+
+void gf_input_source_set_index (GfInputSource *inputSource,
+ gint index);
+
+
+gchar * gf_input_source_get_id (GfInputSource *inputSource);
+
+gchar * gf_input_source_get_display_name (GfInputSource *inputSource);
+
+gchar * gf_input_source_get_short_name (GfInputSource *inputSource);
+
+gint gf_input_source_get_index (GfInputSource *inputSource);
+
+void gf_input_source_activate (GfInputSource *inputSource);
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]