[gimp] app: port GimpThumbBox from URI to GFile



commit 69686fe4463568e17baf86bd39f26d73c7df7d63
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 8 00:58:42 2014 +0200

    app: port GimpThumbBox from URI to GFile

 app/widgets/gimpfiledialog.c |    8 ++--
 app/widgets/gimpthumbbox.c   |   63 ++++++++++++++++++++---------------------
 app/widgets/gimpthumbbox.h   |   12 ++++----
 3 files changed, 41 insertions(+), 42 deletions(-)
---
diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c
index 9f5d187..87510ab 100644
--- a/app/widgets/gimpfiledialog.c
+++ b/app/widgets/gimpfiledialog.c
@@ -968,16 +968,16 @@ static void
 gimp_file_dialog_selection_changed (GtkFileChooser *chooser,
                                     GimpFileDialog *dialog)
 {
-  gimp_thumb_box_take_uris (GIMP_THUMB_BOX (dialog->thumb_box),
-                            gtk_file_chooser_get_uris (chooser));
+  gimp_thumb_box_take_files (GIMP_THUMB_BOX (dialog->thumb_box),
+                             gtk_file_chooser_get_files (chooser));
 }
 
 static void
 gimp_file_dialog_update_preview (GtkFileChooser *chooser,
                                  GimpFileDialog *dialog)
 {
-  gimp_thumb_box_take_uri (GIMP_THUMB_BOX (dialog->thumb_box),
-                           gtk_file_chooser_get_preview_uri (chooser));
+  gimp_thumb_box_take_file (GIMP_THUMB_BOX (dialog->thumb_box),
+                            gtk_file_chooser_get_preview_file (chooser));
 }
 
 static void
diff --git a/app/widgets/gimpthumbbox.c b/app/widgets/gimpthumbbox.c
index 55149c5..01909df 100644
--- a/app/widgets/gimpthumbbox.c
+++ b/app/widgets/gimpthumbbox.c
@@ -39,7 +39,6 @@
 #include "plug-in/gimppluginmanager.h"
 
 #include "file/file-procedure.h"
-#include "file/file-utils.h"
 
 #include "gimpfiledialog.h" /* eek */
 #include "gimpthumbbox.h"
@@ -91,7 +90,7 @@ static void gimp_thumb_box_thumb_state_notify     (GimpThumbnail     *thumb,
 static void gimp_thumb_box_create_thumbnails      (GimpThumbBox      *box,
                                                    gboolean           force);
 static void gimp_thumb_box_create_thumbnail       (GimpThumbBox      *box,
-                                                   const gchar       *uri,
+                                                   GFile             *file,
                                                    GimpThumbnailSize  size,
                                                    gboolean           force,
                                                    GimpProgress      *progress);
@@ -158,7 +157,7 @@ gimp_thumb_box_finalize (GObject *object)
 {
   GimpThumbBox *box = GIMP_THUMB_BOX (object);
 
-  gimp_thumb_box_take_uris (box, NULL);
+  gimp_thumb_box_take_files (box, NULL);
 
   if (box->imagefile)
     {
@@ -444,10 +443,11 @@ gimp_thumb_box_new (GimpContext *context)
 }
 
 void
-gimp_thumb_box_take_uri (GimpThumbBox *box,
-                         gchar        *uri)
+gimp_thumb_box_take_file (GimpThumbBox *box,
+                          GFile        *file)
 {
   g_return_if_fail (GIMP_IS_THUMB_BOX (box));
+  g_return_if_fail (G_IS_FILE (file));
 
   if (box->idle_id)
     {
@@ -455,12 +455,11 @@ gimp_thumb_box_take_uri (GimpThumbBox *box,
       box->idle_id = 0;
     }
 
-  gimp_object_take_name (GIMP_OBJECT (box->imagefile), uri);
+  gimp_imagefile_set_file (box->imagefile, file);
 
-  if (uri)
+  if (file)
     {
-      gchar *basename = file_utils_uri_display_basename (uri);
-
+      gchar *basename = g_path_get_basename (gimp_file_get_utf8_name (file));
       gtk_label_set_text (GTK_LABEL (box->filename), basename);
       g_free (basename);
     }
@@ -469,23 +468,23 @@ gimp_thumb_box_take_uri (GimpThumbBox *box,
       gtk_label_set_text (GTK_LABEL (box->filename), _("No selection"));
     }
 
-  gtk_widget_set_sensitive (GTK_WIDGET (box), uri != NULL);
+  gtk_widget_set_sensitive (GTK_WIDGET (box), file != NULL);
   gimp_imagefile_update (box->imagefile);
 }
 
 void
-gimp_thumb_box_take_uris (GimpThumbBox *box,
-                          GSList       *uris)
+gimp_thumb_box_take_files (GimpThumbBox *box,
+                           GSList       *files)
 {
   g_return_if_fail (GIMP_IS_THUMB_BOX (box));
 
-  if (box->uris)
+  if (box->files)
     {
-      g_slist_free_full (box->uris, (GDestroyNotify) g_free);
-      box->uris = NULL;
+      g_slist_free_full (box->files, (GDestroyNotify) g_object_unref);
+      box->files = NULL;
     }
 
-  box->uris = uris;
+  box->files = files;
 }
 
 
@@ -554,7 +553,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
   GimpFileDialog *dialog   = NULL;
   GtkWidget      *toplevel;
   GSList         *list;
-  gint            n_uris;
+  gint            n_files;
   gint            i;
 
   if (gimp->config->thumbnail_size == GIMP_THUMBNAIL_SIZE_NONE)
@@ -572,15 +571,15 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
   else
     gtk_widget_set_sensitive (toplevel, FALSE);
 
-  if (box->uris)
+  if (box->files)
     {
       gtk_widget_hide (box->info);
       gtk_widget_show (box->progress);
     }
 
-  n_uris = g_slist_length (box->uris);
+  n_files = g_slist_length (box->files);
 
-  if (n_uris > 1)
+  if (n_files > 1)
     {
       gchar *str;
 
@@ -588,13 +587,13 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
 
       progress = gimp_sub_progress_new (GIMP_PROGRESS (box));
 
-      gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), 0, n_uris);
+      gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), 0, n_files);
 
