[nautilus/gtk4-preparation-trunk: 52/64] general: Move to GFile-centric GtkFileChooser API
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk4-preparation-trunk: 52/64] general: Move to GFile-centric GtkFileChooser API
- Date: Thu, 23 Dec 2021 02:10:17 +0000 (UTC)
commit d6e64f50254f9c37f2d44a8647e9f6502ab686b2
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 af4b019c3..c8478a13d 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -5870,16 +5870,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;
@@ -5887,7 +5885,6 @@ uri_is_parent_of_selection (GList *selection,
found = g_file_equal (file, parent);
g_object_unref (parent);
}
- g_object_unref (file);
return found;
}
@@ -5896,13 +5893,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
@@ -5914,10 +5910,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)
@@ -5944,7 +5942,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;
@@ -5985,19 +5983,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);
@@ -6400,7 +6397,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);
@@ -6436,14 +6433,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 304c5311c..873857cf5 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -5188,11 +5188,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
@@ -5215,7 +5217,7 @@ static void
select_image_button_callback (GtkWidget *widget,
NautilusPropertiesWindow *self)
{
- GtkWidget *dialog, *preview;
+ GtkWidget *dialog;
GtkFileFilter *filter;
GList *l;
NautilusFile *file;
@@ -5256,15 +5258,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]