[maemo-commits] [maemo-commits] r14668 - in projects/haf/trunk/hildon-input-method: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Oct 29 14:51:48 EET 2007
Author: tjunnone
Date: 2007-10-29 14:51:46 +0200 (Mon, 29 Oct 2007)
New Revision: 14668

Modified:
   projects/haf/trunk/hildon-input-method/ChangeLog
   projects/haf/trunk/hildon-input-method/src/hildon-im-main.c
Log:
2007-10-29  Tomas Junnonen  <tomas.junnonen at nokia.com>

        * src/hildon-im-main.c: Added dbus message filter to catch
          the locale change signal during the first boot wizard.
          Fixes NB#74315.


Modified: projects/haf/trunk/hildon-input-method/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-input-method/ChangeLog	2007-10-29 12:24:05 UTC (rev 14667)
+++ projects/haf/trunk/hildon-input-method/ChangeLog	2007-10-29 12:51:46 UTC (rev 14668)
@@ -1,3 +1,9 @@
+2007-10-29  Tomas Junnonen  <tomas.junnonen at nokia.com>
+
+	* src/hildon-im-main.c: Added dbus message filter to catch
+	  the locale change signal during the first boot wizard.
+	  Fixes NB#74315.
+
 2007-10-25  Tomas Junnonen  <tomas.junnonen at nokia.com>
 
 	* src/hildon-im-plugin.[c,h]:

Modified: projects/haf/trunk/hildon-input-method/src/hildon-im-main.c
===================================================================
--- projects/haf/trunk/hildon-input-method/src/hildon-im-main.c	2007-10-29 12:24:05 UTC (rev 14667)
+++ projects/haf/trunk/hildon-input-method/src/hildon-im-main.c	2007-10-29 12:51:46 UTC (rev 14668)
@@ -36,6 +36,7 @@
 #endif
 
 #include "osso-log.h"
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -45,7 +46,12 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <dbus/dbus.h>
 
+#define LOCALE_IFACE "com.nokia.LocaleChangeNotification"
+#define LOCALE_SIGNAL "locale_changed"
+#define LOCALE_RULE "type='signal',interface='" LOCALE_IFACE "',member='" LOCALE_SIGNAL "'"
+
 GtkWidget *keyboard = NULL;
 
 static void
@@ -60,10 +66,48 @@
   reload_plugins (HILDON_IM_UI(keyboard));
 }
 
+static DBusHandlerResult
+dbus_msg_handler (DBusConnection *connection,
+                  DBusMessage *msg,
+                  void *user_data)
+{
+  const char *interface = dbus_message_get_interface(msg);
+  const char *method = dbus_message_get_member(msg);
+  const char *sender = dbus_message_get_sender(msg);
+  gint message_type = -1;
+    
+  if (!(message_type = dbus_message_get_type(msg)) ||
+      !sender || !interface || !method)
+    return FALSE;
+  
+  if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
+  {
+    if (strcmp(interface, LOCALE_IFACE) == 0 &&
+        strcmp(method, LOCALE_SIGNAL) == 0)
+    {
+      char *new_locale = NULL;
+
+      dbus_message_get_args(msg, NULL,
+			    DBUS_TYPE_STRING, &new_locale,
+			    DBUS_TYPE_INVALID);
+      if (new_locale)
+      {
+        /* Note: This will only affect UI elements created
+           from here on. Existing UI will not be localized. */
+        setlocale(LC_ALL, new_locale);
+      }
+    }
+  }
+  
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 int
 main(int argc, char *argv[])
 {
   struct sigaction sv;
+  DBusConnection *dbus_connection = NULL;
+  DBusError dbus_error_code;
 
   if (!g_thread_supported ()) g_thread_init (NULL);
   gtk_init(&argc, &argv);
@@ -80,6 +124,33 @@
 
   g_signal_connect(keyboard, "destroy", gtk_main_quit, NULL);
 
+  dbus_error_init(&dbus_error_code);
+  /* Establish DBus connection */
+  if (!(dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error_code)))
+  {
+    g_warning("DBUS connection failed: %s\n", dbus_error_code.message);
+    dbus_error_free (&dbus_error_code);
+  }
+
+  if (dbus_connection)
+  {
+    dbus_bus_add_match(dbus_connection, LOCALE_RULE, &dbus_error_code);
+    if (dbus_error_is_set(&dbus_error_code))
+    {
+      g_warning("Unable to add match for locale change: %s\n",
+                dbus_error_code.message);
+      dbus_error_free(&dbus_error_code);
+    }
+  }
+  
+  if (!dbus_connection_add_filter(dbus_connection,
+                                  dbus_msg_handler,
+                                  NULL, NULL))
+  {
+    g_warning("Failed to add filter: %s\n", dbus_error_code.message);
+    dbus_error_free(&dbus_error_code);
+  }
+
   /* gtk_main_quit at SIGTERM */
   sigemptyset(&sv.sa_mask);
   sv.sa_flags = 0;


More information about the maemo-commits mailing list