[gimp] app: Cleanup gimp_display_shell_format_filename()



commit 27f12b2505ecb18fa3a29f12738c485a21350deb
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Jul 5 23:58:55 2009 +0200

    app: Cleanup gimp_display_shell_format_filename()

 app/display/gimpdisplayshell-title.c |   55 +++++++++++++++-------------------
 1 files changed, 24 insertions(+), 31 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-title.c b/app/display/gimpdisplayshell-title.c
index 4793583..bda0785 100644
--- a/app/display/gimpdisplayshell-title.c
+++ b/app/display/gimpdisplayshell-title.c
@@ -441,35 +441,39 @@ gimp_display_shell_format_filename (gchar       *buf,
                                     GimpImage   *image,
                                     const gchar *filename)
 {
-  gint         incr          = 0;
+  const gchar *source        = NULL;
   const gchar *name_format   = NULL;
-  const gchar *name          = NULL;
   const gchar *export_status = NULL;
-  const gchar *format_string = NULL;
-  const gchar *source        = NULL;
-  const gchar *export_to     = NULL;
+  gchar       *format_string = NULL;
+  gchar       *name          = NULL;
+  gint         incr          = 0;
 
-  source    = g_object_get_data (G_OBJECT (image),
-                                 GIMP_FILE_IMPORT_SOURCE_URI_KEY);
-  export_to = g_object_get_data (G_OBJECT (image),
-                                 GIMP_FILE_EXPORT_TO_URI_KEY);
+  source = g_object_get_data (G_OBJECT (image),
+                              GIMP_FILE_IMPORT_SOURCE_URI_KEY);
 
-  if (source)
+  /* Calculate filename and format */
+  if (! source)
     {
       /* As soon as the image is saved the source is forgotten, so the
-       * above condition is enough to figure out name_format and name
+       * above condition is enough to figure out name and name format
        */
-      name_format = "[%s]";
-      name        = source;
+      name        = g_strdup (filename);
+      name_format = "%s";
     }
   else
     {
-      name_format = "%s";
-      name        = gimp_object_get_name (GIMP_OBJECT (image));
+      gchar *source_no_ext = file_utils_uri_with_new_ext (source, NULL);
+      name = file_utils_uri_display_basename (source_no_ext);
+      g_free (source_no_ext);
+
+      name_format = "[%s]";
     }
 
+  /* Calculate filename suffix */
   if (! gimp_image_is_export_dirty (image))
     {
+      const gchar *export_to = g_object_get_data (G_OBJECT (image),
+                                                  GIMP_FILE_EXPORT_TO_URI_KEY);
       if (export_to)
         export_status = _(" (exported)");
       else if (source)
@@ -482,24 +486,13 @@ gimp_display_shell_format_filename (gchar       *buf,
       export_status = _(" (imported)");
     }
 
+  /* Merge strings and print the result */
   format_string = g_strconcat (name_format, export_status, NULL);
-
-  if (source)
-    {
-      gchar *source_no_ext   = file_utils_uri_with_new_ext (source, NULL);
-      gchar *source_basename = file_utils_uri_display_basename (source_no_ext);
-
-      incr = print (buf, len, start, format_string, source_basename);
-
-      g_free (source_basename);
-      g_free (source_no_ext);
-    }
-  else
-    {
-      incr = print (buf, len, start, format_string, filename);
-    }
-
+  incr = print (buf, len, start, format_string, name);
   g_free (format_string);
 
+  /* Cleanup */
+  g_free (name);
+
   return incr;
 }



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