Merged from 2.4:

2004-08-18  Federico Mena Quintero  <federico@ximian.com>

	Merged from 2.4:

	Fixes #149251:

	* gtk/gtkfilechooserdefault.c: Renamed SHORTCUTS_COL_PATH to
	SHORTCUTS_COL_DATA.  Add SHORTCUTS_COL_IS_VOLUME, to determine
	easily whether the SHORTCUTS_COL_DATA points to a GtkFilePath or a
	GtkFileSystemVolume.
	(shortcuts_model_create): Create a boolean column for
	SHORTCUTS_COL_IS_VOLUME.
	(shortcuts_reload_icons): Simplify with the use of the
	SHORTCUTS_COL_IS_VOLUME column.  Don't leak the pixbuf.
	(shortcuts_insert_path): Add the SHORTCUTS_COL_IS_VOLUME data.
	(shortcuts_free_row_data): New helper function; frees the data
	columns for an iter.
	(shortcuts_remove_rows): Don't take a callback for freeing the
	data; free everything here instead.  Use
	shortcuts_free_row_data().
	(volume_remove_cb): Removed.
	(remove_bookmark_cb): Removed.
	(remove_row_cb): Make this a single generic function to delete
	rows.
	(shortcuts_add_volumes): Use remove_row_cb().
	(shortcuts_add_bookmarks): Likewise.
	(struct _GtkFileChooserDefault): Removed the
	shortcuts_current_folder_is_volume field.
	(shortcuts_add_current_folder): Oops, don't free the volume.
	(remove_current_folder_cb): Removed.
	(shortcut_find_position): Simplify through the use of the
	SHORTCUTS_COL_IS_VOLUME column.
	(remove_selected_bookmarks): Assert that we don't get a volume.
	(shortcuts_reorder): Likewise; also, plug a leak.
	(gtk_file_chooser_default_remove_shortcut_folder): Simplify
	through the use of shortcuts_remove_rows().
	(gtk_file_chooser_default_list_shortcut_folders): Assert that we
	don't get a volume.
	(shortcuts_activate_iter): Simplify.
	(home_folder_handler): Simplify by using
	shortcuts_activate_iter().
	(shortcuts_free): New function; frees all the data columns.
	(gtk_file_chooser_default_finalize): Unref the
	shortcuts_filter_model and the shortcuts model data first.
This commit is contained in:
Federico Mena Quintero 2004-08-18 16:30:58 +00:00 committed by Federico Mena Quintero
parent 9f326d612b
commit 65ddedd1ae
5 changed files with 361 additions and 171 deletions

View File

@ -1,3 +1,48 @@
2004-08-18 Federico Mena Quintero <federico@ximian.com>
Merged from 2.4:
Fixes #149251:
* gtk/gtkfilechooserdefault.c: Renamed SHORTCUTS_COL_PATH to
SHORTCUTS_COL_DATA. Add SHORTCUTS_COL_IS_VOLUME, to determine
easily whether the SHORTCUTS_COL_DATA points to a GtkFilePath or a
GtkFileSystemVolume.
(shortcuts_model_create): Create a boolean column for
SHORTCUTS_COL_IS_VOLUME.
(shortcuts_reload_icons): Simplify with the use of the
SHORTCUTS_COL_IS_VOLUME column. Don't leak the pixbuf.
(shortcuts_insert_path): Add the SHORTCUTS_COL_IS_VOLUME data.
(shortcuts_free_row_data): New helper function; frees the data
columns for an iter.
(shortcuts_remove_rows): Don't take a callback for freeing the
data; free everything here instead. Use
shortcuts_free_row_data().
(volume_remove_cb): Removed.
(remove_bookmark_cb): Removed.
(remove_row_cb): Make this a single generic function to delete
rows.
(shortcuts_add_volumes): Use remove_row_cb().
(shortcuts_add_bookmarks): Likewise.
(struct _GtkFileChooserDefault): Removed the
shortcuts_current_folder_is_volume field.
(shortcuts_add_current_folder): Oops, don't free the volume.
(remove_current_folder_cb): Removed.
(shortcut_find_position): Simplify through the use of the
SHORTCUTS_COL_IS_VOLUME column.
(remove_selected_bookmarks): Assert that we don't get a volume.
(shortcuts_reorder): Likewise; also, plug a leak.
(gtk_file_chooser_default_remove_shortcut_folder): Simplify
through the use of shortcuts_remove_rows().
(gtk_file_chooser_default_list_shortcut_folders): Assert that we
don't get a volume.
(shortcuts_activate_iter): Simplify.
(home_folder_handler): Simplify by using
shortcuts_activate_iter().
(shortcuts_free): New function; frees all the data columns.
(gtk_file_chooser_default_finalize): Unref the
shortcuts_filter_model and the shortcuts model data first.
Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org> Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org>
* gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix * gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix

