Exemplo n.º 1
0
static void
handle_channel_deletes (ReaderEngine *engine,
                        gint sub)
{
	gchar *query;
	const gchar *subject;
	GtkTreeIter *iter;
	TrackerSparqlCursor *cursor;
	ReaderEnginePrivate *priv;

	priv = reader_engine_get_instance_private (engine);

	query = g_strdup_printf ("SELECT tracker:uri(%d) {}", sub);
	cursor = tracker_sparql_connection_query (priv->tracker, query, NULL, NULL);
	tracker_sparql_cursor_next (cursor, NULL, NULL);
	subject = tracker_sparql_cursor_get_string (cursor, 0, NULL);

	if (find_in_model (GTK_TREE_MODEL (priv->data), GD_MAIN_COLUMN_ID, subject, &iter)) {
		remove_channel_data (GTK_TREE_MODEL (priv->data), iter);
		gtk_list_store_remove (priv->data, iter);
		gtk_tree_iter_free (iter);
	}

	g_free (query);
	g_object_unref (cursor);
}
void QGalleryTrackerResultSetPrivate::run()
{
    iCache.values.clear();

    GError *error = 0;
    if (TrackerSparqlCursor *cursor = tracker_sparql_connection_query(
                connection, sparql.toUtf8(), 0, &error)) {
        const QVariant variant;
        while (tracker_sparql_cursor_next(cursor, 0, 0)) {
            const int rowWidth = qMin(tableWidth, tracker_sparql_cursor_get_n_columns(cursor));
            int i = 0;
            for (; i < rowWidth; ++i) {
                iCache.values.append(valueColumns.at(i)->toVariant(cursor, i));
            }
            for (; i < tableWidth; ++i)
                iCache.values.append(variant);
        }
        g_object_unref(G_OBJECT(cursor));
    } else {
        queryError = QDocumentGallery::FilterError;
        queryErrorString = QString::fromUtf8(error->message);
        g_error_free(error);
    }

    iCache.count = iCache.values.count() / tableWidth;

    synchronize();
}
Exemplo n.º 3
0
static gchar *
get_class_from_prefix (TrackerSparqlConnection *connection,
                       const gchar             *prefix)
{
    GError *error = NULL;
    TrackerSparqlCursor *cursor;
    const gchar *query;
    gchar *found = NULL;

    query = "SELECT ?prefix ?ns "
            "WHERE {"
            "  ?ns a tracker:Namespace ;"
            "  tracker:prefix ?prefix "
            "}";

    /* We have namespace prefix, get full name */
    cursor = tracker_sparql_connection_query (connection, query, NULL, &error);

    if (error) {
        g_printerr ("%s, %s\n",
                    _("Could not get namespace prefixes"),
                    error->message);
        g_error_free (error);

        return NULL;
    }

    if (!cursor) {
        g_printerr ("%s\n",
                    _("No namespace prefixes were found"));

        return NULL;
    }

    while (tracker_sparql_cursor_next (cursor, NULL, NULL) && !found) {
        const gchar *class_prefix, *class_name;

        class_prefix = tracker_sparql_cursor_get_string (cursor, 0, NULL);
        class_name = tracker_sparql_cursor_get_string (cursor, 1, NULL);

        if (strcmp (class_prefix, prefix) == 0) {
            found = g_strdup (class_name);
        }
    }

    g_object_unref (cursor);

    return found;
}
Exemplo n.º 4
0
static void
item_warn (TrackerSparqlConnection *conn,
           gint                     id,
           const gchar             *sparql,
           const GError            *error)
{
	TrackerSparqlCursor *cursor;
	const gchar *elem;
	gchar *query;

	query = g_strdup_printf ("SELECT COALESCE (nie:url (?u), ?u) {"
	                         "  ?u a rdfs:Resource. "
	                         "  FILTER (tracker:id (?u) = %d)"
	                         "}", id);

	cursor = tracker_sparql_connection_query (conn, query, NULL, NULL);
	g_free (query);

	g_debug ("--8<------------------------------");
	g_debug ("The information relevant for a bug report is between "
	         "the dotted lines");

	if (cursor &&
	    tracker_sparql_cursor_next (cursor, NULL, NULL)) {
		elem = tracker_sparql_cursor_get_string (cursor, 0, NULL);
		g_warning ("Could not insert metadata for item \"%s\": %s",
		           elem, error->message);
	} else {
		g_warning ("Could not insert metadata for item with ID %d: %s",
		           id, error->message);
	}

	g_warning ("If the error above is recurrent for the same item/ID, "
	           "consider running \"%s\" in the terminal with the "
	           "TRACKER_VERBOSITY=3 environment variable, and filing a "
	           "bug with the additional information", g_get_prgname ());

	g_debug ("Sparql was:\n%s", sparql);
	g_debug ("NOTE: The information above may contain data you "
	         "consider sensitive. Feel free to edit it out, but please "
	         "keep it as unmodified as you possibly can.");
	g_debug ("------------------------------>8--");

	g_clear_object (&cursor);
}
void QTrackerDirectSyncResult::selectQuery()
{
    if (!driverPrivate->driver->isOpen()) {
        setLastError(QSparqlError(driverPrivate->error,
                                  QSparqlError::ConnectionError));
        return;
    }

    GError * error = 0;
    cursor = tracker_sparql_connection_query(driverPrivate->connection, query().toUtf8().constData(), 0, &error);
    if (error || !cursor) {
        setLastError(QSparqlError(QString::fromUtf8(error ? error->message : "unknown error"),
                        error ? errorCodeToType(error->code) : QSparqlError::StatementError,
                        error ? error->code : -1));
        if (error)
            g_error_free(error);
        qWarning() << "QTrackerDirectSyncResult:" << lastError() << query();
    }
}
Exemplo n.º 6
0
static void
handle_channel_inserts (ReaderEngine *engine,
                        gint sub)
{
	gchar *query;
	const gchar *subject;
	TrackerSparqlCursor *cursor;
	ReaderEnginePrivate *priv;

	priv = reader_engine_get_instance_private (engine);

	query = g_strdup_printf ("SELECT tracker:uri(%d) {}", sub);
	cursor = tracker_sparql_connection_query (priv->tracker, query, NULL, NULL);
	tracker_sparql_cursor_next (cursor, NULL, NULL);
	subject = tracker_sparql_cursor_get_string (cursor, 0, NULL);
	collect_channels (engine, subject);

	g_free (query);
	g_object_unref (cursor);
}
Exemplo n.º 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;
}
Exemplo n.º 8
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;
}