diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2020-02-21 15:11:15 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2020-02-22 15:22:06 +0000 |
commit | 5f070ff233386eae3b3290d12ba67745833dcb8c (patch) | |
tree | 0134efb5e47f7a57d47a7f09c1f16c3b2a69f52f /gtk | |
parent | b002572824a8b902fe44b879ac8bdf097fb3d6e9 (diff) | |
download | gtk+-5f070ff233386eae3b3290d12ba67745833dcb8c.tar.gz |
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
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkfilechooser.c | 1127 | ||||
-rw-r--r-- | gtk/gtkfilechooser.h | 67 | ||||
-rw-r--r-- | gtk/gtkfilechooserbutton.c | 15 | ||||
-rw-r--r-- | gtk/gtkfilechooserdialog.c | 31 | ||||
-rw-r--r-- | gtk/gtkfilechoosernative.c | 4 | ||||
-rw-r--r-- | gtk/gtkfilechoosernativewin32.c | 12 | ||||
-rw-r--r-- | gtk/gtkfilechooserprivate.h | 8 | ||||
-rw-r--r-- | gtk/gtkfilechooserutils.c | 10 | ||||
-rw-r--r-- | gtk/gtkfilechooserwidget.c | 23 | ||||
-rw-r--r-- | gtk/gtkprinteroptionwidget.c | 70 | ||||
-rw-r--r-- | gtk/inspector/css-editor.c | 22 |
11 files changed, 279 insertions, 1110 deletions
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)); @@ -638,285 +616,6 @@ gtk_file_chooser_get_create_folders (GtkFileChooser *chooser) } /** - * 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 * @name: (type filename): the filename to use, as a UTF-8 string @@ -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); @@ -969,145 +669,6 @@ gtk_file_chooser_get_current_name (GtkFileChooser *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)); @@ -1861,189 +1257,18 @@ gtk_file_chooser_get_filter (GtkFileChooser *chooser) } /** - * 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 * * 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); return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser); @@ -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 */ @@ -245,10 +203,6 @@ 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); /* Extra widget @@ -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,27 +236,16 @@ 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, const char *label, 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); |