[tracker/collation-gconf-locale: 9/20] tracker-store: Recreate indexes when locale change detected



commit 9a8c4f9ddfc86be165f4a306cc33234c92403ab1
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Oct 28 16:11:21 2010 +0200

    tracker-store: Recreate indexes when locale change detected

 src/libtracker-data/tracker-data-manager.c |   24 +++++++++++++
 src/libtracker-data/tracker-data-manager.h |    2 +
 src/tracker-store/tracker-main.c           |   49 ++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 123d2e1..46404d8 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3073,6 +3073,30 @@ tracker_data_manager_recreate_indexes (void)
 }
 
 gboolean
+tracker_data_manager_reload (TrackerBusyCallback busy_callback,
+                             gpointer            busy_user_data)
+{
+	TrackerDBManagerFlags flags;
+	guint select_cache_size;
+	guint update_cache_size;
+	gboolean is_first;
+
+	/* Shutdown data manager... */
+	flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
+	tracker_data_manager_shutdown ();
+
+	return tracker_data_manager_init (flags,
+	                                  NULL,
+	                                  &is_first,
+	                                  TRUE,
+	                                  select_cache_size,
+	                                  update_cache_size,
+	                                  busy_callback,
+	                                  busy_user_data,
+	                                  "Reloading data manager");
+}
+
+gboolean
 tracker_data_manager_init (TrackerDBManagerFlags  flags,
                            const gchar          **test_schemas,
                            gboolean              *first_time,
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 49b811a..beb6daf 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -55,6 +55,8 @@ gboolean tracker_data_manager_init                   (TrackerDBManagerFlags  fla
                                                       gpointer               busy_user_data,
                                                       const gchar           *busy_status);
 void     tracker_data_manager_shutdown               (void);
+gboolean tracker_data_manager_reload                 (TrackerBusyCallback    busy_callback,
+                                                      gpointer               busy_user_data);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index b9d2801..3972a6b 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -41,6 +41,7 @@
 #include <libtracker-common/tracker-ioprio.h>
 #include <libtracker-common/tracker-log.h>
 #include <libtracker-common/tracker-ontologies.h>
+#include <libtracker-common/tracker-locale.h>
 
 #include <libtracker-data/tracker-data-manager.h>
 #include <libtracker-data/tracker-data-backup.h>
@@ -83,6 +84,7 @@ typedef struct {
 
 /* Private */
 static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
+static gpointer locale_notification_id;
 
 /* Private command line parameters */
 static gboolean version;
@@ -261,6 +263,48 @@ shutdown_directories (void)
 	}
 }
 
+static void
+tracker_locale_notify_cb (TrackerLocaleID id,
+                          gpointer        user_data)
+{
+	TrackerStatus *notifier;
+	TrackerBusyCallback busy_callback;
+	gpointer busy_user_data;
+
+	tracker_store_set_active (FALSE);
+
+	notifier = TRACKER_STATUS (tracker_dbus_get_object (TRACKER_TYPE_STATUS));
+
+	busy_callback = tracker_status_get_callback (notifier,
+	                                             &busy_user_data);
+
+	tracker_data_manager_reload (NULL, NULL);
+
+	tracker_store_set_active (TRUE);
+}
+
+static void
+initialize_locale_subscription (void)
+{
+	gchar *collation_locale;
+
+	collation_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
+
+	g_debug ("Initial collation locale is '%s', subscribing for updates...",
+	         collation_locale);
+
+	locale_notification_id = tracker_locale_notify_add (TRACKER_LOCALE_COLLATE,
+	                                                    tracker_locale_notify_cb,
+	                                                    NULL,
+	                                                    NULL);
+}
+
+static void
+shutdown_locale_subscription (void)
+{
+	tracker_locale_notify_remove (locale_notification_id);
+}
+
 static GStrv
 get_notifiable_classes (void)
 {
@@ -516,6 +560,9 @@ main (gint argc, gchar *argv[])
 		goto shutdown;
 	}
 
+	/* Setup subscription to get notified of locale changes */
+	initialize_locale_subscription ();
+
 	tracker_dbus_register_prepare_class_signal ();
 
 	tracker_events_init (get_notifiable_classes);
@@ -552,6 +599,8 @@ main (gint argc, gchar *argv[])
 	tracker_writeback_shutdown ();
 	tracker_events_shutdown ();
 
+	shutdown_locale_subscription ();
+
 	tracker_dbus_shutdown ();
 	tracker_data_manager_shutdown ();
 	tracker_log_shutdown ();



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