diff options
author | Martyn Russell <martyn@lanedo.com> | 2014-10-10 23:04:52 +0100 |
---|---|---|
committer | Martyn Russell <martyn@lanedo.com> | 2014-10-27 16:02:01 +0000 |
commit | b44c1c8245bd8dec97b4deda3461f2547704c5c8 (patch) | |
tree | d7846ae9817966cece4f18fd41aef35ee05fe706 | |
parent | b73af3b0d5e5d149301ffc188f2082f01b4ada3e (diff) | |
download | tracker-b44c1c8245bd8dec97b4deda3461f2547704c5c8.tar.gz |
libtracker-common: Removed tracker-miner-locale, only apps/userguides need it
We actually do this directly in the miners ourselves now instead, the code is
quite small and it is cleaner too now. We store a file per miner in case one
isn't run for a period of time between locale updates.
-rw-r--r-- | src/libtracker-common/Makefile.am | 6 | ||||
-rw-r--r-- | src/libtracker-common/tracker-common.h | 1 | ||||
-rw-r--r-- | src/libtracker-common/tracker-miner-locale.c | 133 | ||||
-rw-r--r-- | src/libtracker-common/tracker-miner-locale.h | 30 | ||||
-rw-r--r-- | src/libtracker-data/tracker-db-manager.c | 8 | ||||
-rw-r--r-- | src/miners/apps/tracker-miner-applications.c | 96 | ||||
-rw-r--r-- | src/miners/user-guides/tracker-miner-user-guides.c | 96 |
7 files changed, 171 insertions, 199 deletions
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am index b44a2212e..f7e0ddd55 100644 --- a/src/libtracker-common/Makefile.am +++ b/src/libtracker-common/Makefile.am @@ -27,8 +27,7 @@ libtracker_common_la_SOURCES = \ tracker-storage.c \ tracker-type-utils.c \ tracker-utils.c \ - tracker-locale.c \ - tracker-miner-locale.c + tracker-locale.c noinst_HEADERS = \ tracker-dbus.h \ @@ -44,8 +43,7 @@ noinst_HEADERS = \ tracker-storage.h \ tracker-type-utils.h \ tracker-utils.h \ - tracker-locale.h \ - tracker-miner-locale.h + tracker-locale.h if HAVE_TRACKER_FTS libtracker_common_la_SOURCES += tracker-language.c diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h index 44f329214..dd3b5cad7 100644 --- a/src/libtracker-common/tracker-common.h +++ b/src/libtracker-common/tracker-common.h @@ -41,7 +41,6 @@ #include "tracker-type-utils.h" #include "tracker-utils.h" #include "tracker-locale.h" -#include "tracker-miner-locale.h" #include "tracker-enum-types.h" #undef __LIBTRACKER_COMMON_INSIDE__ diff --git a/src/libtracker-common/tracker-miner-locale.c b/src/libtracker-common/tracker-miner-locale.c deleted file mode 100644 index a247383b7..000000000 --- a/src/libtracker-common/tracker-miner-locale.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 <string.h> - -#include "tracker-locale.h" -#include "tracker-miner-locale.h" - -/* NOTE: This applies to more miners than just the application miner, - * it's kept this way to avoid breaking things. - */ -#define TRACKER_MINER_LOCALE_FILE "miner-applications-locale.txt" - -static gchar * -miner_locale_get_filename (void) -{ - /* Locate locale file */ - return g_build_filename (g_get_user_cache_dir (), "tracker", TRACKER_MINER_LOCALE_FILE, NULL); -} - -static gchar * -miner_locale_get_previous (void) -{ - gchar *locale_file, *locale = NULL; - - locale_file = miner_locale_get_filename (); - - if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) { - gchar *contents; - - /* Check locale is correct */ - if (G_LIKELY (g_file_get_contents (locale_file, &contents, NULL, NULL))) { - if (contents && - contents[0] == '\0') { - g_critical (" Empty locale file found at '%s'", locale_file); - g_free (contents); - } else { - /* Re-use contents */ - locale = contents; - } - } else { - g_critical (" Could not get content of file '%s'", locale_file); - } - } else { - g_message (" Could not find locale file:'%s'", locale_file); - } - - g_free (locale_file); - - return locale; -} - -static gchar * -miner_locale_get_current (void) -{ - gchar *current_locale; - - /* Get current tracker LANG locale */ - current_locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE); - - return current_locale; -} - -void -tracker_miner_locale_set_current (void) -{ - GError *error = NULL; - gchar *locale_file, *locale = NULL; - - locale_file = miner_locale_get_filename (); - - g_message (" Creating locale file '%s'", locale_file); - - locale = miner_locale_get_current (); - - 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 (locale); - g_free (locale_file); -} - -gboolean -tracker_miner_locale_changed (void) -{ - gchar *previous_locale; - gchar *current_locale; - gboolean changed; - - current_locale = miner_locale_get_current (); - - /* Get previous locale */ - previous_locale = miner_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); - changed = TRUE; - } else { - g_message ("Current and previous locales match: '%s'", previous_locale); - changed = FALSE; - } - - g_free (previous_locale); - g_free (current_locale); - return changed; -} diff --git a/src/libtracker-common/tracker-miner-locale.h b/src/libtracker-common/tracker-miner-locale.h deleted file mode 100644 index 6aa909d0e..000000000 --- a/src/libtracker-common/tracker-miner-locale.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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_MINER_FS_LOCALE_H__ -#define __TRACKER_MINER_FS_LOCALE_H__ - -G_BEGIN_DECLS - -void tracker_miner_locale_set_current (void); -gboolean tracker_miner_locale_changed (void); - -G_END_DECLS - -#endif /* __TRACKER_MINER_FS_LOCALE_H__ */ diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c index b682248a7..30d9b7be1 100644 --- a/src/libtracker-data/tracker-db-manager.c +++ b/src/libtracker-data/tracker-db-manager.c @@ -33,10 +33,7 @@ #include <glib/gstdio.h> -#include <libtracker-common/tracker-date-time.h> -#include <libtracker-common/tracker-file-utils.h> -#include <libtracker-common/tracker-utils.h> -#include <libtracker-common/tracker-locale.h> +#include <libtracker-common/tracker-common.h> #if HAVE_TRACKER_FTS #include <libtracker-fts/tracker-fts.h> @@ -681,6 +678,7 @@ tracker_db_manager_locale_changed (void) g_free (db_locale); g_free (current_locale); + return changed; } @@ -691,7 +689,7 @@ tracker_db_manager_set_current_locale (void) /* Get current collation locale */ current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE); - g_message ("Changing db locale to: '%s'", current_locale); + g_message ("Saving DB locale as: '%s'", current_locale); db_set_locale (current_locale); g_free (current_locale); } diff --git a/src/miners/apps/tracker-miner-applications.c b/src/miners/apps/tracker-miner-applications.c index 9e092dd13..13d65fac1 100644 --- a/src/miners/apps/tracker-miner-applications.c +++ b/src/miners/apps/tracker-miner-applications.c @@ -23,6 +23,8 @@ #include "tracker-miner-applications.h" +#define LOCALE_FILENAME "locale-for-miner-apps.txt" + #define GROUP_DESKTOP_ENTRY "Desktop Entry" #define APPLICATION_DATASOURCE_URN "urn:nepomuk:datasource:84f20000-1241-11de-8c30-0800200c9a66" @@ -170,10 +172,28 @@ miner_finished_cb (TrackerMinerFS *fs, guint total_files_ignored, gpointer user_data) { - /* Update locale file if necessary */ - if (tracker_miner_locale_changed ()) { - tracker_miner_locale_set_current (); + /* Save locale, if it changes the variation in the desktop + * file languages needs to be re-indexed. + */ + GError *error = NULL; + gchar *locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE); + gchar *locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL); + + g_message ("Saving locale used to index applications"); + g_message (" Creating locale file '%s'", locale_file); + + 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 (locale); + g_free (locale_file); } static gboolean @@ -927,28 +947,78 @@ miner_applications_reset (TrackerMiner *miner) g_object_unref (sparql); } -gboolean -tracker_miner_applications_detect_locale_changed (TrackerMiner *miner) +static gboolean +detect_locale_changed (TrackerMiner *miner) { + gchar *locale_file; + gchar *previous_locale = NULL; + gchar *current_locale; gboolean changed; - changed = tracker_miner_locale_changed (); + locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL); + + if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) { + gchar *contents; + + /* Check locale is correct */ + if (G_LIKELY (g_file_get_contents (locale_file, &contents, NULL, NULL))) { + if (contents && + contents[0] == '\0') { + g_critical (" Empty locale file found at '%s'", locale_file); + g_free (contents); + } else { + /* Re-use contents */ + previous_locale = contents; + } + } else { + g_critical (" Could not get content of file '%s'", locale_file); + } + } else { + g_message (" Could not find locale file:'%s'", locale_file); + } + + g_free (locale_file); + + current_locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE); + + /* 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); + changed = TRUE; + } else { + g_message ("Current and previous locales match: '%s'", previous_locale); + changed = FALSE; + } + + g_free (current_locale); + g_free (previous_locale); + if (changed) { g_message ("Locale change detected, so resetting miner to " "remove all previously created items..."); miner_applications_reset (miner); } + return changed; } TrackerMiner * tracker_miner_applications_new (GError **error) { - return g_initable_new (TRACKER_TYPE_MINER_APPLICATIONS, - NULL, - error, - "name", "Applications", - "processing-pool-wait-limit", 10, - "processing-pool-ready-limit", 100, - NULL); + TrackerMiner *miner; + + miner = g_initable_new (TRACKER_TYPE_MINER_APPLICATIONS, + NULL, + error, + "name", "Applications", + "processing-pool-wait-limit", 10, + "processing-pool-ready-limit", 100, + NULL); + + /* If the locales changed, we need to reset things first */ + detect_locale_changed (miner); + + return miner; } diff --git a/src/miners/user-guides/tracker-miner-user-guides.c b/src/miners/user-guides/tracker-miner-user-guides.c index 8328dfacc..2ceaeb09a 100644 --- a/src/miners/user-guides/tracker-miner-user-guides.c +++ b/src/miners/user-guides/tracker-miner-user-guides.c @@ -27,6 +27,8 @@ #include "tracker-miner-user-guides.h" +#define LOCALE_FILENAME "locale-for-miner-user-guides.txt" + // FIXME: get this value from tracker conf #define MAX_EXTRACT_SIZE 1024 * 1024 // 1 MiB #define MAX_TITLE_LENGTH 1000 @@ -222,10 +224,28 @@ miner_finished_cb (TrackerMinerFS *fs, guint total_files_ignored, gpointer user_data) { - /* Update locale file if necessary */ - if (tracker_miner_locale_changed ()) { - tracker_miner_locale_set_current (); + /* Save locale, if it changes the variation in the desktop + * file languages needs to be re-indexed. + */ + GError *error = NULL; + gchar *locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE); + gchar *locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL); + + g_message ("Saving locale used to index applications"); + g_message (" Creating locale file '%s'", locale_file); + + 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 (locale); + g_free (locale_file); } static gboolean @@ -685,28 +705,78 @@ miner_userguides_reset (TrackerMiner *miner) g_object_unref (sparql); } -gboolean -tracker_miner_userguides_detect_locale_changed (TrackerMiner *miner) +static gboolean +detect_locale_changed (TrackerMiner *miner) { + gchar *locale_file; + gchar *previous_locale = NULL; + gchar *current_locale; gboolean changed; - changed = tracker_miner_locale_changed (); + locale_file = g_build_filename (g_get_user_cache_dir (), "tracker", LOCALE_FILENAME, NULL); + + if (G_LIKELY (g_file_test (locale_file, G_FILE_TEST_EXISTS))) { + gchar *contents; + + /* Check locale is correct */ + if (G_LIKELY (g_file_get_contents (locale_file, &contents, NULL, NULL))) { + if (contents && + contents[0] == '\0') { + g_critical (" Empty locale file found at '%s'", locale_file); + g_free (contents); + } else { + /* Re-use contents */ + previous_locale = contents; + } + } else { + g_critical (" Could not get content of file '%s'", locale_file); + } + } else { + g_message (" Could not find locale file:'%s'", locale_file); + } + + g_free (locale_file); + + current_locale = tracker_locale_get (TRACKER_LOCALE_LANGUAGE); + + /* 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); + changed = TRUE; + } else { + g_message ("Current and previous locales match: '%s'", previous_locale); + changed = FALSE; + } + + g_free (current_locale); + g_free (previous_locale); + if (changed) { g_message ("Locale change detected, so resetting miner to " "remove all previously created items..."); miner_userguides_reset (miner); } + return changed; } TrackerMiner * tracker_miner_userguides_new (GError **error) { - return g_initable_new (TRACKER_TYPE_MINER_USERGUIDES, - NULL, - error, - "name", "Userguides", - "processing-pool-wait-limit", 10, - "processing-pool-ready-limit", 100, - NULL); + TrackerMiner *miner; + + miner = g_initable_new (TRACKER_TYPE_MINER_USERGUIDES, + NULL, + error, + "name", "Userguides", + "processing-pool-wait-limit", 10, + "processing-pool-ready-limit", 100, + NULL); + + /* If the locales changed, we need to reset things first */ + detect_locale_changed (miner); + + return miner; } |