[gimp] app: change file_utils_filename_to_uri() to file_utils_filename_to_file()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: change file_utils_filename_to_uri() to file_utils_filename_to_file()
- Date: Tue, 8 Jul 2014 08:28:18 +0000 (UTC)
commit c884c4f630a116fe581a80a5bce05f360bd6d229
Author: Michael Natterer <mitch gimp org>
Date: Tue Jul 8 10:25:25 2014 +0200
app: change file_utils_filename_to_uri() to file_utils_filename_to_file()
app/core/gimpimage.c | 25 +++++----------
app/dialogs/file-open-location-dialog.c | 20 +++---------
app/file/file-utils.c | 23 +++++---------
app/file/file-utils.h | 2 +-
app/pdb/fileops-cmds.c | 52 +++++++++++--------------------
tools/pdbgen/pdb/fileops.pdb | 52 +++++++++++--------------------
6 files changed, 58 insertions(+), 116 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 9e2dd5c..f801d95 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1856,13 +1856,6 @@ gimp_image_set_file (GimpImage *image,
file ? g_file_get_uri (file) : NULL);
}
-static void
-gimp_image_take_uri (GimpImage *image,
- gchar *uri)
-{
- gimp_object_take_name (GIMP_OBJECT (image), uri);
-}
-
/**
* gimp_image_get_untitled_file:
*
@@ -1926,19 +1919,17 @@ void
gimp_image_set_filename (GimpImage *image,
const gchar *filename)
{
+ GFile *file = NULL;
+
g_return_if_fail (GIMP_IS_IMAGE (image));
if (filename && strlen (filename))
- {
- gimp_image_take_uri (image,
- file_utils_filename_to_uri (image->gimp,
- filename,
- NULL));
- }
- else
- {
- gimp_image_set_file (image, NULL);
- }
+ file = file_utils_filename_to_file (image->gimp, filename, NULL);
+
+ gimp_image_set_file (image, file);
+
+ if (file)
+ g_object_unref (file);
}
/**
diff --git a/app/dialogs/file-open-location-dialog.c b/app/dialogs/file-open-location-dialog.c
index 25d672e..16c6091 100644
--- a/app/dialogs/file-open-location-dialog.c
+++ b/app/dialogs/file-open-location-dialog.c
@@ -171,31 +171,21 @@ file_open_location_response (GtkDialog *dialog,
if (text && strlen (text))
{
GimpImage *image;
- gchar *uri;
gchar *filename;
- gchar *hostname;
- GFile *file = NULL;
- GError *error = NULL;
+ GFile *file;
GimpPDBStatusType status;
+ GError *error = NULL;
- filename = g_filename_from_uri (text, &hostname, NULL);
+ filename = g_filename_from_uri (text, NULL, NULL);
if (filename)
{
- uri = g_filename_to_uri (filename, hostname, &error);
-
- g_free (hostname);
+ file = g_file_new_for_uri (text);
g_free (filename);
}
else
{
- uri = file_utils_filename_to_uri (gimp, text, &error);
- }
-
- if (uri)
- {
- file = g_file_new_for_uri (uri);
- g_free (uri);
+ file = file_utils_filename_to_file (gimp, text, &error);
}
box = gimp_progress_box_new ();
diff --git a/app/file/file-utils.c b/app/file/file-utils.c
index 554127b..b369e0d 100644
--- a/app/file/file-utils.c
+++ b/app/file/file-utils.c
@@ -89,10 +89,10 @@ file_utils_filename_is_uri (const gchar *filename,
return FALSE;
}
-gchar *
-file_utils_filename_to_uri (Gimp *gimp,
- const gchar *filename,
- GError **error)
+GFile *
+file_utils_filename_to_file (Gimp *gimp,
+ const gchar *filename,
+ GError **error)
{
GFile *file;
gchar *absolute;
@@ -111,9 +111,7 @@ file_utils_filename_to_uri (Gimp *gimp,
{
if (g_utf8_validate (filename, -1, NULL))
{
- g_object_unref (file);
-
- return g_strdup (filename);
+ return file;
}
else
{
@@ -121,15 +119,12 @@ file_utils_filename_to_uri (Gimp *gimp,
G_CONVERT_ERROR,
G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
_("Invalid character sequence in URI"));
- g_object_unref (file);
return NULL;
}
}
else if (file_utils_filename_is_uri (filename, &temp_error))
{
- g_object_unref (file);
-
- return g_strdup (filename);
+ return file;
}
else if (temp_error)
{
@@ -139,8 +134,6 @@ file_utils_filename_to_uri (Gimp *gimp,
return NULL;
}
- g_object_unref (file);
-
if (! g_path_is_absolute (filename))
{
gchar *current;
@@ -154,11 +147,11 @@ file_utils_filename_to_uri (Gimp *gimp,
absolute = g_strdup (filename);
}
- uri = g_filename_to_uri (absolute, NULL, error);
+ file = g_file_new_for_path (absolute);
g_free (absolute);
- return uri;
+ return file;
}
GFile *
diff --git a/app/file/file-utils.h b/app/file/file-utils.h
index 4e180fd..950dab1 100644
--- a/app/file/file-utils.h
+++ b/app/file/file-utils.h
@@ -21,7 +21,7 @@
#define __FILE_UTILS_H__
-gchar * file_utils_filename_to_uri (Gimp *gimp,
+GFile * file_utils_filename_to_file (Gimp *gimp,
const gchar *filename,
GError **error);
diff --git a/app/pdb/fileops-cmds.c b/app/pdb/fileops-cmds.c
index 214ef0d..9051358 100644
--- a/app/pdb/fileops-cmds.c
+++ b/app/pdb/fileops-cmds.c
@@ -61,23 +61,19 @@ file_load_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
- gchar *uri;
GFile *file;
gint i;
- uri = file_utils_filename_to_uri (gimp,
- g_value_get_string (gimp_value_array_index (args, 1)),
- error);
+ file = file_utils_filename_to_file (gimp,
+ g_value_get_string (gimp_value_array_index (args, 1)),
+ error);
- if (! uri)
+ if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
- file_proc =
- file_procedure_find (gimp->plug_in_manager->load_procs, file, error);
+ file_proc = file_procedure_find (gimp->plug_in_manager->load_procs,
+ file, error);
g_object_unref (file);
@@ -142,17 +138,13 @@ file_load_layer_invoker (GimpProcedure *procedure,
if (success)
{
- gchar *uri = file_utils_filename_to_uri (gimp, filename, error);
+ GFile *file = file_utils_filename_to_file (gimp, filename, error);
- if (uri)
+ if (file)
{
- GFile *file;
GList *layers;
GimpPDBStatusType status;
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
@@ -202,17 +194,13 @@ file_load_layers_invoker (GimpProcedure *procedure,
if (success)
{
- gchar *uri = file_utils_filename_to_uri (gimp, filename, error);
+ GFile *file = file_utils_filename_to_file (gimp, filename, error);
- if (uri)
+ if (file)
{
- GFile *file;
GList *layers;
GimpPDBStatusType status;
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
@@ -266,27 +254,23 @@ file_save_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
- gchar *uri;
GFile *file;
gint i;
- uri = file_utils_filename_to_uri (gimp,
- g_value_get_string (gimp_value_array_index (args, 3)),
- error);
+ file = file_utils_filename_to_file (gimp,
+ g_value_get_string (gimp_value_array_index (args, 3)),
+ error);
- if (! uri)
+ if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
- file_proc =
- file_procedure_find (gimp->plug_in_manager->save_procs, file, NULL);
+ file_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
+ file, NULL);
if (! file_proc)
- file_proc = file_procedure_find (gimp->plug_in_manager->export_procs, file,
- error);
+ file_proc = file_procedure_find (gimp->plug_in_manager->export_procs,
+ file, error);
g_object_unref (file);
diff --git a/tools/pdbgen/pdb/fileops.pdb b/tools/pdbgen/pdb/fileops.pdb
index dbee7be..aba62f0 100644
--- a/tools/pdbgen/pdb/fileops.pdb
+++ b/tools/pdbgen/pdb/fileops.pdb
@@ -54,23 +54,19 @@ HELP
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
- gchar *uri;
GFile *file;
gint i;
- uri = file_utils_filename_to_uri (gimp,
- g_value_get_string (gimp_value_array_index (args, 1)),
- error);
+ file = file_utils_filename_to_file (gimp,
+ g_value_get_string (gimp_value_array_index (args, 1)),
+ error);
- if (! uri)
+ if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
- file_proc =
- file_procedure_find (gimp->plug_in_manager->load_procs, file, error);
+ file_proc = file_procedure_find (gimp->plug_in_manager->load_procs,
+ file, error);
g_object_unref (file);
@@ -146,17 +142,13 @@ HELP
%invoke = (
code => <<'CODE'
{
- gchar *uri = file_utils_filename_to_uri (gimp, filename, error);
+ GFile *file = file_utils_filename_to_file (gimp, filename, error);
- if (uri)
+ if (file)
{
- GFile *file;
GList *layers;
GimpPDBStatusType status;
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
@@ -209,17 +201,13 @@ HELP
%invoke = (
code => <<'CODE'
{
- gchar *uri = file_utils_filename_to_uri (gimp, filename, error);
+ GFile *file = file_utils_filename_to_file (gimp, filename, error);
- if (uri)
+ if (file)
{
- GFile *file;
GList *layers;
GimpPDBStatusType status;
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
@@ -288,27 +276,23 @@ HELP
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
- gchar *uri;
GFile *file;
gint i;
- uri = file_utils_filename_to_uri (gimp,
- g_value_get_string (gimp_value_array_index (args, 3)),
- error);
+ file = file_utils_filename_to_file (gimp,
+ g_value_get_string (gimp_value_array_index (args, 3)),
+ error);
- if (! uri)
+ if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
- file_proc =
- file_procedure_find (gimp->plug_in_manager->save_procs, file, NULL);
+ file_proc = file_procedure_find (gimp->plug_in_manager->save_procs,
+ file, NULL);
if (! file_proc)
- file_proc = file_procedure_find (gimp->plug_in_manager->export_procs, file,
- error);
+ file_proc = file_procedure_find (gimp->plug_in_manager->export_procs,
+ file, error);
g_object_unref (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]