tracker-0.16.2/src/tracker-utils/tracker-stats.c

No issues found

  1 /*
  2  * Copyright (C) 2006, Jamie McCracken <jamiemcc@gnome.org>
  3  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
  4  *
  5  * This library is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU Library General Public
  7  * License as published by the Free Software Foundation; either
  8  * version 2 of the License, or (at your option) any later version.
  9  *
 10  * This library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Library General Public
 16  * License along with this library; if not, write to the
 17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 18  * Boston, MA  02110-1301, USA.
 19  */
 20 
 21 #include "config.h"
 22 
 23 #include <stdlib.h>
 24 #include <string.h>
 25 #include <time.h>
 26 #include <locale.h>
 27 
 28 #include <glib.h>
 29 #include <glib/gi18n.h>
 30 
 31 #include <libtracker-sparql/tracker-sparql.h>
 32 
 33 #define ABOUT \
 34 	"Tracker " PACKAGE_VERSION "\n"
 35 
 36 #define LICENSE \
 37 	"This program is free software and comes without any warranty.\n" \
 38 	"It is licensed under version 2 or later of the General Public " \
 39 	"License which can be viewed at:\n" \
 40 	"\n" \
 41 	"  http://www.gnu.org/licenses/gpl.txt\n"
 42 
 43 static gboolean print_version;
 44 
 45 static GOptionEntry entries[] = {
 46 	{ "version", 'V', 0, G_OPTION_ARG_NONE, &print_version,
 47 	  N_("Print version"),
 48 	  NULL
 49 	},
 50 	{ NULL }
 51 };
 52 
 53 int
 54 main (int argc, char **argv)
 55 {
 56 	TrackerSparqlConnection *connection;
 57 	TrackerSparqlCursor *cursor;
 58 	GOptionContext *context;
 59 	GError *error = NULL;
 60 
 61 	setlocale (LC_ALL, "");
 62 
 63 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
 64 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 65 	textdomain (GETTEXT_PACKAGE);
 66 
 67 	/* Translators: this messagge will apper immediately after the  */
 68 	/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
 69 	context = g_option_context_new (_(" - Show statistics for all Nepomuk defined ontology classes"));
 70 	g_option_context_add_main_entries (context, entries, NULL);
 71 	g_option_context_parse (context, &argc, &argv, NULL);
 72 
 73 	if (print_version) {
 74 		g_print ("\n" ABOUT "\n" LICENSE "\n");
 75 		g_option_context_free (context);
 76 
 77 		return EXIT_SUCCESS;
 78 	}
 79 
 80 	g_option_context_free (context);
 81 
 82 	connection = tracker_sparql_connection_get (NULL, &error);
 83 
 84 	if (!connection) {
 85 		g_printerr ("%s: %s\n",
 86 		            _("Could not establish a connection to Tracker"),
 87 		            error ? error->message : _("No error given"));
 88 		g_clear_error (&error);
 89 		return EXIT_FAILURE;
 90 	}
 91 
 92 	cursor = tracker_sparql_connection_statistics (connection, NULL, &error);
 93 
 94 	if (error) {
 95 		g_printerr ("%s, %s\n",
 96 		            _("Could not get Tracker statistics"),
 97 		            error->message);
 98 		g_error_free (error);
 99 		return EXIT_FAILURE;
100 	}
101 
102 	if (!cursor) {
103 		g_print ("%s\n", _("No statistics available"));
104 	} else {
105 		gint count = 0;
106 
107 		g_print ("%s\n", _("Statistics:"));
108 
109 		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
110 			g_print ("  %s = %s\n",
111 			         tracker_sparql_cursor_get_string (cursor, 0, NULL),
112 			         tracker_sparql_cursor_get_string (cursor, 1, NULL));
113 			count++;
114 		}
115 
116 		if (count == 0) {
117 			g_print ("  %s\n", _("None"));
118 		}
119 
120 		g_print ("\n");
121 
122 		g_object_unref (cursor);
123 	}
124 
125 	g_object_unref (connection);
126 
127 	return EXIT_SUCCESS;
128 }