[tracker/tracker-0.10] libtracker-common: Read meegotouch locales from GConf over DBus directly



commit 86e715865c1007fdd43a09a6a83614639946f3ab
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Apr 4 12:21:04 2011 +0200

    libtracker-common: Read meegotouch locales from GConf over DBus directly
    
    Fixes NB#240272.

 src/libtracker-common/Makefile.am                |    5 +
 src/libtracker-common/tracker-locale-gconfdbus.c |  172 ++++++++++++++++++++++
 src/libtracker-common/tracker-locale-gconfdbus.h |   38 +++++
 src/libtracker-common/tracker-locale.c           |    8 +
 4 files changed, 223 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index eeaabe3..897a4ac 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -63,6 +63,11 @@ libtracker_common_la_SOURCES += tracker-language.c
 noinst_HEADERS += tracker-language.h
 endif
 
+if HAVE_MAEMO
+libtracker_common_la_SOURCES += tracker-locale-gconfdbus.c
+noinst_HEADERS += tracker-locale-gconfdbus.h
+endif
+
 libtracker_common_la_LDFLAGS = \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
diff --git a/src/libtracker-common/tracker-locale-gconfdbus.c b/src/libtracker-common/tracker-locale-gconfdbus.c
new file mode 100644
index 0000000..538d66d
--- /dev/null
+++ b/src/libtracker-common/tracker-locale-gconfdbus.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2010 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "tracker-locale-gconfdbus.h"
+
+/* This helps with testing, change all the names in gconf-dbus and then you
+ * can run it in parallel with an upstream gconf-d of the GNOME platform */
+#define GCONF_DBUS_NAME "GConf"
+
+#define GCONF_DBUS_SERVICE                    "org.gnome." GCONF_DBUS_NAME
+#define GCONF_DBUS_SERVER_INTERFACE           "org.gnome." GCONF_DBUS_NAME ".Server"
+#define GCONF_DBUS_DATABASE_INTERFACE         "org.gnome." GCONF_DBUS_NAME ".Database"
+#define GCONF_DBUS_SERVER_OBJECT              "/org/gnome/" GCONF_DBUS_NAME "/Server"
+#define GCONF_DBUS_CLIENT_OBJECT              "/org/gnome/" GCONF_DBUS_NAME "/Client"
+#define GCONF_DBUS_CLIENT_INTERFACE           "org.gnome." GCONF_DBUS_NAME ".Client"
+
+/* Base dir for all gconf locale values */
+#define MEEGOTOUCH_LOCALE_DIR                 "/meegotouch/i18n"
+
+#define TRACKER_DISABLE_MEEGOTOUCH_LOCALE_ENV "TRACKER_DISABLE_MEEGOTOUCH_LOCALE"
+
+static gchar*gconf_dbus_default_db = NULL;
+static GDBusConnection *connection = NULL;
+
+/* gconf keys for tracker locales, as defined in:
+ * http://apidocs.meego.com/1.0/mtf/i18n.html
+ */
+static const gchar *gconf_locales[TRACKER_LOCALE_LAST] = {
+	MEEGOTOUCH_LOCALE_DIR "/language",
+	MEEGOTOUCH_LOCALE_DIR "/lc_time",
+	MEEGOTOUCH_LOCALE_DIR "/lc_collate",
+	MEEGOTOUCH_LOCALE_DIR "/lc_numeric",
+	MEEGOTOUCH_LOCALE_DIR "/lc_monetary"
+};
+
+static gchar *
+get_value_from_config (const gchar *key_in)
+{
+	const gchar *locale = setlocale (LC_CTYPE, NULL);
+	const gchar *key, *value, *schema;
+	gchar *val = NULL;
+	gboolean is_set, is_default, is_writable;
+	gint type;
+	GError *error = NULL;
+	GVariant *reply;
+
+	reply = g_dbus_connection_call_sync (connection,
+	                                     GCONF_DBUS_SERVICE,
+	                                     gconf_dbus_default_db,
+	                                     GCONF_DBUS_DATABASE_INTERFACE,
+	                                     "LookupExtended",
+	                                     g_variant_new ("(ssb)", key_in, locale, TRUE),
+	                                     NULL,
+	                                     G_DBUS_CALL_FLAGS_NONE,
+	                                     -1,
+	                                     NULL,
+	                                     &error);
+
+	if (error) {
+		g_variant_unref (reply);
+		g_critical ("%s", error->message);
+		g_clear_error (&error);
+
+		return NULL;
+	}
+
+	if (g_variant_is_of_type (reply, G_VARIANT_TYPE ("((s(is)bsbb))"))) {
+		g_variant_get (reply, "((&s(i&s)b&sbb))",
+		               &key, &type, &value,
+		               &is_set, &schema,
+		               &is_default, &is_writable,
+		               NULL);
+
+		val = g_strdup (value);
+	}
+
+	g_variant_unref (reply);
+
+	return val;
+}
+
+void
+tracker_locale_gconfdbus_init (void)
+{
+	if (!g_getenv (TRACKER_DISABLE_MEEGOTOUCH_LOCALE_ENV)) {
+		guint i;
+		GError *error = NULL;
+		GVariant *reply;
+
+		g_message ("Retrieving locale from GConf is ENABLED");
+
+		connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+		if (error) {
+			g_critical ("%s", error->message);
+			g_clear_error (&error);
+			return;
+		}
+
+		reply = g_dbus_connection_call_sync (connection,
+		                                     GCONF_DBUS_SERVICE,
+		                                     GCONF_DBUS_SERVER_OBJECT,
+		                                     GCONF_DBUS_SERVER_INTERFACE,
+		                                     "GetDefaultDatabase",
+		                                     NULL,
+		                                     NULL,
+		                                     G_DBUS_CALL_FLAGS_NONE,
+		                                     -1,
+		                                     NULL,
+		                                     &error);
+
+
+		if (error) {
+			g_critical ("%s", error->message);
+			g_clear_error (&error);
+			return;
+		}
+
+		g_variant_get (reply, "(s)", &gconf_dbus_default_db, NULL);
+
+		g_variant_unref (reply);
+
+		/* And initialize all */
+		for (i = 0; i < TRACKER_LOCALE_LAST; i++) {
+			gchar *str;
+
+			str = get_value_from_config (gconf_locales[i]);
+			if (str) {
+				tracker_locale_set (i, str);
+				g_free (str);
+			}
+		}
+	}
+}
+
+void
+tracker_locale_gconfdbus_shutdown (void)
+{
+	g_free (gconf_dbus_default_db);
+	gconf_dbus_default_db = NULL;
+
+	if (connection) {
+		g_object_unref (connection);
+		connection = NULL;
+	}
+}
+
diff --git a/src/libtracker-common/tracker-locale-gconfdbus.h b/src/libtracker-common/tracker-locale-gconfdbus.h
new file mode 100644
index 0000000..0ca2691
--- /dev/null
+++ b/src/libtracker-common/tracker-locale-gconfdbus.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_COMMON_LOCALE_GCONFDBUS_H__
+#define __LIBTRACKER_COMMON_LOCALE_GCONFDBUS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-common/tracker-common.h> must be included directly."
+#endif
+
+#include "tracker-locale.h"
+
+void tracker_locale_gconfdbus_init     (void);
+void tracker_locale_gconfdbus_shutdown (void);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_COMMON_LOCALE_GCONFDBUS_H__ */
diff --git a/src/libtracker-common/tracker-locale.c b/src/libtracker-common/tracker-locale.c
index 5fa9c4e..82058aa 100644
--- a/src/libtracker-common/tracker-locale.c
+++ b/src/libtracker-common/tracker-locale.c
@@ -26,6 +26,10 @@
 
 #include "tracker-locale.h"
 
+#ifdef HAVE_MAEMO
+#include "tracker-locale-gconfdbus.h"
+#endif /* HAVE_MAEMO */
+
 /* Current locales in use. They will be stored in heap and available throughout
  * the whole program execution, so will be reported as still reachable by Valgrind.
  */
@@ -103,6 +107,10 @@ locale_init (void)
 {
 	guint i;
 
+#ifdef HAVE_MAEMO
+	tracker_locale_gconfdbus_init ();
+#endif /* HAVE_MAEMO */
+
 	/* Initialize those not retrieved from gconf, or if not in maemo */
 	for (i = 0; i < TRACKER_LOCALE_LAST; i++) {
 		if (!current_locales[i]) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]