[balsa/remember-mailbox-positions] Go back to weak ref
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/remember-mailbox-positions] Go back to weak ref
- Date: Wed, 13 Feb 2019 16:30:41 +0000 (UTC)
commit 8704cb9d3f3f58971c7409d864ea1a2de2b84a9e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Feb 13 11:29:43 2019 -0500
Go back to weak ref
src/balsa-index.c | 50 +++++++++++++++++++++++++++-----------------------
src/mailbox-node.c | 2 ++
2 files changed, 29 insertions(+), 23 deletions(-)
---
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 20fdb9e66..0850dc4c0 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -199,6 +199,13 @@ bndx_class_init(BalsaIndexClass * klass)
}
/* Object class destroy method. */
+static void
+bndx_mbnode_weak_notify(gpointer data, GObject *where_the_object_was)
+{
+ BalsaIndex *bindex = data;
+ bindex->mailbox_node = NULL;
+ gtk_widget_destroy(GTK_WIDGET(bindex));
+}
static void
bndx_destroy(GObject * obj)
@@ -208,23 +215,22 @@ bndx_destroy(GObject * obj)
g_return_if_fail(obj != NULL);
index = BALSA_INDEX(obj);
- if (index->mailbox_node != NULL) {
- LibBalsaMailbox *mailbox;
-
- mailbox = index->mailbox_node->mailbox;
- if (mailbox != NULL)
- g_object_ref(mailbox);
+ if (index->mailbox_node) {
+ LibBalsaMailbox* mailbox;
- g_object_unref(index->mailbox_node);
- index->mailbox_node = NULL;
+ if ((mailbox = index->mailbox_node->mailbox)) {
+ g_signal_handlers_disconnect_matched(mailbox,
+ G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, index);
+ gtk_tree_view_set_model(GTK_TREE_VIEW(index), NULL);
+ libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
+ }
- if (mailbox != NULL) {
- g_signal_handlers_disconnect_matched(mailbox,
- G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL, index);
- gtk_tree_view_set_model(GTK_TREE_VIEW(index), NULL);
- libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
- g_object_unref(mailbox);
+ if (index->mailbox_node) {
+ g_object_weak_unref(G_OBJECT(index->mailbox_node),
+ (GWeakNotify) bndx_mbnode_weak_notify,
+ index);
+ index->mailbox_node = NULL;
}
}
@@ -238,10 +244,10 @@ bndx_destroy(GObject * obj)
index->popup_menu = NULL;
}
- g_free(index->filter_string);
- index->filter_string = NULL;
+ g_free(index->filter_string); index->filter_string = NULL;
- G_OBJECT_CLASS(parent_class)->dispose(obj);
+ if (G_OBJECT_CLASS(parent_class)->dispose)
+ (*G_OBJECT_CLASS(parent_class)->dispose) (obj);
}
/* Widget class popup menu method. */
@@ -555,9 +561,6 @@ bndx_selection_changed_func(GtkTreeModel * model, GtkTreePath * path,
static void
bndx_selection_changed(GtkTreeSelection * selection, BalsaIndex * index)
{
- if (index->mailbox_node == NULL)
- return;
-
index->next_msgno = 0;
gtk_tree_selection_selected_foreach(selection,
(GtkTreeSelectionForeachFunc)
@@ -963,8 +966,9 @@ balsa_index_load_mailbox_node(BalsaIndex * index,
/*
* set the new mailbox
*/
- index->mailbox_node = g_object_ref(mbnode);
-
+ index->mailbox_node = mbnode;
+ g_object_weak_ref(G_OBJECT(mbnode),
+ (GWeakNotify) bndx_mbnode_weak_notify, index);
/*
* rename "from" column to "to" for outgoing mail
*/
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index 397f08283..1d1447653 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -196,6 +196,8 @@ balsa_mailbox_node_dispose(GObject * object)
libbalsa_mailbox_set_open(mailbox,
libbalsa_mailbox_is_open(mailbox));
config_save_mailbox_view(mailbox->url, mailbox->view);
+ if (balsa_app.main_window)
+ balsa_window_close_mbnode(balsa_app.main_window, mn);
g_object_unref(mailbox);
mn->mailbox = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]