[tracker/collation-gconf-locale: 8/11] tracker-store: Moved locale change subscription stuff to separate files



commit a1174a89408640ea290426e966ac73c87b301030
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Thu Nov 4 16:29:45 2010 +0200

    tracker-store: Moved locale change subscription stuff to separate files

 src/tracker-store/Makefile.am             |    4 +-
 src/tracker-store/tracker-locale-change.c |  140 +++++++++++++++++++++++++++++
 src/tracker-store/tracker-locale-change.h |   32 +++++++
 src/tracker-store/tracker-main.c          |  103 +--------------------
 4 files changed, 178 insertions(+), 101 deletions(-)
---
diff --git a/src/tracker-store/Makefile.am b/src/tracker-store/Makefile.am
index c3ad7b5..b113296 100644
--- a/src/tracker-store/Makefile.am
+++ b/src/tracker-store/Makefile.am
@@ -38,7 +38,9 @@ tracker_store_SOURCES =                                \
 	tracker-status.c                               \
 	tracker-status.h                               \
 	tracker-steroids.c                             \
-	tracker-steroids.h
+	tracker-steroids.h                             \
+	tracker-locale-change.h                        \
+	tracker-locale-change.c
 
 tracker_store_LDADD =                                  \
 	$(top_builddir)/src/libtracker-data/libtracker-data.la \
diff --git a/src/tracker-store/tracker-locale-change.c b/src/tracker-store/tracker-locale-change.c
new file mode 100644
index 0000000..cbecbd4
--- /dev/null
+++ b/src/tracker-store/tracker-locale-change.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2010 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+
+#include <libtracker-common/tracker-locale.h>
+#include <libtracker-data/tracker-data-manager.h>
+#include <libtracker-data/tracker-db-dbus.h>
+
+#include "tracker-store.h"
+#include "tracker-dbus.h"
+#include "tracker-resources.h"
+#include "tracker-events.h"
+#include "tracker-locale-change.h"
+
+typedef struct {
+	gpointer resources;
+	TrackerNotifyClassGetter getter;
+} TrackerLocaleChangeContext;
+
+/* Private */
+static gpointer locale_notification_id;
+static gboolean locale_change_notified;
+
+static void
+tracker_locale_change_process_cb (gpointer user_data)
+{
+	TrackerStatus *notifier;
+	TrackerBusyCallback busy_callback;
+	gpointer busy_user_data;
+	TrackerLocaleChangeContext *ctxt = user_data;
+
+	notifier = TRACKER_STATUS (tracker_dbus_get_object (TRACKER_TYPE_STATUS));
+
+	busy_callback = tracker_status_get_callback (notifier,
+	                                             &busy_user_data);
+
+	g_message ("Processing locale change...");
+	/* Reload! This will regenerate indexes with the new locale */
+	tracker_data_manager_reload (busy_callback, busy_user_data);
+
+	if (ctxt->resources) {
+		tracker_events_init (ctxt->getter);
+		tracker_resources_enable_signals (ctxt->resources);
+		g_object_unref (ctxt->resources);
+	}
+	g_free (ctxt);
+
+	tracker_store_set_active (TRUE, FALSE, NULL);
+
+	locale_change_notified = FALSE;
+}
+
+static gboolean
+tracker_locale_change_process_idle_cb (gpointer data)
+{
+	TrackerLocaleChangeContext *ctxt;
+
+	ctxt = g_new0 (TrackerLocaleChangeContext, 1);
+	ctxt->resources = tracker_dbus_get_object (TRACKER_TYPE_RESOURCES);
+	if (ctxt->resources) {
+		g_object_ref (ctxt->resources);
+		tracker_resources_disable_signals (ctxt->resources);
+		ctxt->getter = tracker_events_get_class_getter ();
+		tracker_events_shutdown ();
+	}
+
+	/* Note: Right now, the passed callback may be called instantly and not
+	 * in an idle. */
+	g_message ("Setting tracker-store as inactive...");
+	tracker_store_set_active (FALSE, tracker_locale_change_process_cb, ctxt);
+
+	return FALSE;
+}
+
+static void
+tracker_locale_notify_cb (TrackerLocaleID id,
+                          gpointer        user_data)
+{
+	if (locale_change_notified) {
+		g_message ("Locale change was already notified, not doing it again");
+	} else {
+		locale_change_notified = TRUE;
+		/* Set an idle callback to process the locale change.
+		 * NOTE: We cannot process it right here because we will be
+		 * closing and opening new connections to the DB while doing it,
+		 * and the DB connections are also part of the subscriber list
+		 * for locale changes, so we may end up waiting to acquire an
+		 * already locked mutex.
+		 */
+		g_message ("Locale change notified, preparing to rebuild indexes...");
+		g_idle_add (tracker_locale_change_process_idle_cb, NULL);
+	}
+}
+
+void
+tracker_locale_change_initialize_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);
+}
+
+void
+tracker_locale_change_shutdown_subscription (void)
+{
+	tracker_locale_notify_remove (locale_notification_id);
+}
diff --git a/src/tracker-store/tracker-locale-change.h b/src/tracker-store/tracker-locale-change.h
new file mode 100644
index 0000000..7d63001
--- /dev/null
+++ b/src/tracker-store/tracker-locale-change.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2010 Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_STORE_LOCALE_CHANGE_H__
+#define __TRACKER_STORE_LOCALE_CHANGE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+void tracker_locale_change_initialize_subscription (void);
+void tracker_locale_change_shutdown_subscription (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_STORE_LOCALE_CHANGE_H__ */
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index 97948b8..2c01733 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -57,8 +57,7 @@
 #include "tracker-backup.h"
 #include "tracker-store.h"
 #include "tracker-statistics.h"
-#include "tracker-resources.h"
-#include "tracker-events.h"
+#include "tracker-locale-change.h"
 
 #define ABOUT	  \
 	"Tracker " PACKAGE_VERSION "\n"
@@ -84,15 +83,8 @@ typedef struct {
 	gboolean shutdown;
 } TrackerMainPrivate;
 
-typedef struct {
-	gpointer resources;
-	TrackerNotifyClassGetter getter;
-} TrackerLocaleChangeContext;
-
 /* Private */
 static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
-static gpointer locale_notification_id;
-static gboolean locale_change_notified;
 
 /* Private command line parameters */
 static gboolean version;
@@ -271,95 +263,6 @@ shutdown_directories (void)
 	}
 }
 
