push mim_eng
[mim] / src / mim / mim-main.c
1 /************************************************************************
2 **
3 **  Copyright (C) 2009  MiM
4 **
5 **          Contact: Handspring <xhealer@gmail.com>
6 **
7 **          AUTHOR:
8 **
9 **  This file is part of MiM Pinyin.
10 **
11 **  This is free software: you can redistribute it and/or modify
12 **  it under the terms of the GNU General Public License as published by
13 **  the Free Software Foundation, either version 3 of the License, or
14 **  (at your option) any later version.
15 **
16 **  This is distributed in the hope that it will be useful,
17 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 **  GNU General Public License for more details.
20 **
21 **  You should have received a copy of the GNU General Public License
22 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
23 **
24 *************************************************************************/
25 #include <dbus/dbus.h>
26 #include <dbus/dbus-glib.h>
27 #include <glib.h>
28 #include <gconf/gconf-client.h>
29
30 #include "dbus-callback.h"
31 #include "gconf-change-cb.h"
32
33 static DBusHandlerResult 
34 dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
35 {
36         const gchar *sig_mumber;
37         sig_mumber = dbus_message_get_member(message);
38 #ifdef SWITCH
39         switch()
40         {
41                 case "init_string":
42                         get_ui_string(message, connection);
43                         break;
44                 case "user_select":             
45                         user_select_cb(message);
46                         break;
47                 case "click_backspace":
48                         backspace_key_cb();
49                         break;
50                 case "click_priv":              
51                         priv_click_cb();
52                         break;
53                 case "click_next":              
54                         next_click_cb();
55                         break;
56                 case "click_space":             
57                         space_key_cb();
58                         break;
59                 case "click_enter":             
60                         enter_key_cb();
61                         break;
62                 default:
63                         printf("Message quit received\n");
64                 GMainLoop *loop = (GMainLoop*) user_data;
65                 g_main_loop_quit(loop);
66                         break;
67         }
68 #endif
69         g_print("recived message mumber: %s\n", sig_mumber);
70         
71         if(sig_mumber == NULL)
72                 g_printf("recived NULL signal\n");
73                 
74         else if (!strcmp(sig_mumber,"init_string"))
75         {
76                 get_ui_string(message,connection);
77                 g_printf("signal init string");
78         }
79         
80         else if (!strcmp(sig_mumber, "user_select"))
81                 user_select_cb(message);
82                 
83         else if (!strcmp(sig_mumber,"click_backspace"))
84                 backspace_key_cb();
85                 
86         else if (!strcmp(sig_mumber, "click_priv"))
87         {
88                 priv_click_cb();
89                 g_printf("signal click priv");
90         }
91         
92         else if (!strcmp(sig_mumber,"click_next"))
93                 next_click_cb();
94                 
95         else if (!strcmp(sig_mumber,"click_space"))
96                 space_key_cb();
97                 
98         else if (!strcmp(sig_mumber,"click_enter"))
99                 enter_key_cb();
100                 
101         else
102                 g_printf("signal cannot resolve\n");
103                         
104         return DBUS_HANDLER_RESULT_HANDLED;
105 }
106  
107 int main()
108 {
109     DBusConnection *connection;
110     DBusError error;
111     GConfClient *client;
112     
113     /* glib main loop */
114     GMainLoop *loop;
115     loop = g_main_loop_new(NULL,FALSE);
116     
117     dbus_error_init(&error);
118     connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
119     if ( dbus_error_is_set(&error) )
120     {
121         g_printf("Error connecting to the daemon bus: %s",error.message);
122         dbus_error_free(&error);
123         return 1;
124     }
125     dbus_bus_add_match (connection,
126         "type='signal',interface='org.ifanr.mim.mainui'",NULL);
127     dbus_connection_add_filter (connection, dbus_filter, loop, NULL);
128     /* dbus-glib call */
129     dbus_connection_setup_with_g_main(connection,NULL);
130     
131     client = gconf_client_get_default ();
132     /* Add our directory to the list of directories the GConfClient will
133          * watch.
134          */
135     gconf_client_add_dir (client,
136                     PATH,
137                     GCONF_CLIENT_PRELOAD_NONE,
138                     NULL);
139
140     /* Listen to changes to our key. */
141     gconf_client_notify_add (client,
142                     KEY,
143                     gconf_notify_func,
144                     NULL,/*user data*/
145                     NULL,
146                     NULL);
147     
148     /* run glib main loop */
149     g_main_loop_run(loop);
150     return 0;
151 }
152
153