[tracker/collation-gconf-locale: 30/31] tracker-miner-applications: remove previously inserted items if locale change detected



commit 79b961179f55b5e1ae0fd35802c675afd9e8ba8d
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Wed Nov 17 11:15:29 2010 +0100

    tracker-miner-applications: remove previously inserted items if locale change detected

 src/miners/fs/tracker-miner-applications.c |  201 +++++++++++++---------------
 1 files changed, 91 insertions(+), 110 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index 81b21f6..bcd03eb 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ * Copyright (C) 2008-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
@@ -24,13 +24,12 @@
 #include <libtracker-common/tracker-locale.h>
 
 #include "tracker-miner-applications.h"
+#include "tracker-miner-applications-locale.h"
 
 #ifdef HAVE_MEEGOTOUCH
 #include "tracker-miner-applications-meego.h"
 #endif
 
-#define TRACKER_MINER_APPLICATIONS_LOCALE_FILE "miner-applications-locale.txt"
-
 #define GROUP_DESKTOP_ENTRY          "Desktop Entry"
 
 #define APPLICATION_DATASOURCE_URN   "urn:nepomuk:datasource:84f20000-1241-11de-8c30-0800200c9a66"
@@ -747,131 +746,113 @@ miner_applications_process_file_attributes (TrackerMinerFS       *fs,
 	return FALSE;
 }
 
-static gchar *
-miner_applications_get_previous_locale (const gchar *locale_file)
-{
-	gchar *locale = 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 && strlen (contents) == 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_critical ("  Could not find locale file:'%s'", locale_file);
-	}
-
-	return locale;
-}
-
+/* If a reset is requested, we will remove from the store all items previously
+ * inserted by the tracker-miner-applications, this is:
+ *  (a) all elements which are nfo:softwareIcon of a given nfo:Software
+ *  (b) all nfo:Software in our graph (includes both applications and maemo applets)
+ *  (c) all elements which are nfo:softwareCategoryIcon of a given nfo:SoftwareCategory
+ *  (d) all nfo:SoftwareCategory in our graph
+ */
 static void
-miner_applications_set_current_locale (const gchar *locale_file,
-                                       const gchar *locale)
+miner_applications_reset (TrackerMiner *miner)
 {
 	GError *error = NULL;
-	gchar  *str;
-
-	g_message ("  Creating locale file '%s'", locale_file);
+	TrackerSparqlBuilder *sparql;
 
-	str = g_strdup_printf ("%s", locale ? locale : "");
+	sparql = tracker_sparql_builder_new_update ();
 
-	if (!g_file_set_contents (locale_file, str, -1, &error)) {
-		g_message ("  Could not set file contents, %s",
-		           error ? error->message : "no error given");
-		g_clear_error (&error);
-	}
+	/* (a) all elements which are nfo:softwareIcon of a given nfo:Software */
+	tracker_sparql_builder_delete_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+	tracker_sparql_builder_subject_variable (sparql, "icon");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "rdfs:Resource");
+	tracker_sparql_builder_delete_close (sparql);
 
-	g_free (str);
-}
+	tracker_sparql_builder_where_open (sparql);
+	tracker_sparql_builder_subject_variable (sparql, "software");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "nfo:Software");
+	tracker_sparql_builder_subject_variable (sparql, "icon");
+	tracker_sparql_builder_predicate (sparql, "nfo:softwareIcon");
+	tracker_sparql_builder_object_variable (sparql, "software");
+	tracker_sparql_builder_where_close (sparql);
+
+	/* (b) all nfo:Software in our graph (includes both applications and maemo applets) */
+	tracker_sparql_builder_delete_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+	tracker_sparql_builder_subject_variable (sparql, "software");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "rdfs:Resource");
+	tracker_sparql_builder_delete_close (sparql);
 
-static gboolean
-miner_applications_locale_changed (void)
-{
-	gchar *previous_locale;
-	gchar *current_locale;
-	gboolean changed;
-	gchar *data_dir;
-	gchar *filename;
+	tracker_sparql_builder_where_open (sparql);
+	tracker_sparql_builder_subject_variable (sparql, "software");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "nfo:Software");
+	tracker_sparql_builder_where_close (sparql);
 
