[balsa] Open most recent mailbox first on restart



commit ef372e937c822225e28f2c7d8357ea867c280336
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Sep 11 19:57:34 2009 -0400

    Open most recent mailbox first on restart

 ChangeLog                      |   18 +++++++
 libbalsa/libbalsa-marshal.list |    1 +
 src/balsa-app.c                |    9 ++--
 src/balsa-app.h                |    1 +
 src/balsa-index.c              |    2 -
 src/balsa-mblist.c             |   32 +++++++++----
 src/balsa-mblist.h             |    1 +
 src/mailbox-node.c             |    2 +-
 src/main-window.c              |  102 ++++++++++++++++++++++++---------------
 src/main-window.h              |    8 ++-
 src/save-restore.c             |    5 ++
 11 files changed, 123 insertions(+), 58 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0208e5c..3ab129a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2009-09-11  Peter Bloomfield
 
+	Open most recent mailbox first on restart
+
+	* libbalsa/libbalsa-marshal.list: new marshaller.
+	* src/balsa-app.h: new member current_mailbox_url.
+	* src/save-restore.c (config_global_load), (config_save): save
+	and restore it.
+	* src/main-window.h: new api for open-mbnode class method.
+	* src/balsa-mblist.h: new method balsa_mblist_open_mailbox_hidden;
+	* src/balsa-app.c (open_mailboxes_idle_cb): use them.
+	* src/balsa-index.c (balsa_index_transfer): ditto.
+	* src/balsa-mblist.c (bmbl_open_mailbox),
+	(balsa_mblist_open_mailbox), (balsa_mblist_open_mailbox_hidden):
+	ditto.
+	* src/mailbox-node.c (load_mailbox_view): ditto.
+	* src/main-window.c: ditto.
+
+2009-09-11  Peter Bloomfield
+
 	* src/mailbox-conf.c (mailbox_conf_set_values):
 	initialize mailbox name for local mailbox;
 	(local_mailbox_dialog_cb), (create_local_mailbox_dialog):
diff --git a/libbalsa/libbalsa-marshal.list b/libbalsa/libbalsa-marshal.list
index 14f0bb8..b670324 100644
--- a/libbalsa/libbalsa-marshal.list
+++ b/libbalsa/libbalsa-marshal.list
@@ -13,4 +13,5 @@ POINTER:POINTER,POINTER
 POINTER:VOID
 VOID:INT,INT,INT
 VOID:INT,INT,INT,STRING
+VOID:OBJECT,BOOLEAN
 VOID:POINTER,INT
diff --git a/src/balsa-app.c b/src/balsa-app.c
index e849f00..1330d44 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -534,7 +534,7 @@ open_mailboxes_idle_cb(gchar ** urls)
             return FALSE;
         }
 
-        str = g_string_new(NULL);
+        str = g_string_new(balsa_app.current_mailbox_url);
         g_hash_table_foreach(libbalsa_mailbox_view_table,
                              (GHFunc) append_url_if_open, str);
         urls = g_strsplit(str->str, ";", 0);
@@ -547,7 +547,9 @@ open_mailboxes_idle_cb(gchar ** urls)
 	    fprintf(stderr, "open_mailboxes_idle_cb: opening %s => %p..\n",
 		    *tmp, mbox);
 	if (mbox)
-	    balsa_mblist_open_mailbox(mbox);
+            /* The first mailbox we open will be shown; the others will
+             * have notebook pages, but will not be shown. */
+	    balsa_mblist_open_mailbox_hidden(mbox);
         else {
 	    /* Do not try to open it next time. */
 	    LibBalsaMailboxView *view =
@@ -566,9 +568,6 @@ open_mailboxes_idle_cb(gchar ** urls)
     }
     g_strfreev(urls);
 
-    if (gtk_notebook_get_current_page(GTK_NOTEBOOK(balsa_app.notebook)) >=
-        0)
-        gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook), 0);
     gdk_threads_leave();
 
     return FALSE;
diff --git a/src/balsa-app.h b/src/balsa-app.h
index 3ec852c..2eaf8a9 100644
--- a/src/balsa-app.h
+++ b/src/balsa-app.h
@@ -335,6 +335,7 @@ extern struct BalsaApplication {
 
     /* list of currently open mailboxes */
     GList *open_mailbox_list;  /* data is a pointer to the mailbox */
+    gchar *current_mailbox_url;/* remember for next session */
     
     /* font used to display messages */
     gchar *message_font;
diff --git a/src/balsa-index.c b/src/balsa-index.c
index b302df6..117f182 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2169,8 +2169,6 @@ balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
 	return;
     }
 