View File

@ -1,3 +1,48 @@
2004-08-18 Federico Mena Quintero <federico@ximian.com>
Merged from 2.4:
Fixes #149251:
* gtk/gtkfilechooserdefault.c: Renamed SHORTCUTS_COL_PATH to
SHORTCUTS_COL_DATA. Add SHORTCUTS_COL_IS_VOLUME, to determine
easily whether the SHORTCUTS_COL_DATA points to a GtkFilePath or a
GtkFileSystemVolume.
(shortcuts_model_create): Create a boolean column for
SHORTCUTS_COL_IS_VOLUME.
(shortcuts_reload_icons): Simplify with the use of the
SHORTCUTS_COL_IS_VOLUME column. Don't leak the pixbuf.
(shortcuts_insert_path): Add the SHORTCUTS_COL_IS_VOLUME data.
(shortcuts_free_row_data): New helper function; frees the data
columns for an iter.
(shortcuts_remove_rows): Don't take a callback for freeing the
data; free everything here instead. Use
shortcuts_free_row_data().
(volume_remove_cb): Removed.
(remove_bookmark_cb): Removed.
(remove_row_cb): Make this a single generic function to delete
rows.
(shortcuts_add_volumes): Use remove_row_cb().
(shortcuts_add_bookmarks): Likewise.
(struct _GtkFileChooserDefault): Removed the
shortcuts_current_folder_is_volume field.
(shortcuts_add_current_folder): Oops, don't free the volume.
(remove_current_folder_cb): Removed.
(shortcut_find_position): Simplify through the use of the
SHORTCUTS_COL_IS_VOLUME column.
(remove_selected_bookmarks): Assert that we don't get a volume.
(shortcuts_reorder): Likewise; also, plug a leak.
(gtk_file_chooser_default_remove_shortcut_folder): Simplify
through the use of shortcuts_remove_rows().
(gtk_file_chooser_default_list_shortcut_folders): Assert that we
don't get a volume.
(shortcuts_activate_iter): Simplify.
(home_folder_handler): Simplify by using
shortcuts_activate_iter().
(shortcuts_free): New function; frees all the data columns.
(gtk_file_chooser_default_finalize): Unref the
shortcuts_filter_model and the shortcuts model data first.
Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org> Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org>
* gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix * gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix

View File