-static void
-tracker_locale_change_process_cb (gpointer user_data)
-{
-	TrackerStatus *notifier;
-	TrackerBusyCallback busy_callback;
-	gpointer busy_user_data;
-	TrackerLocaleChangeContext *ctxt = user_data;
-
-	notifier = TRACKER_STATUS (tracker_dbus_get_object (TRACKER_TYPE_STATUS));
-
-	busy_callback = tracker_status_get_callback (notifier,
-	                                             &busy_user_data);
-
-	tracker_data_manager_reload (busy_callback, busy_user_data);
-
-	if (ctxt->resources) {
-		tracker_events_init (ctxt->getter);
-		tracker_resources_enable_signals (ctxt->resources);
-		g_object_unref (ctxt->resources);
-	}
-	g_free (ctxt);
-
-	tracker_store_set_active (TRUE, FALSE, NULL);
-
-	locale_change_notified = FALSE;
-}
-
-static gboolean
-tracker_locale_change_process_idle_cb (gpointer data)
-{
-	TrackerLocaleChangeContext *ctxt;
-
-	ctxt = g_new0 (TrackerLocaleChangeContext, 1);
-	ctxt->resources = tracker_dbus_get_object (TRACKER_TYPE_RESOURCES);
-	if (ctxt->resources) {
-		g_object_ref (ctxt->resources);
-		tracker_resources_disable_signals (ctxt->resources);
-		ctxt->getter = tracker_events_get_class_getter ();
-		tracker_events_shutdown ();
-	}
-
-	/* Note: Right now, the passed callback may be called instantly and not
-	 * in an idle. */
-	tracker_store_set_active (FALSE, tracker_locale_change_process_cb, ctxt);
-
-	return FALSE;
-}
-
-static void
-tracker_locale_notify_cb (TrackerLocaleID id,
-                          gpointer        user_data)
-{
-	if (locale_change_notified) {
-		g_message ("Locale change was already notified, not doing it again");
-	} else {
-		locale_change_notified = TRUE;
-		/* Set an idle callback to process the locale change.
-		 * NOTE: We cannot process it right here because we will be
-		 * closing and opening new connections to the DB while doing it,
-		 * and the DB connections are also part of the subscriber list
-		 * for locale changes, so we may end up waiting to acquire an
-		 * already locked mutex.
-		 */
-		g_idle_add (tracker_locale_change_process_idle_cb, NULL);
-	}
-}
-
-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)
 {
@@ -616,7 +519,7 @@ main (gint argc, gchar *argv[])
 	}
 
 	/* Setup subscription to get notified of locale changes */
-	initialize_locale_subscription ();
+	tracker_locale_change_initialize_subscription ();
 
 	tracker_dbus_register_prepare_class_signal ();
 
@@ -654,7 +557,7 @@ main (gint argc, gchar *argv[])
 	tracker_writeback_shutdown ();
 	tracker_events_shutdown ();
 
-	shutdown_locale_subscription ();
+	tracker_locale_change_shutdown_subscription ();
 
 	tracker_dbus_shutdown ();
 	tracker_data_manager_shutdown ();



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