-    balsa_window_set_statusbar(balsa_app.main_window, from_mailbox);
-
     if (from_mailbox == balsa_app.trash && !copy)
         enable_empty_trash(balsa_app.main_window, TRASH_CHECK);
     else if (to_mailbox == balsa_app.trash)
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index 6f05269..d4dc115 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -1119,8 +1119,8 @@ balsa_mblist_find_all_unread_mboxes(LibBalsaMailbox * mailbox)
  * mailbox page, or if a new page needs to be created and the mailbox
  * parsed.
  */
-void
-balsa_mblist_open_mailbox(LibBalsaMailbox * mailbox)
+static void
+bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
 {
     int i;
     GtkWidget *index;
@@ -1141,20 +1141,34 @@ balsa_mblist_open_mailbox(LibBalsaMailbox * mailbox)
     
     i = balsa_find_notebook_page_num(mailbox);
     if (i != -1) {
-	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));
+        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));
+        }
     } else { /* page with mailbox not found, open it */
-	balsa_window_open_mbnode(balsa_app.main_window, mbnode);
+        balsa_window_open_mbnode(balsa_app.main_window, mbnode,
+                                 set_current);
 
 	if (balsa_app.mblist->display_info)
 	    balsa_mblist_update_mailbox(balsa_app.mblist_tree_store,
                                         mailbox);
     }
     g_object_unref(mbnode);
-    
-    balsa_window_set_statusbar(balsa_app.main_window, mailbox);
+}
+
+void
+balsa_mblist_open_mailbox(LibBalsaMailbox * mailbox)
+{
+    bmbl_open_mailbox(mailbox, TRUE);
+}
+
+void
+balsa_mblist_open_mailbox_hidden(LibBalsaMailbox * mailbox)
+{
+    bmbl_open_mailbox(mailbox, FALSE);
 }
 
 void
diff --git a/src/balsa-mblist.h b/src/balsa-mblist.h
index 499dbb0..4b9afa4 100644
--- a/src/balsa-mblist.h
+++ b/src/balsa-mblist.h
@@ -67,6 +67,7 @@ gboolean balsa_mblist_focus_mailbox(BalsaMBList * mblist,
 
 GList *balsa_mblist_find_all_unread_mboxes(LibBalsaMailbox * mailbox);
 void balsa_mblist_open_mailbox(LibBalsaMailbox * mailbox);
+void balsa_mblist_open_mailbox_hidden(LibBalsaMailbox * mailbox);
 void balsa_mblist_close_mailbox(LibBalsaMailbox * mailbox);
 /* balsa_mblist_close_lru_peer_mbx closes least recently used mailbox
  * on the same server as the one given as the argument */
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index 333fb8a..9178e66 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -400,7 +400,7 @@ load_mailbox_view(BalsaMailboxNode * mbnode)
     if (libbalsa_mailbox_get_frozen(mailbox)
 	&& libbalsa_mailbox_get_open(mailbox))
 	/* We are rescanning. */
-	balsa_window_open_mbnode(balsa_app.main_window, mbnode);
+	balsa_window_open_mbnode(balsa_app.main_window, mbnode, TRUE);
     libbalsa_mailbox_set_frozen(mailbox, FALSE);
 }
 
diff --git a/src/main-window.c b/src/main-window.c
index f5e61be..2e4cd1b 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -76,6 +76,8 @@
 
 #include "libinit_balsa/assistant_init.h"
 
+#include "libbalsa/libbalsa-marshal.h"
+
 #define MAILBOX_DATA "mailbox_data"
 
 enum {
@@ -116,7 +118,8 @@ static void bw_display_new_mail_notification(int num_new, int has_new);
 static void balsa_window_class_init(BalsaWindowClass * klass);
 static void balsa_window_init(BalsaWindow * window);
 static void balsa_window_real_open_mbnode(BalsaWindow *window,
-                                          BalsaMailboxNode *mbnode);
+                                          BalsaMailboxNode *mbnode,
+                                          gboolean set_current);
 static void balsa_window_real_close_mbnode(BalsaWindow *window,
 					   BalsaMailboxNode *mbnode);
 static void balsa_window_destroy(GtkObject * object);
@@ -243,8 +246,8 @@ static void bw_set_threading_menu(BalsaWindow * window, int option);
 static void bw_show_mbtree(BalsaWindow * window);
 #endif /* ENABLE_TOUCH_UI */
 static void bw_set_filter_menu(BalsaWindow * window, int gui_filter);
