diff --git a/bindings/python/eekboard/Makefile.am b/bindings/python/eekboard/Makefile.am index 5209ea9f..e64dc4f0 100644 --- a/bindings/python/eekboard/Makefile.am +++ b/bindings/python/eekboard/Makefile.am @@ -20,5 +20,6 @@ pkgpython_PYTHON = \ serializable.py \ symbol.py \ keysym.py \ + text.py \ client.py \ context.py diff --git a/bindings/python/eekboard/__init__.py b/bindings/python/eekboard/__init__.py index d723f00e..951cfdc6 100644 --- a/bindings/python/eekboard/__init__.py +++ b/bindings/python/eekboard/__init__.py @@ -17,6 +17,7 @@ from symbol import * from keysym import * +from text import * from serializable import * from client import * from context import * diff --git a/bindings/python/eekboard/text.py b/bindings/python/eekboard/text.py new file mode 100644 index 00000000..2b3c200b --- /dev/null +++ b/bindings/python/eekboard/text.py @@ -0,0 +1,35 @@ +# Copyright (C) 2011 Daiki Ueno +# Copyright (C) 2011 Red Hat, Inc. + +# 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 +# . + +import symbol + +class Text(symbol.Symbol): + __gtype_name__ = "PYEekText" + __NAME__ = "EekText" + + def __init__(self): + super(Text, self).__init__() + + text = property(lambda self: self.__text) + + def serialize(self, struct): + super(Text, self).serialize(struct) + struct.append(dbus.String(self.__text)) + + def deserialize(self, struct): + super(Text, self).deserialize(struct) + self.__text = struct.pop(0) diff --git a/docs/reference/eek/eek-docs.sgml b/docs/reference/eek/eek-docs.sgml index 241c8c4c..be6433b6 100644 --- a/docs/reference/eek/eek-docs.sgml +++ b/docs/reference/eek/eek-docs.sgml @@ -46,6 +46,7 @@ + diff --git a/docs/reference/eek/eek-sections.txt b/docs/reference/eek/eek-sections.txt index be0b431f..282247a6 100644 --- a/docs/reference/eek/eek-sections.txt +++ b/docs/reference/eek/eek-sections.txt @@ -95,6 +95,24 @@ EEK_IS_SECTION_CLASS EEK_SECTION_GET_CLASS +
+eek-text +EekText +EekText +EekTextClass +eek_text_new +eek_text_get_text +EekTextPrivate + +EEK_TEXT +EEK_IS_TEXT +EEK_TYPE_TEXT +eek_text_get_type +EEK_TEXT_CLASS +EEK_IS_TEXT_CLASS +EEK_TEXT_GET_CLASS +
+
eek-theme-context eek_theme_context_new @@ -174,6 +192,8 @@ eek_symbol_set_modifier_mask eek_symbol_is_modifier eek_symbol_set_icon_name eek_symbol_get_icon_name +eek_symbol_category_get_name +eek_symbol_category_from_name EekSymbolPrivate EEK_SYMBOL diff --git a/eek/Makefile.am b/eek/Makefile.am index 81e5558a..4defb2c1 100644 --- a/eek/Makefile.am +++ b/eek/Makefile.am @@ -35,6 +35,7 @@ libeek_public_headers = \ $(srcdir)/eek-key.h \ $(srcdir)/eek-symbol.h \ $(srcdir)/eek-keysym.h \ + $(srcdir)/eek-text.h \ $(srcdir)/eek-symbol-matrix.h \ $(srcdir)/eek-types.h \ $(srcdir)/eek-xml.h \ @@ -64,6 +65,7 @@ libeek_sources = \ $(srcdir)/eek-symbol-matrix.c \ $(srcdir)/eek-symbol.c \ $(srcdir)/eek-keysym.c \ + $(srcdir)/eek-text.c \ $(srcdir)/eek-types.c \ $(srcdir)/eek-serializable.c \ $(srcdir)/eek-xml.c \ diff --git a/eek/eek-text.c b/eek/eek-text.c new file mode 100644 index 00000000..b4eae911 --- /dev/null +++ b/eek/eek-text.c @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2011 Daiki Ueno + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "eek-text.h" +#include "eek-serializable.h" + +enum { + PROP_0, + PROP_TEXT, + PROP_LAST +}; + +struct _EekTextPrivate { + gchar *text; +}; + +static void eek_serializable_iface_init (EekSerializableIface *iface); + +G_DEFINE_TYPE_WITH_CODE (EekText, eek_text, EEK_TYPE_SYMBOL, + G_IMPLEMENT_INTERFACE (EEK_TYPE_SERIALIZABLE, + eek_serializable_iface_init)); + +#define EEK_TEXT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEK_TYPE_TEXT, EekTextPrivate)) + +static EekSerializableIface *eek_text_parent_serializable_iface; + +static void +eek_text_real_serialize (EekSerializable *self, + GVariantBuilder *builder) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(self); + + eek_text_parent_serializable_iface->serialize (self, builder); + + g_variant_builder_add (builder, "s", priv->text); +} + +static gsize +eek_text_real_deserialize (EekSerializable *self, + GVariant *variant, + gsize index) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(self); + + index = eek_text_parent_serializable_iface->deserialize (self, + variant, + index); + + g_variant_get_child (variant, index++, "u", &priv->text); + + return index; +} + +static void +eek_serializable_iface_init (EekSerializableIface *iface) +{ + eek_text_parent_serializable_iface = + g_type_interface_peek_parent (iface); + + iface->serialize = eek_text_real_serialize; + iface->deserialize = eek_text_real_deserialize; +} + +static void +eek_text_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(object); + switch (prop_id) { + case PROP_TEXT: + g_free (priv->text); + priv->text = g_strdup (g_value_get_string (value)); + break; + default: + g_object_set_property (object, + g_param_spec_get_name (pspec), + value); + break; + } +} + +static void +eek_text_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(object); + switch (prop_id) { + case PROP_TEXT: + g_value_set_string (value, priv->text); + break; + default: + g_object_get_property (object, + g_param_spec_get_name (pspec), + value); + break; + } +} + +static void +eek_text_finalize (GObject *object) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(object); + + g_free (priv->text); + G_OBJECT_CLASS (eek_text_parent_class)->finalize (object); +} + +static void +eek_text_class_init (EekTextClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + g_type_class_add_private (gobject_class, sizeof (EekTextPrivate)); + + gobject_class->set_property = eek_text_set_property; + gobject_class->get_property = eek_text_get_property; + gobject_class->finalize = eek_text_finalize; + + pspec = g_param_spec_string ("text", + "Text", + "Text", + NULL, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_TEXT, pspec); +} + +static void +eek_text_init (EekText *self) +{ + self->priv = EEK_TEXT_GET_PRIVATE(self); +} + +EekText * +eek_text_new (const gchar *text) +{ + return g_object_new (EEK_TYPE_TEXT, + "label", text, + "category", EEK_SYMBOL_CATEGORY_FUNCTION, + "text", text, + NULL); +} + +const gchar * +eek_text_get_text (EekText *text) +{ + EekTextPrivate *priv = EEK_TEXT_GET_PRIVATE(text); + + return priv->text; +} diff --git a/eek/eek-text.h b/eek/eek-text.h new file mode 100644 index 00000000..5d77114e --- /dev/null +++ b/eek/eek-text.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011 Daiki Ueno + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#if !defined(__EEK_H_INSIDE__) && !defined(EEK_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef EEK_TEXT_H +#define EEK_TEXT_H 1 + +#include "eek-symbol.h" + +G_BEGIN_DECLS + +#define EEK_TYPE_TEXT (eek_text_get_type()) +#define EEK_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEK_TYPE_TEXT, EekText)) +#define EEK_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEK_TYPE_TEXT, EekTextClass)) +#define EEK_IS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEK_TYPE_TEXT)) +#define EEK_IS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEK_TYPE_TEXT)) +#define EEK_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEK_TYPE_TEXT, EekTextClass)) + +typedef struct _EekTextClass EekTextClass; +typedef struct _EekTextPrivate EekTextPrivate; + +struct _EekText { + /*< private >*/ + EekSymbol parent; + + EekTextPrivate *priv; +}; + +struct _EekTextClass { + /*< private >*/ + EekSymbolClass parent_class; +}; + +GType eek_text_get_type (void) G_GNUC_CONST; +EekText *eek_text_new (const gchar *text); +const gchar *eek_text_get_text (EekText *text); + +G_END_DECLS + +#endif /* EEK_TEXT_H */ diff --git a/eek/eek-types.h b/eek/eek-types.h index e84f4034..15dad0ce 100644 --- a/eek/eek-types.h +++ b/eek/eek-types.h @@ -140,6 +140,7 @@ typedef struct _EekSection EekSection; typedef struct _EekKeyboard EekKeyboard; typedef struct _EekSymbol EekSymbol; typedef struct _EekKeysym EekKeysym; +typedef struct _EekText EekText; typedef struct _EekTheme EekTheme; typedef struct _EekThemeContext EekThemeContext; typedef struct _EekThemeNode EekThemeNode; diff --git a/eek/eek-xml-layout.c b/eek/eek-xml-layout.c index 1f37b9b3..4a9b904a 100644 --- a/eek/eek-xml-layout.c +++ b/eek/eek-xml-layout.c @@ -33,6 +33,7 @@ #include "eek-section.h" #include "eek-key.h" #include "eek-keysym.h" +#include "eek-text.h" enum { PROP_0, @@ -93,6 +94,7 @@ static const gchar *valid_path_list[] = { "symbols/key/section/keyboard", "groups/symbols/key/section/keyboard", "levels/symbols/key/section/keyboard", + "text/symbols/key/section/keyboard", "keysym/symbols/key/section/keyboard", "symbol/symbols/key/section/keyboard", "invalid/symbols/key/section/keyboard", @@ -411,7 +413,8 @@ end_element_callback (GMarkupParseContext *pcontext, } if (g_strcmp0 (element_name, "symbol") == 0 || - g_strcmp0 (element_name, "keysym") == 0) { + g_strcmp0 (element_name, "keysym") == 0 || + g_strcmp0 (element_name, "text") == 0) { EekSymbol *symbol; if (g_strcmp0 (element_name, "keysym") == 0) { @@ -421,6 +424,8 @@ end_element_callback (GMarkupParseContext *pcontext, else keysym = eek_keysym_new_from_name (text); symbol = EEK_SYMBOL(keysym); + } else if (g_strcmp0 (element_name, "text") == 0) { + symbol = EEK_SYMBOL(eek_text_new (text)); } else { symbol = eek_symbol_new (text); eek_symbol_set_category (symbol, EEK_SYMBOL_CATEGORY_KEYNAME); diff --git a/eek/eek-xml.c b/eek/eek-xml.c index 475874ba..66321596 100644 --- a/eek/eek-xml.c +++ b/eek/eek-xml.c @@ -34,6 +34,7 @@ #include "eek-key.h" #include "eek-xml.h" #include "eek-keysym.h" +#include "eek-text.h" #define g_string_append_indent(string, indent) \ { \ @@ -156,6 +157,11 @@ output_key_callback (EekElement *element, gpointer user_data) "%s\n", eek_symbol_get_name (symbol)); } + else if (EEK_IS_TEXT(symbol)) { + g_string_markup_printf (data->output, + "%s\n", + eek_text_get_text (EEK_TEXT(symbol))); + } else g_string_markup_printf (data->output, "%s\n", diff --git a/eek/eek.c b/eek/eek.c index 272f7b38..8c037163 100644 --- a/eek/eek.c +++ b/eek/eek.c @@ -42,4 +42,5 @@ eek_init (void) g_type_class_ref (EEK_TYPE_SYMBOL); g_type_class_ref (EEK_TYPE_KEYSYM); + g_type_class_ref (EEK_TYPE_TEXT); } diff --git a/eek/eek.h b/eek/eek.h index 0fd8ca7f..3e8df396 100644 --- a/eek/eek.h +++ b/eek/eek.h @@ -28,6 +28,7 @@ #include "eek-layout.h" #include "eek-symbol.h" #include "eek-keysym.h" +#include "eek-text.h" #include "eek-xml.h" #include "eek-serializable.h" #include "eek-theme.h" diff --git a/examples/eekxml/Makefile.am b/examples/eekxml/Makefile.am index 6a57899b..19271e8e 100644 --- a/examples/eekxml/Makefile.am +++ b/examples/eekxml/Makefile.am @@ -1,5 +1,5 @@ bin_SCRIPTS = eekxml -EXTRA_DIST = eekxml.in mim2remap +EXTRA_DIST = eekxml.in mim2remap.el DISTCLEANFILES = eekxml eekxml: eekxml.in diff --git a/examples/eekxml/eekxml.in b/examples/eekxml/eekxml.in index d7ec6ddd..1081fa11 100644 --- a/examples/eekxml/eekxml.in +++ b/examples/eekxml/eekxml.in @@ -35,9 +35,12 @@ def remap(keyboard, mapping): if mapped: if mapped.has_key('xkeysym'): replace = Eek.Keysym.new(mapped['xkeysym']) + elif mapped.has_key('text'): + replace = Eek.Text.new(mapped['text']) else: replace = Eek.Symbol.new(mapped['name']) replace.set_category(Eek.SymbolCategory.LETTER) + replace.set_name(symbol.get_name()) if mapped.has_key('label'): replace.set_label(mapped['label']) if mapped.has_key('category'):