Remove serialization code for EekKey, EekSection, and EekKeyboard.
This commit is contained in:
105
eek/eek-key.c
105
eek/eek-key.c
@ -39,7 +39,6 @@
|
||||
#include "eek-section.h"
|
||||
#include "eek-keyboard.h"
|
||||
#include "eek-symbol.h"
|
||||
#include "eek-serializable.h"
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
@ -59,11 +58,7 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
static void eek_serializable_iface_init (EekSerializableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (EekKey, eek_key, EEK_TYPE_ELEMENT,
|
||||
G_IMPLEMENT_INTERFACE (EEK_TYPE_SERIALIZABLE,
|
||||
eek_serializable_iface_init));
|
||||
G_DEFINE_TYPE (EekKey, eek_key, EEK_TYPE_ELEMENT);
|
||||
|
||||
#define EEK_KEY_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEK_TYPE_KEY, EekKeyPrivate))
|
||||
@ -79,104 +74,6 @@ struct _EekKeyPrivate
|
||||
gboolean is_pressed;
|
||||
};
|
||||
|
||||
static EekSerializableIface *eek_key_parent_serializable_iface;
|
||||
|
||||
static GVariant *
|
||||
_g_variant_new_symbol_matrix (EekSymbolMatrix *symbol_matrix)
|
||||
{
|
||||
GVariantBuilder builder, array;
|
||||
gint i, num_symbols = symbol_matrix->num_groups * symbol_matrix->num_levels;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(iiv)"));
|
||||
g_variant_builder_add (&builder, "i", symbol_matrix->num_groups);
|
||||
g_variant_builder_add (&builder, "i", symbol_matrix->num_levels);
|
||||
g_variant_builder_init (&array, G_VARIANT_TYPE ("av"));
|
||||
for (i = 0; i < num_symbols; i++) {
|
||||
GVariant *symbol = eek_serializable_serialize
|
||||
(EEK_SERIALIZABLE(symbol_matrix->data[i]));
|
||||
g_variant_builder_add (&array, "v", symbol);
|
||||
}
|
||||
g_variant_builder_add (&builder, "v", g_variant_builder_end (&array));
|
||||
return g_variant_builder_end (&builder);
|
||||
}
|
||||
|
||||
static EekSymbolMatrix *
|
||||
_g_variant_get_symbol_matrix (GVariant *variant)
|
||||
{
|
||||
gint num_groups, num_levels, i;
|
||||
EekSymbolMatrix *symbol_matrix;
|
||||
GVariant *array, *child;
|
||||
GVariantIter iter;
|
||||
|
||||
g_variant_get_child (variant, 0, "i", &num_groups);
|
||||
g_variant_get_child (variant, 1, "i", &num_levels);
|
||||
symbol_matrix = eek_symbol_matrix_new (num_groups, num_levels);
|
||||
|
||||
g_variant_get_child (variant, 2, "v", &array);
|
||||
g_variant_iter_init (&iter, array);
|
||||
for (i = 0; i < num_groups * num_levels; i++) {
|
||||
EekSerializable *serializable;
|
||||
|
||||
if (!g_variant_iter_next (&iter, "v", &child)) {
|
||||
eek_symbol_matrix_free (symbol_matrix);
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
|
||||
serializable = eek_serializable_deserialize (child);
|
||||
symbol_matrix->data[i] = EEK_SYMBOL(serializable);
|
||||
}
|
||||
return symbol_matrix;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_key_real_serialize (EekSerializable *self,
|
||||
GVariantBuilder *builder)
|
||||
{
|
||||
EekKeyPrivate *priv = EEK_KEY_GET_PRIVATE(self);
|
||||
|
||||
eek_key_parent_serializable_iface->serialize (self, builder);
|
||||
|
||||
g_variant_builder_add (builder, "u", priv->keycode);
|
||||
g_variant_builder_add (builder, "v",
|
||||
_g_variant_new_symbol_matrix (priv->symbol_matrix));
|
||||
g_variant_builder_add (builder, "i", priv->column);
|
||||
g_variant_builder_add (builder, "i", priv->row);
|
||||
g_variant_builder_add (builder, "u", priv->oref);
|
||||
}
|
||||
|
||||
static gsize
|
||||
eek_key_real_deserialize (EekSerializable *self,
|
||||
GVariant *variant,
|
||||
gsize index)
|
||||
{
|
||||
EekKeyPrivate *priv = EEK_KEY_GET_PRIVATE(self);
|
||||
GVariant *symbol_matrix;
|
||||
|
||||
index = eek_key_parent_serializable_iface->deserialize (self,
|
||||
variant,
|
||||
index);
|
||||
|
||||
g_variant_get_child (variant, index++, "u", &priv->keycode);
|
||||
g_variant_get_child (variant, index++, "v", &symbol_matrix);
|
||||
eek_symbol_matrix_free (priv->symbol_matrix);
|
||||
priv->symbol_matrix = _g_variant_get_symbol_matrix (symbol_matrix);
|
||||
g_variant_get_child (variant, index++, "i", &priv->column);
|
||||
g_variant_get_child (variant, index++, "i", &priv->row);
|
||||
g_variant_get_child (variant, index++, "u", &priv->oref);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_serializable_iface_init (EekSerializableIface *iface)
|
||||
{
|
||||
eek_key_parent_serializable_iface =
|
||||
g_type_interface_peek_parent (iface);
|
||||
|
||||
iface->serialize = eek_key_real_serialize;
|
||||
iface->deserialize = eek_key_real_deserialize;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_key_real_set_keycode (EekKey *self, guint keycode)
|
||||
{
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
#include "eek-section.h"
|
||||
#include "eek-key.h"
|
||||
#include "eek-symbol.h"
|
||||
#include "eek-serializable.h"
|
||||
#include "eek-enumtypes.h"
|
||||
|
||||
enum {
|
||||
@ -53,11 +52,7 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
static void eek_serializable_iface_init (EekSerializableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (EekKeyboard, eek_keyboard, EEK_TYPE_CONTAINER,
|
||||
G_IMPLEMENT_INTERFACE (EEK_TYPE_SERIALIZABLE,
|
||||
eek_serializable_iface_init));
|
||||
G_DEFINE_TYPE (EekKeyboard, eek_keyboard, EEK_TYPE_CONTAINER);
|
||||
|
||||
#define EEK_KEYBOARD_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEK_TYPE_KEYBOARD, EekKeyboardPrivate))
|
||||
@ -75,120 +70,6 @@ struct _EekKeyboardPrivate
|
||||
EekModifierType alt_gr_mask;
|
||||
};
|
||||
|
||||
static EekSerializableIface *eek_keyboard_parent_serializable_iface;
|
||||
|
||||
static GVariant *_g_variant_new_outline (EekOutline *outline);
|
||||
static EekOutline *_g_variant_get_outline (GVariant *variant);
|
||||
|
||||
static GVariant *
|
||||
_g_variant_new_outline (EekOutline *outline)
|
||||
{
|
||||
GVariantBuilder builder, array;
|
||||
gint i;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(div)"));
|
||||
g_variant_builder_add (&builder, "d", outline->corner_radius);
|
||||
g_variant_builder_add (&builder, "i", outline->num_points);
|
||||
g_variant_builder_init (&array, G_VARIANT_TYPE ("a(dd)"));
|
||||
for (i = 0; i < outline->num_points; i++)
|
||||
g_variant_builder_add (&array,
|
||||
"(dd)",
|
||||
outline->points[i].x,
|
||||
outline->points[i].y);
|
||||
g_variant_builder_add (&builder, "v", g_variant_builder_end (&array));
|
||||
return g_variant_builder_end (&builder);
|
||||
}
|
||||
|
||||
static EekOutline *
|
||||
_g_variant_get_outline (GVariant *variant)
|
||||
{
|
||||
EekOutline *outline;
|
||||
GVariant *array;
|
||||
GVariantIter iter;
|
||||
gdouble x, y;
|
||||
gint i;
|
||||
|
||||
outline = g_slice_new0 (EekOutline);
|
||||
|
||||
g_variant_get_child (variant, 0, "d", &outline->corner_radius);
|
||||
g_variant_get_child (variant, 1, "i", &outline->num_points);
|
||||
|
||||
outline->points = g_slice_alloc0 (sizeof (EekPoint) * outline->num_points);
|
||||
|
||||
g_variant_get_child (variant, 2, "v", &array);
|
||||
g_variant_iter_init (&iter, array);
|
||||
for (i = 0; i < outline->num_points; i++) {
|
||||
if (!g_variant_iter_next (&iter, "(dd)", &x, &y)) {
|
||||
eek_outline_free (outline);
|
||||
g_return_val_if_reached (NULL);
|
||||
}
|
||||
outline->points[i].x = x;
|
||||
outline->points[i].y = y;
|
||||
}
|
||||
|
||||
return outline;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_keyboard_real_serialize (EekSerializable *self,
|
||||
GVariantBuilder *builder)
|
||||
{
|
||||
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(self);
|
||||
GVariantBuilder array;
|
||||
guint i;
|
||||
|
||||
eek_keyboard_parent_serializable_iface->serialize (self, builder);
|
||||
|
||||
g_variant_builder_init (&array, G_VARIANT_TYPE ("av"));
|
||||
for (i = 0; i < priv->outline_array->len; i++) {
|
||||
EekOutline *outline =
|
||||
eek_keyboard_get_outline (EEK_KEYBOARD(self), i + 1);
|
||||
g_variant_builder_add (&array, "v",
|
||||
_g_variant_new_outline (outline));
|
||||
}
|
||||
g_variant_builder_add (builder, "v", g_variant_builder_end (&array));
|
||||
g_variant_builder_add (builder, "u", priv->num_lock_mask);
|
||||
g_variant_builder_add (builder, "u", priv->alt_gr_mask);
|
||||
}
|
||||
|
||||
static gsize
|
||||
eek_keyboard_real_deserialize (EekSerializable *self,
|
||||
GVariant *variant,
|
||||
gsize index)
|
||||
{
|
||||
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(self);
|
||||
GVariant *array, *outline;
|
||||
GVariantIter iter;
|
||||
|
||||
index = eek_keyboard_parent_serializable_iface->deserialize (self,
|
||||
variant,
|
||||
index);
|
||||
|
||||
g_variant_get_child (variant, index++, "v", &array);
|
||||
|
||||
g_variant_iter_init (&iter, array);
|
||||
while (g_variant_iter_next (&iter, "v", &outline)) {
|
||||
EekOutline *_outline = _g_variant_get_outline (outline);
|
||||
g_array_append_val (priv->outline_array, *_outline);
|
||||
/* don't use eek_outline_free here, so as to keep _outline->points */
|
||||
g_slice_free (EekOutline, _outline);
|
||||
}
|
||||
g_variant_get_child (variant, index++, "u", &priv->num_lock_mask);
|
||||
g_variant_get_child (variant, index++, "u", &priv->alt_gr_mask);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_serializable_iface_init (EekSerializableIface *iface)
|
||||
{
|
||||
eek_keyboard_parent_serializable_iface =
|
||||
g_type_interface_peek_parent (iface);
|
||||
|
||||
iface->serialize = eek_keyboard_real_serialize;
|
||||
iface->deserialize = eek_keyboard_real_deserialize;
|
||||
}
|
||||
|
||||
static void
|
||||
on_key_pressed (EekSection *section,
|
||||
EekKey *key,
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
#include "eek-section.h"
|
||||
#include "eek-key.h"
|
||||
#include "eek-symbol.h"
|
||||
#include "eek-serializable.h"
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
@ -53,11 +52,7 @@ enum {
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
static void eek_serializable_iface_init (EekSerializableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (EekSection, eek_section, EEK_TYPE_CONTAINER,
|
||||
G_IMPLEMENT_INTERFACE (EEK_TYPE_SERIALIZABLE,
|
||||
eek_serializable_iface_init));
|
||||
G_DEFINE_TYPE (EekSection, eek_section, EEK_TYPE_CONTAINER);
|
||||
|
||||
#define EEK_SECTION_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEK_TYPE_SECTION, EekSectionPrivate))
|
||||
@ -77,80 +72,6 @@ struct _EekSectionPrivate
|
||||
EekModifierType modifiers;
|
||||
};
|
||||
|
||||
static EekSerializableIface *eek_section_parent_serializable_iface;
|
||||
|
||||
static GVariant *
|
||||
_g_variant_new_row (EekRow *row)
|
||||
{
|
||||
GVariantBuilder builder;
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("(iu)"));
|
||||
g_variant_builder_add (&builder, "i", row->num_columns);
|
||||
g_variant_builder_add (&builder, "u", row->orientation);
|
||||
|
||||
return g_variant_builder_end (&builder);
|
||||
}
|
||||
|
||||
static EekRow *
|
||||
_g_variant_get_row (GVariant *variant)
|
||||
{
|
||||
EekRow *row = g_slice_new (EekRow);
|
||||
g_variant_get_child (variant, 0, "i", &row->num_columns);
|
||||
g_variant_get_child (variant, 1, "u", &row->orientation);
|
||||
return row;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_section_real_serialize (EekSerializable *self,
|
||||
GVariantBuilder *builder)
|
||||
{
|
||||
EekSectionPrivate *priv = EEK_SECTION_GET_PRIVATE(self);
|
||||
GSList *head;
|
||||
GVariantBuilder array;
|
||||
|
||||
eek_section_parent_serializable_iface->serialize (self, builder);
|
||||
|
||||
g_variant_builder_add (builder, "i", priv->angle);
|
||||
|
||||
g_variant_builder_init (&array, G_VARIANT_TYPE("av"));
|
||||
for (head = priv->rows; head; head = g_slist_next (head))
|
||||
g_variant_builder_add (&array, "v", _g_variant_new_row (head->data));
|
||||
g_variant_builder_add (builder, "v", g_variant_builder_end (&array));
|
||||
}
|
||||
|
||||
static gsize
|
||||
eek_section_real_deserialize (EekSerializable *self,
|
||||
GVariant *variant,
|
||||
gsize index)
|
||||
{
|
||||
EekSectionPrivate *priv = EEK_SECTION_GET_PRIVATE(self);
|
||||
GVariant *array, *child;
|
||||
GVariantIter iter;
|
||||
|
||||
index = eek_section_parent_serializable_iface->deserialize (self,
|
||||
variant,
|
||||
index);
|
||||
|
||||
g_variant_get_child (variant, index++, "i", &priv->angle);
|
||||
g_variant_get_child (variant, index++, "v", &array);
|
||||
g_variant_iter_init (&iter, array);
|
||||
while (g_variant_iter_next (&iter, "v", &child))
|
||||
priv->rows = g_slist_prepend (priv->rows, _g_variant_get_row (child));
|
||||
priv->rows = g_slist_reverse (priv->rows);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_serializable_iface_init (EekSerializableIface *iface)
|
||||
{
|
||||
eek_section_parent_serializable_iface =
|
||||
g_type_interface_peek_parent (iface);
|
||||
|
||||
iface->serialize = eek_section_real_serialize;
|
||||
iface->deserialize = eek_section_real_deserialize;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_section_real_set_angle (EekSection *self,
|
||||
gint angle)
|
||||
|
||||
@ -5,10 +5,6 @@ eek_init (void)
|
||||
{
|
||||
g_type_init ();
|
||||
|
||||
/* preload Eek* types for EekKeyboard deserialization */
|
||||
g_type_class_ref (EEK_TYPE_KEYBOARD);
|
||||
g_type_class_ref (EEK_TYPE_SECTION);
|
||||
g_type_class_ref (EEK_TYPE_KEY);
|
||||
g_type_class_ref (EEK_TYPE_SYMBOL);
|
||||
g_type_class_ref (EEK_TYPE_KEYSYM);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user