Commit f5874fd2 authored by Darin Adler's avatar Darin Adler
Browse files

Simplified calls to bonobo_object_ref/unref.

	* Many files:
	Simplified calls to bonobo_object_ref/unref.

	* components/history/nautilus-history-view.c: (update_history):
	Fixed so that a history update while one is already in progress
	will work properly.

	* libnautilus/nautilus-view.c:
	(remove_listener): New.
	(update_listener): Renamed from nautilus_view_set_frame, made it
	handle various cases better. Fixed leak of property bag.
	(forget_cached_view_frame): New.
	(nautilus_view_set_frame_callback): Use new forget_cached_view_frame
	and update_listener.
	(nautilus_view_construct_from_bonobo_control): Use
	g_signal_connect_object.  Not sure if this is better, since they
	are part of the same aggregate.
	(nautilus_view_finalize): Use new forget_cached_view_frame and
	remove_listener.
	(nautilus_view_dispose): Use new forget_cached_view_frame and
	remove_listener.
	(nautilus_view_get_view_frame): Fixed leak of control frame.
	(nautilus_view_set_listener_mask): Simplified, and made it work even
	if you call it multiple times, by calling new update_listener.

	* libnautilus-private/nautilus-icon-canvas-item.c:
	(create_label_layout): Handle NULL font_name case just in case.
	* libnautilus-private/nautilus-icon-container.c:
	(nautilus_icon_container_set_zoom_level): Use
	invalidate_label_sizes instead of setting update_icon_font.
	(nautilus_icon_container_set_font_name): Do nothing if font name
	doesn't change. If it does, use invalidate_label_sizes rather than
	setting update_icon_font.
	(nautilus_icon_container_set_font_size_table): Only redraw if font
	size changes. Also, use invalidate_label_sizes rather than setting
	update_icon_font.

	* libnautilus-private/nautilus-directory.c:
	(add_preferences_callbacks):
	* libnautilus-private/nautilus-icon-factory.c: (get_icon_factory):
	Initialize global preferences as needed.

	* src/file-manager/fm-icon-view.c: (fm_icon_view_finalize):
	* src/file-manager/fm-search-list-view.c: (real_destroy):
	* src/nautilus-application.c: (nautilus_application_destroy),
	(nautilus_application_create_window),
	(nautilus_application_class_init):
	* src/nautilus-main.c: (main):

	* src/nautilus-view-frame.c: (create_corba_objects): Fix property
	bag leak.
parent 8f111d13
2002-02-26 Darin Adler <darin@bentspoon.com>
* Many files:
Simplified calls to bonobo_object_ref/unref.
* components/history/nautilus-history-view.c: (update_history):
Fixed so that a history update while one is already in progress
will work properly.
* libnautilus/nautilus-view.c:
(remove_listener): New.
(update_listener): Renamed from nautilus_view_set_frame, made it
handle various cases better. Fixed leak of property bag.
(forget_cached_view_frame): New.
(nautilus_view_set_frame_callback): Use new forget_cached_view_frame
and update_listener.
(nautilus_view_construct_from_bonobo_control): Use
g_signal_connect_object. Not sure if this is better, since they
are part of the same aggregate.
(nautilus_view_finalize): Use new forget_cached_view_frame and
remove_listener.
(nautilus_view_dispose): Use new forget_cached_view_frame and
remove_listener.
(nautilus_view_get_view_frame): Fixed leak of control frame.
(nautilus_view_set_listener_mask): Simplified, and made it work even
if you call it multiple times, by calling new update_listener.
* libnautilus-private/nautilus-icon-canvas-item.c:
(create_label_layout): Handle NULL font_name case just in case.
* libnautilus-private/nautilus-icon-container.c:
(nautilus_icon_container_set_zoom_level): Use
invalidate_label_sizes instead of setting update_icon_font.
(nautilus_icon_container_set_font_name): Do nothing if font name
doesn't change. If it does, use invalidate_label_sizes rather than
setting update_icon_font.
(nautilus_icon_container_set_font_size_table): Only redraw if font
size changes. Also, use invalidate_label_sizes rather than setting
update_icon_font.
* libnautilus-private/nautilus-directory.c:
(add_preferences_callbacks):
* libnautilus-private/nautilus-icon-factory.c: (get_icon_factory):
Initialize global preferences as needed.
* src/file-manager/fm-icon-view.c: (fm_icon_view_finalize):
* src/file-manager/fm-search-list-view.c: (real_destroy):
* src/nautilus-application.c: (nautilus_application_destroy),
(nautilus_application_create_window),
(nautilus_application_class_init):
* src/nautilus-main.c: (main):
* src/nautilus-view-frame.c: (create_corba_objects): Fix property
bag leak.
2002-02-26 Michael Meeks <michael@ximian.com>
* components/history/nautilus-history-view.c
......@@ -25,6 +79,8 @@
that makes us return the right name, rather than returning
an already-freed pointer.
=== nautilus 1.1.6 ===
2002-02-25 Darin Adler <darin@bentspoon.com>
* configure.in: Bump version.
......
......@@ -117,7 +117,7 @@ main (int argc, char *argv[])
} while (object_count > 0);
/* Let the factory go. */
bonobo_object_unref (BONOBO_OBJECT (factory));
bonobo_object_unref (factory);
gnome_vfs_shutdown ();
......
......@@ -93,10 +93,7 @@ nautilus_adapter_control_embed_strategy_destroy (GtkObject *object)
strategy = NAUTILUS_ADAPTER_CONTROL_EMBED_STRATEGY (object);
if (strategy->details->control_frame != NULL) {
bonobo_object_unref (BONOBO_OBJECT (strategy->details->control_frame));
}
bonobo_object_unref (strategy->details->control_frame);
g_free (strategy->details);
EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
......
......@@ -91,11 +91,7 @@ nautilus_adapter_control_factory_embed_strategy_destroy (GtkObject *object)
strategy = NAUTILUS_ADAPTER_CONTROL_FACTORY_EMBED_STRATEGY (object);
if (strategy->details->control_frame != NULL) {
bonobo_object_unref (BONOBO_OBJECT (strategy->details->control_frame));
strategy->details->control_frame = NULL;
}
bonobo_object_unref (strategy->details->control_frame);
g_free (strategy->details);
strategy->details = NULL;
......
......@@ -89,7 +89,7 @@ static void
adapter_object_weak_notify (gpointer server,
GObject *adapter)
{
bonobo_object_unref (BONOBO_OBJECT (server));
bonobo_object_unref (server);
}
......@@ -108,7 +108,7 @@ impl_Nautilus_ComponentAdapterFactory_create_adapter (PortableServer_Servant se
if (adapter == NULL) {
return CORBA_OBJECT_NIL;
} else {
bonobo_object_ref (BONOBO_OBJECT (factory_servant));
bonobo_object_ref (factory_servant);
adapter_view = nautilus_adapter_get_nautilus_view (adapter);
g_object_weak_ref (G_OBJECT (adapter_view),
......
......@@ -193,12 +193,8 @@ nautilus_hardware_view_destroy (GtkObject *object)
hardware_view = NAUTILUS_HARDWARE_VIEW (object);
/* free the property bag */
if (hardware_view->details->property_bag != NULL) {
bonobo_object_unref (BONOBO_OBJECT (hardware_view->details->property_bag));
}
bonobo_object_unref (hardware_view->details->property_bag);
/* remove the timer task */
if (hardware_view->details->timer_task != 0) {
gtk_timeout_remove (hardware_view->details->timer_task);
}
......
......@@ -29,7 +29,6 @@
#include <bonobo/bonobo-ui-util.h>
#include <eel/eel-debug.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <gtk/gtkcellrendererpixbuf.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkliststore.h>
......@@ -39,7 +38,6 @@
#include <gtk/gtkscrolledwindow.h>
#include <libgnome/gnome-macros.h>
#include <libnautilus-private/nautilus-bookmark.h>
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus/nautilus-view-standard-main.h>
#define FACTORY_IID "OAFIID:nautilus_history_view_factory:912d6634-d18f-40b6-bb83-bdfe16f1d15e"
......@@ -53,13 +51,9 @@
typedef struct {
NautilusView parent;
GtkTreeView *treeview;
GtkListStore *store;
GtkTreeSelection *selection;
gboolean updating_history;
int press_row;
gboolean *external_destroyed_flag;
int selection_changed_id;
GtkTreeView *tree_view;
guint selection_changed_id;
gboolean *stop_updating_history;
} NautilusHistoryView;
typedef struct {
......@@ -71,9 +65,9 @@ enum {
HISTORY_VIEW_COLUMN_NAME,
HISTORY_VIEW_COLUMN_BOOKMARK,
HISTORY_VIEW_COLUMN_COUNT,
} HistoryViewColumnType;
};
static GtkType nautilus_history_view_get_type (void);
static GType nautilus_history_view_get_type (void);
BONOBO_CLASS_BOILERPLATE (NautilusHistoryView, nautilus_history_view,
NautilusView, NAUTILUS_TYPE_VIEW)
......@@ -82,38 +76,31 @@ static void
update_history (NautilusHistoryView *view,
const Nautilus_History *history)
{
GtkTreeView *treeview;
GtkListStore *store;
GtkTreeSelection *selection;
NautilusBookmark *bookmark;
Nautilus_HistoryItem *item;
GdkPixbuf *pixbuf;
guint i;
gboolean destroyed_flag;
gboolean stop_updating_history;
GtkTreeIter iter;
/* FIXME: We'll end up with old history if this happens. */
if (view->updating_history) {
return;
}
treeview = view->treeview;
store = view->store;
selection = view->selection;
/* Set up a local boolean so we can detect that the view has
* been destroyed. We can't ask the view itself because once
* it's destroyed it's pointer is a pointer to freed storage.
*/
/* FIXME: We can't just keep an extra ref to the view as we
* normally would because of a bug in Bonobo that means a
* BonoboControl must not outlast its BonoboFrame
* BonoboControl must not outlast its BonoboControlFrame
* (NautilusHistoryView is a BonoboControl).
*/
destroyed_flag = FALSE;
view->external_destroyed_flag = &destroyed_flag;
if (view->stop_updating_history != NULL) {
*view->stop_updating_history = TRUE;
}
stop_updating_history = FALSE;
view->stop_updating_history = &stop_updating_history;
view->updating_history = TRUE;
store = GTK_LIST_STORE (gtk_tree_view_get_model (view->tree_view));
gtk_list_store_clear (store);
......@@ -129,9 +116,10 @@ update_history (NautilusHistoryView *view,
* in practice, none of the other calls used here have
* that problem.
*/
if (destroyed_flag) {
if (stop_updating_history) {
return;
}
pixbuf = bonobo_ui_util_xml_to_pixbuf (item->icon);
gtk_list_store_append (store, &iter);
......@@ -144,18 +132,17 @@ update_history (NautilusHistoryView *view,
if (pixbuf != NULL) {
g_object_unref (pixbuf);
}
}
selection = GTK_TREE_SELECTION (gtk_tree_view_get_selection (view->tree_view));
g_signal_handler_block (selection, view->selection_changed_id);
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) {
if (gtk_tree_model_get_iter_root (GTK_TREE_MODEL (store), &iter)) {
gtk_tree_selection_select_iter (selection, &iter);
}
g_signal_handler_unblock (selection, view->selection_changed_id);
g_signal_handler_unblock (selection, view->selection_changed_id);
view->updating_history = FALSE;
view->external_destroyed_flag = NULL;
view->stop_updating_history = NULL;
}
static void
......@@ -173,7 +160,6 @@ on_selection_changed (GtkTreeSelection *selection,
gpointer user_data)
{
NautilusHistoryView *view;
GtkListStore *store;
GtkTreeIter iter;
NautilusBookmark *bookmark;
char *uri;
......@@ -182,17 +168,13 @@ on_selection_changed (GtkTreeSelection *selection,
g_return_if_fail (NAUTILUS_IS_HISTORY_VIEW (user_data));
view = NAUTILUS_HISTORY_VIEW (user_data);
store = view->store;
/* If this function returns FALSE, we don't have any rows selected */
if (!gtk_tree_selection_get_selected (selection,
NULL,
&iter)) {
if (! gtk_tree_selection_get_selected (selection, NULL, &iter)) {
return;
}
gtk_tree_model_get (GTK_TREE_MODEL (store),
&iter,
gtk_tree_model_get (GTK_TREE_MODEL (gtk_tree_view_get_model (view->tree_view)), &iter,
HISTORY_VIEW_COLUMN_BOOKMARK, &bookmark,
-1);
......@@ -207,16 +189,16 @@ on_selection_changed (GtkTreeSelection *selection,
static void
nautilus_history_view_instance_init (NautilusHistoryView *view)
{
GtkTreeView *treeview;
GtkTreeView *tree_view;
GtkTreeViewColumn *col;
GtkCellRenderer *cell;
GtkListStore *store;
GtkTreeSelection *selection;
GtkWidget *window;
treeview = GTK_TREE_VIEW (gtk_tree_view_new ());
gtk_tree_view_set_headers_visible (treeview, FALSE);
gtk_widget_show (GTK_WIDGET (treeview));
tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
gtk_tree_view_set_headers_visible (tree_view, FALSE);
gtk_widget_show (GTK_WIDGET (tree_view));
col = GTK_TREE_VIEW_COLUMN (gtk_tree_view_column_new ());
......@@ -233,45 +215,39 @@ nautilus_history_view_instance_init (NautilusHistoryView *view)
NULL);
gtk_tree_view_column_set_fixed_width (col, NAUTILUS_ICON_SIZE_SMALLER);
gtk_tree_view_append_column (treeview, col);
gtk_tree_view_append_column (tree_view, col);
store = gtk_list_store_new (HISTORY_VIEW_COLUMN_COUNT,
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
NAUTILUS_TYPE_BOOKMARK);
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store));
selection = GTK_TREE_SELECTION (gtk_tree_view_get_selection (treeview));
gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (store));
window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (treeview));
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (tree_view));
gtk_widget_show (window);
nautilus_view_construct (NAUTILUS_VIEW (view), window);
g_object_ref (treeview);
view->treeview = treeview;
view->store = store;
view->selection = selection;
g_object_ref (tree_view);
view->tree_view = tree_view;
nautilus_view_set_listener_mask (NAUTILUS_VIEW (view),
NAUTILUS_VIEW_LISTEN_HISTORY);
view->selection_changed_id = g_signal_connect (selection,
"changed",
G_CALLBACK (on_selection_changed),
view);
selection = gtk_tree_view_get_selection (tree_view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
view->selection_changed_id = g_signal_connect_object
(selection, "changed",
G_CALLBACK (on_selection_changed), view, 0);
g_signal_connect (view,
"history_changed",
G_CALLBACK (history_changed_callback),
view);
g_signal_connect (view, "history_changed",
G_CALLBACK (history_changed_callback), view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
}
static void
......@@ -281,19 +257,19 @@ nautilus_history_view_finalize (GObject *object)
view = NAUTILUS_HISTORY_VIEW (object);
if (view->external_destroyed_flag != NULL) {
*view->external_destroyed_flag = TRUE;
if (view->stop_updating_history != NULL) {
*view->stop_updating_history = TRUE;
}
g_object_unref (view->treeview);
g_object_unref (view->tree_view);
GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
nautilus_history_view_class_init (NautilusHistoryViewClass *klass)
nautilus_history_view_class_init (NautilusHistoryViewClass *class)
{
G_OBJECT_CLASS (klass)->finalize = nautilus_history_view_finalize;
G_OBJECT_CLASS (class)->finalize = nautilus_history_view_finalize;
}
int
......@@ -312,6 +288,6 @@ main (int argc, char *argv[])
FACTORY_IID,
VIEW_IID,
nautilus_view_create_from_get_type_function,
nautilus_global_preferences_init,
NULL,
nautilus_history_view_get_type);
}
......@@ -345,9 +345,7 @@ do_destroy (GtkObject *obj, News *news)
nautilus_news_free_channel_list (news);
/* free the property bag */
if (news->property_bag != NULL) {
bonobo_object_unref (BONOBO_OBJECT (news->property_bag));
}
bonobo_object_unref (news->property_bag);
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_NEWS_MAX_ITEMS,
max_items_changed,
......
......@@ -342,8 +342,8 @@ do_destroy (GtkObject *obj, Notes *notes)
* this because it exposes a bonobo bug.
*/
if (!GTK_OBJECT_DESTROYED (GTK_OBJECT (notes->view))) {
bonobo_object_ref (BONOBO_OBJECT (notes->view));
bonobo_object_idle_unref (BONOBO_OBJECT (notes->view));
bonobo_object_ref (notes->view);
bonobo_object_idle_unref (notes->view);
}
#endif
......
......@@ -103,7 +103,7 @@ main (int argc, char *argv[])
gtk_main ();
} while (object_count > 0);
bonobo_object_unref (BONOBO_OBJECT (factory));
bonobo_object_unref (factory);
}
gnome_vfs_shutdown ();
......
......@@ -653,9 +653,7 @@ nautilus_throbber_finalize (GObject *object)
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME,
nautilus_throbber_theme_changed, object);
if (throbber->details->property_bag != NULL) {
bonobo_object_unref (BONOBO_OBJECT (throbber->details->property_bag));
}
bonobo_object_unref (throbber->details->property_bag);
if (throbber->details->control != NULL) {
g_object_remove_weak_pointer (G_OBJECT (throbber->details->control),
......
......@@ -587,7 +587,7 @@ nautilus_directory_unregister_metadata_monitor (NautilusDirectory *directory)
CORBA_exception_free (&ev);
bonobo_object_release_unref (metafile, NULL);
bonobo_object_unref (BONOBO_OBJECT (directory->details->metafile_monitor));
bonobo_object_unref (directory->details->metafile_monitor);
directory->details->metafile_monitor = NULL;
}
......@@ -283,6 +283,8 @@ async_data_preference_changed_callback (gpointer callback_data)
static void
add_preferences_callbacks (void)
{
nautilus_global_preferences_init ();
eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
filtering_changed_callback,
NULL);
......
......@@ -1145,7 +1145,11 @@ create_label_layout (NautilusIconCanvasItem *item,
pango_layout_set_spacing (layout, LABEL_LINE_SPACING);
/* Create a font description */
desc = pango_font_description_from_string (container->details->font_name);
if (container->details->font_name == NULL) {
desc = pango_font_description_new ();
} else {
desc = pango_font_description_from_string (container->details->font_name);
}
pango_font_description_set_size (desc, container->details->font_size_table [container->details->zoom_level] * PANGO_SCALE);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
......
......@@ -3710,11 +3710,11 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
/* Get the icons. */
g_signal_emit (container,
signals[GET_ICON_IMAGES], 0,
icon->data,
(icon == details->drop_target) ? "accept" : "",
&emblem_scalable_icons,
&scalable_icon);
signals[GET_ICON_IMAGES], 0,
icon->data,
(icon == details->drop_target) ? "accept" : "",
&emblem_scalable_icons,
&scalable_icon);
/* compute the maximum size based on the scale factor */
min_image_size = MINIMUM_IMAGE_SIZE * GNOME_CANVAS (container)->pixels_per_unit;
......@@ -3733,8 +3733,7 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
nautilus_scalable_icon_unref (scalable_icon);
/* in the rare case an image is too small, scale it up */
/* in the rare case an image is too small, scale it up */
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
if (width < min_image_size || height < min_image_size) {
......@@ -3801,10 +3800,6 @@ nautilus_icon_container_update_icon (NautilusIconContainer *container,
nautilus_icon_canvas_item_set_attach_points (icon->item, &attach_points);
nautilus_icon_canvas_item_set_emblems (icon->item, emblem_pixbufs);
if (container->details->update_icon_font == TRUE) {
nautilus_icon_canvas_item_invalidate_label_size (icon->item);
}
/* Let the pixbufs go. */
g_object_unref (pixbuf);
eel_gdk_pixbuf_list_free (emblem_pixbufs);
......@@ -4028,9 +4023,7 @@ nautilus_icon_container_set_zoom_level (NautilusIconContainer *container, int ne
/ NAUTILUS_ICON_SIZE_STANDARD;
gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (container), pixels_per_unit);
/* We need to update the icon font too */
container->details->update_icon_font = TRUE;
invalidate_label_sizes (container);
nautilus_icon_container_request_update_all (container);
}
......@@ -4044,16 +4037,16 @@ nautilus_icon_container_set_zoom_level (NautilusIconContainer *container, int ne
void
nautilus_icon_container_request_update_all (NautilusIconContainer *container)
{
GList *p;
GList *node;
NautilusIcon *icon;
g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
for (p = container->details->icons; p != NULL; p = p->next) {
nautilus_icon_container_update_icon (container, p->data);
for (node = container->details->icons; node != NULL; node = node->next) {
icon = node->data;
nautilus_icon_container_update_icon (container, icon);
}
container->details->update_icon_font = FALSE;
redo_layout (container);
}
......@@ -5081,39 +5074,45 @@ nautilus_icon_container_theme_changed (gpointer user_data)
}
void
nautilus_icon_container_set_font_name (NautilusIconContainer *container,
const char *font_name)
nautilus_icon_container_set_font_name (NautilusIconContainer *container,
const char *font_name)
{
g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
g_free (container->details->font_name);
g_print ("new font name is: %s\n", font_name);
if (font_name != NULL) {
container->details->font_name = g_strdup (font_name);
}
else {
container->details->font_name = NULL;
if (eel_strcmp (container->details->font_name, font_name) == 0) {
return;
}
container->details->update_icon_font = TRUE;
g_free (container->details->font_name);
container->details->font_name = g_strdup (font_name);
invalidate_label_sizes (container);
nautilus_icon_container_request_update_all (container);
}
void
nautilus_icon_container_set_font_size_table (NautilusIconContainer *container,
const int font_size_table[NAUTILUS_ZOOM_LEVEL_LARGEST + 1])
{
int old_font_size;
int i;
g_return_if_fail (NAUTILUS_IS_ICON_CONTAINER (container));
g_return_if_fail (font_size_table != NULL);
old_font_size = container->details->font_size_table[container->details->zoom_level];
for (i = 0; i <= NAUTILUS_ZOOM_LEVEL_LARGEST; i++) {
container->details->font_size_table[i] = font_size_table[i];
if (container->details->font_size_table[i] != font_size_table[i]) {
container->details->font_size_table[i] = font_size_table[i];
changed = TRUE;
}
}
container->details->update_icon_font = TRUE;
if (old_font_size != container->details->font_size_table[container->details->zoom_level]) {
invalidate_label_sizes (container);