Support text symbol.
a
This commit is contained in:
@ -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 \
|
||||
|
||||
176
eek/eek-text.c
Normal file
176
eek/eek-text.c
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
60
eek/eek-text.h
Normal file
60
eek/eek-text.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user