add new file
[mim] / src / mim / dbus-callback.c
1 #include "dbus-callback.h"
2
3 void get_ui_string(DBusMessage *message, DBusConnection *mim_conn) {
4     DBusMessageIter iter;
5     Composition composition;
6     
7     dbus_message_iter_init(message, &iter);
8     dbus_message_iter_get_basic(&iter, &composition.unparsed);
9
10     g_printf("sigvalue = %s \n", composition.unparsed);
11     connection = mim_conn;
12     seg_string(composition);
13 }
14
15 /*seg the string that from ui model
16  *
17  *
18  * 
19  * */
20 static void seg_string(Composition composition) {
21         /* seg teh string that form ui model, 
22          * and then
23          * */
24         gint str_len, i;
25         
26         composition.En_Ch_Flag = FALSE;
27         str_len = strlen(composition.unparsed);
28         for (i = 0;i < str_len; i++)
29         {
30                 gchar c = *(composition.unparsed + i);
31                 composition.str_list[i][10] = c;
32                 g_printf("seg_string c = %c \n", composition.str_list[i][10]);
33         }
34         if (composition.En_Ch_Flag)
35         {
36                     DBusMessage *statu_message;
37                     statu_message = dbus_message_new_signal ("/org/ifanr/mim/engine",
38                                                         "org.ifanr.mim.engine",
39                                                         "isEnglish");
40                     /* Send the signal */
41                     dbus_connection_send (connection, statu_message, NULL);
42                     dbus_message_unref (statu_message);
43                 return;
44         }
45         else
46         {
47                 match_string(composition, i);
48                 g_printf("str_len = %d \n", str_len);
49         }
50 }
51
52 /*when you seg string that from ui, match they with chunck
53  *
54  *
55  * 
56  * */
57 static void match_string(Composition composition, gint i){
58         /*invoke hua yang's API*/
59         g_printf("chinese string\n");
60         if (i >= 3)
61         {
62                 g_printf("strlist.length >= 3\n");
63         }
64         else if (i == 2)
65                 g_printf("strlist.length == 2\n");
66         else if (i == 1)
67                 g_printf("strlist.length == 1\n");
68         send_ch_string("chinese string");
69 }
70
71 static void send_ch_string(gchar *ch_string)
72 {
73     DBusMessage *message;
74     DBusMessageIter iter;
75     gchar *message_text = ch_string;
76     message = dbus_message_new_signal ("/org/ifanr/mim/engine",
77                                         "org.ifanr.mim.engine",
78                                         "ch_string");
79     /* Send the signal */
80     dbus_message_iter_init_append(message, &iter);
81     dbus_message_iter_append_basic(&iter,
82                                                             DBUS_TYPE_STRING,
83                                                             &message_text);
84     dbus_connection_send (connection, message, NULL);
85     dbus_message_unref (message);
86 }
87
88 void priv_click_cb() {
89     g_printf("priv click cb\n");
90 }
91
92 void next_click_cb() {
93     g_printf("next click cb");
94 }
95
96 void user_select_cb(DBusMessage *message) {
97     g_printf("user select received\n");
98     DBusMessageIter iter;
99     gint select_num;
100
101     dbus_message_iter_init(message, &iter);
102     dbus_message_iter_get_basic(&iter, &select_num);
103
104     g_printf("select_num = %d \n", select_num);
105         
106
107     if (0)
108     {
109         /*
110          * input has finished;
111          * Word Priority Adjustment, 
112          * or inserting newly built phrases into storage
113          * if need insert newly built phrases, we need invote the nominee.pop
114          * */ 
115     }
116     else
117     {
118         /*engine pushes the selected candidate into Nominee, 
119          * and then move the starting syllable cursor of the composition according
120          *  to the char number of the selected candidate
121          *  */
122     }
123 }
124
125 /*if the backspace key clicked, invole this function
126  *
127  *
128  *
129  * */
130 void backspace_key_cb() {
131 #if 0   
132         if in chinese
133         {
134                 /*Check if the Nominee is empty, 
135                  * if not, this means user has wrongly selected some
136                  * candidate and this operation should be rolled back.
137                  * */
138                 if (Nominee == NULL)
139                         if (he last key pressed is Mandatory Separator Key) {
140                                 remove it and update composition display;
141                         }
142                         else {
143                                 remove the last key and; 
144                         }
145                 else {
146                         /*The cursor of composition is moved back according 
147                          * to the Char number of the last element in Nominee, 
148                          * then Nominee.Pop() is triggered and the last element is removed. 
149                          * */
150                 }
151         }
152         else if in english
153         {
154                 /*the last char in last syllable should be removed, 
155                  * and then */
156                 if (composition empty now)
157                         /*input is cancelled()*/
158                         return;
159         }
160         /*re seg*/
161         seg_string();
162         /*engine re-examine the C/E status*/
163         #endif
164 }
165
166 /*if the space key clicked, invole this function*/
167 void space_key_cb() {
168         #if 0
169         if in chinese
170         {
171                 ;
172         }
173         else if in english
174         {
175                 ;
176         }
177         #endif
178 }
179
180 void enter_key_cb() {
181     g_printf("user type the enter key\n");
182     DBusMessage *message;
183     DBusMessageIter iter;
184     const gint user_select = 1;
185     message = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
186     /* Send the signal */
187     dbus_message_iter_init_append(message, &iter);
188     dbus_message_iter_append_basic(&iter,
189                                    DBUS_TYPE_INT32,
190                                    &user_select);
191     user_select_cb(message);
192 }
193