[gtk/wip/ebassi/filechooser-new] Remove filename/URI API from GtkFileChooser
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/filechooser-new] Remove filename/URI API from GtkFileChooser
- Date: Fri, 21 Feb 2020 15:21:51 +0000 (UTC)
commit bc2d277a4b1f4bab71703198dd624604369eaa20
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Feb 21 15:11:15 2020 +0000
Remove filename/URI API from GtkFileChooser
GtkFileChooser's API predates GIO by a few years, so it started off with
filenames and URI as character arrays. After introducing GIO as a
dependency, the API included GFile-based entry points.
It's much more appropriate to use GFile everywhere, as we want to
encourage people to use GIO instead of passing random bytes to low level
POSIX API.
See: #2455
demos/constraint-editor/constraint-editor-window.c | 32 +-
demos/node-editor/node-editor-window.c | 38 +-
docs/reference/gtk/gtk4-sections.txt | 36 +-
gtk/gtkfilechooser.c | 1127 +++-----------------
gtk/gtkfilechooser.h | 67 +-
gtk/gtkfilechooserbutton.c | 15 +-
gtk/gtkfilechooserdialog.c | 31 +-
gtk/gtkfilechoosernative.c | 4 +-
gtk/gtkfilechoosernativewin32.c | 12 +-
gtk/gtkfilechooserprivate.h | 8 -
gtk/gtkfilechooserutils.c | 10 +-
gtk/gtkfilechooserwidget.c | 23 +-
gtk/gtkprinteroptionwidget.c | 70 +-
gtk/inspector/css-editor.c | 22 +-
tests/print-editor.c | 66 +-
tests/testfilechooser.c | 69 +-
tests/testfilechooserbutton.c | 98 +-
tests/testgtk.c | 27 +-
18 files changed, 514 insertions(+), 1241 deletions(-)
---
diff --git a/demos/constraint-editor/constraint-editor-window.c
b/demos/constraint-editor/constraint-editor-window.c
index 48d092c9da..c4b545c2d8 100644
--- a/demos/constraint-editor/constraint-editor-window.c
+++ b/demos/constraint-editor/constraint-editor-window.c
@@ -221,9 +221,12 @@ open_cb (GtkWidget *button,
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Load",
"_Cancel");
-
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
+
+ GFile *cwd = g_file_new_for_path (".");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
+ g_object_unref (cwd);
+
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
}
@@ -290,14 +293,20 @@ save_response_cb (GtkNativeDialog *dialog,
if (response == GTK_RESPONSE_ACCEPT)
{
GListModel *model;
- char *text, *filename;
+ GFile *file;
+ char *text;
GError *error = NULL;
model = constraint_view_get_model (CONSTRAINT_VIEW (self->view));
text = serialize_model (model);
-
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (!g_file_set_contents (filename, text, -1, &error))
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ g_file_replace_contents (file, text, -1,
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ NULL,
+ &error);
+ if (error != NULL)
{
GtkWidget *dialog;
@@ -312,7 +321,9 @@ save_response_cb (GtkNativeDialog *dialog,
gtk_widget_show (dialog);
g_error_free (error);
}
- g_free (filename);
+
+ g_free (text);
+ g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
@@ -329,9 +340,12 @@ save_cb (GtkWidget *button,
GTK_FILE_CHOOSER_ACTION_SAVE,
"_Save",
"_Cancel");
-
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
+
+ GFile *cwd = g_file_new_for_path (".");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
+ g_object_unref (cwd);
+
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
}
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c
index 9e880354f3..3bb2318654 100644
--- a/demos/node-editor/node-editor-window.c
+++ b/demos/node-editor/node-editor-window.c
@@ -385,7 +385,11 @@ show_open_filechooser (NodeEditorWindow *self)
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
+
+ GFile *cwd = g_file_new_for_path (".");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
+ g_object_unref (cwd);
+
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
gtk_widget_show (dialog);
}
@@ -406,13 +410,20 @@ save_response_cb (GtkWidget *dialog,
if (response == GTK_RESPONSE_ACCEPT)
{
- char *text, *filename;
+ GFile *file;
+ char *text;
GError *error = NULL;
text = get_current_text (self->text_buffer);
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (!g_file_set_contents (filename, text, -1, &error))
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ g_file_replace_contents (file, text, -1,
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ NULL,
+ &error);
+ if (error != NULL)
{
GtkWidget *dialog;
@@ -427,7 +438,9 @@ save_response_cb (GtkWidget *dialog,
gtk_widget_show (dialog);
g_error_free (error);
}
- g_free (filename);
+
+ g_free (text);
+ g_object_unref (file);
}
gtk_widget_destroy (dialog);
@@ -449,7 +462,11 @@ save_cb (GtkWidget *button,
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
+
+ GFile *cwd = g_file_new_for_path (".");
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
+ g_object_unref (cwd);
+
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
gtk_widget_show (dialog);
}
@@ -523,10 +540,10 @@ export_image_response_cb (GtkWidget *dialog,
if (response == GTK_RESPONSE_ACCEPT)
{
- char *filename;
+ GFile *file;
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (!gdk_texture_save_to_png (texture, filename))
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ if (!gdk_texture_save_to_png (texture, g_file_peek_path (file)))
{
GtkWidget *message_dialog;
@@ -538,7 +555,8 @@ export_image_response_cb (GtkWidget *dialog,
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show (message_dialog);
}
- g_free (filename);
+
+ g_object_unref (file);
}
gtk_widget_destroy (dialog);
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 6b4dfca4b1..804cb9b24c 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1140,51 +1140,37 @@ gtk_file_chooser_set_create_folders
gtk_file_chooser_get_create_folders
gtk_file_chooser_set_current_name
gtk_file_chooser_get_current_name
-gtk_file_chooser_get_filename
-gtk_file_chooser_set_filename
-gtk_file_chooser_select_filename
-gtk_file_chooser_unselect_filename
+<SUBSECTION>
+gtk_file_chooser_get_file
+gtk_file_chooser_set_file
+gtk_file_chooser_select_file
+gtk_file_chooser_unselect_file
gtk_file_chooser_select_all
gtk_file_chooser_unselect_all
-gtk_file_chooser_get_filenames
+gtk_file_chooser_get_files
gtk_file_chooser_set_current_folder
gtk_file_chooser_get_current_folder
-gtk_file_chooser_get_uri
-gtk_file_chooser_set_uri
-gtk_file_chooser_select_uri
-gtk_file_chooser_unselect_uri
-gtk_file_chooser_get_uris
-gtk_file_chooser_set_current_folder_uri
-gtk_file_chooser_get_current_folder_uri
+<SUBSECTION>
gtk_file_chooser_set_preview_widget
gtk_file_chooser_get_preview_widget
gtk_file_chooser_set_preview_widget_active
gtk_file_chooser_get_preview_widget_active
gtk_file_chooser_set_use_preview_label
gtk_file_chooser_get_use_preview_label
-gtk_file_chooser_get_preview_filename
-gtk_file_chooser_get_preview_uri
+gtk_file_chooser_get_preview_file
gtk_file_chooser_set_extra_widget
gtk_file_chooser_get_extra_widget
+<SUBSECTION>
gtk_file_chooser_add_filter
gtk_file_chooser_remove_filter
gtk_file_chooser_list_filters
gtk_file_chooser_set_filter
gtk_file_chooser_get_filter
+<SUBSECTION>
gtk_file_chooser_add_shortcut_folder
gtk_file_chooser_remove_shortcut_folder
gtk_file_chooser_list_shortcut_folders
-gtk_file_chooser_add_shortcut_folder_uri
-gtk_file_chooser_remove_shortcut_folder_uri
-gtk_file_chooser_list_shortcut_folder_uris
-gtk_file_chooser_get_current_folder_file
-gtk_file_chooser_get_file
-gtk_file_chooser_get_files
-gtk_file_chooser_get_preview_file
-gtk_file_chooser_select_file
-gtk_file_chooser_set_current_folder_file
-gtk_file_chooser_set_file
-gtk_file_chooser_unselect_file
+<SUBSECTION>
gtk_file_chooser_add_choice
gtk_file_chooser_remove_choice
gtk_file_chooser_set_choice
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index b858f83251..25ea82ff36 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -58,22 +58,8 @@
* # File Names and Encodings
*
* When the user is finished selecting files in a
- * #GtkFileChooser, your program can get the selected names
- * either as filenames or as URIs. For URIs, the normal escaping
- * rules are applied if the URI contains non-ASCII characters.
- * However, filenames are always returned in
- * the character set specified by the
- * `G_FILENAME_ENCODING` environment variable.
- * Please see the GLib documentation for more details about this
- * variable.
- *
- * This means that while you can pass the result of
- * gtk_file_chooser_get_filename() to open() or fopen(),
- * you may not be able to directly set it as the text of a
- * #GtkLabel widget unless you convert it first to UTF-8,
- * which all GTK+ widgets expect. You should use g_filename_to_utf8()
- * to convert filenames into strings that can be passed to GTK+
- * widgets.
+ * #GtkFileChooser, your program can get the selected filenames as
+ * #GFiles.
*
* # Adding a Preview Widget
*
@@ -85,7 +71,7 @@
* you need to update the contents of the preview.
*
* Your callback should use
- * gtk_file_chooser_get_preview_filename() to see what needs
+ * gtk_file_chooser_get_preview_file() to see what needs
* previewing. Once you have generated the preview for the
* corresponding file, you must call
* gtk_file_chooser_set_preview_widget_active() with a boolean
@@ -103,27 +89,29 @@
*
* gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
* g_signal_connect (my_file_chooser, "update-preview",
- * G_CALLBACK (update_preview_cb), preview);
+ * G_CALLBACK (update_preview_cb), preview);
* }
*
* static void
* update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
* {
- * GtkWidget *preview;
- * char *filename;
- * GdkPixbuf *pixbuf;
- * gboolean have_preview;
+ * GtkWidget *preview = data;
*
- * preview = GTK_WIDGET (data);
- * filename = gtk_file_chooser_get_preview_filename (file_chooser);
+ * g_autoptr(GFile) preview_file =
+ * gtk_file_chooser_get_preview_file (file_chooser);
*
- * pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
- * have_preview = (pixbuf != NULL);
- * g_free (filename);
+ * g_autoptr(GFileInputStream) preview_stream =
+ * g_file_read (preview_file, NULL, NULL);
+ *
+ * GdkPixbuf *pixbuf =
+ * gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (preview_stream),
+ * 128, 128, TRUE,
+ * NULL,
+ * NULL);
+ * gboolean have_preview = pixbuf != NULL;
*
* gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
- * if (pixbuf)
- * g_object_unref (pixbuf);
+ * g_clear_object (&pixbuf);
*
* gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
* }
@@ -163,9 +151,9 @@ G_DEFINE_INTERFACE (GtkFileChooser, gtk_file_chooser, G_TYPE_OBJECT);
static gboolean
confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
- GValue *return_accu,
- const GValue *handler_return,
- gpointer dummy)
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer dummy)
{
gboolean continue_emission;
GtkFileChooserConfirmation conf;
@@ -197,16 +185,14 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
*
* See also: gtk_file_chooser_set_current_folder(),
* gtk_file_chooser_get_current_folder(),
- * gtk_file_chooser_set_current_folder_uri(),
- * gtk_file_chooser_get_current_folder_uri().
*/
g_signal_new (I_("current-folder-changed"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, current_folder_changed),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
/**
* GtkFileChooser::selection-changed:
@@ -220,20 +206,14 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* Normally you do not need to connect to this signal, as it is easier to wait
* for the file chooser to finish running, and then to get the list of
* selected files using the functions mentioned below.
- *
- * See also: gtk_file_chooser_select_filename(),
- * gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
- * gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
- * gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
- * gtk_file_chooser_get_uris().
*/
g_signal_new (I_("selection-changed"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
/**
* GtkFileChooser::update-preview:
@@ -247,8 +227,7 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* Once you have installed a preview widget with
* gtk_file_chooser_set_preview_widget(), you should update it when this
* signal is emitted. You can use the functions
- * gtk_file_chooser_get_preview_filename() or
- * gtk_file_chooser_get_preview_uri() to get the name of the file to preview.
+ * gtk_file_chooser_get_preview_file() to get the name of the file to preview.
* Your widget may not be able to preview all kinds of files; your callback
* must call gtk_file_chooser_set_preview_widget_active() to inform the file
* chooser about whether the preview was generated successfully or not.
@@ -259,16 +238,15 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* See also: gtk_file_chooser_set_preview_widget(),
* gtk_file_chooser_set_preview_widget_active(),
* gtk_file_chooser_set_use_preview_label(),
- * gtk_file_chooser_get_preview_filename(),
- * gtk_file_chooser_get_preview_uri().
+ * gtk_file_chooser_get_preview_file()
*/
g_signal_new (I_("update-preview"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, update_preview),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
/**
* GtkFileChooser::file-activated:
@@ -282,17 +260,15 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* by #GtkFileChooserDialog to know when to activate the default button in the
* dialog.
*
- * See also: gtk_file_chooser_get_filename(),
- * gtk_file_chooser_get_filenames(), gtk_file_chooser_get_uri(),
- * gtk_file_chooser_get_uris().
+ * See also: gtk_file_chooser_get_file(), gtk_file_chooser_get_files()
*/
g_signal_new (I_("file-activated"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
/**
* GtkFileChooser::confirm-overwrite:
@@ -329,18 +305,22 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* static GtkFileChooserConfirmation
* confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
* {
- * char *uri;
+ * g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);
*
- * uri = gtk_file_chooser_get_uri (chooser);
- *
- * if (is_uri_read_only (uri))
+ * // file_is_read_only() is defined elsewhere
+ * if (file_is_read_only (file))
* {
- * if (user_wants_to_replace_read_only_file (uri))
+ * // user_wants_to_replace_read_only_file() is defined elsewhere
+ * if (user_wants_to_replace_read_only_file (file))
* return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
* else
* return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
- * } else
- * return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
+ * }
+ * else
+ * {
+ * // fall back to the default dialog
+ * return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
+ * }
* }
*
* ...
@@ -352,7 +332,7 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* G_CALLBACK (confirm_overwrite_callback), NULL);
*
* if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
- * save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
+ * save_to_file (gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
*
* gtk_widget_destroy (chooser);
* ]|
@@ -361,69 +341,69 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* action to take after emitting the signal.
*/
g_signal_new (I_("confirm-overwrite"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
- confirm_overwrite_accumulator, NULL,
- _gtk_marshal_ENUM__VOID,
- GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
+ confirm_overwrite_accumulator, NULL,
+ _gtk_marshal_ENUM__VOID,
+ GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
g_object_interface_install_property (iface,
- g_param_spec_enum ("action",
- P_("Action"),
- P_("The type of operation that the file selector is
performing"),
- GTK_TYPE_FILE_CHOOSER_ACTION,
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_PARAM_READWRITE));
+ g_param_spec_enum ("action",
+ P_("Action"),
+ P_("The type of operation that the file selector
is performing"),
+ GTK_TYPE_FILE_CHOOSER_ACTION,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_object ("filter",
- P_("Filter"),
- P_("The current filter for selecting which files
are displayed"),
- GTK_TYPE_FILE_FILTER,
- GTK_PARAM_READWRITE));
+ g_param_spec_object ("filter",
+ P_("Filter"),
+ P_("The current filter for selecting which files
are displayed"),
+ GTK_TYPE_FILE_FILTER,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_boolean ("local-only",
- P_("Local Only"),
- P_("Whether the selected file(s) should be
limited to local file: URLs"),
- FALSE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("local-only",
+ P_("Local Only"),
+ P_("Whether the selected file(s) should be
limited to local file: URLs"),
+ FALSE,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_object ("preview-widget",
- P_("Preview widget"),
- P_("Application supplied widget for custom
previews."),
- GTK_TYPE_WIDGET,
- GTK_PARAM_READWRITE));
+ g_param_spec_object ("preview-widget",
+ P_("Preview widget"),
+ P_("Application supplied widget for custom
previews."),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_boolean ("preview-widget-active",
- P_("Preview Widget Active"),
- P_("Whether the application supplied widget for
custom previews should be shown."),
- TRUE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("preview-widget-active",
+ P_("Preview Widget Active"),
+ P_("Whether the application supplied widget for
custom previews should be shown."),
+ TRUE,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_boolean ("use-preview-label",
- P_("Use Preview Label"),
- P_("Whether to display a label with the name of
the previewed file."),
- TRUE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("use-preview-label",
+ P_("Use Preview Label"),
+ P_("Whether to display a label with the name of
the previewed file."),
+ TRUE,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_object ("extra-widget",
- P_("Extra widget"),
- P_("Application supplied widget for extra
options."),
- GTK_TYPE_WIDGET,
- GTK_PARAM_READWRITE));
+ g_param_spec_object ("extra-widget",
+ P_("Extra widget"),
+ P_("Application supplied widget for extra
options."),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_boolean ("select-multiple",
- P_("Select Multiple"),
- P_("Whether to allow multiple files to be
selected"),
- FALSE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("select-multiple",
+ P_("Select Multiple"),
+ P_("Whether to allow multiple files to be
selected"),
+ FALSE,
+ GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
- g_param_spec_boolean ("show-hidden",
- P_("Show Hidden"),
- P_("Whether the hidden files and folders should
be displayed"),
- FALSE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("show-hidden",
+ P_("Show Hidden"),
+ P_("Whether the hidden files and folders should
be displayed"),
+ FALSE,
+ GTK_PARAM_READWRITE));
/**
* GtkFileChooser:do-overwrite-confirmation:
@@ -433,13 +413,13 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* selects a file name that already exists.
*/
g_object_interface_install_property (iface,
- g_param_spec_boolean ("do-overwrite-confirmation",
- P_("Do overwrite confirmation"),
- P_("Whether a file chooser in save mode "
- "will present an overwrite confirmation
dialog "
- "if necessary."),
- FALSE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("do-overwrite-confirmation",
+ P_("Do overwrite confirmation"),
+ P_("Whether a file chooser in save mode "
+ "will present an overwrite confirmation
dialog "
+ "if necessary."),
+ FALSE,
+ GTK_PARAM_READWRITE));
/**
* GtkFileChooser:create-folders:
@@ -448,12 +428,12 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
* will offer the user to create new folders.
*/
g_object_interface_install_property (iface,
- g_param_spec_boolean ("create-folders",
- P_("Allow folder creation"),
- P_("Whether a file chooser not in open mode "
- "will offer the user to create new folders."),
- TRUE,
- GTK_PARAM_READWRITE));
+ g_param_spec_boolean ("create-folders",
+ P_("Allow folder creation"),
+ P_("Whether a file chooser not in open mode "
+ "will offer the user to create new
folders."),
+ TRUE,
+ GTK_PARAM_READWRITE));
}
/**
@@ -482,7 +462,7 @@ gtk_file_chooser_error_quark (void)
**/
void
gtk_file_chooser_set_action (GtkFileChooser *chooser,
- GtkFileChooserAction action)
+ GtkFileChooserAction action)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -521,9 +501,7 @@ gtk_file_chooser_get_action (GtkFileChooser *chooser)
* accessible through the operating system’s native file
* system and therefore the application only
* needs to worry about the filename functions in
- * #GtkFileChooser, like gtk_file_chooser_get_filename(),
- * rather than the URI functions like
- * gtk_file_chooser_get_uri(),
+ * #GtkFileChooser, like gtk_file_chooser_get_file().
*
* On some systems non-native files may still be
* available using the native filesystem via a userspace
@@ -531,7 +509,7 @@ gtk_file_chooser_get_action (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_local_only (GtkFileChooser *chooser,
- gboolean local_only)
+ gboolean local_only)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -570,7 +548,7 @@ gtk_file_chooser_get_local_only (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
- gboolean select_multiple)
+ gboolean select_multiple)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -609,7 +587,7 @@ gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
- gboolean create_folders)
+ gboolean create_folders)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -637,285 +615,6 @@ gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
return create_folders;
}
-/**
- * gtk_file_chooser_get_filename:
- * @chooser: a #GtkFileChooser
- *
- * Gets the filename for the currently selected file in
- * the file selector. The filename is returned as an absolute path. If
- * multiple files are selected, one of the filenames will be returned at
- * random.
- *
- * If the file chooser is in folder mode, this function returns the selected
- * folder.
- *
- * Returns: (nullable) (type filename): The currently selected filename,
- * or %NULL if no file is selected, or the selected file can't
- * be represented with a local filename. Free with g_free().
- **/
-gchar *
-gtk_file_chooser_get_filename (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *result = NULL;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_file (chooser);
-
- if (file)
- {
- result = g_file_get_path (file);
- g_object_unref (file);
- }
-
- return result;
-}
-
-/**
- * gtk_file_chooser_set_filename:
- * @chooser: a #GtkFileChooser
- * @filename: (type filename): the filename to set as current
- *
- * Sets @filename as the current filename for the file chooser, by changing to
- * the file’s parent folder and actually selecting the file in list; all other
- * files will be unselected. If the @chooser is in
- * %GTK_FILE_CHOOSER_ACTION_SAVE mode, the file’s base name will also appear in
- * the dialog’s file name entry.
- *
- * Note that the file must exist, or nothing will be done except
- * for the directory change.
- *
- * You should use this function only when implementing a save
- * dialog for which you already have a file name to which
- * the user may save. For example, when the user opens an existing file and
- * then does Save As... to save a copy or
- * a modified version. If you don’t have a file name already — for
- * example, if the user just created a new file and is saving it for the first
- * time, do not call this function. Instead, use something similar to this:
- * |[<!-- language="C" -->
- * if (document_is_new)
- * {
- * // the user just created a new document
- * gtk_file_chooser_set_current_name (chooser, "Untitled document");
- * }
- * else
- * {
- * // the user edited an existing document
- * gtk_file_chooser_set_filename (chooser, existing_filename);
- * }
- * ]|
- *
- * In the first case, the file chooser will present the user with useful suggestions
- * as to where to save his new file. In the second case, the file’s existing location
- * is already known, so the file chooser will use it.
- *
- * Returns: Not useful.
- **/
-gboolean
-gtk_file_chooser_set_filename (GtkFileChooser *chooser,
- const gchar *filename)
-{
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
-
- gtk_file_chooser_unselect_all (chooser);
- return gtk_file_chooser_select_filename (chooser, filename);
-}
-
-/**
- * gtk_file_chooser_select_filename:
- * @chooser: a #GtkFileChooser
- * @filename: (type filename): the filename to select
- *
- * Selects a filename. If the file name isn’t in the current
- * folder of @chooser, then the current folder of @chooser will
- * be changed to the folder containing @filename.
- *
- * Returns: Not useful.
- *
- * See also: gtk_file_chooser_set_filename()
- **/
-gboolean
-gtk_file_chooser_select_filename (GtkFileChooser *chooser,
- const gchar *filename)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
-
- file = g_file_new_for_path (filename);
- result = gtk_file_chooser_select_file (chooser, file, NULL);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_unselect_filename:
- * @chooser: a #GtkFileChooser
- * @filename: (type filename): the filename to unselect
- *
- * Unselects a currently selected filename. If the filename
- * is not in the current directory, does not exist, or
- * is otherwise not currently selected, does nothing.
- **/
-void
-gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
- const char *filename)
-{
- GFile *file;
-
- g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
- g_return_if_fail (filename != NULL);
-
- file = g_file_new_for_path (filename);
- gtk_file_chooser_unselect_file (chooser, file);
- g_object_unref (file);
-}
-
-/* Converts a list of GFile* to a list of strings using the specified function */
-static GSList *
-files_to_strings (GSList *files,
- gchar * (*convert_func) (GFile *file))
-{
- GSList *strings;
-
- strings = NULL;
-
- for (; files; files = files->next)
- {
- GFile *file;
- gchar *string;
-
- file = files->data;
- string = (* convert_func) (file);
-
- if (string)
- strings = g_slist_prepend (strings, string);
- }
-
- return g_slist_reverse (strings);
-}
-
-static gchar *
-file_to_uri_with_native_path (GFile *file)
-{
- gchar *result = NULL;
- gchar *native;
-
- native = g_file_get_path (file);
- if (native)
- {
- result = g_filename_to_uri (native, NULL, NULL); /* NULL-GError */
- g_free (native);
- }
-
- return result;
-}
-
-/**
- * gtk_file_chooser_get_filenames:
- * @chooser: a #GtkFileChooser
- *
- * Lists all the selected files and subfolders in the current folder of
- * @chooser. The returned names are full absolute paths. If files in the current
- * folder cannot be represented as local filenames they will be ignored. (See
- * gtk_file_chooser_get_uris())
- *
- * Returns: (element-type filename) (transfer full): a #GSList
- * containing the filenames of all selected files and subfolders in
- * the current folder. Free the returned list with g_slist_free(),
- * and the filenames with g_free().
- **/
-GSList *
-gtk_file_chooser_get_filenames (GtkFileChooser *chooser)
-{
- GSList *files, *result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- files = gtk_file_chooser_get_files (chooser);
-
- result = files_to_strings (files, g_file_get_path);
- g_slist_free_full (files, g_object_unref);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_set_current_folder:
- * @chooser: a #GtkFileChooser
- * @filename: (type filename): the full path of the new current folder
- *
- * Sets the current folder for @chooser from a local filename.
- * The user will be shown the full contents of the current folder,
- * plus user interface elements for navigating to other folders.
- *
- * In general, you should not use this function. See the
- * [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up]
- * for the rationale behind this.
- *
- * Returns: Not useful.
- **/
-gboolean
-gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
- const gchar *filename)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
-
- file = g_file_new_for_path (filename);
- result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_get_current_folder:
- * @chooser: a #GtkFileChooser
- *
- * Gets the current folder of @chooser as a local filename.
- * See gtk_file_chooser_set_current_folder().
- *
- * Note that this is the folder that the file chooser is currently displaying
- * (e.g. "/home/username/Documents"), which is not the same
- * as the currently-selected folder if the chooser is in
- * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode
- * (e.g. "/home/username/Documents/selected-folder/". To get the
- * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
- * usual way to get the selection.
- *
- * Returns: (nullable) (type filename): the full path of the current
- * folder, or %NULL if the current path cannot be represented as a local
- * filename. Free with g_free(). This function will also return
- * %NULL if the file chooser was unable to load the last folder that
- * was requested from it; for example, as would be for calling
- * gtk_file_chooser_set_current_folder() on a nonexistent folder.
- **/
-gchar *
-gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *filename;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_current_folder_file (chooser);
- if (!file)
- return NULL;
-
- filename = g_file_get_path (file);
- g_object_unref (file);
-
- return filename;
-}
-
/**
* gtk_file_chooser_set_current_name:
* @chooser: a #GtkFileChooser
@@ -928,13 +627,14 @@ gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
* pass “Untitled.doc” or a similarly suitable suggestion for the @name.
*
* If you want to preselect a particular existing file, you should use
- * gtk_file_chooser_set_filename() or gtk_file_chooser_set_uri() instead.
+ * gtk_file_chooser_set_file() instead.
+ *
* Please see the documentation for those functions for an example of using
* gtk_file_chooser_set_current_name() as well.
**/
void
gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
- const gchar *name)
+ const gchar *name)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (name != NULL);
@@ -968,145 +668,6 @@ gtk_file_chooser_get_current_name (GtkFileChooser *chooser)
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_name (chooser);
}
-/**
- * gtk_file_chooser_get_uri:
- * @chooser: a #GtkFileChooser
- *
- * Gets the URI for the currently selected file in
- * the file selector. If multiple files are selected,
- * one of the filenames will be returned at random.
- *
- * If the file chooser is in folder mode, this function returns the selected
- * folder.
- *
- * Returns: (nullable) (transfer full): The currently selected URI, or %NULL
- * if no file is selected. If gtk_file_chooser_set_local_only() is set to
- * %TRUE (the default) a local URI will be returned for any FUSE locations.
- * Free with g_free()
- **/
-gchar *
-gtk_file_chooser_get_uri (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *result = NULL;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_file (chooser);
- if (file)
- {
- if (gtk_file_chooser_get_local_only (chooser))
- result = file_to_uri_with_native_path (file);
- else
- result = g_file_get_uri (file);
-
- g_object_unref (file);
- }
-
- return result;
-}
-
-/**
- * gtk_file_chooser_set_uri:
- * @chooser: a #GtkFileChooser
- * @uri: the URI to set as current
- *
- * Sets the file referred to by @uri as the current file for the file chooser,
- * by changing to the URI’s parent folder and actually selecting the URI in the
- * list. If the @chooser is %GTK_FILE_CHOOSER_ACTION_SAVE mode, the URI’s base
- * name will also appear in the dialog’s file name entry.
- *
- * Note that the URI must exist, or nothing will be done except for the
- * directory change.
- *
- * You should use this function only when implementing a save
- * dialog for which you already have a file name to which
- * the user may save. For example, when the user opens an existing file and then
- * does Save As... to save a copy or a
- * modified version. If you don’t have a file name already — for example,
- * if the user just created a new file and is saving it for the first time, do
- * not call this function. Instead, use something similar to this:
- * |[<!-- language="C" -->
- * if (document_is_new)
- * {
- * // the user just created a new document
- * gtk_file_chooser_set_current_name (chooser, "Untitled document");
- * }
- * else
- * {
- * // the user edited an existing document
- * gtk_file_chooser_set_uri (chooser, existing_uri);
- * }
- * ]|
- *
- *
- * In the first case, the file chooser will present the user with useful suggestions
- * as to where to save his new file. In the second case, the file’s existing location
- * is already known, so the file chooser will use it.
- *
- * Returns: Not useful.
- **/
-gboolean
-gtk_file_chooser_set_uri (GtkFileChooser *chooser,
- const char *uri)
-{
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
-
- gtk_file_chooser_unselect_all (chooser);
- return gtk_file_chooser_select_uri (chooser, uri);
-}
-
-/**
- * gtk_file_chooser_select_uri:
- * @chooser: a #GtkFileChooser
- * @uri: the URI to select
- *
- * Selects the file to by @uri. If the URI doesn’t refer to a
- * file in the current folder of @chooser, then the current folder of
- * @chooser will be changed to the folder containing @filename.
- *
- * Returns: Not useful.
- **/
-gboolean
-gtk_file_chooser_select_uri (GtkFileChooser *chooser,
- const char *uri)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
-
- file = g_file_new_for_uri (uri);
- result = gtk_file_chooser_select_file (chooser, file, NULL);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_unselect_uri:
- * @chooser: a #GtkFileChooser
- * @uri: the URI to unselect
- *
- * Unselects the file referred to by @uri. If the file
- * is not in the current directory, does not exist, or
- * is otherwise not currently selected, does nothing.
- **/
-void
-gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
- const char *uri)
-{
- GFile *file;
-
- g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
- g_return_if_fail (uri != NULL);
-
- file = g_file_new_for_uri (uri);
- gtk_file_chooser_unselect_file (chooser, file);
- g_object_unref (file);
-}
-
/**
* gtk_file_chooser_select_all:
* @chooser: a #GtkFileChooser
@@ -1137,123 +698,20 @@ gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
}
/**
- * gtk_file_chooser_get_uris:
- * @chooser: a #GtkFileChooser
- *
- * Lists all the selected files and subfolders in the current folder of
- * @chooser. The returned names are full absolute URIs.
- *
- * Returns: (element-type utf8) (transfer full): a #GSList containing the URIs of all selected
- * files and subfolders in the current folder. Free the returned list
- * with g_slist_free(), and the filenames with g_free().
- **/
-GSList *
-gtk_file_chooser_get_uris (GtkFileChooser *chooser)
-{
- GSList *files, *result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- files = gtk_file_chooser_get_files (chooser);
-
- if (gtk_file_chooser_get_local_only (chooser))
- result = files_to_strings (files, file_to_uri_with_native_path);
- else
- result = files_to_strings (files, g_file_get_uri);
-
- g_slist_free_full (files, g_object_unref);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_set_current_folder_uri:
- * @chooser: a #GtkFileChooser
- * @uri: the URI for the new current folder
- *
- * Sets the current folder for @chooser from an URI.
- * The user will be shown the full contents of the current folder,
- * plus user interface elements for navigating to other folders.
- *
- * In general, you should not use this function. See the
- * [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up]
- * for the rationale behind this.
- *
- * Returns: %TRUE if the folder could be changed successfully, %FALSE
- * otherwise.
- **/
-gboolean
-gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
- const gchar *uri)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
-
- file = g_file_new_for_uri (uri);
- result = gtk_file_chooser_set_current_folder_file (chooser, file, NULL);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_get_current_folder_uri:
- * @chooser: a #GtkFileChooser
- *
- * Gets the current folder of @chooser as an URI.
- * See gtk_file_chooser_set_current_folder_uri().
- *
- * Note that this is the folder that the file chooser is currently displaying
- * (e.g. "file:///home/username/Documents"), which is not the same
- * as the currently-selected folder if the chooser is in
- * %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode
- * (e.g. "file:///home/username/Documents/selected-folder/". To get the
- * currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the
- * usual way to get the selection.
- *
- * Returns: (nullable) (transfer full): the URI for the current folder.
- * Free with g_free(). This function will also return %NULL if the file chooser
- * was unable to load the last folder that was requested from it; for example,
- * as would be for calling gtk_file_chooser_set_current_folder_uri() on a
- * nonexistent folder.
- */
-gchar *
-gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *uri;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_current_folder_file (chooser);
- if (!file)
- return NULL;
-
- uri = g_file_get_uri (file);
- g_object_unref (file);
-
- return uri;
-}
-
-/**
- * gtk_file_chooser_set_current_folder_file:
+ * gtk_file_chooser_set_current_folder:
* @chooser: a #GtkFileChooser
* @file: the #GFile for the new folder
- * @error: (allow-none): location to store error, or %NULL.
+ * @error: location to store error, or %NULL.
*
* Sets the current folder for @chooser from a #GFile.
- * Internal function, see gtk_file_chooser_set_current_folder_uri().
*
* Returns: %TRUE if the folder could be changed successfully, %FALSE
* otherwise.
**/
gboolean
-gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
- GFile *file,
- GError **error)
+gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
+ GFile *file,
+ GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
@@ -1263,16 +721,15 @@ gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
}
/**
- * gtk_file_chooser_get_current_folder_file:
+ * gtk_file_chooser_get_current_folder:
* @chooser: a #GtkFileChooser
*
* Gets the current folder of @chooser as #GFile.
- * See gtk_file_chooser_get_current_folder_uri().
*
* Returns: (transfer full): the #GFile for the current folder.
*/
GFile *
-gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
+gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
@@ -1285,8 +742,7 @@ gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser)
* @file: the file to select
* @error: (allow-none): location to store error, or %NULL
*
- * Selects the file referred to by @file. An internal function. See
- * _gtk_file_chooser_select_uri().
+ * Selects the file referred to by @file.
*
* Returns: Not useful.
**/
@@ -1325,9 +781,9 @@ gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
* @chooser: a #GtkFileChooser
*
* Lists all the selected files and subfolders in the current folder of @chooser
- * as #GFile. An internal function, see gtk_file_chooser_get_uris().
+ * as #GFile.
*
- * Returns: (element-type GFile) (transfer full): a #GSList
+ * Returns: (element-type GFile) (transfer full): a list
* containing a #GFile for each selected file and subfolder in the
* current folder. Free the returned list with g_slist_free(), and
* the files with g_object_unref().
@@ -1370,7 +826,7 @@ gtk_file_chooser_get_files (GtkFileChooser *chooser)
* if (document_is_new)
* {
* // the user just created a new document
- * gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
+ * gtk_file_chooser_set_current_folder (chooser, default_file_for_saving);
* gtk_file_chooser_set_current_name (chooser, "Untitled document");
* }
* else
@@ -1429,7 +885,7 @@ gtk_file_chooser_get_file (GtkFileChooser *chooser)
return result;
}
-/**
+/*< private >
* _gtk_file_chooser_get_file_system:
* @chooser: a #GtkFileChooser
*
@@ -1457,9 +913,9 @@ _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
* Sets an application-supplied widget to use to display a custom preview
* of the currently selected file. To implement a preview, after setting the
* preview widget, you connect to the #GtkFileChooser::update-preview
- * signal, and call gtk_file_chooser_get_preview_filename() or
- * gtk_file_chooser_get_preview_uri() on each change. If you can
- * display a preview of the new file, update your widget and
+ * signal, and call gtk_file_chooser_get_preview_file().
+ *
+ * If you can display a preview of the new file, update your widget and
* set the preview active using gtk_file_chooser_set_preview_widget_active().
* Otherwise, set the preview inactive.
*
@@ -1469,7 +925,7 @@ _gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser,
- GtkWidget *preview_widget)
+ GtkWidget *preview_widget)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1518,7 +974,7 @@ gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser,
- gboolean active)
+ gboolean active)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1561,7 +1017,7 @@ gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
- gboolean use_label)
+ gboolean use_label)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1595,10 +1051,9 @@ gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser)
* @chooser: a #GtkFileChooser
*
* Gets the #GFile that should be previewed in a custom preview
- * Internal function, see gtk_file_chooser_get_preview_uri().
*
* Returns: (nullable) (transfer full): the #GFile for the file to preview,
- * or %NULL if no file is selected. Free with g_object_unref().
+ * or %NULL if no file is selected. Free with g_object_unref().
**/
GFile *
gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
@@ -1609,106 +1064,47 @@ gtk_file_chooser_get_preview_file (GtkFileChooser *chooser)
}
/**
- * _gtk_file_chooser_add_shortcut_folder:
+ * gtk_file_chooser_add_shortcut_folder:
* @chooser: a #GtkFileChooser
- * @file: file for the folder to add
- * @error: (allow-none): location to store error, or %NULL
+ * @folder: a #GFile for the folder to add
+ * @error: location to store error, or %NULL
*
* Adds a folder to be displayed with the shortcut folders in a file chooser.
- * Internal function, see gtk_file_chooser_add_shortcut_folder().
*
* Returns: %TRUE if the folder could be added successfully, %FALSE
* otherwise.
**/
gboolean
-_gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
- GFile *file,
- GError **error)
+gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
+ GFile *folder,
+ GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ g_return_val_if_fail (G_IS_FILE (folder), FALSE);
- return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
+ return GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, folder, error);
}
/**
- * _gtk_file_chooser_remove_shortcut_folder:
+ * gtk_file_chooser_remove_shortcut_folder:
* @chooser: a #GtkFileChooser
- * @file: file for the folder to remove
- * @error: (allow-none): location to store error, or %NULL
+ * @folder: a #GFile for the folder to remove
+ * @error: location to store error, or %NULL
*
- * Removes a folder from the shortcut folders in a file chooser. Internal
- * function, see gtk_file_chooser_remove_shortcut_folder().
+ * Removes a folder from the shortcut folders in a file chooser.
*
* Returns: %TRUE if the folder could be removed successfully, %FALSE
* otherwise.
**/
gboolean
-_gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
- GFile *file,
- GError **error)
+gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
+ GFile *folder,
+ GError **error)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ g_return_val_if_fail (G_IS_FILE (folder), FALSE);
- return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
-}
-
-/**
- * gtk_file_chooser_get_preview_filename:
- * @chooser: a #GtkFileChooser
- *
- * Gets the filename that should be previewed in a custom preview
- * widget. See gtk_file_chooser_set_preview_widget().
- *
- * Returns: (nullable) (type filename): the filename to preview, or %NULL if
- * no file is selected, or if the selected file cannot be represented
- * as a local filename. Free with g_free()
- **/
-char *
-gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *result = NULL;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_preview_file (chooser);
- if (file)
- {
- result = g_file_get_path (file);
- g_object_unref (file);
- }
-
- return result;
-}
-
-/**
- * gtk_file_chooser_get_preview_uri:
- * @chooser: a #GtkFileChooser
- *
- * Gets the URI that should be previewed in a custom preview
- * widget. See gtk_file_chooser_set_preview_widget().
- *
- * Returns: (nullable) (transfer full): the URI for the file to preview,
- * or %NULL if no file is selected. Free with g_free().
- **/
-char *
-gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
-{
- GFile *file;
- gchar *result = NULL;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- file = gtk_file_chooser_get_preview_file (chooser);
- if (file)
- {
- result = g_file_get_uri (file);
- g_object_unref (file);
- }
-
- return result;
+ return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, folder, error);
}
/**
@@ -1720,7 +1116,7 @@ gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
- GtkWidget *extra_widget)
+ GtkWidget *extra_widget)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1769,7 +1165,7 @@ gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_add_filter (GtkFileChooser *chooser,
- GtkFileFilter *filter)
+ GtkFileFilter *filter)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1785,7 +1181,7 @@ gtk_file_chooser_add_filter (GtkFileChooser *chooser,
**/
void
gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
- GtkFileFilter *filter)
+ GtkFileFilter *filter)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -1826,7 +1222,7 @@ gtk_file_chooser_list_filters (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_filter (GtkFileChooser *chooser,
- GtkFileFilter *filter)
+ GtkFileFilter *filter)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_return_if_fail (GTK_IS_FILE_FILTER (filter));
@@ -1860,69 +1256,6 @@ gtk_file_chooser_get_filter (GtkFileChooser *chooser)
return filter;
}
-/**
- * gtk_file_chooser_add_shortcut_folder:
- * @chooser: a #GtkFileChooser
- * @folder: (type filename): filename of the folder to add
- * @error: (allow-none): location to store error, or %NULL
- *
- * Adds a folder to be displayed with the shortcut folders in a file chooser.
- * Note that shortcut folders do not get saved, as they are provided by the
- * application. For example, you can use this to add a
- * “/usr/share/mydrawprogram/Clipart” folder to the volume list.
- *
- * Returns: %TRUE if the folder could be added successfully, %FALSE
- * otherwise. In the latter case, the @error will be set as appropriate.
- **/
-gboolean
-gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
- const char *folder,
- GError **error)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (folder != NULL, FALSE);
-
- file = g_file_new_for_path (folder);
- result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_remove_shortcut_folder:
- * @chooser: a #GtkFileChooser
- * @folder: (type filename): filename of the folder to remove
- * @error: (allow-none): location to store error, or %NULL
- *
- * Removes a folder from a file chooser’s list of shortcut folders.
- *
- * Returns: %TRUE if the operation succeeds, %FALSE otherwise.
- * In the latter case, the @error will be set as appropriate.
- *
- * See also: gtk_file_chooser_add_shortcut_folder()
- **/
-gboolean
-gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
- const char *folder,
- GError **error)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (folder != NULL, FALSE);
-
- file = g_file_new_for_path (folder);
- result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
- g_object_unref (file);
-
- return result;
-}
-
/**
* gtk_file_chooser_list_shortcut_folders:
* @chooser: a #GtkFileChooser
@@ -1930,119 +1263,11 @@ gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
* Queries the list of shortcut folders in the file chooser, as set by
* gtk_file_chooser_add_shortcut_folder().
*
- * Returns: (nullable) (element-type filename) (transfer full): A list
+ * Returns: (nullable) (element-type Gio.File) (transfer full): A list
* of folder filenames, or %NULL if there are no shortcut folders.
- * Free the returned list with g_slist_free(), and the filenames with
- * g_free().
- **/
+ */
GSList *
gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
-{
- GSList *folders;
- GSList *result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
-
- result = files_to_strings (folders, g_file_get_path);
- g_slist_free_full (folders, g_object_unref);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_add_shortcut_folder_uri:
- * @chooser: a #GtkFileChooser
- * @uri: URI of the folder to add
- * @error: (allow-none): location to store error, or %NULL
- *
- * Adds a folder URI to be displayed with the shortcut folders in a file
- * chooser. Note that shortcut folders do not get saved, as they are provided
- * by the application. For example, you can use this to add a
- * “file:///usr/share/mydrawprogram/Clipart” folder to the volume list.
- *
- * Returns: %TRUE if the folder could be added successfully, %FALSE
- * otherwise. In the latter case, the @error will be set as appropriate.
- **/
-gboolean
-gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
- const char *uri,
- GError **error)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
-
- file = g_file_new_for_uri (uri);
- result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->add_shortcut_folder (chooser, file, error);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_remove_shortcut_folder_uri:
- * @chooser: a #GtkFileChooser
- * @uri: URI of the folder to remove
- * @error: (allow-none): location to store error, or %NULL
- *
- * Removes a folder URI from a file chooser’s list of shortcut folders.
- *
- * Returns: %TRUE if the operation succeeds, %FALSE otherwise.
- * In the latter case, the @error will be set as appropriate.
- *
- * See also: gtk_file_chooser_add_shortcut_folder_uri()
- **/
-gboolean
-gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
- const char *uri,
- GError **error)
-{
- GFile *file;
- gboolean result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
- g_return_val_if_fail (uri != NULL, FALSE);
-
- file = g_file_new_for_uri (uri);
- result = GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, file, error);
- g_object_unref (file);
-
- return result;
-}
-
-/**
- * gtk_file_chooser_list_shortcut_folder_uris:
- * @chooser: a #GtkFileChooser
- *
- * Queries the list of shortcut folders in the file chooser, as set by
- * gtk_file_chooser_add_shortcut_folder_uri().
- *
- * Returns: (nullable) (element-type utf8) (transfer full): A list of
- * folder URIs, or %NULL if there are no shortcut folders. Free the
- * returned list with g_slist_free(), and the URIs with g_free().
- **/
-GSList *
-gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser)
-{
- GSList *folders;
- GSList *result;
-
- g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
-
- folders = _gtk_file_chooser_list_shortcut_folder_files (chooser);
-
- result = files_to_strings (folders, g_file_get_uri);
- g_slist_free_full (folders, g_object_unref);
-
- return result;
-}
-
-GSList *
-_gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
@@ -2058,7 +1283,7 @@ _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_show_hidden (GtkFileChooser *chooser,
- gboolean show_hidden)
+ gboolean show_hidden)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
@@ -2105,7 +1330,7 @@ gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
**/
void
gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
- gboolean do_overwrite_confirmation)
+ gboolean do_overwrite_confirmation)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h
index 9c13dd4032..98cb71545a 100644
--- a/gtk/gtkfilechooser.h
+++ b/gtk/gtkfilechooser.h
@@ -156,52 +156,10 @@ void gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
GDK_AVAILABLE_IN_ALL
gchar *gtk_file_chooser_get_current_name (GtkFileChooser *chooser);
-/* Filename manipulation
- */
-GDK_AVAILABLE_IN_ALL
-gchar * gtk_file_chooser_get_filename (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_set_filename (GtkFileChooser *chooser,
- const char *filename);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser,
- const char *filename);
-GDK_AVAILABLE_IN_ALL
-void gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
- const char *filename);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_select_all (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_unselect_all (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-GSList * gtk_file_chooser_get_filenames (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
- const gchar *filename);
-GDK_AVAILABLE_IN_ALL
-gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
-
-
-/* URI manipulation
- */
-GDK_AVAILABLE_IN_ALL
-gchar * gtk_file_chooser_get_uri (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser,
- const char *uri);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_select_uri (GtkFileChooser *chooser,
- const char *uri);
-GDK_AVAILABLE_IN_ALL
-void gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
- const char *uri);
-GDK_AVAILABLE_IN_ALL
-GSList * gtk_file_chooser_get_uris (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
- const gchar *uri);
-GDK_AVAILABLE_IN_ALL
-gchar * gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser);
/* GFile manipulation */
GDK_AVAILABLE_IN_ALL
@@ -220,11 +178,11 @@ void gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
GDK_AVAILABLE_IN_ALL
GSList * gtk_file_chooser_get_files (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
+gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
GFile *file,
GError **error);
GDK_AVAILABLE_IN_ALL
-GFile * gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser);
+GFile * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
/* Preview widget
*/
@@ -244,10 +202,6 @@ void gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-char *gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-char *gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
GFile *gtk_file_chooser_get_preview_file (GtkFileChooser *chooser);
@@ -274,7 +228,7 @@ GSList *gtk_file_chooser_list_filters (GtkFileChooser *chooser);
*/
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_set_filter (GtkFileChooser *chooser,
- GtkFileFilter *filter);
+ GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
@@ -282,26 +236,15 @@ GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
- const char *folder,
+ GFile *folder,
GError **error);
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
- const char *folder,
+ GFile *folder,
GError **error);
GDK_AVAILABLE_IN_ALL
GSList *gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
- const char *uri,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
- const char *uri,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-GSList *gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser);
-
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
const char *id,
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index ff6dd9bbf3..c14d01ead9 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -80,11 +80,12 @@
* |[<!-- language="C" -->
* {
* GtkWidget *button;
+ * GFile *cwd = g_file_new_for_path ("/etc");
*
* button = gtk_file_chooser_button_new (_("Select a file"),
* GTK_FILE_CHOOSER_ACTION_OPEN);
- * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button),
- * "/etc");
+ * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd);
+ * g_object_unref (cwd);
* }
* ]|
*
@@ -556,7 +557,7 @@ gtk_file_chooser_button_set_current_folder (GtkFileChooser *chooser,
g_signal_emit_by_name (button, "current-folder-changed");
if (priv->active)
- gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->chooser), file, NULL);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->chooser), file, NULL);
return TRUE;
}
@@ -688,7 +689,7 @@ gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
delegate = g_object_get_qdata (G_OBJECT (chooser),
GTK_FILE_CHOOSER_DELEGATE_QUARK);
- retval = _gtk_file_chooser_add_shortcut_folder (delegate, file, error);
+ retval = gtk_file_chooser_add_shortcut_folder (delegate, file, error);
if (retval)
{
@@ -728,7 +729,7 @@ gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
delegate = g_object_get_qdata (G_OBJECT (chooser),
GTK_FILE_CHOOSER_DELEGATE_QUARK);
- retval = _gtk_file_chooser_remove_shortcut_folder (delegate, file, error);
+ retval = gtk_file_chooser_remove_shortcut_folder (delegate, file, error);
if (retval)
{
@@ -2550,7 +2551,7 @@ save_inactive_state (GtkFileChooserButton *button)
if (priv->selection_while_inactive)
g_object_unref (priv->selection_while_inactive);
- priv->current_folder_while_inactive = gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER
(priv->chooser));
+ priv->current_folder_while_inactive = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER
(priv->chooser));
priv->selection_while_inactive = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->chooser));
}
@@ -2560,7 +2561,7 @@ restore_inactive_state (GtkFileChooserButton *button)
GtkFileChooserButtonPrivate *priv = gtk_file_chooser_button_get_instance_private (button);
if (priv->current_folder_while_inactive)
- gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->chooser),
priv->current_folder_while_inactive, NULL);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->chooser),
priv->current_folder_while_inactive, NULL);
if (priv->selection_while_inactive)
gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->chooser), priv->selection_while_inactive, NULL);
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 56d89fbb5a..729ae82668 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -85,11 +85,9 @@
* res = gtk_dialog_run (GTK_DIALOG (dialog));
* if (res == GTK_RESPONSE_ACCEPT)
* {
- * char *filename;
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
- * filename = gtk_file_chooser_get_filename (chooser);
- * open_file (filename);
- * g_free (filename);
+ * g_autoptr(GFile) filen = gtk_file_chooser_get_file (chooser);
+ * open_file (file);
* }
*
* gtk_widget_destroy (dialog);
@@ -116,20 +114,15 @@
* gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
*
* if (user_edited_a_new_document)
- * gtk_file_chooser_set_current_name (chooser,
- * _("Untitled document"));
+ * gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
* else
- * gtk_file_chooser_set_filename (chooser,
- * existing_filename);
+ * gtk_file_chooser_set_file (chooser, existing_filename);
*
* res = gtk_dialog_run (GTK_DIALOG (dialog));
* if (res == GTK_RESPONSE_ACCEPT)
* {
- * char *filename;
- *
- * filename = gtk_file_chooser_get_filename (chooser);
- * save_to_file (filename);
- * g_free (filename);
+ * g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);
+ * save_to_file (file);
* }
*
* gtk_widget_destroy (dialog);
@@ -145,7 +138,7 @@
* and suggest a name such as “Untitled” with gtk_file_chooser_set_current_name().
*
* - To save a file under a different name. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
- * and set the existing filename with gtk_file_chooser_set_filename().
+ * and set the existing file with gtk_file_chooser_set_file().
*
* - To choose a folder instead of a file. Use #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
*
@@ -156,7 +149,7 @@
* considered to be a good policy, as now the file chooser is
* able to make good suggestions on its own. In general, you
* should only cause the file chooser to show a specific folder
- * when it is appropriate to use gtk_file_chooser_set_filename(),
+ * when it is appropriate to use gtk_file_chooser_set_file(),
* i.e. when you are doing a Save As command and you already
* have a file saved somewhere.
@@ -362,18 +355,18 @@ file_chooser_widget_selection_changed (GtkWidget *widget,
{
GtkFileChooserDialogPrivate *priv = gtk_file_chooser_dialog_get_instance_private (dialog);
GtkWidget *button;
- GSList *uris;
+ GSList *files;
gboolean sensitive;
button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
if (button == NULL)
return;
- uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (priv->widget));
- sensitive = (uris != NULL);
+ files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->widget));
+ sensitive = (files != NULL);
gtk_widget_set_sensitive (button, sensitive);
- g_slist_free_full (uris, g_free);
+ g_slist_free_full (files, g_object_unref);
}
static void
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index ffd0ae83d0..a722587efb 100644
--- a/gtk/gtkfilechoosernative.c
+++ b/gtk/gtkfilechoosernative.c
@@ -644,8 +644,8 @@ gtk_file_chooser_native_set_current_folder (GtkFileChooser *chooser,
GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
gboolean res;
- res = gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (self->dialog),
- file, error);
+ res = gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->dialog),
+ file, error);
if (res)
diff --git a/gtk/gtkfilechoosernativewin32.c b/gtk/gtkfilechoosernativewin32.c
index 3bb81be29c..e1534a5696 100644
--- a/gtk/gtkfilechoosernativewin32.c
+++ b/gtk/gtkfilechoosernativewin32.c
@@ -69,7 +69,7 @@ typedef struct {
char *cancel_label;
char *title;
- GSList *shortcut_uris;
+ GSList *shortcut_files;
GArray *choices_selections;
GFile *current_folder;
@@ -331,7 +331,7 @@ filechooser_win32_thread_data_free (FilechooserWin32ThreadData *data)
g_array_free (data->choices_selections, TRUE);
data->choices_selections = NULL;
}
- g_slist_free_full (data->shortcut_uris, g_free);
+ g_slist_free_full (data->shortcut_files, g_object_unref);
g_slist_free_full (data->files, g_object_unref);
if (data->self)
g_object_unref (data->self);
@@ -538,9 +538,9 @@ filechooser_win32_thread (gpointer _data)
g_free (label);
}
- for (l = data->shortcut_uris; l != NULL; l = l->next)
+ for (l = data->shortcut_files; l != NULL; l = l->next)
{
- IShellItem *item = get_shell_item_for_uri (l->data);
+ IShellItem *item = get_shell_item_for_file (l->data);
if (item)
{
hr = IFileDialog_AddPlace (pfd, item, FDAP_BOTTOM);
@@ -911,8 +911,8 @@ gtk_file_chooser_native_win32_show (GtkFileChooserNative *self)
self->mode_data = data;
data->self = g_object_ref (self);
- data->shortcut_uris =
- gtk_file_chooser_list_shortcut_folder_uris (GTK_FILE_CHOOSER (self->dialog));
+ data->shortcut_files =
+ gtk_file_chooser_list_shortcut_folders (GTK_FILE_CHOOSER (self->dialog));
data->accept_label = translate_mnemonics (self->accept_label);
data->cancel_label = translate_mnemonics (self->cancel_label);
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index fab92fc243..a19b1f6495 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -112,14 +112,6 @@ struct _GtkFileChooserIface
};
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
-gboolean _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
- GFile *folder,
- GError **error);
-gboolean _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
- GFile *folder,
- GError **error);
-GSList * _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser);
-
G_END_DECLS
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index c022306dca..fe71729933 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -289,7 +289,7 @@ delegate_add_shortcut_folder (GtkFileChooser *chooser,
GFile *file,
GError **error)
{
- return _gtk_file_chooser_add_shortcut_folder (get_delegate (chooser), file, error);
+ return gtk_file_chooser_add_shortcut_folder (get_delegate (chooser), file, error);
}
static gboolean
@@ -297,13 +297,13 @@ delegate_remove_shortcut_folder (GtkFileChooser *chooser,
GFile *file,
GError **error)
{
- return _gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
+ return gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
}
static GSList *
delegate_list_shortcut_folders (GtkFileChooser *chooser)
{
- return _gtk_file_chooser_list_shortcut_folder_files (get_delegate (chooser));
+ return gtk_file_chooser_list_shortcut_folders (get_delegate (chooser));
}
static gboolean
@@ -311,13 +311,13 @@ delegate_set_current_folder (GtkFileChooser *chooser,
GFile *file,
GError **error)
{
- return gtk_file_chooser_set_current_folder_file (get_delegate (chooser), file, error);
+ return gtk_file_chooser_set_current_folder (get_delegate (chooser), file, error);
}
static GFile *
delegate_get_current_folder (GtkFileChooser *chooser)
{
- return gtk_file_chooser_get_current_folder_file (get_delegate (chooser));
+ return gtk_file_chooser_get_current_folder (get_delegate (chooser));
}
static void
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 265f5de88d..832f9d04c2 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -913,7 +913,7 @@ change_folder_and_display_error (GtkFileChooserWidget *impl,
* list_row_activated()
* fetches path from model; path belongs to the model (*)
* calls change_folder_and_display_error()
- * calls gtk_file_chooser_set_current_folder_file()
+ * calls gtk_file_chooser_set_current_folder()
* changing folders fails, sets model to NULL, thus freeing the path in (*)
*/
@@ -2832,7 +2832,7 @@ switch_to_home_dir (GtkFileChooserWidget *impl)
home_file = g_file_new_for_path (home);
- gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */
g_object_unref (home_file);
}
@@ -3734,10 +3734,12 @@ settings_save (GtkFileChooserWidget *impl)
static void
switch_to_cwd (GtkFileChooserWidget *impl)
{
- char *current_working_dir;
+ char *current_working_dir = g_get_current_dir ();
+ GFile *cwd = g_file_new_for_path (current_working_dir);
- current_working_dir = g_get_current_dir ();
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), cwd, NULL);
+
+ g_object_unref (cwd);
g_free (current_working_dir);
}
@@ -5599,7 +5601,7 @@ gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
parent_file = g_file_get_parent (file);
if (!parent_file)
- return gtk_file_chooser_set_current_folder_file (chooser, file, error);
+ return gtk_file_chooser_set_current_folder (chooser, file, error);
fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->browse_files_tree_view)));
@@ -5639,7 +5641,7 @@ gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
{
gboolean result;
- result = gtk_file_chooser_set_current_folder_file (chooser, parent_file, error);
+ result = gtk_file_chooser_set_current_folder (chooser, parent_file, error);
g_object_unref (parent_file);
return result;
}
@@ -5948,7 +5950,7 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser)
{
GFile *current_folder;
- current_folder = gtk_file_chooser_get_current_folder_file (chooser);
+ current_folder = gtk_file_chooser_get_current_folder (chooser);
if (current_folder)
info.result = g_slist_prepend (info.result, current_folder);
@@ -7801,6 +7803,7 @@ static void
desktop_folder_handler (GtkFileChooserWidget *impl)
{
const char *name;
+ GFile *file;
/* "To disable a directory, point it to the homedir."
* See http://freedesktop.org/wiki/Software/xdg-user-dirs
@@ -7809,7 +7812,9 @@ desktop_folder_handler (GtkFileChooserWidget *impl)
if (!g_strcmp0 (name, g_get_home_dir ()))
return;
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), name);
+ file = g_file_new_for_path (name);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), file, NULL);
+ g_object_unref (file);
}
/* Handler for the "search-shortcut" keybinding signal */
diff --git a/gtk/gtkprinteroptionwidget.c b/gtk/gtkprinteroptionwidget.c
index 13e8558beb..1897e44f24 100644
--- a/gtk/gtkprinteroptionwidget.c
+++ b/gtk/gtkprinteroptionwidget.c
@@ -68,7 +68,7 @@ struct GtkPrinterOptionWidgetPrivate
GtkWidget *button;
/* the last location for save to file, that the user selected */
- gchar *last_location;
+ GFile *last_location;
};
enum {
@@ -485,42 +485,49 @@ dialog_response_callback (GtkDialog *dialog,
GtkPrinterOptionWidget *widget)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
- gchar *uri = NULL;
- gchar *new_location = NULL;
+ GFile *new_location = NULL;
+ char *uri = NULL;
if (response_id == GTK_RESPONSE_ACCEPT)
{
- gchar *filename;
- gchar *filename_utf8;
- gchar *filename_short;
-
- new_location = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
- filename_short = trim_long_filename (filename_utf8);
- gtk_button_set_label (GTK_BUTTON (priv->button), filename_short);
- g_free (filename_short);
- g_free (filename_utf8);
- g_free (filename);
+ GFileInfo *info;
+
+ new_location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ info = g_file_query_info (new_location,
+ "standard::display-name",
+ 0,
+ NULL,
+ NULL);
+ if (info != NULL)
+ {
+ const char *filename_utf8 = g_file_info_get_display_name (info);
+
+ char *filename_short = trim_long_filename (filename_utf8);
+ gtk_button_set_label (GTK_BUTTON (priv->button), filename_short);
+
+ g_free (filename_short);
+ g_object_unref (info);
+ }
+
+ g_object_unref (new_location);
}
gtk_widget_destroy (GTK_WIDGET (dialog));
if (new_location)
- uri = new_location;
+ uri = g_file_get_uri (new_location);
else
- uri = priv->last_location;
+ uri = g_file_get_uri (priv->last_location);
- if (uri)
+ if (uri != NULL)
{
gtk_printer_option_set (priv->source, uri);
emit_changed (widget);
+ g_free (uri);
}
- g_free (new_location);
- g_free (priv->last_location);
- priv->last_location = NULL;
+ g_object_unref (new_location);
+ g_clear_object (&priv->last_location);
/* unblock the handler which was blocked in the filesave_choose_cb function */
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
@@ -531,7 +538,6 @@ filesave_choose_cb (GtkWidget *button,
GtkPrinterOptionWidget *widget)
{
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
- gchar *last_location = NULL;
GtkWidget *dialog;
GtkWindow *toplevel;
@@ -550,23 +556,21 @@ filesave_choose_cb (GtkWidget *button,
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), FALSE);
/* select the current filename in the dialog */
- if (priv->source != NULL)
+ if (priv->source != NULL && priv->source->value != NULL)
{
- priv->last_location = last_location = g_strdup (priv->source->value);
- if (last_location)
+ priv->last_location = g_file_new_for_uri (priv->source->value);
+ if (priv->last_location)
{
- GFile *file;
- gchar *basename;
- gchar *basename_utf8;
+ char *basename;
+ char *basename_utf8;
+
+ gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->last_location, NULL);
- gtk_file_chooser_select_uri (GTK_FILE_CHOOSER (dialog), last_location);
- file = g_file_new_for_uri (last_location);
- basename = g_file_get_basename (file);
+ basename = g_file_get_basename (priv->last_location);
basename_utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename_utf8);
g_free (basename_utf8);
g_free (basename);
- g_object_unref (file);
}
}
diff --git a/gtk/inspector/css-editor.c b/gtk/inspector/css-editor.c
index 4cb20632d7..b0b7ae6997 100644
--- a/gtk/inspector/css-editor.c
+++ b/gtk/inspector/css-editor.c
@@ -185,14 +185,22 @@ get_current_text (GtkTextBuffer *buffer)
static void
save_to_file (GtkInspectorCssEditor *ce,
- const gchar *filename)
+ GFile *file)
{
- gchar *text;
GError *error = NULL;
+ char *text;
text = get_current_text (ce->priv->text);
- if (!g_file_set_contents (filename, text, -1, &error))
+ g_file_replace_contents (file, text, -1,
+ NULL,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ NULL,
+ &error);
+
+ if (error != NULL)
{
GtkWidget *dialog;
@@ -220,11 +228,9 @@ save_response (GtkWidget *dialog,
if (response == GTK_RESPONSE_ACCEPT)
{
- gchar *filename;
-
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- save_to_file (ce, filename);
- g_free (filename);
+ GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ save_to_file (ce, file);
+ g_object_unref (file);
}
gtk_widget_destroy (dialog);
diff --git a/tests/print-editor.c b/tests/print-editor.c
index b141fbb80c..7e2d0f0796 100644
--- a/tests/print-editor.c
+++ b/tests/print-editor.c
@@ -3,7 +3,7 @@
#include <gtk/gtk.h>
static GtkWidget *main_window;
-static char *filename = NULL;
+static GFile *filename = NULL;
static GtkPageSetup *page_setup = NULL;
static GtkPrintSettings *settings = NULL;
static gboolean file_changed = FALSE;
@@ -20,7 +20,7 @@ update_title (GtkWindow *window)
if (filename == NULL)
basename = g_strdup ("Untitled");
else
- basename = g_path_get_basename (filename);
+ basename = g_file_get_basename (filename);
title = g_strdup_printf ("Simple Editor with printing - %s", basename);
g_free (basename);
@@ -81,7 +81,8 @@ get_text (void)
}
static void
-set_text (const char *text, gsize len)
+set_text (const char *text,
+ gsize len)
{
gtk_text_buffer_set_text (buffer, text, len);
file_changed = FALSE;
@@ -89,7 +90,7 @@ set_text (const char *text, gsize len)
}
static void
-load_file (const char *open_filename)
+load_file (GFile *open_filename)
{
GtkWidget *error_dialog;
char *contents;
@@ -98,37 +99,45 @@ load_file (const char *open_filename)
error_dialog = NULL;
error = NULL;
- if (g_file_get_contents (open_filename, &contents, &len, &error))
+ g_file_load_contents (open_filename, NULL, &contents, &len, NULL, &error);
+ if (error == NULL)
{
if (g_utf8_validate (contents, len, NULL))
{
- filename = g_strdup (open_filename);
+ g_clear_object (&filename);
+ filename = g_object_ref (open_filename);
set_text (contents, len);
g_free (contents);
}
else
{
+ GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
+ const char *display_name = g_file_info_get_display_name (info);
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error loading file %s:\n%s",
- open_filename,
+ display_name,
"Not valid utf8");
+ g_object_unref (info);
}
}
else
{
+ GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
+ const char *display_name = g_file_info_get_display_name (info);
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error loading file %s:\n%s",
- open_filename,
+ display_name,
error->message);
-
+ g_object_unref (info);
g_error_free (error);
}
+
if (error_dialog)
{
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
@@ -138,38 +147,49 @@ load_file (const char *open_filename)
static void
-save_file (const char *save_filename)
+save_file (GFile *save_filename)
{
char *text = get_text ();
GtkWidget *error_dialog;
GError *error;
error = NULL;
- if (g_file_set_contents (save_filename,
- text, -1, &error))
+ g_file_replace_contents (save_filename,
+ text, -1,
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL,
+ NULL,
+ &error);
+
+ if (error != NULL)
{
if (save_filename != filename)
{
- g_free (filename);
- filename = g_strdup (save_filename);
+ g_clear_object (&filename);
+ filename = g_object_ref (save_filename);
}
file_changed = FALSE;
update_ui ();
}
else
{
+ GFileInfo *info = g_file_query_info (save_filename, "standard::display-name", 0, NULL, NULL);
+ const char *display_name = g_file_info_get_display_name (info);
+
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error saving to file %s:\n%s",
- filename,
+ display_name,
error->message);
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show (error_dialog);
g_error_free (error);
+ g_object_unref (info);
}
}
@@ -481,7 +501,6 @@ activate_save_as (GSimpleAction *action,
{
GtkWidget *dialog;
gint response;
- char *save_filename;
dialog = gtk_file_chooser_dialog_new ("Select file",
GTK_WINDOW (main_window),
@@ -494,9 +513,9 @@ activate_save_as (GSimpleAction *action,
if (response == GTK_RESPONSE_OK)
{
- save_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ GFile *save_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
save_file (save_filename);
- g_free (save_filename);
+ g_object_unref (save_filename);
}
gtk_widget_destroy (dialog);
@@ -520,7 +539,6 @@ activate_open (GSimpleAction *action,
{
GtkWidget *dialog;
gint response;
- char *open_filename;
dialog = gtk_file_chooser_dialog_new ("Select file",
GTK_WINDOW (main_window),
@@ -533,9 +551,9 @@ activate_open (GSimpleAction *action,
if (response == GTK_RESPONSE_OK)
{
- open_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ GFile *open_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
load_file (open_filename);
- g_free (open_filename);
+ g_object_unref (open_filename);
}
gtk_widget_destroy (dialog);
@@ -689,7 +707,11 @@ command_line (GApplication *application,
argv = g_application_command_line_get_arguments (command_line, &argc);
if (argc == 2)
- load_file (argv[1]);
+ {
+ GFile *file = g_file_new_for_commandline_arg (argv[1]);
+ load_file (file);
+ g_object_unref (file);
+ }
return 0;
}
diff --git a/tests/testfilechooser.c b/tests/testfilechooser.c
index 6086d9d917..cdcffc213d 100644
--- a/tests/testfilechooser.c
+++ b/tests/testfilechooser.c
@@ -44,28 +44,38 @@ static GtkFileChooserAction action;
static void
print_current_folder (GtkFileChooser *chooser)
{
- gchar *uri;
+ GFile *cwd;
- uri = gtk_file_chooser_get_current_folder_uri (chooser);
- g_print ("Current folder changed :\n %s\n", uri ? uri : "(null)");
- g_free (uri);
+ cwd = gtk_file_chooser_get_current_folder (chooser);
+ if (cwd != NULL)
+ {
+ char *uri = g_file_get_uri (cwd);
+ g_print ("Current folder changed :\n %s\n", uri ? uri : "(null)");
+ g_free (uri);
+ g_object_unref (cwd);
+ }
+ else
+ {
+ g_print ("Current folder changed :\n none\n");
+ }
}
static void
print_selected (GtkFileChooser *chooser)
{
- GSList *uris = gtk_file_chooser_get_uris (chooser);
+ GSList *uris = gtk_file_chooser_get_files (chooser);
GSList *tmp_list;
g_print ("Selection changed :\n");
for (tmp_list = uris; tmp_list; tmp_list = tmp_list->next)
{
- gchar *uri = tmp_list->data;
- g_print (" %s\n", uri);
+ GFile *file = tmp_list->data;
+ char *uri = g_file_get_uri (file);
+ g_print (" %s\n", uri ? uri : "(null)");
g_free (uri);
}
g_print ("\n");
- g_slist_free (uris);
+ g_slist_free_full (uris, g_object_unref);
}
static void
@@ -79,7 +89,7 @@ response_cb (GtkDialog *dialog,
{
GSList *list;
- list = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
+ list = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
if (list)
{
@@ -89,11 +99,13 @@ response_cb (GtkDialog *dialog,
for (l = list; l; l = l->next)
{
- g_print ("%s\n", (char *) l->data);
- g_free (l->data);
+ GFile *file = l->data;
+ char *uri = g_file_get_uri (file);
+ g_print (" %s\n", uri ? uri : "(null)");
+ g_free (uri);
}
- g_slist_free (list);
+ g_slist_free_full (list, g_object_unref);
}
else
g_print ("No selected files\n");
@@ -341,7 +353,8 @@ static void
set_current_folder (GtkFileChooser *chooser,
const char *name)
{
- if (!gtk_file_chooser_set_current_folder (chooser, name))
+ GFile *file = g_file_new_for_path (name);
+ if (!gtk_file_chooser_set_current_folder (chooser, file, NULL))
{
GtkWidget *dialog;
@@ -354,6 +367,7 @@ set_current_folder (GtkFileChooser *chooser,
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
+ g_object_unref (file);
}
static void
@@ -374,7 +388,8 @@ static void
set_filename (GtkFileChooser *chooser,
const char *name)
{
- if (!gtk_file_chooser_set_filename (chooser, name))
+ GFile *file = g_file_new_for_path (name);
+ if (!gtk_file_chooser_set_file (chooser, file, NULL))
{
GtkWidget *dialog;
@@ -387,6 +402,7 @@ set_filename (GtkFileChooser *chooser,
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
+ g_object_unref (file);
}
static void
@@ -409,7 +425,7 @@ get_selection_cb (GtkButton *button,
{
GSList *selection;
- selection = gtk_file_chooser_get_uris (chooser);
+ selection = gtk_file_chooser_get_files (chooser);
g_print ("Selection: ");
@@ -421,16 +437,19 @@ get_selection_cb (GtkButton *button,
for (l = selection; l; l = l->next)
{
- char *uri = l->data;
+ GFile *file = l->data;
+ char *uri = g_file_get_uri (file);
g_print ("%s\n", uri);
+ g_free (uri);
+
if (l->next)
g_print (" ");
}
}
- g_slist_free_full (selection, g_free);
+ g_slist_free_full (selection, g_object_unref);
}
static void
@@ -534,6 +553,7 @@ main (int argc, char **argv)
char *action_arg = NULL;
char *initial_filename = NULL;
char *initial_folder = NULL;
+ GFile *file;
GError *error = NULL;
GOptionEntry options[] = {
{ "action", 'a', 0, G_OPTION_ARG_STRING, &action_arg, "Filechooser action", "ACTION" },
@@ -680,7 +700,7 @@ main (int argc, char **argv)
G_CALLBACK (update_preview_cb), NULL);
#endif
- /* Extra widget */
+ /* Choices */
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (dialog), "choice1",
"Choose one:",
@@ -690,12 +710,13 @@ main (int argc, char **argv)
/* Shortcuts */
- gtk_file_chooser_add_shortcut_folder_uri (GTK_FILE_CHOOSER (dialog),
- "file:///usr/share/pixmaps",
- NULL);
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
- g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
- NULL);
+ file = g_file_new_for_uri ("file:///usr/share/pixmaps");
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), file, NULL);
+ g_object_unref (file);
+
+ file = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_MUSIC));
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), file, NULL);
+ g_object_unref (file);
/* Initial filename or folder */
diff --git a/tests/testfilechooserbutton.c b/tests/testfilechooserbutton.c
index 550d625e01..d226aa0809 100644
--- a/tests/testfilechooserbutton.c
+++ b/tests/testfilechooserbutton.c
@@ -45,23 +45,31 @@ static void
print_selected_path_clicked_cb (GtkWidget *button,
gpointer user_data)
{
- gchar *folder, *filename;
+ GFile *folder, *filename;
+ char *folder_uri, *filename_uri;
folder = gtk_file_chooser_get_current_folder (user_data);
- filename = gtk_file_chooser_get_filename (user_data);
+ filename = gtk_file_chooser_get_file (user_data);
+
+ folder_uri = g_file_get_uri (folder);
+ filename_uri = g_file_get_uri (filename);
g_message ("Currently Selected:\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
- folder, filename);
- g_free (folder);
- g_free (filename);
+ folder_uri, filename_uri);
+ g_free (folder_uri);
+ g_free (filename_uri);
+
+ g_object_unref (folder);
+ g_object_unref (filename);
}
static void
add_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
gpointer user_data)
{
+ GFile *path = g_file_new_for_path (gtk_src_dir);
GError *err = NULL;
- if (!gtk_file_chooser_add_shortcut_folder (user_data, gtk_src_dir, &err))
+ if (!gtk_file_chooser_add_shortcut_folder (user_data, path, &err))
{
g_message ("Couldn't add `%s' as shortcut folder: %s", gtk_src_dir,
err->message);
@@ -71,15 +79,18 @@ add_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
{
g_message ("Added `%s' as shortcut folder.", gtk_src_dir);
}
+
+ g_object_unref (path);
}
static void
del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
gpointer user_data)
{
+ GFile *path = g_file_new_for_path (gtk_src_dir);
GError *err = NULL;
- if (!gtk_file_chooser_remove_shortcut_folder (user_data, gtk_src_dir, &err))
+ if (!gtk_file_chooser_remove_shortcut_folder (user_data, path, &err))
{
g_message ("Couldn't remove `%s' as shortcut folder: %s", gtk_src_dir,
err->message);
@@ -89,6 +100,8 @@ del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
{
g_message ("Removed `%s' as shortcut folder.", gtk_src_dir);
}
+
+ g_object_unref (path);
}
static void
@@ -155,54 +168,76 @@ static void
chooser_current_folder_changed_cb (GtkFileChooser *chooser,
gpointer user_data)
{
- gchar *folder, *filename;
+ GFile *folder, *filename;
+ char *folder_uri, *filename_uri;
- folder = gtk_file_chooser_get_current_folder_uri (chooser);
- filename = gtk_file_chooser_get_uri (chooser);
+ folder = gtk_file_chooser_get_current_folder (chooser);
+ filename = gtk_file_chooser_get_file (chooser);
+
+ folder_uri = g_file_get_uri (folder);
+ filename_uri = g_file_get_uri (filename);
g_message ("%s::current-folder-changed\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
- G_OBJECT_TYPE_NAME (chooser), folder, filename);
- g_free (folder);
- g_free (filename);
+ G_OBJECT_TYPE_NAME (chooser), folder_uri, filename_uri);
+ g_free (folder_uri);
+ g_free (filename_uri);
+
+ g_object_unref (folder);
+ g_object_unref (filename);
}
static void
chooser_selection_changed_cb (GtkFileChooser *chooser,
gpointer user_data)
{
- gchar *filename;
+ GFile *filename;
+ char *uri;
+
+ filename = gtk_file_chooser_get_file (chooser);
- filename = gtk_file_chooser_get_uri (chooser);
+ uri = g_file_get_uri (filename);
g_message ("%s::selection-changed\n\tSelection:`%s'\nDone.\n",
- G_OBJECT_TYPE_NAME (chooser), filename);
- g_free (filename);
+ G_OBJECT_TYPE_NAME (chooser), uri);
+ g_free (uri);
+
+ g_object_unref (filename);
}
static void
chooser_file_activated_cb (GtkFileChooser *chooser,
gpointer user_data)
{
- gchar *folder, *filename;
+ GFile *folder, *filename;
+ char *folder_uri, *filename_uri;
+
+ folder = gtk_file_chooser_get_current_folder (chooser);
+ filename = gtk_file_chooser_get_file (chooser);
- folder = gtk_file_chooser_get_current_folder_uri (chooser);
- filename = gtk_file_chooser_get_uri (chooser);
+ folder_uri = g_file_get_uri (folder);
+ filename_uri = g_file_get_uri (filename);
g_message ("%s::file-activated\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
- G_OBJECT_TYPE_NAME (chooser), folder, filename);
- g_free (folder);
- g_free (filename);
+ G_OBJECT_TYPE_NAME (chooser), folder_uri, filename_uri);
+ g_free (folder_uri);
+ g_free (filename_uri);
+
+ g_object_unref (folder);
+ g_object_unref (filename);
}
static void
chooser_update_preview_cb (GtkFileChooser *chooser,
gpointer user_data)
{
- gchar *filename;
+ GFile *filename;
- filename = gtk_file_chooser_get_preview_uri (chooser);
+ filename = gtk_file_chooser_get_preview_file (chooser);
if (filename != NULL)
{
+ char *uri = g_file_get_uri (filename);
g_message ("%s::update-preview\n\tPreview Filename: `%s'\nDone.\n",
- G_OBJECT_TYPE_NAME (chooser), filename);
- g_free (filename);
+ G_OBJECT_TYPE_NAME (chooser), uri);
+ g_free (uri);
+
+ g_object_unref (filename);
}
}
@@ -214,6 +249,7 @@ add_new_filechooser_button (const gchar *mnemonic,
GtkSizeGroup *label_group)
{
GtkWidget *hbox, *label, *chooser, *button;
+ GFile *path;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_add (GTK_CONTAINER (group_box), hbox);
@@ -227,8 +263,12 @@ add_new_filechooser_button (const gchar *mnemonic,
" - testfilechooserbutton", NULL),
action);
gtk_widget_set_hexpand (chooser, TRUE);
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
- gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
+
+ path = g_file_new_for_path (gtk_src_dir);
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), path, NULL);
+ gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), path, NULL);
+ g_object_unref (path);
+
gtk_label_set_mnemonic_widget (GTK_LABEL (label), chooser);
g_signal_connect (chooser, "current-folder-changed",
G_CALLBACK (chooser_current_folder_changed_cb), NULL);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 3d4c32bf1c..6c65009cfc 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -5709,14 +5709,17 @@ native_response (GtkNativeDialog *self,
char *response;
GtkFileFilter *filter;
- uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (self));
+ uris = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (self));
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self));
s = g_string_new ("");
for (l = uris; l != NULL; l = l->next)
{
- g_string_prepend (s, l->data);
+ char *uri = g_file_get_uri (l->data);
+ g_string_prepend (s, uri);
g_string_prepend (s, "\n");
+ g_free (uri);
}
+ g_slist_free_full (uris, g_object_unref);
switch (response_id)
{
@@ -5826,12 +5829,12 @@ native_visible_notify_hide (GObject *object,
gtk_widget_set_sensitive (hide_button, visible);
}
-static char *
+static GFile *
get_some_file (void)
{
GFile *dir = g_file_new_for_path (g_get_current_dir ());
GFileEnumerator *e;
- char *res = NULL;
+ GFile *res = NULL;
e = g_file_enumerate_children (dir, "*", 0, NULL, NULL);
if (e)
@@ -5846,8 +5849,7 @@ get_some_file (void)
if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
{
GFile *child = g_file_enumerator_get_child (e, info);
- res = g_file_get_path (child);
- g_object_unref (child);
+ res = g_steal_pointer (&child);
}
g_object_unref (info);
}
@@ -5882,9 +5884,8 @@ native_action_changed (GtkWidget *combo,
{
if (save_as)
{
- char *file = get_some_file ();
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (native), file);
- g_free (file);
+ GFile *file = get_some_file ();
+ gtk_file_chooser_set_file (GTK_FILE_CHOOSER (native), file, NULL);
}
else
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (native), "newname.txt");
@@ -5962,6 +5963,8 @@ create_native_dialogs (GtkWidget *widget)
if (!window)
{
+ GFile *path;
+
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (widget));
@@ -5974,9 +5977,9 @@ create_native_dialogs (GtkWidget *widget)
g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (destroy_native), native);
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native),
- g_get_current_dir (),
- NULL);
+ path = g_file_new_for_path (g_get_current_dir ());
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native), path, NULL);
+ g_object_unref (path);
gtk_window_set_title (GTK_WINDOW(window), "Native dialog parent");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]