Commit 7e17ba8a authored by Jürg Billeter's avatar Jürg Billeter Committed by Martyn Russell

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.
parent 9ceea9ac
......@@ -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;
}
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment