Commit 6bca8c4f authored by Michael Natterer's avatar Michael Natterer 😴

pdb, app, libgimp, plug-ins: replace most PDB filenames/URIs by GFile

and in an attack of madness, changes almost all file plug-in
code to use GFile instead of filenames, which means passing
the GFile down to the bottom and get its filename at the very
end where it's actually needed.
parent a5ac3e45
Pipeline #114135 passed with stages
in 18 minutes and 10 seconds
......@@ -66,15 +66,13 @@ file_gbr_load_invoker (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
GimpImage *image = NULL;
const gchar *uri;
GFile *file;
GInputStream *input;
GError *my_error = NULL;
gimp_set_busy (gimp);
uri = g_value_get_string (gimp_value_array_index (args, 1));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 1));
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
......@@ -97,8 +95,6 @@ file_gbr_load_invoker (GimpProcedure *procedure,
gimp_file_get_utf8_name (file));
}
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, image != NULL,
error ? *error : NULL);
......@@ -122,7 +118,6 @@ file_gbr_save_invoker (GimpProcedure *procedure,
GimpImage *image;
GimpDrawable *drawable;
GimpBrush *brush;
const gchar *uri;
const gchar *name;
GFile *file;
gint spacing;
......@@ -132,11 +127,9 @@ file_gbr_save_invoker (GimpProcedure *procedure,
image = g_value_get_object (gimp_value_array_index (args, 1));
drawable = g_value_get_object (gimp_value_array_index (args, 2));
uri = g_value_get_string (gimp_value_array_index (args, 3));
spacing = g_value_get_int (gimp_value_array_index (args, 5));
name = g_value_get_string (gimp_value_array_index (args, 6));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 3));
spacing = g_value_get_int (gimp_value_array_index (args, 4));
name = g_value_get_string (gimp_value_array_index (args, 5));
brush = file_gbr_image_to_brush (image, drawable, name, spacing);
......@@ -145,7 +138,6 @@ file_gbr_save_invoker (GimpProcedure *procedure,
success = gimp_data_save (GIMP_DATA (brush), error);
g_object_unref (brush);
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
......
......@@ -499,7 +499,6 @@ file_gex_load_invoker (GimpProcedure *procedure,
GError **error)
{
GimpValueArray *return_vals;
const gchar *uri;
GFile *file;
gchar *ext_dir = NULL;
AsApp *appdata = NULL;
......@@ -507,8 +506,7 @@ file_gex_load_invoker (GimpProcedure *procedure,
gimp_set_busy (gimp);
uri = g_value_get_string (gimp_value_array_index (args, 1));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 1));
success = file_gex_validate (file, &appdata, error);
if (success)
......@@ -548,8 +546,6 @@ file_gex_load_invoker (GimpProcedure *procedure,
success = FALSE;
}
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
gimp_unset_busy (gimp);
......
......@@ -67,15 +67,13 @@ file_gih_load_invoker (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
GimpImage *image = NULL;
const gchar *uri;
GFile *file;
GInputStream *input;
GError *my_error = NULL;
gimp_set_busy (gimp);
uri = g_value_get_string (gimp_value_array_index (args, 1));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 1));
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
......@@ -102,8 +100,6 @@ file_gih_load_invoker (GimpProcedure *procedure,
gimp_file_get_utf8_name (file));
}
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, image != NULL,
error ? *error : NULL);
......@@ -126,7 +122,6 @@ file_gih_save_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
GimpImage *image;
GimpBrushPipe *pipe;
const gchar *uri;
const gchar *name;
const gchar *params;
GFile *file;
......@@ -136,12 +131,10 @@ file_gih_save_invoker (GimpProcedure *procedure,
gimp_set_busy (gimp);
image = g_value_get_object (gimp_value_array_index (args, 1));
uri = g_value_get_string (gimp_value_array_index (args, 3));
spacing = g_value_get_int (gimp_value_array_index (args, 5));
name = g_value_get_string (gimp_value_array_index (args, 6));
params = g_value_get_string (gimp_value_array_index (args, 7));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 3));
spacing = g_value_get_int (gimp_value_array_index (args, 4));
name = g_value_get_string (gimp_value_array_index (args, 5));
params = g_value_get_string (gimp_value_array_index (args, 6));
pipe = file_gih_image_to_pipe (image, name, spacing, params);
......@@ -150,7 +143,6 @@ file_gih_save_invoker (GimpProcedure *procedure,
success = gimp_data_save (GIMP_DATA (pipe), error);
g_object_unref (pipe);
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
......
......@@ -63,15 +63,13 @@ file_pat_load_invoker (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
GimpImage *image = NULL;
const gchar *uri;
GFile *file;
GInputStream *input;
GError *my_error = NULL;
gimp_set_busy (gimp);
uri = g_value_get_string (gimp_value_array_index (args, 1));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 1));
input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
......@@ -98,8 +96,6 @@ file_pat_load_invoker (GimpProcedure *procedure,
gimp_file_get_utf8_name (file));
}
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, image != NULL,
error ? *error : NULL);
......@@ -123,7 +119,6 @@ file_pat_save_invoker (GimpProcedure *procedure,
GimpImage *image;
GimpDrawable *drawable;
GimpPattern *pattern;
const gchar *uri;
const gchar *name;
GFile *file;
gboolean success;
......@@ -132,10 +127,8 @@ file_pat_save_invoker (GimpProcedure *procedure,
image = g_value_get_object (gimp_value_array_index (args, 1));
drawable = g_value_get_object (gimp_value_array_index (args, 2));
uri = g_value_get_string (gimp_value_array_index (args, 3));
name = g_value_get_string (gimp_value_array_index (args, 5));
file = g_file_new_for_uri (uri);
file = g_value_get_object (gimp_value_array_index (args, 3));
name = g_value_get_string (gimp_value_array_index (args, 4));
pattern = file_pat_image_to_pattern (image, drawable, name);
......@@ -144,7 +137,6 @@ file_pat_save_invoker (GimpProcedure *procedure,
success = gimp_data_save (GIMP_DATA (pattern), error);
g_object_unref (pattern);
g_object_unref (file);
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
......
......@@ -89,13 +89,11 @@ file_data_init (Gimp *gimp)
GIMP_RUN_INTERACTIVE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to load",
TRUE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to load",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_image ("image",
......@@ -162,13 +160,11 @@ file_data_init (Gimp *gimp)
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to export",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to export",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_int ("spacing",
"spacing",
......@@ -225,13 +221,11 @@ file_data_init (Gimp *gimp)
GIMP_RUN_INTERACTIVE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to load",
TRUE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to load",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_image ("image",
......@@ -298,13 +292,11 @@ file_data_init (Gimp *gimp)
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to export",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to export",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_int ("spacing",
"spacing",
......@@ -368,13 +360,11 @@ file_data_init (Gimp *gimp)
GIMP_RUN_INTERACTIVE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to load",
TRUE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to load",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_image ("image",
"Image",
......@@ -440,14 +430,11 @@ file_data_init (Gimp *gimp)
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to export",
FALSE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to export",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("name",
"name",
......@@ -496,13 +483,11 @@ file_data_init (Gimp *gimp)
GIMP_RUN_INTERACTIVE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_string ("uri",
"URI",
"The URI of the file "
"to load",
TRUE, FALSE, TRUE,
NULL,
GIMP_PARAM_READWRITE));
g_param_spec_object ("file",
"File",
"The file to load",
G_TYPE_FILE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("extension-id",
......
......@@ -79,9 +79,9 @@ file_open_image (Gimp *gimp,
GError **error)
{
GimpValueArray *return_vals;
GFile *orig_file;
GimpImage *image = NULL;
GFile *local_file = NULL;
gchar *uri = NULL;
gboolean mounted = TRUE;
GError *my_error = NULL;
......@@ -94,6 +94,8 @@ file_open_image (Gimp *gimp,
*status = GIMP_PDB_EXECUTION_ERROR;
orig_file = file;
/* FIXME enable these tests for remote files again, needs testing */
if (g_file_is_native (file) &&
g_file_query_exists (file, NULL))
......@@ -199,15 +201,12 @@ file_open_image (Gimp *gimp,
return NULL;
}
uri = g_file_get_uri (local_file);
file = local_file;
}
g_free (my_path);
}
if (! uri)
uri = g_file_get_uri (file);
if (progress)
g_object_add_weak_pointer (G_OBJECT (progress), (gpointer) &progress);
......@@ -216,14 +215,12 @@ file_open_image (Gimp *gimp,
context, progress, error,
gimp_object_get_name (file_proc),
GIMP_TYPE_RUN_MODE, run_mode,
G_TYPE_STRING, uri,
G_TYPE_FILE, file,
G_TYPE_NONE);
if (progress)
g_object_remove_weak_pointer (G_OBJECT (progress), (gpointer) &progress);
g_free (uri);
*status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
if (*status == GIMP_PDB_SUCCESS && ! file_proc->generic_file_proc)
......@@ -232,7 +229,7 @@ file_open_image (Gimp *gimp,
if (local_file)
{
if (image)
gimp_image_set_file (image, file);
gimp_image_set_file (image, orig_file);
g_file_delete (local_file, NULL, NULL);
g_object_unref (local_file);
......@@ -278,7 +275,7 @@ file_open_image (Gimp *gimp,
if (file_open_file_proc_is_import (file_proc))
{
file_import_image (image, context, file,
file_import_image (image, context, orig_file,
run_mode == GIMP_RUN_INTERACTIVE,
progress);
}
......
......@@ -65,9 +65,9 @@ file_save (Gimp *gimp,
{
GimpDrawable *drawable;
GimpValueArray *return_vals;
GFile *orig_file;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
GFile *local_file = NULL;
gchar *uri = NULL;
gboolean mounted = TRUE;
GError *my_error = NULL;
......@@ -83,9 +83,11 @@ file_save (Gimp *gimp,
g_return_val_if_fail (error == NULL || *error == NULL,
GIMP_PDB_CALLING_ERROR);
orig_file = file;
/* ref image and file, so they can't get deleted during save */
g_object_ref (image);
g_object_ref (file);
g_object_ref (orig_file);
gimp_image_saving (image);
......@@ -177,15 +179,12 @@ file_save (Gimp *gimp,
goto out;
}
uri = g_file_get_uri (local_file);
file = local_file;
}
g_free (my_path);
}
if (! uri)
uri = g_file_get_uri (file);
return_vals =
gimp_pdb_execute_procedure_by_name (image->gimp->pdb,
gimp_get_user_context (gimp),
......@@ -194,7 +193,7 @@ file_save (Gimp *gimp,
GIMP_TYPE_RUN_MODE, run_mode,
GIMP_TYPE_IMAGE, image,
GIMP_TYPE_DRAWABLE, drawable,
G_TYPE_STRING, uri,
G_TYPE_FILE, file,
G_TYPE_NONE);
status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
......@@ -207,7 +206,7 @@ file_save (Gimp *gimp,
{
GError *my_error = NULL;
if (! file_remote_upload_image_finish (gimp, file, local_file,
if (! file_remote_upload_image_finish (gimp, orig_file, local_file,
progress, &my_error))
{
status = GIMP_PDB_EXECUTION_ERROR;
......@@ -230,7 +229,7 @@ file_save (Gimp *gimp,
if (change_saved_state)
{
gimp_image_set_file (image, file);
gimp_image_set_file (image, orig_file);
gimp_image_set_save_proc (image, file_proc);
/* Forget the import source when we save. We interpret a
......@@ -256,7 +255,7 @@ file_save (Gimp *gimp,
* happens implicitly when saving since the GimpObject name
* of a GimpImage is the last-save URI
*/
gimp_image_set_exported_file (image, file);
gimp_image_set_exported_file (image, orig_file);
gimp_image_set_export_proc (image, file_proc);
/* An image can not be considered both exported and imported
......@@ -269,13 +268,13 @@ file_save (Gimp *gimp,
}
if (export_backward || export_forward)
gimp_image_exported (image, file);
gimp_image_exported (image, orig_file);
else
gimp_image_saved (image, file);
gimp_image_saved (image, orig_file);
documents = GIMP_DOCUMENT_LIST (image->gimp->documents);
imagefile = gimp_document_list_add_file (documents, file,
imagefile = gimp_document_list_add_file (documents, orig_file,
g_slist_nth_data (file_proc->mime_types_list, 0));
/* only save a thumbnail if we are saving as XCF, see bug #25272 */
......@@ -298,10 +297,8 @@ file_save (Gimp *gimp,
gimp_image_flush (image);
out:
g_object_unref (file);
g_object_unref (orig_file);
g_object_unref (image);
g_free (uri);
return status;
}
......@@ -168,27 +168,22 @@ file_utils_filename_to_file (Gimp *gimp,
}
GdkPixbuf *
file_utils_load_thumbnail (const gchar *filename)
file_utils_load_thumbnail (GFile *file)
{
GimpThumbnail *thumbnail = NULL;
GdkPixbuf *pixbuf = NULL;
gchar *uri;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
uri = g_filename_to_uri (filename, NULL, NULL);
uri = g_file_get_uri (file);
if (uri)
{
thumbnail = gimp_thumbnail_new ();
gimp_thumbnail_set_uri (thumbnail, uri);
thumbnail = gimp_thumbnail_new ();
gimp_thumbnail_set_uri (thumbnail, uri);
pixbuf = gimp_thumbnail_load_thumb (thumbnail,
(GimpThumbSize) GIMP_THUMBNAIL_SIZE_NORMAL,
NULL);
}
g_free (uri);
pixbuf = gimp_thumbnail_load_thumb (thumbnail,
(GimpThumbSize) GIMP_THUMBNAIL_SIZE_NORMAL,
NULL);
if (pixbuf)
{
......@@ -215,21 +210,21 @@ file_utils_load_thumbnail (const gchar *filename)
}
gboolean
file_utils_save_thumbnail (GimpImage *image,
const gchar *filename)
file_utils_save_thumbnail (GimpImage *image,
GFile *file)
{
GFile *file;
GFile *image_file;
gboolean success = FALSE;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
file = gimp_image_get_file (image);
image_file = gimp_image_get_file (image);
if (file)
if (image_file)
{
gchar *image_uri = g_file_get_uri (file);
gchar *uri = g_filename_to_uri (filename, NULL, NULL);
gchar *image_uri = g_file_get_uri (image_file);
gchar *uri = g_file_get_uri (file);
if (uri && image_uri && ! strcmp (uri, image_uri))
{
......
......@@ -25,9 +25,9 @@ GFile * file_utils_filename_to_file (Gimp *gimp,
const gchar *filename,
GError **error);
GdkPixbuf * file_utils_load_thumbnail (const gchar *filename);
GdkPixbuf * file_utils_load_thumbnail (GFile *file);
gboolean file_utils_save_thumbnail (GimpImage *image,
const gchar *filename);
GFile *file);
#endif /* __FILE_UTILS_H__ */
......@@ -58,9 +58,7 @@ file_load_invoker (GimpProcedure *procedure,
GFile *file;
gint i;
file = file_utils_filename_to_file (gimp,
g_value_get_string (gimp_value_array_index (args, 1)),
error);
file = g_value_get_object (gimp_value_array_index (args, 1));
if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
......@@ -71,12 +69,8 @@ file_load_invoker (GimpProcedure *procedure,
file, error);
if (! file_proc)
{
g_object_unref (file);
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
}
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
proc = GIMP_PROCEDURE (file_proc);
......@@ -112,8 +106,6 @@ file_load_invoker (GimpProcedure *procedure,
}
}
g_object_unref (file);
return return_vals;
}
......@@ -129,35 +121,26 @@ file_load_layer_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
gint run_mode;
GimpImage *image;
const gchar *filename;
GFile *file;
GimpLayer *layer = NULL;
run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
image = g_value_get_object (gimp_value_array_index (args, 1));
filename = g_value_get_string (gimp_value_array_index (args, 2));
file = g_value_get_object (gimp_value_array_index (args, 2));
if (success)
{
GFile *file = file_utils_filename_to_file (gimp, filename, error);
if (file)
{
GList *layers;
GimpPDBStatusType status;
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
GList *layers;
GimpPDBStatusType status;
g_object_unref (file);
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
if (layers)
{
layer = layers->data;
g_list_free (layers);
}
else
success = FALSE;
if (layers)
{
layer = layers->data;
g_list_free (layers);
}
else
success = FALSE;
......@@ -184,49 +167,40 @@ file_load_layers_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
gint run_mode;
GimpImage *image;
const gchar *filename;
GFile *file;
gint num_layers = 0;
GimpLayer **layers = NULL;
run_mode = g_value_get_enum (gimp_value_array_index (args, 0));
image = g_value_get_object (gimp_value_array_index (args, 1));
filename = g_value_get_string (gimp_value_array_index (args, 2));
file = g_value_get_object (gimp_value_array_index (args, 2));
if (success)
{
GFile *file = file_utils_filename_to_file (gimp, filename, error);
GList *layer_list;
GimpPDBStatusType status;
if (file)
layer_list = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
if (layers)
{
GList *layer_list;
GimpPDBStatusType status;
GList *list;
gint i;
layer_list = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
num_layers = g_list_length (layer_list);
g_object_unref (file);
layers = g_new (GimpLayer *, num_layers);
if (layers)
for (i = 0, list = layer_list;
i < num_layers;
i++, list = g_list_next (list))
{