Mailing List Archive

r19364 - in projects/haf/trunk/hildon-input-method-plugins-example: . src
Author: jrocha
Date: 2009-09-17 20:19:56 +0300 (Thu, 17 Sep 2009)
New Revision: 19364

Added:
projects/haf/trunk/hildon-input-method-plugins-example/src/hildon-im-keyboard-decorator.c
Modified:
projects/haf/trunk/hildon-input-method-plugins-example/ChangeLog
projects/haf/trunk/hildon-input-method-plugins-example/src/Makefile.am
Log:
2009-09-17 Joaquim Rocha <jrocha@igalia.com>

* hildon-im-keyboard-decorator.c: Created a hardware keyboard plugin example
that exchanges some ASCII characters by similar non-ASCII characters.

Modified: projects/haf/trunk/hildon-input-method-plugins-example/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-input-method-plugins-example/ChangeLog 2009-09-17 16:59:55 UTC (rev 19363)
+++ projects/haf/trunk/hildon-input-method-plugins-example/ChangeLog 2009-09-17 17:19:56 UTC (rev 19364)
@@ -1,3 +1,8 @@
+2009-09-17 Joaquim Rocha <jrocha@igalia.com>
+
+ * hildon-im-keyboard-decorator.c: Created a hardware keyboard plugin example
+ that exchanges some ASCII characters by similar non-ASCII characters.
+
2009-09-15 Joaquim Rocha <jrocha@igalia.com>

* hildon-im-onehand-fkb.c (set_kb_mode): Added a scrolled window to the

Modified: projects/haf/trunk/hildon-input-method-plugins-example/src/Makefile.am
===================================================================
--- projects/haf/trunk/hildon-input-method-plugins-example/src/Makefile.am 2009-09-17 16:59:55 UTC (rev 19363)
+++ projects/haf/trunk/hildon-input-method-plugins-example/src/Makefile.am 2009-09-17 17:19:56 UTC (rev 19364)
@@ -13,7 +13,8 @@
# /usr/lib/hildon-input-method/, where it will be found by the
# hildon-input-method framework:
implugindir = $(libdir)/hildon-input-method
-implugin_LTLIBRARIES = him_vkb_example.la hildon_im_example_fkb.la hildon_im_onehand_fkb.la
+implugin_LTLIBRARIES = him_vkb_example.la hildon_im_example_fkb.la \
+ hildon_im_onehand_fkb.la hildon_im_keyboard_decorator.la

# Build the plugins (shared libraries):
him_vkb_example_la_SOURCES = him-vkb-example.c
@@ -28,6 +29,10 @@
hildon_im_onehand_fkb_la_LIBADD = $(HIM_PLUGINS_EXAMPLE_LIBS)
hildon_im_onehand_fkb_la_LDFLAGS = -avoid-version -module

+hildon_im_keyboard_decorator_la_SOURCES = hildon-im-keyboard-decorator.c
+hildon_im_keyboard_decorator_la_LIBADD = $(HIM_PLUGINS_EXAMPLE_LIBS)
+hildon_im_keyboard_decorator_la_LDFLAGS = -avoid-version -module
+
# After installation, update the cache so that hildon-input-method knows about
# the new plugin:
install-data-hook:

Added: projects/haf/trunk/hildon-input-method-plugins-example/src/hildon-im-keyboard-decorator.c
===================================================================
--- projects/haf/trunk/hildon-input-method-plugins-example/src/hildon-im-keyboard-decorator.c 2009-09-17 16:59:55 UTC (rev 19363)
+++ projects/haf/trunk/hildon-input-method-plugins-example/src/hildon-im-keyboard-decorator.c 2009-09-17 17:19:56 UTC (rev 19364)
@@ -0,0 +1,406 @@
+/*
+ * This file is part of hildon-input-method-plugins-example
+ *
+ * Copyright (C) 2006-2007 Nokia Corporation. All rights reserved.
+ *
+ * Author: Joaquim Rocha <jrocha@igalia.com>
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+#include "hildon-im-plugin.h"
+#include "hildon-im-ui.h"
+
+#include <string.h>
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include <libosso.h>
+#include <mce/dbus-names.h>
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+
+#define HILDON_IM_KEYBOARD_DECORATOR_TYPE hildon_im_keyboard_decorator_get_type ()
+#define HILDON_IM_KEYBOARD_DECORATOR(obj) GTK_CHECK_CAST(obj, hildon_im_keyboard_decorator_get_type (), HildonIMKeyboardDecorator)
+#define HILDON_IM_KEYBOARD_DECORATOR_CLASS(klass) \
+ GTK_CHECK_CLASS_CAST(klass, hildon_im_keyboard_decorator_get_type, \
+ HildonIMKeyboardDecoratorClass)
+#define HILDON_IS_IM_KEYBOARD_DECORATOR(obj) \
+ GTK_CHECK_TYPE(obj, hildon_im_keyboard_decorator_get_type ())
+#define HILDON_IM_KEYBOARD_DECORATOR_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_IM_KEYBOARD_DECORATOR_TYPE,\
+ HildonIMKeyboardDecoratorPrivate))
+
+typedef struct
+{
+ gunichar character;
+ gchar *variants;
+}
+HKDCharacterVariant;
+
+static const HKDCharacterVariant chr_variants[] = {
+ {'!', "!¡"},
+ {'?', "?¿"},
+ {'a', "aáàāåăæд"},
+ {'b', "bβъвБб"},
+ {'c', "cçćč"},
+ {'d', "dď"},
+ {'e', "eéèēěεзξёэ"},
+ {'h', "hн"},
+ {'i', "iíìīĭι"},
+ {'k', "kк"},
+ {'m', "mм"},
+ {'n', "nńñийп"},
+ {'o', "oóòōõŏθσѳǿø"},
+ {'p', "pρ"},
+ {'q', "qфφψ"},
+ {'r', "rŕля"},
+ {'s', "sśš"},
+ {'t', "tťтτ"},
+ {'u', "uúùūůũŭц"},
+ {'w', "wшщ"},
+ {'x', "xχ"},
+ {'y', "yýỳч"},
+ {'z', "zźž"}
+ };
+
+typedef struct
+{
+ GtkContainerClass parent;
+}
+HildonIMKeyboardDecoratorClass;
+
+typedef struct
+{
+ GtkContainer parent;
+}
+HildonIMKeyboardDecorator;
+
+typedef struct
+{
+ HildonIMUI *ui;
+}
+HildonIMKeyboardDecoratorPrivate;
+
+static GType hildon_im_keyboard_decorator_type = 0;
+static GtkWidgetClass *parent_class = NULL;
+
+GType hildon_im_keyboard_decorator_get_type (void);
+GtkWidget *hildon_im_keyboard_decorator_new (HildonIMUI *kbd);
+
+/*
+ * HildonIMPlugin interface
+ */
+static void hildon_im_keyboard_decorator_iface_init (HildonIMPluginIface *iface);
+
+static void hildon_im_keyboard_decorator_enable (HildonIMPlugin *plugin, gboolean init);
+static void hildon_im_keyboard_decorator_disable (HildonIMPlugin *plugin);
+static void hildon_im_keyboard_decorator_surrounding_received (HildonIMPlugin *plugin,
+ const gchar *surrounding,
+ gint offset);
+static void hildon_im_keyboard_decorator_key_event(HildonIMPlugin *plugin,
+ GdkEventType type,
+ guint state,
+ guint keyval,
+ guint hardware_keycode);
+
+/*
+ * GObject functions
+ */
+static void hildon_im_keyboard_decorator_finalize (GObject *obj);
+static void hildon_im_keyboard_decorator_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void hildon_im_keyboard_decorator_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void hildon_im_keyboard_decorator_class_init (HildonIMKeyboardDecoratorClass *klass);
+static void hildon_im_keyboard_decorator_init (HildonIMKeyboardDecorator *self);
+
+/*
+ * Module functions
+ */
+
+HildonIMPlugin*
+module_create (HildonIMUI *keyboard)
+{
+ return HILDON_IM_PLUGIN (hildon_im_keyboard_decorator_new (keyboard));
+}
+
+void
+module_exit(void)
+{
+ /* empty */
+}
+
+void
+module_init(GTypeModule *module)
+{
+ static const GTypeInfo type_info = {
+ sizeof(HildonIMKeyboardDecoratorClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) hildon_im_keyboard_decorator_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(HildonIMKeyboardDecorator),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) hildon_im_keyboard_decorator_init,
+ };
+
+ static const GInterfaceInfo plugin_info = {
+ (GInterfaceInitFunc) hildon_im_keyboard_decorator_iface_init,
+ NULL, /* interface_finalize */
+ NULL, /* interface_data */
+ };
+
+ hildon_im_keyboard_decorator_type =
+ g_type_module_register_type(module,
+ GTK_TYPE_CONTAINER, "HildonIMKeyboardDecorator",
+ &type_info,
+ 0);
+
+ g_type_module_add_interface(module,
+ HILDON_IM_KEYBOARD_DECORATOR_TYPE,
+ HILDON_IM_TYPE_PLUGIN,
+ &plugin_info);
+}
+
+/*
+ * This is used to know the plugin's information when loading the module
+ */
+const HildonIMPluginInfo *
+hildon_im_plugin_get_info(void)
+{
+ static const HildonIMPluginInfo info =
+ {
+ "HIM Decorator", /* description */
+ "hildon_im_keyboard_decorator", /* name */
+ NULL, /* menu title */
+ NULL, /* gettext domain */
+ TRUE, /* visible in menu */
+ TRUE, /* cached */
+ HILDON_IM_TYPE_FULLSCREEN, /* UI type */
+ HILDON_IM_GROUP_LATIN, /* group */
+ HILDON_IM_DEFAULT_PLUGIN_PRIORITY, /* priority */
+ NULL, /* special character plugin */
+ NULL, /* help page */
+ TRUE, /* disable common UI buttons */
+ 0, /* plugin height */
+ HILDON_IM_TRIGGER_KEYBOARD /* trigger */
+ };
+
+ return &info;
+}
+
+/*
+ * This function returns the list of available languages supported
+ * by the plugin.
+ */
+gchar **
+hildon_im_plugin_get_available_languages (gboolean *free)
+{
+ static gchar *langs[] = {"en_GB", NULL};
+ *free = FALSE;
+
+ return langs;
+}
+
+GType
+hildon_im_keyboard_decorator_get_type (void)
+{
+ return hildon_im_keyboard_decorator_type;
+}
+
+/*
+ * Implement the interface.
+ */
+static void
+hildon_im_keyboard_decorator_iface_init (HildonIMPluginIface *iface)
+{
+ iface->enable = hildon_im_keyboard_decorator_enable;
+ iface->disable = hildon_im_keyboard_decorator_disable;
+ iface->surrounding_received = hildon_im_keyboard_decorator_surrounding_received;
+ iface->key_event = hildon_im_keyboard_decorator_key_event;
+}
+
+static void
+hildon_im_keyboard_decorator_class_init (HildonIMKeyboardDecoratorClass *klass)
+{
+ GObjectClass *object_class;
+ GtkObjectClass *gtk_object_class;
+ GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
+
+ parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (HildonIMKeyboardDecoratorPrivate));
+
+ object_class = G_OBJECT_CLASS(klass);
+ gtk_object_class = GTK_OBJECT_CLASS(klass);
+ widget_class = GTK_WIDGET_CLASS(klass);
+ container_class = GTK_CONTAINER_CLASS(klass);
+
+ object_class->set_property = hildon_im_keyboard_decorator_set_property;
+ object_class->get_property = hildon_im_keyboard_decorator_get_property;
+ object_class->finalize = hildon_im_keyboard_decorator_finalize;
+
+ g_object_class_install_property (object_class, HILDON_IM_PROP_UI,
+ g_param_spec_object (HILDON_IM_PROP_UI_DESCRIPTION,
+ HILDON_IM_PROP_UI_DESCRIPTION,
+ "UI that uses plugin",
+ HILDON_IM_TYPE_UI,
+ G_PARAM_READWRITE
+ | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+hildon_im_keyboard_decorator_init (HildonIMKeyboardDecorator *self)
+{
+ HildonIMKeyboardDecoratorPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_IM_KEYBOARD_DECORATOR (self));
+ priv = HILDON_IM_KEYBOARD_DECORATOR_GET_PRIVATE (self);
+}
+
+static void
+hildon_im_keyboard_decorator_finalize(GObject *obj)
+{
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ {
+ G_OBJECT_CLASS (parent_class)->finalize (obj);
+ }
+}
+
+GtkWidget *
+hildon_im_keyboard_decorator_new (HildonIMUI *kbd)
+{
+ return g_object_new (HILDON_IM_KEYBOARD_DECORATOR_TYPE,
+ HILDON_IM_PROP_UI_DESCRIPTION, kbd, NULL);
+}
+
+static void
+hildon_im_keyboard_decorator_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ HildonIMKeyboardDecoratorPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_IM_KEYBOARD_DECORATOR(object));
+ priv = HILDON_IM_KEYBOARD_DECORATOR_GET_PRIVATE(object);
+
+ switch (prop_id)
+ {
+ case HILDON_IM_PROP_UI:
+ g_value_set_object(value, priv->ui);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+hildon_im_keyboard_decorator_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ HildonIMKeyboardDecoratorPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_IM_KEYBOARD_DECORATOR (object));
+ priv = HILDON_IM_KEYBOARD_DECORATOR_GET_PRIVATE(object);
+
+ switch (prop_id)
+ {
+ case HILDON_IM_PROP_UI:
+ priv->ui = g_value_get_object(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+hildon_im_keyboard_decorator_enable(HildonIMPlugin *plugin, gboolean init)
+{
+}
+
+static void
+hildon_im_keyboard_decorator_disable(HildonIMPlugin *plugin)
+{
+}
+
+static void
+hildon_im_keyboard_decorator_surrounding_received(HildonIMPlugin *plugin,
+ const gchar *surrounding,
+ gint offset)
+{
+}
+
+static gunichar
+hildon_im_keyboard_decorator_get_variant_for_chr (gunichar chr)
+{
+ int i;
+ for (i = 0; i < G_N_ELEMENTS (chr_variants); i++)
+ {
+ HKDCharacterVariant variant = chr_variants[i];
+ if (variant.character == chr)
+ {
+ gint choices = g_utf8_strlen (variant.variants, -1);
+ if (choices)
+ {
+ gint choice = g_random_int_range (0, choices);
+ gunichar new_chr = g_utf8_get_char (g_utf8_offset_to_pointer (variant.variants, choice));
+ if (g_unichar_isupper(chr))
+ {
+ new_chr = g_unichar_toupper(new_chr);
+ }
+ return new_chr;
+ }
+ }
+ }
+
+ return chr;
+}
+
+static void
+hildon_im_keyboard_decorator_key_event(HildonIMPlugin *plugin,
+ GdkEventType type,
+ guint state,
+ guint keyval,
+ guint hardware_keycode)
+{
+ guint chr;
+ HildonIMKeyboardDecoratorPrivate *priv = HILDON_IM_KEYBOARD_DECORATOR_GET_PRIVATE (plugin);
+
+ chr = gdk_keyval_to_unicode (keyval);
+
+ if (type == GDK_KEY_PRESS && g_unichar_isprint (chr) && !g_unichar_isdigit(chr))
+ {
+ hildon_im_ui_send_communication_message (priv->ui, HILDON_IM_CONTEXT_HANDLE_BACKSPACE);
+ gunichar variant = hildon_im_keyboard_decorator_get_variant_for_chr (chr);
+
+ gchar character[7];
+ int len = g_unichar_to_utf8 (variant, character);
+ character[len] = '\0';
+
+ hildon_im_ui_send_utf8 (priv->ui, character);
+ }
+}

_______________________________________________
maemo-commits mailing list
maemo-commits@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-commits