[tracker/collation-gconf-locale] libtracker-data: enable locale retrieval with tracker_locale_get()
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/collation-gconf-locale] libtracker-data: enable locale retrieval with tracker_locale_get()
- Date: Wed, 1 Sep 2010 18:48:11 +0000 (UTC)
commit b93638c276b3d3c902609a0a6d4b2af14c7c1294
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 ecde014..b22a919 100644
--- a/src/libtracker-data/tracker-collation.c
+++ b/src/libtracker-data/tracker-collation.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <string.h>
+#include <libtracker-common/tracker-locale.h>
#include "tracker-collation.h"
/* If defined, will dump additional traces */
@@ -95,7 +96,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);
@@ -110,6 +114,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 912e693..4d37195 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3128,6 +3128,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 27153fe..82bdef0 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -505,16 +505,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,
@@ -648,6 +639,25 @@ tracker_db_interface_sqlite_fts_init (TrackerDBInterface *db_interface,
#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 a923a08..585ef77 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -36,6 +36,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);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index a201937..5b87e2e 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>
@@ -548,7 +549,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 ();
@@ -566,20 +567,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]