[balsa] balsa-index: Use modern macros



commit 3b55346f771caf0ec551e001e5edb2923cb89abf
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Jul 21 20:45:36 2019 -0400

    balsa-index: Use modern macros
    
    balsa-index: Use modern macros to declare and define.
    Make BalsaIndex opaque, and provide necessary accessors.
    
    * src/balsa-index.c: use G_DEFINE_TYPE to define BalsaIndex;
      (balsa_index_class_init), (bndx_destroy),
      (balsa_index_init), (balsa_index_select_thread),
      (balsa_index_get_mailbox_node), (balsa_index_get_current_msgno),
      (balsa_index_get_filter_no), (balsa_index_get_next_message),
      (balsa_index_get_prev_message), (balsa_index_get_filter_string),
      (balsa_index_set_last_use_time):
    * src/balsa-index.h: use G_DECLARE_FINAL_TYPE;
    * src/balsa-app.c (balsa_find_index_by_mailbox):
    * src/balsa-mblist.c (bmbl_tree_expand), (bmbl_drag_cb),
      (bmbl_open_mailbox), (bmbl_update_mailbox):
    * src/main-window.c (continue_activated), (print_activated),
      (reset_filter_activated), (mailbox_close_activated),
      (select_filters_activated), (remove_duplicates_activated),
      (threading_change_state), (bw_enable_mailbox_menus),
      (balsa_window_update_book_menus), (bw_enable_message_menus),
      (balsa_window_set_thread_messages),
      (balsa_window_real_close_mbnode), (bw_close_mailbox_on_timer),
      (bw_find_real), (bw_hide_changed_set_view_filter),
      (bw_reset_filter), (bw_notebook_switch_page_cb),
      (bw_index_changed_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
      the accessors.

 ChangeLog            |  33 +++++++++++++
 src/balsa-app.c      |  20 +++++---
 src/balsa-index.c    | 137 +++++++++++++++++++++++++++++++++++++--------------
 src/balsa-index.h    |  66 +++++++------------------
 src/balsa-mblist.c   |  26 +++++-----
 src/main-window.c    | 106 +++++++++++++++++++++------------------
 src/message-window.c |  13 ++---
 src/sendmsg-window.c |   4 +-
 8 files changed, 244 insertions(+), 161 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index eb1fa6252..44a394909 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2019-07-21  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       balsa-index: Use modern macros to declare and define.
+
+       Make BalsaIndex opaque, and provide necessary accessors.
+
+       * src/balsa-index.c: use G_DEFINE_TYPE to define BalsaIndex;
+       (balsa_index_class_init), (bndx_destroy),
+       (balsa_index_init), (balsa_index_select_thread),
+       (balsa_index_get_mailbox_node), (balsa_index_get_current_msgno),
+       (balsa_index_get_filter_no), (balsa_index_get_next_message),
+       (balsa_index_get_prev_message), (balsa_index_get_filter_string),
+       (balsa_index_set_last_use_time):
+       * src/balsa-index.h: use G_DECLARE_FINAL_TYPE;
+       * src/balsa-app.c (balsa_find_index_by_mailbox):
+       * src/balsa-mblist.c (bmbl_tree_expand), (bmbl_drag_cb),
+       (bmbl_open_mailbox), (bmbl_update_mailbox):
+       * src/main-window.c (continue_activated), (print_activated),
+       (reset_filter_activated), (mailbox_close_activated),
+       (select_filters_activated), (remove_duplicates_activated),
+       (threading_change_state), (bw_enable_mailbox_menus),
+       (balsa_window_update_book_menus), (bw_enable_message_menus),
+       (balsa_window_set_thread_messages),
+       (balsa_window_real_close_mbnode), (bw_close_mailbox_on_timer),
+       (bw_find_real), (bw_hide_changed_set_view_filter),
+       (bw_reset_filter), (bw_notebook_switch_page_cb),
+       (bw_index_changed_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
+       the accessors.
+
 2019-07-19  Peter Bloomfield  <pbloomfield bellsouth net>
 
        * libbalsa/filter-file.c (libbalsa_mailbox_filters_load_config):
diff --git a/src/balsa-app.c b/src/balsa-app.c
index ca5c9e86d..606920044 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -884,18 +884,22 @@ BalsaIndex*
 balsa_find_index_by_mailbox(LibBalsaMailbox * mailbox)
 {
     GtkWidget *page;
-    GtkWidget *index;
+    GtkWidget *child;
     guint i;
-    g_return_val_if_fail(balsa_app.notebook, NULL);
+
+    g_return_val_if_fail(GTK_IS_NOTEBOOK(balsa_app.notebook), NULL);
 
     for (i = 0;
-        (page =
-         gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i));
+        (page = gtk_notebook_get_nth_page((GtkNotebook *) balsa_app.notebook, i)) != NULL;
         i++) {
-        index = gtk_bin_get_child(GTK_BIN(page));
-       if (index && BALSA_INDEX(index)->mailbox_node
-            && BALSA_INDEX(index)->mailbox_node->mailbox == mailbox)
-           return BALSA_INDEX(index);
+        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);
+
+            if (mailbox_node != NULL && mailbox_node->mailbox == mailbox)
+                return bindex;
+        }
     }
 
     /* didn't find a matching mailbox */
