Make GtkFileChooserButton use GtkBookmarksManager

It's unfortunate that now we have two instances of the bookmarks manager
for each GtkFileChooserButton; one for the button itself and one for the
underlying GtkFileChooserDefault.  We may refactor that in the future.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
This commit is contained in:
Federico Mena Quintero 2011-09-30 08:50:15 -05:00
parent 60f8411998
commit 06bfe5bd43

View File

@ -185,12 +185,13 @@ struct _GtkFileChooserButtonPrivate
gulong dialog_folder_changed_id;
gulong dialog_selection_changed_id;
gulong fs_volumes_changed_id;
gulong fs_bookmarks_changed_id;
GCancellable *dnd_select_folder_cancellable;
GCancellable *update_button_cancellable;
GSList *change_icon_theme_cancellables;
GtkBookmarksManager *bookmarks_manager;
gint icon_size;
guint8 n_special;
@ -310,8 +311,7 @@ static void update_label_and_image (GtkFileChooserButton *button)
/* Child Object Callbacks */
static void fs_volumes_changed_cb (GtkFileSystem *fs,
gpointer user_data);
static void fs_bookmarks_changed_cb (GtkFileSystem *fs,
gpointer user_data);
static void bookmarks_changed_cb (gpointer user_data);
static void combo_box_changed_cb (GtkComboBox *combo_box,
gpointer user_data);
@ -476,6 +476,9 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
gtk_widget_push_composite_child ();
/* Bookmarks manager */
priv->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, button);
/* Button */
priv->button = gtk_button_new ();
g_signal_connect (priv->button, "clicked",
@ -744,7 +747,7 @@ gtk_file_chooser_button_constructor (GType type,
model_add_volumes (button, list);
g_slist_free (list);
list = _gtk_file_system_list_bookmarks (priv->fs);
list = _gtk_bookmarks_manager_list_bookmarks (priv->bookmarks_manager);
model_add_bookmarks (button, list);
g_slist_foreach (list, (GFunc) g_object_unref, NULL);
g_slist_free (list);
@ -771,9 +774,6 @@ gtk_file_chooser_button_constructor (GType type,
priv->fs_volumes_changed_id =
g_signal_connect (priv->fs, "volumes-changed",
G_CALLBACK (fs_volumes_changed_cb), object);
priv->fs_bookmarks_changed_id =
g_signal_connect (priv->fs, "bookmarks-changed",
G_CALLBACK (fs_bookmarks_changed_cb), object);
return object;
}
@ -854,7 +854,7 @@ gtk_file_chooser_button_set_property (GObject *object,
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value);
fs_volumes_changed_cb (priv->fs, button);
fs_bookmarks_changed_cb (priv->fs, button);
bookmarks_changed_cb (button);
break;
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
@ -982,11 +982,16 @@ gtk_file_chooser_button_destroy (GtkWidget *widget)
if (priv->fs)
{
g_signal_handler_disconnect (priv->fs, priv->fs_volumes_changed_id);
g_signal_handler_disconnect (priv->fs, priv->fs_bookmarks_changed_id);
g_object_unref (priv->fs);
priv->fs = NULL;
}
if (priv->bookmarks_manager)
{
_gtk_bookmarks_manager_free (priv->bookmarks_manager);
priv->bookmarks_manager = NULL;
}
GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->destroy (widget);
}
@ -1511,7 +1516,7 @@ set_info_for_file_at_iter (GtkFileChooserButton *button,
data = g_new0 (struct SetDisplayNameData, 1);
data->button = g_object_ref (button);
data->label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
data->label = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
tree_path = gtk_tree_model_get_path (button->priv->model, iter);
data->row_ref = gtk_tree_row_reference_new (button->priv->model, tree_path);
@ -1890,7 +1895,7 @@ model_add_bookmarks (GtkFileChooserButton *button,
* If we switch to a better bookmarks file format (XBEL), we
* should use mime info to get a better icon.
*/
label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
label = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
if (!label)
label = _gtk_file_chooser_label_for_file (file);
@ -1993,7 +1998,7 @@ model_update_current_folder (GtkFileChooserButton *button,
* If we switch to a better bookmarks file format (XBEL), we
* should use mime info to get a better icon.
*/
label = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
label = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
if (!label)
label = _gtk_file_chooser_label_for_file (file);
@ -2385,7 +2390,7 @@ update_label_and_image (GtkFileChooserButton *button)
{
GdkPixbuf *pixbuf;
label_text = _gtk_file_system_get_bookmark_label (button->priv->fs, file);
label_text = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
pixbuf = gtk_icon_theme_load_icon (get_icon_theme (GTK_WIDGET (priv->image)),
"text-x-generic",
priv->icon_size, 0, NULL);
@ -2441,14 +2446,13 @@ fs_volumes_changed_cb (GtkFileSystem *fs,
}
static void
fs_bookmarks_changed_cb (GtkFileSystem *fs,
gpointer user_data)
bookmarks_changed_cb (gpointer user_data)
{
GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (user_data);
GtkFileChooserButtonPrivate *priv = button->priv;
GSList *bookmarks;
bookmarks = _gtk_file_system_list_bookmarks (fs);
bookmarks = _gtk_bookmarks_manager_list_bookmarks (priv->bookmarks_manager);
model_remove_rows (user_data,
model_get_type_position (user_data,
ROW_TYPE_BOOKMARK_SEPARATOR),