[tracker/collation-gconf-locale: 4/13] libtracker-data: Reset collator in connection when locale change detected
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/collation-gconf-locale: 4/13] libtracker-data: Reset collator in connection when locale change detected
- Date: Mon, 22 Nov 2010 20:18:55 +0000 (UTC)
commit 3982a9425979df673e6073146dcbce733e374816
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu Oct 28 17:28:52 2010 +0200
libtracker-data: Reset collator in connection when locale change detected
src/libtracker-data/tracker-data-manager.c | 1 +
src/libtracker-data/tracker-db-interface-sqlite.c | 62 +++++++++++++++++++--
2 files changed, 58 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c29b9c8..1140023 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3205,6 +3205,7 @@ tracker_data_manager_reload (TrackerBusyCallback busy_callback,
flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
tracker_data_manager_shutdown ();
+ /* And initialize it again, this actually triggers index recreation. */
return tracker_data_manager_init (flags,
NULL,
&is_first,
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 9d7c5ab..21abb21 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -57,7 +57,10 @@ struct TrackerDBInterface {
GSList *function_data;
+ /* Collation and locale change */
gpointer collator;
+ gpointer locale_notification_id;
+ gboolean collator_reset_requested;
guint ro : 1;
#if HAVE_TRACKER_FTS
@@ -85,6 +88,7 @@ struct TrackerDBCursor {
TrackerSparqlCursor parent_instance;
sqlite3_stmt *stmt;
TrackerDBStatement *ref_stmt;
+ gboolean started;
gboolean finished;
TrackerPropertyType *types;
gint n_types;
@@ -527,6 +531,16 @@ check_interrupt (void *user_data)
}
static void
+tracker_locale_notify_cb (TrackerLocaleID id,
+ gpointer user_data)
+{
+ TrackerDBInterface *db_interface = user_data;
+
+ /* Request a collator reset. */
+ db_interface->collator_reset_requested = TRUE;
+}
+
+static void
open_database (TrackerDBInterface *db_interface)
{
int mode;
@@ -546,9 +560,12 @@ open_database (TrackerDBInterface *db_interface)
}
/* Set our unicode collation function */
- if (!db_interface->collator) {
- tracker_db_interface_sqlite_reset_collator (db_interface);
- }
+ tracker_db_interface_sqlite_reset_collator (db_interface);
+ /* And register for updates on locale changes */
+ db_interface->locale_notification_id = tracker_locale_notify_add (TRACKER_LOCALE_COLLATE,
+ tracker_locale_notify_cb,
+ db_interface,
+ NULL);
sqlite3_progress_handler (db_interface->db, 100,
check_interrupt, db_interface);
@@ -730,6 +747,8 @@ tracker_db_interface_sqlite_reset_collator (TrackerDBInterface *db_interface)
}
}
+
+
static void
tracker_db_interface_sqlite_finalize (GObject *object)
{
@@ -744,6 +763,7 @@ tracker_db_interface_sqlite_finalize (GObject *object)
g_free (db_interface->filename);
g_free (db_interface->busy_status);
+ tracker_locale_notify_remove (db_interface->locale_notification_id);
tracker_collation_shutdown (db_interface->collator);
G_OBJECT_CLASS (tracker_db_interface_parent_class)->finalize (object);
@@ -1072,6 +1092,13 @@ create_result_set_from_stmt (TrackerDBInterface *interface,
columns = sqlite3_column_count (stmt);
result = SQLITE_OK;
+ /* Statement is going to start, check if we got a request to reset the
+ * collator, and if so, do it. */
+ if (interface->collator_reset_requested) {
+ tracker_db_interface_sqlite_reset_collator (interface);
+ interface->collator_reset_requested = FALSE;
+ }
+
while (result == SQLITE_OK ||
result == SQLITE_ROW) {
@@ -1102,8 +1129,14 @@ create_result_set_from_stmt (TrackerDBInterface *interface,
}
}
- if (result != SQLITE_DONE) {
-
+ if (result == SQLITE_DONE) {
+ /* Statement finished, check if we got a request to reset the
+ * collator, and if so, do it. */
+ if (interface->collator_reset_requested) {
+ tracker_db_interface_sqlite_reset_collator (interface);
+ interface->collator_reset_requested = FALSE;
+ }
+ } else {
/* This is rather fatal */
if (sqlite3_errcode (interface->db) == SQLITE_IOERR ||
sqlite3_errcode (interface->db) == SQLITE_CORRUPT ||
@@ -1500,6 +1533,17 @@ db_cursor_iter_next (TrackerDBCursor *cursor,
TrackerDBStatement *stmt = cursor->ref_stmt;
TrackerDBInterface *iface = stmt->db_interface;
+ if (!cursor->started) {
+ /* Statement is going to start, check if we got a request to reset the
+ * collator, and if so, do it. */
+ if (iface->collator_reset_requested) {
+ tracker_db_interface_sqlite_reset_collator (iface);
+ iface->collator_reset_requested = FALSE;
+ }
+
+ cursor->started = TRUE;
+ }
+
if (!cursor->finished) {
guint result;
@@ -1529,6 +1573,14 @@ db_cursor_iter_next (TrackerDBCursor *cursor,
cursor->finished = (result != SQLITE_ROW);
}
+ /* Statement finished, check if we got a request to reset the
+ * collator, and if so, do it. */
+ if (cursor->finished &&
+ iface->collator_reset_requested) {
+ tracker_db_interface_sqlite_reset_collator (iface);
+ iface->collator_reset_requested = FALSE;
+ }
+
return (!cursor->finished);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]