tracker r2060 - in branches/indexer-split: . src/tracker-utils
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2060 - in branches/indexer-split: . src/tracker-utils
- Date: Tue, 12 Aug 2008 15:45:21 +0000 (UTC)
Author: mr
Date: Tue Aug 12 15:45:21 2008
New Revision: 2060
URL: http://svn.gnome.org/viewvc/tracker?rev=2060&view=rev
Log:
* src/tracker-utils/Makefile.am: Added.
* src/tracker-utils/tracker-files.c:
* src/tracker-utils/tracker-query.c:
* src/tracker-utils/tracker-search.c:
* src/tracker-utils/tracker-status.c: Clean up these examples.
More importantly make it show the help if the wrong parameters are
used or none at all.
Added:
branches/indexer-split/src/tracker-utils/Makefile.am
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/tracker-utils/tracker-files.c
branches/indexer-split/src/tracker-utils/tracker-query.c
branches/indexer-split/src/tracker-utils/tracker-search.c
branches/indexer-split/src/tracker-utils/tracker-status.c
Added: branches/indexer-split/src/tracker-utils/Makefile.am
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/tracker-utils/Makefile.am Tue Aug 12 15:45:21 2008
@@ -0,0 +1,41 @@
+INCLUDES = \
+ -g \
+ -DLOCALEDIR=\""$(localedir)"\" \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -I$(top_srcdir)/src \
+ $(DBUS_CFLAGS) \
+ $(GLIB2_CFLAGS)
+
+bin_PROGRAMS = \
+ tracker-search \
+ tracker-query \
+ tracker-meta-folder \
+ tracker-stats \
+ tracker-tag \
+ tracker-files \
+ tracker-status \
+ tracker-unique
+
+tracker_search_SOURCES = tracker-search.c
+tracker_search_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_query_SOURCES = tracker-query.c
+tracker_query_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_meta_folder_SOURCES = tracker-meta-folder.c
+tracker_meta_folder_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_stats_SOURCES = tracker-stats.c
+tracker_stats_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_tag_SOURCES = tracker-tag.c
+tracker_tag_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_files_SOURCES = tracker-files.c
+tracker_files_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_status_SOURCES = tracker-status.c
+tracker_status_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
+
+tracker_unique_SOURCES = tracker-unique.c
+tracker_unique_LDADD = $(top_builddir)/src/libtracker/libtrackerclient.la
Modified: branches/indexer-split/src/tracker-utils/tracker-files.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-files.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-files.c Tue Aug 12 15:45:21 2008
@@ -1,4 +1,5 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
* Copyright (C) 2008, Nokia
*
@@ -18,29 +19,41 @@
* Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
#include <time.h>
#include <locale.h>
+
+#include <glib.h>
#include <glib/gi18n.h>
#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") },
+static gchar *service;
+static gchar **mimes;
+static gint limit = 512;
+static gint offset;
+
+static GOptionEntry entries[] = {
+ { "service", 's', 0, G_OPTION_ARG_STRING, &service,
+ N_("Search from a specific service"),
+ NULL
+ },
+ { "limit", 'l', 0, G_OPTION_ARG_INT, &limit,
+ N_("Limit the number of results shown"),
+ N_("512")
+ },
+ { "offset", 'o', 0, G_OPTION_ARG_INT, &offset,
+ N_("Offset the results"),
+ N_("0")
+ },
+ { "add-mime", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &mimes,
+ N_("MIME types (can be used multiple times)"),
+ NULL
+ },
{ NULL }
};
@@ -59,23 +72,30 @@
context = g_option_context_new (_("- Search for files by service or by MIME type"));
g_option_context_add_main_entries (context, entries, "tracker-files");
+ g_option_context_parse (context, &argc, &argv, NULL);
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- g_print ("option parsing failed: %s\n", error->message);
- exit (1);
- }
+ if (!service && !mimes) {
+ gchar *help;
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr (help);
+ g_free (help);
+
+ return EXIT_FAILURE;
+ }
g_option_context_free (context);
client = tracker_connect (FALSE);
if (!client) {
- g_print (_("Could not initialize Tracker - exiting...\n"));
+ g_printerr (_("Could not establish a DBus connection to Tracker"));
return EXIT_FAILURE;
}
if (service) {
- gchar **array = NULL;
+ gchar **array;
gchar **p_strarray;
type = tracker_service_name_to_type (service);
@@ -88,13 +108,14 @@
&error);
if (error) {
- g_warning ("An error has occurred : %s", error->message);
+ g_warning ("Could not get files by service type, %s",
+ error->message);
g_error_free (error);
return EXIT_FAILURE;
}
if (!array) {
- g_print ("no results were found matching your query\n");
+ g_print ("No results were found matching your query\n");
return EXIT_FAILURE;
}
@@ -106,7 +127,7 @@
}
if (mimes) {
- gchar **array = NULL;
+ gchar **array;
gchar **p_strarray;
array = tracker_files_get_by_mime_type (client,
@@ -117,13 +138,14 @@
&error);
if (error) {
- g_warning ("An error has occurred : %s", error->message);
+ g_warning ("Could not get files by mime type, %s",
+ error->message);
g_error_free (error);
- return 1;
+ return EXIT_FAILURE;
}
if (!array) {
- g_print ("no results were found matching your query\n");
+ g_print ("No results were found matching your query\n");
return EXIT_FAILURE;
}
Modified: branches/indexer-split/src/tracker-utils/tracker-query.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-query.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-query.c Tue Aug 12 15:45:21 2008
@@ -1,4 +1,5 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
* Copyright (C) 2008, Nokia
*
@@ -18,12 +19,13 @@
* Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include "config.h"
-#include <locale.h>
-#include <time.h>
#include <sys/param.h>
#include <stdlib.h>
+#include <time.h>
+#include <locale.h>
+
#include <glib.h>
#include <glib-object.h>
#include <glib/gstdio.h>
@@ -36,197 +38,214 @@
#include "../trackerd/mingw-compat.h"
#endif
-static gchar *search = NULL;
-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, 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},
+static gchar *path;
+static gchar *search;
+static gchar **fields;
+static gchar *service;
+static gchar *keyword;
+static gint limit = 512;
+static gint offset;
+
+static GOptionEntry entries[] = {
+ { "path", 'p', 0, G_OPTION_ARG_STRING, &path,
+ N_("Path to use in query"),
+ NULL,
+ },
+ { "service", 's', 0, G_OPTION_ARG_STRING, &service,
+ N_("Search from a specific service"),
+ NULL
+ },
+ { "limit", 'l', 0, G_OPTION_ARG_INT, &limit,
+ N_("Limit the number of results shown"),
+ N_("512")
+ },
+ { "offset", 'o', 0, G_OPTION_ARG_INT, &offset,
+ N_("Offset the results"),
+ N_("0")
+ },
+ { "search-term", 't', 0, G_OPTION_ARG_STRING, &search,
+ N_("Adds a fulltext search filter"),
+ NULL,
+ },
+ { "keyword", 'k', 0, G_OPTION_ARG_STRING, &keyword,
+ N_("Adds a keyword filter"),
+ NULL
+ },
+ { G_OPTION_REMAINING, 0, 0,
+ G_OPTION_ARG_STRING_ARRAY, &fields,
+ N_("Metadata Fields"),
+ NULL
+ },
{ NULL }
};
-
-static int field_count;
-
-static char *
-realpath_in_utf8 (const char *path)
-{
- char *str_path_tmp = NULL, *str_path = NULL;
-
- str_path_tmp = realpath (path, NULL);
-
- if (str_path_tmp) {
- str_path = g_filename_to_utf8 (str_path_tmp, -1, NULL, NULL, NULL);
-
- g_free (str_path_tmp);
- }
-
- if (!str_path) {
- g_warning ("realpath_in_utf8(): locale to UTF8 failed!");
- return NULL;
- }
-
- return str_path;
-}
-
static void
get_meta_table_data (gpointer value)
-
{
- char **meta, **meta_p;
-
- meta = (char **)value;
-
- int i = 0;
- for (meta_p = meta; *meta_p; meta_p++) {
-
- char *str;
+ gchar **meta, **p;
+ gint i = 0;
- str = g_filename_from_utf8 (*meta_p, -1, NULL, NULL, NULL);
+ meta = value;
- if (i == 0) {
- g_print ("%s : ", str);
+ for (p = meta, i = 0; *p; p++, i++) {
+ gchar *str;
- } else {
- g_print ("%s, ", *meta_p);
- }
- i++;
+ str = g_filename_from_utf8 (*p, -1, NULL, NULL, NULL);
+
+ switch (i) {
+ case 0:
+ g_print (" %s:'%s'", _("Path"), str);
+ break;
+ case 1:
+ g_print (", %s:'%s'", _("Service"), *p);
+ break;
+ case 2:
+ g_print (", %s:'%s'", _("MIME-type"), *p);
+ break;
+ default:
+ break;
+ }
}
+
g_print ("\n");
}
-
-
int
main (int argc, char **argv)
{
- 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;
+ TrackerClient *client;
+ ServiceType type;
+ GOptionContext *context;
+ GError *error = NULL;
+ gchar *search;
+ gchar *path_in_utf8;
+ gchar *content;
+ gchar *buffer;
+ gsize size;
+ GPtrArray *array;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- context = g_option_context_new (_("- perform an RDF query and return results with specified metadata fields"));
+ context = g_option_context_new (_("- Query using RDF and return results "
+ "with specified metadata fields"));
g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, &error);
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ if (!fields || !path) {
+ gchar *help;
+
+ g_printerr (_("Path or fields are missing"));
+ g_printerr ("\n"
+ "\n");
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr (help);
+ g_free (help);
+
+ return EXIT_FAILURE;
+ }
g_option_context_free (context);
- if (error) {
- g_printerr ("invalid arguments: %s\n", error->message);
- return EXIT_FAILURE;
- }
+ client = tracker_connect (FALSE);
- if (!fields) {
- g_printerr ("missing input rdf query file, try --help for help\n");
+ if (!client) {
+ g_printerr (_("Could not establish a DBus connection to Tracker"));
return EXIT_FAILURE;
}
-
+
+ if (limit <= 0) {
+ limit = 512;
+ }
if (!service) {
+ g_print (_("Defaulting to 'files' service"));
+ g_print ("\n");
+
type = SERVICE_FILES;
} else {
type = tracker_service_name_to_type (service);
if (type == SERVICE_OTHER_FILES && g_ascii_strcasecmp (service, "Other")) {
- g_printerr ("service not recognized, searching in Other Files...\n");
+ g_printerr (_("Service not recognized, searching in other files...\n"));
}
}
- str_path = realpath_in_utf8 (fields[0]);
-
- if (!str_path || !g_file_get_contents (str_path, &tmp, &buffer_length, NULL)) {
- g_print ("Could not read file %s\n", str_path);
+ path_in_utf8 = g_filename_to_utf8 (path, -1, NULL, NULL, &error);
+ if (error) {
+ g_printerr ("%s:'%s', %s\n",
+ _("Could not get UTF-8 path from path"),
+ path,
+ error->message);
+ g_error_free (error);
+ tracker_disconnect (client);
+
return EXIT_FAILURE;
}
- g_free (str_path);
-
- buffer = g_locale_to_utf8 (tmp, buffer_length, NULL, NULL, NULL);
-
- if (!buffer) {
- g_warning ("Cannot convert query file to UTF8!");
- g_free (tmp);
+ g_file_get_contents (path_in_utf8, &content, &size, &error);
+ if (error) {
+ g_printerr ("%s:'%s', %s\n",
+ _("Could not read file"),
+ path_in_utf8,
+ error->message);
+ g_error_free (error);
+ g_free (path_in_utf8);
+ tracker_disconnect (client);
+
return EXIT_FAILURE;
}
+ g_free (path_in_utf8);
- client = tracker_connect (FALSE);
-
- if (!client) {
- g_print ("Could not initialize Tracker over dbus connection - exiting...\n");
- return EXIT_FAILURE;
- }
-
- char **meta_fields = NULL;
-
- g_free (fields[0]);
- int i = 0;
- for (p_strarray = fields+1; *p_strarray; p_strarray++) {
- fields[i] = *p_strarray;
- i++;
- }
- fields[i] = NULL;
-
-
- if (i == 0) {
- meta_fields = g_new (char *, 2);
-
- field_count = 1;
-
- meta_fields[0] = g_strdup ("File:Mime");
- meta_fields[1] = NULL;
- g_strfreev (fields);
- fields = meta_fields;
- }
-
- out_array = tracker_search_query (client,
- time(NULL),
- type,
- fields,
- search,
- keyword,
- buffer,
- offset,
- limit,
- FALSE,
- &error);
+ buffer = g_locale_to_utf8 (content, size, NULL, NULL, &error);
+ g_free (content);
- g_strfreev (meta_fields);
+ if (error) {
+ g_printerr ("%s, %s",
+ _("Could not convert query file to UTF-8"),
+ error->message);
+ g_error_free (error);
+ tracker_disconnect (client);
+
+ return EXIT_FAILURE;
+ }
+
+ array = tracker_search_query (client,
+ time (NULL),
+ type,
+ fields,
+ search,
+ keyword,
+ buffer,
+ offset,
+ limit,
+ FALSE,
+ &error);
+ g_free (buffer);
if (error) {
- g_warning (_("An error has occurred : %s\n"), error->message);
+ g_printerr ("%s, %s",
+ _("Could not query search"),
+ error->message);
g_error_free (error);
- g_free (buffer);
- return EXIT_FAILURE;
- }
-
- if (out_array) {
- g_ptr_array_foreach (out_array, (GFunc) get_meta_table_data, NULL);
- g_ptr_array_free (out_array, TRUE);
- }
+ return EXIT_FAILURE;
+ }
+
+ if (!array) {
+ g_print (_("No results found matching your query"));
+ g_print ("\n");
+ } else {
+ g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
+ g_ptr_array_free (array, TRUE);
+ }
tracker_disconnect (client);
- g_free (buffer);
-
- return EXIT_FAILURE;
+ return EXIT_SUCCESS;
}
Modified: branches/indexer-split/src/tracker-utils/tracker-search.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-search.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-search.c Tue Aug 12 15:45:21 2008
@@ -1,4 +1,5 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
* Copyright (C) 2008, Nokia
*
@@ -18,72 +19,92 @@
* Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include "config.h"
-#include <locale.h>
#include <stdlib.h>
-#include <time.h>
#include <string.h>
+#include <time.h>
+#include <locale.h>
+
#include <glib.h>
#include <glib/gi18n.h>
#include <tracker.h>
-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_("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},
+static gint limit = 512;
+static gint offset;
+static gchar **terms;
+static gchar *service;
+static gboolean detailed;
+
+static GOptionEntry entries[] = {
+ { "service", 's', 0, G_OPTION_ARG_STRING, &service,
+ N_("Search from a specific service"),
+ NULL
+ },
+ { "limit", 'l', 0, G_OPTION_ARG_INT, &limit,
+ N_("Limit the number of results shown"),
+ N_("512")
+ },
+ { "offset", 'o', 0, G_OPTION_ARG_INT, &offset,
+ N_("Offset the results"),
+ N_("0")
+ },
+ { "detailed", 'd', 0, G_OPTION_ARG_NONE, &detailed,
+ N_("Show more detailed results with service and mime type"),
+ NULL
+ },
+ { G_OPTION_REMAINING, 0, 0,
+ G_OPTION_ARG_STRING_ARRAY, &terms,
+ N_("search terms"),
+ NULL
+ },
{ NULL }
};
-
static void
get_meta_table_data (gpointer value)
-
{
- char **meta, **meta_p;
+ gchar **meta, **p;
+ gint i = 0;
- meta = (char **) value;
+ meta = value;
- int i = 0;
- for (meta_p = meta; *meta_p; meta_p++) {
+ for (p = meta, i = 0; *p; p++, i++) {
+ gchar *str;
- char *str;
-
- str = g_filename_from_utf8 (*meta_p, -1, NULL, NULL, NULL);
-
- if (i == 0) {
- g_print ("%s : ", str);
-
- } else {
- g_print ("%s, ", *meta_p);
- }
- i++;
+ str = g_filename_from_utf8 (*p, -1, NULL, NULL, NULL);
+
+ switch (i) {
+ case 0:
+ g_print (" %s:'%s'", _("Path"), str);
+ break;
+ case 1:
+ g_print (", %s:'%s'", _("Service"), *p);
+ break;
+ case 2:
+ g_print (", %s:'%s'", _("MIME-type"), *p);
+ break;
+ default:
+ break;
+ }
}
+
g_print ("\n");
}
int
main (int argc, char **argv)
{
- GOptionContext *context = NULL;
- TrackerClient *client = NULL;
- GError *error = NULL;
- ServiceType type;
- gchar *search;
- gchar *summary;
- gchar **result;
- char **p_strarray;
- GPtrArray *out_array = NULL;
-
+ TrackerClient *client;
+ ServiceType type;
+ GOptionContext *context;
+ GError *error = NULL;
+ gchar *search;
+ gchar *summary;
+ gchar **strv;
+ gchar **p;
+ GPtrArray *array;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -95,123 +116,150 @@
/* Translators: this message will appear after the usage string */
/* and before the list of options. */
- summary = g_strconcat (_("Specifying more then one term, will be "
- "showed items containing ALL the specified "
- "terms (term1 AND term2 - logical conjunction)"),
- "\n\n",
- _("The list of recognized services is:"),
- "\n\tDocuments Emails EmailAttachments Music Images Videos Text Development Applications Conversations Folders Files",
+ summary = g_strconcat (_("Specifying multiple terms apply an AND "
+ "operator to the search performed"),
+ "\n",
+ _("This means if you search for 'foo' and 'bar', "
+ "they must BOTH exist"),
+ "\n",
+ "\n",
+ _("Recognized services include:"),
+ "\n"
+ "\n",
+ " Documents\n"
+ " Emails\n"
+ " EmailAttachments\n"
+ " Music\n"
+ " Images\n"
+ " Videos\n"
+ " Text\n"
+ " Development\n"
+ " Applications\n"
+ " Conversations\n"
+ " Folders\n"
+ " Files",
NULL);
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_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
g_free (summary);
- 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 EXIT_FAILURE;
- }
+ if (!terms) {
+ gchar *help;
- if (!terms) {
- g_printerr (_("%s: missing search terms"), argv[0]);
- g_printerr ("\n");
- g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
- g_printerr ("\n");
- return EXIT_FAILURE;
- }
+ g_printerr (_("Search terms are missing"));
+ g_printerr ("\n"
+ "\n");
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr (help);
+ g_free (help);
- if (limit <= 0)
- limit = 512;
+ return EXIT_FAILURE;
+ }
+
+ g_option_context_free (context);
client = tracker_connect (FALSE);
if (!client) {
- g_printerr (_("%s: no connection to tracker daemon"), argv[0]);
- g_printerr ("\n");
- g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
- g_printerr ("\n");
-
+ g_printerr (_("Could not establish a DBus connection to Tracker"));
return EXIT_FAILURE;
}
+ if (limit <= 0) {
+ limit = 512;
+ }
+
if (!service) {
+ g_print (_("Defaulting to 'files' service"));
+ g_print ("\n");
+
type = SERVICE_FILES;
} else {
type = tracker_service_name_to_type (service);
if (type == SERVICE_OTHER_FILES && g_ascii_strcasecmp (service, "Other")) {
- g_printerr (_("Service not recognized, searching in Other Files...\n"));
+ g_printerr (_("Service not recognized, searching in other files...\n"));
}
}
search = g_strjoinv (" ", terms);
- if (!detailed) {
- result = tracker_search_text (client,
- time(NULL),
- type,
- search,
- offset,
- limit,
- &error);
- } else {
- out_array = tracker_search_text_detailed (client,
- time(NULL),
- type,
- search,
- offset,
- limit,
- &error);
- result = NULL;
- }
-
- g_free (search);
-
-
- if (error) {
- g_printerr (_("%s: internal tracker error: %s"),
- argv[0], error->message);
- g_printerr ("\n");
- g_error_free (error);
- return EXIT_FAILURE;
- }
-
- if ((!detailed && !result) || (detailed && !out_array)) {
- /* FIXME!! coreutilus don't print anything on no-results */
- g_print (_("No results found matching your query"));
- g_print ("\n");
- tracker_disconnect (client);
- return EXIT_SUCCESS;
- }
-
if (detailed) {
- if (out_array) {
- g_ptr_array_foreach (out_array, (GFunc) get_meta_table_data, NULL);
- g_ptr_array_free (out_array, TRUE);
- }
- tracker_disconnect (client);
- return EXIT_SUCCESS;
- }
-
-
-
- for (p_strarray = result; *p_strarray; p_strarray++) {
- char *s = g_locale_from_utf8 (*p_strarray, -1, NULL, NULL, NULL);
-
- if (!s)
- continue;
+ array = tracker_search_text_detailed (client,
+ time (NULL),
+ type,
+ search,
+ offset,
+ limit,
+ &error);
+ g_free (search);
+
+ if (error) {
+ g_printerr (_("Could not get find detailed results by text"));
+ g_printerr (", %s\n", error->message);
+
+ g_error_free (error);
+ tracker_disconnect (client);
+
+ return EXIT_FAILURE;
+ }
+
+ if (!array) {
+ g_print (_("No results found matching your query"));
+ g_print ("\n");
+ } else {
+ g_print (_("Results:"));
+ g_print ("\n");
+
+ g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
+ g_ptr_array_free (array, TRUE);
+ }
+ } else {
+ strv = tracker_search_text (client,
+ time (NULL),
+ type,
+ search,
+ offset,
+ limit,
+ &error);
+ g_free (search);
+
+ if (error) {
+ g_printerr (_("Could not get find results by text"));
+ g_printerr (", %s\n", error->message);
+
+ g_error_free (error);
+ tracker_disconnect (client);
+
+ return EXIT_FAILURE;
+ }
+
+ if (!strv) {
+ g_print (_("No results found matching your query"));
+ g_print ("\n");
+ } else {
+ for (p = strv; *p; p++) {
+ gchar *s;
+
+ s = g_locale_from_utf8 (*p, -1, NULL, NULL, NULL);
+
+ if (!s) {
+ continue;
+ }
+
+ g_print ("%s\n", s);
+ g_free (s);
+ }
- g_print ("%s\n", s);
- g_free (s);
+ g_free (strv);
+ }
}
-
- g_strfreev (result);
-
+
tracker_disconnect (client);
- return EXIT_SUCCESS;
+
+ return EXIT_SUCCESS;
}
Modified: branches/indexer-split/src/tracker-utils/tracker-status.c
==============================================================================
--- branches/indexer-split/src/tracker-utils/tracker-status.c (original)
+++ branches/indexer-split/src/tracker-utils/tracker-status.c Tue Aug 12 15:45:21 2008
@@ -1,4 +1,5 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
* Copyright (C) 2008, Nokia
*
@@ -18,12 +19,13 @@
* Boston, MA 02110-1301, USA.
*/
-#include <config.h>
+#include "config.h"
-#include <locale.h>
+#include <string.h>
#include <stdlib.h>
#include <time.h>
-#include <string.h>
+#include <locale.h>
+
#include <glib.h>
#include <glib/gi18n.h>
@@ -32,9 +34,9 @@
gint
main (gint argc, gchar *argv[])
{
- GError *error = NULL;
- TrackerClient *client = NULL;
- gchar* status;
+ TrackerClient *client;
+ GError *error = NULL;
+ gchar *status;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -42,26 +44,24 @@
client = tracker_connect (FALSE);
- if (!client) {
- g_printerr (_("%s: no connection to tracker daemon"), argv[0]);
- g_printerr ("\n");
- g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
- g_printerr ("\n");
- return EXIT_FAILURE;
- }
+ if (!client) {
+ g_printerr (_("Could not establish a DBus connection to Tracker"));
+ return EXIT_FAILURE;
+ }
status = tracker_get_status (client, &error);
if (error) {
- g_printerr (_("%s: internal tracker error: %s"),
- argv[0], error->message);
- g_printerr ("\n");
+ g_printerr ("%s, %s\n",
+ _("Could not get Tracker status"),
+ error->message);
g_error_free (error);
+
return EXIT_FAILURE;
}
if (status) {
- g_print ("Tracker daemon's status is %s\n", status);
+ g_print ("Tracker status is '%s'\n", status);
}
tracker_disconnect (client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]