summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfujiwarat <takao.fujiwara1@gmail.com>2017-04-03 12:24:27 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2017-04-03 12:24:27 +0900
commitcb0a36c254dc7a96b2a984e715f96cc2ec32e2d5 (patch)
tree035bc09708a2914a0915902cc6ace996abf94c62 /src
parent8b6f9fa531aa9d9b5d6c0184b2294d071f920d7f (diff)
downloadibus-cb0a36c254dc7a96b2a984e715f96cc2ec32e2d5.tar.gz
src: Enable unicode_alt in EmojiOne json file
EmojiOne json file has unicode_alt property which includes emoji modifer characters. Review URL: https://codereview.appspot.com/316420043
Diffstat (limited to 'src')
-rw-r--r--src/emoji-parser.c20
-rw-r--r--src/ibusemoji.c48
-rw-r--r--src/ibusemoji.h14
3 files changed, 75 insertions, 7 deletions
diff --git a/src/emoji-parser.c b/src/emoji-parser.c
index f9e34703..e5dce3f8 100644
--- a/src/emoji-parser.c
+++ b/src/emoji-parser.c
@@ -40,6 +40,7 @@
typedef struct _EmojiData EmojiData;
struct _EmojiData {
gchar *emoji;
+ gchar *emoji_alternates;
GSList *annotations;
gboolean is_annotation;
gchar *description;
@@ -54,6 +55,7 @@ reset_emoji_element (EmojiData *data)
g_assert (data != NULL);
g_clear_pointer (&data->emoji, g_free);
+ g_clear_pointer (&data->emoji_alternates, g_free);
g_slist_free_full (data->annotations, g_free);
data->annotations = NULL;
g_clear_pointer (&data->description, g_free);
@@ -112,6 +114,10 @@ update_emoji_list (EmojiData *data)
"category",
data->category ? data->category
: g_strdup (""),
+ "emoji-alternates",
+ data->emoji_alternates
+ ? data->emoji_alternates
+ : g_strdup (""),
NULL);
data->list = g_slist_append (data->list, emoji);
}
@@ -271,7 +277,8 @@ failed_to_parse_unicode_annotations:
static gboolean
parse_emojione_unicode (JsonNode *node,
- EmojiData *data)
+ EmojiData *data,
+ gboolean is_alternates)
{
const gchar *str, *unicode;
gchar *endptr = NULL;
@@ -305,7 +312,10 @@ parse_emojione_unicode (JsonNode *node,
endptr = NULL;
}
- data->emoji = g_string_free (emoji, FALSE);
+ if (is_alternates)
+ data->emoji_alternates = g_string_free (emoji, FALSE);
+ else
+ data->emoji = g_string_free (emoji, FALSE);
return TRUE;
}
@@ -480,7 +490,11 @@ parse_emojione_emoji_data (JsonNode *node,
EmojiData *data)
{
if (g_strcmp0 (member, "unicode") == 0)
- return parse_emojione_unicode (node, data);
+ return parse_emojione_unicode (node, data, FALSE);
+ else if (g_strcmp0 (member, "unicode_alt") == 0)
+ return parse_emojione_unicode (node, data, TRUE);
+ else if (g_strcmp0 (member, "unicode_alternates") == 0)
+ return parse_emojione_unicode (node, data, TRUE);
else if (g_strcmp0 (member, "shortname") == 0)
return parse_emojione_shortname (node, data);
else if (g_strcmp0 (member, "name") == 0)
diff --git a/src/ibusemoji.c b/src/ibusemoji.c
index c61cd703..4be092ac 100644
--- a/src/ibusemoji.c
+++ b/src/ibusemoji.c
@@ -29,14 +29,15 @@
#include "ibusinternal.h"
#define IBUS_EMOJI_DATA_MAGIC "IBusEmojiData"
-#define IBUS_EMOJI_DATA_VERSION (2)
+#define IBUS_EMOJI_DATA_VERSION (3)
enum {
PROP_0 = 0,
PROP_EMOJI,
PROP_ANNOTATIONS,
PROP_DESCRIPTION,
- PROP_CATEGORY
+ PROP_CATEGORY,
+ PROP_EMOJI_ALTERNATES
};
struct _IBusEmojiDataPrivate {
@@ -44,6 +45,7 @@ struct _IBusEmojiDataPrivate {
GSList *annotations;
gchar *description;
gchar *category;
+ gchar *emoji_alternates;
};
#define IBUS_EMOJI_DATA_GET_PRIVATE(o) \
@@ -142,6 +144,19 @@ ibus_emoji_data_class_init (IBusEmojiDataClass *class)
"The emoji category",
"",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ /**
+ * IBusEmojiData:emoji_alternates:
+ *
+ * The emoji alternate characters
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_EMOJI_ALTERNATES,
+ g_param_spec_string ("emoji-alternates",
+ "emoji alternate charasters",
+ "The emoji alternate characters UTF-8",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -180,19 +195,24 @@ ibus_emoji_data_set_property (IBusEmojiData *emoji,
emoji->priv->emoji = g_value_dup_string (value);
break;
case PROP_ANNOTATIONS:
- g_assert (emoji->priv->annotations == NULL);
+ if (emoji->priv->annotations)
+ g_slist_free_full (emoji->priv->annotations, g_free);
emoji->priv->annotations =
g_slist_copy_deep (g_value_get_pointer (value),
(GCopyFunc) g_strdup, NULL);
break;
case PROP_DESCRIPTION:
- g_assert (emoji->priv->description == NULL);
+ g_free (emoji->priv->description);
emoji->priv->description = g_value_dup_string (value);
break;
case PROP_CATEGORY:
g_assert (emoji->priv->category == NULL);
emoji->priv->category = g_value_dup_string (value);
break;
+ case PROP_EMOJI_ALTERNATES:
+ g_assert (emoji->priv->emoji_alternates == NULL);
+ emoji->priv->emoji_alternates = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (emoji, prop_id, pspec);
}
@@ -220,6 +240,9 @@ ibus_emoji_data_get_property (IBusEmojiData *emoji,
case PROP_CATEGORY:
g_value_set_string (value, ibus_emoji_data_get_category (emoji));
break;
+ case PROP_EMOJI_ALTERNATES:
+ g_value_set_string (value, ibus_emoji_data_get_emoji_alternates(emoji));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (emoji, prop_id, pspec);
}
@@ -247,6 +270,9 @@ ibus_emoji_data_serialize (IBusEmojiData *emoji,
}
g_variant_builder_add (builder, "s", NOTNULL (emoji->priv->description));
g_variant_builder_add (builder, "s", NOTNULL (emoji->priv->category));
+ g_variant_builder_add (builder, "s",
+ NOTNULL (emoji->priv->emoji_alternates));
+#undef NOTNULL
return TRUE;
}
@@ -277,6 +303,10 @@ ibus_emoji_data_deserialize (IBusEmojiData *emoji,
&emoji->priv->description);
ibus_g_variant_get_child_string (variant, retval++,
&emoji->priv->category);
+ if (g_variant_n_children (variant) < retval + 1)
+ return retval;
+ ibus_g_variant_get_child_string (variant, retval++,
+ &emoji->priv->emoji_alternates);
return retval;
}
@@ -295,6 +325,7 @@ ibus_emoji_data_copy (IBusEmojiData *dest,
NULL);
dest->priv->description = g_strdup (src->priv->description);
dest->priv->category = g_strdup (src->priv->category);
+ dest->priv->emoji_alternates = g_strdup (src->priv->emoji_alternates);
return TRUE;
}
@@ -314,6 +345,7 @@ ibus_emoji_data_new (const gchar *first_property_name, ...)
g_assert (emoji->priv->emoji != NULL);
g_assert (emoji->priv->description != NULL);
g_assert (emoji->priv->category != NULL);
+ g_assert (emoji->priv->emoji_alternates != NULL);
return emoji;
}
@@ -370,6 +402,14 @@ ibus_emoji_data_get_category (IBusEmojiData *emoji)
return emoji->priv->category;
}
+const gchar *
+ibus_emoji_data_get_emoji_alternates (IBusEmojiData *emoji)
+{
+ g_return_val_if_fail (IBUS_IS_EMOJI_DATA (emoji), NULL);
+
+ return emoji->priv->emoji_alternates;
+}
+
static void
variant_foreach_add_emoji (IBusEmojiData *emoji,
diff --git a/src/ibusemoji.h b/src/ibusemoji.h
index eb24fdda..233cadd6 100644
--- a/src/ibusemoji.h
+++ b/src/ibusemoji.h
@@ -156,6 +156,20 @@ const gchar * ibus_emoji_data_get_category (IBusEmojiData *emoji);
/**
+ * ibus_emoji_data_get_emoji_alternates:
+ * @emoji : An #IBusEmojiData
+ *
+ * Gets the emoji alternate characters in #IBusEmojiData. It should not be
+ * freed. The alternates are defined in "unicode_alt" in EmojiOne json.
+ *
+ * Returns: emoji alternates property in #IBusEmojiData
+ *
+ */
+const gchar * ibus_emoji_data_get_emoji_alternates
+ (IBusEmojiData *emoji);
+
+
+/**
* ibus_emoji_dict_save:
* @path: A path of the saved dictionary file.
* @dict: (element-type utf8 gpointer) (transfer none): An Emoji dictionary