diff --git a/src/balsa-index.c b/src/balsa-index.c
index aa22a05cc..bd6bd5d5f 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -60,8 +60,6 @@
 
 
 /* gtk widget */
-static void bndx_class_init(BalsaIndexClass * klass);
-static void bndx_instance_init(BalsaIndex * index);
 static void bndx_destroy(GObject * obj);
 static gboolean bndx_popup_menu(GtkWidget * widget);
 
@@ -142,38 +140,44 @@ static void bndx_select_row(BalsaIndex * index, GtkTreePath * path);
 /* Other callbacks. */
 static void bndx_store_address(gpointer data);
 
-static GtkTreeViewClass *parent_class = NULL;
+struct _BalsaIndex {
+    GtkTreeView tree_view;
+
+    /* the popup menu and some items we need to refer to */
+    GtkWidget *popup_menu;
+    GtkWidget *delete_item;
+    GtkWidget *undelete_item;
+    GtkWidget *move_to_trash_item;
+    GtkWidget *toggle_item;
+    GtkWidget *move_to_item;
+
+    BalsaMailboxNode* mailbox_node;
+    guint current_msgno;
+    guint next_msgno;
+       gboolean current_message_is_deleted:1;
+    gboolean prev_message:1;
+    gboolean next_message:1;
+    gboolean has_selection_changed_idle:1;
+    gboolean has_mailbox_changed_idle:1;
+    gboolean collapsing:1;
+    int    filter_no;
+    gchar *filter_string; /* Quick view filter string, if any */
+
+    /* signal handler ids */
+    gulong row_expanded_id;
+    gulong row_collapsed_id;
+    gulong selection_changed_id;
+
+       LibBalsaMailboxSearchIter *search_iter;
+    BalsaIndexWidthPreference width_preference;
+};
 
 /* Class type. */
-GType
-balsa_index_get_type(void)
-{
-    static GType balsa_index_type = 0;
-
-    if (!balsa_index_type) {
-        static const GTypeInfo balsa_index_info = {
-            sizeof(BalsaIndexClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-            (GClassInitFunc) bndx_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-            sizeof(BalsaIndex),
-            0,                  /* n_preallocs */
-            (GInstanceInitFunc) bndx_instance_init
-        };
-
-        balsa_index_type =
-            g_type_register_static(GTK_TYPE_TREE_VIEW,
-                                   "BalsaIndex", &balsa_index_info, 0);
-    }
-
-    return balsa_index_type;
-}
+G_DEFINE_TYPE(BalsaIndex, balsa_index, GTK_TYPE_TREE_VIEW)
 
 /* BalsaIndex class init method. */
 static void
-bndx_class_init(BalsaIndexClass * klass)
+balsa_index_class_init(BalsaIndexClass * klass)
 {
     GObjectClass *object_class;
     GtkWidgetClass *widget_class;
@@ -181,21 +185,17 @@ bndx_class_init(BalsaIndexClass * klass)
     object_class = (GObjectClass *) klass;
     widget_class = (GtkWidgetClass *) klass;
 
-    parent_class = g_type_class_peek_parent(klass);
-
     balsa_index_signals[INDEX_CHANGED] =
         g_signal_new("index-changed",
                      G_TYPE_FROM_CLASS(object_class),
                     G_SIGNAL_RUN_FIRST,
-                     G_STRUCT_OFFSET(BalsaIndexClass,
-                                     index_changed),
+                     0,
                      NULL, NULL,
                     NULL,
                      G_TYPE_NONE, 0);
 
     object_class->dispose = bndx_destroy;
     widget_class->popup_menu = bndx_popup_menu;
-    klass->index_changed = NULL;
 }
 
 /* Object class destroy method. */
@@ -246,8 +246,7 @@ bndx_destroy(GObject * obj)
 
     g_free(index->filter_string); index->filter_string = NULL;
 
-    if (G_OBJECT_CLASS(parent_class)->dispose)
-        (*G_OBJECT_CLASS(parent_class)->dispose) (obj);
+    G_OBJECT_CLASS(balsa_index_parent_class)->dispose(obj);
 }
 
 /* Widget class popup menu method. */
