[tracker/libtracker-common-cleanup] libtracker-common: Removed tracker-miner-locale, only apps/userguides need it
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-common-cleanup] libtracker-common: Removed tracker-miner-locale, only apps/userguides need it
- Date: Fri, 10 Oct 2014 22:07:28 +0000 (UTC)
commit 117d8d61e6fa20b276b63bdf68cab236240ebf2d
Author: Martyn Russell <martyn lanedo com>
Date: Fri Oct 10 23:04:52 2014 +0100
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.
src/libtracker-common/Makefile.am | 6 +-
src/libtracker-common/tracker-common.h | 1 -
src/libtracker-common/tracker-miner-locale.c | 133 --------------------
src/libtracker-common/tracker-miner-locale.h | 30 -----
src/libtracker-data/tracker-db-manager.c | 8 +-
src/miners/apps/tracker-miner-applications.c | 96 ++++++++++++--
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 b44a221..f7e0ddd 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 44f3292..dd3b5ca 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-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index b682248..30d9b7b 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 9e092dd..13d65fa 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 8328dfa..2ceaeb0 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]