1 /************************************************************************
3 ** Copyright (C) 2009 MiM
5 ** Contact: Handspring <xhealer@gmail.com>
9 ** This file is part of MiM Pinyin.
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.
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.
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/>.
24 *************************************************************************/
25 #include <dbus/dbus.h>
26 #include <dbus/dbus-glib.h>
28 #include <gconf/gconf-client.h>
30 #include "dbus-callback.h"
31 #include "gconf-change-cb.h"
33 static DBusHandlerResult
34 dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
36 const gchar *sig_mumber;
37 sig_mumber = dbus_message_get_member(message);
42 get_ui_string(message, connection);
45 user_select_cb(message);
47 case "click_backspace":
63 printf("Message quit received\n");
64 GMainLoop *loop = (GMainLoop*) user_data;
65 g_main_loop_quit(loop);
69 g_print("recived message mumber: %s\n", sig_mumber);
71 if(sig_mumber == NULL)
72 g_printf("recived NULL signal\n");
74 else if (!strcmp(sig_mumber,"init_string"))
76 get_ui_string(message,connection);
77 g_printf("signal init string");
80 else if (!strcmp(sig_mumber, "user_select"))
81 user_select_cb(message);
83 else if (!strcmp(sig_mumber,"click_backspace"))
86 else if (!strcmp(sig_mumber, "click_priv"))
89 g_printf("signal click priv");
92 else if (!strcmp(sig_mumber,"click_next"))
95 else if (!strcmp(sig_mumber,"click_space"))
98 else if (!strcmp(sig_mumber,"click_enter"))
102 g_printf("signal cannot resolve\n");
104 return DBUS_HANDLER_RESULT_HANDLED;
109 DBusConnection *connection;
115 loop = g_main_loop_new(NULL,FALSE);
117 dbus_error_init(&error);
118 connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
119 if ( dbus_error_is_set(&error) )
121 g_printf("Error connecting to the daemon bus: %s",error.message);
122 dbus_error_free(&error);
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);
129 dbus_connection_setup_with_g_main(connection,NULL);
131 client = gconf_client_get_default ();
132 /* Add our directory to the list of directories the GConfClient will
135 gconf_client_add_dir (client,
137 GCONF_CLIENT_PRELOAD_NONE,
140 /* Listen to changes to our key. */
141 gconf_client_notify_add (client,
148 /* run glib main loop */
149 g_main_loop_run(loop);