From 84c6eb0e8fdb5dc9ab1b80935edbff939657040d Mon Sep 17 00:00:00 2001 From: Yuanle Song <sylecn@gmail.com> Date: Wed, 23 Oct 2019 21:41:56 +0800 Subject: [PATCH] v0.9.3 removed FuzzyFlag property. use fuzzy_flag param in a new method instead. added GetCandidatesV2 method in service interface. use this new method in zero-el. --- ...yinService1.ZeroPinyinServiceInterface.xml | 33 +++++++++++++++---- main.c | 27 +++++++++++---- meson.build | 2 +- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface.xml b/com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface.xml index 31c3f61..3d3cbe2 100644 --- a/com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface.xml +++ b/com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface.xml @@ -4,13 +4,34 @@ <node> <interface name="com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface"> <!-- - FuzzyFlag: fuzzy matching flag for GetCandidates method. - 0 0b0 no fuzzy matching - 1 0b1 enable fuzzy match on z<->zh, c<->ch, s<->sh - 2 0b10 enable fuzzy match on l<->n - flag numbers can be combined with bit or. + GetCandidatesV2: + + Difference to GetCandidates: A fuzzy_flag param is added. + + @preedit_str: the preedit string + @fetch_size: how many candidates to fetch + @fuzzy_flag: fuzzy flag when matching candidate + 0 0b0 no fuzzy matching + 1 0b1 enable fuzzy match on z<->zh, c<->ch, s<->sh + 2 0b10 enable fuzzy match on l<->n + fuzzy flag numbers can be combined with bit or. + @candidates: the candidates + @matched_preedit_str_lengths: the matched str length in preedit str for + each candidate + + Get candidates for a preedit string. This method will fetch at least + fetch_size candidates if they exists. However, this method is allowed to + return more candidates than fetch_size. + --> - <property name="FuzzyFlag" type="u" access="readwrite"></property> + <method name="GetCandidatesV2"> + <arg type="s" name="preedit_str"/> + <arg type="u" name="fetch_size"/> + <arg type="u" name="fuzzy_flag"/> + <arg type="as" name="candidates" direction="out"/> + <arg type="au" name="matched_preedit_str_lengths" direction="out"/> + <arg type="aa(ii)" name="candidates_pinyin_indices" direction="out"/> + </method> <!-- GetCandidates: diff --git a/main.c b/main.c index 5bce0d7..266e885 100644 --- a/main.c +++ b/main.c @@ -19,11 +19,12 @@ typedef struct { } AppData; static gboolean -on_handle_get_candidates(ZeroPinyinService *object, - GDBusMethodInvocation *invocation, - const gchar *preedit_str, - guint fetch_size, - AppData *appdata) +on_handle_get_candidates_v2(ZeroPinyinService *object, + GDBusMethodInvocation *invocation, + const gchar *preedit_str, + guint fetch_size, + guint fuzzy_flag, + AppData *appdata) { if (preedit_str == NULL || fetch_size == 0) { g_dbus_method_invocation_return_dbus_error( @@ -45,7 +46,7 @@ on_handle_get_candidates(ZeroPinyinService *object, candidates_builder = g_variant_builder_new(G_VARIANT_TYPE("as")); matched_lengths_builder = g_variant_builder_new(G_VARIANT_TYPE("au")); candidates_pinyin_indices = g_variant_builder_new(G_VARIANT_TYPE("aa(ii)")); - get_candidates(appdata->db, preedit_str, fetch_size, zero_pinyin_service_get_fuzzy_flag(object), candidates_builder, matched_lengths_builder, candidates_pinyin_indices); + get_candidates(appdata->db, preedit_str, fetch_size, fuzzy_flag, candidates_builder, matched_lengths_builder, candidates_pinyin_indices); result = g_variant_new("(asauaa(ii))", candidates_builder, matched_lengths_builder, candidates_pinyin_indices); g_assert_nonnull(result); @@ -60,6 +61,16 @@ on_handle_get_candidates(ZeroPinyinService *object, return TRUE; } +static gboolean +on_handle_get_candidates(ZeroPinyinService *object, + GDBusMethodInvocation *invocation, + const gchar *preedit_str, + guint fetch_size, + AppData *appdata) +{ + return on_handle_get_candidates_v2(object, invocation, preedit_str, fetch_size, 0, appdata); +} + static gboolean on_handle_commit_candidate(ZeroPinyinService *object, GDBusMethodInvocation *invocation, @@ -134,6 +145,10 @@ on_bus_acquired(GDBusConnection *connection, g_message("on_bus_acquired() name=%s", name); appdata->interface = zero_pinyin_service_skeleton_new(); + g_signal_connect(appdata->interface, + "handle-get-candidates-v2", + G_CALLBACK(on_handle_get_candidates_v2), + appdata); g_signal_connect(appdata->interface, "handle-get-candidates", G_CALLBACK(on_handle_get_candidates), diff --git a/meson.build b/meson.build index 073b1d1..1ffc309 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ # -*- mode: conf -*- project('zero-pinyin-service', ['c', 'cpp'], - version: '0.9.2', + version: '0.9.3', license: 'GPL', default_options: [ 'warning_level=2', -- GitLab