1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
3 /* GTK+: gtkfilechooserbutton.c
5 * Copyright (c) 2004 James M. Cape <jcape@ignore-your.tv>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
34 #include "gtkbutton.h"
35 #include "gtkcelllayout.h"
36 #include "gtkcellrenderertext.h"
37 #include "gtkcellrendererpixbuf.h"
38 #include "gtkcombobox.h"
40 #include "gtkicontheme.h"
41 #include "gtkiconfactory.h"
44 #include "gtkliststore.h"
46 #include "gtktreemodelfilter.h"
47 #include "gtkseparator.h"
48 #include "gtkfilechooserdialog.h"
49 #include "gtkfilechooserprivate.h"
50 #include "gtkfilechooserutils.h"
51 #include "gtkmarshalers.h"
53 #include "gtkfilechooserbutton.h"
55 #include "gtkorientable.h"
57 #include "gtktypebuiltins.h"
58 #include "gtkprivate.h"
62 * SECTION:gtkfilechooserbutton
63 * @Short_description: A button to launch a file selection dialog
64 * @Title: GtkFileChooserButton
65 * @See_also:#GtkFileChooserDialog
67 * The #GtkFileChooserButton is a widget that lets the user select a
68 * file. It implements the #GtkFileChooser interface. Visually, it is a
69 * file name with a button to bring up a #GtkFileChooserDialog.
70 * The user can then use that dialog to change the file associated with
71 * that button. This widget does not support setting the
72 * #GtkFileChooser:select-multiple property to %TRUE.
75 * <title>Create a button to let the user select a file in /etc</title>
80 * button = gtk_file_chooser_button_new (_("Select a file"),
81 * GTK_FILE_CHOOSER_ACTION_OPEN);
82 * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button),
88 * The #GtkFileChooserButton supports the #GtkFileChooserAction<!-- -->s
89 * %GTK_FILE_CHOOSER_ACTION_OPEN and %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
92 * The #GtkFileChooserButton will ellipsize the label,
93 * and thus will thus request little horizontal space. To give the button
94 * more space, you should call gtk_widget_get_preferred_size(),
95 * gtk_file_chooser_button_set_width_chars(), or pack the button in
96 * such a way that other interface elements give space to the widget.
101 /* **************** *
103 * **************** */
105 #define DEFAULT_TITLE N_("Select a File")
106 #define DESKTOP_DISPLAY_NAME N_("Desktop")
107 #define FALLBACK_DISPLAY_NAME N_("(None)")
108 #define FALLBACK_ICON_NAME "stock_unknown"
109 #define FALLBACK_ICON_SIZE 16
112 /* ********************** *
113 * Private Enumerations *
114 * ********************** */
134 /* TreeModel Columns */
146 /* TreeModel Row Types */
152 ROW_TYPE_BOOKMARK_SEPARATOR,
154 ROW_TYPE_CURRENT_FOLDER_SEPARATOR,
155 ROW_TYPE_CURRENT_FOLDER,
156 ROW_TYPE_OTHER_SEPARATOR,
159 ROW_TYPE_INVALID = -1
164 /* ******************** *
165 * Private Structures *
166 * ******************** */
168 struct _GtkFileChooserButtonPrivate
174 GtkWidget *combo_box;
175 GtkCellRenderer *icon_cell;
176 GtkCellRenderer *name_cell;
179 GtkTreeModel *filter_model;
184 gulong combo_box_changed_id;
185 gulong dialog_file_activated_id;
186 gulong dialog_folder_changed_id;
187 gulong dialog_selection_changed_id;
188 gulong fs_volumes_changed_id;
189 gulong fs_bookmarks_changed_id;
191 GCancellable *dnd_select_folder_cancellable;
192 GCancellable *update_button_cancellable;
193 GSList *change_icon_theme_cancellables;
201 guint has_bookmark_separator : 1;
202 guint has_current_folder_separator : 1;
203 guint has_current_folder : 1;
204 guint has_other_separator : 1;
206 /* Used for hiding/showing the dialog when the button is hidden */
209 /* Used to track whether we need to set a default current folder on ::map() */
210 guint folder_has_been_set : 1;
212 guint focus_on_click : 1;
227 /* ********************* *
228 * Function Prototypes *
229 * ********************* */
231 /* GtkFileChooserIface Functions */
232 static void gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface);
233 static gboolean gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
236 static gboolean gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
240 /* GObject Functions */
241 static GObject *gtk_file_chooser_button_constructor (GType type,
243 GObjectConstructParam *params);
244 static void gtk_file_chooser_button_set_property (GObject *object,
248 static void gtk_file_chooser_button_get_property (GObject *object,
252 static void gtk_file_chooser_button_finalize (GObject *object);
254 /* GtkWidget Functions */
255 static void gtk_file_chooser_button_destroy (GtkWidget *widget);
256 static void gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
257 GdkDragContext *context,
260 GtkSelectionData *data,
263 static void gtk_file_chooser_button_show_all (GtkWidget *widget);
264 static void gtk_file_chooser_button_show (GtkWidget *widget);
265 static void gtk_file_chooser_button_hide (GtkWidget *widget);
266 static void gtk_file_chooser_button_map (GtkWidget *widget);
267 static gboolean gtk_file_chooser_button_mnemonic_activate (GtkWidget *widget,
268 gboolean group_cycling);
269 static void gtk_file_chooser_button_style_updated (GtkWidget *widget);
270 static void gtk_file_chooser_button_screen_changed (GtkWidget *widget,
271 GdkScreen *old_screen);
273 /* Utility Functions */
274 static GtkIconTheme *get_icon_theme (GtkWidget *widget);
275 static void set_info_for_file_at_iter (GtkFileChooserButton *fs,
279 static gint model_get_type_position (GtkFileChooserButton *button,
281 static void model_free_row_data (GtkFileChooserButton *button,
283 static inline void model_add_special (GtkFileChooserButton *button);
284 static inline void model_add_other (GtkFileChooserButton *button);
285 static void model_add_volumes (GtkFileChooserButton *button,
287 static void model_add_bookmarks (GtkFileChooserButton *button,
289 static void model_update_current_folder (GtkFileChooserButton *button,
291 static void model_remove_rows (GtkFileChooserButton *button,
295 static gboolean filter_model_visible_func (GtkTreeModel *model,
299 static gboolean combo_box_row_separator_func (GtkTreeModel *model,
302 static void name_cell_data_func (GtkCellLayout *layout,
303 GtkCellRenderer *cell,
307 static void open_dialog (GtkFileChooserButton *button);
308 static void update_combo_box (GtkFileChooserButton *button);
309 static void update_label_and_image (GtkFileChooserButton *button);
311 /* Child Object Callbacks */
312 static void fs_volumes_changed_cb (GtkFileSystem *fs,
314 static void fs_bookmarks_changed_cb (GtkFileSystem *fs,
317 static void combo_box_changed_cb (GtkComboBox *combo_box,
320 static void button_clicked_cb (GtkButton *real_button,
323 static void dialog_update_preview_cb (GtkFileChooser *dialog,
325 static void dialog_selection_changed_cb (GtkFileChooser *dialog,
327 static void dialog_file_activated_cb (GtkFileChooser *dialog,
329 static void dialog_current_folder_changed_cb (GtkFileChooser *dialog,
331 static void dialog_notify_cb (GObject *dialog,
334 static gboolean dialog_delete_event_cb (GtkWidget *dialog,
337 static void dialog_response_cb (GtkDialog *dialog,
341 static guint file_chooser_button_signals[LAST_SIGNAL] = { 0 };
343 /* ******************* *
344 * GType Declaration *
345 * ******************* */
347 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserButton, gtk_file_chooser_button, GTK_TYPE_BOX, { \
348 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER, gtk_file_chooser_button_file_chooser_iface_init) \
352 /* ***************** *
354 * ***************** */
357 gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
359 GObjectClass *gobject_class;
360 GtkWidgetClass *widget_class;
362 gobject_class = G_OBJECT_CLASS (class);
363 widget_class = GTK_WIDGET_CLASS (class);
365 gobject_class->constructor = gtk_file_chooser_button_constructor;
366 gobject_class->set_property = gtk_file_chooser_button_set_property;
367 gobject_class->get_property = gtk_file_chooser_button_get_property;
368 gobject_class->finalize = gtk_file_chooser_button_finalize;
370 widget_class->destroy = gtk_file_chooser_button_destroy;
371 widget_class->drag_data_received = gtk_file_chooser_button_drag_data_received;
372 widget_class->show_all = gtk_file_chooser_button_show_all;
373 widget_class->show = gtk_file_chooser_button_show;
374 widget_class->hide = gtk_file_chooser_button_hide;
375 widget_class->map = gtk_file_chooser_button_map;
376 widget_class->style_updated = gtk_file_chooser_button_style_updated;
377 widget_class->screen_changed = gtk_file_chooser_button_screen_changed;
378 widget_class->mnemonic_activate = gtk_file_chooser_button_mnemonic_activate;
381 * GtkFileChooserButton::file-set:
382 * @widget: the object which received the signal.
384 * The ::file-set signal is emitted when the user selects a file.
386 * Note that this signal is only emitted when the <emphasis>user</emphasis>
391 file_chooser_button_signals[FILE_SET] =
392 g_signal_new (I_("file-set"),
393 G_TYPE_FROM_CLASS (gobject_class),
395 G_STRUCT_OFFSET (GtkFileChooserButtonClass, file_set),
397 _gtk_marshal_VOID__VOID,
401 * GtkFileChooserButton:dialog:
403 * Instance of the #GtkFileChooserDialog associated with the button.
407 g_object_class_install_property (gobject_class, PROP_DIALOG,
408 g_param_spec_object ("dialog",
410 P_("The file chooser dialog to use."),
411 GTK_TYPE_FILE_CHOOSER,
412 (GTK_PARAM_WRITABLE |
413 G_PARAM_CONSTRUCT_ONLY)));
416 * GtkFileChooserButton:focus-on-click:
418 * Whether the #GtkFileChooserButton button grabs focus when it is clicked
423 g_object_class_install_property (gobject_class,
425 g_param_spec_boolean ("focus-on-click",
426 P_("Focus on click"),
427 P_("Whether the button grabs focus when it is clicked with the mouse"),
429 GTK_PARAM_READWRITE));
432 * GtkFileChooserButton:title:
434 * Title to put on the #GtkFileChooserDialog associated with the button.
438 g_object_class_install_property (gobject_class, PROP_TITLE,
439 g_param_spec_string ("title",
441 P_("The title of the file chooser dialog."),
443 GTK_PARAM_READWRITE));
446 * GtkFileChooserButton:width-chars:
448 * The width of the entry and label inside the button, in characters.
452 g_object_class_install_property (gobject_class, PROP_WIDTH_CHARS,
453 g_param_spec_int ("width-chars",
454 P_("Width In Characters"),
455 P_("The desired width of the button widget, in characters."),
457 GTK_PARAM_READWRITE));
459 _gtk_file_chooser_install_properties (gobject_class);
461 g_type_class_add_private (class, sizeof (GtkFileChooserButtonPrivate));
465 gtk_file_chooser_button_init (GtkFileChooserButton *button)
467 GtkFileChooserButtonPrivate *priv;
468 GtkWidget *box, *image, *sep;
469 GtkTargetList *target_list;
471 priv = button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
472 GTK_TYPE_FILE_CHOOSER_BUTTON,
473 GtkFileChooserButtonPrivate);
475 priv->icon_size = FALLBACK_ICON_SIZE;
476 priv->focus_on_click = TRUE;
478 gtk_widget_push_composite_child ();
481 priv->button = gtk_button_new ();
482 g_signal_connect (priv->button, "clicked",
483 G_CALLBACK (button_clicked_cb), button);
484 gtk_box_pack_start (GTK_BOX (button), priv->button, TRUE, TRUE, 0);
485 gtk_widget_set_halign (priv->button, GTK_ALIGN_FILL);
486 gtk_widget_show (priv->button);
488 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
489 gtk_container_add (GTK_CONTAINER (priv->button), box);
490 gtk_widget_show (box);
492 priv->image = gtk_image_new ();
493 gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
494 gtk_widget_show (priv->image);
496 priv->label = gtk_label_new (_(FALLBACK_DISPLAY_NAME));
497 gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
498 gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
499 gtk_widget_set_valign (priv->label, GTK_ALIGN_CENTER);
500 gtk_box_pack_start (GTK_BOX (box), priv->label, TRUE, TRUE, 0);
501 //gtk_container_add (GTK_CONTAINER (box), priv->label);
502 gtk_widget_show (priv->label);
504 sep = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
505 gtk_box_pack_start (GTK_BOX (box), sep, FALSE, FALSE, 0);
506 gtk_widget_show (sep);
508 image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
509 gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
510 gtk_widget_show (image);
513 /* Keep in sync with columns enum, line 88 */
515 GTK_TREE_MODEL (gtk_list_store_new (NUM_COLUMNS,
516 GDK_TYPE_PIXBUF, /* Icon */
517 G_TYPE_STRING, /* Display Name */
518 G_TYPE_CHAR, /* Row Type */
519 G_TYPE_POINTER /* Volume || Path */,
520 G_TYPE_BOOLEAN /* Is Folder? */,
521 G_TYPE_POINTER /* cancellable */));
523 priv->combo_box = gtk_combo_box_new ();
524 priv->combo_box_changed_id =
525 g_signal_connect (priv->combo_box, "changed",
526 G_CALLBACK (combo_box_changed_cb), button);
527 gtk_box_pack_start (GTK_BOX (button), priv->combo_box, TRUE, TRUE, 0);
528 gtk_widget_set_halign (priv->combo_box, GTK_ALIGN_FILL);
530 priv->icon_cell = gtk_cell_renderer_pixbuf_new ();
531 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box),
532 priv->icon_cell, FALSE);
533 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->combo_box),
534 priv->icon_cell, "pixbuf", ICON_COLUMN);
536 priv->name_cell = gtk_cell_renderer_text_new ();
537 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_box),
538 priv->name_cell, TRUE);
539 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->combo_box),
540 priv->name_cell, "text", DISPLAY_NAME_COLUMN);
541 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->combo_box),
542 priv->name_cell, name_cell_data_func,
545 gtk_widget_pop_composite_child ();
548 gtk_drag_dest_set (GTK_WIDGET (button),
549 (GTK_DEST_DEFAULT_ALL),
552 target_list = gtk_target_list_new (NULL, 0);
553 gtk_target_list_add_uri_targets (target_list, TEXT_URI_LIST);
554 gtk_target_list_add_text_targets (target_list, TEXT_PLAIN);
555 gtk_drag_dest_set_target_list (GTK_WIDGET (button), target_list);
556 gtk_target_list_unref (target_list);
560 /* ******************************* *
561 * GtkFileChooserIface Functions *
562 * ******************************* */
564 gtk_file_chooser_button_file_chooser_iface_init (GtkFileChooserIface *iface)
566 _gtk_file_chooser_delegate_iface_init (iface);
568 iface->add_shortcut_folder = gtk_file_chooser_button_add_shortcut_folder;
569 iface->remove_shortcut_folder = gtk_file_chooser_button_remove_shortcut_folder;
573 gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
577 GtkFileChooser *delegate;
580 delegate = g_object_get_qdata (G_OBJECT (chooser),
581 GTK_FILE_CHOOSER_DELEGATE_QUARK);
582 retval = _gtk_file_chooser_add_shortcut_folder (delegate, file, error);
586 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
587 GtkFileChooserButtonPrivate *priv = button->priv;
591 pos = model_get_type_position (button, ROW_TYPE_SHORTCUT);
592 pos += priv->n_shortcuts;
594 gtk_list_store_insert (GTK_LIST_STORE (priv->model), &iter, pos);
595 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
597 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
598 TYPE_COLUMN, ROW_TYPE_SHORTCUT,
599 DATA_COLUMN, g_object_ref (file),
600 IS_FOLDER_COLUMN, FALSE,
602 set_info_for_file_at_iter (button, file, &iter);
605 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
612 gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
616 GtkFileChooser *delegate;
619 delegate = g_object_get_qdata (G_OBJECT (chooser),
620 GTK_FILE_CHOOSER_DELEGATE_QUARK);
622 retval = _gtk_file_chooser_remove_shortcut_folder (delegate, file, error);
626 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
627 GtkFileChooserButtonPrivate *priv = button->priv;
632 pos = model_get_type_position (button, ROW_TYPE_SHORTCUT);
633 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
639 gtk_tree_model_get (priv->model, &iter,
644 if (type == ROW_TYPE_SHORTCUT &&
645 data && g_file_equal (data, file))
647 model_free_row_data (GTK_FILE_CHOOSER_BUTTON (chooser), &iter);
648 gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter);
650 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
651 update_combo_box (GTK_FILE_CHOOSER_BUTTON (chooser));
655 while (type == ROW_TYPE_SHORTCUT &&
656 gtk_tree_model_iter_next (priv->model, &iter));
663 /* ******************* *
664 * GObject Functions *
665 * ******************* */
668 gtk_file_chooser_button_constructor (GType type,
670 GObjectConstructParam *params)
673 GtkFileChooserButton *button;
674 GtkFileChooserButtonPrivate *priv;
676 char *current_folder;
678 object = G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->constructor (type,
681 button = GTK_FILE_CHOOSER_BUTTON (object);
686 priv->dialog = gtk_file_chooser_dialog_new (NULL, NULL,
687 GTK_FILE_CHOOSER_ACTION_OPEN,
694 gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog),
695 GTK_RESPONSE_ACCEPT);
696 gtk_dialog_set_alternative_button_order (GTK_DIALOG (priv->dialog),
701 gtk_file_chooser_button_set_title (button, _(DEFAULT_TITLE));
703 else if (!gtk_window_get_title (GTK_WINDOW (priv->dialog)))
705 gtk_file_chooser_button_set_title (button, _(DEFAULT_TITLE));
708 current_folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (priv->dialog));
709 if (current_folder != NULL)
711 priv->folder_has_been_set = TRUE;
712 g_free (current_folder);
715 g_signal_connect (priv->dialog, "delete-event",
716 G_CALLBACK (dialog_delete_event_cb), object);
717 g_signal_connect (priv->dialog, "response",
718 G_CALLBACK (dialog_response_cb), object);
720 /* This is used, instead of the standard delegate, to ensure that signals are only
721 * delegated when the OK button is pressed. */
722 g_object_set_qdata (object, GTK_FILE_CHOOSER_DELEGATE_QUARK, priv->dialog);
723 priv->dialog_folder_changed_id =
724 g_signal_connect (priv->dialog, "current-folder-changed",
725 G_CALLBACK (dialog_current_folder_changed_cb), object);
726 priv->dialog_file_activated_id =
727 g_signal_connect (priv->dialog, "file-activated",
728 G_CALLBACK (dialog_file_activated_cb), object);
729 priv->dialog_selection_changed_id =
730 g_signal_connect (priv->dialog, "selection-changed",
731 G_CALLBACK (dialog_selection_changed_cb), object);
732 g_signal_connect (priv->dialog, "update-preview",
733 G_CALLBACK (dialog_update_preview_cb), object);
734 g_signal_connect (priv->dialog, "notify",
735 G_CALLBACK (dialog_notify_cb), object);
736 g_object_add_weak_pointer (G_OBJECT (priv->dialog),
737 (gpointer) (&priv->dialog));
740 g_object_ref (_gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (priv->dialog)));
742 model_add_special (button);
744 list = _gtk_file_system_list_volumes (priv->fs);
745 model_add_volumes (button, list);
748 list = _gtk_file_system_list_bookmarks (priv->fs);
749 model_add_bookmarks (button, list);
750 g_slist_foreach (list, (GFunc) g_object_unref, NULL);
753 model_add_other (button);
755 priv->filter_model = gtk_tree_model_filter_new (priv->model, NULL);
756 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter_model),
757 filter_model_visible_func,
760 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo_box), priv->filter_model);
761 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (priv->combo_box),
762 combo_box_row_separator_func,
765 /* set up the action for a user-provided dialog, this also updates
766 * the label, image and combobox
768 g_object_set (object,
769 "action", gtk_file_chooser_get_action (GTK_FILE_CHOOSER (priv->dialog)),
772 priv->fs_volumes_changed_id =
773 g_signal_connect (priv->fs, "volumes-changed",
774 G_CALLBACK (fs_volumes_changed_cb), object);
775 priv->fs_bookmarks_changed_id =
776 g_signal_connect (priv->fs, "bookmarks-changed",
777 G_CALLBACK (fs_bookmarks_changed_cb), object);
783 gtk_file_chooser_button_set_property (GObject *object,
788 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
789 GtkFileChooserButtonPrivate *priv = button->priv;
795 priv->dialog = g_value_get_object (value);
797 case PROP_FOCUS_ON_CLICK:
798 gtk_file_chooser_button_set_focus_on_click (button, g_value_get_boolean (value));
800 case PROP_WIDTH_CHARS:
801 gtk_file_chooser_button_set_width_chars (GTK_FILE_CHOOSER_BUTTON (object),
802 g_value_get_int (value));
804 case GTK_FILE_CHOOSER_PROP_ACTION:
805 switch (g_value_get_enum (value))
807 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
808 case GTK_FILE_CHOOSER_ACTION_SAVE:
813 eclass = g_type_class_peek (GTK_TYPE_FILE_CHOOSER_ACTION);
814 eval = g_enum_get_value (eclass, g_value_get_enum (value));
815 g_warning ("%s: Choosers of type `%s' do not support `%s'.",
816 G_STRFUNC, G_OBJECT_TYPE_NAME (object), eval->value_name);
818 g_value_set_enum ((GValue *) value, GTK_FILE_CHOOSER_ACTION_OPEN);
823 g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
824 update_label_and_image (GTK_FILE_CHOOSER_BUTTON (object));
825 update_combo_box (GTK_FILE_CHOOSER_BUTTON (object));
827 switch (g_value_get_enum (value))
829 case GTK_FILE_CHOOSER_ACTION_OPEN:
830 gtk_widget_hide (priv->combo_box);
831 gtk_widget_show (priv->button);
833 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
834 gtk_widget_hide (priv->button);
835 gtk_widget_show (priv->combo_box);
838 g_assert_not_reached ();
844 case GTK_FILE_CHOOSER_PROP_FILTER:
845 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
846 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
847 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
848 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
849 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
850 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
851 case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
852 g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
855 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
856 g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
857 fs_volumes_changed_cb (priv->fs, button);
858 fs_bookmarks_changed_cb (priv->fs, button);
861 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
862 g_warning ("%s: Choosers of type `%s` do not support selecting multiple files.",
863 G_STRFUNC, G_OBJECT_TYPE_NAME (object));
866 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
872 gtk_file_chooser_button_get_property (GObject *object,
877 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
878 GtkFileChooserButtonPrivate *priv = button->priv;
882 case PROP_WIDTH_CHARS:
883 g_value_set_int (value,
884 gtk_label_get_width_chars (GTK_LABEL (priv->label)));
886 case PROP_FOCUS_ON_CLICK:
887 g_value_set_boolean (value,
888 gtk_file_chooser_button_get_focus_on_click (button));
892 case GTK_FILE_CHOOSER_PROP_ACTION:
893 case GTK_FILE_CHOOSER_PROP_FILTER:
894 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
895 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
896 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
897 case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
898 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
899 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
900 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
901 case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
902 case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
903 g_object_get_property (G_OBJECT (priv->dialog), pspec->name, value);
907 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
913 gtk_file_chooser_button_finalize (GObject *object)
915 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (object);
916 GtkFileChooserButtonPrivate *priv = button->priv;
919 g_object_unref (priv->old_file);
921 G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->finalize (object);
924 /* ********************* *
925 * GtkWidget Functions *
926 * ********************* */
929 gtk_file_chooser_button_destroy (GtkWidget *widget)
931 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
932 GtkFileChooserButtonPrivate *priv = button->priv;
936 if (priv->dialog != NULL)
938 gtk_widget_destroy (priv->dialog);
942 if (priv->model && gtk_tree_model_get_iter_first (priv->model, &iter)) do
944 model_free_row_data (button, &iter);
946 while (gtk_tree_model_iter_next (priv->model, &iter));
948 if (priv->dnd_select_folder_cancellable)
950 g_cancellable_cancel (priv->dnd_select_folder_cancellable);
951 priv->dnd_select_folder_cancellable = NULL;
954 if (priv->update_button_cancellable)
956 g_cancellable_cancel (priv->update_button_cancellable);
957 priv->update_button_cancellable = NULL;
960 if (priv->change_icon_theme_cancellables)
962 for (l = priv->change_icon_theme_cancellables; l; l = l->next)
964 GCancellable *cancellable = G_CANCELLABLE (l->data);
965 g_cancellable_cancel (cancellable);
967 g_slist_free (priv->change_icon_theme_cancellables);
968 priv->change_icon_theme_cancellables = NULL;
973 g_object_unref (priv->model);
977 if (priv->filter_model)
979 g_object_unref (priv->filter_model);
980 priv->filter_model = NULL;
985 g_signal_handler_disconnect (priv->fs, priv->fs_volumes_changed_id);
986 g_signal_handler_disconnect (priv->fs, priv->fs_bookmarks_changed_id);
987 g_object_unref (priv->fs);
991 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->destroy (widget);
994 struct DndSelectFolderData
996 GtkFileSystem *file_system;
997 GtkFileChooserButton *button;
998 GtkFileChooserAction action;
1006 dnd_select_folder_get_info_cb (GCancellable *cancellable,
1008 const GError *error,
1011 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1012 struct DndSelectFolderData *data = user_data;
1014 if (cancellable != data->button->priv->dnd_select_folder_cancellable)
1016 g_object_unref (data->button);
1017 g_object_unref (data->file);
1018 g_strfreev (data->uris);
1021 g_object_unref (cancellable);
1025 data->button->priv->dnd_select_folder_cancellable = NULL;
1027 if (!cancelled && !error && info != NULL)
1031 is_folder = _gtk_file_info_consider_as_directory (info);
1034 (((data->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER && is_folder) ||
1035 (data->action == GTK_FILE_CHOOSER_ACTION_OPEN && !is_folder)) &&
1036 gtk_file_chooser_select_file (GTK_FILE_CHOOSER (data->button->priv->dialog),
1040 data->selected = FALSE;
1042 if (data->selected || data->uris[++data->i] == NULL)
1044 g_signal_emit (data->button, file_chooser_button_signals[FILE_SET], 0);
1046 g_object_unref (data->button);
1047 g_object_unref (data->file);
1048 g_strfreev (data->uris);
1051 g_object_unref (cancellable);
1056 g_object_unref (data->file);
1058 data->file = g_file_new_for_uri (data->uris[data->i]);
1060 data->button->priv->dnd_select_folder_cancellable =
1061 _gtk_file_system_get_info (data->file_system, data->file,
1063 dnd_select_folder_get_info_cb, user_data);
1065 g_object_unref (cancellable);
1069 gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
1070 GdkDragContext *context,
1073 GtkSelectionData *data,
1077 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1078 GtkFileChooserButtonPrivate *priv = button->priv;
1082 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received != NULL)
1083 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received (widget,
1089 if (widget == NULL || context == NULL || data == NULL || gtk_selection_data_get_length (data) < 0)
1097 struct DndSelectFolderData *info;
1099 uris = gtk_selection_data_get_uris (data);
1104 info = g_new0 (struct DndSelectFolderData, 1);
1105 info->button = g_object_ref (button);
1108 info->selected = FALSE;
1109 info->file_system = priv->fs;
1110 g_object_get (priv->dialog, "action", &info->action, NULL);
1112 info->file = g_file_new_for_uri (info->uris[info->i]);
1114 if (priv->dnd_select_folder_cancellable)
1115 g_cancellable_cancel (priv->dnd_select_folder_cancellable);
1117 priv->dnd_select_folder_cancellable =
1118 _gtk_file_system_get_info (priv->fs, info->file,
1120 dnd_select_folder_get_info_cb, info);
1125 text = (char*) gtk_selection_data_get_text (data);
1126 file = g_file_new_for_uri (text);
1127 gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), file,
1129 g_object_unref (file);
1131 g_signal_emit (button, file_chooser_button_signals[FILE_SET], 0);
1138 gtk_drag_finish (context, TRUE, FALSE, drag_time);
1142 gtk_file_chooser_button_show_all (GtkWidget *widget)
1144 gtk_widget_show (widget);
1148 gtk_file_chooser_button_show (GtkWidget *widget)
1150 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1151 GtkFileChooserButtonPrivate *priv = button->priv;
1153 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->show)
1154 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->show (widget);
1157 open_dialog (GTK_FILE_CHOOSER_BUTTON (widget));
1161 gtk_file_chooser_button_hide (GtkWidget *widget)
1163 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1164 GtkFileChooserButtonPrivate *priv = button->priv;
1166 gtk_widget_hide (priv->dialog);
1168 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->hide)
1169 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->hide (widget);
1173 gtk_file_chooser_button_map (GtkWidget *widget)
1175 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1176 GtkFileChooserButtonPrivate *priv = button->priv;
1178 if (!priv->folder_has_been_set)
1180 char *current_working_dir;
1182 current_working_dir = g_get_current_dir ();
1183 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (widget), current_working_dir);
1184 g_free (current_working_dir);
1186 priv->folder_has_been_set = TRUE;
1189 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->map (widget);
1193 gtk_file_chooser_button_mnemonic_activate (GtkWidget *widget,
1194 gboolean group_cycling)
1196 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
1197 GtkFileChooserButtonPrivate *priv = button->priv;
1199 switch (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (priv->dialog)))
1201 case GTK_FILE_CHOOSER_ACTION_OPEN:
1202 gtk_widget_grab_focus (priv->button);
1204 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
1205 return gtk_widget_mnemonic_activate (priv->combo_box, group_cycling);
1208 g_assert_not_reached ();
1215 /* Changes the icons wherever it is needed */
1216 struct ChangeIconThemeData
1218 GtkFileChooserButton *button;
1219 GtkTreeRowReference *row_ref;
1223 change_icon_theme_get_info_cb (GCancellable *cancellable,
1225 const GError *error,
1228 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1230 struct ChangeIconThemeData *data = user_data;
1232 if (!g_slist_find (data->button->priv->change_icon_theme_cancellables, cancellable))
1235 data->button->priv->change_icon_theme_cancellables =
1236 g_slist_remove (data->button->priv->change_icon_theme_cancellables, cancellable);
1238 if (cancelled || error)
1241 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
1249 width = MAX (width, gdk_pixbuf_get_width (pixbuf));
1251 path = gtk_tree_row_reference_get_path (data->row_ref);
1254 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1255 gtk_tree_path_free (path);
1257 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1258 ICON_COLUMN, pixbuf,
1261 g_object_set (data->button->priv->icon_cell,
1265 g_object_unref (pixbuf);
1269 g_object_unref (data->button);
1270 gtk_tree_row_reference_free (data->row_ref);
1273 g_object_unref (cancellable);
1277 change_icon_theme (GtkFileChooserButton *button)
1279 GtkFileChooserButtonPrivate *priv = button->priv;
1280 GtkSettings *settings;
1281 GtkIconTheme *theme;
1284 gint width = 0, height = 0;
1286 for (l = button->priv->change_icon_theme_cancellables; l; l = l->next)
1288 GCancellable *cancellable = G_CANCELLABLE (l->data);
1289 g_cancellable_cancel (cancellable);
1291 g_slist_free (button->priv->change_icon_theme_cancellables);
1292 button->priv->change_icon_theme_cancellables = NULL;
1294 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
1296 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
1298 priv->icon_size = MAX (width, height);
1300 priv->icon_size = FALLBACK_ICON_SIZE;
1302 update_label_and_image (button);
1304 gtk_tree_model_get_iter_first (priv->model, &iter);
1306 theme = get_icon_theme (GTK_WIDGET (button));
1314 type = ROW_TYPE_INVALID;
1315 gtk_tree_model_get (priv->model, &iter,
1322 case ROW_TYPE_SPECIAL:
1323 case ROW_TYPE_SHORTCUT:
1324 case ROW_TYPE_BOOKMARK:
1325 case ROW_TYPE_CURRENT_FOLDER:
1328 if (g_file_is_native (G_FILE (data)))
1331 GCancellable *cancellable;
1332 struct ChangeIconThemeData *info;
1334 info = g_new0 (struct ChangeIconThemeData, 1);
1335 info->button = g_object_ref (button);
1336 path = gtk_tree_model_get_path (priv->model, &iter);
1337 info->row_ref = gtk_tree_row_reference_new (priv->model, path);
1338 gtk_tree_path_free (path);
1341 _gtk_file_system_get_info (priv->fs, data,
1343 change_icon_theme_get_info_cb,
1345 button->priv->change_icon_theme_cancellables =
1346 g_slist_append (button->priv->change_icon_theme_cancellables, cancellable);
1350 /* Don't call get_info for remote paths to avoid latency and
1352 * If we switch to a better bookmarks file format (XBEL), we
1353 * should use mime info to get a better icon.
1355 pixbuf = gtk_icon_theme_load_icon (theme, "folder-remote",
1356 priv->icon_size, 0, NULL);
1359 pixbuf = gtk_icon_theme_load_icon (theme, FALLBACK_ICON_NAME,
1360 priv->icon_size, 0, NULL);
1362 case ROW_TYPE_VOLUME:
1364 pixbuf = _gtk_file_system_volume_render_icon (data,
1365 GTK_WIDGET (button),
1369 pixbuf = gtk_icon_theme_load_icon (theme, FALLBACK_ICON_NAME,
1370 priv->icon_size, 0, NULL);
1378 width = MAX (width, gdk_pixbuf_get_width (pixbuf));
1380 gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter,
1381 ICON_COLUMN, pixbuf,
1385 g_object_unref (pixbuf);
1387 while (gtk_tree_model_iter_next (priv->model, &iter));
1389 g_object_set (button->priv->icon_cell,
1395 gtk_file_chooser_button_style_updated (GtkWidget *widget)
1397 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->style_updated (widget);
1399 if (gtk_widget_has_screen (widget))
1400 change_icon_theme (GTK_FILE_CHOOSER_BUTTON (widget));
1404 gtk_file_chooser_button_screen_changed (GtkWidget *widget,
1405 GdkScreen *old_screen)
1407 if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->screen_changed)
1408 GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->screen_changed (widget,
1411 change_icon_theme (GTK_FILE_CHOOSER_BUTTON (widget));
1415 /* ******************* *
1416 * Utility Functions *
1417 * ******************* */
1420 static GtkIconTheme *
1421 get_icon_theme (GtkWidget *widget)
1423 if (gtk_widget_has_screen (widget))
1424 return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1426 return gtk_icon_theme_get_default ();
1430 struct SetDisplayNameData
1432 GtkFileChooserButton *button;
1434 GtkTreeRowReference *row_ref;
1438 set_info_get_info_cb (GCancellable *cancellable,
1440 const GError *error,
1441 gpointer callback_data)
1443 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1447 GCancellable *model_cancellable = NULL;
1448 struct SetDisplayNameData *data = callback_data;
1451 if (!data->button->priv->model)
1452 /* button got destroyed */
1455 path = gtk_tree_row_reference_get_path (data->row_ref);
1457 /* Cancellable doesn't exist anymore in the model */
1460 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1461 gtk_tree_path_free (path);
1463 /* Validate the cancellable */
1464 gtk_tree_model_get (data->button->priv->model, &iter,
1465 CANCELLABLE_COLUMN, &model_cancellable,
1467 if (cancellable != model_cancellable)
1470 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1471 CANCELLABLE_COLUMN, NULL,
1474 if (cancelled || error)
1475 /* There was an error, leave the fallback name in there */
1478 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
1481 data->label = g_strdup (g_file_info_get_display_name (info));
1483 is_folder = _gtk_file_info_consider_as_directory (info);
1485 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1486 ICON_COLUMN, pixbuf,
1487 DISPLAY_NAME_COLUMN, data->label,
1488 IS_FOLDER_COLUMN, is_folder,
1492 g_object_unref (pixbuf);
1495 g_object_unref (data->button);
1496 g_free (data->label);
1497 gtk_tree_row_reference_free (data->row_ref);
1500 if (model_cancellable)
1501 g_object_unref (model_cancellable);
1505 set_info_for_file_at_iter (GtkFileChooserButton *button,
1509 struct SetDisplayNameData *data;
1510 GtkTreePath *tree_path;
1511 GCancellable *cancellable;
1513 data = g_new0 (struct SetDisplayNameData, 1);
1514 data->button = g_object_ref (button);
1515 data->label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
1517 tree_path = gtk_tree_model_get_path (button->priv->model, iter);
1518 data->row_ref = gtk_tree_row_reference_new (button->priv->model, tree_path);
1519 gtk_tree_path_free (tree_path);
1521 cancellable = _gtk_file_system_get_info (button->priv->fs, file,
1522 "standard::type,standard::icon,standard::display-name",
1523 set_info_get_info_cb, data);
1525 gtk_list_store_set (GTK_LIST_STORE (button->priv->model), iter,
1526 CANCELLABLE_COLUMN, cancellable,
1530 /* Shortcuts Model */
1532 model_get_type_position (GtkFileChooserButton *button,
1537 if (row_type == ROW_TYPE_SPECIAL)
1540 retval += button->priv->n_special;
1542 if (row_type == ROW_TYPE_VOLUME)
1545 retval += button->priv->n_volumes;
1547 if (row_type == ROW_TYPE_SHORTCUT)
1550 retval += button->priv->n_shortcuts;
1552 if (row_type == ROW_TYPE_BOOKMARK_SEPARATOR)
1555 retval += button->priv->has_bookmark_separator;
1557 if (row_type == ROW_TYPE_BOOKMARK)
1560 retval += button->priv->n_bookmarks;
1562 if (row_type == ROW_TYPE_CURRENT_FOLDER_SEPARATOR)
1565 retval += button->priv->has_current_folder_separator;
1567 if (row_type == ROW_TYPE_CURRENT_FOLDER)
1570 retval += button->priv->has_current_folder;
1572 if (row_type == ROW_TYPE_OTHER_SEPARATOR)
1575 retval += button->priv->has_other_separator;
1577 if (row_type == ROW_TYPE_OTHER)
1580 g_assert_not_reached ();
1585 model_free_row_data (GtkFileChooserButton *button,
1590 GCancellable *cancellable;
1592 gtk_tree_model_get (button->priv->model, iter,
1595 CANCELLABLE_COLUMN, &cancellable,
1600 g_cancellable_cancel (cancellable);
1601 g_object_unref (cancellable);
1606 case ROW_TYPE_SPECIAL:
1607 case ROW_TYPE_SHORTCUT:
1608 case ROW_TYPE_BOOKMARK:
1609 case ROW_TYPE_CURRENT_FOLDER:
1610 g_object_unref (data);
1612 case ROW_TYPE_VOLUME:
1613 _gtk_file_system_volume_unref (data);
1621 model_add_special_get_info_cb (GCancellable *cancellable,
1623 const GError *error,
1626 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1630 GCancellable *model_cancellable = NULL;
1631 struct ChangeIconThemeData *data = user_data;
1634 if (!data->button->priv->model)
1635 /* button got destroyed */
1638 path = gtk_tree_row_reference_get_path (data->row_ref);
1640 /* Cancellable doesn't exist anymore in the model */
1643 gtk_tree_model_get_iter (data->button->priv->model, &iter, path);
1644 gtk_tree_path_free (path);
1646 gtk_tree_model_get (data->button->priv->model, &iter,
1647 CANCELLABLE_COLUMN, &model_cancellable,
1649 if (cancellable != model_cancellable)
1652 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1653 CANCELLABLE_COLUMN, NULL,
1656 if (cancelled || error)
1659 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
1663 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1664 ICON_COLUMN, pixbuf,
1666 g_object_unref (pixbuf);
1669 gtk_tree_model_get (data->button->priv->model, &iter,
1670 DISPLAY_NAME_COLUMN, &name,
1673 gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
1674 DISPLAY_NAME_COLUMN, g_file_info_get_display_name (info),
1679 g_object_unref (data->button);
1680 gtk_tree_row_reference_free (data->row_ref);
1683 if (model_cancellable)
1684 g_object_unref (model_cancellable);
1688 model_add_special (GtkFileChooserButton *button)
1690 const gchar *homedir;
1691 const gchar *desktopdir;
1692 GtkListStore *store;
1697 store = GTK_LIST_STORE (button->priv->model);
1698 pos = model_get_type_position (button, ROW_TYPE_SPECIAL);
1700 homedir = g_get_home_dir ();
1704 GtkTreePath *tree_path;
1705 GCancellable *cancellable;
1706 struct ChangeIconThemeData *info;
1708 file = g_file_new_for_path (homedir);
1709 gtk_list_store_insert (store, &iter, pos);
1712 info = g_new0 (struct ChangeIconThemeData, 1);
1713 info->button = g_object_ref (button);
1714 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
1715 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
1717 gtk_tree_path_free (tree_path);
1719 cancellable = _gtk_file_system_get_info (button->priv->fs, file,
1720 "standard::icon,standard::display-name",
1721 model_add_special_get_info_cb, info);
1723 gtk_list_store_set (store, &iter,
1725 DISPLAY_NAME_COLUMN, NULL,
1726 TYPE_COLUMN, ROW_TYPE_SPECIAL,
1728 IS_FOLDER_COLUMN, TRUE,
1729 CANCELLABLE_COLUMN, cancellable,
1732 button->priv->n_special++;
1735 desktopdir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1737 /* "To disable a directory, point it to the homedir."
1738 * See http://freedesktop.org/wiki/Software/xdg-user-dirs
1740 if (g_strcmp0 (desktopdir, g_get_home_dir ()) != 0)
1742 GtkTreePath *tree_path;
1743 GCancellable *cancellable;
1744 struct ChangeIconThemeData *info;
1746 file = g_file_new_for_path (desktopdir);
1747 gtk_list_store_insert (store, &iter, pos);
1750 info = g_new0 (struct ChangeIconThemeData, 1);
1751 info->button = g_object_ref (button);
1752 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
1753 info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
1755 gtk_tree_path_free (tree_path);
1757 cancellable = _gtk_file_system_get_info (button->priv->fs, file,
1758 "standard::icon,standard::display-name",
1759 model_add_special_get_info_cb, info);
1761 gtk_list_store_set (store, &iter,
1762 TYPE_COLUMN, ROW_TYPE_SPECIAL,
1764 DISPLAY_NAME_COLUMN, _(DESKTOP_DISPLAY_NAME),
1766 IS_FOLDER_COLUMN, TRUE,
1767 CANCELLABLE_COLUMN, cancellable,
1770 button->priv->n_special++;
1775 model_add_volumes (GtkFileChooserButton *button,
1778 GtkListStore *store;
1780 gboolean local_only;
1786 store = GTK_LIST_STORE (button->priv->model);
1787 pos = model_get_type_position (button, ROW_TYPE_VOLUME);
1788 local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (button->priv->dialog));
1790 for (l = volumes; l; l = l->next)
1792 GtkFileSystemVolume *volume;
1795 gchar *display_name;
1801 if (_gtk_file_system_volume_is_mounted (volume))
1805 base_file = _gtk_file_system_volume_get_root (volume);
1806 if (base_file != NULL)
1808 if (!g_file_is_native (base_file))
1810 g_object_unref (base_file);
1814 g_object_unref (base_file);
1819 pixbuf = _gtk_file_system_volume_render_icon (volume,
1820 GTK_WIDGET (button),
1821 button->priv->icon_size,
1823 display_name = _gtk_file_system_volume_get_display_name (volume);
1825 gtk_list_store_insert (store, &iter, pos);
1826 gtk_list_store_set (store, &iter,
1827 ICON_COLUMN, pixbuf,
1828 DISPLAY_NAME_COLUMN, display_name,
1829 TYPE_COLUMN, ROW_TYPE_VOLUME,
1830 DATA_COLUMN, _gtk_file_system_volume_ref (volume),
1831 IS_FOLDER_COLUMN, TRUE,
1835 g_object_unref (pixbuf);
1836 g_free (display_name);
1838 button->priv->n_volumes++;
1843 extern gchar * _gtk_file_chooser_label_for_file (GFile *file);
1846 model_add_bookmarks (GtkFileChooserButton *button,
1849 GtkListStore *store;
1852 gboolean local_only;
1858 store = GTK_LIST_STORE (button->priv->model);
1859 pos = model_get_type_position (button, ROW_TYPE_BOOKMARK);
1860 local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (button->priv->dialog));
1862 for (l = bookmarks; l; l = l->next)
1868 if (g_file_is_native (file))
1870 gtk_list_store_insert (store, &iter, pos);
1871 gtk_list_store_set (store, &iter,
1873 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
1874 TYPE_COLUMN, ROW_TYPE_BOOKMARK,
1875 DATA_COLUMN, g_object_ref (file),
1876 IS_FOLDER_COLUMN, FALSE,
1878 set_info_for_file_at_iter (button, file, &iter);
1883 GtkIconTheme *icon_theme;
1889 /* Don't call get_info for remote paths to avoid latency and
1891 * If we switch to a better bookmarks file format (XBEL), we
1892 * should use mime info to get a better icon.
1894 label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
1896 label = _gtk_file_chooser_label_for_file (file);
1898 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
1899 pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
1900 button->priv->icon_size, 0, NULL);
1902 gtk_list_store_insert (store, &iter, pos);
1903 gtk_list_store_set (store, &iter,
1904 ICON_COLUMN, pixbuf,
1905 DISPLAY_NAME_COLUMN, label,
1906 TYPE_COLUMN, ROW_TYPE_BOOKMARK,
1907 DATA_COLUMN, g_object_ref (file),
1908 IS_FOLDER_COLUMN, TRUE,
1912 g_object_unref (pixbuf);
1915 button->priv->n_bookmarks++;
1919 if (button->priv->n_bookmarks > 0 &&
1920 !button->priv->has_bookmark_separator)
1922 pos = model_get_type_position (button, ROW_TYPE_BOOKMARK_SEPARATOR);
1924 gtk_list_store_insert (store, &iter, pos);
1925 gtk_list_store_set (store, &iter,
1927 DISPLAY_NAME_COLUMN, NULL,
1928 TYPE_COLUMN, ROW_TYPE_BOOKMARK_SEPARATOR,
1930 IS_FOLDER_COLUMN, FALSE,
1932 button->priv->has_bookmark_separator = TRUE;
1937 model_update_current_folder (GtkFileChooserButton *button,
1940 GtkListStore *store;
1947 store = GTK_LIST_STORE (button->priv->model);
1949 if (!button->priv->has_current_folder_separator)
1951 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER_SEPARATOR);
1952 gtk_list_store_insert (store, &iter, pos);
1953 gtk_list_store_set (store, &iter,
1955 DISPLAY_NAME_COLUMN, NULL,
1956 TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER_SEPARATOR,
1958 IS_FOLDER_COLUMN, FALSE,
1960 button->priv->has_current_folder_separator = TRUE;
1963 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER);
1964 if (!button->priv->has_current_folder)
1966 gtk_list_store_insert (store, &iter, pos);
1967 button->priv->has_current_folder = TRUE;
1971 gtk_tree_model_iter_nth_child (button->priv->model, &iter, NULL, pos);
1972 model_free_row_data (button, &iter);
1975 if (g_file_is_native (file))
1977 gtk_list_store_set (store, &iter,
1979 DISPLAY_NAME_COLUMN, _(FALLBACK_DISPLAY_NAME),
1980 TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
1981 DATA_COLUMN, g_object_ref (file),
1982 IS_FOLDER_COLUMN, FALSE,
1984 set_info_for_file_at_iter (button, file, &iter);
1989 GtkIconTheme *icon_theme;
1992 /* Don't call get_info for remote paths to avoid latency and
1994 * If we switch to a better bookmarks file format (XBEL), we
1995 * should use mime info to get a better icon.
1997 label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
1999 label = _gtk_file_chooser_label_for_file (file);
2001 icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
2003 if (g_file_is_native (file))
2004 pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder",
2005 button->priv->icon_size, 0, NULL);
2007 pixbuf = gtk_icon_theme_load_icon (icon_theme, "folder-remote",
2008 button->priv->icon_size, 0, NULL);
2010 gtk_list_store_set (store, &iter,
2011 ICON_COLUMN, pixbuf,
2012 DISPLAY_NAME_COLUMN, label,
2013 TYPE_COLUMN, ROW_TYPE_CURRENT_FOLDER,
2014 DATA_COLUMN, g_object_ref (file),
2015 IS_FOLDER_COLUMN, TRUE,
2019 g_object_unref (pixbuf);
2024 model_add_other (GtkFileChooserButton *button)
2026 GtkListStore *store;
2030 store = GTK_LIST_STORE (button->priv->model);
2031 pos = model_get_type_position (button, ROW_TYPE_OTHER_SEPARATOR);
2033 gtk_list_store_insert (store, &iter, pos);
2034 gtk_list_store_set (store, &iter,
2036 DISPLAY_NAME_COLUMN, NULL,
2037 TYPE_COLUMN, ROW_TYPE_OTHER_SEPARATOR,
2039 IS_FOLDER_COLUMN, FALSE,
2041 button->priv->has_other_separator = TRUE;
2044 gtk_list_store_insert (store, &iter, pos);
2045 gtk_list_store_set (store, &iter,
2047 DISPLAY_NAME_COLUMN, _("Other..."),
2048 TYPE_COLUMN, ROW_TYPE_OTHER,
2050 IS_FOLDER_COLUMN, FALSE,
2055 model_remove_rows (GtkFileChooserButton *button,
2059 GtkListStore *store;
2064 store = GTK_LIST_STORE (button->priv->model);
2070 if (!gtk_tree_model_iter_nth_child (button->priv->model, &iter, NULL, pos))
2071 g_assert_not_reached ();
2073 model_free_row_data (button, &iter);
2074 gtk_list_store_remove (store, &iter);
2081 static inline gboolean
2082 test_if_file_is_visible (GtkFileSystem *fs,
2084 gboolean local_only,
2090 if (local_only && !g_file_is_native (file))
2100 filter_model_visible_func (GtkTreeModel *model,
2104 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2105 GtkFileChooserButtonPrivate *priv = button->priv;
2108 gboolean local_only, retval, is_folder;
2110 type = ROW_TYPE_INVALID;
2112 local_only = gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->dialog));
2114 gtk_tree_model_get (model, iter,
2117 IS_FOLDER_COLUMN, &is_folder,
2122 case ROW_TYPE_CURRENT_FOLDER:
2125 case ROW_TYPE_SPECIAL:
2126 case ROW_TYPE_SHORTCUT:
2127 case ROW_TYPE_BOOKMARK:
2128 retval = test_if_file_is_visible (priv->fs, data, local_only, is_folder);
2130 case ROW_TYPE_VOLUME:
2135 if (_gtk_file_system_volume_is_mounted (data))
2139 base_file = _gtk_file_system_volume_get_root (data);
2143 if (!g_file_is_native (base_file))
2145 g_object_unref (base_file);
2163 name_cell_data_func (GtkCellLayout *layout,
2164 GtkCellRenderer *cell,
2165 GtkTreeModel *model,
2172 gtk_tree_model_get (model, iter,
2176 if (type == ROW_TYPE_CURRENT_FOLDER)
2177 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
2179 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
2183 combo_box_row_separator_func (GtkTreeModel *model,
2187 gchar type = ROW_TYPE_INVALID;
2189 gtk_tree_model_get (model, iter, TYPE_COLUMN, &type, -1);
2191 return (type == ROW_TYPE_BOOKMARK_SEPARATOR ||
2192 type == ROW_TYPE_CURRENT_FOLDER_SEPARATOR ||
2193 type == ROW_TYPE_OTHER_SEPARATOR);
2197 update_combo_box (GtkFileChooserButton *button)
2199 GtkFileChooserButtonPrivate *priv = button->priv;
2204 gtk_tree_model_get_iter_first (priv->filter_model, &iter);
2206 files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
2215 type = ROW_TYPE_INVALID;
2218 gtk_tree_model_get (priv->filter_model, &iter,
2225 case ROW_TYPE_SPECIAL:
2226 case ROW_TYPE_SHORTCUT:
2227 case ROW_TYPE_BOOKMARK:
2228 case ROW_TYPE_CURRENT_FOLDER:
2229 row_found = (files &&
2231 g_file_equal (data, files->data));
2233 case ROW_TYPE_VOLUME:
2237 base_file = _gtk_file_system_volume_get_root (data);
2240 row_found = (files &&
2242 g_file_equal (base_file, files->data));
2243 g_object_unref (base_file);
2254 g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
2255 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box),
2257 g_signal_handler_unblock (priv->combo_box,
2258 priv->combo_box_changed_id);
2261 while (!row_found && gtk_tree_model_iter_next (priv->filter_model, &iter));
2263 /* If it hasn't been found already, update & select the current-folder row. */
2264 if (!row_found && files && files->data)
2266 GtkTreeIter filter_iter;
2269 model_update_current_folder (button, files->data);
2270 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2272 pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER);
2273 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
2275 gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
2276 &filter_iter, &iter);
2278 g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
2279 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box), &filter_iter);
2280 g_signal_handler_unblock (priv->combo_box, priv->combo_box_changed_id);
2283 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
2284 g_slist_free (files);
2289 update_label_get_info_cb (GCancellable *cancellable,
2291 const GError *error,
2294 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
2296 GtkFileChooserButton *button = data;
2297 GtkFileChooserButtonPrivate *priv = button->priv;
2299 if (cancellable != priv->update_button_cancellable)
2302 priv->update_button_cancellable = NULL;
2304 if (cancelled || error)
2307 gtk_label_set_text (GTK_LABEL (priv->label), g_file_info_get_display_name (info));
2309 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size);
2312 pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
2314 priv->icon_size, 0, NULL);
2316 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
2318 g_object_unref (pixbuf);
2321 g_object_unref (button);
2322 g_object_unref (cancellable);
2326 update_label_and_image (GtkFileChooserButton *button)
2328 GtkFileChooserButtonPrivate *priv = button->priv;
2332 files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
2335 if (priv->update_button_cancellable)
2337 g_cancellable_cancel (priv->update_button_cancellable);
2338 priv->update_button_cancellable = NULL;
2341 if (files && files->data)
2344 GtkFileSystemVolume *volume = NULL;
2348 volume = _gtk_file_system_get_volume_for_file (priv->fs, file);
2353 base_file = _gtk_file_system_volume_get_root (volume);
2354 if (base_file && g_file_equal (base_file, file))
2358 label_text = _gtk_file_system_volume_get_display_name (volume);
2359 pixbuf = _gtk_file_system_volume_render_icon (volume,
2360 GTK_WIDGET (button),
2363 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
2365 g_object_unref (pixbuf);
2369 g_object_unref (base_file);
2371 _gtk_file_system_volume_unref (volume);
2377 if (g_file_is_native (file))
2379 priv->update_button_cancellable =
2380 _gtk_file_system_get_info (priv->fs, file,
2381 "standard::icon,standard::display-name",
2382 update_label_get_info_cb,
2383 g_object_ref (button));
2389 label_text = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
2390 pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
2392 priv->icon_size, 0, NULL);
2393 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
2395 g_object_unref (pixbuf);
2399 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
2400 g_slist_free (files);
2404 gtk_label_set_text (GTK_LABEL (priv->label), label_text);
2405 g_free (label_text);
2409 gtk_label_set_text (GTK_LABEL (priv->label), _(FALLBACK_DISPLAY_NAME));
2410 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
2415 /* ************************ *
2416 * Child Object Callbacks *
2417 * ************************ */
2421 fs_volumes_changed_cb (GtkFileSystem *fs,
2424 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2425 GtkFileChooserButtonPrivate *priv = button->priv;
2428 model_remove_rows (user_data,
2429 model_get_type_position (user_data, ROW_TYPE_VOLUME),
2432 priv->n_volumes = 0;
2434 volumes = _gtk_file_system_list_volumes (fs);
2435 model_add_volumes (user_data, volumes);
2436 g_slist_free (volumes);
2438 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2440 update_label_and_image (user_data);
2441 update_combo_box (user_data);
2445 fs_bookmarks_changed_cb (GtkFileSystem *fs,
2448 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2449 GtkFileChooserButtonPrivate *priv = button->priv;
2452 bookmarks = _gtk_file_system_list_bookmarks (fs);
2453 model_remove_rows (user_data,
2454 model_get_type_position (user_data,
2455 ROW_TYPE_BOOKMARK_SEPARATOR),
2456 (priv->n_bookmarks + priv->has_bookmark_separator));
2457 priv->has_bookmark_separator = FALSE;
2458 priv->n_bookmarks = 0;
2459 model_add_bookmarks (user_data, bookmarks);
2460 g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL);
2461 g_slist_free (bookmarks);
2463 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2465 update_label_and_image (user_data);
2466 update_combo_box (user_data);
2471 open_dialog (GtkFileChooserButton *button)
2473 GtkFileChooserButtonPrivate *priv = button->priv;
2475 /* Setup the dialog parent to be chooser button's toplevel, and be modal
2477 if (!gtk_widget_get_visible (priv->dialog))
2479 GtkWidget *toplevel;
2481 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
2483 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
2485 if (GTK_WINDOW (toplevel) != gtk_window_get_transient_for (GTK_WINDOW (priv->dialog)))
2486 gtk_window_set_transient_for (GTK_WINDOW (priv->dialog),
2487 GTK_WINDOW (toplevel));
2489 gtk_window_set_modal (GTK_WINDOW (priv->dialog),
2490 gtk_window_get_modal (GTK_WINDOW (toplevel)));
2498 g_signal_handler_block (priv->dialog,
2499 priv->dialog_folder_changed_id);
2500 g_signal_handler_block (priv->dialog,
2501 priv->dialog_file_activated_id);
2502 g_signal_handler_block (priv->dialog,
2503 priv->dialog_selection_changed_id);
2504 files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
2508 priv->old_file = g_object_ref (files->data);
2510 g_slist_foreach (files, (GFunc) g_object_unref, NULL);
2511 g_slist_free (files);
2514 priv->active = TRUE;
2517 gtk_widget_set_sensitive (priv->combo_box, FALSE);
2518 gtk_window_present (GTK_WINDOW (priv->dialog));
2523 combo_box_changed_cb (GtkComboBox *combo_box,
2528 if (gtk_combo_box_get_active_iter (combo_box, &iter))
2530 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2531 GtkFileChooserButtonPrivate *priv = button->priv;
2535 type = ROW_TYPE_INVALID;
2538 gtk_tree_model_get (priv->filter_model, &iter,
2545 case ROW_TYPE_SPECIAL:
2546 case ROW_TYPE_SHORTCUT:
2547 case ROW_TYPE_BOOKMARK:
2548 case ROW_TYPE_CURRENT_FOLDER:
2549 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
2551 gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->dialog),
2554 case ROW_TYPE_VOLUME:
2558 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
2559 base_file = _gtk_file_system_volume_get_root (data);
2562 gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->dialog),
2564 g_object_unref (base_file);
2568 case ROW_TYPE_OTHER:
2569 open_dialog (user_data);
2579 button_clicked_cb (GtkButton *real_button,
2582 open_dialog (user_data);
2587 dialog_current_folder_changed_cb (GtkFileChooser *dialog,
2590 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2591 GtkFileChooserButtonPrivate *priv = button->priv;
2593 priv->folder_has_been_set = TRUE;
2595 g_signal_emit_by_name (button, "current-folder-changed");
2599 dialog_file_activated_cb (GtkFileChooser *dialog,
2602 g_signal_emit_by_name (user_data, "file-activated");
2606 dialog_selection_changed_cb (GtkFileChooser *dialog,
2609 update_label_and_image (user_data);
2610 update_combo_box (user_data);
2611 g_signal_emit_by_name (user_data, "selection-changed");
2615 dialog_update_preview_cb (GtkFileChooser *dialog,
2618 g_signal_emit_by_name (user_data, "update-preview");
2622 dialog_notify_cb (GObject *dialog,
2628 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (dialog)),
2629 GTK_TYPE_FILE_CHOOSER);
2630 if (g_object_interface_find_property (iface, pspec->name))
2631 g_object_notify (user_data, pspec->name);
2633 if (g_ascii_strcasecmp (pspec->name, "local-only") == 0)
2635 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2636 GtkFileChooserButtonPrivate *priv = button->priv;
2638 if (priv->has_current_folder)
2644 pos = model_get_type_position (user_data,
2645 ROW_TYPE_CURRENT_FOLDER);
2646 gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, pos);
2649 gtk_tree_model_get (priv->model, &iter, DATA_COLUMN, &data, -1);
2651 /* If the path isn't local but we're in local-only mode now, remove
2652 * the custom-folder row */
2653 if (data && g_file_is_native (G_FILE (data)) &&
2654 gtk_file_chooser_get_local_only (GTK_FILE_CHOOSER (priv->dialog)))
2657 model_remove_rows (user_data, pos, 2);
2661 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
2662 update_combo_box (user_data);
2667 dialog_delete_event_cb (GtkWidget *dialog,
2671 g_signal_emit_by_name (dialog, "response", GTK_RESPONSE_DELETE_EVENT);
2677 dialog_response_cb (GtkDialog *dialog,
2681 GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
2682 GtkFileChooserButtonPrivate *priv = button->priv;
2684 if (response == GTK_RESPONSE_ACCEPT ||
2685 response == GTK_RESPONSE_OK)
2687 g_signal_emit_by_name (user_data, "current-folder-changed");
2688 g_signal_emit_by_name (user_data, "selection-changed");
2690 else if (priv->old_file)
2692 switch (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)))
2694 case GTK_FILE_CHOOSER_ACTION_OPEN:
2695 gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->old_file,
2698 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
2699 gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
2700 priv->old_file, NULL);
2703 g_assert_not_reached ();
2708 gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
2712 g_object_unref (priv->old_file);
2713 priv->old_file = NULL;
2716 update_label_and_image (user_data);
2717 update_combo_box (user_data);
2721 g_signal_handler_unblock (priv->dialog,
2722 priv->dialog_folder_changed_id);
2723 g_signal_handler_unblock (priv->dialog,
2724 priv->dialog_file_activated_id);
2725 g_signal_handler_unblock (priv->dialog,
2726 priv->dialog_selection_changed_id);
2727 priv->active = FALSE;
2730 gtk_widget_set_sensitive (priv->combo_box, TRUE);
2731 gtk_widget_hide (priv->dialog);
2733 if (response == GTK_RESPONSE_ACCEPT ||
2734 response == GTK_RESPONSE_OK)
2735 g_signal_emit (user_data, file_chooser_button_signals[FILE_SET], 0);
2739 /* ************************************************************************** *
2741 * ************************************************************************** */
2744 * gtk_file_chooser_button_new:
2745 * @title: the title of the browse dialog.
2746 * @action: the open mode for the widget.
2748 * Creates a new file-selecting button widget.
2750 * Returns: a new button widget.
2755 gtk_file_chooser_button_new (const gchar *title,
2756 GtkFileChooserAction action)
2758 g_return_val_if_fail (action == GTK_FILE_CHOOSER_ACTION_OPEN ||
2759 action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, NULL);
2761 return g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
2763 "title", (title ? title : _(DEFAULT_TITLE)),
2768 * gtk_file_chooser_button_new_with_dialog:
2769 * @dialog: the widget to use as dialog
2771 * Creates a #GtkFileChooserButton widget which uses @dialog as its
2772 * file-picking window.
2774 * Note that @dialog must be a #GtkDialog (or subclass) which
2775 * implements the #GtkFileChooser interface and must not have
2776 * %GTK_DIALOG_DESTROY_WITH_PARENT set.
2778 * Also note that the dialog needs to have its confirmative button
2779 * added with response %GTK_RESPONSE_ACCEPT or %GTK_RESPONSE_OK in
2780 * order for the button to take over the file selected in the dialog.
2782 * Returns: a new button widget.
2787 gtk_file_chooser_button_new_with_dialog (GtkWidget *dialog)
2789 g_return_val_if_fail (GTK_IS_FILE_CHOOSER (dialog) && GTK_IS_DIALOG (dialog), NULL);
2791 return g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
2797 * gtk_file_chooser_button_set_title:
2798 * @button: the button widget to modify.
2799 * @title: the new browse dialog title.
2801 * Modifies the @title of the browse dialog used by @button.
2806 gtk_file_chooser_button_set_title (GtkFileChooserButton *button,
2809 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2811 gtk_window_set_title (GTK_WINDOW (button->priv->dialog), title);
2812 g_object_notify (G_OBJECT (button), "title");
2816 * gtk_file_chooser_button_get_title:
2817 * @button: the button widget to examine.
2819 * Retrieves the title of the browse dialog used by @button. The returned value
2820 * should not be modified or freed.
2822 * Returns: a pointer to the browse dialog's title.
2827 gtk_file_chooser_button_get_title (GtkFileChooserButton *button)
2829 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), NULL);
2831 return gtk_window_get_title (GTK_WINDOW (button->priv->dialog));
2835 * gtk_file_chooser_button_get_width_chars:
2836 * @button: the button widget to examine.
2838 * Retrieves the width in characters of the @button widget's entry and/or label.
2840 * Returns: an integer width (in characters) that the button will use to size itself.
2845 gtk_file_chooser_button_get_width_chars (GtkFileChooserButton *button)
2847 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), -1);
2849 return gtk_label_get_width_chars (GTK_LABEL (button->priv->label));
2853 * gtk_file_chooser_button_set_width_chars:
2854 * @button: the button widget to examine.
2855 * @n_chars: the new width, in characters.
2857 * Sets the width (in characters) that @button will use to @n_chars.
2862 gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button,
2865 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2867 gtk_label_set_width_chars (GTK_LABEL (button->priv->label), n_chars);
2868 g_object_notify (G_OBJECT (button), "width-chars");
2872 * gtk_file_chooser_button_set_focus_on_click:
2873 * @button: a #GtkFileChooserButton
2874 * @focus_on_click: whether the button grabs focus when clicked with the mouse
2876 * Sets whether the button will grab focus when it is clicked with the mouse.
2877 * Making mouse clicks not grab focus is useful in places like toolbars where
2878 * you don't want the keyboard focus removed from the main area of the
2884 gtk_file_chooser_button_set_focus_on_click (GtkFileChooserButton *button,
2885 gboolean focus_on_click)
2887 GtkFileChooserButtonPrivate *priv;
2889 g_return_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button));
2891 priv = button->priv;
2893 focus_on_click = focus_on_click != FALSE;
2895 if (priv->focus_on_click != focus_on_click)
2897 priv->focus_on_click = focus_on_click;
2898 gtk_button_set_focus_on_click (GTK_BUTTON (priv->button), focus_on_click);
2899 gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (priv->combo_box), focus_on_click);
2901 g_object_notify (G_OBJECT (button), "focus-on-click");
2906 * gtk_file_chooser_button_get_focus_on_click:
2907 * @button: a #GtkFileChooserButton
2909 * Returns whether the button grabs focus when it is clicked with the mouse.
2910 * See gtk_file_chooser_button_set_focus_on_click().
2912 * Return value: %TRUE if the button grabs focus when it is clicked with
2918 gtk_file_chooser_button_get_focus_on_click (GtkFileChooserButton *button)
2920 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_BUTTON (button), FALSE);
2922 return button->priv->focus_on_click;