[tracker] Fixes: NB#186096, X-MeeGo-logical-id not extracted from application .desktop files



commit 469cde447513d1280d5881f818e001720104e5e8
Author: Mikael Ottela <mikael ottela ixonos com>
Date:   Tue Oct 5 04:55:08 2010 +0300

    Fixes: NB#186096, X-MeeGo-logical-id not extracted from application .desktop files

 configure.ac                                       |   26 ++++++-
 data/ontologies/91-maemo.ontology                  |    5 +
 src/miners/fs/Makefile.am                          |    6 ++
 src/miners/fs/tracker-miner-applications-meego.cpp |   62 +++++++++++++++
 src/miners/fs/tracker-miner-applications-meego.h   |   30 +++++++
 src/miners/fs/tracker-miner-applications.c         |   80 ++++++++++++++++++-
 6 files changed, 202 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index cb827d4..fde9b12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -142,6 +142,7 @@ HAL_REQUIRED=0.5
 UPOWER_REQUIRED=0.9.0
 GDKPIXBUF_REQUIRED=2.12.0
 QUILL_REQUIRED=1.0.0
+MEEGOTOUCH_REQUIRED=0.20
 POPPLER_REQUIRED=0.12.2
 CAIRO_REQUIRED=1.0
 GDK_REQUIRED=1.0
@@ -372,7 +373,6 @@ fi
 
 AM_CONDITIONAL(HAVE_UNIT_TESTS, test "x$have_unit_tests" = "xyes")
 
-
 ####################################################################
 # Should we install Maemo specific ontologies
 ####################################################################
