[balsa/wip/gtk4: 336/351] Clean up some BalsaMailboxNode code



commit 3780d81a667c56ca95d9f6faa3381aa9d8fdb5cc
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun May 6 12:19:25 2018 -0400

    Clean up some BalsaMailboxNode code

 src/balsa-mblist.c |   52 ++++++++++++++++++++++++-----------------
 src/folder-conf.c  |   65 ++++++++++++++++++++++++++++++++-------------------
 src/main-window.c  |   16 ++++++++----
 3 files changed, 81 insertions(+), 52 deletions(-)
---
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index a8cdf47..632d3e8 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -554,11 +554,13 @@ bmbl_tree_collapse_helper(GtkTreeModel * model, GtkTreeIter * iter)
     if (gtk_tree_model_iter_children(model, &child_iter, iter)) {
         do {
             BalsaMailboxNode *mbnode;
+            LibBalsaMailbox *mailbox;
 
             gtk_tree_model_get(model, &child_iter,
                                MBNODE_COLUMN, &mbnode, -1);
-            if (balsa_mailbox_node_get_mailbox(mbnode))
-               libbalsa_mailbox_set_exposed(balsa_mailbox_node_get_mailbox(mbnode), FALSE);
+            mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+            if (mailbox != NULL)
+               libbalsa_mailbox_set_exposed(mailbox, FALSE);
            g_object_unref(mbnode);
             bmbl_tree_collapse_helper(model, &child_iter);
         } while (gtk_tree_model_iter_next(model, &child_iter));
@@ -843,13 +845,15 @@ bmbl_row_activated_cb(GtkTreeView * tree_view, GtkTreePath * path,
     GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
     GtkTreeIter iter;
     BalsaMailboxNode *mbnode;
+    LibBalsaMailbox *mailbox;
 
     gtk_tree_model_get_iter(model, &iter, path);
     gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
     g_return_if_fail(mbnode != NULL);
 
-    if (balsa_mailbox_node_get_mailbox(mbnode))
-        balsa_mblist_open_mailbox(balsa_mailbox_node_get_mailbox(mbnode));
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox != NULL)
+        balsa_mblist_open_mailbox(mailbox);
     g_object_unref(mbnode);
 }
 
@@ -1093,17 +1097,17 @@ get_lru_descendant(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
 {
     struct lru_data *dt  = (struct lru_data*)data;
     BalsaMailboxNode *mbnode;
+    LibBalsaMailbox *mailbox;
 
     if(!gtk_tree_path_is_descendant(path, dt->ancestor_path))
         return FALSE;
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
 
-    if (balsa_mailbox_node_get_mailbox(mbnode) != NULL &&
-        libbalsa_mailbox_is_open(balsa_mailbox_node_get_mailbox(mbnode)) &&
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox != NULL && libbalsa_mailbox_is_open(mailbox) &&
         (dt->mbnode == NULL ||
          (balsa_mailbox_node_get_last_use(mbnode)
-          < balsa_mailbox_node_get_last_use(dt->mbnode))))
-    {
+          < balsa_mailbox_node_get_last_use(dt->mbnode)))) {
         g_set_object(&dt->mbnode, mbnode);
     }
 
