Пример #1
0
static gboolean
writeback_dispatcher_initable_init (GInitable    *initable,
                                    GCancellable *cancellable,
                                    GError       **error)
{
	TrackerWritebackDispatcherPrivate *priv;
	GError *internal_error = NULL;

	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (initable);

	priv->connection = tracker_sparql_connection_get (NULL, &internal_error);

	if (internal_error) {
		g_propagate_error (error, internal_error);
		return FALSE;
	}

	priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &internal_error);

	if (internal_error) {
		g_propagate_error (error, internal_error);
		return FALSE;
	}

	priv->signal_id = g_signal_connect_object (priv->files_miner,
	                                           "writeback-file",
	                                           G_CALLBACK (writeback_dispatcher_writeback_file),
	                                           initable,
	                                           G_CONNECT_AFTER);

	return TRUE;
}
Пример #2
0
static void
biji_note_book_constructed (GObject *object)
{
  BijiNoteBook *self;
  BijiNoteBookPrivate *priv;
  BijiProvider *provider;
  gchar *filename;
  GFile *cache;
  GError *error;


  G_OBJECT_CLASS (biji_note_book_parent_class)->constructed (object);
  self = BIJI_NOTE_BOOK (object);
  priv = self->priv;
  error = NULL;

  /* If tracker fails for some reason,
   * do not attempt anything */
  priv->connection = tracker_sparql_connection_get (NULL, &error);

  if (error)
  {
    g_warning ("%s", error->message);
    g_error_free (error);
    priv->error = g_error_new (BIJI_ERROR, BIJI_ERROR_TRACKER, "Tracker is not available");
    return;
  }

  priv->log = biji_zeitgeist_init ();

  /* Ensure cache directory for icons */
  filename = g_build_filename (g_get_user_cache_dir (),
                               g_get_application_name (),
                               NULL);
  cache = g_file_new_for_path (filename);
  g_free (filename);
  g_file_make_directory (cache, NULL, NULL);
  g_object_unref (cache);

  provider = biji_local_provider_new (self, self->priv->location);
  _add_provider (self, provider);
}
Пример #3
0
static void
reader_engine_init (ReaderEngine *engine)
{
	ReaderEnginePrivate *priv;

	priv = reader_engine_get_instance_private (engine);

	/*
		TODO error handling
	*/
	priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
	priv->tracker = tracker_sparql_connection_get (NULL, NULL);

	priv->data = gtk_list_store_new (EXTRA_COLUMN_LAST,
	                                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
	                                 GDK_TYPE_PIXBUF, G_TYPE_LONG, G_TYPE_BOOLEAN, G_TYPE_INT,
	                                 G_TYPE_INT, G_TYPE_STRING, G_TYPE_POINTER);

	g_dbus_connection_signal_subscribe (priv->connection,
	                                    TRACKER_DBUS_SERVICE,
	                                    TRACKER_DBUS_INTERFACE_RESOURCES,
	                                    "GraphUpdated",
	                                    TRACKER_DBUS_OBJECT_RESOURCES,
	                                    "http://www.tracker-project.org/temp/mfo#FeedChannel",
	                                    G_DBUS_SIGNAL_FLAGS_NONE,
	                                    (GDBusSignalCallback) on_channel_update, engine, NULL);

	g_dbus_connection_signal_subscribe (priv->connection,
	                                    TRACKER_DBUS_SERVICE,
	                                    TRACKER_DBUS_INTERFACE_RESOURCES,
	                                    "GraphUpdated",
	                                    TRACKER_DBUS_OBJECT_RESOURCES,
	                                    "http://www.tracker-project.org/temp/mfo#FeedMessage",
	                                    G_DBUS_SIGNAL_FLAGS_NONE,
	                                    (GDBusSignalCallback) on_message_update, engine, NULL);

	collect_channels (engine, NULL);
}
Пример #4
0
static gboolean
tracker_controller_dbus_start (TrackerController   *controller,
                               GError             **error)
{
	TrackerControllerPrivate *priv;
	GError *err = NULL;
	GDBusInterfaceVTable interface_vtable = {
		handle_method_call,
		NULL, NULL
	};

	priv = controller->priv;

	priv->connection = tracker_sparql_connection_get (NULL, &err);

	if (!priv->connection) {
		g_propagate_error (error, err);
		return FALSE;
	}

	priv->d_connection = g_bus_get_sync (TRACKER_IPC_BUS, NULL, &err);

	if (!priv->d_connection) {
		g_propagate_error (error, err);
		return FALSE;
	}

	priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &err);
	if (!priv->introspection_data) {
		g_propagate_error (error, err);
		return FALSE;
	}

	g_message ("Registering D-Bus object...");
	g_message ("  Path:'" TRACKER_WRITEBACK_PATH "'");
	g_message ("  Object Type:'%s'", G_OBJECT_TYPE_NAME (controller));

	priv->registration_id =
		g_dbus_connection_register_object (priv->d_connection,
		                                   TRACKER_WRITEBACK_PATH,
		                                   priv->introspection_data->interfaces[0],
		                                   &interface_vtable,
		                                   controller,
		                                   NULL,
		                                   &err);

	if (err) {
		g_critical ("Could not register the D-Bus object "TRACKER_WRITEBACK_PATH", %s",
		            err ? err->message : "no error given.");
		g_propagate_error (error, err);
		return FALSE;
	}

	priv->bus_name_id =
		g_bus_own_name_on_connection (priv->d_connection,
		                              TRACKER_WRITEBACK_SERVICE,
		                              G_BUS_NAME_OWNER_FLAGS_NONE,
		                              bus_name_acquired_cb,
		                              bus_name_vanished_cb,
		                              controller, NULL);

	if (err) {
		g_critical ("Could not own the D-Bus name "TRACKER_WRITEBACK_SERVICE", %s",
		            err ? err->message : "no error given.");
		g_propagate_error (error, err);
		return FALSE;
	}

	return TRUE;
}
Пример #5
0
int main (int argc, char **argv)
{
	GtkWidget *window;
	GtkWidget *frame;
	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *list;
	GtkWidget *scroll;
	GtkWidget *setts;
	GtkWidget *adder;
	GtkListStore *model;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *col;
	GtkTreeSelection *selection;
	TrackerSparqlConnection *tracker;

	gtk_init (&argc, &argv);
	g_set_application_name ("Phidias Feeds Manager");

	tracker = tracker_sparql_connection_get (NULL, NULL);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
	gtk_container_add (GTK_CONTAINER (window), vbox);

	frame = gtk_frame_new ("Manage");
	gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
	gtk_container_add (GTK_CONTAINER (frame), hbox);

	list = gtk_tree_view_new ();
	renderer = gtk_cell_renderer_text_new ();
	col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", 1, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (list), col);
	scroll = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), list);
	gtk_box_pack_start (GTK_BOX (hbox), scroll, TRUE, TRUE, 0);

	setts = feed_settings_new ();
	gtk_box_pack_start (GTK_BOX (hbox), setts, FALSE, FALSE, 0);

	frame = gtk_frame_new ("Add");
	gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);

	adder = feeds_adder_new ();
	gtk_container_add (GTK_CONTAINER (frame), adder);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);

	model = gtk_list_store_new (7, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN);
	/*
		TODO	Sort elements by name
	*/
	gtk_tree_view_set_model (GTK_TREE_VIEW (list), GTK_TREE_MODEL (model));

	g_signal_connect (setts, "remove-feed", G_CALLBACK (feed_removed), tracker);
	g_signal_connect (setts, "save-feed", G_CALLBACK (feed_saved), tracker);
	g_signal_connect (setts, "update-feed", G_CALLBACK (feed_modified), model);
	g_signal_connect (selection, "changed", G_CALLBACK (feed_selected_cb), setts);
	g_signal_connect (window, "delete-event", G_CALLBACK (exit_all), setts);

	init_model (tracker, model);
	listen_tracker (model);
	tune_model (tracker, model);
	feeds_adder_wire_tracker (FEEDS_ADDER (adder), tracker);

	gtk_widget_show_all (window);
	gtk_main ();

	g_object_unref (tracker);

	exit (0);
}
Пример #6
0
int
main (int argc, char **argv)
{
	TrackerSparqlConnection *connection;
	GOptionContext *context;
	GError *error = NULL;
	gchar **p;

	g_type_init();

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, 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 (_("- Import data using Turtle files"));

	/* Translators: this message will appear after the usage string */
	/* and before the list of options.                              */
	g_option_context_add_main_entries (context, entries, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);

	if (print_version) {
		g_print ("\n" ABOUT "\n" LICENSE "\n");
		g_option_context_free (context);

		return EXIT_SUCCESS;
	}

	if (!filenames) {
		gchar *help;

		g_printerr ("%s\n\n",
		            _("One or more files have not been specified"));

		help = g_option_context_get_help (context, TRUE, NULL);
		g_option_context_free (context);
		g_printerr ("%s", help);
		g_free (help);

		return EXIT_FAILURE;
	}

	g_option_context_free (context);

	connection = tracker_sparql_connection_get (NULL, &error);

	if (!connection) {
		g_printerr ("%s: %s\n",
		            _("Could not establish a connection to Tracker"),
		            error ? error->message : _("No error given"));
		g_clear_error (&error);
		return EXIT_FAILURE;
	}

	for (p = filenames; *p; p++) {
		GError *error = NULL;
		GFile *file;

		g_print ("%s:'%s'\n",
		         _("Importing Turtle file"),
		         *p);

		file = g_file_new_for_commandline_arg (*p);
		tracker_sparql_connection_load (connection, file, NULL, &error);
		g_object_unref (file);

		if (error) {
			g_printerr ("  %s, %s\n",
			            _("Unable to import Turtle file"),
			            error->message);

			g_error_free (error);
			continue;
		}

		g_print ("  %s\n", _("Done"));
		g_print ("\n");
	}

	g_object_unref (connection);

	return EXIT_SUCCESS;
}
Пример #7
0
GHashTable *
tracker_sparql_get_prefixes (void)
{
    TrackerSparqlConnection *connection;
    TrackerSparqlCursor *cursor;
    GError *error = NULL;
    GHashTable *retval;
    const gchar *query;

    connection = tracker_sparql_connection_get (NULL, &error);

    if (!connection) {
        g_printerr ("%s: %s\n",
                    _("Could not establish a connection to Tracker"),
                    error ? error->message : _("No error given"));
        g_clear_error (&error);
        return NULL;
    }

    retval = g_hash_table_new_full (g_str_hash,
                                    g_str_equal,
                                    g_free,
                                    g_free);

    /* FIXME: Would like to get this in the same SPARQL that we
     * use to get the info, but doesn't seem possible at the
     * moment with the limited string manipulation features we
     * support in SPARQL.
     */
    query = "SELECT ?ns ?prefix "
            "WHERE {"
            "  ?ns a tracker:Namespace ;"
            "  tracker:prefix ?prefix "
            "}";

    cursor = tracker_sparql_connection_query (connection, query, NULL, &error);

    g_object_unref (connection);

    if (error) {
        g_printerr ("%s, %s\n",
                    _("Unable to retrieve namespace prefixes"),
                    error->message);

        g_error_free (error);
        return retval;
    }

    if (!cursor) {
        g_printerr ("%s\n", _("No namespace prefixes were returned"));
        return retval;
    }

    while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
        const gchar *key, *value;

        key = tracker_sparql_cursor_get_string (cursor, 0, NULL);
        value = tracker_sparql_cursor_get_string (cursor, 1, NULL);

        if (!key || !value) {
            continue;
        }

        g_hash_table_insert (retval,
                             g_strndup (key, strlen (key) - 1),
                             g_strdup (value));
    }

    if (cursor) {
        g_object_unref (cursor);
    }

    return retval;
}
gint
main (gint argc, gchar **argv)
{
	GTimer *array_t, *update_t;

	g_type_init ();

	connection = tracker_sparql_connection_get (NULL, NULL);

	g_print ("First run (first update then array)\n");

	tracker_sparql_connection_update (connection,
	                                  "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
	                                  0, NULL, NULL);

	update_t = g_timer_new ();
	test_tracker_sparql_update_async ();
	g_timer_stop (update_t);

	tracker_sparql_connection_update (connection,
	                                  "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
	                                  0, NULL, NULL);

	array_t = g_timer_new ();
	test_tracker_sparql_update_array_async ();
	g_timer_stop (array_t);

	tracker_sparql_connection_update (connection,
	                                  "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
	                                  0, NULL, NULL);

	g_print ("Array: %f, Update: %f\n", g_timer_elapsed (array_t, NULL), g_timer_elapsed (update_t, NULL));

	g_print ("Reversing run (first array then update)\n");

	g_timer_destroy (array_t);
	g_timer_destroy (update_t);

	array_t = g_timer_new ();
	test_tracker_sparql_update_array_async ();
	g_timer_stop (array_t);

	tracker_sparql_connection_update (connection,
	                                  "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
	                                  0, NULL, NULL);

	update_t = g_timer_new ();
	test_tracker_sparql_update_async ();
	g_timer_stop (update_t);

	tracker_sparql_connection_update (connection,
	                                  "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
	                                  0, NULL, NULL);

	g_print ("Array: %f, Update: %f\n", g_timer_elapsed (array_t, NULL), g_timer_elapsed (update_t, NULL));

	g_timer_destroy (array_t);
	g_timer_destroy (update_t);
	g_object_unref (connection);

	return 0;
}
Пример #9
0
static int
get_file_and_folder_count (int *files,
                           int *folders)
{
	TrackerSparqlConnection *connection;
	TrackerSparqlCursor *cursor;
	GError *error = NULL;

	connection = tracker_sparql_connection_get (NULL, &error);

	if (files) {
		*files = 0;
	}

	if (folders) {
		*folders = 0;
	}

	if (!connection) {
		g_printerr ("%s: %s\n",
		            _("Could not establish a connection to Tracker"),
		            error ? error->message : _("No error given"));
		g_clear_error (&error);
		return EXIT_FAILURE;
	}

	if (files) {
		const gchar query[] =
			"\nSELECT COUNT(?file) "
			"\nWHERE { "
			"\n  ?file a nfo:FileDataObject ;"
			"\n        tracker:available true ."
			"\n  FILTER (?file != nfo:Folder) "
			"\n}";

		cursor = tracker_sparql_connection_query (connection, query, NULL, &error);

		if (error || !tracker_sparql_cursor_next (cursor, NULL, NULL)) {
			g_printerr ("%s, %s\n",
			            _("Could not get basic status for Tracker"),
			            error->message);
			g_error_free (error);
			return EXIT_FAILURE;
		}

		*files = tracker_sparql_cursor_get_integer (cursor, 0);

		g_object_unref (cursor);
	}

	if (folders) {
		const gchar query[] =
			"\nSELECT COUNT(?folders)"
			"\nWHERE { "
			"\n  ?folders a nfo:Folder ;"
			"\n           tracker:available true ."
			"\n}";

		cursor = tracker_sparql_connection_query (connection, query, NULL, &error);

		if (error || !tracker_sparql_cursor_next (cursor, NULL, NULL)) {
			g_printerr ("%s, %s\n",
			            _("Could not get basic status for Tracker"),
			            error->message);
			g_error_free (error);
			return EXIT_FAILURE;
		}

		*folders = tracker_sparql_cursor_get_integer (cursor, 0);

		g_object_unref (cursor);
	}

	g_object_unref (connection);

	return EXIT_SUCCESS;
}
Пример #10
0
static int
collect_debug (void)
{
	/* What to collect?
	 * This is based on information usually requested from maintainers to users.
	 *
	 * 1. Package details, e.g. version.
	 * 2. Disk size, space left, type (SSD/etc)
	 * 3. Size of dataset (tracker-stats), size of databases
	 * 4. Current configuration (libtracker-fts, tracker-miner-fs, tracker-extract)
	 *    All txt files in ~/.cache/
	 * 5. Statistics about data (tracker-stats)
	 */

	GDir *d;
	gchar *data_dir;
	gchar *str;

	data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL);

	/* 1. Package details, e.g. version. */
	g_print ("[Package Details]\n");
	g_print ("%s: " PACKAGE_VERSION "\n", _("Version"));
	g_print ("\n\n");

	/* 2. Disk size, space left, type (SSD/etc) */
	guint64 remaining_bytes;
	gdouble remaining;

	g_print ("[%s]\n", _("Disk Information"));

	remaining_bytes = tracker_file_system_get_remaining_space (data_dir);
	str = g_format_size (remaining_bytes);

	remaining = tracker_file_system_get_remaining_space_percentage (data_dir);
	g_print ("%s: %s (%3.2lf%%)\n",
	         _("Remaining space on database partition"),
	         str,
	         remaining);
	g_free (str);
	g_print ("\n\n");

	/* 3. Size of dataset (tracker-stats), size of databases */
	g_print ("[%s]\n", _("Data Set"));

	for (d = g_dir_open (data_dir, 0, NULL); d != NULL;) {
		const gchar *f;
		gchar *path;
		goffset size;

		f = g_dir_read_name (d);
		if (!f) {
			break;
		}

		if (g_str_has_suffix (f, ".txt")) {
			continue;
		}

		path = g_build_filename (data_dir, f, NULL);
		size = tracker_file_get_size (path);
		str = g_format_size (size);

		g_print ("%s\n%s\n\n", path, str);
		g_free (str);
		g_free (path);
	}
	g_dir_close (d);
	g_print ("\n");

	/* 4. Current configuration (libtracker-fts, tracker-miner-fs, tracker-extract)
	 *    All txt files in ~/.cache/
	 */
	GSList *all, *l;

	g_print ("[%s]\n", _("Configuration"));

	all = tracker_gsettings_get_all (NULL);

	if (all) {
		for (l = all; l; l = l->next) {
			ComponentGSettings *c = l->data;
			gchar **keys, **p;

			if (!c) {
				continue;
			}

			keys = g_settings_list_keys (c->settings);
			for (p = keys; p && *p; p++) {
				GVariant *v;
				gchar *printed;

				v = g_settings_get_value (c->settings, *p);
				printed = g_variant_print (v, FALSE);
				g_print ("%s.%s: %s\n", c->name, *p, printed);
				g_free (printed);
				g_variant_unref (v);
			}
		}

		tracker_gsettings_free (all);
	} else {
		g_print ("** %s **\n", _("No configuration was found"));
	}
	g_print ("\n\n");

	g_print ("[%s]\n", _("States"));

	for (d = g_dir_open (data_dir, 0, NULL); d != NULL;) {
		const gchar *f;
		gchar *path;
		gchar *content = NULL;

		f = g_dir_read_name (d);
		if (!f) {
			break;
		}

		if (!g_str_has_suffix (f, ".txt")) {
			continue;
		}

		path = g_build_filename (data_dir, f, NULL);
		if (g_file_get_contents (path, &content, NULL, NULL)) {
			/* Special case last-index.txt which is time() dump to file */
			if (g_str_has_suffix (path, "last-crawl.txt")) {
				guint64 then, now;

				now = (guint64) time (NULL);
				then = g_ascii_strtoull (content, NULL, 10);
				str = tracker_seconds_to_string (now - then, FALSE);

				g_print ("%s\n%s (%s)\n\n", path, content, str);
			} else {
				g_print ("%s\n%s\n\n", path, content);
			}
			g_free (content);
		}
		g_free (path);
	}
	g_dir_close (d);
	g_print ("\n");

	/* 5. Statistics about data (tracker-stats) */
	TrackerSparqlConnection *connection;
	GError *error = NULL;

	g_print ("[%s]\n", _("Data Statistics"));

	connection = tracker_sparql_connection_get (NULL, &error);

	if (!connection) {
		g_print ("** %s, %s **\n",
		         _("No connection available"),
		         error ? error->message : _("No error given"));
		g_clear_error (&error);
	} else {
		TrackerSparqlCursor *cursor;

		cursor = tracker_sparql_connection_statistics (connection, NULL, &error);

		if (error) {
			g_print ("** %s, %s **\n",
			         _("Could not get statistics"),
			         error ? error->message : _("No error given"));
			g_error_free (error);
		} else {
			if (!cursor) {
				g_print ("** %s **\n",
				         _("No statistics were available"));
			} else {
				gint count = 0;

				while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
					g_print ("%s: %s\n",
					         tracker_sparql_cursor_get_string (cursor, 0, NULL),
					         tracker_sparql_cursor_get_string (cursor, 1, NULL));
					count++;
				}

				if (count == 0) {
					g_print ("%s\n",
					         _("Database is currently empty"));
				}

				g_object_unref (cursor);
			}
		}
	}

	g_object_unref (connection);
	g_print ("\n\n");

	g_print ("\n");

	g_free (data_dir);

	return EXIT_SUCCESS;
}
Пример #11
0
static int
status_stat (void)
{
	TrackerSparqlConnection *connection;
	TrackerSparqlCursor *cursor;
	GError *error = NULL;

	connection = tracker_sparql_connection_get (NULL, &error);

	if (!connection) {
		g_printerr ("%s: %s\n",
		            _("Could not establish a connection to Tracker"),
		            error ? error->message : _("No error given"));
		g_clear_error (&error);
		return EXIT_FAILURE;
	}

	cursor = tracker_sparql_connection_statistics (connection, NULL, &error);

	g_object_unref (connection);

	if (error) {
		g_printerr ("%s, %s\n",
		            _("Could not get Tracker statistics"),
		            error->message);
		g_error_free (error);
		return EXIT_FAILURE;
	}

	/* We use search terms on ALL ontologies not just common ones */
	if (terms && g_strv_length (terms) > 0) {
		show_all = TRUE;
	}

	if (!cursor) {
		g_print ("%s\n", _("No statistics available"));
	} else {
		GString *output;

		output = g_string_new ("");

		if (!show_all) {
			get_common_rdf_types ();
		}

		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
			const gchar *rdf_type;
			const gchar *rdf_type_count;

			rdf_type = tracker_sparql_cursor_get_string (cursor, 0, NULL);
			rdf_type_count = tracker_sparql_cursor_get_string (cursor, 1, NULL);

			if (!show_all && !g_hash_table_contains (common_rdf_types, rdf_type)) {
				continue;
			}

			if (terms) {
				gint i, n_terms;
				gboolean show_rdf_type = FALSE;

				n_terms = g_strv_length (terms);

				for (i = 0;
				     i < n_terms && !show_rdf_type;
				     i++) {
					show_rdf_type = g_str_match_string (terms[i], rdf_type, TRUE);
				}

				if (!show_rdf_type) {
					continue;
				}
			}

			g_string_append_printf (output,
			                        "  %s = %s\n",
			                        rdf_type,
			                        rdf_type_count);
		}

		if (output->len > 0) {
			/* To translators: This is to say there are no
			 * statistics found. We use a "Statistics:
			 * None" with multiple print statements */
			g_string_prepend (output, "\n");
			g_string_prepend (output, _("Statistics:"));
		} else {
			g_string_append_printf (output,
			                        "  %s\n", _("None"));
		}

		g_print ("%s\n", output->str);
		g_string_free (output, TRUE);

		if (common_rdf_types) {
			g_hash_table_unref (common_rdf_types);
		}

		g_object_unref (cursor);
	}

	return EXIT_SUCCESS;
}
Пример #12
0
int
main (int argc, char **argv)
{
	TrackerSparqlConnection *connection;
	TrackerSparqlCursor *cursor;
	GOptionContext *context;
	GError *error = NULL;

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, 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 statistics for all Nepomuk defined ontology classes"));
	g_option_context_add_main_entries (context, entries, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);

	if (print_version) {
		g_print ("\n" ABOUT "\n" LICENSE "\n");
		g_option_context_free (context);

		return EXIT_SUCCESS;
	}

	/* We use search terms on ALL ontologies not just common ones */
	if (terms && g_strv_length (terms) > 0) {
		show_all = TRUE;
	}

	g_option_context_free (context);

	connection = tracker_sparql_connection_get (NULL, &error);

	if (!connection) {
		g_printerr ("%s: %s\n",
		            _("Could not establish a connection to Tracker"),
		            error ? error->message : _("No error given"));
		g_clear_error (&error);
		return EXIT_FAILURE;
	}

	cursor = tracker_sparql_connection_statistics (connection, NULL, &error);

	if (error) {
		g_printerr ("%s, %s\n",
		            _("Could not get Tracker statistics"),
		            error->message);
		g_error_free (error);
		return EXIT_FAILURE;
	}

	if (!cursor) {
		g_print ("%s\n", _("No statistics available"));
	} else {
		GString *output;

		output = g_string_new ("");

		if (!show_all) {
			get_common_rdf_types ();
		}

		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
			const gchar *rdf_type;
			const gchar *rdf_type_count;

			rdf_type = tracker_sparql_cursor_get_string (cursor, 0, NULL);
			rdf_type_count = tracker_sparql_cursor_get_string (cursor, 1, NULL);

			if (!show_all && !g_hash_table_contains (common_rdf_types, rdf_type)) {
				continue;
			}

			if (terms) {
				gint i, n_terms;
				gboolean show_rdf_type = FALSE;

				n_terms = g_strv_length (terms);

				for (i = 0;
				     i < n_terms && !show_rdf_type;
				     i++) {
					show_rdf_type = g_str_match_string (terms[i], rdf_type, TRUE);
				}

				if (!show_rdf_type) {
					continue;
				}
			}

			g_string_append_printf (output,
			                        "  %s = %s\n",
			                        rdf_type,
			                        rdf_type_count);
		}

		if (output->len > 0) {
			/* To translators: This is to say there are no
			 * statistics found. We use a "Statistics:
			 * None" with multiple print statements */
			g_string_prepend (output, "\n");
			g_string_prepend (output, _("Statistics:"));
		} else {
			g_string_append_printf (output,
			                        "  %s\n", _("None"));
		}

		g_print ("%s\n", output->str);
		g_string_free (output, TRUE);

		if (common_rdf_types) {
			g_hash_table_unref (common_rdf_types);
		}

		g_object_unref (cursor);
	}

	g_object_unref (connection);

	return EXIT_SUCCESS;
}
Пример #13
0
int
main (int argc, char **argv)
{
	gchar *log_filename;
	GMainLoop *loop;
	GOptionContext *context;
	TrackerMinerRSS *miner;
	GError *error = NULL;
	const gchar *error_message;

	g_type_init();

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	tzset ();

	/* Translators: this messagge will apper immediately after the
	 * usage string - Usage: COMMAND <THIS_MESSAGE>
	 */
	context = g_option_context_new (_("- start the feeds indexer"));
	g_option_context_add_main_entries (context, entries, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);

	if ((add_feed && !title) || (!add_feed && title)) {
		error_message = _("Adding a feed requires --add-feed and --title");
	} else {
		error_message = NULL;
	}

	if (error_message) {
		gchar *help;

		g_printerr ("%s\n\n", error_message);

		help = g_option_context_get_help (context, TRUE, NULL);
		g_option_context_free (context);
		g_printerr ("%s", help);
		g_free (help);

		return EXIT_FAILURE;
	}

	g_option_context_free (context);

	/* Command line stuff doesn't use logging, so we're using g_print*() */
	if (add_feed && title) {
		TrackerSparqlConnection *connection;
		const gchar *query;

		g_print ("Adding feed:\n"
		         "  title:'%s'\n"
		         "  url:'%s'\n",
		         title,
		         add_feed);

		connection = tracker_sparql_connection_get (NULL, &error);

		if (!connection) {
			g_printerr ("%s: %s\n",
			            _("Could not establish a connection to Tracker"),
			            error ? error->message : _("No error given"));
			g_clear_error (&error);
			return EXIT_FAILURE;
		}

		/* FIXME: Make interval configurable */
		query = g_strdup_printf ("INSERT {"
		                         "  _:FeedSettings a mfo:FeedSettings ;"
		                         "                   mfo:updateInterval 20 ."
		                         "  _:Feed a nie:DataObject, mfo:FeedChannel ;"
		                         "           mfo:feedSettings _:FeedSettings ;"
		                         "           nie:url \"%s\" ;"
		                         "           nie:title \"%s\" . "
		                         "}",
		                         add_feed,
		                         title);

		tracker_sparql_connection_update (connection,
		                                  query,
		                                  G_PRIORITY_DEFAULT,
		                                  NULL,
		                                  &error);

		if (error) {
			g_printerr ("%s, %s\n",
			            _("Could not add feed"),
			            error->message);
			g_error_free (error);
			g_object_unref (connection);

			return EXIT_FAILURE;
		}

		g_print ("Done\n");

		return EXIT_SUCCESS;
	}

	tracker_log_init (verbosity, &log_filename);
	if (log_filename != NULL) {
		g_message ("Using log file:'%s'", log_filename);
		g_free (log_filename);
	}

	miner = tracker_miner_rss_new (&error);
	if (!miner) {
		g_critical ("Could not create new RSS miner: '%s', exiting...\n",
		            error ? error->message : "unknown error");
		return EXIT_FAILURE;
	}

	tracker_miner_start (TRACKER_MINER (miner));

	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);

	tracker_log_shutdown ();
	g_main_loop_unref (loop);
	g_object_unref (miner);

	return EXIT_SUCCESS;
}