-      for (list = box->uris->next, i = 1;
+      for (list = box->files->next, i = 1;
            list;
            list = g_slist_next (list), i++)
         {
-          str = g_strdup_printf (_("Thumbnail %d of %d"), i, n_uris);
+          str = g_strdup_printf (_("Thumbnail %d of %d"), i, n_files);
           gtk_progress_bar_set_text (GTK_PROGRESS_BAR (box->progress), str);
           g_free (str);
 
@@ -612,10 +611,10 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
           if (dialog && dialog->canceled)
             goto canceled;
 
-          gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), i, n_uris);
+          gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (progress), i, n_files);
         }
 
-      str = g_strdup_printf (_("Thumbnail %d of %d"), n_uris, n_uris);
+      str = g_strdup_printf (_("Thumbnail %d of %d"), n_files, n_files);
       gtk_progress_bar_set_text (GTK_PROGRESS_BAR (box->progress), str);
       g_free (str);
 
@@ -625,10 +624,10 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
         gtk_main_iteration ();
     }
 
-  if (box->uris)
+  if (box->files)
     {
       gimp_thumb_box_create_thumbnail (box,
-                                       box->uris->data,
+                                       box->files->data,
                                        gimp->config->thumbnail_size,
                                        force,
                                        progress);
@@ -638,7 +637,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
 
  canceled:
 
-  if (n_uris > 1)
+  if (n_files > 1)
     {
       g_object_unref (progress);
 
@@ -646,7 +645,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
       gtk_progress_bar_set_text (GTK_PROGRESS_BAR (box->progress), "");
     }
 
-  if (box->uris)
+  if (box->files)
     {
       gtk_widget_hide (box->progress);
       gtk_widget_show (box->info);
@@ -662,7 +661,7 @@ gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
 
 static void
 gimp_thumb_box_create_thumbnail (GimpThumbBox      *box,
-                                 const gchar       *uri,
+                                 GFile             *file,
                                  GimpThumbnailSize  size,
                                  gboolean           force,
                                  GimpProgress      *progress)
@@ -670,11 +669,11 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox      *box,
   GimpThumbnail *thumb = gimp_imagefile_get_thumbnail (box->imagefile);
   gchar         *basename;
 
-  basename = file_utils_uri_display_basename (uri);
+  basename = g_path_get_basename (gimp_file_get_utf8_name (file));
   gtk_label_set_text (GTK_LABEL (box->filename), basename);
   g_free (basename);
 
-  gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
+  gimp_imagefile_set_file (box->imagefile, file);
 
   if (force ||
       (gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED &&
diff --git a/app/widgets/gimpthumbbox.h b/app/widgets/gimpthumbbox.h
index 6245cc4..eb9999e 100644
--- a/app/widgets/gimpthumbbox.h
+++ b/app/widgets/gimpthumbbox.h
@@ -35,7 +35,7 @@ struct _GimpThumbBox
 
   GimpContext   *context;
   GimpImagefile *imagefile;
-  GSList        *uris;
+  GSList        *files;
 
   GtkWidget     *preview;
   GtkWidget     *filename;
@@ -55,12 +55,12 @@ struct _GimpThumbBoxClass
 
 GType       gimp_thumb_box_get_type  (void) G_GNUC_CONST;
 
-GtkWidget * gimp_thumb_box_new       (GimpContext  *context);
+GtkWidget * gimp_thumb_box_new        (GimpContext  *context);
 
-void        gimp_thumb_box_take_uri  (GimpThumbBox *box,
-                                      gchar        *uri);
-void        gimp_thumb_box_take_uris (GimpThumbBox *box,
-                                      GSList       *uris);
+void        gimp_thumb_box_take_file  (GimpThumbBox *box,
+                                       GFile        *file);
+void        gimp_thumb_box_take_files (GimpThumbBox *box,
+                                       GSList       *files);
 
 
 #endif  /*  __GIMP_THUMB_BOX_H__  */


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