1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserimpldefault.c: Default implementation of GtkFileChooser
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "gtkcellrendererseptext.h"
22 #include "gtkfilechooserimpldefault.h"
23 #include "gtkfilechooserentry.h"
24 #include "gtkfilechooserenums.h"
25 #include "gtkfilechooserutils.h"
26 #include "gtkfilechooser.h"
27 #include "gtkfilesystemmodel.h"
29 #include <gtk/gtkalignment.h>
30 #include <gtk/gtkcellrendererpixbuf.h>
31 #include <gtk/gtkcellrenderertext.h>
32 #include <gtk/gtkentry.h>
33 #include <gtk/gtkframe.h>
34 #include <gtk/gtkhbox.h>
35 #include <gtk/gtkhpaned.h>
36 #include <gtk/gtkicontheme.h>
37 #include <gtk/gtkimage.h>
38 #include <gtk/gtklabel.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkoptionmenu.h>
41 #include <gtk/gtkscrolledwindow.h>
42 #include <gtk/gtkstock.h>
43 #include <gtk/gtktable.h>
44 #include <gtk/gtktreeview.h>
45 #include <gtk/gtktreemodelsort.h>
46 #include <gtk/gtktreeselection.h>
47 #include <gtk/gtktreestore.h>
48 #include <gtk/gtkvbox.h>
53 typedef struct _GtkFileChooserImplDefaultClass GtkFileChooserImplDefaultClass;
55 #define GTK_FILE_CHOOSER_IMPL_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_IMPL_DEFAULT, GtkFileChooserImplDefaultClass))
56 #define GTK_IS_FILE_CHOOSER_IMPL_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_IMPL_DEFAULT))
57 #define GTK_FILE_CHOOSER_IMPL_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_IMPL_DEFAULT, GtkFileChooserImplDefaultClass))
59 struct _GtkFileChooserImplDefaultClass
61 GtkVBoxClass parent_class;
64 struct _GtkFileChooserImplDefault
66 GtkVBox parent_instance;
68 GtkFileSystem *file_system;
69 GtkFileSystemModel *tree_model;
70 GtkTreeStore *shortcuts_model;
71 GtkFileSystemModel *list_model;
72 GtkTreeModelSort *sort_model;
74 GtkFileChooserAction action;
76 GtkFileFilter *current_filter;
85 guint bookmarks_changed_id;
86 GtkTreeIter bookmarks_iter;
88 GtkFilePath *current_folder;
89 GtkFilePath *preview_path;
91 GtkWidget *preview_frame;
93 GtkWidget *filter_alignment;
94 GtkWidget *filter_option_menu;
95 GtkWidget *tree_scrollwin;
97 GtkWidget *shortcuts_scrollwin;
98 GtkWidget *shortcuts_tree;
99 GtkWidget *add_bookmark_button;
100 GtkWidget *remove_bookmark_button;
101 GtkWidget *list_scrollwin;
104 GtkWidget *preview_widget;
105 GtkWidget *extra_widget;
107 guint folder_mode : 1;
108 guint local_only : 1;
109 guint preview_widget_active : 1;
110 guint select_multiple : 1;
111 guint show_hidden : 1;
112 guint changing_folder : 1;
113 guint list_sort_ascending : 1;
114 guint bookmarks_set : 1;
117 /* Column numbers for the shortcuts tree. Keep these in sync with create_shortcuts_model() */
119 SHORTCUTS_COL_PIXBUF,
122 SHORTCUTS_COL_NUM_COLUMNS
125 /* Column numbers for the file list */
130 FILE_LIST_COL_NUM_COLUMNS
133 /* Standard icon size */
136 static void gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class);
137 static void gtk_file_chooser_impl_default_iface_init (GtkFileChooserIface *iface);
138 static void gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl);
140 static GObject* gtk_file_chooser_impl_default_constructor (GType type,
141 guint n_construct_properties,
142 GObjectConstructParam *construct_params);
143 static void gtk_file_chooser_impl_default_finalize (GObject *object);
144 static void gtk_file_chooser_impl_default_set_property (GObject *object,
148 static void gtk_file_chooser_impl_default_get_property (GObject *object,
152 static void gtk_file_chooser_impl_default_show_all (GtkWidget *widget);
154 static void gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
155 const GtkFilePath *path);
156 static GtkFilePath * gtk_file_chooser_impl_default_get_current_folder (GtkFileChooser *chooser);
157 static void gtk_file_chooser_impl_default_set_current_name (GtkFileChooser *chooser,
159 static void gtk_file_chooser_impl_default_select_path (GtkFileChooser *chooser,
160 const GtkFilePath *path);
161 static void gtk_file_chooser_impl_default_unselect_path (GtkFileChooser *chooser,
162 const GtkFilePath *path);
163 static void gtk_file_chooser_impl_default_select_all (GtkFileChooser *chooser);
164 static void gtk_file_chooser_impl_default_unselect_all (GtkFileChooser *chooser);
165 static GSList * gtk_file_chooser_impl_default_get_paths (GtkFileChooser *chooser);
166 static GtkFilePath * gtk_file_chooser_impl_default_get_preview_path (GtkFileChooser *chooser);
167 static GtkFileSystem *gtk_file_chooser_impl_default_get_file_system (GtkFileChooser *chooser);
168 static void gtk_file_chooser_impl_default_add_filter (GtkFileChooser *chooser,
169 GtkFileFilter *filter);
170 static void gtk_file_chooser_impl_default_remove_filter (GtkFileChooser *chooser,
171 GtkFileFilter *filter);
172 static GSList * gtk_file_chooser_impl_default_list_filters (GtkFileChooser *chooser);
173 static gboolean gtk_file_chooser_impl_default_add_shortcut_folder (GtkFileChooser *chooser,
174 const GtkFilePath *path,
176 static gboolean gtk_file_chooser_impl_default_remove_shortcut_folder (GtkFileChooser *chooser,
177 const GtkFilePath *path,
179 static GSList * gtk_file_chooser_impl_default_list_shortcut_folders (GtkFileChooser *chooser);
181 static void set_current_filter (GtkFileChooserImplDefault *impl,
182 GtkFileFilter *filter);
183 static void check_preview_change (GtkFileChooserImplDefault *impl);
185 static void filter_option_menu_changed (GtkOptionMenu *option_menu,
186 GtkFileChooserImplDefault *impl);
187 static void tree_selection_changed (GtkTreeSelection *tree_selection,
188 GtkFileChooserImplDefault *impl);
189 static void shortcuts_selection_changed (GtkTreeSelection *tree_selection,
190 GtkFileChooserImplDefault *impl);
191 static void list_selection_changed (GtkTreeSelection *tree_selection,
192 GtkFileChooserImplDefault *impl);
193 static void list_row_activated (GtkTreeView *tree_view,
195 GtkTreeViewColumn *column,
196 GtkFileChooserImplDefault *impl);
197 static void entry_activate (GtkEntry *entry,
198 GtkFileChooserImplDefault *impl);
200 static void tree_name_data_func (GtkTreeViewColumn *tree_column,
201 GtkCellRenderer *cell,
202 GtkTreeModel *tree_model,
205 static void list_icon_data_func (GtkTreeViewColumn *tree_column,
206 GtkCellRenderer *cell,
207 GtkTreeModel *tree_model,
210 static void list_name_data_func (GtkTreeViewColumn *tree_column,
211 GtkCellRenderer *cell,
212 GtkTreeModel *tree_model,
216 static void list_size_data_func (GtkTreeViewColumn *tree_column,
217 GtkCellRenderer *cell,
218 GtkTreeModel *tree_model,
222 static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
223 GtkCellRenderer *cell,
224 GtkTreeModel *tree_model,
228 static GObjectClass *parent_class;
231 _gtk_file_chooser_impl_default_get_type (void)
233 static GType file_chooser_impl_default_type = 0;
235 if (!file_chooser_impl_default_type)
237 static const GTypeInfo file_chooser_impl_default_info =
239 sizeof (GtkFileChooserImplDefaultClass),
240 NULL, /* base_init */
241 NULL, /* base_finalize */
242 (GClassInitFunc) gtk_file_chooser_impl_default_class_init,
243 NULL, /* class_finalize */
244 NULL, /* class_data */
245 sizeof (GtkFileChooserImplDefault),
247 (GInstanceInitFunc) gtk_file_chooser_impl_default_init,
250 static const GInterfaceInfo file_chooser_info =
252 (GInterfaceInitFunc) gtk_file_chooser_impl_default_iface_init, /* interface_init */
253 NULL, /* interface_finalize */
254 NULL /* interface_data */
257 file_chooser_impl_default_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserImplDefault",
258 &file_chooser_impl_default_info, 0);
259 g_type_add_interface_static (file_chooser_impl_default_type,
260 GTK_TYPE_FILE_CHOOSER,
264 return file_chooser_impl_default_type;
268 gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class)
270 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
271 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
273 parent_class = g_type_class_peek_parent (class);
275 gobject_class->finalize = gtk_file_chooser_impl_default_finalize;
276 gobject_class->constructor = gtk_file_chooser_impl_default_constructor;
277 gobject_class->set_property = gtk_file_chooser_impl_default_set_property;
278 gobject_class->get_property = gtk_file_chooser_impl_default_get_property;
280 widget_class->show_all = gtk_file_chooser_impl_default_show_all;
282 _gtk_file_chooser_install_properties (gobject_class);
286 gtk_file_chooser_impl_default_iface_init (GtkFileChooserIface *iface)
288 iface->select_path = gtk_file_chooser_impl_default_select_path;
289 iface->unselect_path = gtk_file_chooser_impl_default_unselect_path;
290 iface->select_all = gtk_file_chooser_impl_default_select_all;
291 iface->unselect_all = gtk_file_chooser_impl_default_unselect_all;
292 iface->get_paths = gtk_file_chooser_impl_default_get_paths;
293 iface->get_preview_path = gtk_file_chooser_impl_default_get_preview_path;
294 iface->get_file_system = gtk_file_chooser_impl_default_get_file_system;
295 iface->set_current_folder = gtk_file_chooser_impl_default_set_current_folder;
296 iface->get_current_folder = gtk_file_chooser_impl_default_get_current_folder;
297 iface->set_current_name = gtk_file_chooser_impl_default_set_current_name;
298 iface->add_filter = gtk_file_chooser_impl_default_add_filter;
299 iface->remove_filter = gtk_file_chooser_impl_default_remove_filter;
300 iface->list_filters = gtk_file_chooser_impl_default_list_filters;
301 iface->add_shortcut_folder = gtk_file_chooser_impl_default_add_shortcut_folder;
302 iface->remove_shortcut_folder = gtk_file_chooser_impl_default_remove_shortcut_folder;
303 iface->list_shortcut_folders = gtk_file_chooser_impl_default_list_shortcut_folders;
307 gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl)
309 impl->folder_mode = FALSE;
310 impl->local_only = TRUE;
311 impl->preview_widget_active = TRUE;
312 impl->select_multiple = FALSE;
313 impl->show_hidden = FALSE;
315 gtk_container_set_border_width (GTK_CONTAINER (impl), 5);
319 gtk_file_chooser_impl_default_finalize (GObject *object)
321 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
323 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
324 impl->bookmarks_changed_id = 0;
325 g_object_unref (impl->file_system);
327 G_OBJECT_CLASS (parent_class)->finalize (object);
331 update_preview_widget_visibility (GtkFileChooserImplDefault *impl)
333 if (impl->preview_widget_active && impl->preview_widget)
334 gtk_widget_show (impl->preview_frame);
336 gtk_widget_hide (impl->preview_frame);
340 set_preview_widget (GtkFileChooserImplDefault *impl,
341 GtkWidget *preview_widget)
343 if (preview_widget == impl->preview_widget)
346 if (impl->preview_widget)
347 gtk_container_remove (GTK_CONTAINER (impl->preview_frame),
348 impl->preview_widget);
350 impl->preview_widget = preview_widget;
351 if (impl->preview_widget)
353 gtk_widget_show (impl->preview_widget);
354 gtk_container_add (GTK_CONTAINER (impl->preview_frame),
355 impl->preview_widget);
358 update_preview_widget_visibility (impl);
361 /* Used from gtk_tree_model_foreach(); selects the item that corresponds to the
364 set_current_shortcut_foreach_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
366 GtkFileChooserImplDefault *impl;
367 GtkFilePath *model_path;
368 GtkTreeSelection *selection;
370 impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (data);
372 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
374 gtk_tree_model_get (model, iter, SHORTCUTS_COL_PATH, &model_path, -1);
376 if (model_path && impl->current_folder && gtk_file_path_compare (model_path, impl->current_folder) == 0)
378 gtk_tree_selection_select_path (selection, path);
382 gtk_tree_selection_unselect_path (selection, path);
387 /* Selects the appropriate node in the shortcuts tree based on the current folder */
389 shortcuts_select_folder (GtkFileChooserImplDefault *impl)
391 gtk_tree_model_foreach (GTK_TREE_MODEL (impl->shortcuts_model),
392 set_current_shortcut_foreach_cb,
396 /* Convenience function to get the display name and icon info for a path */
398 get_file_info (GtkFileSystem *file_system, const GtkFilePath *path, GError **error)
400 GtkFilePath *parent_path;
401 GtkFileFolder *parent_folder;
404 if (!gtk_file_system_get_parent (file_system, path, &parent_path, error))
407 parent_folder = gtk_file_system_get_folder (file_system, parent_path,
408 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
410 gtk_file_path_free (parent_path);
415 info = gtk_file_folder_get_info (parent_folder, path, error);
416 g_object_unref (parent_folder);
421 /* Inserts a path in the shortcuts tree, making a copy of it. A position of -1
422 * indicates the end of the tree. If the label is NULL, then the display name
423 * of a GtkFileInfo is used.
426 shortcuts_insert_path (GtkFileChooserImplDefault *impl,
428 const GtkFilePath *path,
434 GtkFilePath *path_copy;
438 /* FIXME: what if someone adds a shortcut to a root? get_file_info() will not
439 * work in that case, I think...
443 info = gtk_file_system_get_root_info (impl->file_system,
445 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
448 info = get_file_info (impl->file_system, path, error);
453 pixbuf = gtk_file_info_render_icon (info, impl->shortcuts_tree, ICON_SIZE);
455 gtk_tree_store_insert (impl->shortcuts_model, &iter, NULL, pos);
456 path_copy = gtk_file_path_copy (path);
459 label = gtk_file_info_get_display_name (info);
461 gtk_tree_store_set (impl->shortcuts_model, &iter,
462 SHORTCUTS_COL_PIXBUF, pixbuf,
463 SHORTCUTS_COL_NAME, label,
464 SHORTCUTS_COL_PATH, path_copy,
467 gtk_file_info_free (info);
470 g_object_unref (pixbuf);
475 /* Appends an item for the user's home directory to the shortcuts model */
477 shortcuts_append_home (GtkFileChooserImplDefault *impl)
481 GtkFilePath *home_path;
484 name = g_get_user_name ();
485 label = g_strdup_printf ("%s's Home", name);
487 home = g_get_home_dir ();
488 home_path = gtk_file_system_filename_to_path (impl->file_system, home);
490 impl->has_home = shortcuts_insert_path (impl, -1, home_path, FALSE, label, NULL); /* FIXME: use GError? */
493 gtk_file_path_free (home_path);
496 /* Appends the ~/Desktop directory to the shortcuts model */
498 shortcuts_append_desktop (GtkFileChooserImplDefault *impl)
503 /* FIXME: What is the Right Way of finding the desktop directory? */
505 name = g_build_filename (g_get_home_dir (), "Desktop", NULL);
506 path = gtk_file_system_filename_to_path (impl->file_system, name);
509 impl->has_desktop = shortcuts_insert_path (impl, -1, path, FALSE, NULL, NULL); /* FIXME: use GError? */
510 gtk_file_path_free (path);
513 /* Appends all the file system roots to the shortcuts model */
515 shortcuts_append_file_system_roots (GtkFileChooserImplDefault *impl)
519 roots = gtk_file_system_list_roots (impl->file_system);
520 /* FIXME: handle the roots-changed signal on the file system */
524 for (l = roots; l; l = l->next)
529 if (shortcuts_insert_path (impl, -1, path, TRUE, NULL, NULL)) /* FIXME: use GError? */
533 gtk_file_paths_free (roots);
536 /* Removes the bookmarks separator node and all the bookmarks from the tree
540 remove_bookmark_rows (GtkFileChooserImplDefault *impl)
545 if (!impl->bookmarks_set)
548 /* Ugh. Is there a better way to do this? */
550 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &impl->bookmarks_iter);
552 while (gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
553 gtk_tree_store_remove (impl->shortcuts_model, &impl->bookmarks_iter);
555 impl->bookmarks_set = FALSE;
558 /* Appends the bookmarks separator node and the bookmarks from the file system. */
560 shortcuts_append_bookmarks (GtkFileChooserImplDefault *impl)
562 GSList *bookmarks, *l;
564 remove_bookmark_rows (impl);
566 gtk_tree_store_append (impl->shortcuts_model, &impl->bookmarks_iter, NULL);
567 gtk_tree_store_set (impl->shortcuts_model, &impl->bookmarks_iter,
568 SHORTCUTS_COL_PIXBUF, NULL,
569 SHORTCUTS_COL_NAME, NULL,
570 SHORTCUTS_COL_PATH, NULL,
572 impl->bookmarks_set = TRUE;
573 impl->num_bookmarks = 0;
575 bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
577 for (l = bookmarks; l; l = l->next)
582 if (shortcuts_insert_path (impl, -1, path, FALSE, NULL, NULL)) /* FIXME: use GError? */
583 impl->num_bookmarks++;
587 /* Creates the GtkTreeStore used as the shortcuts model */
589 create_shortcuts_model (GtkFileChooserImplDefault *impl)
591 if (impl->shortcuts_model)
592 g_object_unref (impl->shortcuts_model);
594 /* Keep this order in sync with the SHORCUTS_COL_* enum values */
595 impl->shortcuts_model = gtk_tree_store_new (SHORTCUTS_COL_NUM_COLUMNS,
596 GDK_TYPE_PIXBUF, /* pixbuf */
597 G_TYPE_STRING, /* name */
598 G_TYPE_POINTER); /* path */
600 if (impl->file_system)
602 shortcuts_append_home (impl);
603 shortcuts_append_desktop (impl);
604 shortcuts_append_file_system_roots (impl);
605 shortcuts_append_bookmarks (impl);
608 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model));
611 /* Creates the widgets for the filter option menu */
613 create_filter (GtkFileChooserImplDefault *impl)
618 impl->filter_alignment = gtk_alignment_new (0.0, 0.5, 0.0, 1.0);
619 gtk_alignment_set_padding (GTK_ALIGNMENT (impl->filter_alignment), 0, 6, 0, 0);
620 /* Don't show filter initially -- don't gtk_widget_show() the filter_alignment here */
622 hbox = gtk_hbox_new (FALSE, 6);
623 gtk_container_add (GTK_CONTAINER (impl->filter_alignment), hbox);
624 gtk_widget_show (hbox);
626 label = gtk_label_new_with_mnemonic ("Files of _type:");
627 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
628 gtk_widget_show (label);
630 impl->filter_option_menu = gtk_option_menu_new ();
631 gtk_option_menu_set_menu (GTK_OPTION_MENU (impl->filter_option_menu),
633 gtk_box_pack_start (GTK_BOX (hbox), impl->filter_option_menu, FALSE, FALSE, 0);
634 gtk_widget_show (impl->filter_option_menu);
636 gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->filter_option_menu);
638 g_signal_connect (impl->filter_option_menu, "changed",
639 G_CALLBACK (filter_option_menu_changed), impl);
641 return impl->filter_alignment;
644 /* Creates the widgets for the folder tree */
646 create_folder_tree (GtkFileChooserImplDefault *impl)
648 GtkTreeSelection *selection;
650 /* Scrolled window */
652 impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
653 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
654 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
655 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
657 if (impl->folder_mode)
658 gtk_widget_show (impl->tree_scrollwin);
662 impl->tree = gtk_tree_view_new ();
663 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
665 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
666 g_signal_connect (selection, "changed",
667 G_CALLBACK (tree_selection_changed), impl);
669 gtk_container_add (GTK_CONTAINER (impl->tree_scrollwin), impl->tree);
670 gtk_widget_show (impl->tree);
674 impl->tree_model = _gtk_file_system_model_new (impl->file_system, NULL, -1,
675 GTK_FILE_INFO_DISPLAY_NAME);
676 _gtk_file_system_model_set_show_files (impl->tree_model, FALSE);
678 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->tree),
679 GTK_TREE_MODEL (impl->tree_model));
683 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (impl->tree), 0,
685 gtk_cell_renderer_text_new (),
686 tree_name_data_func, impl, NULL);
687 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->tree),
688 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
690 return impl->tree_scrollwin;
693 /* Callback used when the "Add bookmark" button is clicked */
695 add_bookmark_button_clicked_cb (GtkButton *button,
696 GtkFileChooserImplDefault *impl)
698 gtk_file_system_add_bookmark (impl->file_system, impl->current_folder, NULL); /* FIXME: use GError */
701 /* Callback used when the "Remove bookmark" button is clicked */
703 remove_bookmark_button_clicked_cb (GtkButton *button,
704 GtkFileChooserImplDefault *impl)
706 GtkTreeSelection *selection;
710 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
712 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
715 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &path, -1);
717 gtk_file_system_remove_bookmark (impl->file_system, path, NULL); /* FIXME: use GError */
720 /* Sensitize the "add bookmark" button if the current folder is not in the
721 * bookmarks list, or de-sensitize it otherwise.
724 bookmarks_check_add_sensitivity (GtkFileChooserImplDefault *impl)
731 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
736 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &path, -1);
738 if (path && gtk_file_path_compare (path, impl->current_folder) == 0)
744 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
746 gtk_widget_set_sensitive (impl->add_bookmark_button, !exists);
749 /* Sets the sensitivity of the "remove bookmark" button depending on whether a
750 * bookmark row is selected in the shortcuts tree.
753 bookmarks_check_remove_sensitivity (GtkFileChooserImplDefault *impl)
755 GtkTreeSelection *selection;
757 gboolean is_bookmark;
759 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
761 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
763 GtkTreePath *bookmarks_path;
764 GtkTreePath *sel_path;
766 bookmarks_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model),
767 &impl->bookmarks_iter);
768 sel_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
770 is_bookmark = (gtk_tree_path_compare (bookmarks_path, sel_path) < 0);
772 gtk_tree_path_free (bookmarks_path);
773 gtk_tree_path_free (sel_path);
778 gtk_widget_set_sensitive (impl->remove_bookmark_button, is_bookmark);
781 /* Creates the widgets for the shortcuts and bookmarks tree */
783 create_shortcuts_tree (GtkFileChooserImplDefault *impl)
787 GtkTreeSelection *selection;
788 GtkTreeViewColumn *column;
789 GtkCellRenderer *renderer;
792 vbox = gtk_vbox_new (FALSE, 12);
793 gtk_widget_show (vbox);
795 /* Scrolled window */
797 impl->shortcuts_scrollwin = gtk_scrolled_window_new (NULL, NULL);
798 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
799 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
800 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
802 gtk_box_pack_start (GTK_BOX (vbox), impl->shortcuts_scrollwin, TRUE, TRUE, 0);
803 gtk_widget_show (impl->shortcuts_scrollwin);
807 impl->shortcuts_tree = gtk_tree_view_new ();
808 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE);
810 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
811 g_signal_connect (selection, "changed",
812 G_CALLBACK (shortcuts_selection_changed), impl);
814 gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_tree);
815 gtk_widget_show (impl->shortcuts_tree);
819 create_shortcuts_model (impl);
823 column = gtk_tree_view_column_new ();
824 gtk_tree_view_column_set_title (column, "Folder");
826 renderer = gtk_cell_renderer_pixbuf_new ();
827 gtk_tree_view_column_pack_start (column, renderer, FALSE);
828 gtk_tree_view_column_set_attributes (column, renderer,
829 "pixbuf", SHORTCUTS_COL_PIXBUF,
832 renderer = _gtk_cell_renderer_sep_text_new ();
833 gtk_tree_view_column_pack_start (column, renderer, TRUE);
834 gtk_tree_view_column_set_attributes (column, renderer,
835 "text", SHORTCUTS_COL_NAME,
838 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_tree), column);
840 /* Bookmark buttons */
842 hbox = gtk_hbox_new (FALSE, 12);
843 gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
844 gtk_widget_show (hbox);
846 impl->add_bookmark_button = gtk_button_new_with_label ("Add bookmark");
847 g_signal_connect (impl->add_bookmark_button, "clicked",
848 G_CALLBACK (add_bookmark_button_clicked_cb), impl);
849 gtk_box_pack_start (GTK_BOX (hbox), impl->add_bookmark_button, TRUE, TRUE, 0);
850 gtk_widget_set_sensitive (impl->add_bookmark_button, FALSE);
851 gtk_widget_show (impl->add_bookmark_button);
853 impl->remove_bookmark_button = gtk_button_new ();
854 g_signal_connect (impl->remove_bookmark_button, "clicked",
855 G_CALLBACK (remove_bookmark_button_clicked_cb), impl);
856 image = gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_BUTTON);
857 gtk_container_add (GTK_CONTAINER (impl->remove_bookmark_button), image);
858 gtk_widget_show (image);
859 gtk_widget_set_sensitive (impl->remove_bookmark_button, FALSE);
860 gtk_box_pack_start (GTK_BOX (hbox), impl->remove_bookmark_button, FALSE, FALSE, 0);
861 gtk_widget_show (impl->remove_bookmark_button);
863 shortcuts_select_folder (impl);
868 /* Creates the widgets for the file list */
870 create_file_list (GtkFileChooserImplDefault *impl)
872 GtkTreeSelection *selection;
873 GtkTreeViewColumn *column;
874 GtkCellRenderer *renderer;
876 /* Scrolled window */
878 impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
879 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
880 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
881 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
883 if (!impl->folder_mode)
884 gtk_widget_show (impl->list_scrollwin);
888 impl->list = gtk_tree_view_new ();
889 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
890 gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
891 g_signal_connect (impl->list, "row_activated",
892 G_CALLBACK (list_row_activated), impl);
893 gtk_widget_show (impl->list);
895 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
896 g_signal_connect (selection, "changed",
897 G_CALLBACK (list_selection_changed), impl);
899 /* Filename column */
901 column = gtk_tree_view_column_new ();
902 gtk_tree_view_column_set_title (column, "File name");
903 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_NAME);
905 renderer = gtk_cell_renderer_pixbuf_new ();
906 gtk_tree_view_column_pack_start (column, renderer, TRUE);
907 gtk_tree_view_column_set_cell_data_func (column, renderer,
908 list_icon_data_func, impl, NULL);
910 renderer = gtk_cell_renderer_text_new ();
911 gtk_tree_view_column_pack_start (column, renderer, TRUE);
912 gtk_tree_view_column_set_cell_data_func (column, renderer,
913 list_name_data_func, impl, NULL);
915 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
919 column = gtk_tree_view_column_new ();
920 gtk_tree_view_column_set_title (column, "Size");
922 renderer = gtk_cell_renderer_text_new ();
923 gtk_tree_view_column_pack_start (column, renderer, TRUE);
924 gtk_tree_view_column_set_cell_data_func (column, renderer,
925 list_size_data_func, impl, NULL);
926 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
927 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
929 /* Modification time column */
931 column = gtk_tree_view_column_new ();
932 gtk_tree_view_column_set_title (column, "Modified");
934 renderer = gtk_cell_renderer_text_new ();
935 gtk_tree_view_column_pack_start (column, renderer, TRUE);
936 gtk_tree_view_column_set_cell_data_func (column, renderer,
937 list_mtime_data_func, impl, NULL);
938 gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_MTIME);
939 gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
941 return impl->list_scrollwin;
945 create_filename_entry (GtkFileChooserImplDefault *impl)
950 hbox = gtk_hbox_new (FALSE, 6);
951 gtk_widget_show (hbox);
953 label = gtk_label_new_with_mnemonic ("_Location:");
954 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
955 gtk_widget_show (label);
957 impl->entry = _gtk_file_chooser_entry_new ();
958 gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
959 g_signal_connect (impl->entry, "activate",
960 G_CALLBACK (entry_activate), impl);
961 _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry),
964 gtk_box_pack_start (GTK_BOX (hbox), impl->entry, TRUE, TRUE, 0);
965 gtk_widget_show (impl->entry);
967 gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->entry);
973 gtk_file_chooser_impl_default_constructor (GType type,
974 guint n_construct_properties,
975 GObjectConstructParam *construct_params)
977 GtkFileChooserImplDefault *impl;
987 object = parent_class->constructor (type,
988 n_construct_properties,
990 impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
992 g_assert (impl->file_system);
994 gtk_widget_push_composite_child ();
998 table = gtk_table_new (3, 2, FALSE);
999 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
1000 gtk_box_pack_start (GTK_BOX (impl), table, TRUE, TRUE, 0);
1001 gtk_widget_show (table);
1005 widget = create_filter (impl);
1006 gtk_table_attach (GTK_TABLE (table), widget,
1008 GTK_EXPAND | GTK_FILL, 0,
1013 hpaned = gtk_hpaned_new ();
1014 gtk_table_attach (GTK_TABLE (table), hpaned,
1016 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
1018 gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
1019 gtk_widget_show (hpaned);
1021 /* Shortcuts list */
1023 widget = create_shortcuts_tree (impl);
1024 gtk_paned_add1 (GTK_PANED (hpaned), widget);
1028 hbox = gtk_hbox_new (FALSE, 12);
1029 gtk_paned_add2 (GTK_PANED (hpaned), hbox);
1030 gtk_widget_show (hbox);
1032 widget = create_folder_tree (impl);
1033 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1037 widget = create_file_list (impl);
1038 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1040 /* Location/filename entry */
1042 widget = create_filename_entry (impl);
1043 gtk_table_attach (GTK_TABLE (table), widget,
1045 GTK_EXPAND | GTK_FILL, 0,
1050 impl->preview_frame = gtk_frame_new ("Preview");
1051 gtk_table_attach (GTK_TABLE (table), impl->preview_frame,
1053 0, GTK_EXPAND | GTK_FILL,
1055 /* Don't show preview frame initially */
1058 focus_chain = g_list_append (NULL, impl->entry);
1059 focus_chain = g_list_append (focus_chain, impl->tree);
1060 focus_chain = g_list_append (focus_chain, impl->list);
1061 gtk_container_set_focus_chain (GTK_CONTAINER (impl), focus_chain);
1062 g_list_free (focus_chain);
1065 gtk_widget_pop_composite_child ();
1070 /* Sets the extra_widget by packing it in the appropriate place */
1072 set_extra_widget (GtkFileChooserImplDefault *impl,
1073 GtkWidget *extra_widget)
1075 if (extra_widget == impl->extra_widget)
1078 if (impl->extra_widget)
1079 gtk_container_remove (GTK_CONTAINER (impl), impl->extra_widget);
1081 impl->extra_widget = extra_widget;
1082 if (impl->extra_widget)
1084 gtk_widget_show (impl->extra_widget);
1085 gtk_box_pack_end (GTK_BOX (impl), impl->extra_widget, FALSE, FALSE, 0);
1089 /* Callback used when the set of bookmarks changes in the file system */
1091 bookmarks_changed_cb (GtkFileSystem *file_system,
1092 GtkFileChooserImplDefault *impl)
1094 shortcuts_append_bookmarks (impl);
1095 shortcuts_select_folder (impl);
1097 bookmarks_check_add_sensitivity (impl);
1098 bookmarks_check_remove_sensitivity (impl);
1102 gtk_file_chooser_impl_default_set_property (GObject *object,
1104 const GValue *value,
1108 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
1112 case GTK_FILE_CHOOSER_PROP_ACTION:
1113 impl->action = g_value_get_enum (value);
1115 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
1117 GtkFileSystem *file_system = g_value_get_object (value);
1118 if (impl->file_system != file_system)
1120 if (impl->file_system)
1122 g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
1123 impl->bookmarks_changed_id = 0;
1124 g_object_unref (impl->file_system);
1126 impl->file_system = file_system;
1127 if (impl->file_system)
1129 g_object_ref (impl->file_system);
1130 impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
1131 G_CALLBACK (bookmarks_changed_cb),
1137 case GTK_FILE_CHOOSER_PROP_FILTER:
1138 set_current_filter (impl, g_value_get_object (value));
1140 case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
1142 gboolean folder_mode = g_value_get_boolean (value);
1143 if (folder_mode != impl->folder_mode)
1145 impl->folder_mode = folder_mode;
1146 if (impl->folder_mode)
1148 gtk_widget_hide (impl->list_scrollwin);
1149 gtk_widget_show (impl->tree_scrollwin);
1153 gtk_widget_hide (impl->tree_scrollwin);
1154 gtk_widget_show (impl->list_scrollwin);
1159 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
1160 impl->local_only = g_value_get_boolean (value);
1162 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
1163 set_preview_widget (impl, g_value_get_object (value));
1165 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
1166 impl->preview_widget_active = g_value_get_boolean (value);
1167 update_preview_widget_visibility (impl);
1169 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
1170 set_extra_widget (impl, g_value_get_object (value));
1172 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
1174 gboolean select_multiple = g_value_get_boolean (value);
1175 if (select_multiple != impl->select_multiple)
1177 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1179 impl->select_multiple = select_multiple;
1180 gtk_tree_selection_set_mode (selection,
1182 GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE));
1183 /* FIXME: See note in check_preview_change() */
1184 check_preview_change (impl);
1188 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
1190 gboolean show_hidden = g_value_get_boolean (value);
1191 if (show_hidden != impl->show_hidden)
1193 impl->show_hidden = show_hidden;
1194 _gtk_file_system_model_set_show_hidden (impl->tree_model, show_hidden);
1195 _gtk_file_system_model_set_show_hidden (impl->list_model, show_hidden);
1200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1206 gtk_file_chooser_impl_default_get_property (GObject *object,
1211 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
1215 case GTK_FILE_CHOOSER_PROP_ACTION:
1216 g_value_set_enum (value, impl->action);
1218 case GTK_FILE_CHOOSER_PROP_FILTER:
1219 g_value_set_object (value, impl->current_filter);
1221 case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
1222 g_value_set_boolean (value, impl->folder_mode);
1224 case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
1225 g_value_set_boolean (value, impl->local_only);
1227 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
1228 g_value_set_object (value, impl->preview_widget);
1230 case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
1231 g_value_set_boolean (value, impl->preview_widget_active);
1233 case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
1234 g_value_set_object (value, impl->extra_widget);
1236 case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
1237 g_value_set_boolean (value, impl->select_multiple);
1239 case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
1240 g_value_set_boolean (value, impl->show_hidden);
1243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1248 /* We override show-all since we have internal widgets that
1249 * shouldn't be shown when you call show_all(), like the filter
1253 gtk_file_chooser_impl_default_show_all (GtkWidget *widget)
1255 gtk_widget_show (widget);
1259 expand_and_select_func (GtkFileSystemModel *model,
1264 GtkFileChooserImplDefault *impl = user_data;
1265 GtkTreeView *tree_view;
1267 if (model == impl->tree_model)
1268 tree_view = GTK_TREE_VIEW (impl->tree);
1270 tree_view = GTK_TREE_VIEW (impl->list);
1272 gtk_tree_view_expand_to_path (tree_view, path);
1273 gtk_tree_view_expand_row (tree_view, path, FALSE);
1274 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
1275 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), path, NULL, TRUE, 0.3, 0.5);
1279 list_model_filter_func (GtkFileSystemModel *model,
1281 const GtkFileInfo *file_info,
1284 GtkFileChooserImplDefault *impl = user_data;
1285 GtkFileFilterInfo filter_info;
1286 GtkFileFilterFlags needed;
1289 if (!impl->current_filter)
1292 filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
1294 needed = gtk_file_filter_get_needed (impl->current_filter);
1296 filter_info.display_name = gtk_file_info_get_display_name (file_info);
1297 filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
1299 if (needed & GTK_FILE_FILTER_FILENAME)
1301 filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
1302 if (filter_info.filename)
1303 filter_info.contains |= GTK_FILE_FILTER_FILENAME;
1306 filter_info.filename = NULL;
1308 if (needed & GTK_FILE_FILTER_URI)
1310 filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
1311 if (filter_info.filename)
1312 filter_info.contains |= GTK_FILE_FILTER_URI;
1315 filter_info.uri = NULL;
1317 result = gtk_file_filter_filter (impl->current_filter, &filter_info);
1319 if (filter_info.filename)
1320 g_free ((gchar *)filter_info.filename);
1321 if (filter_info.uri)
1322 g_free ((gchar *)filter_info.uri);
1328 install_list_model_filter (GtkFileChooserImplDefault *impl)
1330 if (impl->current_filter)
1331 _gtk_file_system_model_set_filter (impl->list_model,
1332 list_model_filter_func,
1336 #define COMPARE_DIRECTORIES \
1337 GtkFileChooserImplDefault *impl = user_data; \
1338 const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->tree_model, a); \
1339 const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->tree_model, b); \
1340 gboolean dir_a = gtk_file_info_get_is_folder (info_a); \
1341 gboolean dir_b = gtk_file_info_get_is_folder (info_b); \
1343 if (dir_a != dir_b) \
1344 return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
1346 /* Sort callback for the filename column */
1348 name_sort_func (GtkTreeModel *model,
1353 COMPARE_DIRECTORIES;
1355 return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
1358 /* Sort callback for the size column */
1360 size_sort_func (GtkTreeModel *model,
1365 COMPARE_DIRECTORIES;
1368 gint64 size_a = gtk_file_info_get_size (info_a);
1369 gint64 size_b = gtk_file_info_get_size (info_b);
1371 return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
1375 /* Sort callback for the mtime column */
1377 mtime_sort_func (GtkTreeModel *model,
1382 COMPARE_DIRECTORIES;
1385 GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
1386 GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
1388 return ta > tb ? -1 : (ta == tb ? 0 : 1);
1392 /* Callback used when the sort column changes. We cache the sort order for use
1393 * in name_sort_func().
1396 list_sort_column_changed_cb (GtkTreeSortable *sortable,
1397 GtkFileChooserImplDefault *impl)
1399 GtkSortType sort_type;
1401 if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
1402 impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
1405 /* Gets rid of the old list model and creates a new one for the current folder */
1407 set_list_model (GtkFileChooserImplDefault *impl)
1409 if (impl->list_model)
1411 g_object_unref (impl->list_model);
1412 impl->list_model = NULL;
1414 g_object_unref (impl->sort_model);
1415 impl->sort_model = NULL;
1418 impl->list_model = _gtk_file_system_model_new (impl->file_system,
1419 impl->current_folder, 0,
1420 GTK_FILE_INFO_ICON |
1421 GTK_FILE_INFO_DISPLAY_NAME |
1422 GTK_FILE_INFO_IS_FOLDER |
1423 GTK_FILE_INFO_SIZE |
1424 GTK_FILE_INFO_MODIFICATION_TIME);
1425 install_list_model_filter (impl);
1427 impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->list_model));
1428 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
1429 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
1430 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
1431 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
1432 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
1433 impl->list_sort_ascending = TRUE;
1435 g_signal_connect (impl->sort_model, "sort_column_changed",
1436 G_CALLBACK (list_sort_column_changed_cb), impl);
1438 gtk_tree_view_set_model (GTK_TREE_VIEW (impl->list),
1439 GTK_TREE_MODEL (impl->sort_model));
1440 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->list));
1441 gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->list),
1442 GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
1446 update_chooser_entry (GtkFileChooserImplDefault *impl)
1448 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1449 const GtkFileInfo *info;
1451 GtkTreeIter child_iter;
1453 /* Fixing this for multiple selection involves getting the full
1454 * selection and diffing to find out what the most recently selected
1455 * file is; there is logic in GtkFileSelection that probably can
1456 * be copied; check_preview_change() is similar.
1458 if (impl->select_multiple ||
1459 !gtk_tree_selection_get_selected (selection, NULL, &iter))
1462 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
1466 info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
1468 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry),
1469 gtk_file_info_get_display_name (info));
1473 gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
1474 const GtkFilePath *path)
1476 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1478 _gtk_file_system_model_path_do (impl->tree_model, path,
1479 expand_and_select_func, impl);
1482 static GtkFilePath *
1483 gtk_file_chooser_impl_default_get_current_folder (GtkFileChooser *chooser)
1485 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1487 return gtk_file_path_copy (impl->current_folder);
1491 gtk_file_chooser_impl_default_set_current_name (GtkFileChooser *chooser,
1494 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1496 _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry), name);
1500 select_func (GtkFileSystemModel *model,
1505 GtkFileChooserImplDefault *impl = user_data;
1506 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
1507 GtkTreePath *sorted_path;
1509 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model, path);
1510 gtk_tree_view_set_cursor (tree_view, sorted_path, NULL, FALSE);
1511 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), sorted_path, NULL, TRUE, 0.3, 0.0);
1512 gtk_tree_path_free (sorted_path);
1516 gtk_file_chooser_impl_default_select_path (GtkFileChooser *chooser,
1517 const GtkFilePath *path)
1519 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1520 GtkFilePath *parent_path;
1522 if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, NULL)) /* NULL-GError */
1527 _gtk_file_chooser_set_current_folder_path (chooser, path);
1531 _gtk_file_chooser_set_current_folder_path (chooser, parent_path);
1532 gtk_file_path_free (parent_path);
1533 _gtk_file_system_model_path_do (impl->list_model, path,
1539 unselect_func (GtkFileSystemModel *model,
1544 GtkFileChooserImplDefault *impl = user_data;
1545 GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
1546 GtkTreePath *sorted_path;
1548 sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
1550 gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
1552 gtk_tree_path_free (sorted_path);
1556 gtk_file_chooser_impl_default_unselect_path (GtkFileChooser *chooser,
1557 const GtkFilePath *path)
1559 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1561 _gtk_file_system_model_path_do (impl->list_model, path,
1562 unselect_func, impl);
1566 gtk_file_chooser_impl_default_select_all (GtkFileChooser *chooser)
1568 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1569 if (impl->select_multiple)
1571 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1572 gtk_tree_selection_select_all (selection);
1577 gtk_file_chooser_impl_default_unselect_all (GtkFileChooser *chooser)
1579 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1580 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1582 gtk_tree_selection_unselect_all (selection);
1586 get_paths_foreach (GtkTreeModel *model,
1591 GtkTreePath *child_path;
1592 GtkTreeIter child_iter;
1593 const GtkFilePath *file_path;
1597 GtkFileChooserImplDefault *impl;
1600 child_path = gtk_tree_model_sort_convert_path_to_child_path (info->impl->sort_model, path);
1601 gtk_tree_model_get_iter (GTK_TREE_MODEL (info->impl->list_model), &child_iter, child_path);
1602 gtk_tree_path_free (child_path);
1604 file_path = _gtk_file_system_model_get_path (info->impl->list_model, &child_iter);
1605 info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
1609 gtk_file_chooser_impl_default_get_paths (GtkFileChooser *chooser)
1611 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1612 GtkTreeSelection *selection;
1616 GtkFileChooserImplDefault *impl;
1619 if (!impl->sort_model)
1622 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1625 gtk_tree_selection_selected_foreach (selection,
1626 get_paths_foreach, &info);
1627 return g_slist_reverse (info.result);
1630 static GtkFilePath *
1631 gtk_file_chooser_impl_default_get_preview_path (GtkFileChooser *chooser)
1633 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1635 if (impl->preview_path)
1636 return gtk_file_path_copy (impl->preview_path);
1641 static GtkFileSystem *
1642 gtk_file_chooser_impl_default_get_file_system (GtkFileChooser *chooser)
1644 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1646 return impl->file_system;
1650 find_filter_menu_item (GtkFileChooserImplDefault *impl,
1651 GtkFileFilter *filter,
1654 GtkWidget *menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (impl->filter_option_menu));
1655 GList *children = gtk_container_get_children (GTK_CONTAINER (menu));
1662 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
1664 if (g_object_get_data (tmp_list->data, "gtk-file-filter") == filter)
1667 *index_return = index;
1668 return tmp_list->data;
1673 g_list_free (children);
1679 gtk_file_chooser_impl_default_add_filter (GtkFileChooser *chooser,
1680 GtkFileFilter *filter)
1682 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1684 GtkWidget *menu_item;
1687 if (g_slist_find (impl->filters, filter))
1689 g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
1693 g_object_ref (filter);
1694 gtk_object_sink (GTK_OBJECT (filter));
1695 impl->filters = g_slist_append (impl->filters, filter);
1697 name = gtk_file_filter_get_name (filter);
1699 name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
1701 menu_item = gtk_menu_item_new_with_label (name);
1702 g_object_set_data (G_OBJECT (menu_item), "gtk-file-filter", filter);
1703 gtk_widget_show (menu_item);
1705 menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (impl->filter_option_menu));
1706 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1707 /* Option menus don't react to menu size changes properly */
1708 gtk_widget_size_request (menu, NULL);
1710 if (!g_slist_find (impl->filters, impl->current_filter))
1711 set_current_filter (impl, filter);
1713 gtk_widget_show (impl->filter_alignment);
1717 gtk_file_chooser_impl_default_remove_filter (GtkFileChooser *chooser,
1718 GtkFileFilter *filter)
1720 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1722 GtkWidget *menu_item;
1724 if (!g_slist_find (impl->filters, filter))
1726 g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
1730 impl->filters = g_slist_remove (impl->filters, filter);
1732 if (filter == impl->current_filter)
1735 set_current_filter (impl, impl->filters->data);
1737 set_current_filter (impl, NULL);
1740 menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (impl->filter_option_menu));
1741 menu_item = find_filter_menu_item (impl, filter, NULL);
1742 g_assert (menu_item);
1743 gtk_widget_destroy (menu_item);
1744 /* Option menus don't react to menu size changes properly */
1745 gtk_widget_size_request (menu, NULL);
1747 g_object_unref (filter);
1750 gtk_widget_hide (impl->filter_alignment);
1754 gtk_file_chooser_impl_default_list_filters (GtkFileChooser *chooser)
1756 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1758 return g_slist_copy (impl->filters);
1761 /* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
1763 shortcuts_get_pos_for_shortcut_folder (GtkFileChooserImplDefault *impl,
1766 return pos + ((impl->has_home ? 1 : 0)
1767 + (impl->has_desktop ? 1 : 0)
1772 gtk_file_chooser_impl_default_add_shortcut_folder (GtkFileChooser *chooser,
1773 const GtkFilePath *path,
1776 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1780 pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
1782 /* FIXME: how do we know if the path is a file system root? */
1783 result = shortcuts_insert_path (impl, pos, path, FALSE, NULL, error);
1786 impl->num_shortcuts++;
1792 gtk_file_chooser_impl_default_remove_shortcut_folder (GtkFileChooser *chooser,
1793 const GtkFilePath *path,
1796 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1801 if (impl->num_shortcuts == 0)
1804 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
1805 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
1806 g_assert_not_reached ();
1808 for (i = 0; i < impl->num_shortcuts; i++)
1810 GtkFilePath *shortcut;
1812 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
1813 g_assert (shortcut != NULL);
1815 if (gtk_file_path_compare (shortcut, path) == 0)
1817 /* The other columns are freed by the GtkTreeStore */
1818 gtk_file_path_free (shortcut);
1819 gtk_tree_store_remove (impl->shortcuts_model, &iter);
1820 impl->num_shortcuts--;
1824 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1825 g_assert_not_reached ();
1831 GTK_FILE_CHOOSER_ERROR,
1832 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
1833 "shortcut %s does not exist",
1834 gtk_file_path_get_string (path));
1840 gtk_file_chooser_impl_default_list_shortcut_folders (GtkFileChooser *chooser)
1842 GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
1848 pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
1849 if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
1850 g_assert_not_reached ();
1854 for (i = 0; i < impl->num_shortcuts; i++)
1856 GtkFilePath *shortcut;
1858 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
1859 g_assert (shortcut != NULL);
1861 list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
1863 if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
1864 g_assert_not_reached ();
1867 return g_slist_reverse (list);
1871 set_current_filter (GtkFileChooserImplDefault *impl,
1872 GtkFileFilter *filter)
1874 if (impl->current_filter != filter)
1876 int menu_item_index;
1878 /* If we have filters, new filter must be one of them
1880 find_filter_menu_item (impl, filter, &menu_item_index);
1881 if (impl->filters && menu_item_index < 0)
1884 if (impl->current_filter)
1885 g_object_unref (impl->current_filter);
1886 impl->current_filter = filter;
1887 if (impl->current_filter)
1889 g_object_ref (impl->current_filter);
1890 gtk_object_sink (GTK_OBJECT (filter));
1894 gtk_option_menu_set_history (GTK_OPTION_MENU (impl->filter_option_menu),
1897 install_list_model_filter (impl);
1899 g_object_notify (G_OBJECT (impl), "filter");
1904 open_and_close (GtkTreeView *tree_view,
1905 GtkTreePath *target_path)
1907 GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
1911 path = gtk_tree_path_new ();
1912 gtk_tree_path_append_index (path, 0);
1914 gtk_tree_model_get_iter (model, &iter, path);
1918 if (gtk_tree_path_is_ancestor (path, target_path) ||
1919 gtk_tree_path_compare (path, target_path) == 0)
1921 GtkTreeIter child_iter;
1922 gtk_tree_view_expand_row (tree_view, path, FALSE);
1923 if (gtk_tree_model_iter_children (model, &child_iter, &iter))
1926 gtk_tree_path_down (path);
1931 gtk_tree_view_collapse_row (tree_view, path);
1935 GtkTreeIter parent_iter;
1936 GtkTreeIter next_iter;
1939 if (gtk_tree_model_iter_next (model, &next_iter))
1942 gtk_tree_path_next (path);
1946 if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
1950 gtk_tree_path_up (path);
1957 gtk_tree_path_free (path);
1961 filter_option_menu_changed (GtkOptionMenu *option_menu,
1962 GtkFileChooserImplDefault *impl)
1964 gint new_index = gtk_option_menu_get_history (GTK_OPTION_MENU (option_menu));
1965 GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
1967 set_current_filter (impl, new_filter);
1971 check_preview_change (GtkFileChooserImplDefault *impl)
1973 const GtkFilePath *new_path = NULL;
1975 /* Fixing preview for multiple selection involves getting the full
1976 * selection and diffing to find out what the most recently selected
1977 * file is; there is logic in GtkFileSelection that probably can
1978 * be copied. update_chooser_entry() is similar.
1980 if (impl->sort_model && !impl->select_multiple)
1982 GtkTreeSelection *selection;
1985 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
1986 if (gtk_tree_selection_get_selected (selection, NULL, &iter))
1988 GtkTreeIter child_iter;
1990 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
1991 &child_iter, &iter);
1993 new_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
1997 if (new_path != impl->preview_path &&
1998 !(new_path && impl->preview_path &&
1999 gtk_file_path_compare (new_path, impl->preview_path) == 0))
2001 if (impl->preview_path)
2002 gtk_file_path_free (impl->preview_path);
2005 impl->preview_path = gtk_file_path_copy (new_path);
2007 impl->preview_path = NULL;
2009 g_signal_emit_by_name (impl, "update-preview");
2014 tree_selection_changed (GtkTreeSelection *selection,
2015 GtkFileChooserImplDefault *impl)
2018 const GtkFilePath *file_path;
2021 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
2024 file_path = _gtk_file_system_model_get_path (impl->tree_model, &iter);
2025 if (impl->current_folder && gtk_file_path_compare (file_path, impl->current_folder) == 0)
2028 if (impl->current_folder)
2029 gtk_file_path_free (impl->current_folder);
2030 impl->current_folder = gtk_file_path_copy (file_path);
2031 _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), file_path);
2033 /* Close the tree up to only the parents of the newly selected
2034 * node and it's immediate children are visible.
2036 path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->tree_model), &iter);
2037 open_and_close (GTK_TREE_VIEW (impl->tree), path);
2038 gtk_tree_path_free (path);
2040 /* Create the new list model */
2041 set_list_model (impl);
2043 shortcuts_select_folder (impl);
2045 g_signal_emit_by_name (impl, "current-folder-changed", 0);
2047 update_chooser_entry (impl);
2048 check_preview_change (impl);
2049 bookmarks_check_add_sensitivity (impl);
2051 g_signal_emit_by_name (impl, "selection-changed", 0);
2054 /* Callback used when the selection in the shortcuts list changes */
2056 shortcuts_selection_changed (GtkTreeSelection *selection,
2057 GtkFileChooserImplDefault *impl)
2062 if (impl->changing_folder)
2065 bookmarks_check_remove_sensitivity (impl);
2067 /* Set the current folder */
2069 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
2072 gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &path, -1);
2076 /* We are on the bookmarks separator node, so unselect it */
2077 shortcuts_select_folder (impl);
2078 /* FIXME: how to make this row unselectable? */
2082 impl->changing_folder = TRUE;
2083 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), path);
2084 impl->changing_folder = FALSE;
2088 list_selection_changed (GtkTreeSelection *selection,
2089 GtkFileChooserImplDefault *impl)
2091 update_chooser_entry (impl);
2092 check_preview_change (impl);
2094 g_signal_emit_by_name (impl, "selection-changed", 0);
2097 /* Callback used when a row in the file list is activated */
2099 list_row_activated (GtkTreeView *tree_view,
2101 GtkTreeViewColumn *column,
2102 GtkFileChooserImplDefault *impl)
2104 GtkTreeIter iter, child_iter;
2105 const GtkFileInfo *info;
2107 if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
2110 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
2112 info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
2114 if (gtk_file_info_get_is_folder (info))
2116 const GtkFilePath *file_path;
2118 file_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
2119 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
2124 g_signal_emit_by_name (impl, "file-activated");
2128 entry_activate (GtkEntry *entry,
2129 GtkFileChooserImplDefault *impl)
2131 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (entry);
2132 const GtkFilePath *folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
2133 const gchar *file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
2134 GtkFilePath *new_folder = NULL;
2136 /* If the file part is non-empty, we need to figure out if it
2137 * refers to a folder within folder. We could optimize the case
2138 * here where the folder is already loaded for one of our tree models.
2140 if (file_part[0] == '\0' && gtk_file_path_compare (impl->current_folder, folder_path) != 0)
2141 new_folder = gtk_file_path_copy (folder_path);
2144 GtkFileFolder *folder = NULL;
2145 GtkFilePath *subfolder_path = NULL;
2146 GtkFileInfo *info = NULL;
2148 folder = gtk_file_system_get_folder (impl->file_system,
2150 GTK_FILE_INFO_IS_FOLDER,
2151 NULL); /* NULL-GError */
2154 subfolder_path = gtk_file_system_make_path (impl->file_system,
2157 NULL); /* NULL-GError */
2160 info = gtk_file_folder_get_info (folder,
2162 NULL); /* NULL-GError */
2164 if (info && gtk_file_info_get_is_folder (info))
2165 new_folder = gtk_file_path_copy (subfolder_path);
2168 g_object_unref (folder);
2171 gtk_file_path_free (subfolder_path);
2174 gtk_file_info_free (info);
2179 g_signal_stop_emission_by_name (entry, "activate");
2181 _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), new_folder);
2182 _gtk_file_chooser_entry_set_file_part (chooser_entry, "");
2184 gtk_file_path_free (new_folder);
2188 static const GtkFileInfo *
2189 get_list_file_info (GtkFileChooserImplDefault *impl,
2192 GtkTreeIter child_iter;
2194 gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
2198 return _gtk_file_system_model_get_info (impl->tree_model, &child_iter);
2202 tree_name_data_func (GtkTreeViewColumn *tree_column,
2203 GtkCellRenderer *cell,
2204 GtkTreeModel *tree_model,
2208 GtkFileChooserImplDefault *impl = data;
2209 const GtkFileInfo *info = _gtk_file_system_model_get_info (impl->tree_model, iter);
2214 "text", gtk_file_info_get_display_name (info),
2220 list_icon_data_func (GtkTreeViewColumn *tree_column,
2221 GtkCellRenderer *cell,
2222 GtkTreeModel *tree_model,
2226 GtkFileChooserImplDefault *impl = data;
2227 const GtkFileInfo *info = get_list_file_info (impl, iter);
2231 GtkWidget *widget = GTK_TREE_VIEW_COLUMN (tree_column)->tree_view;
2232 GdkPixbuf *pixbuf = gtk_file_info_render_icon (info, widget, ICON_SIZE);
2239 g_object_unref (pixbuf);
2243 /* Sets a cellrenderer's text, making it bold if the GtkFileInfo is a folder */
2245 set_cell_text_bold_if_folder (const GtkFileInfo *info, GtkCellRenderer *cell, const char *text)
2249 "weight", gtk_file_info_get_is_folder (info) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
2254 list_name_data_func (GtkTreeViewColumn *tree_column,
2255 GtkCellRenderer *cell,
2256 GtkTreeModel *tree_model,
2260 GtkFileChooserImplDefault *impl = data;
2261 const GtkFileInfo *info = get_list_file_info (impl, iter);
2266 set_cell_text_bold_if_folder (info, cell, gtk_file_info_get_display_name (info));
2271 list_size_data_func (GtkTreeViewColumn *tree_column,
2272 GtkCellRenderer *cell,
2273 GtkTreeModel *tree_model,
2277 GtkFileChooserImplDefault *impl = data;
2278 const GtkFileInfo *info = get_list_file_info (impl, iter);
2279 gint64 size = gtk_file_info_get_size (info);
2282 if (!info || gtk_file_info_get_is_folder (info))
2285 if (size < (gint64)1024)
2286 str = g_strdup_printf ("%d bytes", (gint)size);
2287 else if (size < (gint64)1024*1024)
2288 str = g_strdup_printf ("%.1f K", size / (1024.));
2289 else if (size < (gint64)1024*1024*1024)
2290 str = g_strdup_printf ("%.1f M", size / (1024.*1024.));
2292 str = g_strdup_printf ("%.1f G", size / (1024.*1024.*1024.));
2302 /* Tree column data callback for the file list; fetches the mtime of a file */
2304 list_mtime_data_func (GtkTreeViewColumn *tree_column,
2305 GtkCellRenderer *cell,
2306 GtkTreeModel *tree_model,
2310 GtkFileChooserImplDefault *impl;
2311 const GtkFileInfo *info;
2313 struct tm tm, now_tm;
2318 info = get_list_file_info (impl, iter);
2322 mtime = (time_t) gtk_file_info_get_modification_time (info);
2323 tm = *localtime (&mtime);
2326 now_tm = *localtime (&now);
2329 if (tm.tm_mday == now_tm.tm_mday
2330 && tm.tm_mon == now_tm.tm_mon
2331 && tm.tm_year == now_tm.tm_year)
2332 strcpy (buf, "Today");
2337 /* Days from last week */
2339 for (i = 1; i < 7; i++)
2344 then = now - i * 60 * 60 * 24;
2345 then_tm = *localtime (&then);
2347 if (tm.tm_mday == then_tm.tm_mday
2348 && tm.tm_mon == then_tm.tm_mon
2349 && tm.tm_year == then_tm.tm_year)
2352 strcpy (buf, "Yesterday");
2354 if (strftime (buf, sizeof (buf), "%A", &tm) == 0)
2355 strcpy (buf, "Unknown");
2361 /* Any other date */
2365 if (strftime (buf, sizeof (buf), "%d/%b/%Y", &tm) == 0)
2366 strcpy (buf, "Unknown");
2370 set_cell_text_bold_if_folder (info, cell, buf);
2374 _gtk_file_chooser_impl_default_new (GtkFileSystem *file_system)
2376 return g_object_new (GTK_TYPE_FILE_CHOOSER_IMPL_DEFAULT,
2377 "file-system", file_system,