[tracker/collation-gconf-locale: 2/13] 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: 2/13] libtracker-data: Enable locale retrieval with tracker_locale_get()
- Date: Mon, 22 Nov 2010 20:18:45 +0000 (UTC)
commit efca8e3c3dc9d1c2af62f314cc975396881707bb
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 | 17 ++++++-
src/libtracker-data/tracker-data-manager.c | 3 +
src/libtracker-data/tracker-db-interface-sqlite.c | 46 +++++++++++++--------
src/libtracker-data/tracker-db-interface-sqlite.h | 1 +
src/libtracker-data/tracker-db-manager.c | 16 +++++---
5 files changed, 56 insertions(+), 27 deletions(-)
---
diff --git a/src/libtracker-data/tracker-collation.c b/src/libtracker-data/tracker-collation.c
index 830aece..e0ff2d0 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 */
@@ -48,9 +49,12 @@
gpointer
tracker_collation_init (void)
{
- const gchar *locale = setlocale (LC_COLLATE, NULL);
+ gchar *locale;
+ /* Get locale! */
+ locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
g_debug ("[libunistring collation] Initializing collator for locale '%s'", locale);
+ g_free (locale);
/* Nothing to do */
return NULL;
}
@@ -98,7 +102,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 +120,7 @@ tracker_collation_init (void)
u_errorName (status));
}
}
+ g_free (locale);
return collator;
}
@@ -183,9 +191,12 @@ tracker_collation_utf8 (gpointer collator,
gpointer
tracker_collation_init (void)
{
- const gchar *locale = setlocale (LC_COLLATE, NULL);
+ gchar *locale;
+ /* Get locale! */
+ locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
g_debug ("[GLib collation] Initializing collator for locale '%s'", locale);
+ g_free (locale);
/* Nothing to do */
return NULL;
}
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 98b1ca3..0d2f9ff 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3741,6 +3741,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..9d7c5ab 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,
@@ -603,8 +594,8 @@ tracker_db_interface_sqlite_constructor (GType type,
TrackerDBInterface *db_iface;
object = (* G_OBJECT_CLASS (tracker_db_interface_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
+ n_construct_properties,
+ construct_params);
db_iface = TRACKER_DB_INTERFACE (object);
open_database (db_iface);
@@ -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)
{
@@ -901,12 +911,12 @@ tracker_db_interface_create_statement (TrackerDBInterface *db_interfac
full_query = g_strdup_vprintf (query, args);
va_end (args);
- /* There are three kinds of queries:
- * a) Cached queries: SELECT and UPDATE ones (cache_type)
- * b) Non-Cached queries: NONE ones (cache_type)
- * c) Forced Non-Cached: in case of a stmt being already in use, we can't
- * reuse it (you can't use two different loops on a sqlite3_stmt, of
- * course). This happens with recursive uses of a cursor, for example */
+ /* There are three kinds of queries:
+ * a) Cached queries: SELECT and UPDATE ones (cache_type)
+ * b) Non-Cached queries: NONE ones (cache_type)
+ * c) Forced Non-Cached: in case of a stmt being already in use, we can't
+ * reuse it (you can't use two different loops on a sqlite3_stmt, of
+ * course). This happens with recursive uses of a cursor, for example */
if (cache_type != TRACKER_DB_STATEMENT_CACHE_TYPE_NONE) {
stmt = g_hash_table_lookup (db_interface->dynamic_statements, full_query);
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 6d3b900..93d6b6a 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>
@@ -584,7 +585,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 ();
@@ -602,20 +603,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
@@ -659,6 +660,7 @@ static void
db_recreate_all (void)
{
guint i;
+ gchar *locale;
/* We call an internal version of this function here
* because at the time 'initialized' = FALSE and that
@@ -684,8 +686,10 @@ db_recreate_all (void)
dbs[i].iface = NULL;
}
+ locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
/* Initialize locale file */
- db_set_locale (setlocale (LC_COLLATE, NULL));
+ db_set_locale (locale);
+ g_free (locale);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]