@@ -296,7 +295,7 @@ bndx_string_width(const gchar * text)
 /* BalsaIndex instance init method; no tree store is set on the tree
  * view--that's handled later, when the view is populated. */
 static void
-bndx_instance_init(BalsaIndex * index)
+balsa_index_init(BalsaIndex * index)
 {
     GtkTreeView *tree_view = GTK_TREE_VIEW(index);
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
@@ -2833,3 +2832,67 @@ balsa_index_select_thread(BalsaIndex * bindex)
     } while (valid
              && gtk_tree_model_iter_parent(model, &next_iter, &iter));
 }
+
+/*
+ * Getters
+ */
+
+BalsaMailboxNode *
+balsa_index_get_mailbox_node(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
+
+    return bindex->mailbox_node;
+}
+
+guint
+balsa_index_get_current_msgno(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), 0);
+
+    return bindex->current_msgno;
+}
+
+gint
+balsa_index_get_filter_no(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), 0);
+
+    return bindex->filter_no;
+}
+
+gboolean
+balsa_index_get_next_message(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), 0);
+
+    return bindex->next_message;
+}
+
+gboolean
+balsa_index_get_prev_message(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), 0);
+
+    return bindex->prev_message;
+}
+
+const gchar *
+balsa_index_get_filter_string(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
+
+    return bindex->filter_string;
+}
+
+/*
+ * Setter
+ */
+
+void
+balsa_index_set_last_use_time(BalsaIndex *bindex)
+{
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
+
+    time(&bindex->mailbox_node->last_use);
+}
diff --git a/src/balsa-index.h b/src/balsa-index.h
index fee4ccc5f..cca381c64 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -26,58 +26,13 @@
 
 G_BEGIN_DECLS
 
-    GType balsa_index_get_type(void);
-
-#define BALSA_TYPE_INDEX          (balsa_index_get_type ())
-#define BALSA_INDEX(obj)          (G_TYPE_CHECK_INSTANCE_CAST (obj, BALSA_TYPE_INDEX, BalsaIndex))
-#define BALSA_INDEX_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST (klass, BALSA_TYPE_INDEX, BalsaIndexClass))
-#define BALSA_IS_INDEX(obj)       (G_TYPE_CHECK_INSTANCE_TYPE (obj, BALSA_TYPE_INDEX))
-#define BALSA_IS_INDEX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, BALSA_TYPE_INDEX))
+#define BALSA_TYPE_INDEX (balsa_index_get_type ())
 
+G_DECLARE_FINAL_TYPE(BalsaIndex, balsa_index, BALSA, INDEX, GtkTreeView)
 
     typedef enum { BALSA_INDEX_WIDE, BALSA_INDEX_NARROW }
         BalsaIndexWidthPreference;
 