-	/* Locate previous locale file */
-	data_dir = g_build_filename (g_get_user_cache_dir (),
-	                             "tracker",
-	                             NULL);
-	filename = g_build_filename (data_dir, TRACKER_MINER_APPLICATIONS_LOCALE_FILE, NULL);
+	/* (c) all elements which are nfo:softwareCategoryIcon of a given nfo:SoftwareCategory */
+	tracker_sparql_builder_delete_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+	tracker_sparql_builder_subject_variable (sparql, "icon");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "rdfs:Resource");
+	tracker_sparql_builder_delete_close (sparql);
 
-	/* Get current tracker locale */
-	current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
+	tracker_sparql_builder_where_open (sparql);
+	tracker_sparql_builder_subject_variable (sparql, "category");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "nfo:SoftwareCategory");
+	tracker_sparql_builder_subject_variable (sparql, "icon");
+	tracker_sparql_builder_predicate (sparql, "nfo:softwareCategoryIcon");
+	tracker_sparql_builder_object_variable (sparql, "category");
+	tracker_sparql_builder_where_close (sparql);
+
+	/* (d) all nfo:SoftwareCategory in our graph */
+	tracker_sparql_builder_delete_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+	tracker_sparql_builder_subject_variable (sparql, "category");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "rdfs:Resource");
+	tracker_sparql_builder_delete_close (sparql);
 
-#ifdef HAVE_MEEGOTOUCH
-	/* If we have meegotouch enabled, sanity check to compare with our
-	 * tracker locale */
-	{
-		/* Get also current meegotouch locale, which should be EQUAL to
-		 * the tracker locale */
-		gchar *current_mlocale;
-
-		current_mlocale = tracker_miner_applications_meego_get_locale ();
-
-		if (g_strcmp0 (current_locale, current_mlocale) != 0) {
-			g_critical ("Wrong locale settings (tracker locale '%s' vs MLocale '%s')",
-			            current_locale, current_mlocale);
-		}
+	tracker_sparql_builder_where_open (sparql);
+	tracker_sparql_builder_subject_variable (sparql, "category");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "nfo:SoftwareCategory");
+	tracker_sparql_builder_where_close (sparql);
 
-		g_free (current_mlocale);
-	}
-#endif
+	/* Execute a sync update, we don't want the apps miner to start before
+	 * we finish this. */
+	tracker_sparql_connection_update (tracker_miner_get_connection (miner),
+	                                  tracker_sparql_builder_get_result (sparql),
+	                                  G_PRIORITY_HIGH,
+	                                  NULL,
+	                                  &error);
 
-	/* Get previous locale */
-	previous_locale = miner_applications_get_previous_locale (filename);
-
-	/* 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_set_current_locale (filename, current_locale);
-		changed = TRUE;
-	} else {
-		g_message ("Current and previous locales match: '%s'", previous_locale);
-		changed = FALSE;
+	if (error) {
+		/* Some error happened performing the query, not good */
+		g_critical ("Couldn't remove previously created items: %s",
+		            error ? error->message : "unknown error");
+		g_error_free (error);
 	}
 
-	g_free (previous_locale);
-	g_free (current_locale);
-	g_free (filename);
-	g_free (data_dir);
-	return changed;
-}
-
-static void
-miner_applications_initialize_locale (void)
-{
-	/* If a locale change was detected, we need to remove all our previously
-	 * created resources from the store, so that they are properly recreated.
-	 */
-	if (miner_applications_locale_changed ()) {
-		/* TODO, nice sparql update removing all in our graph */
-	}
+	g_object_unref (sparql);
 }
 
 TrackerMiner *
 tracker_miner_applications_new (void)
 {
-	/* Initialize locale-related checks */
-	miner_applications_initialize_locale ();
+	TrackerMiner *miner;
+
+	miner = g_object_new (TRACKER_TYPE_MINER_APPLICATIONS,
+	                      "name", "Applications",
+	                      NULL);
+
+	/* Before returning the newly created miner, check if we need
+	 * to reset it */
+	if (tracker_miner_applications_locale_changed ()) {
+		g_message ("Locale change detected, so resetting miner to "
+		           "remove all previously created items...");
+		miner_applications_reset (miner);
+	}
 
-	return g_object_new (TRACKER_TYPE_MINER_APPLICATIONS,
-	                     "name", "Applications",
-	                     NULL);
+	return miner;
 }



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