[balsa] balsa-index: Add a convenience function
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] balsa-index: Add a convenience function
- Date: Mon, 22 Jul 2019 01:37:55 +0000 (UTC)
commit c49800e19ba514f67442af7d8600532881f1a82d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun Jul 21 21:35:55 2019 -0400
balsa-index: Add a convenience function
Add a convenience function balsa_index_get_mailbox().
* src/balsa-index.c (balsa_index_get_mailbox): define it;
* src/balsa-index.h: declare it;
* src/balsa-app.c (balsa_find_index_by_mailbox):
* src/balsa-mblist.c (bmbl_tree_expand), (bmbl_drag_cb),
(bmbl_update_mailbox):
* src/main-window.c (continue_activated), (print_activated),
(mailbox_close_activated), (select_filters_activated),
(remove_duplicates_activated), (threading_change_state),
(bw_enable_message_menus), (balsa_window_set_thread_messages),
(balsa_window_real_close_mbnode), (bw_find_real),
(bw_hide_changed_set_view_filter), (bw_notebook_switch_page_cb),
(bw_idle_cb), (bw_notebook_drag_received_cb),
(bw_notebook_page_notify_cb), (balsa_window_next_unread):
* src/message-window.c (mw_set_buttons_sensitive):
* src/sendmsg-window.c (attachments_add), (drag_data_quote): use it.
ChangeLog | 22 ++++++++++++++++++++++
src/balsa-app.c | 5 +++--
src/balsa-index.c | 12 ++++++++++++
src/balsa-index.h | 6 ++++++
src/balsa-mblist.c | 6 +++---
src/main-window.c | 53 +++++++++++++++++++++++++---------------------------
src/message-window.c | 2 +-
src/sendmsg-window.c | 4 ++--
8 files changed, 74 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 44a394909..630a96816 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2019-07-21 Peter Bloomfield <pbloomfield bellsouth net>
+
+ balsa-index: Add a convenience function
+ balsa_index_get_mailbox().
+
+ * src/balsa-index.c (balsa_index_get_mailbox): define it;
+ * src/balsa-index.h: declare it;
+ * src/balsa-app.c (balsa_find_index_by_mailbox):
+ * src/balsa-mblist.c (bmbl_tree_expand), (bmbl_drag_cb),
+ (bmbl_update_mailbox):
+ * src/main-window.c (continue_activated), (print_activated),
+ (mailbox_close_activated), (select_filters_activated),
+ (remove_duplicates_activated), (threading_change_state),
+ (bw_enable_message_menus), (balsa_window_set_thread_messages),
+ (balsa_window_real_close_mbnode), (bw_find_real),
+ (bw_hide_changed_set_view_filter), (bw_notebook_switch_page_cb),
+ (bw_idle_cb), (bw_notebook_drag_received_cb),
+ (bw_notebook_page_notify_cb), (balsa_window_next_unread):
+ * src/message-window.c (mw_set_buttons_sensitive):
+ * src/sendmsg-window.c (attachments_add), (drag_data_quote): use
+ it.
+
2019-07-21 Peter Bloomfield <pbloomfield bellsouth net>
balsa-index: Use modern macros to declare and define.
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 606920044..ac50ae951 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -887,6 +887,7 @@ balsa_find_index_by_mailbox(LibBalsaMailbox * mailbox)
GtkWidget *child;
guint i;
+ g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), NULL);
g_return_val_if_fail(GTK_IS_NOTEBOOK(balsa_app.notebook), NULL);
for (i = 0;
@@ -895,9 +896,9 @@ balsa_find_index_by_mailbox(LibBalsaMailbox * mailbox)
child = gtk_bin_get_child(GTK_BIN(page));
if (child != NULL) {
BalsaIndex *bindex = BALSA_INDEX(child);
- BalsaMailboxNode *mailbox_node = balsa_index_get_mailbox_node(bindex);
+ LibBalsaMailbox *this_mailbox = balsa_index_get_mailbox(bindex);
- if (mailbox_node != NULL && mailbox_node->mailbox == mailbox)
+ if (this_mailbox == mailbox)
return bindex;
}
}
diff --git a/src/balsa-index.c b/src/balsa-index.c
index bd6bd5d5f..96a95ddef 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2896,3 +2896,15 @@ balsa_index_set_last_use_time(BalsaIndex *bindex)
time(&bindex->mailbox_node->last_use);
}
+
+/*
+ * Convenience
+ */
+
+LibBalsaMailbox *
+balsa_index_get_mailbox(BalsaIndex *bindex)
+{
+ g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
+
+ return bindex->mailbox_node != NULL ? bindex->mailbox_node->mailbox : NULL;
+}
diff --git a/src/balsa-index.h b/src/balsa-index.h
index cca381c64..300d8f936 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -155,6 +155,12 @@ const gchar * balsa_index_get_filter_string(BalsaIndex *bindex);
void balsa_index_set_last_use_time(BalsaIndex *bindex);
+/*
+ * Convenience
+ */
+
+LibBalsaMailbox * balsa_index_get_mailbox(BalsaIndex *bindex);
+
#define BALSA_INDEX_VIEW_ON_OPEN "balsa-index-view-on-open"
G_END_DECLS
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index b01a9f73f..3c645d2ac 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -551,7 +551,7 @@ bmbl_tree_expand(GtkTreeView * tree_view, GtkTreeIter * iter,
balsa_window_find_current_index(balsa_app.main_window);
LibBalsaMailbox *current_mailbox =
current_index != NULL ?
- balsa_index_get_mailbox_node(BALSA_INDEX(current_index))->mailbox :
+ balsa_index_get_mailbox(BALSA_INDEX(current_index)):
NULL;
gboolean first_mailbox = TRUE;
@@ -840,7 +840,7 @@ bmbl_drag_cb(GtkWidget * widget, GdkDragContext * context,
return;
}
- orig_mailbox = balsa_index_get_mailbox_node(orig_index)->mailbox;
+ orig_mailbox = balsa_index_get_mailbox(orig_index);
/* find the node and mailbox */
@@ -1434,7 +1434,7 @@ bmbl_update_mailbox(GtkTreeStore * store, LibBalsaMailbox * mailbox)
bindex = balsa_window_find_current_index(balsa_app.main_window);
if (bindex == NULL ||
- mailbox != balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox)
+ mailbox != balsa_index_get_mailbox(BALSA_INDEX(bindex)))
return;
balsa_window_set_statusbar(balsa_app.main_window, mailbox);
diff --git a/src/main-window.c b/src/main-window.c
index c1109a7a7..8f7b28fb1 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -1026,7 +1026,7 @@ continue_activated(GSimpleAction * action,
bindex = balsa_window_find_current_index(window);
if (bindex != NULL &&
- balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox == balsa_app.draftbox)
+ balsa_index_get_mailbox(BALSA_INDEX(bindex)) == balsa_app.draftbox)
balsa_message_continue(BALSA_INDEX(bindex));
else
balsa_mblist_open_mailbox(balsa_app.draftbox);
@@ -1095,7 +1095,7 @@ print_activated(GSimpleAction * action,
current_msgno = balsa_index_get_current_msgno(bindex);
if (current_msgno > 0) {
LibBalsaMessage *message =
- libbalsa_mailbox_get_message(balsa_index_get_mailbox_node(bindex)->mailbox,
+ libbalsa_mailbox_get_message(balsa_index_get_mailbox(bindex),
current_msgno);
if (message == NULL)
@@ -1368,12 +1368,11 @@ mailbox_close_activated(GSimpleAction * action,
gpointer user_data)
{
BalsaWindow *window = BALSA_WINDOW(user_data);
- GtkWidget *index;
+ GtkWidget *bindex;
- index = balsa_window_find_current_index(window);
- if (index)
- balsa_mblist_close_mailbox(balsa_index_get_mailbox_node(BALSA_INDEX(index))->
- mailbox);
+ bindex = balsa_window_find_current_index(window);
+ if (bindex != NULL)
+ balsa_mblist_close_mailbox(balsa_index_get_mailbox(BALSA_INDEX(bindex)));
}
static void
@@ -1396,7 +1395,7 @@ select_filters_activated(GSimpleAction * action,
index = balsa_window_find_current_index(window);
if (index)
- filters_run_dialog(balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox,
+ filters_run_dialog(balsa_index_get_mailbox(BALSA_INDEX(index)),
GTK_WINDOW(balsa_app.main_window));
else
/* FIXME : Perhaps should we be able to apply filters on folders (ie recurse on all mailboxes in it),
@@ -1417,7 +1416,7 @@ remove_duplicates_activated(GSimpleAction * action,
index = balsa_window_find_current_index(window);
if (index) {
LibBalsaMailbox *mailbox =
- balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox;
+ balsa_index_get_mailbox(BALSA_INDEX(index));
GError *err = NULL;
gint dup_count =
libbalsa_mailbox_move_duplicates(mailbox, NULL, &err);
@@ -1877,7 +1876,6 @@ threading_change_state(GSimpleAction * action,
BalsaWindow *window = BALSA_WINDOW(user_data);
GtkWidget *index;
gboolean thread_messages;
- BalsaMailboxNode *mbnode;
LibBalsaMailbox *mailbox;
thread_messages = g_variant_get_boolean(state);
@@ -1888,8 +1886,8 @@ threading_change_state(GSimpleAction * action,
/* bw->current_index may have been destroyed and cleared during
* set-threading: */
index = balsa_window_find_current_index(window);
- if (index && (mbnode = balsa_index_get_mailbox_node(BALSA_INDEX(index)))
- && (mailbox = mbnode->mailbox))
+ if (index != NULL &&
+ (mailbox = balsa_index_get_mailbox(BALSA_INDEX(index))) != NULL)
bw_enable_expand_collapse(window, mailbox);
g_simple_action_set_state(action, state);
@@ -2490,7 +2488,7 @@ bw_enable_message_menus(BalsaWindow * window, guint msgno)
G_N_ELEMENTS(message_actions), enable);
enable_mod =
- (enable && !libbalsa_mailbox_get_readonly(balsa_index_get_mailbox_node(bindex)->mailbox));
+ (enable && !libbalsa_mailbox_get_readonly(balsa_index_get_mailbox(bindex)));
bw_actions_set_enabled(window, modify_message_actions,
G_N_ELEMENTS(modify_message_actions),
enable_mod);
@@ -2621,14 +2619,12 @@ void
balsa_window_set_thread_messages(BalsaWindow * window, gboolean thread_messages)
{
GtkWidget *index;
- BalsaMailboxNode *mbnode;
LibBalsaMailbox *mailbox;
bw_action_set_boolean(window, "threading", thread_messages);
if ((index = balsa_window_find_current_index(window)) != NULL
- && (mbnode = balsa_index_get_mailbox_node(BALSA_INDEX(index))) != NULL
- && (mailbox = mbnode->mailbox) != NULL)
+ && (mailbox = balsa_index_get_mailbox(BALSA_INDEX(index))) != NULL)
bw_enable_expand_collapse(window, mailbox);
}
@@ -3048,11 +3044,12 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
index = balsa_window_find_current_index(window);
mailbox = g_new(LibBalsaMailbox *, 1);
- if (index) {
- *mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(index))-> mailbox;
+ if (index != NULL) {
+ *mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
g_object_add_weak_pointer(G_OBJECT(*mailbox), (gpointer *) mailbox);
- } else
+ } else {
*mailbox = NULL;
+ }
g_idle_add((GSourceFunc) bw_focus_idle, mailbox);
}
@@ -3906,7 +3903,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
if(ok == FIND_RESPONSE_FILTER) {
LibBalsaMailbox *mailbox =
- balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox;
+ balsa_index_get_mailbox(BALSA_INDEX(bindex));
LibBalsaCondition *filter, *res;
filter = bw_get_view_filter(window);
res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
@@ -3976,7 +3973,7 @@ bw_hide_changed_set_view_filter(BalsaWindow * window)
if(!index)
return;
- mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox;
+ mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
/* Store the new filter mask in the mailbox view before we set the
* view filter; rethreading triggers bw_set_filter_menu,
* which retrieves the mask from the mailbox view, and we want it to
@@ -4146,9 +4143,9 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
g_object_add_weak_pointer(G_OBJECT(index),
(gpointer *) &window->current_index);
/* Note when this mailbox was exposed, for use in auto-expunge. */
- time(&balsa_index_get_mailbox_node(index)->last_use);
+ balsa_index_set_last_use_time(index);
- mailbox = balsa_index_get_mailbox_node(index)->mailbox;
+ mailbox = balsa_index_get_mailbox(index);
if (libbalsa_mailbox_get_name(mailbox)) {
if (libbalsa_mailbox_get_readonly(mailbox)) {
title =
@@ -4250,7 +4247,7 @@ bw_idle_cb(BalsaWindow * window)
index = (BalsaIndex *) window->current_index;
if (index)
balsa_message_set(BALSA_MESSAGE(window->preview),
- balsa_index_get_mailbox_node(index)->mailbox,
+ balsa_index_get_mailbox(index),
balsa_index_get_current_msgno(index));
else
balsa_message_set(BALSA_MESSAGE(window->preview), NULL, 0);
@@ -4358,14 +4355,14 @@ bw_notebook_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
return;
}
- orig_mailbox = balsa_index_get_mailbox_node(orig_index)->mailbox;
+ orig_mailbox = balsa_index_get_mailbox(orig_index);
index = bw_notebook_find_page (GTK_NOTEBOOK(widget), x, y);
if (index == NULL)
return;
- mailbox = balsa_index_get_mailbox_node(index)->mailbox;
+ mailbox = balsa_index_get_mailbox(index);
if (mailbox != NULL && mailbox != orig_mailbox)
balsa_index_transfer(orig_index, selected, mailbox,
@@ -4402,7 +4399,7 @@ bw_notebook_page_notify_cb(GtkWidget *widget,
LibBalsaMailbox *mailbox;
gint page_num;
- mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(child))->mailbox;
+ mailbox = balsa_index_get_mailbox(BALSA_INDEX(child));
page_num = gtk_notebook_page_num(notebook, widget);
libbalsa_mailbox_set_position(mailbox, page_num);
}
@@ -4765,7 +4762,7 @@ balsa_window_next_unread(BalsaWindow * window)
{
BalsaIndex *index =
BALSA_INDEX(balsa_window_find_current_index(window));
- LibBalsaMailbox *mailbox = index ? balsa_index_get_mailbox_node(index)->mailbox : NULL;
+ LibBalsaMailbox *mailbox = index ? balsa_index_get_mailbox(index): NULL;
if (libbalsa_mailbox_get_unread(mailbox) > 0) {
if (!balsa_index_select_next_unread(index)) {
diff --git a/src/message-window.c b/src/message-window.c
index a7f154d3f..0d9c4479f 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -323,7 +323,7 @@ mw_set_buttons_sensitive(MessageWindow * mw)
enable = index && balsa_index_previous_msgno(index, current_msgno) > 0;
mw_set_enabled(mw, "previous-message", enable);
- mailbox = index != NULL ? balsa_index_get_mailbox_node(index)->mailbox : NULL;
+ mailbox = index != NULL ? balsa_index_get_mailbox(index): NULL;
enable = mailbox != NULL && libbalsa_mailbox_get_unread_messages(mailbox) > 0;
mw_set_enabled(mw, "next-unread", enable);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index d8c163e03..9b7fee353 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2206,7 +2206,7 @@ attachments_add(GtkWidget * widget,
if (info == TARGET_MESSAGES) {
BalsaIndex *index =
*(BalsaIndex **) gtk_selection_data_get_data(selection_data);
- LibBalsaMailbox *mailbox = balsa_index_get_mailbox_node(index)->mailbox;
+ LibBalsaMailbox *mailbox = balsa_index_get_mailbox(index);
GArray *selected = balsa_index_selected_msgnos_new(index);
guint i;
@@ -2784,7 +2784,7 @@ drag_data_quote(GtkWidget * widget,
case TARGET_MESSAGES:
index =
*(BalsaIndex **) gtk_selection_data_get_data(selection_data);
- mailbox = balsa_index_get_mailbox_node(index)->mailbox;
+ mailbox = balsa_index_get_mailbox(index);
selected = balsa_index_selected_msgnos_new(index);
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]