static void
photos_single_item_job_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GTask *task = G_TASK (user_data);
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  GDestroyNotify result_destroy = NULL;
  GError *error;
  gboolean success;
  gpointer result = NULL;

  error = NULL;
  /* Note that tracker_sparql_cursor_next_finish can return FALSE even
   * without an error.
   */
  success = tracker_sparql_cursor_next_finish (cursor, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      goto out;
    }

  if (success)
    {
      result = g_object_ref (cursor);
      result_destroy = g_object_unref;
    }

  g_task_return_pointer (task, result, result_destroy);

 out:
  g_object_unref (task);
}
static void
photos_tracker_controller_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (user_data);
  PhotosTrackerControllerPrivate *priv = self->priv;
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  gboolean valid;
  gint64 now;

  valid = tracker_sparql_cursor_next_finish (cursor, res, NULL); /* TODO: use GError */
  if (!valid)
    {
      tracker_sparql_cursor_close (cursor);
      photos_tracker_controller_query_finished (self, NULL);
      g_object_unref (self);
      return;
    }

  now = g_get_monotonic_time ();
  photos_debug (PHOTOS_DEBUG_TRACKER, "Query Cursor: %" G_GINT64_FORMAT, (now - priv->last_query_time) / 1000000);

  photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor);
  tracker_sparql_cursor_next_async (cursor,
                                    priv->cancellable,
                                    photos_tracker_controller_cursor_next,
                                    self);
}
static void
load_integer_value_next_cb (TrackerSparqlCursor *const cursor,
                            GAsyncResult        *const result,
                            GTask               *const task)
{

  g_autoptr(GError) error = NULL;

  gboolean const more = tracker_sparql_cursor_next_finish (
    cursor,
    result,
    &error
  );

  if (!more) {
    nul_warning ("no more rows to load");
    g_task_return_int (task, -1);
    return;
  }

  gint64 const integer = tracker_sparql_cursor_get_integer (cursor, 0);

  g_task_return_int (task, integer);

}
static void
photos_fetch_collections_job_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosFetchCollectionsJob *self = PHOTOS_FETCH_COLLECTIONS_JOB (user_data);
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  GError *error;
  gboolean valid;
  gchar *urn;

  error = NULL;
  valid = tracker_sparql_cursor_next_finish (cursor, res, &error);
  if (error != NULL)
    {
      g_warning ("Unable to fetch collections: %s", error->message);
      g_error_free (error);
      goto end;
    }
  if (!valid)
    goto end;

  urn = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
  self->collections = g_list_prepend (self->collections, urn);

  tracker_sparql_cursor_next_async (cursor,
                                    NULL,
                                    photos_fetch_collections_job_cursor_next,
                                    self);
  return;

 end:
  self->collections = g_list_reverse (self->collections);
  photos_fetch_collections_job_emit_callback (self);
  tracker_sparql_cursor_close (cursor);
  g_object_unref (self);
}
static void
photos_import_dialog_fetch_collections_local_cursor_next (GObject *source_object,
                                                          GAsyncResult *res,
                                                          gpointer user_data)
{
  PhotosImportDialog *self;
  g_autoptr (PhotosBaseItem) collection = NULL;
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  gboolean success;
  const gchar *identifier;
  g_autofree gchar *identifier_time = NULL;

  {
    g_autoptr (GError) error = NULL;

    /* Note that tracker_sparql_cursor_next_finish can return FALSE even
     * without an error.
     */
    success = tracker_sparql_cursor_next_finish (cursor, 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 (!success)
    {
      photos_import_dialog_initialize_index_and_popover (self);
      goto out;
    }

  collection = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), G_TYPE_NONE, cursor, FALSE);
  photos_import_dialog_add_collection (self, collection);

  identifier = photos_base_item_get_identifier (collection);
  identifier_time = g_strdup_printf ("%s%" G_GINT64_FORMAT, PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER, self->time);
  if (g_strcmp0 (identifier, identifier_time) == 0)
    {
      const gchar *id;

      id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection));
      photos_debug (PHOTOS_DEBUG_IMPORT, "Default collection already exists: %s", id);
      g_set_object (&self->default_collection, collection);
    }

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

 out:
  return;
}
示例#6
0
static void
cursor_cb (GObject      *object,
           GAsyncResult *res,
           gpointer      user_data)
{
	TrackerSparqlCursor *cursor;
	GError *error = NULL;
	MyData *md = user_data;
	gboolean more_results;

	cursor = TRACKER_SPARQL_CURSOR (object);
	more_results = tracker_sparql_cursor_next_finish (cursor,
	                                                  res,
	                                                  &error);

	if (!error) {
		static gint i = 0;

		if (more_results) {
			if (i++ < 5) {
				if (i == 1) {
					g_print ("Printing first 5 results:\n");
				}

				g_print ("  %s\n", tracker_sparql_cursor_get_string (cursor, 0, NULL));

				if (i == 5) {
					g_print ("  ...\n");
					g_print ("  Printing nothing for remaining results\n");
				}
			}

			tracker_sparql_cursor_next_async (cursor,
			                                  md->cancellable,
			                                  cursor_cb,
			                                  md);
		} else {
			g_print ("\n");
			g_print ("Async cursor next took: %.6f (for all %d results)\n",
			         g_timer_elapsed (md->timer, NULL), i);

			g_object_unref (cursor);
			g_main_loop_quit (md->loop);
		}
	} else {
		g_critical ("Could not run cursor next: %s", error->message);

		if (cursor) {
			g_object_unref (cursor);
		}

		g_error_free (error);
		g_main_loop_quit (md->loop);
	}
}
示例#7
0
static void
cursor_callback (GObject      *object,
                 GAsyncResult *result,
                 gpointer      user_data)
{
  GtkSearchEngineTracker *tracker;
  GError *error = NULL;
  TrackerSparqlCursor *cursor;
	GList *hits;
  gboolean success;

  gdk_threads_enter ();

  tracker = GTK_SEARCH_ENGINE_TRACKER (user_data);

	cursor = TRACKER_SPARQL_CURSOR (object);
	success = tracker_sparql_cursor_next_finish (cursor, result, &error);

  if (error)
    {
      _gtk_search_engine_error (GTK_SEARCH_ENGINE (tracker), error->message);

      g_error_free (error);

      if (cursor)
	      g_object_unref (cursor);

      gdk_threads_leave ();
      return;
    }

  if (!success)
	  {
		  _gtk_search_engine_finished (GTK_SEARCH_ENGINE (tracker));

		  if (cursor)
			  g_object_unref (cursor);

		  gdk_threads_leave ();
		  return;
	  }

  /* We iterate result by result, not n at a time. */
  hits = g_list_append (NULL, (gchar*) tracker_sparql_cursor_get_string (cursor, 0, NULL));
  _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (tracker), hits);
  g_list_free (hits);

  /* Get next */
  cursor_next (tracker, cursor);

  gdk_threads_leave ();

}
static void
photos_properties_dialog_location_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosPropertiesDialog *self;
  g_autoptr (GeocodeLocation) location = NULL;
  g_autoptr (GeocodeReverse) reverse = NULL;
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  gboolean success;
  gdouble latitude;
  gdouble longitude;

  {
    g_autoptr (GError) error = NULL;

    /* Note that tracker_sparql_cursor_next_finish can return FALSE even
     * without an error.
     */
    success = tracker_sparql_cursor_next_finish (cursor, res, &error);
    if (error != NULL)
      {
        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
          g_warning ("Unable to read latitude and longitude: %s", error->message);
        goto out;
      }
  }

  self = PHOTOS_PROPERTIES_DIALOG (user_data);

  /* Note that the following SPARQL query:
   *   SELECT slo:latitude (<(foo)>) slo:longitude (<(foo)>) WHERE {}
   * ... will not return an empty cursor, but:
   *   (null), (null)
   */
  if (!success)
    {
      g_warning ("Cursor is empty — possibly wrong SPARQL query");
      goto out;
    }

  latitude = tracker_sparql_cursor_get_double (cursor, 0);
  longitude = tracker_sparql_cursor_get_double (cursor, 1);
  location = geocode_location_new (latitude, longitude, GEOCODE_LOCATION_ACCURACY_UNKNOWN);
  reverse = geocode_reverse_new_for_location (location);
  geocode_reverse_resolve_async (reverse,
                                 self->cancellable,
                                 photos_properties_dialog_location_reverse_resolve,
                                 self);

 out:
  return;
}
static void
next_cb (GObject      *const object,
         GAsyncResult *const result,
         GTask        *const task)
{

  g_autoptr(GError) error = NULL;

  AsyncSparqlWork *const work = async_sparql_work_get (task);
  TrackerSparqlCursor *const cursor = work->cursor;

  gboolean const more = tracker_sparql_cursor_next_finish (
    cursor,
    result,
    &error
  );

  if (error) {
    nul_debug ("error: %s", error->message);
    g_task_return_error (task, g_error_copy (error));
    return;
  }

  if (!more) {
    GVariant *const variant = g_variant_builder_end (work->builder);
    nul_debug (
      "end of data after %" G_GSIZE_FORMAT " rows",
      g_variant_n_children (variant)
    );
    work->variant = g_variant_ref_sink (variant);
    g_task_return_pointer (task, work, NULL);
    return;
  }

  g_variant_builder_add_value (
    work->builder,
    work->func (cursor)
  );

  tracker_sparql_cursor_next_async (
    cursor,
    g_task_get_cancellable (task),
    (GAsyncReadyCallback) next_cb,
    task
  );

}
示例#10
0
static void
photos_camera_cache_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GTask *task = G_TASK (user_data);
  PhotosCameraCache *self;
  PhotosCameraCachePrivate *priv;
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  GError *error;
  const gchar *manufacturer;
  const gchar *model;
  gchar *camera;
  gpointer key;

  self = PHOTOS_CAMERA_CACHE (g_task_get_source_object (task));
  priv = self->priv;

  error = NULL;
  tracker_sparql_cursor_next_finish (cursor, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      goto out;
    }

  manufacturer = tracker_sparql_cursor_get_string (cursor, 0, NULL);
  model = tracker_sparql_cursor_get_string (cursor, 1, NULL);

  if (manufacturer == NULL && model == NULL)
    camera = NULL;
  else if (manufacturer == NULL || g_str_has_prefix (model, manufacturer))
    camera = g_strdup (model);
  else if (model == NULL)
    camera = g_strdup (manufacturer);
  else
    camera = g_strconcat (manufacturer, " ", model, NULL);

  key = g_task_get_task_data (task);
  g_hash_table_insert (priv->cache, key, camera);

  g_task_return_pointer (task, g_strdup (camera), g_free);

 out:
  tracker_sparql_cursor_close (cursor);
  g_object_unref (task);
}
static void
photos_offset_controller_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosOffsetController *self = PHOTOS_OFFSET_CONTROLLER (user_data);
  PhotosOffsetControllerPrivate *priv = self->priv;
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  gboolean valid;

  valid = tracker_sparql_cursor_next_finish (cursor, res, NULL);
  if (valid)
    {
      priv->count = (gint) tracker_sparql_cursor_get_integer (cursor, 0);
      g_signal_emit (self, signals[COUNT_CHANGED], 0, priv->count);
    }

  tracker_sparql_cursor_close (cursor);
  g_object_unref (self);
}
示例#12
0
static void
photos_fetch_ids_job_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  PhotosFetchIdsJob *self;
  GCancellable *cancellable;
  g_autoptr (GTask) task = G_TASK (user_data);
  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
  GError *error;
  gboolean success;

  self = PHOTOS_FETCH_IDS_JOB (g_task_get_source_object (task));
  cancellable = g_task_get_cancellable (task);

  error = NULL;
  /* Note that tracker_sparql_cursor_next_finish can return FALSE even
   * without an error.
   */
  success = tracker_sparql_cursor_next_finish (cursor, res, &error);
  if (error != NULL)
    {
      g_task_return_error (task, error);
      goto end;
    }

  if (success)
    {
      const gchar *id;

      id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
      g_ptr_array_add (self->ids, g_strdup (id));

      tracker_sparql_cursor_next_async (cursor,
                                        cancellable,
                                        photos_fetch_ids_job_cursor_next,
                                        g_object_ref (task));
      return;
    }

  g_ptr_array_add (self->ids, NULL);
  g_task_return_pointer (task, self->ids->pdata, NULL);

 end:
  return;
}
static void
tracker_evt_preupdate_sources_item_cb (GObject              *object,
                                       GAsyncResult         *result,
                                       tracker_evt_update_t *evt)
{
  const gchar *type, *datasource, *uri, *datasource_name;
  gboolean source_available = FALSE;
  GrlTrackerSource *source;
  GError *error = NULL;

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

  if (!tracker_sparql_cursor_next_finish (evt->cursor, result, &error)) {
    if (error != NULL) {
      GRL_DEBUG ("\terror in parsing : %s", error->message);
      g_error_free (error);
    } else {
      GRL_DEBUG ("\tend of parsing... start notifying sources");
    }

    g_clear_object (&evt->cursor);

    /* Once all sources have been preupdated, start items
       updates. */
    tracker_evt_update_items (evt);
    tracker_evt_update_orphans (evt);

    return;
  }

  type = tracker_sparql_cursor_get_string (evt->cursor, 0, NULL);
  datasource = tracker_sparql_cursor_get_string (evt->cursor, 1, NULL);
  datasource_name = tracker_sparql_cursor_get_string (evt->cursor, 2, NULL);
  uri = tracker_sparql_cursor_get_string (evt->cursor, 3, NULL);
  if (tracker_sparql_cursor_is_bound (evt->cursor, 4))
    source_available = tracker_sparql_cursor_get_boolean (evt->cursor, 4);

  source = grl_tracker_source_find (datasource);

  GRL_DEBUG ("\tdatasource=%s uri=%s available=%i source=%p",
             datasource, uri, source_available, source);

  if (source_available) {
    if (source == NULL) {
      gchar *source_name = grl_tracker_get_source_name (type, uri, datasource,
                                                        datasource_name);
      /* Defer source creation until we have processed all sources */
      if (source_name) {
        tracker_evt_update_source_add (evt, datasource, source_name);
        g_free (source_name);
      }
    } else {
      GRL_DEBUG ("\tChanges on source %p / %s", source, datasource);
    }
  } else if (!source_available && source != NULL) {
    tracker_evt_update_source_del (evt, GRL_TRACKER_SOURCE (source));
  }

  tracker_sparql_cursor_next_async (evt->cursor, NULL,
                                    (GAsyncReadyCallback) tracker_evt_preupdate_sources_item_cb,
                                    (gpointer) evt);
}
static void
tracker_evt_update_orphan_item_cb (GObject              *object,
                                   GAsyncResult         *result,
                                   tracker_evt_update_t *evt)
{
  guint id;
  const gchar *type, *datasource;
  GrlTrackerSource *source = NULL;
  GError *error = NULL;

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

  if (!tracker_sparql_cursor_next_finish (evt->cursor, result, &error)) {
    if (error != NULL) {
      GRL_DEBUG ("\terror in parsing : %s", error->message);
      g_error_free (error);
    } else {
      GRL_DEBUG ("\tend of parsing...");
    }

    g_clear_object (&evt->cursor);

    if (grl_tracker_per_device_source) {
      /* Once all items have been processed, add new sources and we're
	 done. */
      tracker_evt_postupdate_sources (evt);
    } else {
      tracker_evt_update_free (evt);
    }

    return;
  }

  type = tracker_sparql_cursor_get_string (evt->cursor, 0, NULL);
  id = tracker_sparql_cursor_get_integer (evt->cursor, 1);
  datasource = tracker_sparql_cursor_get_string (evt->cursor, 2, NULL);

  GRL_DEBUG ("\tOrphan item: id=%u datasource=%s", id, datasource);

  if (!grl_tracker_per_device_source)
    source = grl_tracker_source_find ("");

  if (!source && datasource)
    source = grl_tracker_source_find (datasource);

  if (source && GRL_IS_TRACKER_SOURCE (source)) {
    GrlMedia *media;

    GRL_DEBUG (" \tAdding to cache id=%u", id);
    grl_tracker_source_cache_add_item (grl_tracker_item_cache, id, source);

    if (grl_tracker_source_can_notify (source)) {
      media = grl_tracker_build_grilo_media (type);
      if (media) {
        gchar *str_id = g_strdup_printf ("%i", id);
        gint change_type =
          GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items,
                                                GSIZE_TO_POINTER (id)));

        grl_media_set_id (media, str_id);
        g_free (str_id);

        GRL_DEBUG ("\tNotify id=%u source=%s p=%p", id,
                   grl_source_get_name (GRL_SOURCE (source)),
                   source);
        grl_source_notify_change (GRL_SOURCE (source),
                                  media, change_type, FALSE);

        g_object_unref (media);
      }
    }
  }

  tracker_sparql_cursor_next_async (evt->cursor, NULL,
                                    (GAsyncReadyCallback) tracker_evt_update_orphan_item_cb,
                                    (gpointer) evt);
}