mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 15:14:17 +00:00
emoji: Add keywords to the data
And use them for matching in the Emoji chooser.
This commit is contained in:
parent
44448016e8
commit
ed724ebc35
@ -23,9 +23,10 @@
|
|||||||
* au - sequence of unicode codepoints. If the
|
* au - sequence of unicode codepoints. If the
|
||||||
* sequence contains a 0, it marks the point
|
* sequence contains a 0, it marks the point
|
||||||
* where skin tone modifiers should be inserted
|
* where skin tone modifiers should be inserted
|
||||||
* s - name, e.g. "man worker"
|
* s - name, e.g. "man worker"
|
||||||
* s - shortname, for completion. This includes
|
* s - shortname, for completion. This includes
|
||||||
* colons to mark the ends, e.g. ":guardsman:"
|
* colons to mark the ends, e.g. ":guardsman:"
|
||||||
|
* as - keywords, e.g. "man", "worker"
|
||||||
*/
|
*/
|
||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -100,19 +101,16 @@ main (int argc, char *argv[])
|
|||||||
ro = json_node_get_object (root);
|
ro = json_node_get_object (root);
|
||||||
json_object_iter_init (&iter, ro);
|
json_object_iter_init (&iter, ro);
|
||||||
|
|
||||||
names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)json_object_unref);
|
||||||
name_key = g_string_new ("");
|
name_key = g_string_new ("");
|
||||||
|
|
||||||
while (json_object_iter_next (&iter, &name, &node))
|
while (json_object_iter_next (&iter, &name, &node))
|
||||||
{
|
{
|
||||||
JsonObject *obj = json_node_get_object (node);
|
JsonObject *obj = json_node_get_object (node);
|
||||||
const char *unicode;
|
const char *unicode;
|
||||||
const char *shortname;
|
|
||||||
|
|
||||||
unicode = json_object_get_string_member (obj, "unicode");
|
unicode = json_object_get_string_member (obj, "unicode");
|
||||||
shortname = json_object_get_string_member (obj, "shortname");
|
g_hash_table_insert (names, g_strdup (unicode), json_object_ref (obj));
|
||||||
|
|
||||||
g_hash_table_insert (names, g_strdup (unicode), g_strdup (shortname));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (parser);
|
g_object_unref (parser);
|
||||||
@ -129,19 +127,22 @@ main (int argc, char *argv[])
|
|||||||
array = json_node_get_array (root);
|
array = json_node_get_array (root);
|
||||||
length = json_array_get_length (array);
|
length = json_array_get_length (array);
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(auss)"));
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(aussas)"));
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < length)
|
while (i < length)
|
||||||
{
|
{
|
||||||
JsonNode *node = json_array_get_element (array, i);
|
JsonNode *node = json_array_get_element (array, i);
|
||||||
JsonObject *obj = json_node_get_object (node);
|
JsonObject *obj = json_node_get_object (node);
|
||||||
GVariantBuilder b1;
|
GVariantBuilder b1;
|
||||||
|
GVariantBuilder b2;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *shortname;
|
const char *shortname;
|
||||||
char *code;
|
char *code;
|
||||||
int j;
|
int j, k;
|
||||||
gboolean skip;
|
gboolean skip;
|
||||||
gboolean has_variations;
|
gboolean has_variations;
|
||||||
|
JsonObject *obj2;
|
||||||
|
JsonArray *kw;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
@ -177,9 +178,19 @@ main (int argc, char *argv[])
|
|||||||
if (!parse_code (&b1, code, name_key))
|
if (!parse_code (&b1, code, name_key))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
shortname = g_hash_table_lookup (names, name_key->str);
|
g_variant_builder_init (&b2, G_VARIANT_TYPE ("as"));
|
||||||
|
obj2 = g_hash_table_lookup (names, name_key->str);
|
||||||
|
if (obj2)
|
||||||
|
{
|
||||||
|
shortname = json_object_get_string_member (obj2, "shortname");
|
||||||
|
kw = json_object_get_array_member (obj2, "keywords");
|
||||||
|
for (k = 0; k < json_array_get_length (kw); k++)
|
||||||
|
g_variant_builder_add (&b2, "s", json_array_get_string_element (kw, k));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
shortname = "";
|
||||||
|
|
||||||
g_variant_builder_add (&builder, "(auss)", &b1, name, shortname ? shortname : "");
|
g_variant_builder_add (&builder, "(aussas)", &b1, name, shortname, &b2);
|
||||||
}
|
}
|
||||||
|
|
||||||
v = g_variant_builder_end (&builder);
|
v = g_variant_builder_end (&builder);
|
||||||
|
@ -337,8 +337,8 @@ add_recent_item (GtkEmojiChooser *chooser,
|
|||||||
|
|
||||||
g_variant_ref (item);
|
g_variant_ref (item);
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a((auss)u)"));
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a((aussas)u)"));
|
||||||
g_variant_builder_add (&builder, "(@(auss)u)", item, modifier);
|
g_variant_builder_add (&builder, "(@(aussas)u)", item, modifier);
|
||||||
|
|
||||||
children = NULL;
|
children = NULL;
|
||||||
for (child = gtk_widget_get_last_child (chooser->recent.box);
|
for (child = gtk_widget_get_last_child (chooser->recent.box);
|
||||||
@ -363,7 +363,7 @@ add_recent_item (GtkEmojiChooser *chooser,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_variant_builder_add (&builder, "(@(auss)u)", item2, modifier2);
|
g_variant_builder_add (&builder, "(@(aussas)u)", item2, modifier2);
|
||||||
}
|
}
|
||||||
g_list_free (children);
|
g_list_free (children);
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ populate_emoji_chooser (gpointer data)
|
|||||||
if (!chooser->data)
|
if (!chooser->data)
|
||||||
{
|
{
|
||||||
GBytes *bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL);
|
GBytes *bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL);
|
||||||
chooser->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(auss)"), bytes, TRUE));
|
chooser->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(aussas)"), bytes, TRUE));
|
||||||
g_bytes_unref (bytes);
|
g_bytes_unref (bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,7 +719,9 @@ filter_func (GtkFlowBoxChild *child,
|
|||||||
GVariant *emoji_data;
|
GVariant *emoji_data;
|
||||||
const char *text;
|
const char *text;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char **keywords;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
int i;
|
||||||
|
|
||||||
res = TRUE;
|
res = TRUE;
|
||||||
|
|
||||||
@ -736,6 +738,10 @@ filter_func (GtkFlowBoxChild *child,
|
|||||||
g_variant_get_child (emoji_data, 1, "&s", &name);
|
g_variant_get_child (emoji_data, 1, "&s", &name);
|
||||||
res = g_str_match_string (text, name, TRUE);
|
res = g_str_match_string (text, name, TRUE);
|
||||||
|
|
||||||
|
g_variant_get_child (emoji_data, 3, "^a&s", &keywords);
|
||||||
|
for (i = 0; !res && keywords[i]; i++)
|
||||||
|
res = g_str_match_string (text, keywords[i], TRUE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (res)
|
if (res)
|
||||||
section->empty = FALSE;
|
section->empty = FALSE;
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
<schemalist>
|
<schemalist>
|
||||||
|
|
||||||
<schema id='org.gtk.gtk4.Settings.EmojiChooser' path='/org/gtk/gtk4/settings/emoji-chooser/'>
|
<schema id='org.gtk.gtk4.Settings.EmojiChooser' path='/org/gtk/gtk4/settings/emoji-chooser/'>
|
||||||
<key name='recent-emoji' type='a((auss)u)'>
|
<key name='recent-emoji' type='a((aussas)u)'>
|
||||||
<default>[]</default>
|
<default>[]</default>
|
||||||
<summary>Recently used Emoji</summary>
|
<summary>Recently used Emoji</summary>
|
||||||
<description>
|
<description>
|
||||||
An array of Emoji definitions to show in the Emoji chooser. Each Emoji is
|
An array of Emoji definitions to show in the Emoji chooser. Each Emoji is
|
||||||
specified as an array of codepoints, name and shortname. The extra integer after this
|
specified as an array of codepoints, name, shortname and keywords. The extra
|
||||||
pair is the code of the Fitzpatrick modifier to use in place of a 0 in the
|
integer after this pair is the code of the Fitzpatrick modifier to use in
|
||||||
codepoint array.
|
place of a 0 in the codepoint array.
|
||||||
</description>
|
</description>
|
||||||
</key>
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
|
Loading…
Reference in New Issue
Block a user