[balsa/gtk3] Survive NetworkManager connections coming back.



commit 5a27ed220c78d55fbbb5f8bc30a1eab3adf71f5c
Author: Pawel Salek <pawsa0 gmail com>
Date:   Sun Apr 22 17:30:27 2012 +0200

    Survive NetworkManager connections coming back.
    
    * src/balsa-app.{c,h}: free mem on exit. Longer 'short' mailbox names.
    * src/balsa-mblist.c: use them.
    * src/mailbox-node.h: remove unused bit field.
    * src/main-window.c: check_mailboxes must be called from main thread.

 ChangeLog          |    7 +++++++
 src/balsa-app.c    |   26 +++++++++++++++++++++++++-
 src/balsa-app.h    |    5 +++++
 src/balsa-mblist.c |   17 ++++++++---------
 src/mailbox-node.h |    4 ----
 src/main-window.c  |   12 ++++++++++--
 6 files changed, 55 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ef76b27..2d627e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-22  Pawel Salek
+
+	* src/balsa-app.{c,h}: free mem on exit. Longer 'short' mailbox names.
+	* src/balsa-mblist.c: use them.
+	* src/mailbox-node.h: remove unused bit field.
+	* src/main-window.c: check_mailboxes must be called from main thread.
+
 2012-04-20  Peter Bloomfield
 
 	* src/main-window.c: hide current message immediately, instead
diff --git a/src/balsa-app.c b/src/balsa-app.c
index bab3bb0..06a5005 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -441,12 +441,20 @@ balsa_app_destroy(void)
     g_slist_free(balsa_app.filters);
     balsa_app.filters = NULL;
 
-
     g_list_foreach(balsa_app.identities, (GFunc)g_object_unref, NULL);
     g_list_free(balsa_app.identities);
     balsa_app.identities = NULL;
 
 
+    g_list_foreach(balsa_app.folder_mru, (GFunc)g_free, NULL);
+    g_list_free(balsa_app.folder_mru);
+    balsa_app.folder_mru = NULL;
+
+    g_list_foreach(balsa_app.fcc_mru, (GFunc)g_free, NULL);
+    g_list_free(balsa_app.fcc_mru);
+    balsa_app.fcc_mru = NULL;
+
+
     if(balsa_app.debug) g_print("balsa_app: Finished cleaning up.\n");
 }
 
@@ -751,6 +759,22 @@ balsa_find_sentbox_by_url(const gchar *url)
     return res ? res : balsa_app.sentbox;
 }
 
+gchar*
+balsa_get_short_mailbox_name(const gchar *url)
+{
+    BalsaMailboxNode *mbnode;
+
+    if ((mbnode = balsa_find_url(url)) && mbnode->mailbox) {
+        if (mbnode->server) {
+            return g_strconcat(mbnode->server->host, ":",
+                               mbnode->mailbox->name, NULL);
+        } else {
+            return g_strdup(mbnode->mailbox->name);
+        }
+    }
+    return g_strdup(url);
+}
+
 struct balsa_find_iter_by_data_info {
     GtkTreeIter *iter;
     gpointer data;
diff --git a/src/balsa-app.h b/src/balsa-app.h
index 8a2af60..5ae7910 100644
--- a/src/balsa-app.h
+++ b/src/balsa-app.h
@@ -406,6 +406,11 @@ 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);
+
+/** Returns a short mailbox name that identifies the host. This is
+    longer than LibBalsaMailbox::name which contains only filename
+    without information about mailbox's location in the hierarchy. */
+gchar *balsa_get_short_mailbox_name(const gchar * url);
 gboolean balsa_find_iter_by_data(GtkTreeIter * iter, gpointer data);
 BalsaIndex* balsa_find_index_by_mailbox(LibBalsaMailbox* mailbox);
 
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index bf5d19f..871c985 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -2051,15 +2051,14 @@ bmbl_mru_combo_box_setup(GtkComboBox * combo_box)
 
     for (list = *mro->url_list; list; list = list->next) {
         const gchar *url = list->data;
-        LibBalsaMailbox *mailbox;
-
-        if ((mailbox = balsa_find_mailbox_by_url(url)) || !*url) {
-	    gtk_list_store_append(store, &iter);
-	    gtk_list_store_set(store, &iter,
-                               0, mailbox ? mailbox->name : "",
-                               1, FALSE, -1);
-            mro->real_urls = g_slist_append(mro->real_urls, g_strdup(url));
-        }
+        
+        gchar * short_name = balsa_get_short_mailbox_name(url);
+        gtk_list_store_append(store, &iter);
+        gtk_list_store_set(store, &iter,
+                           0, short_name,
+                           1, FALSE, -1);
+        g_free(short_name);
+        mro->real_urls = g_slist_append(mro->real_urls, g_strdup(url));
     }
 
     /* Separator: */
diff --git a/src/mailbox-node.h b/src/mailbox-node.h
index 628fcee..6fe8e4e 100644
--- a/src/mailbox-node.h
+++ b/src/mailbox-node.h
@@ -74,10 +74,6 @@ struct _BalsaMailboxNode {
     char delim; /* IMAP delimiter so that we do not need to check it
 		 * too often. */
 
-
-    unsigned remote:1;/* is dirname or server field used in data union.
-		       * If there is a need for more types, make a subclass. */
-
     unsigned subscribed:1;     /* Used only by remote */
     unsigned list_inbox:1;     /* Used only by remote */
     unsigned scanned:1;        /* IMAP flag */
diff --git a/src/main-window.c b/src/main-window.c
index 487a5ca..44cdcf1 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3596,6 +3596,13 @@ mw_mbox_change_connection_status(GtkTreeModel * model, GtkTreePath * path,
 }
 
 #if BALSA_USE_THREADS
+static gboolean
+check_new_messages_idle(gpointer user_data)
+{
+    check_new_messages_cb(NULL, balsa_app.main_window);
+    return FALSE;
+}
+
 static void*
 bw_change_connection_status_thread(void *arg)
 {
@@ -3614,8 +3621,9 @@ bw_change_connection_status_thread(void *arg)
     if (is_connected &&
         difftime(time(NULL), balsa_app.main_window->last_check_time) >
         balsa_app.check_mail_timer * 60) {
-        /* Check the mail now, and reset the timer */
-        check_new_messages_cb(NULL, balsa_app.main_window);
+        /* Check the mail now, and reset the timer, remembering it
+           must be called from a main thread. */
+        g_idle_add(check_new_messages_idle, NULL);
     }
 #endif                          /* defined(HAVE_LIBNM_GLIB) */
 



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