@@ -386,6 +386,27 @@ AC_ARG_ENABLE(maemo,
 AM_CONDITIONAL(HAVE_MAEMO, test "x$enable_maemo" = "xyes")
 
 ####################################################################
+# Should we include MeeGo desktop-files
+####################################################################
+
+if test "x$enable_maemo" != "xno"; then
+   PKG_CHECK_MODULES(MEEGOTOUCH,
+                     [meegotouch >= $MEEGOTOUCH_REQUIRED],
+                     [have_meegotouch=yes],
+                     [have_meegotouch=no])
+   AC_SUBST(MEEGOTOUCH_CFLAGS)
+   AC_SUBST(MEEGOTOUCH_LIBS)
+
+   if test "x$have_meegotouch" = "xyes"; then
+      AC_DEFINE(HAVE_MEEGOTOUCH, [], [Define if we have meegotouch])
+   fi
+else
+   have_meegotouch="no  (disabled)"
+fi
+
+AM_CONDITIONAL(HAVE_MEEGOTOUCH, test "x$have_meegotouch" = "xyes")
+
+####################################################################
 # Use tagreadbin in gstreamer extraction?
 ####################################################################
 
@@ -399,7 +420,6 @@ if test "x$enable_tagreadbin" != "xno"; then
   AC_DEFINE(TRACKER_EXTRACT_GSTREAMER_USE_TAGREADBIN, 1, [Use tagreadbin in gstreamer extraction])
 fi
 
-
 ##################################################################
 # Check for UPower
 ##################################################################
@@ -2029,6 +2049,8 @@ Metadata Extractors:
 
 Data Miners:
 
+	Applications:                           yes
+          MeeGo                                 $have_meegotouch
 	RSS:                                    $have_miner_rss
 	Evolution:                              $have_miner_evolution ($evolution_plugins_dir)
 	Flickr:                                 $have_miner_flickr
diff --git a/data/ontologies/91-maemo.ontology b/data/ontologies/91-maemo.ontology
index e2e8447..7dcb078 100644
--- a/data/ontologies/91-maemo.ontology
+++ b/data/ontologies/91-maemo.ontology
@@ -24,6 +24,11 @@ maemo:SoftwareApplet a rdfs:Class ;
 	rdfs:comment "A widget" ;
 	rdfs:subClassOf nfo:Software .
 
+maemo:ControlPanelApplet a rdfs:Class ;
+	rdfs:label "Control Panel Applet for Meego" ;
+	rdfs:comment "A control panel applet for Meego" ;
+	rdfs:subClassOf maemo:SoftwareApplet .
+
 maemo:DesktopBookmark a rdfs:Class ;
 	rdfs:label "Desktop bookmark" ;
 	rdfs:subClassOf nie:InformationElement .
diff --git a/src/miners/fs/Makefile.am b/src/miners/fs/Makefile.am
index dc0fb37..7410f54 100644
--- a/src/miners/fs/Makefile.am
+++ b/src/miners/fs/Makefile.am
@@ -51,6 +51,12 @@ tracker_miner_fs_LDADD =						\
 	-lz								\
 	-lm
 
+if HAVE_MEEGOTOUCH
+INCLUDES += $(MEEGOTOUCH_CFLAGS)
+tracker_miner_fs_SOURCES += tracker-miner-applications-meego.cpp
+tracker_miner_fs_LDADD += $(MEEGOTOUCH_LIBS)
+endif
+
 marshal_sources =							\
 	tracker-marshal.h						\
 	tracker-marshal.c
diff --git a/src/miners/fs/tracker-miner-applications-meego.cpp b/src/miners/fs/tracker-miner-applications-meego.cpp
new file mode 100644
index 0000000..4e2cb0f
--- /dev/null
+++ b/src/miners/fs/tracker-miner-applications-meego.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010, Nokia (ivan frade nokia com)
+ *
+ * This program 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 program 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 program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <QApplication>
+#include <MLocale>
+
+#include <glib.h>
+
+#include "tracker-miner-applications-meego.h"
+
+/* The meego desktop files are using the qt translation system to get
+ * localized strings using catalog and string ids. QApplication and
+ * MLocale are needed for loading the translation catalogs. The
+ * returned string is a multi-string one which has parts of different
+ * lenght separated by '\x9C' unicode escape sequences.
+ *
+ * FIXME: This is insane, try to get rid of at least some of the extra
+ * layers here.
+ */
+gchar *
+tracker_miner_applications_meego_translate (const gchar *catalogue,
+					    const gchar *id)
+{
+	char *argv[] = { "dummy", NULL };
+	int argc = 1;
+
+	/* We need the app for loading translations */
+	QApplication app (argc, argv, FALSE);
+
+	/* Get the system default locale */
+	MLocale locale;
+
+	/* Load the catalog from disk */
+	locale.installTrCatalog (catalogue);
+	MLocale::setDefault (locale);
+
+	GStrv split;
+	split = g_strsplit (qtTrId (id). toAscii ().data (), "\x9C", 2);
+
+	gchar *ret = g_strdup (split[0]);
+	g_strfreev (split);
+
+	return ret;
+}
diff --git a/src/miners/fs/tracker-miner-applications-meego.h b/src/miners/fs/tracker-miner-applications-meego.h
new file mode 100644
index 0000000..8f36523
--- /dev/null
+++ b/src/miners/fs/tracker-miner-applications-meego.h
@@ -0,0 +1,30 @@
+/*
+ * 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_APPLICATIONS_MEEGO_H__
+#define __TRACKER_MINER_FS_APPLICATIONS_MEEGO_H__
+
+G_BEGIN_DECLS
+
+gchar* tracker_miner_applications_meego_translate (const gchar *catalogue,
+                                                   const gchar *id);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_FS_APPLICATIONS_MEEGO_H__ */
diff --git a/src/miners/fs/tracker-miner-applications.c b/src/miners/fs/tracker-miner-applications.c
index 3ad4346..d34aca1 100644
--- a/src/miners/fs/tracker-miner-applications.c
+++ b/src/miners/fs/tracker-miner-applications.c
@@ -24,6 +24,10 @@
 
 #include "tracker-miner-applications.h"
 
+#ifdef HAVE_MEEGOTOUCH
+#include "tracker-miner-applications-meego.h"
+#endif
+
 #define GROUP_DESKTOP_ENTRY          "Desktop Entry"
 
 #define APPLICATION_DATASOURCE_URN   "urn:nepomuk:datasource:84f20000-1241-11de-8c30-0800200c9a66"
@@ -108,6 +112,12 @@ miner_applications_constructed (GObject *object)
 	tracker_miner_fs_directory_add (TRACKER_MINER_FS (object), file, TRUE);
 	g_object_unref (file);
 
+#ifdef HAVE_MEEGOTOUCH
+	file = g_file_new_for_path ("/usr/lib/duicontrolpanel/");
+	tracker_miner_fs_directory_add (TRACKER_MINER_FS (object), file, TRUE);
+	g_object_unref (file);
+#endif /* HAVE_MEEGOTOUCH */
+
 	/* FIXME: Check XDG_DATA_DIRS and also process applications in there */
 }
 