@@ -1198,15 +1202,16 @@ bmbl_real_disconnect_mbnode_signals(BalsaMailboxNode * mbnode)
 static gboolean
 bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
 {
+    LibBalsaMailbox *mailbox;
     const gchar *icon;
     const gchar *name;
     gchar *tmp = NULL;
     gboolean expose = FALSE;
 
-    g_return_val_if_fail(mbnode, FALSE);
+    g_return_val_if_fail(mbnode != NULL, FALSE);
 
-    if (balsa_mailbox_node_get_mailbox(mbnode)) {
-        LibBalsaMailbox *mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox != NULL) {
        static guint mailbox_changed_signal = 0;
 
        if (LIBBALSA_IS_MAILBOX_POP3(mailbox)) {
@@ -1250,15 +1255,14 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
                                                LB_MAILBOX_SUBSCRIBE_YES);
        }
 
-       if (!mailbox_changed_signal)
+       if (mailbox_changed_signal == 0)
            mailbox_changed_signal =
                g_signal_lookup("changed", LIBBALSA_TYPE_MAILBOX);
-       if (!g_signal_has_handler_pending(G_OBJECT(balsa_mailbox_node_get_mailbox(mbnode)),
+       if (!g_signal_has_handler_pending(G_OBJECT(mailbox),
                                           mailbox_changed_signal, 0, TRUE)) {
            /* Now we have a mailbox: */
-           g_signal_connect(balsa_mailbox_node_get_mailbox(mbnode), "changed",
-                            G_CALLBACK(bmbl_mailbox_changed_cb),
-                            NULL);
+           g_signal_connect(mailbox, "changed",
+                            G_CALLBACK(bmbl_mailbox_changed_cb), NULL);
             if (libbalsa_mailbox_get_unread(mailbox) > 0
                 && (libbalsa_mailbox_get_subscribe(mailbox) !=
                     LB_MAILBOX_SUBSCRIBE_NO))
@@ -1267,7 +1271,7 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
                               0, TRUE);
            /* If necessary, expand rows to expose this mailbox after
             * setting its mbnode in the tree-store. */
-           expose = libbalsa_mailbox_get_exposed(balsa_mailbox_node_get_mailbox(mbnode));
+           expose = libbalsa_mailbox_get_exposed(mailbox);
        }
     } else {
        /* new directory, but not a mailbox */
@@ -1286,7 +1290,7 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
                        -1);
     g_free(tmp);
 
-    if (balsa_mailbox_node_get_mailbox(mbnode) != NULL) {
+    if (mailbox != NULL) {
        GtkTreeModel *model = GTK_TREE_MODEL(balsa_app.mblist_tree_store);
        if (expose) {
            GtkTreePath *path = gtk_tree_model_get_path(model, iter);
@@ -1361,10 +1365,13 @@ bmbl_node_style(GtkTreeModel * model, GtkTreeIter * iter)
     gchar *text_total = NULL;
 
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
-    if (!mbnode || !balsa_mailbox_node_get_mailbox(mbnode))
+    if (mbnode == NULL)
         return;
 
     mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox == NULL)
+        return;
+
     unread_messages = libbalsa_mailbox_get_unread(mailbox);
     total_messages = libbalsa_mailbox_get_total(mailbox);
 
@@ -1800,14 +1807,15 @@ bmbl_mru_activated_cb(GtkTreeView * tree_view, GtkTreePath * path,
     GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
     GtkTreeIter iter;
     BalsaMailboxNode *mbnode;
+    LibBalsaMailbox *mailbox;
 
     gtk_tree_model_get_iter(model, &iter, path);
     gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
-    g_return_if_fail(mbnode != NULL);
 
-    if (balsa_mailbox_node_get_mailbox(mbnode)) {
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox != NULL) {
         ((BalsaMBListMRUEntry *) data)->url =
-            g_strdup(libbalsa_mailbox_get_url(balsa_mailbox_node_get_mailbox(mbnode)));
+            g_strdup(libbalsa_mailbox_get_url(mailbox));
         bmbl_mru_activate_cb(NULL, data);
 
         gtk_dialog_response(GTK_DIALOG
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 6588409..e676ba1 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -491,16 +491,20 @@ browse_button_response(GtkDialog * dialog, gint response,
 {
     if (response == GTK_RESPONSE_OK) {
         BalsaMailboxNode *mbnode = bbd->mbnode;
-        if (!mbnode)
+        const gchar *dir;
+        LibBalsaServer *server;
+
+        if (mbnode == NULL)
             return;
 
         bbd->sdd->parent = mbnode;
-        if (balsa_mailbox_node_get_dir(mbnode))
-            gtk_entry_set_text(GTK_ENTRY(bbd->sdd->parent_folder),
-                               balsa_mailbox_node_get_dir(mbnode));
-        if(balsa_mailbox_node_get_server(mbnode))
+        dir = balsa_mailbox_node_get_dir(mbnode);
+        if (dir != NULL)
+            gtk_entry_set_text(GTK_ENTRY(bbd->sdd->parent_folder), dir);
+        server = balsa_mailbox_node_get_server(mbnode);
+        if (server != NULL)
             gtk_label_set_label(GTK_LABEL(bbd->sdd->host_label),
-                                libbalsa_server_get_host(balsa_mailbox_node_get_server(mbnode)));
+                                libbalsa_server_get_host(server));
     }
     validate_sub_folder(NULL, bbd->sdd);
     gtk_widget_set_sensitive(bbd->button, TRUE);
@@ -514,14 +518,15 @@ folder_selection_func(GtkTreeSelection * selection, GtkTreeModel * model,
 {
     GtkTreeIter iter;
     BalsaMailboxNode *mbnode;
+    LibBalsaServer *server;
     gboolean retval;
 
     gtk_tree_model_get_iter(model, &iter, path);
     gtk_tree_model_get(model, &iter, 0, &mbnode, -1);
-    retval = (LIBBALSA_IS_IMAP_SERVER(balsa_mailbox_node_get_server(mbnode))
+    server = balsa_mailbox_node_get_server(mbnode);
+    retval = (LIBBALSA_IS_IMAP_SERVER(server)
              && (sdd->mbnode == NULL
-                 || balsa_mailbox_node_get_server(sdd->mbnode) ==
-                     balsa_mailbox_node_get_server(mbnode)));
+                 || balsa_mailbox_node_get_server(sdd->mbnode) == server));
     g_object_unref(mbnode);
 
     return retval;
@@ -620,8 +625,11 @@ subfolder_conf_clicked_ok(SubfolderDialogData * sdd)
 
     if (sdd->mbnode) {
         /* Views stuff. */
-        if (balsa_mailbox_node_get_mailbox(sdd->mbnode))
-            mailbox_conf_view_check(sdd->mcv, balsa_mailbox_node_get_mailbox(sdd->mbnode));
+        LibBalsaMailbox *mailbox;
+
+        mailbox = balsa_mailbox_node_get_mailbox(sdd->mbnode);
+        if (mailbox != NULL)
+            mailbox_conf_view_check(sdd->mcv, mailbox);
         
         /* rename */
         if ((g_strcmp0(parent, sdd->old_parent) != 0) ||
@@ -703,7 +711,9 @@ folder, parent);
                      * go away, so we'd better rescan from higher up
                      */
                     BalsaMailboxNode *mb = balsa_mailbox_node_get_parent(sdd->mbnode);
-                    while (!balsa_mailbox_node_get_mailbox(mb) && balsa_mailbox_node_get_parent(mb))
+
+                    while (balsa_mailbox_node_get_mailbox(mb) == NULL &&
+                           balsa_mailbox_node_get_parent(mb) != NULL)
                         mb = balsa_mailbox_node_get_parent(mb);
                     balsa_mailbox_node_rescan(mb);
                     balsa_mailbox_node_rescan(sdd->mbnode);
@@ -751,6 +761,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
     SubfolderDialogData *sdd;
     static SubfolderDialogData *sdd_new = NULL;
     guint row;
+    LibBalsaServer *server;
 
     /* Allow only one dialog per mailbox node, and one with mn == NULL
      * for creating a new subfolder. */
@@ -764,9 +775,12 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
     sdd = g_new(SubfolderDialogData, 1);
     sdd->ok = (CommonDialogFunc) subfolder_conf_clicked_ok;
 
-    if ((sdd->mbnode = mn)) {
+    if ((sdd->mbnode = mn) != NULL) {
        /* update */
-       if (!balsa_mailbox_node_get_mailbox(mn)) {
+        LibBalsaMailbox *mailbox;
+
+       mailbox = balsa_mailbox_node_get_mailbox(mn);
+       if (mailbox == NULL) {
             balsa_information(LIBBALSA_INFORMATION_ERROR,
                               _("An IMAP folder that is not a mailbox\n"
                                 "has no properties that can be changed."));
@@ -774,7 +788,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
            return;
        }
        sdd->parent = balsa_mailbox_node_get_parent(mn);
-       sdd->old_folder = libbalsa_mailbox_get_name(balsa_mailbox_node_get_mailbox(mn));
+       sdd->old_folder = libbalsa_mailbox_get_name(mailbox);
     } else {
        /* create */
         sdd->old_folder = NULL;
@@ -833,9 +847,10 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
 
     ++row;
     (void) libbalsa_create_grid_label(_("Host:"), grid, row);
+
+    server = sdd->mbnode != NULL ? balsa_mailbox_node_get_server(sdd->mbnode) : NULL;
     sdd->host_label =
-        gtk_label_new(sdd->mbnode && balsa_mailbox_node_get_server(sdd->mbnode)
-                      ? libbalsa_server_get_host(balsa_mailbox_node_get_server(sdd->mbnode)) : "");
+        gtk_label_new(server != NULL ? libbalsa_server_get_host(server) : "");
     gtk_widget_set_halign(sdd->host_label, GTK_ALIGN_START);
     gtk_widget_set_hexpand(sdd->host_label, TRUE);
     gtk_grid_attach(GTK_GRID(grid), sdd->host_label, 1, row, 1, 1);
@@ -872,19 +887,21 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         gchar * rights;
         gchar * quotas;
         gboolean readonly;
+        LibBalsaMailbox *mailbox;
 
         ++row;
         (void) libbalsa_create_grid_label(_("Permissions:"), grid, row);
 
         /* mailbox closed: no detailed permissions available */
-        readonly = libbalsa_mailbox_get_readonly(balsa_mailbox_node_get_mailbox(mn));
-        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)))) {
+        mailbox = balsa_mailbox_node_get_mailbox(mn);
+        readonly = libbalsa_mailbox_get_readonly(mailbox);
+        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(mailbox))) {
             rights_str = g_string_new(std_acls[readonly ? 1 : 3]);
             rights_str =
                 g_string_append(rights_str,
                                 _("\ndetailed permissions are available only for open folders"));
         } else {
-            rights = libbalsa_imap_get_rights(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)));
+            rights = libbalsa_imap_get_rights(LIBBALSA_MAILBOX_IMAP(mailbox));
             if (!rights) {
                 rights_str = g_string_new(std_acls[readonly ? 1 : 3]);
                 rights_str =
@@ -907,7 +924,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
 
                 /* acl's - only available if I have admin privileges */
                 if ((acls =
-                     libbalsa_imap_get_acls(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn))))) {
+                     libbalsa_imap_get_acls(LIBBALSA_MAILBOX_IMAP(mailbox))) != NULL) {
                     int uid;
 
                     for (uid = 0; acls[uid]; uid += 2) {
@@ -939,12 +956,12 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         (void) libbalsa_create_grid_label(_("Quota:"), grid, row);
 
         /* mailbox closed: no quota available */
-        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn))))
+        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(mailbox)))
             quotas = g_strdup(_("quota information available only for open folders"));
         else {
             gulong max, used;
 
-            if (!libbalsa_imap_get_quota(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)), &max, 
&used))
+            if (!libbalsa_imap_get_quota(LIBBALSA_MAILBOX_IMAP(mailbox), &max, &used))
                 quotas = g_strdup(_("the server does not support quotas"));
             else if (max == 0 && used == 0)
                 quotas = g_strdup(_("no limits"));