@ -1,3 +1,48 @@
2004-08-18 Federico Mena Quintero <federico@ximian.com>
Merged from 2.4:
Fixes #149251:
* gtk/gtkfilechooserdefault.c: Renamed SHORTCUTS_COL_PATH to
SHORTCUTS_COL_DATA. Add SHORTCUTS_COL_IS_VOLUME, to determine
easily whether the SHORTCUTS_COL_DATA points to a GtkFilePath or a
GtkFileSystemVolume.
(shortcuts_model_create): Create a boolean column for
SHORTCUTS_COL_IS_VOLUME.
(shortcuts_reload_icons): Simplify with the use of the
SHORTCUTS_COL_IS_VOLUME column. Don't leak the pixbuf.
(shortcuts_insert_path): Add the SHORTCUTS_COL_IS_VOLUME data.
(shortcuts_free_row_data): New helper function; frees the data
columns for an iter.
(shortcuts_remove_rows): Don't take a callback for freeing the
data; free everything here instead. Use
shortcuts_free_row_data().
(volume_remove_cb): Removed.
(remove_bookmark_cb): Removed.
(remove_row_cb): Make this a single generic function to delete
rows.
(shortcuts_add_volumes): Use remove_row_cb().
(shortcuts_add_bookmarks): Likewise.
(struct _GtkFileChooserDefault): Removed the
shortcuts_current_folder_is_volume field.
(shortcuts_add_current_folder): Oops, don't free the volume.
(remove_current_folder_cb): Removed.
(shortcut_find_position): Simplify through the use of the
SHORTCUTS_COL_IS_VOLUME column.
(remove_selected_bookmarks): Assert that we don't get a volume.
(shortcuts_reorder): Likewise; also, plug a leak.
(gtk_file_chooser_default_remove_shortcut_folder): Simplify
through the use of shortcuts_remove_rows().
(gtk_file_chooser_default_list_shortcut_folders): Assert that we
don't get a volume.
(shortcuts_activate_iter): Simplify.
(home_folder_handler): Simplify by using
shortcuts_activate_iter().
(shortcuts_free): New function; frees all the data columns.
(gtk_file_chooser_default_finalize): Unref the
shortcuts_filter_model and the shortcuts model data first.
Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org> Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org>
* gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix * gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix

View File

@ -1,3 +1,48 @@
2004-08-18 Federico Mena Quintero <federico@ximian.com>
Merged from 2.4:
Fixes #149251:
* gtk/gtkfilechooserdefault.c: Renamed SHORTCUTS_COL_PATH to
SHORTCUTS_COL_DATA. Add SHORTCUTS_COL_IS_VOLUME, to determine
easily whether the SHORTCUTS_COL_DATA points to a GtkFilePath or a
GtkFileSystemVolume.
(shortcuts_model_create): Create a boolean column for
SHORTCUTS_COL_IS_VOLUME.
(shortcuts_reload_icons): Simplify with the use of the
SHORTCUTS_COL_IS_VOLUME column. Don't leak the pixbuf.
(shortcuts_insert_path): Add the SHORTCUTS_COL_IS_VOLUME data.
(shortcuts_free_row_data): New helper function; frees the data
columns for an iter.
(shortcuts_remove_rows): Don't take a callback for freeing the
data; free everything here instead. Use
shortcuts_free_row_data().
(volume_remove_cb): Removed.
(remove_bookmark_cb): Removed.
(remove_row_cb): Make this a single generic function to delete
rows.
(shortcuts_add_volumes): Use remove_row_cb().
(shortcuts_add_bookmarks): Likewise.
(struct _GtkFileChooserDefault): Removed the
shortcuts_current_folder_is_volume field.
(shortcuts_add_current_folder): Oops, don't free the volume.
(remove_current_folder_cb): Removed.
(shortcut_find_position): Simplify through the use of the
SHORTCUTS_COL_IS_VOLUME column.
(remove_selected_bookmarks): Assert that we don't get a volume.
(shortcuts_reorder): Likewise; also, plug a leak.
(gtk_file_chooser_default_remove_shortcut_folder): Simplify
through the use of shortcuts_remove_rows().
(gtk_file_chooser_default_list_shortcut_folders): Assert that we
don't get a volume.
(shortcuts_activate_iter): Simplify.
(home_folder_handler): Simplify by using
shortcuts_activate_iter().
(shortcuts_free): New function; frees all the data columns.
(gtk_file_chooser_default_finalize): Unref the
shortcuts_filter_model and the shortcuts model data first.
Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org> Wed Aug 18 08:31:17 2004 Manish Singh <yosh@gimp.org>
* gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix * gtk/gtkiconview.c: Applied patch from Olivier Andrieu to fix

View File

