[nautilus/wip/antoniof/gtk4-preparation-file-chooser-api: 33/33] general: Move to GFile-centric GtkFileChooser API




commit 5d243fd9722ab31a1ae112d5ca695d2e86bc536b
Author: António Fernandes <antoniof gnome org>
Date:   Wed Dec 22 23:48:26 2021 +0000

    general: Move to GFile-centric GtkFileChooser API
    
    This is going to make the switch to GTK 4 simpler, because URI and path-
    based API is gone there.

 src/nautilus-files-view.c        | 37 +++++++++++++++++--------------------
 src/nautilus-properties-window.c | 20 +++++++++++---------
 2 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index c8baef465..5ceeaeb65 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -5884,16 +5884,14 @@ copy_data_free (CopyCallbackData *data)
 }
 
 static gboolean
-uri_is_parent_of_selection (GList      *selection,
-                            const char *uri)
+uri_is_parent_of_selection (GList *selection,
+                            GFile *file)
 {
     gboolean found;
     GList *l;
-    GFile *file;
 
     found = FALSE;
 
-    file = g_file_new_for_uri (uri);
     for (l = selection; !found && l != NULL; l = l->next)
     {
         GFile *parent;
@@ -5901,7 +5899,6 @@ uri_is_parent_of_selection (GList      *selection,
         found = g_file_equal (file, parent);
         g_object_unref (parent);
     }
-    g_object_unref (file);
     return found;
 }
 
@@ -5910,13 +5907,12 @@ on_destination_dialog_folder_changed (GtkFileChooser *chooser,
                                       gpointer        user_data)
 {
     CopyCallbackData *copy_data = user_data;
-    char *uri;
+    g_autoptr (GFile) file = NULL;
     gboolean found;
 
-    uri = gtk_file_chooser_get_current_folder_uri (chooser);
-    found = uri_is_parent_of_selection (copy_data->selection, uri);
+    file = gtk_file_chooser_get_current_folder_file (chooser);
+    found = uri_is_parent_of_selection (copy_data->selection, file);
     gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_OK, !found);
-    g_free (uri);
 }
 
 static void
@@ -5928,10 +5924,12 @@ on_destination_dialog_response (GtkDialog *dialog,
 
     if (response_id == GTK_RESPONSE_OK)
     {
+        g_autoptr (GFile) target_location = NULL;
         char *target_uri;
         GList *uris, *l;
 
-        target_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+        target_location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+        target_uri = g_file_get_uri (target_location);
 
         uris = NULL;
         for (l = copy_data->selection; l != NULL; l = l->next)
@@ -5975,7 +5973,7 @@ copy_or_move_selection (NautilusFilesView *view,
 {
     NautilusFilesViewPrivate *priv;
     GtkWidget *dialog;
-    char *uri;
+    g_autoptr (GFile) location = NULL;
     CopyCallbackData *copy_data;
     GList *selection;
     const gchar *title;
@@ -6016,19 +6014,18 @@ copy_or_move_selection (NautilusFilesView *view,
     if (nautilus_view_is_searching (NAUTILUS_VIEW (view)))
     {
         directory = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (priv->model));
-        uri = nautilus_directory_get_uri (directory);
+        location = nautilus_directory_get_location (directory);
     }
     else if (showing_starred_directory (view))
     {
-        uri = nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data));
+        location = nautilus_file_get_parent_location (NAUTILUS_FILE (selection->data));
     }
     else
     {
-        uri = nautilus_directory_get_uri (priv->model);
+        location = nautilus_directory_get_location (priv->model);
     }
 
-    gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
-    g_free (uri);
+    gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), location, NULL);
     g_signal_connect (dialog, "current-folder-changed",
                       G_CALLBACK (on_destination_dialog_folder_changed),
                       copy_data);
@@ -6431,7 +6428,7 @@ extract_files_to_chosen_location (NautilusFilesView *view,
     NautilusFilesViewPrivate *priv;
     ExtractToData *data;
     GtkWidget *dialog;
-    g_autofree char *uri = NULL;
+    g_autoptr (GFile) location = NULL;
 
     priv = nautilus_files_view_get_instance_private (view);
 
@@ -6467,14 +6464,14 @@ extract_files_to_chosen_location (NautilusFilesView *view,
 
         search_directory = NAUTILUS_SEARCH_DIRECTORY (priv->model);
         directory = nautilus_search_directory_get_base_model (search_directory);
-        uri = nautilus_directory_get_uri (directory);
+        location = nautilus_directory_get_location (directory);
     }
     else
     {
-        uri = nautilus_directory_get_uri (priv->model);
+        location = nautilus_directory_get_location (priv->model);
     }
 
-    gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
+    gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), location, NULL);
 
     data->view = view;
     data->files = nautilus_file_list_copy (files);
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index ebff01395..40cc9b1e4 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -5207,11 +5207,13 @@ custom_icon_file_chooser_response_cb (GtkDialog                *dialog,
 
         case GTK_RESPONSE_OK:
         {
+            g_autoptr (GFile) location = NULL;
             g_autofree gchar *uri = NULL;
 
-            uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-            if (uri != NULL)
+            location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+            if (location != NULL)
             {
+                uri = g_file_get_uri (location);
                 set_icon (uri, self);
             }
             else
@@ -5234,7 +5236,7 @@ static void
 select_image_button_callback (GtkWidget                *widget,
                               NautilusPropertiesWindow *self)
 {
-    GtkWidget *dialog, *preview;
+    GtkWidget *dialog;
     GtkFileFilter *filter;
     GList *l;
     NautilusFile *file;
@@ -5275,15 +5277,15 @@ select_image_button_callback (GtkWidget                *widget,
 
         if (nautilus_file_is_directory (file))
         {
-            g_autofree gchar *uri = NULL;
-            g_autofree gchar *image_path = NULL;
+            g_autoptr (GFile) image_location = NULL;
 
-            uri = nautilus_file_get_uri (file);
+            image_location = nautilus_file_get_location (file);
 
-            image_path = g_filename_from_uri (uri, NULL, NULL);
-            if (image_path != NULL)
+            if (image_location != NULL)
             {
-                gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), image_path);
+                gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
+                                                          image_location,
+                                                          NULL);
             }
         }
     }


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