WIP.
authorHuang Peng <shawn.p.huang@gmail.com>
Sat, 16 Aug 2008 06:13:19 +0000 (14:13 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Sat, 16 Aug 2008 06:13:19 +0000 (14:13 +0800)
client/gtk2/ibusim.c
client/gtk2/ibusimcontext.c
lib/gtk2/ibusimclient.c
lib/gtk2/ibusimclient.h

index e87c9f6..5fb2eaa 100644 (file)
@@ -26,7 +26,6 @@
 
 #define IBUS_LOCALDIR ""
 
-IBusIMClient *_client = NULL;
 static const GtkIMContextInfo ibus_im_info = {
     "ibus",
     "The Input Bus",
@@ -45,23 +44,19 @@ im_module_init (GTypeModule *type_module)
 {
     ibus_im_client_register_type(type_module);
     ibus_im_context_register_type(type_module);
-
-    _client = ibus_im_client_new ();
 }
 
 void
 im_module_exit (void)
 {
-    g_object_unref (_client);
 }
 
 GtkIMContext *
 im_module_create (const gchar *context_id)
 {
     if (strcmp (context_id, "ibus") == 0) {
-        const gchar *ic;
         IBusIMContext *context;
-        ic = ibus_im_client_create_input_context (_client);
+        context = ibus_im_context_new ();
         return GTK_IM_CONTEXT(context);
     }
     return NULL;
index 1a14564..312bdf5 100644 (file)
@@ -71,6 +71,9 @@ static void     ibus_im_context_set_use_preedit
                                             (GtkIMContext       *context,
                                              gboolean           use_preedit);
 
+/* static methods*/
+static void    _init_ibus_client            (void);
+
 /* callback functions for slave context */
 static void     _slave_commit_cb            (GtkIMContext       *slave,
                                              gchar              *string,
@@ -95,6 +98,10 @@ static void     _slave_delete_surrounding_cb
 static GType                _ibus_type_im_context = 0;
 static GtkIMContextClass    *parent_class = NULL;
 
+static IBusIMClient         *_client = NULL;
+static GHashTable           *_ic_table = NULL;
+static GArray               *_im_context_array = NULL;
+
 void
 ibus_im_context_register_type (GTypeModule *type_module)
 {
@@ -176,6 +183,8 @@ ibus_im_context_init     (IBusIMContext *obj)
 {
     DEBUG_FUNCTION_IN;
 
+    _ibus_client_init ();
+
     IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
     IBusIMContextPrivate *priv = ibus->priv =
         G_TYPE_INSTANCE_GET_PRIVATE (ibus, IBUS_TYPE_IM_CONTEXT, IBusIMContextPrivate);
@@ -214,6 +223,7 @@ ibus_im_context_init     (IBusIMContext *obj)
                 "retrieve-surrounding", G_CALLBACK (_slave_retrieve_surrounding_cb), obj);
     g_signal_connect (ibus->priv->slave,
                 "delete-surrounding", G_CALLBACK (_slave_delete_surrounding_cb), obj);
+    g_array_append (_im_context_array, obj);
 }
 
 static void
@@ -224,6 +234,14 @@ ibus_im_context_finalize (GObject *obj)
     IBusIMContext *ibus = IBUS_IM_CONTEXT (obj);
     IBusIMContextPrivate *priv = ibus->priv;
 
+    gint i;
+    for (i = 0; i < _im_context_array->len; i++) {
+        if (obj == g_array_index (_im_context_array, GObject, i)) {
+            g_array_remove_index_fast (_im_context_array, i);
+            break;
+        }
+    }
+
     ibus_im_client_release_im_context (_client, ibus);
 
     g_object_unref (priv->slave);
@@ -379,6 +397,50 @@ ibus_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit)
     gtk_im_context_set_use_preedit (priv->slave, use_preedit);
 }
 
+static void
+_client_connected_cb (IBusIMClient *client, gpointer user_data)
+{
+}
+
+static void
+_client_disconnected_cb (IBusIMClient *client, gpointer user_data)
+{
+}
+
+static void
+_client_commit_string_cb (IBusIMClient *client, const gchar *gpointer user_data)
+{
+}
+
+static void
+_ibus_client_init (void)
+{
+    if (_client != NULL)
+        return;
+
+    _im_context_array = g_array_new (TRUE, TRUE, sizeof (IBusIMContext *));
+    _ic_table = g_hash_table_new (g_str_hash, g_str_equal);
+
+    _client = ibus_im_client_new ();
+
+    g_signal_connect (_client, "connected",
+                        G_CALLBACK (_client_connected_cb), NULL);
+    g_signal_connect (_client, "disconnected",
+                        G_CALLBACK (_client_disconnected_cb), NULL);
+    g_signal_connect (_client, "commit-string",
+                        G_CALLBACK (_client_commit_string_cb), NULL);
+    g_signal_connect (_client, "update-preedit",
+                        G_CALLBACK (_client_update_preedit_cb), NULL);
+    g_signal_connect (_client, "show-preedit",
+                        G_CALLBACK (_client_show_preedit_cb), NULL);
+    g_signal_connect (_client, "hide-preedit",
+                        G_CALLBACK (_client_hide_preedit_cb), NULL);
+    g_signal_connect (_client, "enabled",
+                        G_CALLBACK (_client_enabled_cb), NULL);
+    g_signal_connect (_client, "disabled",
+                        G_CALLBACK (_client_disabled_cb), NULL);
+
+}
 
 /* Callback functions for slave context */
 static void
index 7829097..2c3e472 100644 (file)
@@ -579,8 +579,6 @@ ibus_im_client_finalize (GObject *obj)
     IBusIMClient *client = IBUS_IM_CLIENT (obj);
     IBusIMClientPrivate *priv = client->priv;
 
-    g_assert (client == _client);
-
 #ifdef HAVE_INOTIFY
     g_source_remove (priv->inotify_source);
     g_io_channel_unref (priv->inotify_channel);
@@ -595,7 +593,6 @@ ibus_im_client_finalize (GObject *obj)
 
     G_OBJECT_CLASS(parent_class)->finalize (obj);
 
-    _client = NULL;
 }
 
 static void
index a0e4f75..00b3fd8 100644 (file)
@@ -88,8 +88,6 @@ struct _IBusIMClientClass {
                              const gchar    *ic);
 };
 
-extern IBusIMClient                *_client;
-
 GType           ibus_im_client_get_type          (void);
 void            ibus_im_client_register_type     (GTypeModule     *type_module);
 IBusIMClient   *ibus_im_client_new               (void);