[gimp] app: port file_open_from_command_line() to GFile
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port file_open_from_command_line() to GFile
- Date: Mon, 7 Jul 2014 22:01:18 +0000 (UTC)
commit a6aa35df57c8de0a0f639ea77b0085e9a4f63439
Author: Michael Natterer <mitch gimp org>
Date: Mon Jul 7 01:02:54 2014 +0200
app: port file_open_from_command_line() to GFile
Use g_file_new_for_commandline_arg() and remove
file_utils_any_to_file().
app/app.c | 12 +++++--
app/file/file-open.c | 86 +++++++++++++++++++--------------------------
app/file/file-open.h | 2 +-
app/file/file-utils.c | 32 -----------------
app/file/file-utils.h | 3 --
app/gui/gimpdbusservice.c | 8 ++--
6 files changed, 50 insertions(+), 93 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index 609aa33..a6b7973 100644
--- a/app/app.c
+++ b/app/app.c
@@ -277,9 +277,15 @@ app_run (const gchar *full_prog_name,
for (i = 0; filenames[i] != NULL; i++)
{
if (run_loop)
- file_open_from_command_line (gimp, filenames[i], as_new,
- initial_screen,
- initial_monitor);
+ {
+ GFile *file = g_file_new_for_commandline_arg (filenames[i]);
+
+ file_open_from_command_line (gimp, file, as_new,
+ initial_screen,
+ initial_monitor);
+
+ g_object_unref (file);
+ }
}
}
diff --git a/app/file/file-open.c b/app/file/file-open.c
index a4e4808..09f875c 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -605,72 +605,58 @@ file_open_layers (Gimp *gimp,
* or from the D-Bus service.
*/
gboolean
-file_open_from_command_line (Gimp *gimp,
- const gchar *filename,
- gboolean as_new,
- GObject *screen,
- gint monitor)
+file_open_from_command_line (Gimp *gimp,
+ GFile *file,
+ gboolean as_new,
+ GObject *screen,
+ gint monitor)
{
- GFile *file;
- gboolean success = FALSE;
- GError *error = NULL;
+ GimpImage *image;
+ GimpObject *display;
+ GimpPDBStatusType status;
+ gboolean success = FALSE;
+ GError *error = NULL;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (screen == NULL || G_IS_OBJECT (screen), FALSE);
- /* we accept URI or filename */
- file = file_utils_any_to_file (gimp, filename, &error);
+ display = gimp_get_empty_display (gimp);
- if (file)
- {
- GimpImage *image;
- GimpObject *display = gimp_get_empty_display (gimp);
- GimpPDBStatusType status;
+ /* show the progress in the last opened display, see bug #704896 */
+ if (! display)
+ display = gimp_context_get_display (gimp_get_user_context (gimp));
- /* show the progress in the last opened display, see bug #704896 */
- if (! display)
- display = gimp_context_get_display (gimp_get_user_context (gimp));
+ if (display)
+ g_object_add_weak_pointer (G_OBJECT (display), (gpointer) &display);
- if (display)
- g_object_add_weak_pointer (G_OBJECT (display), (gpointer) &display);
+ image = file_open_with_display (gimp,
+ gimp_get_user_context (gimp),
+ GIMP_PROGRESS (display),
+ file, as_new,
+ screen, monitor,
+ &status, &error);
- image = file_open_with_display (gimp,
- gimp_get_user_context (gimp),
- GIMP_PROGRESS (display),
- file, as_new,
- screen, monitor,
- &status, &error);
-
- if (image)
- {
- success = TRUE;
-
- g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
- g_object_ref (file),
- (GDestroyNotify) g_object_unref);
- }
- else if (status != GIMP_PDB_CANCEL && display)
- {
- gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
- _("Opening '%s' failed: %s"),
- gimp_file_get_utf8_name (file), error->message);
- g_clear_error (&error);
- }
-
- if (display)
- g_object_remove_weak_pointer (G_OBJECT (display), (gpointer) &display);
+ if (image)
+ {
+ success = TRUE;
- g_object_unref (file);
+ g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
+ g_object_ref (file),
+ (GDestroyNotify) g_object_unref);
}
- else
+ else if (status != GIMP_PDB_CANCEL && display)
{
- g_printerr ("conversion filename -> uri failed: %s\n",
- error->message);
+ gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
+ _("Opening '%s' failed: %s"),
+ gimp_file_get_utf8_name (file), error->message);
g_clear_error (&error);
}
+ if (display)
+ g_object_remove_weak_pointer (G_OBJECT (display), (gpointer) &display);
+
return success;
}
diff --git a/app/file/file-open.h b/app/file/file-open.h
index b60bb04..907168f 100644
--- a/app/file/file-open.h
+++ b/app/file/file-open.h
@@ -78,7 +78,7 @@ GList * file_open_layers (Gimp *gimp,
GError **error);
gboolean file_open_from_command_line (Gimp *gimp,
- const gchar *filename,
+ GFile *file,
gboolean as_new,
GObject *screen,
gint monitor);
diff --git a/app/file/file-utils.c b/app/file/file-utils.c
index 9c31d4f..3095a43 100644
--- a/app/file/file-utils.c
+++ b/app/file/file-utils.c
@@ -167,38 +167,6 @@ file_utils_filename_to_uri (Gimp *gimp,
return uri;
}
-GFile *
-file_utils_any_to_file (Gimp *gimp,
- const gchar *filename_or_uri,
- GError **error)
-{
- GFile *file;
- gchar *uri;
-
- g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
- g_return_val_if_fail (filename_or_uri != NULL, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- /* first try if we got a file uri */
- uri = g_filename_from_uri (filename_or_uri, NULL, NULL);
-
- if (uri)
- {
- g_free (uri);
- uri = g_strdup (filename_or_uri);
- }
- else
- {
- uri = file_utils_filename_to_uri (gimp, filename_or_uri, error);
- }
-
- file = g_file_new_for_uri (uri);
- g_free (uri);
-
- return file;
-}
-
-
/**
* file_utils_filename_from_uri:
* @uri: a URI
diff --git a/app/file/file-utils.h b/app/file/file-utils.h
index 379c5f4..0d9ac42 100644
--- a/app/file/file-utils.h
+++ b/app/file/file-utils.h
@@ -26,9 +26,6 @@ gboolean file_utils_filename_is_uri (const gchar *filename,
gchar * file_utils_filename_to_uri (Gimp *gimp,
const gchar *filename,
GError **error);
-GFile * file_utils_any_to_file (Gimp *gimp,
- const gchar *filename_or_uri,
- GError **error);
gchar * file_utils_filename_from_uri (const gchar *uri);
gchar * file_utils_filename_from_file (GFile *file);
gchar * file_utils_uri_with_new_ext (const gchar *uri,
diff --git a/app/gui/gimpdbusservice.c b/app/gui/gimpdbusservice.c
index cbf12f5..c9598c0 100644
--- a/app/gui/gimpdbusservice.c
+++ b/app/gui/gimpdbusservice.c
@@ -39,7 +39,7 @@
typedef struct
{
- gchar *uri;
+ GFile *file;
gboolean as_new;
} OpenData;
@@ -269,7 +269,7 @@ gimp_dbus_service_open_idle (GimpDBusService *service)
if (data)
{
- file_open_from_command_line (service->gimp, data->uri, data->as_new,
+ file_open_from_command_line (service->gimp, data->file, data->as_new,
NULL, /* FIXME monitor */
0 /* FIXME monitor */);
@@ -290,7 +290,7 @@ gimp_dbus_service_open_data_new (GimpDBusService *service,
{
OpenData *data = g_slice_new (OpenData);
- data->uri = g_strdup (uri);
+ data->file = g_file_new_for_uri (uri);
data->as_new = as_new;
return data;
@@ -299,6 +299,6 @@ gimp_dbus_service_open_data_new (GimpDBusService *service,
static void
gimp_dbus_service_open_data_free (OpenData *data)
{
- g_free (data->uri);
+ g_object_unref (data->file);
g_slice_free (OpenData, data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]