Use G_N_ELEMENTS.
authorPeng Huang <shawn.p.huang@gmail.com>
Thu, 28 Jan 2010 00:42:47 +0000 (08:42 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Thu, 28 Jan 2010 00:42:47 +0000 (08:42 +0800)
bus/ibusimpl.c
bus/inputcontext.c
bus/panelproxy.c

index 7b53d78..62d54ae 100644 (file)
@@ -938,10 +938,9 @@ _ibus_create_input_context (BusIBusImpl     *ibus,
         { "focus-in",       G_CALLBACK (_context_focus_in_cb) },
         { "focus-out",      G_CALLBACK (_context_focus_out_cb) },
         { "destroy",        G_CALLBACK (_context_destroy_cb) },
-        { NULL, NULL }
     };
 
-    for (i = 0; signals[i].name != NULL; i++) {
+    for (i = 0; G_N_ELEMENTS (signals); i++) {
         g_signal_connect (context,
                           signals[i].name,
                           signals[i].callback,
@@ -1232,14 +1231,13 @@ bus_ibus_impl_ibus_message (BusIBusImpl     *ibus,
         { IBUS_INTERFACE_IBUS, "ListActiveEngines",     _ibus_list_active_engines },
         { IBUS_INTERFACE_IBUS, "Exit",                  _ibus_exit },
         { IBUS_INTERFACE_IBUS, "Ping",                  _ibus_ping },
-        { NULL, NULL, NULL }
     };
 
     ibus_message_set_sender (message, bus_connection_get_unique_name (connection));
     ibus_message_set_destination (message, DBUS_SERVICE_DBUS);
 
     if (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
-        for (i = 0; handlers[i].interface != NULL; i++) {
+        for (i = 0; G_N_ELEMENTS (handlers); i++) {
             if (ibus_message_is_method_call (message,
                                              handlers[i].interface,
                                              handlers[i].name)) {
index aa75d1e..8e23a93 100644 (file)
@@ -1117,14 +1117,12 @@ bus_input_context_ibus_message (BusInputContext *context,
         { IBUS_INTERFACE_INPUT_CONTEXT, "SetEngine",         _ic_set_engine },
         { IBUS_INTERFACE_INPUT_CONTEXT, "GetEngine",         _ic_get_engine },
         { IBUS_INTERFACE_INPUT_CONTEXT, "Destroy",           _ic_destroy },
-
-        { NULL, NULL, NULL }
     };
 
     ibus_message_set_sender (message, bus_connection_get_unique_name (connection));
     ibus_message_set_destination (message, DBUS_SERVICE_DBUS);
 
-    for (i = 0; handlers[i].interface != NULL; i++) {
+    for (i = 0; G_N_ELEMENTS (handlers); i++) {
         if (ibus_message_is_method_call (message,
                                          handlers[i].interface,
                                          handlers[i].name)) {
index 1ba5761..ab17fb3 100644 (file)
@@ -61,13 +61,6 @@ static void     bus_panel_proxy_property_activate
 
 static IBusProxyClass  *parent_class = NULL;
 
-struct _SignalCallbackTable {
-    gchar *name;
-    GCallback callback;
-} ;
-
-static const struct _SignalCallbackTable __signals[];
-
 GType
 bus_panel_proxy_get_type (void)
 {
@@ -334,66 +327,6 @@ failed:
 }
 
 
-void
-bus_panel_proxy_focus_in (BusPanelProxy     *panel,
-                          BusInputContext   *context)
-{
-    g_assert (BUS_IS_PANEL_PROXY (panel));
-    g_assert (BUS_IS_INPUT_CONTEXT (context));
-
-    if (panel->focused_context == context)
-        return;
-
-    if (panel->focused_context != NULL)
-        bus_panel_proxy_focus_out (panel, panel->focused_context);
-
-    g_object_ref (context);
-    panel->focused_context = context;
-
-    const gchar *path = ibus_service_get_path ((IBusService *)context);
-
-    ibus_proxy_call ((IBusProxy *) panel,
-                     "FocusIn",
-                     IBUS_TYPE_OBJECT_PATH, &path,
-                     G_TYPE_INVALID);
-
-    /* install signal handlers */
-    gint i;
-    for (i = 0; __signals[i].name != NULL; i++) {
-        g_signal_connect (context,
-                          __signals[i].name,
-                          __signals[i].callback,
-                          panel);
-    }
-}
-
-void
-bus_panel_proxy_focus_out (BusPanelProxy    *panel,
-                           BusInputContext  *context)
-{
-    g_assert (BUS_IS_PANEL_PROXY (panel));
-    g_assert (BUS_IS_INPUT_CONTEXT (context));
-
-    g_assert (panel->focused_context == context);
-
-    /* uninstall signal handlers */
-    gint i;
-    for (i = 0; __signals[i].name != NULL; i++) {
-        g_signal_handlers_disconnect_by_func (context,
-                                              __signals[i].callback,
-                                              panel);
-    }
-
-    const gchar *path = ibus_service_get_path ((IBusService *)context);
-
-    ibus_proxy_call ((IBusProxy *) panel,
-                     "FocusOut",
-                     IBUS_TYPE_OBJECT_PATH, &path,
-                     G_TYPE_INVALID);
-
-    g_object_unref (panel->focused_context);
-    panel->focused_context = NULL;
-}
 
 void
 bus_panel_proxy_set_cursor_location (BusPanelProxy *panel,
@@ -690,8 +623,10 @@ DEFINE_FUNCTION (state_changed)
 
 #undef DEFINE_FUNCTION
 
-static const struct _SignalCallbackTable
-__signals[] = {
+static const struct _SignalCallbackTable {
+    gchar *name;
+    GCallback callback;
+} __signals[] = {
     { "set-cursor-location",        G_CALLBACK (_context_set_cursor_location_cb) },
 
     { "update-preedit-text",        G_CALLBACK (_context_update_preedit_text_cb) },
@@ -718,6 +653,66 @@ __signals[] = {
     { "factory-changed",            G_CALLBACK (_context_state_changed_cb) },
 
     //    { "destroy",                    G_CALLBACK (_context_destroy_cb) },
-    { NULL, NULL}
 };
 
+void
+bus_panel_proxy_focus_in (BusPanelProxy     *panel,
+                          BusInputContext   *context)
+{
+    g_assert (BUS_IS_PANEL_PROXY (panel));
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
+
+    if (panel->focused_context == context)
+        return;
+
+    if (panel->focused_context != NULL)
+        bus_panel_proxy_focus_out (panel, panel->focused_context);
+
+    g_object_ref (context);
+    panel->focused_context = context;
+
+    const gchar *path = ibus_service_get_path ((IBusService *)context);
+
+    ibus_proxy_call ((IBusProxy *) panel,
+                     "FocusIn",
+                     IBUS_TYPE_OBJECT_PATH, &path,
+                     G_TYPE_INVALID);
+
+    /* install signal handlers */
+    gint i;
+    for (i = 0; G_N_ELEMENTS (__signals); i++) {
+        g_signal_connect (context,
+                          __signals[i].name,
+                          __signals[i].callback,
+                          panel);
+    }
+}
+
+void
+bus_panel_proxy_focus_out (BusPanelProxy    *panel,
+                           BusInputContext  *context)
+{
+    g_assert (BUS_IS_PANEL_PROXY (panel));
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
+
+    g_assert (panel->focused_context == context);
+
+    /* uninstall signal handlers */
+    gint i;
+    for (i = 0; G_N_ELEMENTS (__signals); i++) {
+        g_signal_handlers_disconnect_by_func (context,
+                                              __signals[i].callback,
+                                              panel);
+    }
+
+    const gchar *path = ibus_service_get_path ((IBusService *)context);
+
+    ibus_proxy_call ((IBusProxy *) panel,
+                     "FocusOut",
+                     IBUS_TYPE_OBJECT_PATH, &path,
+                     G_TYPE_INVALID);
+
+    g_object_unref (panel->focused_context);
+    panel->focused_context = NULL;
+}
+