From ff6772fd983b17ff173b0a829ba0a86fa72dd472 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 22 Feb 2020 16:39:01 +0000 Subject: [PATCH] Remove preview widget from GtkFileChooser The preview widget harks from a platform before time, when we didn't have GIO, or a thumbnail specification. Very few applications use it correctly, if at all; it has an horrid hack to deal with the ownership of the widget's instance when accessed through the getter function; it messes up the layout of the widget and its label is less than useful when it comes to file names longer than a dozen characters; it's a poor substitute for a proper thumbnail view. --- docs/reference/gtk/gtk4-sections.txt | 8 - gtk/gtkfilechooser.c | 267 --------------------------- gtk/gtkfilechooser.h | 21 --- gtk/gtkfilechooserbutton.c | 30 +-- gtk/gtkfilechoosernative.c | 19 -- gtk/gtkfilechoosernativequartz.c | 5 - gtk/gtkfilechoosernativewin32.c | 5 - gtk/gtkfilechooserprivate.h | 1 - gtk/gtkfilechooserutils.c | 28 --- gtk/gtkfilechooserutils.h | 3 - gtk/gtkfilechooserwidget.c | 212 --------------------- gtk/ui/gtkfilechooserwidget.ui | 10 +- tests/testfilechooser.c | 111 ----------- tests/testfilechooserbutton.c | 19 -- 14 files changed, 2 insertions(+), 737 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index a99b93b2e8..1e08f0ebb9 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -1145,14 +1145,6 @@ gtk_file_chooser_get_files gtk_file_chooser_set_current_folder gtk_file_chooser_get_current_folder -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_file - gtk_file_chooser_add_filter gtk_file_chooser_remove_filter gtk_file_chooser_list_filters diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c index 0dbb05581d..549c56279b 100644 --- a/gtk/gtkfilechooser.c +++ b/gtk/gtkfilechooser.c @@ -61,62 +61,6 @@ * #GtkFileChooser, your program can get the selected filenames as * #GFiles. * - * # Adding a Preview Widget - * - * You can add a custom preview widget to a file chooser and then - * get notification about when the preview needs to be updated. - * To install a preview widget, use - * gtk_file_chooser_set_preview_widget(). Then, connect to the - * #GtkFileChooser::update-preview signal to get notified when - * you need to update the contents of the preview. - * - * Your callback should use - * 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 - * flag that indicates whether your callback could successfully - * generate a preview. - * - * ## Example: Using a Preview Widget ## {#gtkfilechooser-preview} - * |[ - * { - * GtkImage *preview; - * - * ... - * - * preview = gtk_image_new (); - * - * gtk_file_chooser_set_preview_widget (my_file_chooser, preview); - * g_signal_connect (my_file_chooser, "update-preview", - * G_CALLBACK (update_preview_cb), preview); - * } - * - * static void - * update_preview_cb (GtkFileChooser *file_chooser, gpointer data) - * { - * GtkWidget *preview = data; - * - * g_autoptr(GFile) preview_file = - * gtk_file_chooser_get_preview_file (file_chooser); - * - * 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); - * g_clear_object (&pixbuf); - * - * gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); - * } - * ]| - * * # Adding options * * You can add extra widgets to a file chooser to provide options @@ -182,39 +126,6 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface) NULL, G_TYPE_NONE, 0); - /** - * GtkFileChooser::update-preview: - * @chooser: the object which received the signal. - * - * This signal is emitted when the preview in a file chooser should be - * regenerated. For example, this can happen when the currently selected file - * changes. You should use this signal if you want your file chooser to have - * a preview widget. - * - * 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_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. - * - * Please see the example code in - * [Using a Preview Widget][gtkfilechooser-preview]. - * - * 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_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); - /** * GtkFileChooser::file-activated: * @chooser: the object which received the signal. @@ -250,24 +161,6 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface) 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_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_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_object_interface_install_property (iface, g_param_spec_boolean ("select-multiple", P_("Select Multiple"), @@ -707,166 +600,6 @@ _gtk_file_chooser_get_file_system (GtkFileChooser *chooser) return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser); } -/* Preview widget - */ -/** - * gtk_file_chooser_set_preview_widget: - * @chooser: a #GtkFileChooser - * @preview_widget: widget for displaying preview. - * - * 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_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. - * - * When there is no application-supplied preview widget, or the - * application-supplied preview widget is not active, the file chooser - * will display no preview at all. - **/ -void -gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser, - GtkWidget *preview_widget) -{ - g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); - - g_object_set (chooser, "preview-widget", preview_widget, NULL); -} - -/** - * gtk_file_chooser_get_preview_widget: - * @chooser: a #GtkFileChooser - * - * Gets the current preview widget; see - * gtk_file_chooser_set_preview_widget(). - * - * Returns: (nullable) (transfer none): the current preview widget, or %NULL - **/ -GtkWidget * -gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser) -{ - GtkWidget *preview_widget; - - g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL); - - g_object_get (chooser, "preview-widget", &preview_widget, NULL); - - /* Horrid hack; g_object_get() refs returned objects but - * that contradicts the memory management conventions - * for accessors. - */ - if (preview_widget) - g_object_unref (preview_widget); - - return preview_widget; -} - -/** - * gtk_file_chooser_set_preview_widget_active: - * @chooser: a #GtkFileChooser - * @active: whether to display the user-specified preview widget - * - * Sets whether the preview widget set by - * gtk_file_chooser_set_preview_widget() should be shown for the - * current filename. When @active is set to false, the file chooser - * may display an internally generated preview of the current file - * or it may display no preview at all. See - * gtk_file_chooser_set_preview_widget() for more details. - **/ -void -gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser, - gboolean active) -{ - g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); - - g_object_set (chooser, "preview-widget-active", active, NULL); -} - -/** - * gtk_file_chooser_get_preview_widget_active: - * @chooser: a #GtkFileChooser - * - * Gets whether the preview widget set by gtk_file_chooser_set_preview_widget() - * should be shown for the current filename. See - * gtk_file_chooser_set_preview_widget_active(). - * - * Returns: %TRUE if the preview widget is active for the current filename. - **/ -gboolean -gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser) -{ - gboolean active; - - g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE); - - g_object_get (chooser, "preview-widget-active", &active, NULL); - - return active; -} - -/** - * gtk_file_chooser_set_use_preview_label: - * @chooser: a #GtkFileChooser - * @use_label: whether to display a label with the name of the previewed file - * - * Sets whether the file chooser should display a label with the name of - * the file that is being previewed; the default is %TRUE. Applications that - * want to draw the whole preview area themselves should set this to %FALSE and - * display the name themselves in their preview widget. - * - * See also: gtk_file_chooser_set_preview_widget() - **/ -void -gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser, - gboolean use_label) -{ - g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); - - g_object_set (chooser, "use-preview-label", use_label, NULL); -} - -/** - * gtk_file_chooser_get_use_preview_label: - * @chooser: a #GtkFileChooser - * - * Gets whether a label should be drawn with the name of the previewed - * file. See gtk_file_chooser_set_use_preview_label(). - * - * Returns: %TRUE if the file chooser is set to display a label with the - * name of the previewed file, %FALSE otherwise. - **/ -gboolean -gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser) -{ - gboolean use_label; - - g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE); - - g_object_get (chooser, "use-preview-label", &use_label, NULL); - - return use_label; -} - -/** - * gtk_file_chooser_get_preview_file: - * @chooser: a #GtkFileChooser - * - * Gets the #GFile that should be previewed in a custom preview - * - * Returns: (nullable) (transfer full): the #GFile for the file to preview, - * or %NULL if no file is selected. Free with g_object_unref(). - **/ -GFile * -gtk_file_chooser_get_preview_file (GtkFileChooser *chooser) -{ - g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL); - - return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_preview_file (chooser); -} - /** * gtk_file_chooser_add_shortcut_folder: * @chooser: a #GtkFileChooser diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h index dccef32ca0..2aff129c5d 100644 --- a/gtk/gtkfilechooser.h +++ b/gtk/gtkfilechooser.h @@ -141,27 +141,6 @@ gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser, GDK_AVAILABLE_IN_ALL GFile * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser); -/* Preview widget - */ -GDK_AVAILABLE_IN_ALL -void gtk_file_chooser_set_preview_widget (GtkFileChooser *chooser, - GtkWidget *preview_widget); -GDK_AVAILABLE_IN_ALL -GtkWidget *gtk_file_chooser_get_preview_widget (GtkFileChooser *chooser); -GDK_AVAILABLE_IN_ALL -void gtk_file_chooser_set_preview_widget_active (GtkFileChooser *chooser, - gboolean active); -GDK_AVAILABLE_IN_ALL -gboolean gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser); -GDK_AVAILABLE_IN_ALL -void gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser, - gboolean use_label); -GDK_AVAILABLE_IN_ALL -gboolean gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser); - -GDK_AVAILABLE_IN_ALL -GFile *gtk_file_chooser_get_preview_file (GtkFileChooser *chooser); - /* List of user selectable filters */ GDK_AVAILABLE_IN_ALL diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 1260128e4a..f73f52add8 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -332,8 +332,6 @@ static void combo_box_changed_cb (GtkComboBox *combo_box, static void button_clicked_cb (GtkButton *real_button, gpointer user_data); -static void chooser_update_preview_cb (GtkFileChooser *dialog, - gpointer user_data); static void dialog_response_cb (GtkDialog *dialog, gint response, gpointer user_data); @@ -915,9 +913,6 @@ gtk_file_chooser_button_set_property (GObject *object, case PROP_TITLE: case GTK_FILE_CHOOSER_PROP_FILTER: - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: - case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value); break; @@ -951,9 +946,6 @@ gtk_file_chooser_button_get_property (GObject *object, case PROP_TITLE: case GTK_FILE_CHOOSER_PROP_ACTION: case GTK_FILE_CHOOSER_PROP_FILTER: - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: - case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value); @@ -2541,15 +2533,6 @@ open_dialog (GtkFileChooserButton *button) { restore_inactive_state (button); priv->active = TRUE; - - /* Only handle update-preview handler if it is handled on the button */ - if (g_signal_has_handler_pending (button, - g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER), - 0, TRUE)) - { - g_signal_connect (priv->chooser, "update-preview", - G_CALLBACK (chooser_update_preview_cb), button); - } } gtk_widget_set_sensitive (priv->combo_box, FALSE); @@ -2635,13 +2618,6 @@ button_clicked_cb (GtkButton *real_button, /* Dialog */ -static void -chooser_update_preview_cb (GtkFileChooser *dialog, - gpointer user_data) -{ - g_signal_emit_by_name (user_data, "update-preview"); -} - static void common_response_cb (GtkFileChooserButton *button, gint response) @@ -2662,11 +2638,7 @@ common_response_cb (GtkFileChooserButton *button, } if (priv->active) - { - priv->active = FALSE; - - g_signal_handlers_disconnect_by_func (priv->chooser, chooser_update_preview_cb, button); - } + priv->active = FALSE; update_label_and_image (button); update_combo_box (button); diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c index 7a94813802..4db1a2743a 100644 --- a/gtk/gtkfilechoosernative.c +++ b/gtk/gtkfilechoosernative.c @@ -162,8 +162,6 @@ * used. It supports many of the features that #GtkFileChooserDialog * does, but there are some things it does not handle: * - * * Use of custom previews by connecting to #GtkFileChooser::update-preview. - * * * Any #GtkFileFilter added using a mimetype or custom filter. * * If any of these features are used the regular #GtkFileChooserDialog @@ -177,8 +175,6 @@ * be a GTK+ file chooser. In this situation, the following things are not * supported and will be silently ignored: * - * * Use of custom previews by connecting to #GtkFileChooser::update-preview. - * * * Any #GtkFileFilter added with a custom filter. * * ## macOS details ## {#gtkfilechooserdialognative-macos} @@ -187,8 +183,6 @@ * file chooser dialogs. Some features provided by #GtkFileChooserDialog are * not supported: * - * * Use of custom previews by connecting to #GtkFileChooser::update-preview. - * * * Any #GtkFileFilter added with a custom filter. * * * Shortcut folders. @@ -566,13 +560,6 @@ dialog_response_cb (GtkDialog *dialog, _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), response_id); } -static void -dialog_update_preview_cb (GtkFileChooser *file_chooser, - gpointer data) -{ - g_signal_emit_by_name (data, "update-preview"); -} - static void show_dialog (GtkFileChooserNative *self) { @@ -607,11 +594,6 @@ show_dialog (GtkFileChooserNative *self) G_CALLBACK (dialog_response_cb), self); - g_signal_connect (self->dialog, - "update-preview", - G_CALLBACK (dialog_update_preview_cb), - self); - G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_window_present (GTK_WINDOW (self->dialog)); G_GNUC_END_IGNORE_DEPRECATIONS @@ -621,7 +603,6 @@ static void hide_dialog (GtkFileChooserNative *self) { g_signal_handlers_disconnect_by_func (self->dialog, dialog_response_cb, self); - g_signal_handlers_disconnect_by_func (self->dialog, dialog_update_preview_cb, self); gtk_widget_hide (self->dialog); } diff --git a/gtk/gtkfilechoosernativequartz.c b/gtk/gtkfilechoosernativequartz.c index 900f2ab5fc..026cdf1011 100644 --- a/gtk/gtkfilechoosernativequartz.c +++ b/gtk/gtkfilechoosernativequartz.c @@ -438,15 +438,10 @@ gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self) GtkWindow *transient_for; GtkFileChooserAction action; - guint update_preview_signal; GSList *filters, *l; int n_filters, i; char *message = NULL; - update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); - if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) - return FALSE; - data = g_new0 (FileChooserQuartzData, 1); // examine filters! diff --git a/gtk/gtkfilechoosernativewin32.c b/gtk/gtkfilechoosernativewin32.c index feec909d46..56cc5d4dcf 100644 --- a/gtk/gtkfilechoosernativewin32.c +++ b/gtk/gtkfilechoosernativewin32.c @@ -865,14 +865,9 @@ gtk_file_chooser_native_win32_show (GtkFileChooserNative *self) FilechooserWin32ThreadData *data; GtkWindow *transient_for; GtkFileChooserAction action; - guint update_preview_signal; GSList *filters, *l; int n_filters, i; - update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); - if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) - return FALSE; - data = g_new0 (FilechooserWin32ThreadData, 1); filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (self)); diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index c0eeb9f9a0..06a49dea03 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -73,7 +73,6 @@ struct _GtkFileChooserIface void (*select_all) (GtkFileChooser *chooser); void (*unselect_all) (GtkFileChooser *chooser); GSList * (*get_files) (GtkFileChooser *chooser); - GFile * (*get_preview_file) (GtkFileChooser *chooser); GtkFileSystem *(*get_file_system) (GtkFileChooser *chooser); void (*add_filter) (GtkFileChooser *chooser, GtkFileFilter *filter); diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c index 3a4241dabe..afa166056e 100644 --- a/gtk/gtkfilechooserutils.c +++ b/gtk/gtkfilechooserutils.c @@ -40,7 +40,6 @@ static void delegate_unselect_file (GtkFileChooser *choose static void delegate_select_all (GtkFileChooser *chooser); static void delegate_unselect_all (GtkFileChooser *chooser); static GSList * delegate_get_files (GtkFileChooser *chooser); -static GFile * delegate_get_preview_file (GtkFileChooser *chooser); static GtkFileSystem *delegate_get_file_system (GtkFileChooser *chooser); static void delegate_add_filter (GtkFileChooser *chooser, GtkFileFilter *filter); @@ -61,8 +60,6 @@ static void delegate_current_folder_changed (GtkFileChooser *choose gpointer data); static void delegate_selection_changed (GtkFileChooser *chooser, gpointer data); -static void delegate_update_preview (GtkFileChooser *chooser, - gpointer data); static void delegate_file_activated (GtkFileChooser *chooser, gpointer data); @@ -100,15 +97,6 @@ _gtk_file_chooser_install_properties (GObjectClass *klass) g_object_class_override_property (klass, GTK_FILE_CHOOSER_PROP_FILTER, "filter"); - g_object_class_override_property (klass, - GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET, - "preview-widget"); - g_object_class_override_property (klass, - GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE, - "preview-widget-active"); - g_object_class_override_property (klass, - GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL, - "use-preview-label"); g_object_class_override_property (klass, GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, "select-multiple"); @@ -140,7 +128,6 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface) iface->select_all = delegate_select_all; iface->unselect_all = delegate_unselect_all; iface->get_files = delegate_get_files; - iface->get_preview_file = delegate_get_preview_file; iface->get_file_system = delegate_get_file_system; iface->add_filter = delegate_add_filter; iface->remove_filter = delegate_remove_filter; @@ -179,8 +166,6 @@ _gtk_file_chooser_set_delegate (GtkFileChooser *receiver, G_CALLBACK (delegate_current_folder_changed), receiver); g_signal_connect (delegate, "selection-changed", G_CALLBACK (delegate_selection_changed), receiver); - g_signal_connect (delegate, "update-preview", - G_CALLBACK (delegate_update_preview), receiver); g_signal_connect (delegate, "file-activated", G_CALLBACK (delegate_file_activated), receiver); } @@ -236,12 +221,6 @@ delegate_get_files (GtkFileChooser *chooser) return gtk_file_chooser_get_files (get_delegate (chooser)); } -static GFile * -delegate_get_preview_file (GtkFileChooser *chooser) -{ - return gtk_file_chooser_get_preview_file (get_delegate (chooser)); -} - static GtkFileSystem * delegate_get_file_system (GtkFileChooser *chooser) { @@ -344,13 +323,6 @@ delegate_current_folder_changed (GtkFileChooser *chooser, g_signal_emit_by_name (data, "current-folder-changed"); } -static void -delegate_update_preview (GtkFileChooser *chooser, - gpointer data) -{ - g_signal_emit_by_name (data, "update-preview"); -} - static void delegate_file_activated (GtkFileChooser *chooser, gpointer data) diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h index 38341f2d72..96f6658d6f 100644 --- a/gtk/gtkfilechooserutils.h +++ b/gtk/gtkfilechooserutils.h @@ -30,9 +30,6 @@ typedef enum { GTK_FILE_CHOOSER_PROP_FIRST = 0x1000, GTK_FILE_CHOOSER_PROP_ACTION = GTK_FILE_CHOOSER_PROP_FIRST, GTK_FILE_CHOOSER_PROP_FILTER, - GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET, - GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE, - GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL, GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS, GTK_FILE_CHOOSER_PROP_LAST = GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index a6e835c5e0..6ea5fd392c 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -288,9 +288,6 @@ struct _GtkFileChooserWidgetPrivate { GtkWidget *extra_and_filters; GtkWidget *filter_combo_hbox; GtkWidget *filter_combo; - GtkWidget *preview_box; - GtkWidget *preview_label; - GtkWidget *preview_widget; GtkWidget *extra_align; GtkWidget *extra_widget; @@ -323,8 +320,6 @@ struct _GtkFileChooserWidgetPrivate { GtkBookmarksManager *bookmarks_manager; GFile *current_folder; - GFile *preview_file; - char *preview_display_name; GFile *renamed_file; GtkTreeViewColumn *list_name_column; @@ -359,8 +354,6 @@ struct _GtkFileChooserWidgetPrivate { /* Flags */ - guint preview_widget_active : 1; - guint use_preview_label : 1; guint select_multiple : 1; guint show_hidden : 1; guint sort_directories_first : 1; @@ -485,7 +478,6 @@ static void gtk_file_chooser_widget_unselect_file (GtkF static void gtk_file_chooser_widget_select_all (GtkFileChooser *chooser); static void gtk_file_chooser_widget_unselect_all (GtkFileChooser *chooser); static GSList * gtk_file_chooser_widget_get_files (GtkFileChooser *chooser); -static GFile * gtk_file_chooser_widget_get_preview_file (GtkFileChooser *chooser); static GtkFileSystem *gtk_file_chooser_widget_get_file_system (GtkFileChooser *chooser); static void gtk_file_chooser_widget_add_filter (GtkFileChooser *chooser, GtkFileFilter *filter); @@ -541,7 +533,6 @@ static void location_mode_set (GtkFileChooserWidget *impl, LocationMode new_mod static void set_current_filter (GtkFileChooserWidget *impl, GtkFileFilter *filter); -static void check_preview_change (GtkFileChooserWidget *impl); static void filter_combo_changed (GtkComboBox *combo_box, GtkFileChooserWidget *impl); @@ -618,7 +609,6 @@ gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface) iface->select_all = gtk_file_chooser_widget_select_all; iface->unselect_all = gtk_file_chooser_widget_unselect_all; iface->get_files = gtk_file_chooser_widget_get_files; - iface->get_preview_file = gtk_file_chooser_widget_get_preview_file; iface->get_file_system = gtk_file_chooser_widget_get_file_system; iface->set_current_folder = gtk_file_chooser_widget_set_current_folder; iface->get_current_folder = gtk_file_chooser_widget_get_current_folder; @@ -694,8 +684,6 @@ gtk_file_chooser_widget_finalize (GObject *object) /* stopping the load above should have cleared this */ g_assert (priv->load_timeout_id == 0); - g_free (priv->preview_display_name); - G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object); } @@ -908,58 +896,6 @@ change_folder_and_display_error (GtkFileChooserWidget *impl, return result; } -static void -update_preview_widget_visibility (GtkFileChooserWidget *impl) -{ - GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - - if (priv->use_preview_label) - { - if (!priv->preview_label) - { - priv->preview_label = gtk_label_new (priv->preview_display_name); - gtk_box_insert_child_after (GTK_BOX (priv->preview_box), priv->preview_label, NULL); - gtk_label_set_ellipsize (GTK_LABEL (priv->preview_label), PANGO_ELLIPSIZE_MIDDLE); - } - } - else - { - if (priv->preview_label) - { - gtk_widget_destroy (priv->preview_label); - priv->preview_label = NULL; - } - } - - if (priv->preview_widget_active && priv->preview_widget) - gtk_widget_show (priv->preview_box); - else - gtk_widget_hide (priv->preview_box); -} - -static void -set_preview_widget (GtkFileChooserWidget *impl, - GtkWidget *preview_widget) -{ - GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - - if (preview_widget == priv->preview_widget) - return; - - if (priv->preview_widget) - gtk_container_remove (GTK_CONTAINER (priv->preview_box), - priv->preview_widget); - - priv->preview_widget = preview_widget; - if (priv->preview_widget) - { - gtk_widget_show (priv->preview_widget); - gtk_container_add (GTK_CONTAINER (priv->preview_box), priv->preview_widget); - } - - update_preview_widget_visibility (impl); -} - static void new_folder_popover_active (GtkWidget *button, GParamSpec *pspec, @@ -2404,7 +2340,6 @@ location_changed_timeout_cb (gpointer user_data) GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (impl)); - check_preview_change (impl); g_signal_emit_by_name (impl, "selection-changed", 0); priv->location_changed_id = 0; @@ -2696,12 +2631,6 @@ places_sidebar_show_other_locations_with_flags_cb (GtkPlacesSidebar *sidebar GtkPlacesOpenFlags open_flags, GtkFileChooserWidget *impl) { - GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - - priv->preview_widget_active = FALSE; - - update_preview_widget_visibility (impl); - operation_mode_set (impl, OPERATION_MODE_OTHER_LOCATIONS); } @@ -2835,8 +2764,6 @@ set_select_multiple (GtkFileChooserWidget *impl, priv->select_multiple = select_multiple; g_object_notify (G_OBJECT (impl), "select-multiple"); - - check_preview_change (impl); } /* Takes the folder stored in a row in the recent_model, and puts it in the pathbar */ @@ -3243,20 +3170,6 @@ gtk_file_chooser_widget_set_property (GObject *object, set_current_filter (impl, g_value_get_object (value)); break; - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: - set_preview_widget (impl, g_value_get_object (value)); - break; - - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: - priv->preview_widget_active = g_value_get_boolean (value); - update_preview_widget_visibility (impl); - break; - - case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: - priv->use_preview_label = g_value_get_boolean (value); - update_preview_widget_visibility (impl); - break; - case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: { gboolean select_multiple = g_value_get_boolean (value); @@ -3315,18 +3228,6 @@ gtk_file_chooser_widget_get_property (GObject *object, g_value_set_object (value, priv->current_filter); break; - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: - g_value_set_object (value, priv->preview_widget); - break; - - case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: - g_value_set_boolean (value, priv->preview_widget_active); - break; - - case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: - g_value_set_boolean (value, priv->use_preview_label); - break; - case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: g_value_set_boolean (value, priv->select_multiple); break; @@ -5384,8 +5285,6 @@ update_current_folder_get_info_cb (GCancellable *cancellable, g_signal_emit_by_name (impl, "current-folder-changed", 0); - check_preview_change (impl); - g_signal_emit_by_name (impl, "selection-changed", 0); out: @@ -5847,18 +5746,6 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser) return g_slist_reverse (info.result); } -GFile * -gtk_file_chooser_widget_get_preview_file (GtkFileChooser *chooser) -{ - GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser); - GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - - if (priv->preview_file) - return g_object_ref (priv->preview_file); - else - return NULL; -} - static GtkFileSystem * gtk_file_chooser_widget_get_file_system (GtkFileChooser *chooser) { @@ -7297,92 +7184,6 @@ filter_combo_changed (GtkComboBox *combo_box, new_filter); } -static void -check_preview_change (GtkFileChooserWidget *impl) -{ - GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - GtkTreePath *path; - GFile *new_file; - char *new_display_name; - GtkTreeModel *model; - GtkTreeSelection *selection; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->browse_files_tree_view)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view)); - if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_SINGLE || - gtk_tree_selection_get_mode (selection) == GTK_SELECTION_BROWSE) - { - GtkTreeIter iter; - - if (gtk_tree_selection_get_selected (selection, NULL, &iter)) - path = gtk_tree_model_get_path (model, &iter); - else - path = NULL; - } - else - { - gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->browse_files_tree_view), &path, NULL); - if (path && !gtk_tree_selection_path_is_selected (selection, path)) - { - gtk_tree_path_free (path); - path = NULL; - } - } - - if (path) - { - GtkTreeIter iter; - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - MODEL_COL_FILE, &new_file, - MODEL_COL_NAME, &new_display_name, - -1); - - gtk_tree_path_free (path); - } - else - { - new_file = NULL; - new_display_name = NULL; - } - - if (new_file != priv->preview_file && - !(new_file && priv->preview_file && - g_file_equal (new_file, priv->preview_file))) - { - if (priv->preview_file) - { - g_object_unref (priv->preview_file); - g_free (priv->preview_display_name); - } - - if (new_file) - { - priv->preview_file = new_file; - priv->preview_display_name = new_display_name; - } - else - { - priv->preview_file = NULL; - priv->preview_display_name = NULL; - g_free (new_display_name); - } - - if (priv->use_preview_label && priv->preview_label) - gtk_label_set_text (GTK_LABEL (priv->preview_label), priv->preview_display_name); - - g_signal_emit_by_name (impl, "update-preview"); - } - else - { - if (new_file) - g_object_unref (new_file); - - g_free (new_display_name); - } -} - static gboolean list_select_func (GtkTreeSelection *selection, GtkTreeModel *model, @@ -7426,18 +7227,9 @@ list_selection_changed (GtkTreeSelection *selection, location_bar_update (impl); - check_preview_change (impl); - g_signal_emit_by_name (impl, "selection-changed", 0); } -static void -list_cursor_changed (GtkTreeView *list, - GtkFileChooserWidget *impl) -{ - check_preview_change (impl); -} - static gboolean browse_files_tree_view_keynav_failed_cb (GtkWidget *widget, GtkDirectionType direction, @@ -8118,7 +7910,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_path_bar); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, filter_combo_hbox); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, filter_combo); - gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, preview_box); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, extra_align); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, extra_and_filters); gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, location_entry_box); @@ -8152,7 +7943,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_bind_template_callback (widget_class, file_list_query_tooltip_cb); gtk_widget_class_bind_template_callback (widget_class, list_row_activated); gtk_widget_class_bind_template_callback (widget_class, list_selection_changed); - gtk_widget_class_bind_template_callback (widget_class, list_cursor_changed); gtk_widget_class_bind_template_callback (widget_class, browse_files_tree_view_keynav_failed_cb); gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed); gtk_widget_class_bind_template_callback (widget_class, path_bar_clicked); @@ -8286,8 +8076,6 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl) access ("MARK: *** CREATE FILE CHOOSER", F_OK); #endif - priv->preview_widget_active = TRUE; - priv->use_preview_label = TRUE; priv->select_multiple = FALSE; priv->show_hidden = FALSE; priv->show_size_column = TRUE; diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui index ac86348d2f..4253c819a3 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -109,7 +109,7 @@ - + 12 1 @@ -158,7 +158,6 @@ - @@ -325,13 +324,6 @@ - - - 0 - vertical - 12 - - diff --git a/tests/testfilechooser.c b/tests/testfilechooser.c index e96058aa4c..32f36eae06 100644 --- a/tests/testfilechooser.c +++ b/tests/testfilechooser.c @@ -258,97 +258,6 @@ my_new_from_file_at_size (const char *filename, return pixbuf; } -#if 0 -static char * -format_time (time_t t) -{ - gchar buf[128]; - struct tm tm_buf; - time_t now = time (NULL); - const char *format; - - if (abs (now - t) < 24*60*60) - format = "%X"; - else - format = "%x"; - - localtime_r (&t, &tm_buf); - if (strftime (buf, sizeof (buf), format, &tm_buf) == 0) - return g_strdup (""); - else - return g_strdup (buf); -} - -static char * -format_size (gint64 size) -{ - if (size < (gint64)1024) - return g_strdup_printf ("%d bytes", (gint)size); - else if (size < (gint64)1024*1024) - return g_strdup_printf ("%.1f K", size / (1024.)); - else if (size < (gint64)1024*1024*1024) - return g_strdup_printf ("%.1f M", size / (1024.*1024.)); - else - return g_strdup_printf ("%.1f G", size / (1024.*1024.*1024.)); -} - -static void -update_preview_cb (GtkFileChooser *chooser) -{ - gchar *filename = gtk_file_chooser_get_preview_filename (chooser); - gboolean have_preview = FALSE; - - if (filename) - { - GdkPixbuf *pixbuf; - GError *error = NULL; - - pixbuf = my_new_from_file_at_size (filename, 128, 128, &error); - if (pixbuf) - { - gtk_image_set_from_pixbuf (GTK_IMAGE (preview_image), pixbuf); - g_object_unref (pixbuf); - gtk_widget_show (preview_image); - gtk_widget_hide (preview_label); - have_preview = TRUE; - } - else - { - struct stat buf; - if (stat (filename, &buf) == 0) - { - gchar *preview_text; - gchar *size_str; - gchar *modified_time; - - size_str = format_size (buf.st_size); - modified_time = format_time (buf.st_mtime); - - preview_text = g_strdup_printf ("Modified:\t%s\n" - "Size:\t%s\n", - modified_time, - size_str); - gtk_label_set_markup (GTK_LABEL (preview_label), preview_text); - g_free (modified_time); - g_free (size_str); - g_free (preview_text); - - gtk_widget_hide (preview_image); - gtk_widget_show (preview_label); - have_preview = TRUE; - } - } - - g_free (filename); - - if (error) - g_error_free (error); - } - - gtk_file_chooser_set_preview_widget_active (chooser, have_preview); -} -#endif - static void set_current_folder (GtkFileChooser *chooser, const char *name) @@ -623,26 +532,6 @@ main (int argc, char **argv) gtk_file_filter_add_pixbuf_formats (filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); -#if 0 - /* Preview widget */ - /* THIS IS A TERRIBLE PREVIEW WIDGET, AND SHOULD NOT BE COPIED AT ALL. - */ - preview_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview_vbox); - - preview_label = gtk_label_new (NULL); - gtk_container_add (GTK_CONTAINER (preview_vbox), preview_label, TRUE, TRUE, 0); - g_object_set (preview_label, "margin", 6, NULL); - - preview_image = gtk_image_new (); - gtk_container_add (GTK_CONTAINER (preview_vbox), preview_image, TRUE, TRUE, 0); - g_object_set (preview_image, "margin", 6, NULL); - - update_preview_cb (GTK_FILE_CHOOSER (dialog)); - g_signal_connect (dialog, "update-preview", - G_CALLBACK (update_preview_cb), NULL); -#endif - /* Choices */ gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (dialog), "choice1", diff --git a/tests/testfilechooserbutton.c b/tests/testfilechooserbutton.c index d226aa0809..7809cd06fc 100644 --- a/tests/testfilechooserbutton.c +++ b/tests/testfilechooserbutton.c @@ -223,24 +223,6 @@ chooser_file_activated_cb (GtkFileChooser *chooser, g_object_unref (filename); } -static void -chooser_update_preview_cb (GtkFileChooser *chooser, - gpointer user_data) -{ - GFile *filename; - - 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), uri); - g_free (uri); - - g_object_unref (filename); - } -} - static void add_new_filechooser_button (const gchar *mnemonic, const gchar *chooser_title, @@ -274,7 +256,6 @@ add_new_filechooser_button (const gchar *mnemonic, G_CALLBACK (chooser_current_folder_changed_cb), NULL); g_signal_connect (chooser, "selection-changed", G_CALLBACK (chooser_selection_changed_cb), NULL); g_signal_connect (chooser, "file-activated", G_CALLBACK (chooser_file_activated_cb), NULL); - g_signal_connect (chooser, "update-preview", G_CALLBACK (chooser_update_preview_cb), NULL); gtk_container_add (GTK_CONTAINER (hbox), chooser); button = gtk_button_new_with_label ("Tests");