@@ -964,7 +981,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         gtk_grid_attach(GTK_GRID(grid), label, 1, row, 1, 1);
         g_free(quotas);
 
-        sdd->mcv = mailbox_conf_view_new(balsa_mailbox_node_get_mailbox(mn),
+        sdd->mcv = mailbox_conf_view_new(mailbox,
                                          GTK_WINDOW(sdd->dialog),
                                          grid, 5,
                                          G_CALLBACK(set_ok_sensitive));
diff --git a/src/main-window.c b/src/main-window.c
index d04cf05..937b7c5 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3343,11 +3343,13 @@ bw_add_mbox_to_checklist(GtkTreeModel * model, GtkTreePath * path,
     LibBalsaMailbox *mailbox;
 
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
-    g_return_val_if_fail(mbnode, FALSE);
 
-    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode))) {  /* mailbox, not a folder */
+    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode)) != NULL) {
+        /* mailbox, not a folder */
+        const gchar *dir = balsa_mailbox_node_get_dir(mbnode);
+
        if (!LIBBALSA_IS_MAILBOX_IMAP(mailbox) ||
-           bw_imap_check_test(balsa_mailbox_node_get_dir(mbnode) ? balsa_mailbox_node_get_dir(mbnode) :
+           bw_imap_check_test(dir != NULL ? dir :
                            libbalsa_mailbox_imap_get_path
                            (LIBBALSA_MAILBOX_IMAP(mailbox))))
            *list = g_slist_prepend(*list, g_object_ref(mailbox));
@@ -3721,10 +3723,12 @@ mw_mbox_change_connection_status(GtkTreeModel * model, GtkTreePath * path,
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
     g_return_val_if_fail(mbnode, FALSE);
 
-    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode))) {  /* mailbox, not a folder */
+    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode)) != NULL) {
+        /* mailbox, not a folder */
+        const gchar *dir = balsa_mailbox_node_get_dir(mbnode);
+
         if (LIBBALSA_IS_MAILBOX_IMAP(mailbox) &&
-            bw_imap_check_test(balsa_mailbox_node_get_dir(mbnode) ?
-                balsa_mailbox_node_get_dir(mbnode) :
+            bw_imap_check_test(dir != NULL ? dir :
                 libbalsa_mailbox_imap_get_path(LIBBALSA_MAILBOX_IMAP(mailbox)))) {
             libbalsa_mailbox_test_can_reach(g_object_ref(mailbox),
                                             mw_mbox_can_reach_cb, NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]