diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h index d5e5340d18..4e920958db 100644 --- a/app/core/gimpimage-private.h +++ b/app/core/gimpimage-private.h @@ -62,6 +62,7 @@ struct _GimpImagePrivate GFile *imported_file; /* the image's source file */ GFile *exported_file; /* the image's export file */ GFile *save_a_copy_file; /* the image's save-a-copy file */ + GFile *untitled_file; /* a file saying "Untitled" */ gint dirty; /* dirty flag -- # of ops */ guint dirty_time; /* time when image became dirty */ diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 474c9159a3..5d659e6acb 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -993,6 +993,12 @@ gimp_image_finalize (GObject *object) private->save_a_copy_file = NULL; } + if (private->untitled_file) + { + g_object_unref (private->untitled_file); + private->untitled_file = NULL; + } + if (private->layers) { g_object_unref (private->layers); @@ -1866,35 +1872,46 @@ gimp_image_take_uri (GimpImage *image, } /** - * gimp_image_get_untitled_string: + * gimp_image_get_untitled_file: * - * Returns: The (translated) "Untitled" string for newly created - * images. + * Returns: A #GFile saying "Untitled" for newly created images. **/ -const gchar * -gimp_image_get_string_untitled (void) +GFile * +gimp_image_get_untitled_file (const GimpImage *image) { - return _("Untitled"); -} - -/** - * gimp_image_get_uri_or_untitled: - * @image: A #GimpImage. - * - * Get the URI of the XCF image, or "Untitled" if there is no URI. - * - * Returns: The URI, or "Untitled". - **/ -const gchar * -gimp_image_get_uri_or_untitled (const GimpImage *image) -{ - const gchar *uri; + GimpImagePrivate *private; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); - uri = gimp_object_get_name (image); + private = GIMP_IMAGE_GET_PRIVATE (image); - return uri ? uri : gimp_image_get_string_untitled (); + if (! private->untitled_file) + private->untitled_file = g_file_new_for_uri (_("Untitled")); + + return private->untitled_file; +} + +/** + * gimp_image_get_file_or_untitled: + * @image: A #GimpImage. + * + * Get the file of the XCF image, or the "Untitled" file if there is no file. + * + * Returns: A #GFile. + **/ +GFile * +gimp_image_get_file_or_untitled (const GimpImage *image) +{ + GFile *file; + + g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); + + file = gimp_image_get_file (image); + + if (! file) + file = gimp_image_get_untitled_file (image); + + return file; } /** @@ -2141,7 +2158,7 @@ gimp_image_format_display_uri (GimpImage *image, if (file) { - display_file = g_object_ref (file); + display_file = file; uri_format = "%s"; } else @@ -2178,15 +2195,13 @@ gimp_image_format_display_uri (GimpImage *image, } if (! display_file) - display_file = g_file_new_for_uri (gimp_image_get_string_untitled ()); + display_file = gimp_image_get_untitled_file (image); if (basename) display_uri = g_path_get_basename (gimp_file_get_utf8_name (display_file)); else display_uri = g_strdup (gimp_file_get_utf8_name (display_file)); - g_object_unref (display_file); - format_string = g_strconcat (uri_format, export_status, NULL); tmp = g_strdup_printf (format_string, display_uri); diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index 87c85320d3..3f60e8a018 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -133,8 +133,9 @@ GimpImage * gimp_image_get_by_ID (Gimp *gimp, gint id); GFile * gimp_image_get_file (const GimpImage *image); -const gchar * gimp_image_get_uri_or_untitled (const GimpImage *image); -GFile * gimp_image_get_imported_file (const GimpImage *image); +GFile * gimp_image_get_untitled_file (const GimpImage *image); +GFile * gimp_image_get_file_or_untitled (const GimpImage *image); +GFile * gimp_image_get_imported_file (const GimpImage *image); GFile * gimp_image_get_exported_file (const GimpImage *image); GFile * gimp_image_get_save_a_copy_file (const GimpImage *image); GFile * gimp_image_get_any_file (const GimpImage *image); @@ -429,7 +430,5 @@ gboolean gimp_image_coords_in_active_pickable (GimpImage *image, void gimp_image_invalidate_previews (GimpImage *image); -const gchar * gimp_image_get_string_untitled (void); - #endif /* __GIMP_IMAGE_H__ */ diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index 9c355ecd60..9f5d187204 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -563,8 +563,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog, name_file = gimp_image_get_imported_file (image); if (! name_file) - /* XXX leak */ - name_file = g_file_new_for_uri (gimp_image_get_string_untitled ()); + name_file = gimp_image_get_untitled_file (image); /* Priority of default type/extension for Save: @@ -631,8 +630,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog, name_file = gimp_image_get_imported_file (image); if (! name_file) - /* XXX leak */ - name_file = g_file_new_for_uri (gimp_image_get_string_untitled ()); + name_file = gimp_image_get_untitled_file (image); /* Priority of default type/extension for Export: