aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-10-11 16:31:29 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-10-11 16:31:29 +0800
commit81c256ebc1597ccce365adca9861dd96822cf4cd (patch)
treeadfae342966cf08286f9453e97e789f190654dd0
parent4e40ea7c7fe9c469706b23414b1dbe0884e5f267 (diff)
downloadgsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar.gz
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar.bz2
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar.lz
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar.xz
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.tar.zst
gsoc2013-evolution-81c256ebc1597ccce365adca9861dd96822cf4cd.zip
Check that view->view != NULL. (save_contact_cb): Check that view->view !=
2001-10-11 Jon Trowbridge <trow@ximian.com> * gui/component/addressbook.c (new_contact_cb): Check that view->view != NULL. (save_contact_cb): Check that view->view != NULL. (search_cb): Check that view->view != NULL. (delete_contact_cb): Check that view->view != NULL. (print_cb): Check that view->view != NULL. (print_preview_cb): Check that view->view != NULL. (stop_loading_cb): Check that view->view != NULL. (cut_contacts_cb): Check that view->view != NULL. (copy_contacts_cb): Check that view->view != NULL. (paste_contacts_cb): Check that view->view != NULL. (select_all_contacts_cb): Check that view->view != NULL. (send_contact_cb): Check that view->view != NULL. (send_contact_to_cb): Check that view->view != NULL. (update_command_state): Check that view->view != NULL. Hold a reference to the AddressbookView for the duration of the function, in case we exit during bonobo-reentrancy. (addressbook_view_ref): Added. (addressbook_view_unref): Added. Simple ref counting for AddressbookView objects. (addressbook_view_clear): Zero out an AddressbookView. This is now separated from the deallocation of the AddressbookView object, so that we don't leave a dangling pointer if we exit during bonobo-reentrancy in update_command_state. (Which often seems to happen if we exit while addressbook operations are going on.) (destroy_callback): Replace previous call to addressbook_view_free with addressbook_view_clear/addressbook_view_unref calls. (addressbook_factory_new_control): Initialize the reference count in the AddressbookView object. * gui/widgets/e-addressbook-view.c (e_addressbook_view_destroy): Carefully zero out our destroyed object. (command_state_change): Hold a reference to ourselves during the signal emission. (get_selected_cards): Ref cards as we add them to the list. (e_addressbook_view_stop): Check for view != NULL. (e_addressbook_view_can_create): Check for view != NULL. (e_addressbook_view_can_print): Check for view != NULL. (e_addressbook_view_can_save_as): Check for view != NULL. (e_addressbook_view_can_send): Check for view != NULL. (e_addressbook_view_can_send_to): Check for view != NULL. (e_addressbook_view_can_delete): Check for view != NULL. (e_addressbook_view_can_cut): Check for view != NULL. (e_addressbook_view_can_copy): Check for view != NULL. (e_addressbook_view_can_paste): Check for view != NULL. (e_addressbook_view_can_select_all): Check for view != NULL. (e_addressbook_view_can_stop): Check for view != NULL. * gui/widgets/e-addressbook-model.c (addressbook_destroy): Be careful about zeroing out our destroyed object. * backend/ebook/e-book-view.c (e_book_view_stop): Added. Stops event processing in the underlying listener. svn path=/trunk/; revision=13578
-rw-r--r--addressbook/ChangeLog56
-rw-r--r--addressbook/backend/ebook/e-book-view.c8
-rw-r--r--addressbook/backend/ebook/e-book-view.h2
-rw-r--r--addressbook/gui/component/addressbook.c133
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c10
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c52
6 files changed, 206 insertions, 55 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 7b4a2bb90b..21dbacb98b 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,59 @@
+2001-10-11 Jon Trowbridge <trow@ximian.com>
+
+ * gui/component/addressbook.c (new_contact_cb): Check that
+ view->view != NULL.
+ (save_contact_cb): Check that view->view != NULL.
+ (search_cb): Check that view->view != NULL.
+ (delete_contact_cb): Check that view->view != NULL.
+ (print_cb): Check that view->view != NULL.
+ (print_preview_cb): Check that view->view != NULL.
+ (stop_loading_cb): Check that view->view != NULL.
+ (cut_contacts_cb): Check that view->view != NULL.
+ (copy_contacts_cb): Check that view->view != NULL.
+ (paste_contacts_cb): Check that view->view != NULL.
+ (select_all_contacts_cb): Check that view->view != NULL.
+ (send_contact_cb): Check that view->view != NULL.
+ (send_contact_to_cb): Check that view->view != NULL.
+ (update_command_state): Check that view->view != NULL. Hold a
+ reference to the AddressbookView for the duration of the function,
+ in case we exit during bonobo-reentrancy.
+ (addressbook_view_ref): Added.
+ (addressbook_view_unref): Added. Simple ref counting for
+ AddressbookView objects.
+ (addressbook_view_clear): Zero out an AddressbookView. This is
+ now separated from the deallocation of the AddressbookView object,
+ so that we don't leave a dangling pointer if we exit during
+ bonobo-reentrancy in update_command_state. (Which often seems to
+ happen if we exit while addressbook operations are going on.)
+ (destroy_callback): Replace previous call to addressbook_view_free
+ with addressbook_view_clear/addressbook_view_unref calls.
+ (addressbook_factory_new_control): Initialize the reference count
+ in the AddressbookView object.
+
+ * gui/widgets/e-addressbook-view.c (e_addressbook_view_destroy):
+ Carefully zero out our destroyed object.
+ (command_state_change): Hold a reference to ourselves during the
+ signal emission.
+ (get_selected_cards): Ref cards as we add them to the list.
+ (e_addressbook_view_stop): Check for view != NULL.
+ (e_addressbook_view_can_create): Check for view != NULL.
+ (e_addressbook_view_can_print): Check for view != NULL.
+ (e_addressbook_view_can_save_as): Check for view != NULL.
+ (e_addressbook_view_can_send): Check for view != NULL.
+ (e_addressbook_view_can_send_to): Check for view != NULL.
+ (e_addressbook_view_can_delete): Check for view != NULL.
+ (e_addressbook_view_can_cut): Check for view != NULL.
+ (e_addressbook_view_can_copy): Check for view != NULL.
+ (e_addressbook_view_can_paste): Check for view != NULL.
+ (e_addressbook_view_can_select_all): Check for view != NULL.
+ (e_addressbook_view_can_stop): Check for view != NULL.
+
+ * gui/widgets/e-addressbook-model.c (addressbook_destroy): Be
+ careful about zeroing out our destroyed object.
+
+ * backend/ebook/e-book-view.c (e_book_view_stop): Added. Stops
+ event processing in the underlying listener.
+
2001-10-10 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names-manager.c
diff --git a/addressbook/backend/ebook/e-book-view.c b/addressbook/backend/ebook/e-book-view.c
index e56c7e90bc..1af893bcd6 100644
--- a/addressbook/backend/ebook/e-book-view.c
+++ b/addressbook/backend/ebook/e-book-view.c
@@ -207,6 +207,14 @@ e_book_view_set_book (EBookView *book_view, EBook *book)
gtk_object_ref (GTK_OBJECT (book));
}
+void
+e_book_view_stop (EBookView *book_view)
+{
+ g_return_if_fail (book_view && E_IS_BOOK_VIEW (book_view));
+ if (book_view->priv->listener)
+ e_book_view_listener_stop (book_view->priv->listener);
+}
+
static void
e_book_view_init (EBookView *book_view)
{
diff --git a/addressbook/backend/ebook/e-book-view.h b/addressbook/backend/ebook/e-book-view.h
index 5e576d6642..86326ca5b7 100644
--- a/addressbook/backend/ebook/e-book-view.h
+++ b/addressbook/backend/ebook/e-book-view.h
@@ -49,6 +49,8 @@ GtkType e_book_view_get_type (void);
void e_book_view_set_book (EBookView *book_view, struct _EBook *book);
+void e_book_view_stop (EBookView *book_view);
+
#define E_BOOK_VIEW_TYPE (e_book_view_get_type ())
#define E_BOOK_VIEW(o) (GTK_CHECK_CAST ((o), E_BOOK_VIEW_TYPE, EBookView))
#define E_BOOK_VIEW_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BOOK_VIEW_TYPE, EBookViewClass))
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c
index 6b4108046f..8dc978f603 100644
--- a/addressbook/gui/component/addressbook.c
+++ b/addressbook/gui/component/addressbook.c
@@ -55,6 +55,7 @@ static GdkPixbuf *progress_icon[2] = { NULL, NULL };
#define PROPERTY_FOLDER_URI_IDX 1
typedef struct {
+ gint refs;
EAddressbookView *view;
ESearchBar *search;
GtkWidget *vbox;
@@ -65,19 +66,24 @@ typedef struct {
char *passwd;
} AddressbookView;
+static void addressbook_view_ref (AddressbookView *);
+static void addressbook_view_unref (AddressbookView *);
+
static void
new_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
EBook *book;
AddressbookView *view = (AddressbookView *) user_data;
- gtk_object_get(GTK_OBJECT(view->view),
- "book", &book,
- NULL);
+ if (view->view) {
+ gtk_object_get(GTK_OBJECT(view->view),
+ "book", &book,
+ NULL);
- g_assert (E_IS_BOOK (book));
+ g_assert (E_IS_BOOK (book));
- e_addressbook_show_contact_editor (book, e_card_new(""), TRUE, e_addressbook_view_can_create(view->view));
+ e_addressbook_show_contact_editor (book, e_card_new(""), TRUE, e_addressbook_view_can_create(view->view));
+ }
}
static void
@@ -86,20 +92,23 @@ new_contact_list_cb (BonoboUIComponent *uih, void *user_data, const char *path)
EBook *book;
AddressbookView *view = (AddressbookView *) user_data;
- gtk_object_get(GTK_OBJECT(view->view),
- "book", &book,
- NULL);
+ if (view->view) {
+ gtk_object_get(GTK_OBJECT(view->view),
+ "book", &book,
+ NULL);
- g_assert (E_IS_BOOK (book));
+ g_assert (E_IS_BOOK (book));
- e_addressbook_show_contact_list_editor (book, e_card_new(""), TRUE, e_addressbook_view_can_create(view->view));
+ e_addressbook_show_contact_list_editor (book, e_card_new(""), TRUE, e_addressbook_view_can_create(view->view));
+ }
}
static void
save_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_save_as(view->view);
+ if (view->view)
+ e_addressbook_view_save_as(view->view);
}
static void
@@ -113,77 +122,88 @@ search_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- gtk_widget_show(e_addressbook_search_dialog_new(view->view));
+ if (view->view)
+ gtk_widget_show(e_addressbook_search_dialog_new(view->view));
}
static void
delete_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_delete_selection(view->view);
+ if (view->view)
+ e_addressbook_view_delete_selection(view->view);
}
static void
print_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_print(view->view);
+ if (view->view)
+ e_addressbook_view_print(view->view);
}
static void
print_preview_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_print_preview(view->view);
+ if (view->view)
+ e_addressbook_view_print_preview(view->view);
}
static void
stop_loading_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_stop(view->view);
+ if (view->view)
+ e_addressbook_view_stop(view->view);
}
static void
cut_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_cut(view->view);
+ if (view->view)
+ e_addressbook_view_cut(view->view);
}
static void
copy_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_copy(view->view);
+ if (view->view)
+ e_addressbook_view_copy(view->view);
}
static void
paste_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_paste(view->view);
+ if (view->view)
+ e_addressbook_view_paste(view->view);
}
static void
select_all_contacts_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_select_all (view->view);
+ if (view->view)
+ e_addressbook_view_select_all (view->view);
}
static void
send_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_send(view->view);
+ if (view->view)
+ e_addressbook_view_send (view->view);
}
static void
send_contact_to_cb (BonoboUIComponent *uih, void *user_data, const char *path)
{
AddressbookView *view = (AddressbookView *) user_data;
- e_addressbook_view_send_to(view->view);
+ if (view->view)
+ e_addressbook_view_send_to (view->view);
}
static void
@@ -195,7 +215,15 @@ forget_passwords_cb (BonoboUIComponent *uih, void *user_data, const char *path)
static void
update_command_state (EAddressbookView *eav, AddressbookView *view)
{
- BonoboUIComponent *uic = bonobo_control_get_ui_component (view->control);
+ BonoboUIComponent *uic;
+
+ if (view->view == NULL)
+ return;
+
+ addressbook_view_ref (view);
+
+ uic = bonobo_control_get_ui_component (view->control);
+
/* New Contact */
bonobo_ui_component_set_prop (uic,
@@ -263,6 +291,8 @@ update_command_state (EAddressbookView *eav, AddressbookView *view)
"/commands/ContactStop",
"sensitive",
e_addressbook_view_can_stop (view->view) ? "1" : "0", NULL);
+
+ addressbook_view_unref (view);
}
static void
@@ -366,21 +396,51 @@ control_activate_cb (BonoboControl *control,
}
static void
-addressbook_view_free(AddressbookView *view)
+addressbook_view_ref (AddressbookView *view)
+{
+ g_assert (view->refs > 0);
+ ++view->refs;
+}
+
+static void
+addressbook_view_unref (AddressbookView *view)
+{
+ g_assert (view->refs > 0);
+ --view->refs;
+ if (view->refs == 0)
+ g_free (view);
+}
+
+static void
+addressbook_view_clear (AddressbookView *view)
{
EBook *book;
-
- gtk_object_get(GTK_OBJECT(view->view),
- "book", &book,
- NULL);
- if (view->uri)
+
+ if (view->uri && view->view) {
+ gtk_object_get(GTK_OBJECT(view->view),
+ "book", &book,
+ NULL);
gtk_object_unref (GTK_OBJECT (book));
+ }
- if (view->properties)
- bonobo_object_unref(BONOBO_OBJECT(view->properties));
+ if (view->properties) {
+ bonobo_object_unref (BONOBO_OBJECT(view->properties));
+ view->properties = NULL;
+ }
+
+ if (view->view) {
+ gtk_widget_destroy (GTK_WIDGET (view->view));
+ view->view = NULL;
+ }
+
g_free(view->passwd);
+ view->passwd = NULL;
+
g_free(view->uri);
- g_free(view);
+ view->uri = NULL;
+
+ if (view->refs == 0)
+ g_free(view);
}
static void
@@ -447,10 +507,14 @@ book_open_cb (EBook *book, EBookStatus status, gpointer closure)
}
}
-static void destroy_callback(GtkWidget *widget, gpointer data)
+static void
+destroy_callback(GtkWidget *widget, gpointer data)
{
AddressbookView *view = data;
- addressbook_view_free(view);
+ if (view->view && view->view->model && view->view->model->book_view)
+ e_book_view_stop (view->view->model->book_view);
+ addressbook_view_clear (view);
+ addressbook_view_unref (view);
}
static void
@@ -863,6 +927,7 @@ addressbook_factory_new_control (void)
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
view = g_new0 (AddressbookView, 1);
+ view->refs = 1;
view->vbox = gtk_vbox_new (FALSE, 0);
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index fd67d5fd23..a93ae6aa28 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -75,8 +75,9 @@ remove_book_view(EAddressbookModel *model)
model->search_in_progress = FALSE;
- if (model->book_view)
+ if (model->book_view) {
gtk_object_unref(GTK_OBJECT(model->book_view));
+ }
model->book_view = NULL;
}
@@ -87,8 +88,10 @@ addressbook_destroy(GtkObject *object)
EAddressbookModel *model = E_ADDRESSBOOK_MODEL(object);
int i;
- if (model->get_view_idle)
+ if (model->get_view_idle) {
g_source_remove(model->get_view_idle);
+ model->get_view_idle = 0;
+ }
remove_book_view(model);
@@ -100,12 +103,15 @@ addressbook_destroy(GtkObject *object)
model->writable_status_id = 0;
gtk_object_unref(GTK_OBJECT(model->book));
+ model->book = NULL;
}
for ( i = 0; i < model->data_count; i++ ) {
gtk_object_unref(GTK_OBJECT(model->data[i]));
}
+
g_free(model->data);
+ model->data = NULL;
}
static void
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 8c0bed0939..c12e14dcbe 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -257,12 +257,18 @@ e_addressbook_view_destroy (GtkObject *object)
{
EAddressbookView *eav = E_ADDRESSBOOK_VIEW(object);
- if (eav->model)
+ if (eav->model) {
gtk_object_unref(GTK_OBJECT(eav->model));
+ eav->model = NULL;
+ }
- if (eav->book)
+ if (eav->book) {
gtk_object_unref(GTK_OBJECT(eav->book));
+ eav->book = NULL;
+ }
+
g_free(eav->query);
+ eav->query = NULL;
if (eav->view_collection) {
gtk_object_unref (GTK_OBJECT (eav->view_collection));
@@ -280,8 +286,10 @@ e_addressbook_view_destroy (GtkObject *object)
eav->clipboard_cards = NULL;
}
- if (eav->invisible)
+ if (eav->invisible) {
gtk_widget_destroy (eav->invisible);
+ eav->invisible = NULL;
+ }
if (GTK_OBJECT_CLASS(parent_class)->destroy)
GTK_OBJECT_CLASS(parent_class)->destroy(object);
@@ -858,8 +866,9 @@ writable_status (GtkObject *object, gboolean writable, EAddressbookView *eav)
static void
command_state_change (EAddressbookView *eav)
{
- gtk_signal_emit (GTK_OBJECT (eav),
- e_addressbook_view_signals [COMMAND_STATE_CHANGE]);
+ gtk_object_ref (GTK_OBJECT (eav)); /* who knows what might happen during this emission? */
+ gtk_signal_emit (GTK_OBJECT (eav), e_addressbook_view_signals [COMMAND_STATE_CHANGE]);
+ gtk_object_unref (GTK_OBJECT (eav));
}
#ifdef JUST_FOR_TRANSLATORS
@@ -1409,6 +1418,8 @@ get_selected_cards (EAddressbookView *view)
for (iterator = list; iterator; iterator = iterator->next) {
iterator->data = e_addressbook_model_card_at (view->model, GPOINTER_TO_INT (iterator->data));
+ if (iterator->data)
+ gtk_object_ref (iterator->data);
}
list = g_list_reverse (list);
return list;
@@ -1485,7 +1496,8 @@ e_addressbook_view_show_all(EAddressbookView *view)
void
e_addressbook_view_stop(EAddressbookView *view)
{
- e_addressbook_model_stop (view->model);
+ if (view)
+ e_addressbook_model_stop (view->model);
}
static gboolean
@@ -1503,64 +1515,66 @@ e_addressbook_view_selection_nonempty (EAddressbookView *view)
gboolean
e_addressbook_view_can_create (EAddressbookView *view)
{
- return e_addressbook_model_editable (view->model);
+ return view ? e_addressbook_model_editable (view->model) : FALSE;
}
gboolean
e_addressbook_view_can_print (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view);
+ return view ? e_addressbook_view_selection_nonempty (view) : FALSE;
}
gboolean
e_addressbook_view_can_save_as (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view);
+ return view ? e_addressbook_view_selection_nonempty (view) : FALSE;
}
-gboolean e_addressbook_view_can_send (EAddressbookView *view)
+gboolean
+e_addressbook_view_can_send (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view);
+ return view ? e_addressbook_view_selection_nonempty (view) : FALSE;
}
-gboolean e_addressbook_view_can_send_to (EAddressbookView *view)
+gboolean
+e_addressbook_view_can_send_to (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view);
+ return view ? e_addressbook_view_selection_nonempty (view) : FALSE;
}
gboolean
e_addressbook_view_can_delete (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view) && e_addressbook_model_editable (view->model);
+ return view ? e_addressbook_view_selection_nonempty (view) && e_addressbook_model_editable (view->model) : FALSE;
}
gboolean
e_addressbook_view_can_cut (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view) && e_addressbook_model_editable (view->model);
+ return view ? e_addressbook_view_selection_nonempty (view) && e_addressbook_model_editable (view->model) : FALSE;
}
gboolean
e_addressbook_view_can_copy (EAddressbookView *view)
{
- return e_addressbook_view_selection_nonempty (view);
+ return view ? e_addressbook_view_selection_nonempty (view) : FALSE;
}
gboolean
e_addressbook_view_can_paste (EAddressbookView *view)
{
- return e_addressbook_model_editable (view->model);
+ return view ? e_addressbook_model_editable (view->model) : FALSE;
}
gboolean
e_addressbook_view_can_select_all (EAddressbookView *view)
{
- return e_addressbook_model_card_count (view->model) != 0;
+ return view ? e_addressbook_model_card_count (view->model) != 0 : FALSE;
}
gboolean
e_addressbook_view_can_stop (EAddressbookView *view)
{
- return e_addressbook_model_can_stop (view->model);
+ return view ? e_addressbook_model_can_stop (view->model) : FALSE;
}