@@ -117,7 +127,7 @@ insert_data_from_desktop_file (TrackerSparqlBuilder *sparql,
                                const gchar          *metadata_key,
                                GKeyFile             *desktop_file,
                                const gchar          *key,
-                               gboolean                      use_locale)
+                               gboolean              use_locale)
 {
 	gchar *str;
 
@@ -271,11 +281,19 @@ process_desktop_file (ProcessApplicationData  *data,
 {
 	TrackerSparqlBuilder *sparql;
 	GKeyFile *key_file;
-	gchar *path, *type, *filename, *name, *uri = NULL;
+	gchar *name = NULL;
+	gchar *path;
+	gchar *type;
+	gchar *filename;
+	gchar *uri = NULL;
 	GStrv cats;
 	gsize cats_len;
 	gboolean is_software = TRUE;
 	const gchar *parent_urn;
+#ifdef HAVE_MEEGOTOUCH
+	gchar *logical_id = NULL;
+	gchar *translation_catalog = NULL;
+#endif /* HAVE_MEEGOTOUCH */
 
 	sparql = data->sparql;
 	key_file = data->key_file;
@@ -291,8 +309,23 @@ process_desktop_file (ProcessApplicationData  *data,
 
 	/* NOTE: We sanitize categories later on when iterating them */
 
-	/* Try to get the name with locale, then without if that fails */
-	name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL, NULL);
+#ifdef HAVE_MEEGOTOUCH
+	/* If defined, start with the logical strings */
+	logical_id = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "X-MeeGo-Logical-Id", NULL);
+	translation_catalog = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "X-MeeGo-Translation-Catalog", NULL);
+
+	if (logical_id && translation_catalog) {
+		name = tracker_miner_applications_meego_translate (translation_catalog, logical_id);
+	}
+
+	g_free (logical_id);
+	g_free (translation_catalog);
+#endif /* HAVE_MEEGOTOUCH */
+
+	if (!name) {
+		/* Try to get the name with locale, then without if that fails */
+		name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL, NULL);
+	}
 
 	if (!name) {
 		name = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL);
@@ -335,7 +368,6 @@ process_desktop_file (ProcessApplicationData  *data,
 		}
 
 		is_software = FALSE;
-
 	} else if (name && g_ascii_strcasecmp (type, "Application") == 0) {
 		uri = g_file_get_uri (data->file);
 		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
@@ -352,6 +384,25 @@ process_desktop_file (ProcessApplicationData  *data,
 
 		tracker_sparql_builder_predicate (sparql, "nie:dataSource");
 		tracker_sparql_builder_object_iri (sparql, APPLICATION_DATASOURCE_URN);
+#ifdef HAVE_MEEGOTOUCH
+	} else if (name && g_ascii_strcasecmp (type, "ControlPanelApplet") == 0) {
+		/* Special case control panel applets */
+		/* The URI of the InformationElement should be a UUID URN */
+		uri = g_file_get_uri (data->file);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+
+		tracker_sparql_builder_subject_iri (sparql, APPLET_DATASOURCE_URN);
+		tracker_sparql_builder_predicate (sparql, "a");
+		tracker_sparql_builder_object (sparql, "nie:DataSource");
+
+		/* TODO This is atm specific for Maemo */
+		tracker_sparql_builder_subject_iri (sparql, uri);
+
+		tracker_sparql_builder_predicate (sparql, "a");
+		tracker_sparql_builder_object (sparql, "maemo:ControlPanelApplet");
+
+		tracker_sparql_builder_predicate (sparql, "nie:dataSource");
+		tracker_sparql_builder_object_iri (sparql, APPLET_DATASOURCE_URN);
 
 		/* This matches SomeApplet as Type= */
 	} else if (name && g_str_has_suffix (type, "Applet")) {
@@ -371,6 +422,25 @@ process_desktop_file (ProcessApplicationData  *data,
 
 		tracker_sparql_builder_predicate (sparql, "nie:dataSource");
 		tracker_sparql_builder_object_iri (sparql, APPLET_DATASOURCE_URN);
+
+	} else if (name && g_ascii_strcasecmp (type, "DUIApplication") == 0) {
+
+		uri = g_file_get_uri (data->file);
+		tracker_sparql_builder_insert_silent_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
+
+		tracker_sparql_builder_subject_iri (sparql, APPLICATION_DATASOURCE_URN);
+		tracker_sparql_builder_predicate (sparql, "a");
+		tracker_sparql_builder_object (sparql, "nie:DataSource");
+
+		tracker_sparql_builder_subject_iri (sparql, uri);
+
+		tracker_sparql_builder_predicate (sparql, "a");
+		tracker_sparql_builder_object (sparql, "nfo:SoftwareApplication");
+		tracker_sparql_builder_object (sparql, "nie:DataObject");
+
+		tracker_sparql_builder_predicate (sparql, "nie:dataSource");
+		tracker_sparql_builder_object_iri (sparql, APPLICATION_DATASOURCE_URN);
+#endif /* HAVE_MEEGOTOUCH */
 	} else {
 		/* Invalid type, all valid types are already listed above */
 		uri = g_file_get_uri (data->file);



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