-static LibBalsaCondition *bw_get_view_filter(BalsaWindow * window,
-                                             gboolean flags_only);
+static LibBalsaCondition *bw_get_flag_filter(BalsaWindow * window);
+static LibBalsaCondition *bw_get_view_filter(BalsaWindow * window);
 #if defined(ENABLE_TOUCH_UI)
 static gboolean bw_open_mailbox_cb(GtkWidget *w, GdkEventKey *e, gpointer data);
 static void bw_enable_view_filter_cb(GtkToggleAction * action, gpointer data);
@@ -936,8 +939,8 @@ balsa_window_class_init(BalsaWindowClass * klass)
                      G_SIGNAL_RUN_LAST,
                      G_STRUCT_OFFSET(BalsaWindowClass, open_mbnode),
                      NULL, NULL,
-                     g_cclosure_marshal_VOID__OBJECT,
-                     G_TYPE_NONE, 1, G_TYPE_OBJECT);
+                     libbalsa_VOID__OBJECT_BOOLEAN,
+                     G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_BOOLEAN);
 
     window_signals[CLOSE_MAILBOX_NODE] =
         g_signal_new("close_mailbox_node",
@@ -1051,7 +1054,7 @@ bw_set_view_filter(BalsaWindow * bw, gint filter_no, GtkWidget * entry)
     if (!index)
         return;
 
-    view_filter = bw_get_view_filter(bw, FALSE);
+    view_filter = bw_get_view_filter(bw);
     balsa_index_set_view_filter(BALSA_INDEX(index), filter_no,
                                 gtk_entry_get_text(GTK_ENTRY(entry)),
                                 view_filter);
@@ -2154,13 +2157,14 @@ bw_set_filter_menu(BalsaWindow * window, int mask)
    mailbox is already on one of them.
 */
 void
-balsa_window_open_mbnode(BalsaWindow * window, BalsaMailboxNode * mbnode)
+balsa_window_open_mbnode(BalsaWindow * window, BalsaMailboxNode * mbnode,
+                         gboolean set_current)
 {
     g_return_if_fail(window != NULL);
     g_return_if_fail(BALSA_IS_WINDOW(window));
 
     g_signal_emit(G_OBJECT(window), window_signals[OPEN_MAILBOX_NODE],
-                  0, mbnode);
+                  0, mbnode, set_current);
 }
 
 void
@@ -2243,6 +2247,7 @@ bw_notebook_label_new(BalsaMailboxNode * mbnode)
 struct bw_open_mbnode_info {
     BalsaMailboxNode * mbnode;
     BalsaWindow *window;
+    gboolean set_current;
 };
 
 static void
@@ -2255,7 +2260,6 @@ bw_real_open_mbnode(struct bw_open_mbnode_info * info)
     gboolean failurep;
     GError *err = NULL;
     gchar *message;
-    LibBalsaCondition *view_filter;
     LibBalsaMailbox *mailbox;
 
 #ifdef BALSA_USE_THREADS
@@ -2328,26 +2332,16 @@ bw_real_open_mbnode(struct bw_open_mbnode_info * info)
                                    GTK_POLICY_AUTOMATIC);
     gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(index));
     gtk_widget_show(scroll);
-    gtk_notebook_append_page(GTK_NOTEBOOK(info->window->notebook),
-                             scroll, label);
+    page_num =
+        gtk_notebook_append_page(GTK_NOTEBOOK(info->window->notebook),
+                                 scroll, label);
     gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(info->window->notebook),
                                      scroll, TRUE);
 
-    /* change the page to the newly selected notebook item */
-    page_num = gtk_notebook_page_num(GTK_NOTEBOOK
-                                     (info->window->notebook),
-                                     scroll);
-    gtk_notebook_set_current_page(GTK_NOTEBOOK
-                                  (info->window->notebook),
-                                  page_num);
-
-    /* bw_switch_page_cb has now set the hide-states for this mailbox, so
-     * we can set up the view-filter: */
-    view_filter = bw_get_view_filter(info->window, TRUE);
-    libbalsa_mailbox_set_view_filter(mailbox, view_filter,
-                                     FALSE);
-    libbalsa_condition_unref(view_filter);
-    libbalsa_mailbox_make_view_filter_persistent(mailbox);
+    if (info->set_current)
+        /* change the page to the newly selected notebook item */
+        gtk_notebook_set_current_page(GTK_NOTEBOOK(info->window->notebook),
+                                      page_num);
 
     bw_register_open_mailbox(mailbox);
     /* scroll may select the message and GtkTreeView does not like selecting
@@ -2365,7 +2359,9 @@ bw_real_open_mbnode(struct bw_open_mbnode_info * info)
 }
 
 static void
-balsa_window_real_open_mbnode(BalsaWindow * window, BalsaMailboxNode * mbnode)
+balsa_window_real_open_mbnode(BalsaWindow * window,
+                              BalsaMailboxNode * mbnode,
+                              gboolean set_current)
 {
     struct bw_open_mbnode_info *info;
 #ifdef BALSA_USE_THREADS
@@ -2374,6 +2370,7 @@ balsa_window_real_open_mbnode(BalsaWindow * window, BalsaMailboxNode * mbnode)
 #endif
     info = g_new(struct bw_open_mbnode_info, 1);
     info->window = window;
+    info->set_current = set_current;
     g_object_add_weak_pointer(G_OBJECT(window), (gpointer) &info->window);
     info->mbnode = mbnode;
     g_object_ref(mbnode);
@@ -2452,6 +2449,9 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
 
             /* Just in case... */
             g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, NULL);
+
+            g_free(balsa_app.current_mailbox_url);
+            balsa_app.current_mailbox_url = NULL;
         }
     }
 
@@ -4225,7 +4225,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
             LibBalsaMailbox *mailbox = 
                 BALSA_INDEX(bindex)->mailbox_node->mailbox;
             LibBalsaCondition *filter, *res;
-            filter = bw_get_view_filter(window, FALSE);
+            filter = bw_get_view_filter(window);
             res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
                                                   filter, cnd);
             libbalsa_condition_unref(filter);
@@ -4354,7 +4354,7 @@ bw_mailbox_tab_close_cb(GtkWidget * widget, gpointer data)
 
 
 static LibBalsaCondition*
-bw_get_view_filter(BalsaWindow *window, gboolean flags_only)
+bw_get_flag_filter(BalsaWindow *window)
 {
     static struct {
         LibBalsaMessageFlag flag;
@@ -4367,7 +4367,7 @@ bw_get_view_filter(BalsaWindow *window, gboolean flags_only)
         { LIBBALSA_MESSAGE_FLAG_REPLIED, -1, 0 }
     };
     unsigned i, j;
-    LibBalsaCondition *filter, *flag_filter;
+    LibBalsaCondition *filter;
     
     for(i=0; i<ELEMENTS(match_flags); i++)
         match_flags[i].setby = -1;
@@ -4393,25 +4393,36 @@ bw_get_view_filter(BalsaWindow *window, gboolean flags_only)
     /* match_flags contains collected information, time to create a
      * LibBalsaCondition data structure.
      */
-    flag_filter = NULL;
+    filter = NULL;
     for(j=0; j<ELEMENTS(match_flags); j++) {
         LibBalsaCondition *lbc, *res;
         if(match_flags[j].setby < 0) continue;
         lbc = libbalsa_condition_new_flag_enum(match_flags[j].state,
                                                match_flags[j].flag);
         res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
-                                              lbc, flag_filter);
+                                              lbc, filter);
         libbalsa_condition_unref(lbc);
-        libbalsa_condition_unref(flag_filter);
-        flag_filter = res;
+        libbalsa_condition_unref(filter);
+        filter = res;
     }
 
+    return filter;
+}
+
+static LibBalsaCondition*
+bw_get_view_filter(BalsaWindow *window)
+{
+    LibBalsaCondition *filter, *flag_filter;
+    gint i;
+
+    flag_filter = bw_get_flag_filter(window);
+
     /* add string filter on top of that */
 
-    i = flags_only
-        ? -1 : gtk_combo_box_get_active(GTK_COMBO_BOX(window->filter_choice));
-    if(i>=0 && i<(signed)ELEMENTS(view_filters)) {
+    i = gtk_combo_box_get_active(GTK_COMBO_BOX(window->filter_choice));
+    if (i >= 0) {
         const gchar *str = gtk_entry_get_text(GTK_ENTRY(window->sos_entry));
+        g_assert(((guint) i) < G_N_ELEMENTS(view_filters));
         filter = view_filters[i].filter(str);
     } else filter = NULL;
     /* and merge ... */
@@ -4489,12 +4500,12 @@ bw_hide_changed_cb(GtkToggleAction * toggle_action, gpointer data)
     libbalsa_mailbox_set_filter(mailbox, bw_filter_to_int(bw));
 
     /* Set the flags part of this filter as persistent: */
-    filter = bw_get_view_filter(bw, TRUE);
+    filter = bw_get_flag_filter(bw);
     libbalsa_mailbox_set_view_filter(mailbox, filter, FALSE);
     libbalsa_condition_unref(filter);
     libbalsa_mailbox_make_view_filter_persistent(mailbox);
 
-    filter = bw_get_view_filter(bw, FALSE);
+    filter = bw_get_view_filter(bw);
     /* libbalsa_mailbox_set_view_filter() will ref the
      * filter.  We need also to rethread to take into account that
      * some messages might have been removed or added to the view. */
@@ -4694,10 +4705,20 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
     bw_enable_message_menus(window, index->current_msgno);
     bw_enable_mailbox_menus(window, index);
 
+    if (!mailbox->view_filter) {
+        /* bw_enable_mailbox_menus has now set the hide-states for this
+         * mailbox, so we can set up the view-filter: */
+        LibBalsaCondition *view_filter = bw_get_flag_filter(window);
+        libbalsa_mailbox_set_view_filter(mailbox, view_filter, FALSE);
+        libbalsa_condition_unref(view_filter);
+        libbalsa_mailbox_make_view_filter_persistent(mailbox);
+    }
+
     gtk_entry_set_text(GTK_ENTRY(window->sos_entry),
                        index->filter_string ? index->filter_string : "");
     gtk_combo_box_set_active(GTK_COMBO_BOX(window->filter_choice),
                              index->filter_no);
+
     balsa_mblist_focus_mailbox(balsa_app.mblist, mailbox);
     balsa_window_set_statusbar(window, mailbox);
 
@@ -4709,6 +4730,9 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
     bw_enable_edit_menus(window, NULL);
     bw_enable_part_menu_items(window);
 #endif /*ENABLE_TOUCH_UI */
+
+    g_free(balsa_app.current_mailbox_url);
+    balsa_app.current_mailbox_url = g_strdup(mailbox->url);
 }
 
 static void
diff --git a/src/main-window.h b/src/main-window.h
index 889cc4d..ae9bea1 100644
--- a/src/main-window.h
+++ b/src/main-window.h
@@ -94,7 +94,9 @@ struct _BalsaWindow {
 struct _BalsaWindowClass {
     GtkWindowClass parent_class;
 
-    void (*open_mbnode)  (BalsaWindow * window, BalsaMailboxNode * mbnode);
+    void (*open_mbnode)  (BalsaWindow * window,
+                          BalsaMailboxNode * mbnode,
+                          gboolean set_current);
     void (*close_mbnode) (BalsaWindow * window, BalsaMailboxNode * mbnode);
     void (*identities_changed) (BalsaWindow * window);
 };
@@ -118,7 +120,9 @@ GtkWidget *balsa_window_new(void);
 GtkWidget *balsa_window_find_current_index(BalsaWindow * window);
 void balsa_window_update_book_menus(BalsaWindow *window);
 void balsa_window_refresh(BalsaWindow * window);
-void balsa_window_open_mbnode(BalsaWindow * window, BalsaMailboxNode*mbnode);
+void balsa_window_open_mbnode(BalsaWindow * window,
+                              BalsaMailboxNode*mbnode,
+                              gboolean set_current);
 void balsa_window_close_mbnode(BalsaWindow * window, BalsaMailboxNode*mbnode);
 void balsa_identities_changed(BalsaWindow *bw);
 
diff --git a/src/save-restore.c b/src/save-restore.c
index dc8f3d2..7a32df9 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -1060,6 +1060,8 @@ config_global_load(void)
     
     balsa_app.remember_open_mboxes =
 	libbalsa_conf_get_bool("RememberOpenMailboxes=false");
+    balsa_app.current_mailbox_url =
+	libbalsa_conf_get_string("CurrentMailboxURL");
 
     balsa_app.empty_trash_on_exit =
 	libbalsa_conf_get_bool("EmptyTrash=false");
@@ -1446,6 +1448,9 @@ config_save(void)
 
     libbalsa_conf_set_bool("RememberOpenMailboxes",
 			  balsa_app.remember_open_mboxes);
+    libbalsa_conf_set_string("CurrentMailboxURL",
+                             balsa_app.current_mailbox_url);
+
     libbalsa_conf_set_bool("EmptyTrash", balsa_app.empty_trash_on_exit);
 
     if (balsa_app.default_address_book)



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