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




commit 4eb4d00f2c3e67066e872793250ef0becc511121
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        | 24 ++++++++++++------------
 src/nautilus-properties-window.c | 18 ++++++++++--------
 2 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 946771c7b..02bb069b1 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -5892,11 +5892,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)
         {
@@ -5922,7 +5923,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;
@@ -5963,19 +5964,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, "response",
                       G_CALLBACK (on_destination_dialog_response),
                       copy_data);
@@ -6375,7 +6375,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);
 
@@ -6411,14 +6411,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 8c74e49f4..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
@@ -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]