From 55c88a726e7389f446047e286fd9d2af612ac604 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 3 Nov 2014 11:54:10 +0100 Subject: [PATCH] project: Add a method to create assets synchronously This allows to create a add an asset to a project in a synchronous way. API: ges_project_create_asset_sync https://bugzilla.gnome.org/show_bug.cgi?id=740716 --- ges/ges-project.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++ ges/ges-project.h | 4 +++ 2 files changed, 78 insertions(+) diff --git a/ges/ges-project.c b/ges/ges-project.c index 6147b5026c..5d7cdc130f 100644 --- a/ges/ges-project.c +++ b/ges/ges-project.c @@ -709,6 +709,80 @@ ges_project_create_asset (GESProject * project, const gchar * id, return TRUE; } +/** + * ges_project_create_asset_sync: + * @project: A #GESProject + * @id: (allow-none): The id of the asset to create and add to @project + * @extractable_type: The #GType of the asset to create + * @error: A #GError to be set in case of error + * + * Create and add a #GESAsset to @project. You should connect to the + * "asset-added" signal to get the asset when it finally gets added to + * @project + * + * Returns: The newly created #GESAsset + */ +GESAsset * +ges_project_create_asset_sync (GESProject * project, const gchar * id, + GType extractable_type, GError ** error) +{ + GESAsset *asset; + gchar *possible_id = NULL; + gboolean retry = TRUE; + + g_return_val_if_fail (GES_IS_PROJECT (project), FALSE); + g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE), + FALSE); + + if (id == NULL) + id = g_type_name (extractable_type); + + if ((asset = g_hash_table_lookup (project->priv->assets, id))) + return asset; + else if (g_hash_table_lookup (project->priv->loading_assets, id) || + g_hash_table_lookup (project->priv->loaded_with_error, id)) + return NULL; + + /* TODO Add a GCancellable somewhere in our API */ + while (retry) { + + if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) { + asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error)); + } else { + asset = ges_asset_request (extractable_type, id, error); + } + + if (asset) { + retry = FALSE; + + if (possible_id) { + g_free (possible_id); + ges_uri_assets_validate_uri (id); + } + + break; + } else { + GESAsset *tmpasset; + + tmpasset = ges_asset_cache_lookup (extractable_type, id); + possible_id = ges_project_try_updating_id (project, tmpasset, *error); + + if (possible_id == NULL) + return NULL; + + g_clear_error (error); + if (error) + *error = NULL; + + id = possible_id; + } + } + + ges_project_add_asset (project, asset); + + return asset; +} + /** * ges_project_add_asset: * @project: A #GESProject diff --git a/ges/ges-project.h b/ges/ges-project.h index e5cec0181f..689752ef1d 100644 --- a/ges/ges-project.h +++ b/ges/ges-project.h @@ -96,6 +96,10 @@ gboolean ges_project_create_asset (GESProject * project, const gchar *id, GType extractable_type); +GESAsset * ges_project_create_asset_sync (GESProject * project, + const gchar * id, + GType extractable_type, + GError **error); GList * ges_project_get_loading_assets (GESProject * project); gboolean ges_project_add_encoding_profile (GESProject *project, -- 2.34.1