From: xddeng Date: Mon, 26 Oct 2009 08:24:49 +0000 (+0800) Subject: add new file X-Git-Url: http://git.maemo.org/git/?p=mim;a=commitdiff_plain;h=d36e7810a8b72db27a51d3239f0224a0409ed64a;ds=sidebyside add new file --- diff --git a/src/mim/Nominee.c b/src/mim/Nominee.c new file mode 100644 index 0000000..5fd0081 --- /dev/null +++ b/src/mim/Nominee.c @@ -0,0 +1,79 @@ +#include "Nominee.h" + +void InitNom(Nominee *N) +{ + N->top = -1; +} + +gint NomEmpty(Nominee *N) +{ + return N->top == -1; +} + +gint NomFull(Nominee *N) +{ + return N->top == NomSize-1; +} + +void push(Nominee *N,DataType d) +{ + if (NomFull(N)) + { + g_printf("Nominee is full!"); + return ; + } + N->data[++N->top] = d; +} + +DataType pop(Nominee *N) +{ + if (NomEmpty(N)) + { + g_printf("Nominee is empty!\n"); + return FALSE; + } + return(N->data[N->top--]); +} + +gint num(Nominee *N) +{ + return ++N->top; +} + +gchar* disp(Nominee *N) +{ + if (NomEmpty(N)) + { + g_printf("Nomieen is empty!\n"); + return ; + } + gint count = N->top; + + strcpy(UD_Phrase, N->data[N->top--]); + + while(N->top != -1) + { + strcat(UD_Phrase, N->data[N->top--]); + } + g_printf("%s\n",UD_Phrase); + + return UD_Phrase; +} + +gint main() +{ + Nominee *S; + S = (Nominee *)g_slice_alloc0(sizeof(Nominee)); + g_printf("Initialize the stack.\n"); + InitNom(S); + push(S,"aaa"); + push(S,"bbb"); + push(S,"ccc"); + push(S,"ddd"); + + g_printf("pop a element\n"); + DataType aa = pop(S); + + disp(S); + g_slice_free(Nominee, S); +} \ No newline at end of file diff --git a/src/mim/Nominee.h b/src/mim/Nominee.h new file mode 100644 index 0000000..0a33151 --- /dev/null +++ b/src/mim/Nominee.h @@ -0,0 +1,28 @@ +#ifndef NOMINEE_H_ +#define NOMINEE_H_ +#include + +#define NomSize 25 +#define UDP_SIZE 50 +typedef gchar* DataType; +typedef struct nominee{ + DataType data[NomSize];//offset + gint top; +}Nominee; + +gchar UD_Phrase[UDP_SIZE]; + +void InitNom(Nominee *N); + +gint NomEmpty(Nominee *N); + +gint NomFull(Nominee *N); + +void push(Nominee *N,DataType d); + +DataType pop(Nominee *N); + +gint num(Nominee *N); + +gchar* disp(Nominee *N); +#endif /*NOMINEE_H_*/ \ No newline at end of file diff --git a/src/mim/dbus-callback.c b/src/mim/dbus-callback.c new file mode 100644 index 0000000..1aaeec0 --- /dev/null +++ b/src/mim/dbus-callback.c @@ -0,0 +1,193 @@ +#include "dbus-callback.h" + +void get_ui_string(DBusMessage *message, DBusConnection *mim_conn) { + DBusMessageIter iter; + Composition composition; + + dbus_message_iter_init(message, &iter); + dbus_message_iter_get_basic(&iter, &composition.unparsed); + + g_printf("sigvalue = %s \n", composition.unparsed); + connection = mim_conn; + seg_string(composition); +} + +/*seg the string that from ui model + * + * + * + * */ +static void seg_string(Composition composition) { + /* seg teh string that form ui model, + * and then + * */ + gint str_len, i; + + composition.En_Ch_Flag = FALSE; + str_len = strlen(composition.unparsed); + for (i = 0;i < str_len; i++) + { + gchar c = *(composition.unparsed + i); + composition.str_list[i][10] = c; + g_printf("seg_string c = %c \n", composition.str_list[i][10]); + } + if (composition.En_Ch_Flag) + { + DBusMessage *statu_message; + statu_message = dbus_message_new_signal ("/org/ifanr/mim/engine", + "org.ifanr.mim.engine", + "isEnglish"); + /* Send the signal */ + dbus_connection_send (connection, statu_message, NULL); + dbus_message_unref (statu_message); + return; + } + else + { + match_string(composition, i); + g_printf("str_len = %d \n", str_len); + } +} + +/*when you seg string that from ui, match they with chunck + * + * + * + * */ +static void match_string(Composition composition, gint i){ + /*invoke hua yang's API*/ + g_printf("chinese string\n"); + if (i >= 3) + { + g_printf("strlist.length >= 3\n"); + } + else if (i == 2) + g_printf("strlist.length == 2\n"); + else if (i == 1) + g_printf("strlist.length == 1\n"); + send_ch_string("chinese string"); +} + +static void send_ch_string(gchar *ch_string) +{ + DBusMessage *message; + DBusMessageIter iter; + gchar *message_text = ch_string; + message = dbus_message_new_signal ("/org/ifanr/mim/engine", + "org.ifanr.mim.engine", + "ch_string"); + /* Send the signal */ + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, + DBUS_TYPE_STRING, + &message_text); + dbus_connection_send (connection, message, NULL); + dbus_message_unref (message); +} + +void priv_click_cb() { + g_printf("priv click cb\n"); +} + +void next_click_cb() { + g_printf("next click cb"); +} + +void user_select_cb(DBusMessage *message) { + g_printf("user select received\n"); + DBusMessageIter iter; + gint select_num; + + dbus_message_iter_init(message, &iter); + dbus_message_iter_get_basic(&iter, &select_num); + + g_printf("select_num = %d \n", select_num); + + + if (0) + { + /* + * input has finished; + * Word Priority Adjustment, + * or inserting newly built phrases into storage + * if need insert newly built phrases, we need invote the nominee.pop + * */ + } + else + { + /*engine pushes the selected candidate into Nominee, + * and then move the starting syllable cursor of the composition according + * to the char number of the selected candidate + * */ + } +} + +/*if the backspace key clicked, invole this function + * + * + * + * */ +void backspace_key_cb() { +#if 0 + if in chinese + { + /*Check if the Nominee is empty, + * if not, this means user has wrongly selected some + * candidate and this operation should be rolled back. + * */ + if (Nominee == NULL) + if (he last key pressed is Mandatory Separator Key) { + remove it and update composition display; + } + else { + remove the last key and; + } + else { + /*The cursor of composition is moved back according + * to the Char number of the last element in Nominee, + * then Nominee.Pop() is triggered and the last element is removed. + * */ + } + } + else if in english + { + /*the last char in last syllable should be removed, + * and then */ + if (composition empty now) + /*input is cancelled()*/ + return; + } + /*re seg*/ + seg_string(); + /*engine re-examine the C/E status*/ + #endif +} + +/*if the space key clicked, invole this function*/ +void space_key_cb() { + #if 0 + if in chinese + { + ; + } + else if in english + { + ; + } + #endif +} + +void enter_key_cb() { + g_printf("user type the enter key\n"); + DBusMessage *message; + DBusMessageIter iter; + const gint user_select = 1; + message = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL); + /* Send the signal */ + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, + DBUS_TYPE_INT32, + &user_select); + user_select_cb(message); +} + diff --git a/src/mim/dbus-callback.h b/src/mim/dbus-callback.h new file mode 100644 index 0000000..602b5e5 --- /dev/null +++ b/src/mim/dbus-callback.h @@ -0,0 +1,36 @@ +#ifndef DBUS_CALLBACK_H_ +#define DBUS_CALLBACK_H_ + +#include +#include + +DBusConnection *connection; +typedef struct composition{ + gchar *unparsed; + gchar str_list[20][10]; + gint start_point; + gboolean En_Ch_Flag; +}Composition; + +void get_ui_string(DBusMessage *message, DBusConnection *connection); + +static void seg_string(Composition composition); + +static void match_string(Composition composition, gint i); + +static void send_ch_string(gchar *ch_string); + +void user_select_cb(DBusMessage *message); + +void backspace_key_cb(); + +void priv_click_cb(); + +void next_click_cb(); + +void space_key_cb(); + +void enter_key_cb(); + +#endif /*DBUS_CALLBACK_H_*/ + diff --git a/src/mim/gconf-change-cb.c b/src/mim/gconf-change-cb.c new file mode 100644 index 0000000..fbb3553 --- /dev/null +++ b/src/mim/gconf-change-cb.c @@ -0,0 +1,15 @@ +#include "gconf-change-cb.h" +/* This is called when our gconf key is changed. */ +void +gconf_notify_func (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data) +{ + GConfValue *value; + gboolean checked; + + value = gconf_entry_get_value (entry); + + checked = gconf_value_get_bool (value); +} diff --git a/src/mim/gconf-change-cb.h b/src/mim/gconf-change-cb.h new file mode 100644 index 0000000..df3a9af --- /dev/null +++ b/src/mim/gconf-change-cb.h @@ -0,0 +1,15 @@ +#ifndef GCONF_CHANGE_CB_H_ +#define GCONF_CHANGE_CB_H_ +#include +#include + +#define PATH "/apps/mimi/piny" +#define KEY "/apps/mimi/piny/eng_ch" + +void +gconf_notify_func (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data); + +#endif /*GCONF_CHANGE_CB_H_*/