Commit b02ae1b7 authored by Daiki Ueno's avatar Daiki Ueno

Support text symbol.

a
parent 88816018
......@@ -20,5 +20,6 @@ pkgpython_PYTHON = \
serializable.py \
symbol.py \
keysym.py \
text.py \
client.py \
context.py
......@@ -17,6 +17,7 @@
from symbol import *
from keysym import *
from text import *
from serializable import *
from client import *
from context import *
# Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
# 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
# <http://www.gnu.org/licenses/>.
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)
......@@ -46,6 +46,7 @@
<xi:include href="xml/eek-key.xml"/>
<xi:include href="xml/eek-symbol.xml"/>
<xi:include href="xml/eek-keysym.xml"/>
<xi:include href="xml/eek-text.xml"/>
<xi:include href="xml/eek-layout.xml"/>
<xi:include href="xml/eek-types.xml"/>
</chapter>
......
......@@ -95,6 +95,24 @@ EEK_IS_SECTION_CLASS
EEK_SECTION_GET_CLASS
</SECTION>
<SECTION>
<FILE>eek-text</FILE>
<TITLE>EekText</TITLE>
EekText
EekTextClass
eek_text_new
eek_text_get_text
EekTextPrivate
<SUBSECTION Standard>
EEK_TEXT
EEK_IS_TEXT
EEK_TYPE_TEXT
eek_text_get_type
EEK_TEXT_CLASS
EEK_IS_TEXT_CLASS
EEK_TEXT_GET_CLASS
</SECTION>
<SECTION>
<FILE>eek-theme-context</FILE>
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
<SUBSECTION Standard>
EEK_SYMBOL
......
......@@ -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 \
......
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* 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;
}
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* 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 <eek/eek.h> 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 */
......@@ -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;
......
......@@ -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);
......
......@@ -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)
"<keysym>%s</keysym>\n",
eek_symbol_get_name (symbol));
}
else if (EEK_IS_TEXT(symbol)) {
g_string_markup_printf (data->output,
"<text>%s</text>\n",
eek_text_get_text (EEK_TEXT(symbol)));
}
else
g_string_markup_printf (data->output,
"<symbol>%s</symbol>\n",
......
......@@ -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);
}
......@@ -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"
......
bin_SCRIPTS = eekxml
EXTRA_DIST = eekxml.in mim2remap
EXTRA_DIST = eekxml.in mim2remap.el
DISTCLEANFILES = eekxml
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'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment