[balsa/gtk3] Combine mailboxes to be opened at startup in array



commit 10ae21253a804f080845856f923a13adc0603355
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Mar 6 19:20:51 2013 -0500

    Combine mailboxes to be opened at startup in array
    
        Combine all mailboxes to be opened at startup into a single
        array.
    
        * src/balsa-app.c (open_mailboxes_idle_cb),
        (balsa_add_open_mailbox_urls):
        * src/balsa-app.h: new method balsa_add_open_mailbox_urls; drop
        hacky extra-open-ref.
        * src/main.c (initial_open_inbox), (balsa_check_open_mailboxes),
        (scan_mailboxes_idle_cb), (balsa_cleanup), (handle_remote):
        collect mailbox URLs in an array.

 ChangeLog       |   13 +++++++++
 src/balsa-app.c |   37 +++++++++++++------------
 src/balsa-app.h |    2 +-
 src/main.c      |   82 ++++++++++++++++++++++++++++++++++++-------------------
 4 files changed, 87 insertions(+), 47 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c6e76a1..d52398e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2013-03-06  Peter Bloomfield
 
+       Combine all mailboxes to be opened at startup into a single
+       array.
+
+       * src/balsa-app.c (open_mailboxes_idle_cb),
+       (balsa_add_open_mailbox_urls):
+       * src/balsa-app.h: new method balsa_add_open_mailbox_urls; drop
+       hacky extra-open-ref.
+       * src/main.c (initial_open_inbox), (balsa_check_open_mailboxes),
+       (scan_mailboxes_idle_cb), (balsa_cleanup), (handle_remote):
+       collect mailbox URLs in an array.
+
+2013-03-06  Peter Bloomfield
+
        * src/balsa-index.c (bndx_queue_draw_idle_cb),
        (bndx_mailbox_changed_idle): queue redrawing the message index
        each time anything changes, to try to fix mis-rendering.
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 77c3d83..cc0fd19 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -544,15 +544,7 @@ open_mailboxes_idle_cb(gchar ** urls)
 
     gdk_threads_enter();
 
-    if (urls) {
-        gboolean hidden;
-
-        hidden = FALSE;
-        for (tmp = urls; *tmp; ++tmp) {
-            open_mailbox_by_url(*tmp, hidden);
-            hidden = TRUE;
-        }
-    } else if (libbalsa_mailbox_view_table) {
+    if (!urls && libbalsa_mailbox_view_table) {
         GPtrArray *array;
 
         array = g_ptr_array_new();
@@ -560,16 +552,18 @@ open_mailboxes_idle_cb(gchar ** urls)
                              (GHFunc) append_url_if_open, array);
         g_ptr_array_add(array, NULL);
         urls = (gchar **) g_ptr_array_free(array, FALSE);
+    }
 
-        if (*urls) {
-            open_mailbox_by_url(balsa_app.current_mailbox_url, TRUE);
-
-            for (tmp = urls; *tmp; ++tmp) {
-                if (!balsa_app.current_mailbox_url
-                    || strcmp(*tmp, balsa_app.current_mailbox_url)) {
-                    open_mailbox_by_url(*tmp, TRUE);
-                }
-            }
+    if (urls) {
+        for (tmp = urls; *tmp; ++tmp) {
+            gchar **p;
+
+            /* Have we already seen this URL? */
+            for (p = urls; p < tmp; ++p)
+                if (!strcmp(*p, *tmp))
+                    break;
+            if (p == tmp)
+                open_mailbox_by_url(*tmp, TRUE);
         }
     }
 
@@ -579,6 +573,13 @@ open_mailboxes_idle_cb(gchar ** urls)
     return FALSE;
 }
 
+void
+balsa_add_open_mailbox_urls(GPtrArray * url_array)
+{
+    g_hash_table_foreach(libbalsa_mailbox_view_table,
+                         (GHFunc) append_url_if_open, url_array);
+}
+
 GtkWidget *
 balsa_stock_button_with_label(const char *icon, const char *text)
 {
diff --git a/src/balsa-app.h b/src/balsa-app.h
index 3738d35..49b13af 100644
--- a/src/balsa-app.h
+++ b/src/balsa-app.h
@@ -305,7 +305,6 @@ extern struct BalsaApplication {
 
     /* command line options */
     gint open_inbox_upon_startup;
-    gboolean inbox_has_extra_open_ref;
     gint check_mail_upon_startup;
     gint remember_open_mboxes;
     gint open_unread_mailbox;
@@ -407,6 +406,7 @@ BalsaMailboxNode *balsa_find_dir(LibBalsaServer *server, const gchar * path);
 BalsaMailboxNode *balsa_find_url(const gchar * url);
 LibBalsaMailbox *balsa_find_mailbox_by_url(const gchar * url);
 LibBalsaMailbox *balsa_find_sentbox_by_url(const gchar * url);
+void balsa_add_open_mailbox_urls(GPtrArray * url_array);
 
 /** Returns a short mailbox name that identifies the host. This is
     longer than LibBalsaMailbox::name which contains only filename
diff --git a/src/main.c b/src/main.c
index 0cba86d..d156061 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,9 +84,6 @@ static gboolean balsa_init(int argc, char **argv);
 static void config_init(gboolean check_only);
 static void mailboxes_init(gboolean check_only);
 static void balsa_cleanup(void);
-gboolean initial_open_unread_mailboxes(void);
-/* yes void is there cause gcc is tha suck */
-gboolean initial_open_inbox(void);
 
 /* We need separate variable for storing command line requests to check the
    mail because such selection cannot be stored in balsa_app and later
@@ -304,7 +301,7 @@ threads_destroy(void)
    open mailboxes on startup if requested so.
    This is an idle handler. Be sure to use gdk_threads_{enter/leave}
  */
-gboolean
+static gboolean
 initial_open_unread_mailboxes()
 {
     GList *l, *gl;
@@ -325,7 +322,7 @@ initial_open_unread_mailboxes()
 }
 
 
-gboolean
+static gboolean
 initial_open_inbox()
 {
     if (!balsa_app.inbox)
@@ -336,8 +333,6 @@ initial_open_inbox()
     balsa_mblist_open_mailbox_hidden(balsa_app.inbox);
     gdk_threads_leave();
 
-    balsa_app.inbox_has_extra_open_ref = TRUE;
-
     return FALSE;
 }
 
@@ -363,18 +358,16 @@ balsa_get_stats(long *unread, long *unsent)
 static void
 balsa_check_open_mailboxes(void)
 {
-    if (cmd_line_open_mailboxes) {
-        gchar *join;
-        gchar **urls;
+    gchar *join;
+    gchar **urls;
 
-        join = g_strjoinv(";", cmd_line_open_mailboxes);
-        g_strfreev(cmd_line_open_mailboxes);
-        cmd_line_open_mailboxes = NULL;
+    join = g_strjoinv(";", cmd_line_open_mailboxes);
+    g_strfreev(cmd_line_open_mailboxes);
+    cmd_line_open_mailboxes = NULL;
 
-        urls = g_strsplit(join, ";", 20);
-        g_free(join);
-        g_idle_add((GSourceFunc) open_mailboxes_idle_cb, urls);
-    }
+    urls = g_strsplit(join, ";", 20);
+    g_free(join);
+    g_idle_add((GSourceFunc) open_mailboxes_idle_cb, urls);
 }
 
 /* scan_mailboxes:
@@ -386,6 +379,7 @@ scan_mailboxes_idle_cb()
     gboolean valid;
     GtkTreeModel *model;
     GtkTreeIter iter;
+    GPtrArray *url_array;
 
     gdk_threads_enter();
     model = GTK_TREE_MODEL(balsa_app.mblist_tree_store);
@@ -403,16 +397,50 @@ scan_mailboxes_idle_cb()
     balsa_mailbox_node_append_subtree(balsa_app.root_node);
     gdk_threads_leave();
 
-    if (cmd_open_unread_mailbox || balsa_app.open_unread_mailbox)
-       g_idle_add((GSourceFunc) initial_open_unread_mailboxes, NULL);
+    url_array = g_ptr_array_new();
+    if (cmd_open_unread_mailbox || balsa_app.open_unread_mailbox){
+        GList *l, *gl;
 
-    balsa_check_open_mailboxes();
+        gl = balsa_mblist_find_all_unread_mboxes(NULL);
+        for (l = gl; l; l = l->next) {
+            LibBalsaMailbox *mailbox = l->data;
+            g_ptr_array_add(url_array, g_strdup(mailbox->url));
+        }
+        g_list_free(gl);
+    }
 
-    if (balsa_app.remember_open_mboxes)
-       g_idle_add((GSourceFunc) open_mailboxes_idle_cb, NULL);
+    if (cmd_line_open_mailboxes) {
+        gchar *join;
+        gchar **urls;
+        gchar **p;
+
+        join = g_strjoinv(";", cmd_line_open_mailboxes);
+        g_strfreev(cmd_line_open_mailboxes);
+        cmd_line_open_mailboxes = NULL;
+
+        urls = g_strsplit(join, ";", 20);
+        g_free(join);
+
+        for (p = urls; *p; p++)
+            g_ptr_array_add(url_array, *p);
+        g_free(urls); /* not g_strfreev */
+    }
+
+    if (balsa_app.remember_open_mboxes) {
+        if (balsa_app.current_mailbox_url)
+            g_ptr_array_add(url_array, balsa_app.current_mailbox_url);
+        balsa_add_open_mailbox_urls(url_array);
+    }
+
+    if (cmd_open_inbox || balsa_app.open_inbox_upon_startup) {
+        g_ptr_array_add(url_array, g_strdup(balsa_app.inbox->url));
+    }
 
-    if (cmd_open_inbox || balsa_app.open_inbox_upon_startup)
-       g_idle_add((GSourceFunc) initial_open_inbox, NULL);
+    if (url_array->len) {
+        g_ptr_array_add(url_array, NULL);
+        open_mailboxes_idle_cb((gchar **) g_ptr_array_free(url_array,
+                                                           FALSE));
+    }
 
     if(cmd_get_stats) {
         long unread, unsent;
@@ -720,9 +748,6 @@ balsa_cleanup(void)
     }
     pthread_mutex_unlock(&checking_mail_lock);
 #endif
-    if (balsa_app.inbox_has_extra_open_ref)
-        libbalsa_mailbox_close(balsa_app.inbox,
-                               balsa_app.expunge_on_close);
     balsa_app_destroy();
     g_hash_table_destroy(libbalsa_mailbox_view_table);
     libbalsa_mailbox_view_table = NULL;
@@ -801,7 +826,8 @@ handle_remote(int argc, char **argv,
         if (cmd_open_inbox)
             initial_open_inbox();
 
-        balsa_check_open_mailboxes();
+        if (cmd_line_open_mailboxes)
+            balsa_check_open_mailboxes();
 
         if (!balsa_check_open_compose_window()) {
             /* Move the main window to the request's screen */


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