@ -176,7 +176,6 @@ struct _GtkFileChooserDefault
guint list_sort_ascending : 1; guint list_sort_ascending : 1;
guint changing_folder : 1; guint changing_folder : 1;
guint shortcuts_current_folder_active : 1; guint shortcuts_current_folder_active : 1;
guint shortcuts_current_folder_is_volume : 1;
#if 0 #if 0
guint shortcuts_drag_outside : 1; guint shortcuts_drag_outside : 1;
@ -198,7 +197,8 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum { enum {
SHORTCUTS_COL_PIXBUF, SHORTCUTS_COL_PIXBUF,
SHORTCUTS_COL_NAME, SHORTCUTS_COL_NAME,
SHORTCUTS_COL_PATH, SHORTCUTS_COL_DATA,
SHORTCUTS_COL_IS_VOLUME,
SHORTCUTS_COL_REMOVABLE, SHORTCUTS_COL_REMOVABLE,
SHORTCUTS_COL_PIXBUF_VISIBLE, SHORTCUTS_COL_PIXBUF_VISIBLE,
SHORTCUTS_COL_NUM_COLUMNS SHORTCUTS_COL_NUM_COLUMNS
@ -621,12 +621,68 @@ gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
gtk_box_set_spacing (GTK_BOX (impl), 12); gtk_box_set_spacing (GTK_BOX (impl), 12);
} }
/* Frees the data columns for the specified iter in the shortcuts model*/
static void
shortcuts_free_row_data (GtkFileChooserDefault *impl,
GtkTreeIter *iter)
{
gpointer col_data;
gboolean is_volume;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1);
if (!col_data)
return;
if (is_volume)
{
GtkFileSystemVolume *volume;
volume = col_data;
gtk_file_system_volume_free (impl->file_system, volume);
}
else
{
GtkFilePath *path;
path = col_data;
gtk_file_path_free (path);
}
}
/* Frees all the data columns in the shortcuts model */
static void
shortcuts_free (GtkFileChooserDefault *impl)
{
GtkTreeIter iter;
if (!impl->shortcuts_model)
return;
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
do
{
shortcuts_free_row_data (impl, &iter);
}
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
g_object_unref (impl->shortcuts_model);
impl->shortcuts_model = NULL;
}
static void static void
gtk_file_chooser_default_finalize (GObject *object) gtk_file_chooser_default_finalize (GObject *object)
{ {
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object); GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
GSList *l; GSList *l;
if (impl->shortcuts_filter_model)
g_object_unref (impl->shortcuts_filter_model);
shortcuts_free (impl);
g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id); g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
impl->volumes_changed_id = 0; impl->volumes_changed_id = 0;
g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id); g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
@ -658,12 +714,6 @@ gtk_file_chooser_default_finalize (GObject *object)
if (impl->browse_files_model) if (impl->browse_files_model)
g_object_unref (impl->browse_files_model); g_object_unref (impl->browse_files_model);
if (impl->shortcuts_model)
g_object_unref (impl->shortcuts_model);
if (impl->shortcuts_filter_model)
g_object_unref (impl->shortcuts_filter_model);
if (impl->sort_model) if (impl->sort_model)
g_object_unref (impl->sort_model); g_object_unref (impl->sort_model);
@ -880,34 +930,25 @@ static void
shortcuts_reload_icons (GtkFileChooserDefault *impl) shortcuts_reload_icons (GtkFileChooserDefault *impl)
{ {
GtkTreeIter iter; GtkTreeIter iter;
int i;
int bookmarks_separator_idx;
int current_folder_separator_idx;
int volumes_idx;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
return; return;
bookmarks_separator_idx = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
volumes_idx = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
i = 0;
do { do {
gpointer data; gpointer data;
gboolean is_volume;
gboolean pixbuf_visible; gboolean pixbuf_visible;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
SHORTCUTS_COL_PATH, &data, SHORTCUTS_COL_DATA, &data,
SHORTCUTS_COL_IS_VOLUME &is_volume,
SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible, SHORTCUTS_COL_PIXBUF_VISIBLE, &pixbuf_visible,
-1); -1);
if (!pixbuf_visible || !data) if (pixbuf_visible && data)
goto next_iter; {
if (is_volume)
if (i >= volumes_idx && i < volumes_idx + impl->num_volumes)
{ {
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
@ -927,10 +968,9 @@ shortcuts_reload_icons (GtkFileChooserDefault *impl)
gtk_list_store_set (impl->shortcuts_model, &iter, gtk_list_store_set (impl->shortcuts_model, &iter,
SHORTCUTS_COL_PIXBUF, pixbuf, SHORTCUTS_COL_PIXBUF, pixbuf,
-1); -1);
if (pixbuf)
g_object_unref (pixbuf); g_object_unref (pixbuf);
}
next_iter:
i++;
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter)); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
} }
@ -1058,7 +1098,8 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
SHORTCUTS_COL_PIXBUF, pixbuf, SHORTCUTS_COL_PIXBUF, pixbuf,
SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE, SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
SHORTCUTS_COL_NAME, label_copy, SHORTCUTS_COL_NAME, label_copy,
SHORTCUTS_COL_PATH, data, SHORTCUTS_COL_DATA, data,
SHORTCUTS_COL_IS_VOLUME, is_volume,
SHORTCUTS_COL_REMOVABLE, removable, SHORTCUTS_COL_REMOVABLE, removable,
-1); -1);
@ -1204,14 +1245,11 @@ shortcuts_get_index (GtkFileChooserDefault *impl,
return n; return n;
} }
typedef void (* RemoveFunc) (GtkFileChooserDefault *impl, gpointer data);
/* Removes the specified number of rows from the shortcuts list */ /* Removes the specified number of rows from the shortcuts list */
static void static void
shortcuts_remove_rows (GtkFileChooserDefault *impl, shortcuts_remove_rows (GtkFileChooserDefault *impl,
int start_row, int start_row,
int n_rows, int n_rows)
RemoveFunc remove_fn)
{ {
GtkTreePath *path; GtkTreePath *path;
@ -1220,33 +1258,17 @@ shortcuts_remove_rows (GtkFileChooserDefault *impl,
for (; n_rows; n_rows--) for (; n_rows; n_rows--)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gpointer data;
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path)) if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
g_assert_not_reached (); g_assert_not_reached ();
if (remove_fn) shortcuts_free_row_data (impl, &iter);
{
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
(* remove_fn) (impl, data);
}
gtk_list_store_remove (impl->shortcuts_model, &iter); gtk_list_store_remove (impl->shortcuts_model, &iter);
} }
gtk_tree_path_free (path); gtk_tree_path_free (path);
} }
/* Used from shortcuts_remove_rows() in shortcuts_add_volumes() */
static void
volume_remove_cb (GtkFileChooserDefault *impl, gpointer data)
{
GtkFileSystemVolume *volume;
volume = data;
gtk_file_system_volume_free (impl->file_system, volume);
}
/* Adds all the file system volumes to the shortcuts model */ /* Adds all the file system volumes to the shortcuts model */
static void static void
shortcuts_add_volumes (GtkFileChooserDefault *impl) shortcuts_add_volumes (GtkFileChooserDefault *impl)
@ -1260,7 +1282,7 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
impl->changing_folder = TRUE; impl->changing_folder = TRUE;
start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES); start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
shortcuts_remove_rows (impl, start_row, impl->num_volumes, volume_remove_cb); shortcuts_remove_rows (impl, start_row, impl->num_volumes);
impl->num_volumes = 0; impl->num_volumes = 0;
list = gtk_file_system_list_volumes (impl->file_system); list = gtk_file_system_list_volumes (impl->file_system);
@ -1301,16 +1323,6 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
impl->changing_folder = old_changing_folders; impl->changing_folder = old_changing_folders;
} }
/* Used from shortcuts_remove_rows() */
static void
remove_bookmark_cb (GtkFileChooserDefault *impl, gpointer data)
{
GtkFilePath *path;
path = data;
gtk_file_path_free (path);
}
/* Inserts a separator node in the shortcuts list */ /* Inserts a separator node in the shortcuts list */
static void static void
shortcuts_insert_separator (GtkFileChooserDefault *impl, shortcuts_insert_separator (GtkFileChooserDefault *impl,
@ -1326,7 +1338,7 @@ shortcuts_insert_separator (GtkFileChooserDefault *impl,
SHORTCUTS_COL_PIXBUF, NULL, SHORTCUTS_COL_PIXBUF, NULL,
SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE, SHORTCUTS_COL_PIXBUF_VISIBLE, FALSE,
SHORTCUTS_COL_NAME, NULL, SHORTCUTS_COL_NAME, NULL,
SHORTCUTS_COL_PATH, NULL, SHORTCUTS_COL_DATA, NULL,
-1); -1);
} }
@ -1341,13 +1353,9 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
impl->changing_folder = TRUE; impl->changing_folder = TRUE;
if (impl->num_bookmarks > 0) if (impl->num_bookmarks > 0)
{
shortcuts_remove_rows (impl, shortcuts_remove_rows (impl,
shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR), shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR),
impl->num_bookmarks + 1, impl->num_bookmarks + 1);
remove_bookmark_cb);
}
bookmarks = gtk_file_system_list_bookmarks (impl->file_system); bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks); impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks);
@ -1398,20 +1406,17 @@ shortcuts_add_current_folder (GtkFileChooserDefault *impl)
strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0) strcmp (gtk_file_path_get_string (base_path), gtk_file_path_get_string (impl->current_folder)) == 0)
{ {
success = shortcuts_insert_path (impl, pos, TRUE, volume, NULL, NULL, FALSE, NULL); success = shortcuts_insert_path (impl, pos, TRUE, volume, NULL, NULL, FALSE, NULL);
impl->shortcuts_current_folder_is_volume = TRUE; if (!success)
gtk_file_system_volume_free (impl->file_system, volume);
} }
else else
{
success = shortcuts_insert_path (impl, pos, FALSE, NULL, impl->current_folder, NULL, FALSE, NULL); success = shortcuts_insert_path (impl, pos, FALSE, NULL, impl->current_folder, NULL, FALSE, NULL);
impl->shortcuts_current_folder_is_volume = FALSE;
}
if (volume) if (base_path)
gtk_file_system_volume_free (impl->file_system, volume);
gtk_file_path_free (base_path); gtk_file_path_free (base_path);
if (!success) if (!success)
shortcuts_remove_rows (impl, pos - 1, 1, NULL); /* remove the separator */ shortcuts_remove_rows (impl, pos - 1, 1); /* remove the separator */
impl->shortcuts_current_folder_active = success; impl->shortcuts_current_folder_active = success;
} }
@ -1420,17 +1425,6 @@ shortcuts_add_current_folder (GtkFileChooserDefault *impl)
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos); gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
} }
/* Used from shortcuts_remove_rows() in shortcuts_update_current_folder() */
static void
remove_current_folder_cb (GtkFileChooserDefault *impl,
gpointer data)
{
if (impl->shortcuts_current_folder_is_volume)
gtk_file_system_volume_free (impl->file_system, data);
else
gtk_file_path_free (data);
}
/* Updates the current folder row in the shortcuts model */ /* Updates the current folder row in the shortcuts model */
static void static void
shortcuts_update_current_folder (GtkFileChooserDefault *impl) shortcuts_update_current_folder (GtkFileChooserDefault *impl)
@ -1441,7 +1435,7 @@ shortcuts_update_current_folder (GtkFileChooserDefault *impl)
if (impl->shortcuts_current_folder_active) if (impl->shortcuts_current_folder_active)
{ {
shortcuts_remove_rows (impl, pos, 2, remove_current_folder_cb); shortcuts_remove_rows (impl, pos, 2);
impl->shortcuts_current_folder_active = FALSE; impl->shortcuts_current_folder_active = FALSE;
} }
@ -1479,6 +1473,7 @@ shortcuts_model_create (GtkFileChooserDefault *impl)
GDK_TYPE_PIXBUF, /* pixbuf */ GDK_TYPE_PIXBUF, /* pixbuf */
G_TYPE_STRING, /* name */ G_TYPE_STRING, /* name */
G_TYPE_POINTER, /* path or volume */ G_TYPE_POINTER, /* path or volume */
G_TYPE_BOOLEAN, /* is the previous column a volume? */
G_TYPE_BOOLEAN, /* removable */ G_TYPE_BOOLEAN, /* removable */
G_TYPE_BOOLEAN); /* pixbuf cell visibility */ G_TYPE_BOOLEAN); /* pixbuf cell visibility */
@ -1664,35 +1659,32 @@ shortcut_find_position (GtkFileChooserDefault *impl,
{ {
GtkTreeIter iter; GtkTreeIter iter;
int i; int i;
int bookmarks_separator_idx;
int current_folder_separator_idx; int current_folder_separator_idx;
int volumes_idx;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter)) if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
return -1; return -1;
bookmarks_separator_idx = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR); current_folder_separator_idx = shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR);
volumes_idx = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
i = 0;
for (i = 0; i < current_folder_separator_idx; i++) for (i = 0; i < current_folder_separator_idx; i++)
{ {
gpointer data; gpointer col_data;
gboolean is_volume;
if (i == bookmarks_separator_idx) gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
goto next_iter; SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1);
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1); if (col_data)
{
if (i >= volumes_idx && i < volumes_idx + impl->num_volumes) if (is_volume)
{ {
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
GtkFilePath *base_path; GtkFilePath *base_path;
gboolean exists; gboolean exists;
volume = data; volume = col_data;
base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume); base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
exists = strcmp (gtk_file_path_get_string (path), exists = strcmp (gtk_file_path_get_string (path),
@ -1706,13 +1698,13 @@ shortcut_find_position (GtkFileChooserDefault *impl,
{ {
GtkFilePath *model_path; GtkFilePath *model_path;
model_path = data; model_path = col_data;
if (model_path && gtk_file_path_compare (model_path, path) == 0) if (model_path && gtk_file_path_compare (model_path, path) == 0)
return i; return i;
} }
}
next_iter:
gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter); gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
} }
@ -1821,6 +1813,8 @@ static void
remove_selected_bookmarks (GtkFileChooserDefault *impl) remove_selected_bookmarks (GtkFileChooserDefault *impl)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gpointer col_data;
gboolean is_volume;
GtkFilePath *path; GtkFilePath *path;
gboolean removable; gboolean removable;
GError *error; GError *error;
@ -1829,11 +1823,18 @@ remove_selected_bookmarks (GtkFileChooserDefault *impl)
return; return;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
SHORTCUTS_COL_PATH, &path, SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_REMOVABLE, &removable, -1); SHORTCUTS_COL_IS_VOLUME, &is_volume,
SHORTCUTS_COL_REMOVABLE, &removable,
-1);
g_assert (col_data != NULL);
g_assert (!is_volume);
if (!removable) if (!removable)
return; return;
path = col_data;
error = NULL; error = NULL;
if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error)) if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
{ {
@ -2463,6 +2464,8 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
int new_position) int new_position)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gpointer col_data;
gboolean is_volume;
GtkTreePath *path; GtkTreePath *path;
int old_position; int old_position;
int bookmarks_index; int bookmarks_index;
@ -2484,8 +2487,13 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
g_assert (old_position >= 0 && old_position < impl->num_bookmarks); g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
SHORTCUTS_COL_PATH, &file_path, SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1); -1);
g_assert (col_data != NULL);
g_assert (!is_volume);
file_path = col_data;
file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */ file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
/* Remove the path from the old position and insert it in the new one */ /* Remove the path from the old position and insert it in the new one */
@ -2494,7 +2502,7 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
new_position--; new_position--;
if (old_position == new_position) if (old_position == new_position)
return; goto out;
error = NULL; error = NULL;
if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error)) if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
@ -2502,6 +2510,8 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
else else
error_could_not_add_bookmark_dialog (impl, file_path_copy, error); error_could_not_add_bookmark_dialog (impl, file_path_copy, error);
out:
gtk_file_path_free (file_path_copy); gtk_file_path_free (file_path_copy);
} }
@ -4614,16 +4624,21 @@ gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
for (i = 0; i < impl->num_shortcuts; i++) for (i = 0; i < impl->num_shortcuts; i++)
{ {
gpointer col_data;
gboolean is_volume;
GtkFilePath *shortcut; GtkFilePath *shortcut;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1); gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
g_assert (shortcut != NULL); SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1);
g_assert (col_data != NULL);
g_assert (!is_volume);
shortcut = col_data;
if (gtk_file_path_compare (shortcut, path) == 0) if (gtk_file_path_compare (shortcut, path) == 0)
{ {
/* The other columns are freed by the GtkTreeStore */ shortcuts_remove_rows (impl, pos + i, 1);
gtk_file_path_free (shortcut);
gtk_list_store_remove (impl->shortcuts_model, &iter);
impl->num_shortcuts--; impl->num_shortcuts--;
return TRUE; return TRUE;
} }
@ -4665,11 +4680,18 @@ gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
for (i = 0; i < impl->num_shortcuts; i++) for (i = 0; i < impl->num_shortcuts; i++)
{ {
gpointer col_data;
gboolean is_volume;
GtkFilePath *shortcut; GtkFilePath *shortcut;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1); gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
g_assert (shortcut != NULL); SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1);
g_assert (col_data != NULL);
g_assert (!is_volume);
shortcut = col_data;
list = g_slist_prepend (list, gtk_file_path_copy (shortcut)); list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
if (i != impl->num_shortcuts - 1) if (i != impl->num_shortcuts - 1)
@ -5089,37 +5111,29 @@ static void
shortcuts_activate_iter (GtkFileChooserDefault *impl, shortcuts_activate_iter (GtkFileChooserDefault *impl,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
GtkTreePath *path; gpointer col_data;
int item_num; gboolean is_volume;
gpointer data;
int start_row;
path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), iter); gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter,
g_assert (path != NULL); SHORTCUTS_COL_DATA, &col_data,
SHORTCUTS_COL_IS_VOLUME, &is_volume,
-1);
item_num = *gtk_tree_path_get_indices (path); if (!col_data)
gtk_tree_path_free (path); return; /* We are on a separator */
if (item_num == shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR) if (is_volume)
|| item_num == shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER_SEPARATOR))
return;
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), iter, SHORTCUTS_COL_PATH, &data, -1);
start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
if ((item_num >= start_row && item_num < start_row + impl->num_volumes)
|| (item_num == shortcuts_get_index (impl, SHORTCUTS_CURRENT_FOLDER) && impl->shortcuts_current_folder_is_volume))
{ {
GtkFileSystemVolume *volume; GtkFileSystemVolume *volume;
volume = data; volume = col_data;
shortcuts_activate_volume (impl, volume); shortcuts_activate_volume (impl, volume);
} }
else else
{ {
const GtkFilePath *file_path; const GtkFilePath *file_path;
file_path = data; file_path = col_data;
change_folder_and_display_error (impl, file_path); change_folder_and_display_error (impl, file_path);
} }
} }
@ -5706,7 +5720,6 @@ home_folder_handler (GtkFileChooserDefault *impl)
{ {
int pos; int pos;
GtkTreeIter iter; GtkTreeIter iter;
GtkFilePath *path;
if (!impl->has_home) if (!impl->has_home)
return; /* Should we put up an error dialog? */ return; /* Should we put up an error dialog? */
@ -5715,10 +5728,7 @@ home_folder_handler (GtkFileChooserDefault *impl)
if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos)) if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
g_assert_not_reached (); g_assert_not_reached ();
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &path, -1); shortcuts_activate_iter (impl, &iter);
g_assert (path != NULL);
change_folder_and_display_error (impl, path);
} }