[tracker: 3/4] tracker-miner-applications: Update locale file only after mining



commit c40717da36c6b1b87c8bc0e4c496fca578b08ca3
Author: JÃrg Billeter <j bitron ch>
Date:   Fri Oct 28 14:16:11 2011 +0200

    tracker-miner-applications: Update locale file only after mining
    
    This ensures that locale change gets picked up on next start if the
    miner is shut down before finishing.
    
    Fixes NB#284591.

 src/miners/fs/tracker-miner-applications-locale.c |   37 +++++++++++---------
 src/miners/fs/tracker-miner-applications-locale.h |    3 +-
 src/miners/fs/tracker-miner-applications.c        |   19 +++++++++++
 3 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-applications-locale.c b/src/miners/fs/tracker-miner-applications-locale.c
index 4c6676d..679bbd6 100644
--- a/src/miners/fs/tracker-miner-applications-locale.c
+++ b/src/miners/fs/tracker-miner-applications-locale.c
@@ -47,9 +47,11 @@ miner_applications_locale_get_filename (void)
 }
 
 static gchar *
-miner_applications_locale_get_previous (const gchar *locale_file)
+miner_applications_locale_get_previous (void)
 {
-	gchar *locale = NULL;
+	gchar *locale_file, *locale = NULL;
+
+	locale_file = miner_applications_locale_get_filename ();
 
 	if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) {
 		gchar *contents;
@@ -71,6 +73,8 @@ miner_applications_locale_get_previous (const gchar *locale_file)
 		g_message ("  Could not find locale file:'%s'", locale_file);
 	}
 
+	g_free (locale_file);
+
 	return locale;
 }
 
@@ -91,24 +95,30 @@ miner_applications_locale_get_current (void)
 	return current_locale;
 }
 
-static void
-miner_applications_locale_set_current (const gchar *locale_file,
-                                       const gchar *locale)
+void
+tracker_miner_applications_locale_set_current (void)
 {
 	GError *error = NULL;
-	gchar  *str;
+	gchar *locale_file, *locale = NULL;
+
+	locale_file = miner_applications_locale_get_filename ();
 
 	g_message ("  Creating locale file '%s'", locale_file);
 
-	str = g_strdup_printf ("%s", locale ? locale : "");
+	locale = miner_applications_locale_get_current ();
 
-	if (!g_file_set_contents (locale_file, str, -1, &error)) {
+	if (locale == NULL) {
+		locale = g_strdup ("");
+	}
+
+	if (!g_file_set_contents (locale_file, locale, -1, &error)) {
 		g_message ("  Could not set file contents, %s",
 		           error ? error->message : "no error given");
 		g_clear_error (&error);
 	}
 
-	g_free (str);
+	g_free (locale);
+	g_free (locale_file);
 }
 
 gboolean
@@ -117,23 +127,17 @@ tracker_miner_applications_locale_changed (void)
 	gchar *previous_locale;
 	gchar *current_locale;
 	gboolean changed;
-	gchar *filename;
-
-	/* Locate previous locale file */
-	filename = miner_applications_locale_get_filename ();
 
 	current_locale = miner_applications_locale_get_current ();
 
 	/* Get previous locale */
-	previous_locale = miner_applications_locale_get_previous (filename);
+	previous_locale = miner_applications_locale_get_previous ();
 
 	/* Note that having both to NULL is actually valid, they would default
 	 * to the unicode collation without locale-specific stuff. */
 	if (g_strcmp0 (previous_locale, current_locale) != 0) {
 		g_message ("Locale change detected from '%s' to '%s'...",
 		           previous_locale, current_locale);
-		/* Store the new one now */
-		miner_applications_locale_set_current (filename, current_locale);
 		changed = TRUE;
 	} else {
 		g_message ("Current and previous locales match: '%s'", previous_locale);
@@ -142,6 +146,5 @@ tracker_miner_applications_locale_changed (void)
 
 	g_free (previous_locale);
 	g_free (current_locale);
-	g_free (filename);
 	return changed;
 }
diff --git a/src/miners/fs/tracker-miner-applications-locale.h b/src/miners/fs/tracker-miner-applications-locale.h
index 1f514e2..2cf64a5 100644
--- a/src/miners/fs/tracker-miner-applications-locale.h
+++ b/src/miners/fs/tracker-miner-applications-locale.h
@@ -22,7 +22,8 @@
 
 G_BEGIN_DECLS
 
-gboolean tracker_miner_applications_locale_changed (void);
+void     tracker_miner_applications_locale_set_current (void);
+gboolean tracker_miner_applications_locale_changed     (void);
 
 G_END_DECLS
 
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index b20d6a6..cf23f80 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -185,6 +185,21 @@ tracker_locale_notify_cb (TrackerLocaleID id,
 	}
 }
 
+static void
+miner_finished_cb (TrackerMinerFS *fs,
+                   gdouble         seconds_elapsed,
+                   guint           total_directories_found,
+                   guint           total_directories_ignored,
+                   guint           total_files_found,
+                   guint           total_files_ignored,
+                   gpointer        user_data)
+{
+	/* Update locale file if necessary */
+	if (tracker_miner_applications_locale_changed ()) {
+		tracker_miner_applications_locale_set_current ();
+	}
+}
+
 static gboolean
 miner_applications_initable_init (GInitable     *initable,
                                   GCancellable  *cancellable,
@@ -203,6 +218,10 @@ miner_applications_initable_init (GInitable     *initable,
 		return FALSE;
 	}
 
+	g_signal_connect (fs, "finished",
+	                  G_CALLBACK (miner_finished_cb),
+	                  NULL);
+
 	miner_applications_add_directories (fs);
 
 #ifdef HAVE_MEEGOTOUCH



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