[gimp] app: keep the image's "Untitled" string around as GFile too



commit 7f966cad393669c179116c20c09b5705071e945c
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 8 00:15:41 2014 +0200

    app: keep the image's "Untitled" string around as GFile too

 app/core/gimpimage-private.h |    1 +
 app/core/gimpimage.c         |   51 +++++++++++++++++++++++++++--------------
 app/core/gimpimage.h         |    7 ++---
 app/widgets/gimpfiledialog.c |    6 +---
 4 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index d5e5340..4e92095 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 474c915..5d659e6 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");
+  GimpImagePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  if (! private->untitled_file)
+    private->untitled_file = g_file_new_for_uri (_("Untitled"));
+
+  return private->untitled_file;
 }
 
 /**
- * gimp_image_get_uri_or_untitled:
+ * gimp_image_get_file_or_untitled:
  * @image: A #GimpImage.
  *
- * Get the URI of the XCF image, or "Untitled" if there is no URI.
+ * Get the file of the XCF image, or the "Untitled" file if there is no file.
  *
- * Returns: The URI, or "Untitled".
+ * Returns: A #GFile.
  **/
-const gchar *
-gimp_image_get_uri_or_untitled (const GimpImage *image)
+GFile *
+gimp_image_get_file_or_untitled (const GimpImage *image)
 {
-  const gchar *uri;
+  GFile *file;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
-  uri = gimp_object_get_name (image);
+  file = gimp_image_get_file (image);
+
+  if (! file)
+    file = gimp_image_get_untitled_file (image);
 
-  return uri ? uri : gimp_image_get_string_untitled ();
+  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 87c8532..3f60e8a 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 9c355ec..9f5d187 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:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]