...
 
Commits (3)
......@@ -22,6 +22,21 @@
<arg type="u" name="fetch_size"/>
<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>
<!-- CommitCandidate
@candidate: the candidate user committed
@candidate_pinyin_indices: the corresponding element in GetCandidates
candidates_pinyin_indices out param.
This will allow zero-pinyin-service to add candidate to user db and
revert DeleteCandidate effect.
-->
<method name="CommitCandidate">
<arg type="s" name="candidate"/>
<arg type="a(ii)" name="candidate_pinyin_indices"/>
</method>
<!-- DeleteCandidate
......
......@@ -33,14 +33,16 @@ on_handle_get_candidates (ZeroPinyinService *object,
GVariant *result = NULL;
GVariantBuilder *candidates_builder = NULL;
GVariantBuilder *matched_lengths_builder = NULL;
GVariantBuilder *candidates_pinyin_indices = NULL;
/* test data */
/* get_candidates_test (preedit_str, fetch_size, candidates_builder, matched_lengths_builder); */
candidates_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
matched_lengths_builder = g_variant_builder_new (G_VARIANT_TYPE ("au"));
get_candidates (appdata->db, preedit_str, fetch_size, candidates_builder, matched_lengths_builder);
candidates_pinyin_indices = g_variant_builder_new (G_VARIANT_TYPE ("aa(ii)"));
get_candidates (appdata->db, preedit_str, fetch_size, candidates_builder, matched_lengths_builder, candidates_pinyin_indices);
result = g_variant_new ("(asau)", candidates_builder, matched_lengths_builder);
result = g_variant_new ("(asauaa(ii))", candidates_builder, matched_lengths_builder, candidates_pinyin_indices);
g_assert_nonnull (result);
/* result is a GVarient tuple of two dbus arrays */
......@@ -48,10 +50,23 @@ on_handle_get_candidates (ZeroPinyinService *object,
g_variant_builder_unref (candidates_builder);
g_variant_builder_unref (matched_lengths_builder);
g_variant_builder_unref (candidates_pinyin_indices);
return TRUE;
}
static gboolean
on_handle_commit_candidate (ZeroPinyinService *object,
GDBusMethodInvocation *invocation,
const gchar *candidate,
GVariant *candidate_pinyin_indices,
AppData *appdata)
{
commit_candidate (appdata->db, candidate, candidate_pinyin_indices);
g_dbus_method_invocation_return_value (invocation, NULL);
return TRUE;
}
static gboolean
on_handle_delete_candidate (ZeroPinyinService *object,
GDBusMethodInvocation *invocation,
......@@ -118,6 +133,10 @@ on_bus_acquired (GDBusConnection *connection,
"handle-get-candidates",
G_CALLBACK (on_handle_get_candidates),
appdata);
g_signal_connect (appdata->interface,
"handle-commit-candidate",
G_CALLBACK (on_handle_commit_candidate),
appdata);
g_signal_connect (appdata->interface,
"handle-delete-candidate",
G_CALLBACK (on_handle_delete_candidate),
......@@ -154,7 +173,14 @@ on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_message ("on_name_lost() name=%s", name);
AppData *appdata = (AppData*) user_data;
/* this won't happen if this is the only app that tries to take the
* name, because GApplication already have primary instance
* concept. None primary instance will just send 'activate' signal to
* primary instance and exit. They will not try to register ibus at
* all. */
g_message ("on_name_lost() name=%s exiting", name);
g_application_quit (G_APPLICATION (appdata->app));
}
static void
......
# -*- mode: conf -*-
project('zero-pinyin-service', ['c', 'cpp'],
version: '0.5.0',
version: '0.6.0',
license: 'GPL',
default_options: [
'warning_level=2',
......@@ -44,17 +44,19 @@ shared_dep = [glib, gio, uuid, sqlite3]
gen_inc = include_directories('.')
gdbus_codegen = find_program('gdbus-codegen')
zero_panel_generated = custom_target('zero-panel-generated',
zero_pinyin_generated = custom_target('zero-panel-generated',
input: 'com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface.xml',
output: ['zero-pinyin-service-generated.h', 'zero-pinyin-service-generated.c'],
command: [gdbus_codegen, '--generate-c-code', 'zero-pinyin-service-generated', '@[email protected]'])
src = [
lib = [
'../PinyinParser.cc',
'../sqlite3_util.c',
'parse-pinyin.cpp',
'zero-pinyin-service.c',
zero_panel_generated,
'zero-pinyin-service.c']
src = [
lib,
zero_pinyin_generated,
'main.c']
executable('zero-pinyin-service', src,
include_directories: gen_inc,
......@@ -67,5 +69,5 @@ test('parse-pinyin',
dependencies: shared_dep))
test('zero-pinyin-service-test',
executable('zero-pinyin-service-test',
['zero-pinyin-service-test.c'],
[lib, 'zero-pinyin-service-test.c'],
dependencies: shared_dep))
......@@ -4,7 +4,7 @@ static void
test_GString ()
{
GString* s = NULL;
s = g_string_new ("");
s = g_string_new (NULL);
g_string_append_printf (s, "s0=%d ", 1);
g_assert_cmpstr (s->str, ==, "s0=1 ");
......@@ -12,11 +12,24 @@ test_GString ()
g_string_free (s, TRUE);
}
static void
test_build_s_y_fields ()
{
gchar* result = NULL;
result = build_s_y_fields (1);
g_assert_cmpstr (result, ==, ", s0, y0 ");
g_free (result);
result = build_s_y_fields (2);
g_assert_cmpstr (result, ==, ", s0, y0, s1, y1 ");
g_free (result);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/zero/test_GString",
test_GString);
g_test_add_func ("/zero/test_GString", test_GString);
g_test_add_func ("/zero/test_build_s_y_fields", test_build_s_y_fields);
return g_test_run ();
}
This diff is collapsed.
......@@ -18,16 +18,18 @@ typedef struct {
} Pinyin;
typedef struct {
gchar* str; /* the candidate string */
gchar *str; /* the candidate string */
guint freq; /* word frequency [0, 65535] */
guint user_freq; /* user frequency [0, 65535] */
guint matched_py_length; /* matched preedit_str length */
guint char_len; /* candidate Chinese character length */
Pinyin **py_indices; /* Pinyin for each character in this candidate */
} Candidate;
/**
* an implementation of get_candidates() with simple test data.
*/
void get_candidates_test (const char* preedit_str,
void get_candidates_test (const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder);
......@@ -40,11 +42,25 @@ void get_candidates_test (const char* preedit_str,
* @candidates_builder candidates will be added to this builder
* @matched_lengths_builder matched preedit_str length will be added to this builder
*/
void get_candidates (sqlite3* db,
const char* preedit_str,
void get_candidates (sqlite3 *db,
const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder);
GVariantBuilder *matched_lengths_builder,
GVariantBuilder *candidates_pinyin_indices);
/**
* commit candidate.
*
* This will save candidate in user db so it's available in the future.
* It also update user_freq for given candidate.
*/
void commit_candidate (sqlite3 *db,
const gchar *candidate,
GVariant *candidate_pinyin_indices);
/* for test only */
char* build_s_y_fields (const guint n);
G_END_DECLS
......