static void
photos_properties_dialog_location_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor = NULL; /* TODO: use g_autoptr */

  {
    g_autoptr (GError) error = NULL;

    cursor = tracker_sparql_connection_query_finish (connection, res, &error);
    if (error != NULL)
      {
        g_warning ("Unable to query latitude and longitude: %s", error->message);
        goto out;
      }
  }

  tracker_sparql_cursor_next_async (cursor,
                                    self->cancellable,
                                    photos_properties_dialog_location_cursor_next,
                                    self);

 out:
  g_clear_object (&cursor);
}
static void
query_callback (GObject      *object,
                GAsyncResult *result,
                gpointer      user_data)
{
	NemoSearchEngineTracker *tracker;
	TrackerSparqlConnection *connection;
	TrackerSparqlCursor *cursor;
	GError *error = NULL;

	tracker = NEMO_SEARCH_ENGINE_TRACKER (user_data);

	connection = TRACKER_SPARQL_CONNECTION (object);
	cursor = tracker_sparql_connection_query_finish (connection,
	                                                 result,
	                                                 &error);

	if (error) {
		tracker->details->query_pending = FALSE;
		nemo_search_engine_error (NEMO_SEARCH_ENGINE (tracker), error->message);
		g_error_free (error);
		return;
	}

	if (!cursor) {
		tracker->details->query_pending = FALSE;
		nemo_search_engine_finished (NEMO_SEARCH_ENGINE (tracker));
		return;
	}

	cursor_next (tracker, cursor);
}
Example #3
0
static void
query_cb (GObject      *object,
          GAsyncResult *res,
          gpointer      user_data)
{
	TrackerSparqlCursor *cursor;
	GError *error = NULL;
	MyData *md = user_data;

	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object),
	                                                 res,
	                                                 &error);
	g_print ("Async query took: %.6f\n", g_timer_elapsed (md->timer, NULL));

	g_timer_start (md->timer);

	if (!error) {
		tracker_sparql_cursor_next_async (cursor,
		                                  md->cancellable,
		                                  cursor_cb,
		                                  md);
	} else {
		g_critical ("Could not run query: %s", error->message);

		if (cursor) {
			g_object_unref (cursor);
		}

		g_error_free (error);
		g_main_loop_quit (md->loop);
	}
}
Example #4
0
static void find_channel_and_update (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
	gchar **values;
	GtkTreeModel *model;
	GtkTreeIter iter;
	TrackerSparqlCursor *cursor;
	GError *error;

	error = NULL;
	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object), res, &error);

	if (error != NULL) {
		g_warning ("Unable to update channel: %s", error->message);
		g_error_free (error);
		return;
	}

	model = user_data;

	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
		if (retrive_row_by_id (model, tracker_sparql_cursor_get_string (cursor, 0, NULL), &iter) == TRUE) {
			gtk_list_store_set (GTK_LIST_STORE (model), &iter,
					    PREDICATE_NAME, tracker_sparql_cursor_get_string (cursor, 1, NULL),
					    PREDICATE_DOWNLOAD, tracker_sparql_cursor_get_boolean (cursor, 2),
					    PREDICATE_DOWNPATH, tracker_sparql_cursor_get_string (cursor, 3, NULL),
					    PREDICATE_MAXSIZE, tracker_sparql_cursor_get_double (cursor, 4),
					    PREDICATE_EXPIRY, tracker_sparql_cursor_get_double (cursor, 5),
					    6, FALSE, -1);
		}
	}
}
static void
photos_fetch_ids_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  GTask *task = G_TASK (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor; /* TODO: Use g_autoptr */
  GError *error;

  cancellable = g_task_get_cancellable (task);

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  tracker_sparql_cursor_next_async (cursor,
                                    cancellable,
                                    photos_fetch_ids_job_cursor_next,
                                    g_object_ref (task));
  g_object_unref (cursor);
}
static void
do_sparql_query_async_cursor_cb (GObject      *const object,
                                 GAsyncResult *const result,
                                 GTask        *const task)
{

  g_autoptr(GError) error = NULL;

  SparqlQueryWork *const work = sparql_query_work_get (task);
  TrackerSparqlConnection *const conn = work->connection;

  TrackerSparqlCursor *const cur = tracker_sparql_connection_query_finish (
    conn,
    result,
    &error
  );

  if (error) {
    g_task_return_error (task, g_error_copy (error));
    return;
  }

  g_task_return_pointer (task, cur, g_object_unref);

}
Example #7
0
static void
decorator_query_remaining_items_cb (GObject      *object,
                                    GAsyncResult *result,
                                    gpointer      user_data)
{
	TrackerDecorator *decorator = user_data;
	TrackerDecoratorPrivate *priv;
	TrackerSparqlCursor *cursor;
	GError *error = NULL;

	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object),
							 result, &error);
	priv = decorator->priv;
        priv->querying = FALSE;

	if (error || !tracker_sparql_cursor_next (cursor, NULL, &error)) {
		decorator_notify_task_error (decorator, error);
		g_error_free (error);
		return;
	}

	priv->n_remaining_items = g_queue_get_length (&priv->item_cache) +
		tracker_sparql_cursor_get_integer (cursor, 0);
	g_object_unref (cursor);

	g_debug ("Found %ld items to extract", priv->n_remaining_items);

	if (priv->n_remaining_items > 0)
		decorator_cache_next_items (decorator);
	else
		decorator_finish (decorator);
}
static void
tracker_evt_preupdate_sources_cb (GObject              *object,
                                  GAsyncResult         *result,
                                  tracker_evt_update_t *evt)
{
  GError *error = NULL;

  GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt);

  evt->cursor = tracker_sparql_connection_query_finish (grl_tracker_connection,
                                                        result, &error);

  if (error != NULL) {
    GRL_WARNING ("\tCannot handle datasource request : %s", error->message);

    g_error_free (error);

    tracker_evt_update_items (evt);
    tracker_evt_update_orphans (evt);
    return;
  }

  tracker_sparql_cursor_next_async (evt->cursor, NULL,
                                    (GAsyncReadyCallback) tracker_evt_preupdate_sources_item_cb,
                                    (gpointer) evt);
}
Example #9
0
static void fill_model_with_channels (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
	int i;
	GtkWidget *dialog;
	GtkListStore *list;
	TrackerSparqlCursor *cursor;
	GError *error;

	error = NULL;
	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object), res, &error);

	if (error != NULL) {
		dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Unable to fetch data about current feeds:\n%s", error->message);
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "Is Tracker running?");
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
		g_error_free (error);
		return;
	}

	list = user_data;

	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
		gtk_list_store_insert_with_values (list, NULL, G_MAXINT,
						   PREDICATE_SUBJECT, tracker_sparql_cursor_get_string (cursor, 0, NULL),
						   PREDICATE_NAME, tracker_sparql_cursor_get_string (cursor, 1, NULL),
						   PREDICATE_DOWNLOAD, tracker_sparql_cursor_get_boolean (cursor, 2),
						   PREDICATE_DOWNPATH, tracker_sparql_cursor_get_string (cursor, 3, NULL),
						   PREDICATE_MAXSIZE, tracker_sparql_cursor_get_double (cursor, 4),
						   PREDICATE_EXPIRY, tracker_sparql_cursor_get_double (cursor, 5),
						   6, FALSE, -1);
	}
}
Example #10
0
static void
verify_tracker_update (GObject *source,
                       GAsyncResult *res,
                       gpointer unused)
{
	GError *error = NULL;

	tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source), res, &error);

	if (error != NULL) {
		g_warning ("Unable to update Tracker: %s", error->message);
		g_error_free (error);
	}
}
Example #11
0
static void
on_fetch_channels (GObject *source,
                   GAsyncResult *res,
                   ReaderEngine *engine)
{
	TrackerSparqlCursor *cursor;
	GError *error = NULL;

	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source), res, &error);

	if (error != NULL) {
		g_warning ("Unable to fetch channels from Tracker: %s", error->message);
		g_error_free (error);
	}
	else {
		pass_channels (engine, cursor);
	}
}
Example #12
0
static void
photos_camera_cache_equipment_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GTask *task = G_TASK (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor;
  GError *error;

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  tracker_sparql_cursor_next_async (cursor, NULL, photos_camera_cache_cursor_next, g_object_ref (task));
  g_object_unref (cursor);
}
static void
photos_offset_controller_reset_count_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosOffsetController *self = PHOTOS_OFFSET_CONTROLLER (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor;
  GError *error;

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      g_error_free (error);
      return;
    }

  tracker_sparql_cursor_next_async (cursor, NULL, photos_offset_controller_cursor_next, g_object_ref (self));
  g_object_unref (cursor);
}
Example #14
0
static void
query_callback (GObject      *object,
                GAsyncResult *result,
                gpointer      user_data)
{
  GtkSearchEngineTracker *tracker;
  TrackerSparqlConnection *connection;
  TrackerSparqlCursor *cursor;
  GError *error = NULL;

  gdk_threads_enter ();

  tracker = GTK_SEARCH_ENGINE_TRACKER (user_data);

  tracker->priv->query_pending = FALSE;

  connection = TRACKER_SPARQL_CONNECTION (object);
	cursor = tracker_sparql_connection_query_finish (connection,
	                                                 result,
	                                                 &error);

	g_debug ("Query returned cursor:%p", cursor);

  if (error)
    {
      _gtk_search_engine_error (GTK_SEARCH_ENGINE (tracker), error->message);
      g_error_free (error);
      gdk_threads_leave ();
      return;
    }

  if (!cursor)
	  {
		  _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker));
		  gdk_threads_leave ();
		  return;
	  }

  cursor_next (tracker, cursor);
  gdk_threads_leave ();
}
static void
photos_tracker_controller_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  GError *error;
  TrackerSparqlCursor *cursor;

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      photos_tracker_controller_query_finished (self, error);
      g_error_free (error);
      return;
    }

  tracker_sparql_cursor_next_async (cursor,
                                    self->priv->cancellable,
                                    photos_tracker_controller_cursor_next,
                                    g_object_ref (self));
  g_object_unref (cursor);
}
static void
photos_import_dialog_fetch_collections_local_query_executed (GObject *source_object,
                                                             GAsyncResult *res,
                                                             gpointer user_data)
{
  PhotosImportDialog *self;
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor = NULL; /* TODO: use g_autoptr */

  {
    g_autoptr (GError) error = NULL;

    cursor = tracker_sparql_connection_query_finish (connection, res, &error);
    if (error != NULL)
      {
        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
          g_warning ("Unable to fetch local collections: %s", error->message);

        goto out;
      }
  }

  self = PHOTOS_IMPORT_DIALOG (user_data);

  if (cursor == NULL)
    goto out;

  tracker_sparql_cursor_next_async (cursor,
                                    self->cancellable,
                                    photos_import_dialog_fetch_collections_local_cursor_next,
                                    self);

 out:
  g_clear_object (&cursor);
  return;
}
Example #17
0
static void
decorator_cache_items_cb (GObject      *object,
                          GAsyncResult *result,
                          gpointer      user_data)
{
	TrackerDecorator *decorator = user_data;
	TrackerDecoratorPrivate *priv;
	TrackerSparqlConnection *conn;
	TrackerSparqlCursor *cursor;
	TrackerDecoratorInfo *info;
	GError *error = NULL;

	conn = TRACKER_SPARQL_CONNECTION (object);
	cursor = tracker_sparql_connection_query_finish (conn, result, &error);
	priv = decorator->priv;
        priv->querying = FALSE;

	if (error) {
		decorator_notify_task_error (decorator, error);
		g_error_free (error);
	} else {
		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
			info = tracker_decorator_info_new (decorator, cursor);
			g_queue_push_tail (&priv->item_cache, info);
		}
	}

	if (!g_queue_is_empty (&priv->item_cache) && !priv->processing) {
		decorator_start (decorator);
	} else if (g_queue_is_empty (&priv->item_cache) && priv->processing) {
		decorator_finish (decorator);
	}

	decorator_pair_tasks (decorator);
	g_object_unref (cursor);
}
Example #18
0
static void
set_new_read_status (GObject *source,
                     GAsyncResult *res,
                     ItemStatusUpdate *update)
{
	gchar *query;
	GError *error = NULL;

	tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source), res, &error);

	if (error != NULL) {
		g_warning ("Unable to update status of item in Tracker: %s", error->message);
		g_error_free (error);
	}
	else {
		query = g_strdup_printf ("INSERT {<%s> nmo:isRead %s}", update->id, update->read ? "true" : "false");
		tracker_sparql_connection_update_async (TRACKER_SPARQL_CONNECTION (source), query, 0, NULL,
		                                        (GAsyncReadyCallback) verify_tracker_update, NULL);
		g_free (query);
	}

	g_free (update->id);
	g_free (update);
}
static void
photos_fetch_collections_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosFetchCollectionsJob *self = PHOTOS_FETCH_COLLECTIONS_JOB (user_data);
  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
  TrackerSparqlCursor *cursor;
  GError *error;

  error = NULL;
  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
  if (error != NULL)
    {
      g_warning ("Unable to fetch collections: %s", error->message);
      g_error_free (error);
      photos_fetch_collections_job_emit_callback (self);
      return;
    }

  tracker_sparql_cursor_next_async (cursor,
                                    NULL,
                                    photos_fetch_collections_job_cursor_next,
                                    g_object_ref (self));
  g_object_unref (cursor);
}
Example #20
0
static void
on_query_finished (GObject      *source_object,
                   GAsyncResult *res,
                   gpointer      user_data)
{
	GError *error = NULL;
	TrackerSparqlCursor *cursor = NULL;
	GDir *dir = NULL;
	GHashTable *table = NULL;
	const gchar *name;
	gchar *dirname = NULL;
	GList *to_remove = NULL;

	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object),
	                                                 res,
	                                                 &error);

	if (error) {
		goto on_error;
	}

	dirname = g_build_filename (g_get_user_cache_dir (),
	                            "media-art",
	                            NULL);

	if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
		/* Ignore this and just quit the function */
		goto on_error;
	}

	dir = g_dir_open (dirname, 0, &error);

	if (error) {
		goto on_error;
	}

	table = g_hash_table_new_full (g_str_hash,
	                               g_str_equal,
	                               (GDestroyNotify) g_free,
	                               (GDestroyNotify) NULL);

	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
		gchar *target = NULL, *album_path = NULL;
		const gchar *album, *artist;

		album = tracker_sparql_cursor_get_string (cursor, 0, NULL);
		artist = tracker_sparql_cursor_get_value_type (cursor, 1) != TRACKER_SPARQL_VALUE_TYPE_UNBOUND ? tracker_sparql_cursor_get_string (cursor, 1, NULL) : NULL;

		/* The get_path API does stripping itself */
		media_art_get_path (artist,
		                    album,
		                    "album", NULL,
		                    &target, NULL);

		g_hash_table_replace (table, target, target);

		/* Also add the file to which the symlinks are made */
		media_art_get_path (NULL,
		                    album,
		                    "album", NULL,
		                    &album_path, NULL);


		g_hash_table_replace (table, album_path, album_path);
	}

	/* Perhaps we should have an internal list of media art files that we made,
	 * instead of going over all the media art (which could also have been made
	 * by other softwares) */

	for (name = g_dir_read_name (dir); name != NULL; name = g_dir_read_name (dir)) {
		gpointer value;
		gchar *full;

		full = g_build_filename (dirname, name, NULL);

		value = g_hash_table_lookup (table, full);

		if (!value) {
			g_message ("Removing media-art file %s: no album exists that has "
			           "any songs for this media-art cache", name);
			to_remove = g_list_prepend (to_remove, (gpointer) full);
		} else {
			g_free (full);
		}
	}

	g_list_foreach (to_remove, (GFunc) g_unlink, NULL);
	g_list_foreach (to_remove, (GFunc) g_free, NULL);
	g_list_free (to_remove);

on_error:

	g_free (dirname);

	if (table) {
		g_hash_table_unref (table);
	}

	if (cursor) {
		g_object_unref (cursor);
	}

	if (dir) {
		g_dir_close (dir);
	}

	if (error) {
		g_critical ("Error running cleanup of media-art: %s",
		            error->message ? error->message : "No error given");
		g_error_free (error);
	}
}