tracker r1933 - in branches/indexer-split: . src/libtracker



Author: pvanhoof
Date: Fri Jul 25 11:48:13 2008
New Revision: 1933
URL: http://svn.gnome.org/viewvc/tracker?rev=1933&view=rev

Log:
2008-07-25  Philip Van Hoof  <pvanhoof gnome org>

	* src/libtracker/tracker-query.c
	* src/libtracker/tracker-search.c
	* src/libtracker/tracker-tag.c
	* src/libtracker/tracker-stats.c
	* src/libtracker/Makefile.am
	* src/libtracker/tracker-get-meta-for-folder.c
	* src/libtracker/tracker-files.c
	* src/libtracker/tracker-status.c:

	Various code improvements to the clients



Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker/Makefile.am
   branches/indexer-split/src/libtracker/tracker-files.c
   branches/indexer-split/src/libtracker/tracker-get-meta-for-folder.c
   branches/indexer-split/src/libtracker/tracker-query.c
   branches/indexer-split/src/libtracker/tracker-search.c
   branches/indexer-split/src/libtracker/tracker-stats.c
   branches/indexer-split/src/libtracker/tracker-status.c
   branches/indexer-split/src/libtracker/tracker-tag.c

Modified: branches/indexer-split/src/libtracker/Makefile.am
==============================================================================
--- branches/indexer-split/src/libtracker/Makefile.am	(original)
+++ branches/indexer-split/src/libtracker/Makefile.am	Fri Jul 25 11:48:13 2008
@@ -1,7 +1,7 @@
-INCLUDES =				\
+INCLUDES = -I.	-I..				\
 	-DTRACKER_DATADIR=\""$(datadir)"\"	\
-	-DTRACKER_LOCALEDIR=\""$(localedir)"\" \
-	$(GLIB2_CFLAGS)			\
+	-DTRACKER_LOCALEDIR=\""$(localedir)"\"	\
+	$(GLIB2_CFLAGS)				\
 	$(DBUS_CFLAGS)			
 
 # Common linking

Modified: branches/indexer-split/src/libtracker/tracker-files.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-files.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-files.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,121 +18,123 @@
  * Boston, MA  02110-1301, USA.
  */
 
+#include <config.h>
+
 #include <locale.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <time.h>
+#include <locale.h>
+#include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
-
-#define USAGE "usage: \ntracker-files -s ServiceType\t: Gets files with ServiceType (Documents, Music, Images, Videos, Text, Development, Other, Applications, Folders, Files, Conversations, Emails, EmailAttachments)\ntracker-files -m Mime1 [Mime2...] : Get all files that match one of the specified mime types\n"
+#include <tracker.h>
 
+static gchar *service = NULL;
+static gchar **mimes = NULL;
+static gint limit = 512;
+static gint offset = 0;
 
