add new file
[mim] / src / mim / dbus-callback.c
diff --git a/src/mim/dbus-callback.c b/src/mim/dbus-callback.c
new file mode 100644 (file)
index 0000000..1aaeec0
--- /dev/null
@@ -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);
+}
+