Exemplo n.º 1
0
void
gom_resource_save_async (GomResource         *resource,
                         GAsyncReadyCallback  callback,
                         gpointer             user_data)
{
   GomResourcePrivate *priv;
   GSimpleAsyncResult *simple;
   GomAdapter *adapter;

   g_return_if_fail(GOM_IS_RESOURCE(resource));
   g_return_if_fail(callback != NULL);

   priv = resource->priv;

   if (!priv->repository) {
      g_warning("Cannot save resource, no repository set!");
      return;
   }

   simple = g_simple_async_result_new(G_OBJECT(resource), callback, user_data,
                                      gom_resource_save_async);
   adapter = gom_repository_get_adapter(priv->repository);
   g_assert(GOM_IS_ADAPTER(adapter));
   gom_resource_build_save_cmd(resource, adapter);
   gom_adapter_queue_write(adapter, gom_resource_save_cb, simple);
}
Exemplo n.º 2
0
/**
 * gom_repository_get_property:
 * @object: (in): A #GObject.
 * @prop_id: (in): The property identifier.
 * @value: (out): The given property.
 * @pspec: (in): A #ParamSpec.
 *
 * Get a given #GObject property.
 */
static void
gom_repository_get_property (GObject    *object,
                             guint       prop_id,
                             GValue     *value,
                             GParamSpec *pspec)
{
   GomRepository *repository = GOM_REPOSITORY(object);

   switch (prop_id) {
   case PROP_ADAPTER:
      g_value_set_object(value, gom_repository_get_adapter(repository));
      break;
   default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
   }
}
Exemplo n.º 3
0
static void
migrate_cb (GObject      *object,
            GAsyncResult *result,
            gpointer      user_data)
{
   GomRepository *repository = (GomRepository *)object;
   GomAdapter *adapter;
   gboolean ret;
   GError *error = NULL;

   ret = gom_repository_migrate_finish(repository, result, &error);
   g_assert_no_error(error);
   g_assert(ret);

   adapter = gom_repository_get_adapter(repository);
   gom_adapter_close_async(adapter, close_cb, user_data);
}
Exemplo n.º 4
0
/**
 * gom_resource_save_sync:
 * @resource: (in): A #GomResource.
 * @error: (out): A location for a #GError, or %NULL.
 *
 * Returns: %TRUE if successful; otherwise %FALSE.
 */
gboolean
gom_resource_save_sync (GomResource  *resource,
                        GError      **error)
{
   GomResourcePrivate *priv;
   GomAdapter *adapter;
   GAsyncQueue *queue;
   GSimpleAsyncResult *simple;
   gboolean ret;

   g_return_val_if_fail(GOM_IS_RESOURCE(resource), FALSE);

   priv = resource->priv;

   if (!priv->repository) {
      g_set_error(error, GOM_ERROR, GOM_ERROR_COMMAND_NO_REPOSITORY,
                  _("Cannot save resource, no repository set"));
      return FALSE;
   }

   queue = g_async_queue_new();

   simple = g_simple_async_result_new(G_OBJECT(resource), NULL, NULL,
                                      gom_resource_save_sync);
   adapter = gom_repository_get_adapter(priv->repository);
   g_object_set_data(G_OBJECT(simple), "queue", queue);
   g_assert(GOM_IS_ADAPTER(adapter));

   gom_resource_build_save_cmd(resource, adapter);

   gom_adapter_queue_write(adapter, gom_resource_save_cb, simple);
   g_async_queue_pop(queue);
   g_async_queue_unref(queue);

   if (!(ret = g_simple_async_result_get_op_res_gboolean(simple))) {
      g_simple_async_result_propagate_error(simple, error);
   }

   if (ret)
      set_post_save_properties(resource);

   g_object_unref(simple);

   return ret;
}
Exemplo n.º 5
0
void
gom_resource_fetch_m2m_async (GomResource          *resource,
                              GType                 resource_type,
                              const gchar          *m2m_table,
                              GomFilter            *filter,
                              GAsyncReadyCallback   callback,
                              gpointer              user_data)
{
   GSimpleAsyncResult *simple;
   GomRepository *repository;
   GomAdapter *adapter;

   g_return_if_fail(GOM_IS_RESOURCE(resource));
   g_return_if_fail(g_type_is_a(resource_type, GOM_TYPE_RESOURCE));
   g_return_if_fail(m2m_table != NULL);
   g_return_if_fail(callback != NULL);

   repository = gom_resource_get_repository(resource);
   g_assert(GOM_IS_REPOSITORY(repository));

   adapter = gom_repository_get_adapter(repository);
   g_assert(GOM_IS_ADAPTER(adapter));

   simple = g_simple_async_result_new(G_OBJECT(resource), callback, user_data,
                                      gom_resource_fetch_m2m_async);
   g_object_set_data(G_OBJECT(simple), "resource-type",
                     GINT_TO_POINTER(resource_type));
   g_object_set_data_full(G_OBJECT(simple), "m2m-table",
                          g_strdup(m2m_table), g_free);
   if (filter) {
      g_object_set_data_full(G_OBJECT(simple), "filter",
                             g_object_ref(filter), g_object_unref);
   }

   gom_adapter_queue_read(adapter,
                          gom_resource_fetch_m2m_cb,
                          simple);
}
Exemplo n.º 6
0
static void
migrate_cb (GObject      *object,
            GAsyncResult *result,
            gpointer      user_data)
{
   GomRepository *repository = (GomRepository *)object;
   GomAdapter *adapter;
   gboolean ret;
   GError *error = NULL;
   GomResource *resource;
   GomFilter *filter;
   GValue value = { 0, };
   char *url, *thumbnail_url;
   gboolean favourite;

   ret = gom_repository_migrate_finish(repository, result, &error);
   g_assert_no_error(error);
   g_assert(ret);

   /* Get the item containing "sherwood" */
   g_value_init(&value, G_TYPE_STRING);
   g_value_set_string(&value, "%sherwood%");
   filter = gom_filter_new_like(BOOKMARKS_TYPE_RESOURCE, "title", &value);
   g_value_unset(&value);
   resource = gom_repository_find_one_sync(repository,
                                           BOOKMARKS_TYPE_RESOURCE,
                                           filter,
                                           &error);
   g_assert_no_error(error);
   g_assert(resource);

   g_object_get(resource, "url", &url, NULL);
   g_assert_cmpstr(url, ==, "file:///home/hadess/.cache/totem/media/b91c194d5725c4586e583c4963233a3ae3c28ea3e2cc2019f903089911dd6d45");
   g_free(url);

   /* Modify the item */
   g_object_set(resource, "url", "file:///tmp/test", "thumbnail-url", "file:///tmp/test-thumbnail", "favourite", TRUE, NULL);
   ret = gom_resource_save_sync(resource, &error);
   g_assert_no_error(error);
   g_assert(ret);
   g_object_unref(resource);

   /* Fetch it again */
   resource = gom_repository_find_one_sync(repository,
                                           BOOKMARKS_TYPE_RESOURCE,
                                           filter,
                                           &error);
   g_assert_no_error(error);
   g_assert(resource);

   g_object_get(resource, "url", &url, "thumbnail-url", &thumbnail_url, "favourite", &favourite, NULL);
   g_assert_cmpstr(url, ==, "file:///tmp/test");
   g_assert_cmpstr(thumbnail_url, ==, "file:///tmp/test-thumbnail");
   g_assert(favourite);
   g_free(url);
   g_free(thumbnail_url);

   g_object_unref(filter);

   adapter = gom_repository_get_adapter(repository);
   gom_adapter_close_async(adapter, close_cb, user_data);
}