+static GOptionEntry entries[] = 
+{
+	{ "service", 's', 0, G_OPTION_ARG_STRING, &service, N_("Search from a specific service"), "service" },
+	{ "limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("512") },
+	{ "offset", 'o', 0, G_OPTION_ARG_INT, &offset, N_("Offset the results at O"), N_("0") },
+	{ "add-mime", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &mimes, N_("MIME types (can be used multiple times)"), N_("M") },
+	{ NULL }
+};
 
 int
 main (int argc, char **argv) 
 {
 
 	TrackerClient *client = NULL;
-	GError *error = NULL;
 	ServiceType type;
+	GError *error = NULL;
+	GOptionContext *context;
 
-
-	setlocale (LC_ALL, "");
-
-	if (argc < 3) {
-		g_print (USAGE);
-		return 1;
+	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	context = g_option_context_new (_("- Search for files by service or by MIME type"));
+	g_option_context_add_main_entries (context, entries, "tracker-files");
+
+	if (!g_option_context_parse (context, &argc, &argv, &error)) {
+		g_print ("option parsing failed: %s\n", error->message);
+		exit (1);
 	}
 
+	g_option_context_free (context);
+
 	client = tracker_connect (FALSE);
 
 	if (!client) {
-		g_print ("Could not initialize Tracker - exiting...\n");
-		return 1;
+		g_print (_("Could not initialize Tracker - exiting...\n"));
+		return EXIT_FAILURE;
 	}
 
-	if (strcmp (argv[1], "-s") == 0) {
-
-		if (argc != 3) {
-			g_print (USAGE);
-			return 1;
-		} else {
-
-			type = tracker_service_name_to_type (argv[2]);
-
-			char **array = NULL;
-
-			array = tracker_files_get_by_service_type (client, -1, type, 0, 512, &error);
-
-			if (error) {
-				g_warning ("An error has occurred : %s", error->message);
-				g_error_free (error);
-				return 1;
-			}
-
-			if (!array) {
-				g_print ("no results were found matching your query\n");
-				return 1;
-			}
-
-			char **p_strarray;
+	if (service) {
+		gchar **array = NULL;
+		gchar **p_strarray;
+
+		type = tracker_service_name_to_type (service);
+
+		array = tracker_files_get_by_service_type (client, 
+							   time(NULL), 
+							   type, 
+							   offset, 
+							   limit, 
+							   &error);
+
+		if (error) {
+			g_warning ("An error has occurred : %s", error->message);
+			g_error_free (error);
+			return EXIT_FAILURE;
+		}
 
-			for (p_strarray = array; *p_strarray; p_strarray++) {
-				g_print ("%s\n", *p_strarray);
-			}
+		if (!array) {
+			g_print ("no results were found matching your query\n");
+			return EXIT_FAILURE;
+		}
 
-			g_strfreev (array);
+		for (p_strarray = array; *p_strarray; p_strarray++) {
+			g_print ("%s\n", *p_strarray);
 		}
 
-	} else if (strcmp (argv[1], "-m") == 0)  {
+		g_strfreev (array);
+	}
 
-		if (argc < 3) {
-			g_print (USAGE);
+	if (mimes) {
+		gchar **array = NULL;
+		gchar **p_strarray;
+
+		array = tracker_files_get_by_mime_type (client, 
+							time(NULL), 
+							mimes, 
+							offset, 
+							limit, 
+							&error);
+
+		if (error) {
+			g_warning ("An error has occurred : %s", error->message);
+			g_error_free (error);
 			return 1;
-		} else {
-
-			char **mimes = NULL;
-			char **array = NULL;
-			int i;
-
-			mimes = g_new (char *, (argc-1));
-
-			for (i=0; i < (argc-2); i++) {
-				mimes[i] = g_locale_to_utf8 (argv[i+2], -1, NULL, NULL, NULL);
-			}
-			mimes[argc-2] = NULL;
-		
-			array = tracker_files_get_by_mime_type (client, -1, mimes, 0, 512, &error);
-
-			g_strfreev (mimes);
-
-			if (error) {
-				g_warning ("An error has occurred : %s", error->message);
-				g_error_free (error);
-				return 1;
-			}
-
-			if (!array) {
-				g_print ("no results were found matching your query\n");
-				return 1;
-			}
-
-			char **p_strarray;
+		}
 
-			for (p_strarray = array; *p_strarray; p_strarray++) {
-				g_print ("%s\n", *p_strarray);
-			}
+		if (!array) {
+			g_print ("no results were found matching your query\n");
+			return EXIT_FAILURE;
+		}
 
-			g_strfreev (array);
+		for (p_strarray = array; *p_strarray; p_strarray++) {
+			g_print ("%s\n", *p_strarray);
 		}
 
-	}  else {
-		g_print (USAGE);
-		return 1;
+		g_strfreev (array);
 	}
 
 	tracker_disconnect (client);
 
-	return 0;
+	return EXIT_SUCCESS;
 }

Modified: branches/indexer-split/src/libtracker/tracker-get-meta-for-folder.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-get-meta-for-folder.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-get-meta-for-folder.c	Fri Jul 25 11:48:13 2008
@@ -18,11 +18,11 @@
  */
 
 #include <locale.h>
+#include <time.h>
 #include <glib.h>
 #include <glib-object.h>
 
-#include "../libtracker/tracker.h" 
-
+#include <tracker.h>
 
 static void
 get_meta_table_data (gpointer value)
@@ -92,7 +92,11 @@
 
 	char *folder = g_filename_to_utf8 (argv[1], -1, NULL, NULL, NULL);
 
-	out_array = tracker_files_get_metadata_for_files_in_folder (client, -1, folder, meta_fields, &error);
+	out_array = tracker_files_get_metadata_for_files_in_folder (client, 
+								    time(NULL), 
+								    folder, 
+								    meta_fields, 
+								    &error);
 
 	g_free (folder);
 

Modified: branches/indexer-split/src/libtracker/tracker-query.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-query.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-query.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,14 +18,18 @@
  * Boston, MA  02110-1301, USA.
  */
 
+#include <config.h>
+
 #include <locale.h>
+#include <time.h>
 #include <sys/param.h>
 #include <stdlib.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <glib/gstdio.h>
+#include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
+#include <tracker.h>
 
 #include <config.h>
 #ifdef OS_WIN32
@@ -35,13 +40,17 @@
 static gchar **fields = NULL;
 static gchar *service = NULL;
 static gchar *keyword = NULL;
+static gint limit = 512;
+static gint offset = 0;
 
 static GOptionEntry entries[] = {
-	{"service", 's', 0, G_OPTION_ARG_STRING, &service, "search from a specific service", "service"},
-	{"search-term", 't', 0, G_OPTION_ARG_STRING, &search, "adds a fulltext search filter", "search-term"},
-	{"keyword", 'k', 0, G_OPTION_ARG_STRING, &keyword, "adds a keyword filter", "keyword"},
-	{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &fields, "Metadata Fields", NULL},
-	{NULL}
+	{ "service", 's', 0, G_OPTION_ARG_STRING, &service, N_("Search from a specific service"), "service"},
+	{ "limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("512") },
+	{ "offset", 'o', 0, G_OPTION_ARG_INT, &offset, N_("Offset the results at O"), N_("0") },
+	{ "search-term", 't', 0, G_OPTION_ARG_STRING, &search, N_("adds a fulltext search filter"), "search-term"},
+	{ "keyword", 'k', 0, G_OPTION_ARG_STRING, &keyword, N_("adds a keyword filter"), "keyword"},
+	{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &fields, N_("Metadata Fields"), NULL},
+	{ NULL }
 };
 
 
@@ -102,28 +111,32 @@
 	GOptionContext *context = NULL;
 	ServiceType type;
 	char **p_strarray;
-
+	char *str_path;
 	char *buffer, *tmp;
 	gsize buffer_length;
 	GPtrArray *out_array = NULL;
 	GError *error = NULL;
 	TrackerClient *client = NULL;
 
+	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
 
-	setlocale (LC_ALL, "");
+	context = g_option_context_new (_("- perform an RDF query and return results with specified metadata fields"));
 
-	context = g_option_context_new ("RDFQueryFile [MetaDataField...] ... - perform an rdf query and return results witrh specified metadata fields");
 	g_option_context_add_main_entries (context, entries, NULL);
 	g_option_context_parse (context, &argc, &argv, &error);
 
+	g_option_context_free (context);
+
 	if (error) {
 		g_printerr ("invalid arguments: %s\n", error->message);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (!fields) {
 		g_printerr ("missing input rdf query file, try --help for help\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 	
 
@@ -136,16 +149,12 @@
 			g_printerr ("service not recognized, searching in Other Files...\n");
 		}
 	}
-	
-	char *str_path = realpath_in_utf8 (fields[0]);
 
-	if (!str_path) {
-		return 1;
-	}
+	str_path = realpath_in_utf8 (fields[0]);
 
-	if (!g_file_get_contents (str_path, &tmp, &buffer_length, NULL)) {
+	if (!str_path || !g_file_get_contents (str_path, &tmp, &buffer_length, NULL)) {
 		g_print ("Could not read file %s\n", str_path);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	g_free (str_path);
@@ -155,7 +164,7 @@
 	if (!buffer) {
 		g_warning ("Cannot convert query file to UTF8!");
 		g_free (tmp);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 
@@ -163,7 +172,7 @@
 
 	if (!client) {
 		g_print ("Could not initialize Tracker over dbus connection - exiting...\n");
-		return 1; 
+		return EXIT_FAILURE; 
 	}
 
 	char **meta_fields = NULL;
@@ -188,26 +197,36 @@
 		fields = meta_fields;
 	} 
 
-	out_array = tracker_search_query (client, -1, type, fields, search, keyword, buffer, 0, 512, FALSE, &error);
-	
+	out_array = tracker_search_query (client, 
+					  time(NULL), 
+					  type, 
+					  fields, 
+					  search, 
+					  keyword, 
+					  buffer, 
+					  offset, 
+					  limit, 
+					  FALSE, 
+					  &error);
+
 	g_strfreev (meta_fields);
 
 	if (error) {
-		g_warning ("An error has occurred : %s\n", error->message);
+		g_warning (_("An error has occurred : %s\n"), error->message);
 		g_error_free (error);
 		g_free (buffer);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (out_array) {
-		g_ptr_array_foreach (out_array, (GFunc)get_meta_table_data, NULL);
+		g_ptr_array_foreach (out_array, (GFunc) get_meta_table_data, NULL);
 		g_ptr_array_free (out_array, TRUE);
 	}
 
 
-	tracker_disconnect (client);	
+	tracker_disconnect (client);
 
 	g_free (buffer);
 
-	return 0;
+	return EXIT_FAILURE;
 }

Modified: branches/indexer-split/src/libtracker/tracker-search.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-search.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-search.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -20,22 +21,27 @@
 #include <config.h>
 
 #include <locale.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
+#include <tracker.h>
 
-static gint limit = 0;
+static gint limit = 512;
+static gint offset = 0;
 static gchar **terms = NULL;
 static gchar *service = NULL;
 static gboolean detailed;
 
 static GOptionEntry entries[] = {
-	{"limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("N")},
-	{"service", 's', 0, G_OPTION_ARG_STRING, &service, N_("Search for a specific service"), N_("SERVICE")},
-	{"detailed", 'd', 0, G_OPTION_ARG_NONE, &detailed, N_("Show more detailed results with service and mime type as well"), NULL},
-	{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &terms, "search terms", NULL},
-	{NULL}
+	{ "limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("512") },
+	{ "offset", 'o', 0, G_OPTION_ARG_INT, &offset, N_("Offset the results at O"), N_("0") },
+	{ "service", 's', 0, G_OPTION_ARG_STRING, &service, N_("Search from a specific service"), "service" },
+	{ "detailed", 'd', 0, G_OPTION_ARG_NONE, &detailed, N_("Show more detailed results with service and mime type as well"), NULL},
+	{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &terms, N_("search terms"), NULL},
+	{ NULL }
 };
 
 
@@ -45,7 +51,7 @@
 {
 	char **meta, **meta_p;
 
-	meta = (char **)value;
+	meta = (char **) value;
 
 	int i = 0;
 	for (meta_p = meta; *meta_p; meta_p++) {
@@ -78,15 +84,14 @@
 	char **p_strarray;
 	GPtrArray *out_array = NULL;
 
-	setlocale (LC_ALL, "");
 
 	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-        textdomain (GETTEXT_PACKAGE);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
 
 	/* Translators: this messagge will apper immediately after the  */
         /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
-	context = g_option_context_new (_("TERM... - search files for certain terms"));
+	context = g_option_context_new (_("- Search files for certain terms"));
 
 	/* Translators: this message will appear after the usage string */
         /* and before the list of options.                              */
@@ -109,7 +114,7 @@
 		g_printerr ("\n");
 		g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
 		g_printerr ("\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (!terms) {
@@ -117,7 +122,7 @@
 		g_printerr ("\n");
 		g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
 		g_printerr ("\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (limit <= 0)
@@ -131,7 +136,7 @@
                 g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
                 g_printerr ("\n");
 
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (!service) {
@@ -147,9 +152,21 @@
 	search = g_strjoinv (" ", terms);
 
 	if (!detailed) {
-		result = tracker_search_text (client, -1, type, search, 0, limit, &error);
+		result = tracker_search_text (client, 
+					      time(NULL), 
+					      type, 
+					      search, 
+					      offset, 
+					      limit, 
+					      &error);
 	} else  {
-		out_array = tracker_search_text_detailed (client, -1, type, search, 0, limit, &error);
+		out_array = tracker_search_text_detailed (client, 
+							  time(NULL), 
+							  type, 
+							  search, 
+							  offset, 
+							  limit, 
+							  &error);
 		result = NULL;
 	}
 	
@@ -161,7 +178,7 @@
 			    argv[0], error->message);
 		g_printerr ("\n");
 		g_error_free (error);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if ((!detailed && !result) || (detailed && !out_array)) {
@@ -169,16 +186,16 @@
  		g_print (_("No results found matching your query"));
 		g_print ("\n");
 		tracker_disconnect (client);
- 		return 0;
+ 		return EXIT_SUCCESS;
  	}
 
 	if (detailed) {
 		if (out_array) {
-			g_ptr_array_foreach (out_array, (GFunc)get_meta_table_data, NULL);
+			g_ptr_array_foreach (out_array, (GFunc) get_meta_table_data, NULL);
 			g_ptr_array_free (out_array, TRUE);
 		}
 		tracker_disconnect (client);
-		return 0;
+		return EXIT_SUCCESS;
 	} 
 
 
@@ -196,6 +213,5 @@
 	g_strfreev (result);
 
 	tracker_disconnect (client);
-	return 0;
-
+	return EXIT_SUCCESS;
 }

Modified: branches/indexer-split/src/libtracker/tracker-stats.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-stats.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-stats.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -20,14 +21,15 @@
 #include <config.h>
 
 #include <locale.h>
+#include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <glib.h>
-#include <glib-object.h>
 #include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
+#include <tracker.h>
 
-#define TOTAL_COUNT "Total files indexed"
+#define TOTAL_COUNT _("Total files indexed")
 
 static void
 get_meta_table_data (gpointer value)
@@ -62,15 +64,13 @@
 	GOptionContext *context = NULL;
 	TrackerClient *client = NULL;
 
-	setlocale (LC_ALL, "");
-
-        bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-        textdomain (GETTEXT_PACKAGE);
+	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
 
         /* Translators: this messagge will apper immediately after the  */
         /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
-        context = g_option_context_new (_(" - show number of indexed files for each service"));
+        context = g_option_context_new (_(" - Show number of indexed files for each service"));
 
 	g_option_context_parse (context, &argc, &argv, &error);
 
@@ -101,7 +101,6 @@
 		g_error_free (error);
 	}
 
-
 	if (out_array) {
 		gchar *tmp;
 
@@ -117,8 +116,7 @@
 
 	}
 
-
 	tracker_disconnect (client);
 
-	return 0;
+	return EXIT_SUCCESS;
 }

Modified: branches/indexer-split/src/libtracker/tracker-status.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-status.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-status.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -20,25 +21,24 @@
 #include <config.h>
 
 #include <locale.h>
+#include <stdlib.h>
+#include <time.h>
 #include <string.h>
 #include <glib.h>
-#include <glib-object.h>
 #include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
-
+#include <tracker.h>
 
 gint
 main (gint argc, gchar *argv[])
 {
 	GError *error = NULL;
 	TrackerClient *client = NULL;
+	gchar* status;
 
-	setlocale (LC_ALL, "");
-
-        bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-        textdomain (GETTEXT_PACKAGE);
+	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
 
 	client =  tracker_connect (FALSE);
 
@@ -47,22 +47,24 @@
                 g_printerr ("\n");
                 g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
                 g_printerr ("\n");
-                return 1;
+                return EXIT_FAILURE;
         }
 
-        gchar* status = tracker_get_status (client, &error);
+        status = tracker_get_status (client, &error);
 
 	if (error) {
 		g_printerr (_("%s: internal tracker error: %s"), 
 			    argv[0], error->message);
 		g_printerr ("\n");
 		g_error_free (error);
-		return 1;
+		return EXIT_FAILURE;
 	}
 
-	if (status) g_print ("Tracker daemon's status is %s\n", status);
+	if (status) {
+		g_print ("Tracker daemon's status is %s\n", status);
+	}
 
 	tracker_disconnect (client);
 
-	return 0;
+	return EXIT_SUCCESS;
 }

Modified: branches/indexer-split/src/libtracker/tracker-tag.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker-tag.c	(original)
+++ branches/indexer-split/src/libtracker/tracker-tag.c	Fri Jul 25 11:48:13 2008
@@ -1,5 +1,6 @@
 /* Tracker - indexer and metadata database engine
  * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -21,15 +22,18 @@
 
 #include <locale.h>
 #include <stdlib.h>
+#include <time.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include "../libtracker/tracker.h" 
+#include <tracker.h>
 
 #ifdef OS_WIN32
 #include "../trackerd/mingw-compat.h"
 #endif
 
+static gint limit = 512;
+static gint offset = 0;
 static gchar **add = NULL;
 static gchar **delete = NULL;
 static gchar **search = NULL;
@@ -38,13 +42,15 @@
 static gboolean list = FALSE;
 
 static GOptionEntry entries[] = {
-	{"add", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &add, N_("Add specified tag to a file"), N_("TAG")},
-	{"remove", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &delete, N_("Remove specified tag from a file"), N_("TAG")},
-	{"remove-all", 'R', 0, G_OPTION_ARG_NONE, &remove_all, N_("Remove all tags from a file"), NULL},
-	{"list", 'l', 0, G_OPTION_ARG_NONE, &list, N_("List all defined tags"), NULL},
-	{"search", 's', 0, G_OPTION_ARG_STRING_ARRAY, &search, N_("Search for files with specified tag"), N_("TAG")},
-	{G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING_ARRAY, &files, N_("FILE..."), NULL},
-	{NULL}
+	{ "add", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &add, N_("Add specified tag to a file"), N_("TAG")},
+	{ "remove", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &delete, N_("Remove specified tag from a file"), N_("TAG")},
+	{ "remove-all", 'R', 0, G_OPTION_ARG_NONE, &remove_all, N_("Remove all tags from a file"), NULL},
+	{ "list", 'l', 0, G_OPTION_ARG_NONE, &list, N_("List all defined tags"), NULL},
+	{ "limit", 'l', 0, G_OPTION_ARG_INT, &limit, N_("Limit the number of results showed to N"), N_("512") },
+	{ "offset", 'o', 0, G_OPTION_ARG_INT, &offset, N_("Offset the results at O"), N_("0") },
+	{ "search", 's', 0, G_OPTION_ARG_STRING_ARRAY, &search, N_("Search for files with specified tag"), N_("TAG")},
+	{ G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING_ARRAY, &files, N_("FILE..."), NULL},
+	{ NULL }
 };
 
 
@@ -81,11 +87,9 @@
 	gint            i = 0;
         gint            k;
 
-	setlocale (LC_ALL, "");
-
 	bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-        textdomain (GETTEXT_PACKAGE);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
 
 	/* Translators: this messagge will apper immediately after the  
          * usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     
@@ -105,19 +109,19 @@
                                example, 
                                NULL);
 
-	g_option_context_set_summary (context, summary);	     
+	g_option_context_set_summary (context, summary);
 	g_option_context_add_main_entries (context, entries, NULL);
 	g_option_context_parse (context, &argc, &argv, &error);
 	g_option_context_free (context);
-        g_free (summary);
+	g_free (summary);
 	g_free (example);
-	
+
 	if (error) {
 		g_printerr ("%s: %s", argv[0], error->message);
 		g_printerr ("\n");
 		g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
 		g_printerr ("\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 	if (((add || delete || remove_all) && !files) || (remove_all && (add || delete)) || (search && files)) {
@@ -125,7 +129,7 @@
 		g_printerr ("\n");
 		g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
 		g_printerr ("\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 
@@ -136,13 +140,13 @@
 		g_printerr ("\n");
 		g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
 		g_printerr ("\n");
-		return 1;
+		return EXIT_FAILURE;
 	}
 
 
 	if (files) {
 		for (i = 0; files[i] != NULL; i++) {
-                        char resolved_path[1024];
+			char resolved_path[1024];
 			gchar *tmp = realpath (files[i], resolved_path);
 			if (tmp) {
 				g_free (files[i]);
@@ -173,9 +177,7 @@
 				delete[i] = tmp;
 			}
 
-
 		for (i = 0; files[i] != NULL; i++) {
-
 			if (remove_all) {
 				tracker_keywords_remove_all (client, SERVICE_FILES, files[i], &error);
 
@@ -208,13 +210,13 @@
 	}
 
 	if (((list && !files) || (!files && (!remove_all && !delete && !add))) && !search) {
-
 		GPtrArray *out_array = NULL;
 
 		out_array = tracker_keywords_get_list (client, SERVICE_FILES, &error);
 
-		if (error)
+		if (error) {
 			goto error;
+		}
 
 		if (out_array) {
 			g_ptr_array_foreach (out_array, (GFunc)get_meta_table_data, NULL);
@@ -230,10 +232,15 @@
 		for (i = 0; files[i] != NULL; i++) {
 
 			int j = 0;
-			gchar **tags = tracker_keywords_get (client, SERVICE_FILES, files[i], &error);
+			gchar **tags = tracker_keywords_get (client, 
+							     SERVICE_FILES, 
+							     files[i], 
+							     &error);
 
 			if (error) {
-				g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
+				g_printerr (_("%s: internal tracker error: %s"), 
+					    argv[0], 
+					    error->message);
 				g_printerr ("\n");
 			}
 
@@ -252,16 +259,25 @@
 	}
 
 	if (search) {
-
 		int i = 0;
+		gchar **results;
 
 		for (i = 0; search[i] != NULL; i++) {
-			gchar *tmp = g_locale_to_utf8 (search[i], -1, NULL, NULL, NULL);
+			gchar *tmp = g_locale_to_utf8 (search[i], 
+						       -1, 
+						       NULL, 
+						       NULL, 
+						       NULL);
 			g_free (search[i]);
 			search[i] = tmp;
 		}
 
-		gchar **results = tracker_keywords_search (client, -1, SERVICE_FILES, search, 0, 512, &error);
+		results = tracker_keywords_search (client, -1, 
+						   SERVICE_FILES, 
+						   search, 
+						   offset, 
+						   limit, 
+						   &error);
 
 		if (error)
 			goto error;
@@ -280,11 +296,11 @@
 	}
 
 	tracker_disconnect (client);
-	return 0;
+	return EXIT_SUCCESS;
 
 error:
 	g_printerr (_("%s: internal tracker error: %s"), argv[0], error->message);
 	g_printerr ("\n");
 	tracker_disconnect (client);
-	return 1;	
+	return EXIT_FAILURE;
 }



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