[tracker/collation-gconf-locale: 4/17] libtracker-data: enable locale retrieval with tracker_locale_get()



commit 21d5d60462baf133f58a8797a083a5ab787ad397
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Wed Sep 1 20:47:50 2010 +0200

    libtracker-data: enable locale retrieval with tracker_locale_get()

 src/libtracker-data/tracker-collation.c           |    7 ++++-
 src/libtracker-data/tracker-data-manager.c        |    3 ++
 src/libtracker-data/tracker-db-interface-sqlite.c |   30 ++++++++++++++-------
 src/libtracker-data/tracker-db-interface-sqlite.h |    1 +
 src/libtracker-data/tracker-db-manager.c          |   11 ++++---
 5 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-data/tracker-collation.c b/src/libtracker-data/tracker-collation.c
index 830aece..ff20d80 100644
--- a/src/libtracker-data/tracker-collation.c
+++ b/src/libtracker-data/tracker-collation.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <locale.h>
 
+#include <libtracker-common/tracker-locale.h>
 #include "tracker-collation.h"
 
 /* If defined, will dump additional traces */
@@ -98,7 +99,10 @@ tracker_collation_init (void)
 {
 	UCollator *collator = NULL;
 	UErrorCode status = U_ZERO_ERROR;
-	const gchar *locale = setlocale (LC_COLLATE, NULL);
+	gchar *locale;
+
+	/* Get locale! */
+	locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
 
 	g_debug ("[ICU collation] Initializing collator for locale '%s'", locale);
 	collator = ucol_open (locale, &status);
@@ -113,6 +117,7 @@ tracker_collation_init (void)
 			            u_errorName (status));
 		}
 	}
+	g_free (locale);
 	return collator;
 }
 
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a209719..123d2e1 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3617,6 +3617,9 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 	/* If locale changed, re-create indexes */
 	if (!read_only && tracker_db_manager_locale_changed ()) {
+		/* No need to reset the collator in the db interface,
+		 * as this is only executed during startup, which should
+		 * already have the proper locale set in the collator */
 		tracker_data_manager_recreate_indexes ();
 		tracker_db_manager_set_current_locale ();
 	}
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index de7089f..ad57b08 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -547,16 +547,7 @@ open_database (TrackerDBInterface *db_interface)
 
 	/* Set our unicode collation function */
 	if (!db_interface->collator) {
-		db_interface->collator = tracker_collation_init ();
-		if (sqlite3_create_collation (db_interface->db,
-		                              TRACKER_COLLATION_NAME,
-		                              SQLITE_UTF8,
-		                              db_interface->collator,
-		                              tracker_collation_utf8) != SQLITE_OK)
-		{
-			g_critical ("Couldn't set collation function: %s",
-			            sqlite3_errmsg (db_interface->db));
-		}
+		tracker_db_interface_sqlite_reset_collator (db_interface);
 	}
 
 	sqlite3_progress_handler (db_interface->db, 100,
@@ -720,6 +711,25 @@ tracker_db_interface_sqlite_fts_update_rollback (TrackerDBInterface *db_interfac
 }
 #endif
 
+void
+tracker_db_interface_sqlite_reset_collator (TrackerDBInterface *db_interface)
+{
+	if (db_interface->collator)
+		tracker_collation_shutdown (db_interface->collator);
+
+	db_interface->collator = tracker_collation_init ();
+	/* This will overwrite any other collation set before, if any */
+	if (sqlite3_create_collation (db_interface->db,
+	                              TRACKER_COLLATION_NAME,
+	                              SQLITE_UTF8,
+	                              db_interface->collator,
+	                              tracker_collation_utf8) != SQLITE_OK)
+	{
+		g_critical ("Couldn't set collation function: %s",
+		            sqlite3_errmsg (db_interface->db));
+	}
+}
+
 static void
 tracker_db_interface_sqlite_finalize (GObject *object)
 {
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 071a1b9..3259728 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -38,6 +38,7 @@ gint64              tracker_db_interface_sqlite_get_last_insert_id     (TrackerD
 void                tracker_db_interface_sqlite_enable_shared_cache    (void);
 void                tracker_db_interface_sqlite_fts_init               (TrackerDBInterface       *interface,
                                                                         gboolean                  create);
+void                tracker_db_interface_sqlite_reset_collator         (TrackerDBInterface       *interface);
 
 #if HAVE_TRACKER_FTS
 int                 tracker_db_interface_sqlite_fts_update_init        (TrackerDBInterface       *interface,
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index f217462..68dccdc 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -36,6 +36,7 @@
 #include <libtracker-common/tracker-date-time.h>
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-locale.h>
 
 #if HAVE_TRACKER_FTS
 #include <libtracker-fts/tracker-fts.h>
@@ -566,7 +567,7 @@ tracker_db_manager_locale_changed (void)
 	gboolean changed;
 
 	/* Get current collation locale */
-	current_locale = setlocale (LC_COLLATE, NULL);
+	current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
 
 	/* Get db locale */
 	db_locale = db_get_locale ();
@@ -584,20 +585,20 @@ tracker_db_manager_locale_changed (void)
 	}
 
 	g_free (db_locale);
+	g_free (current_locale);
 	return changed;
 }
 
 void
 tracker_db_manager_set_current_locale (void)
 {
-	const gchar *current_locale;
+	gchar *current_locale;
 
 	/* Get current collation locale */
-	current_locale = setlocale (LC_COLLATE, NULL);
-
+	current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
 	g_message ("Changing db locale to: '%s'", current_locale);
-
 	db_set_locale (current_locale);
+	g_free (current_locale);
 }
 
 static void



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