-    typedef struct _BalsaIndex BalsaIndex;
-    typedef struct _BalsaIndexClass BalsaIndexClass;
-
-    struct _BalsaIndex {
-        GtkTreeView tree_view;
-        
-        /* the popup menu and some items we need to refer to */
-        GtkWidget *popup_menu;
-        GtkWidget *delete_item;
-        GtkWidget *undelete_item;
-        GtkWidget *move_to_trash_item;
-        GtkWidget *toggle_item;
-        GtkWidget *move_to_item;
-
-        BalsaMailboxNode* mailbox_node;
-        guint current_msgno;
-        guint next_msgno;
-       gboolean current_message_is_deleted:1;
-        gboolean prev_message:1;
-        gboolean next_message:1;
-        gboolean has_selection_changed_idle:1;
-        gboolean has_mailbox_changed_idle:1;
-        gboolean collapsing:1;
-        int    filter_no;
-        gchar *filter_string; /* Quick view filter string, if any */
-
-        /* signal handler ids */
-        gulong row_expanded_id;
-        gulong row_collapsed_id;
-        gulong selection_changed_id;
-
-       LibBalsaMailboxSearchIter *search_iter;
-        BalsaIndexWidthPreference width_preference;
-    };
-
-    struct _BalsaIndexClass {
-       GtkTreeViewClass parent_class;
-
-        void (*index_changed) (BalsaIndex* bindex);
-    };
 
 /* tree model columns */
     enum {
@@ -183,6 +138,23 @@ G_BEGIN_DECLS
     /* Count of selected messages. */
     gint balsa_index_count_selected_messages(BalsaIndex * bindex);
 
+/*
+ * Getters
+ */
+
+BalsaMailboxNode * balsa_index_get_mailbox_node(BalsaIndex *bindex);
+guint balsa_index_get_current_msgno(BalsaIndex *bindex);
+gint balsa_index_get_filter_no(BalsaIndex *bindex);
+gboolean balsa_index_get_next_message(BalsaIndex *bindex);
+gboolean balsa_index_get_prev_message(BalsaIndex *bindex);
+const gchar * balsa_index_get_filter_string(BalsaIndex *bindex);
+
+/*
+ * Setter
+ */
+
+void balsa_index_set_last_use_time(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 8adf44767..4c9a4870e 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -550,8 +550,8 @@ bmbl_tree_expand(GtkTreeView * tree_view, GtkTreeIter * iter,
        GtkWidget *current_index =
            balsa_window_find_current_index(balsa_app.main_window);
        LibBalsaMailbox *current_mailbox =
-           current_index ?
-           BALSA_INDEX(current_index)->mailbox_node->mailbox :
+           current_index != NULL ?
+           balsa_index_get_mailbox_node(BALSA_INDEX(current_index))->mailbox :
            NULL;
        gboolean first_mailbox = TRUE;
 
@@ -840,7 +840,7 @@ bmbl_drag_cb(GtkWidget * widget, GdkDragContext * context,
         return;
     }
 
-    orig_mailbox = orig_index->mailbox_node->mailbox;
+    orig_mailbox = balsa_index_get_mailbox_node(orig_index)->mailbox;
 
     /* find the node and mailbox */
 
@@ -1137,30 +1137,29 @@ static void
 bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
 {
     int i;
-    GtkWidget *index;
+    GtkWidget *bindex;
     BalsaMailboxNode *mbnode;
 
     mbnode = balsa_find_mailbox(mailbox);
-    if (!mbnode) {
+    if (mbnode == NULL) {
         g_warning(_("Failed to find mailbox"));
         return;
     }
 
-    index = balsa_window_find_current_index(balsa_app.main_window);
+    bindex = balsa_window_find_current_index(balsa_app.main_window);
 
     /* If we currently have a page open, update the time last visited */
-    if (index) {
-       time(&BALSA_INDEX(index)->mailbox_node->last_use);
-    }
+    if (bindex != NULL)
+        balsa_index_set_last_use_time(BALSA_INDEX(index));
 
     i = balsa_find_notebook_page_num(mailbox);
     if (i != -1) {
         if (set_current) {
             gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook),
                                           i);
-            index = balsa_window_find_current_index(balsa_app.main_window);
-            time(&BALSA_INDEX(index)->mailbox_node->last_use);
-            balsa_index_set_column_widths(BALSA_INDEX(index));
+            bindex = balsa_window_find_current_index(balsa_app.main_window);
+            balsa_index_set_last_use_time(BALSA_INDEX(bindex));
+            balsa_index_set_column_widths(BALSA_INDEX(bindex));
         }
     } else { /* page with mailbox not found, open it */
         balsa_window_open_mbnode(balsa_app.main_window, mbnode,
@@ -1434,7 +1433,8 @@ bmbl_update_mailbox(GtkTreeStore * store, LibBalsaMailbox * mailbox)
     bmbl_node_style(model, &iter);
 
     bindex = balsa_window_find_current_index(balsa_app.main_window);
-    if (!bindex || mailbox != BALSA_INDEX(bindex)->mailbox_node->mailbox)
+    if (bindex == NULL ||
+        mailbox != balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox)
         return;
 
     balsa_window_set_statusbar(balsa_app.main_window, mailbox);
diff --git a/src/main-window.c b/src/main-window.c
index 1d295b74f..c1109a7a7 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -1021,13 +1021,13 @@ continue_activated(GSimpleAction * action,
                    gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    GtkWidget *bindex;
 
-    index = balsa_window_find_current_index(window);
+    bindex = balsa_window_find_current_index(window);
 
-    if (index
-        && BALSA_INDEX(index)->mailbox_node->mailbox == balsa_app.draftbox)
-        balsa_message_continue(BALSA_INDEX(index));
+    if (bindex != NULL &&
+        balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox == balsa_app.draftbox)
+        balsa_message_continue(BALSA_INDEX(bindex));
     else
         balsa_mblist_open_mailbox(balsa_app.draftbox);
 }
@@ -1083,20 +1083,24 @@ print_activated(GSimpleAction * action,
                 gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    GtkWidget *widget;
     BalsaIndex *bindex;
+    guint current_msgno;
 
-    index = balsa_window_find_current_index(window);
-    if (!index)
+    widget = balsa_window_find_current_index(window);
+    if (widget == NULL)
         return;
 
-    bindex = BALSA_INDEX(index);
-    if (bindex->current_msgno) {
+    bindex = BALSA_INDEX(widget);
+    current_msgno = balsa_index_get_current_msgno(bindex);
+    if (current_msgno > 0) {
         LibBalsaMessage *message =
-            libbalsa_mailbox_get_message(bindex->mailbox_node->mailbox,
-                                         bindex->current_msgno);
-        if (!message)
+            libbalsa_mailbox_get_message(balsa_index_get_mailbox_node(bindex)->mailbox,
+                                         current_msgno);
+
+        if (message == NULL)
             return;
+
         message_print(message, GTK_WINDOW(window));
         g_object_unref(message);
     }
@@ -1313,7 +1317,7 @@ reset_filter_activated(GSimpleAction * action,
     /* do it by resetting the sos filder */
     gtk_entry_set_text(GTK_ENTRY(window->sos_entry), "");
     index = balsa_window_find_current_index(window);
-    bw_set_view_filter(window, BALSA_INDEX(index)->filter_no,
+    bw_set_view_filter(window, balsa_index_get_filter_no(BALSA_INDEX(index)),
                        window->sos_entry);
 }
 
@@ -1368,7 +1372,7 @@ mailbox_close_activated(GSimpleAction * action,
 
     index = balsa_window_find_current_index(window);
     if (index)
-        balsa_mblist_close_mailbox(BALSA_INDEX(index)->mailbox_node->
+        balsa_mblist_close_mailbox(balsa_index_get_mailbox_node(BALSA_INDEX(index))->
                                    mailbox);
 }
 
@@ -1392,7 +1396,7 @@ select_filters_activated(GSimpleAction * action,
 
     index = balsa_window_find_current_index(window);
     if (index)
-        filters_run_dialog(BALSA_INDEX(index)->mailbox_node->mailbox,
+        filters_run_dialog(balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox,
                            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),
@@ -1413,7 +1417,7 @@ remove_duplicates_activated(GSimpleAction * action,
     index = balsa_window_find_current_index(window);
     if (index) {
         LibBalsaMailbox *mailbox =
-            BALSA_INDEX(index)->mailbox_node->mailbox;
+            balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox;
         GError *err = NULL;
         gint dup_count =
             libbalsa_mailbox_move_duplicates(mailbox, NULL, &err);
@@ -1884,7 +1888,7 @@ 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(index)->mailbox_node)
+    if (index && (mbnode = balsa_index_get_mailbox_node(BALSA_INDEX(index)))
         && (mailbox = mbnode->mailbox))
         bw_enable_expand_collapse(window, mailbox);
 
@@ -2402,7 +2406,7 @@ bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index)
 
     enable = (index != NULL);
     if (enable) {
-        mbnode = index->mailbox_node;
+        mbnode = balsa_index_get_mailbox_node(index);
         mailbox = mbnode->mailbox;
     }
     bw_action_set_enabled(window, "mailbox-expunge",
@@ -2413,9 +2417,9 @@ bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index)
                            G_N_ELEMENTS(mailbox_actions), enable);
     bw_action_set_enabled(window, "new-imap-subfolder", balsa_mailbox_node_is_imap(mbnode));
     bw_action_set_enabled(window, "next-message",
-                          index && index->next_message);
+                          index != NULL && balsa_index_get_next_message(index));
     bw_action_set_enabled(window, "previous-message",
-                          index && index->prev_message);
+                          index != NULL && balsa_index_get_prev_message(index));
 
     bw_action_set_enabled(window, "remove-duplicates", mailbox &&
                           libbalsa_mailbox_can_move_duplicates(mailbox));
@@ -2436,12 +2440,16 @@ bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index)
 void
 balsa_window_update_book_menus(BalsaWindow * window)
 {
-    gboolean has_books = balsa_app.address_book_list != NULL;
+    gboolean enabled = balsa_app.address_book_list != NULL;
+
+    bw_action_set_enabled(window, "address-book",  enabled);
 
-    bw_action_set_enabled(window, "address-book",  has_books);
-    bw_action_set_enabled(window, "store-address", has_books &&
-                          window->current_index &&
-                          BALSA_INDEX(window->current_index)->current_msgno);
+    if (enabled && window->current_index != NULL) {
+        guint current_msgno =
+            balsa_index_get_current_msgno(BALSA_INDEX(window->current_index));
+        enabled = current_msgno > 0;
+    }
+    bw_action_set_enabled(window, "store-address", enabled);
 }
 
 /*
@@ -2482,7 +2490,7 @@ bw_enable_message_menus(BalsaWindow * window, guint msgno)
                            G_N_ELEMENTS(message_actions), enable);
 
     enable_mod =
-        (enable && !libbalsa_mailbox_get_readonly(bindex->mailbox_node->mailbox));
+        (enable && !libbalsa_mailbox_get_readonly(balsa_index_get_mailbox_node(bindex)->mailbox));
     bw_actions_set_enabled(window, modify_message_actions,
                            G_N_ELEMENTS(modify_message_actions),
                            enable_mod);
@@ -2619,7 +2627,7 @@ balsa_window_set_thread_messages(BalsaWindow * window, gboolean thread_messages)
     bw_action_set_boolean(window, "threading", thread_messages);
 
     if ((index = balsa_window_find_current_index(window)) != NULL
-        && (mbnode = BALSA_INDEX(index)->mailbox_node) != NULL
+        && (mbnode = balsa_index_get_mailbox_node(BALSA_INDEX(index))) != NULL
         && (mailbox = mbnode->mailbox) != NULL)
         bw_enable_expand_collapse(window, mailbox);
 }
@@ -3041,7 +3049,7 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
     index = balsa_window_find_current_index(window);
     mailbox = g_new(LibBalsaMailbox *, 1);
     if (index) {
-       *mailbox = BALSA_INDEX(index)->mailbox_node-> mailbox;
+       *mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(index))-> mailbox;
        g_object_add_weak_pointer(G_OBJECT(*mailbox), (gpointer *) mailbox);
     } else
        *mailbox = NULL;
@@ -3084,12 +3092,12 @@ bw_close_mailbox_on_timer(BalsaWindow * window)
             continue;
 
         if (balsa_app.close_mailbox_auto &&
-            (delta_time = current_time - index->mailbox_node->last_use) >
+            (delta_time = current_time - balsa_index_get_mailbox_node(index)->last_use) >
             balsa_app.close_mailbox_timeout) {
             if (balsa_app.debug)
                 fprintf(stderr, "Closing Page %d unused for %d s\n",
                         i, delta_time);
-            balsa_window_real_close_mbnode(window, index->mailbox_node);
+            balsa_window_real_close_mbnode(window, balsa_index_get_mailbox_node(index));
             if (i < c)
                 c--;
             i--;
@@ -3898,7 +3906,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
 
         if(ok == FIND_RESPONSE_FILTER) {
             LibBalsaMailbox *mailbox =
-                BALSA_INDEX(bindex)->mailbox_node->mailbox;
+                balsa_index_get_mailbox_node(BALSA_INDEX(bindex))->mailbox;
             LibBalsaCondition *filter, *res;
             filter = bw_get_view_filter(window);
             res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
@@ -3968,7 +3976,7 @@ bw_hide_changed_set_view_filter(BalsaWindow * window)
     if(!index)
         return;
 
-    mailbox = BALSA_INDEX(index)->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(index))->mailbox;
     /* 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
@@ -3998,7 +4006,7 @@ bw_reset_filter(BalsaWindow * bw)
 
     /* do it by resetting the sos filder */
     gtk_entry_set_text(GTK_ENTRY(bw->sos_entry), "");
-    bw_set_view_filter(bw, bindex->filter_no, bw->sos_entry);
+    bw_set_view_filter(bw, balsa_index_get_filter_no(bindex), bw->sos_entry);
 }
 
 /* empty_trash:
@@ -4117,12 +4125,13 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
     BalsaIndex *index;
     LibBalsaMailbox *mailbox;
     gchar *title;
+    const gchar *filter_string;
 
     if (window->current_index) {
        g_object_remove_weak_pointer(G_OBJECT(window->current_index),
                                     (gpointer *) &window->current_index);
        /* Note when this mailbox was hidden, for use in auto-closing. */
-       time(&BALSA_INDEX(window->current_index)->mailbox_node->last_use);
+        balsa_index_set_last_use_time(BALSA_INDEX(window->current_index));
         window->current_index = NULL;
     }
 
@@ -4137,9 +4146,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(&index->mailbox_node->last_use);
+    time(&balsa_index_get_mailbox_node(index)->last_use);
 
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox_node(index)->mailbox;
     if (libbalsa_mailbox_get_name(mailbox)) {
         if (libbalsa_mailbox_get_readonly(mailbox)) {
             title =
@@ -4155,13 +4164,14 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
 
     g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, index);
     bw_idle_replace(window, index);
-    bw_enable_message_menus(window, index->current_msgno);
+    bw_enable_message_menus(window, balsa_index_get_current_msgno(index));
     bw_enable_mailbox_menus(window, index);
 
+    filter_string = balsa_index_get_filter_string(index);
     gtk_entry_set_text(GTK_ENTRY(window->sos_entry),
-                       index->filter_string ? index->filter_string : "");
+                       filter_string != NULL ? filter_string : "");
     gtk_combo_box_set_active(GTK_COMBO_BOX(window->filter_choice),
-                             index->filter_no);
+                             balsa_index_get_filter_no(index));
 
     balsa_mblist_focus_mailbox(balsa_app.mblist, mailbox);
     balsa_window_set_statusbar(window, mailbox);
@@ -4186,13 +4196,13 @@ bw_index_changed_cb(GtkWidget * widget, gpointer data)
         return;
 
     index = BALSA_INDEX(widget);
-    bw_enable_message_menus(window, index->current_msgno);
+    bw_enable_message_menus(window, balsa_index_get_current_msgno(index));
     bw_enable_mailbox_menus(window, index);
 
     message = BALSA_MESSAGE(window->preview)->message;
     current_msgno = message != NULL ? libbalsa_message_get_msgno(message) : 0;
 
-    if (current_msgno != index->current_msgno)
+    if (current_msgno != balsa_index_get_current_msgno(index))
         bw_idle_replace(window, index);
 }
 
@@ -4240,8 +4250,8 @@ bw_idle_cb(BalsaWindow * window)
     index = (BalsaIndex *) window->current_index;
     if (index)
         balsa_message_set(BALSA_MESSAGE(window->preview),
-                          index->mailbox_node->mailbox,
-                          index->current_msgno);
+                          balsa_index_get_mailbox_node(index)->mailbox,
+                          balsa_index_get_current_msgno(index));
     else
         balsa_message_set(BALSA_MESSAGE(window->preview), NULL, 0);
 
@@ -4348,14 +4358,14 @@ bw_notebook_drag_received_cb(GtkWidget * widget, GdkDragContext * context,
         return;
     }
 
-    orig_mailbox = orig_index->mailbox_node->mailbox;
+    orig_mailbox = balsa_index_get_mailbox_node(orig_index)->mailbox;
 
     index = bw_notebook_find_page (GTK_NOTEBOOK(widget), x, y);
 
     if (index == NULL)
         return;
 
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox_node(index)->mailbox;
 
     if (mailbox != NULL && mailbox != orig_mailbox)
         balsa_index_transfer(orig_index, selected, mailbox,
@@ -4392,7 +4402,7 @@ bw_notebook_page_notify_cb(GtkWidget  *widget,
         LibBalsaMailbox *mailbox;
         gint page_num;
 
-        mailbox = BALSA_INDEX(child)->mailbox_node->mailbox;
+        mailbox = balsa_index_get_mailbox_node(BALSA_INDEX(child))->mailbox;
         page_num = gtk_notebook_page_num(notebook, widget);
         libbalsa_mailbox_set_position(mailbox, page_num);
     }
@@ -4755,7 +4765,7 @@ balsa_window_next_unread(BalsaWindow * window)
 {
     BalsaIndex *index =
         BALSA_INDEX(balsa_window_find_current_index(window));
-    LibBalsaMailbox *mailbox = index ? index->mailbox_node->mailbox : NULL;
+    LibBalsaMailbox *mailbox = index ? balsa_index_get_mailbox_node(index)->mailbox : 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 c89b8d1a0..a7f154d3f 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -306,12 +306,13 @@ mw_menubar_foreach(GtkWidget *widget, gpointer data)
 static void
 mw_set_buttons_sensitive(MessageWindow * mw)
 {
-    LibBalsaMailbox *mailbox = libbalsa_message_get_mailbox(mw->message);
+    LibBalsaMailbox *mailbox;
     BalsaIndex *index = mw->bindex;
     guint current_msgno = libbalsa_message_get_msgno(mw->message);
     gboolean enable;
 
-    if (!mailbox) {
+    mailbox = libbalsa_message_get_mailbox(mw->message);
+    if (mailbox == NULL) {
         gtk_widget_destroy(mw->window);
         return;
     }
@@ -322,12 +323,12 @@ mw_set_buttons_sensitive(MessageWindow * mw)
     enable = index && balsa_index_previous_msgno(index, current_msgno) > 0;
     mw_set_enabled(mw, "previous-message", enable);
 
-    enable = index && libbalsa_mailbox_get_unread_messages(index->mailbox_node->mailbox) > 0;
+    mailbox = index != NULL ? balsa_index_get_mailbox_node(index)->mailbox : NULL;
+
+    enable = mailbox != NULL && libbalsa_mailbox_get_unread_messages(mailbox) > 0;
     mw_set_enabled(mw, "next-unread", enable);
 
-    enable = index
-        && libbalsa_mailbox_total_messages(index->mailbox_node->mailbox) >
-        0;
+    enable = mailbox != NULL && libbalsa_mailbox_total_messages(mailbox) > 0;
     mw_set_enabled(mw, "next-flagged", enable);
 }
 
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index dfce2950b..d8c163e03 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 = index->mailbox_node->mailbox;
+       LibBalsaMailbox *mailbox = balsa_index_get_mailbox_node(index)->mailbox;
         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 = index->mailbox_node->mailbox;
+       mailbox = balsa_index_get_mailbox_node(index)->mailbox;
         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]