[balsa/gtk3] Handle multiple identities with the same address



commit 126663394b5a1d8064f4e75f3ac6eee74fcbb4d8
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Jun 5 19:41:29 2011 -0400

    Handle multiple identities with the same address
    
    	* src/save-restore.c (config_identities_load): load identities
    	in the order in which they were saved.
    	* src/sendmsg-window.c (balsa_sendmsg_destroy_handler),
    	(sw_combo_box_changed), (create_from_entry): move selected
    	identity to the front of
    	balsa_app.identities; see
    	<URL:http://mail.gnome.org/archives/balsa-list/2011-May/msg00025.html>
    	(Carlos Franke).

 ChangeLog            |   11 +++++++++++
 src/save-restore.c   |    1 +
 src/sendmsg-window.c |   45 ++++++++++++++++++++++++++++++++++++---------
 3 files changed, 48 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9d86ce0..b62c3ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-05  Peter Bloomfield
+
+	* src/save-restore.c (config_identities_load): load identities
+	in the order in which they were saved.
+	* src/sendmsg-window.c (balsa_sendmsg_destroy_handler),
+	(sw_combo_box_changed), (create_from_entry): move selected
+	identity to the front of
+	balsa_app.identities; see
+	<URL:http://mail.gnome.org/archives/balsa-list/2011-May/msg00025.html>
+	(Carlos Franke).
+
 2011-06-01  Peter Bloomfield
 
 	Respond to
diff --git a/src/save-restore.c b/src/save-restore.c
index 919ac3f..fa00dc3 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -1693,6 +1693,7 @@ config_identities_load()
     libbalsa_conf_foreach_group(IDENTITY_SECTION_PREFIX,
                                 config_identity_load,
                                 default_ident);
+    balsa_app.identities = g_list_reverse(balsa_app.identities);
 
     if (!balsa_app.identities) {
 	libbalsa_conf_push_group("identity-default");
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 88f48bb..3edaf32 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1044,6 +1044,12 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
     g_object_unref(bsmsg->buffer2);
 #endif                          /* HAVE_GTKSOURCEVIEW */
 
+    /* Move the current identity to the start of the list */
+    balsa_app.identities = g_list_remove(balsa_app.identities,
+                                         bsmsg->ident);
+    balsa_app.identities = g_list_prepend(balsa_app.identities,
+                                          bsmsg->ident);
+
     g_free(bsmsg);
 
     if (quit_on_close) {
@@ -2721,11 +2727,16 @@ create_email_entry(GtkWidget * table, int y_pos, BalsaSendmsg * bsmsg,
 static void
 sw_combo_box_changed(GtkComboBox * combo_box, BalsaSendmsg * bsmsg)
 {
-    gint active = gtk_combo_box_get_active(combo_box);
-    LibBalsaIdentity *ident =
-        g_list_nth_data(balsa_app.identities, active);
+    GtkTreeIter iter;
+
+    if (gtk_combo_box_get_active_iter(combo_box, &iter)) {
+        LibBalsaIdentity *ident;
 
-    update_bsmsg_identity(bsmsg, ident);
+        gtk_tree_model_get(gtk_combo_box_get_model(combo_box), &iter,
+                           2, &ident, -1);
+        update_bsmsg_identity(bsmsg, ident);
+        g_object_unref(ident);
+    }
 }
 
 static void
@@ -2735,15 +2746,31 @@ create_from_entry(GtkWidget * table, BalsaSendmsg * bsmsg)
     GtkListStore *store;
     GtkCellRenderer *renderer;
 
-    store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+    /* For each identity, store the address, the identity name, and a
+     * ref to the identity in a combo-box.
+     * Note: we can't depend on balsa_app.identities staying in the same
+     * order while the compose window is open, so we need a ref to the
+     * actual identity. */
+    store = gtk_list_store_new(3,
+                               G_TYPE_STRING,
+                               G_TYPE_STRING,
+                               G_TYPE_OBJECT);
     for (list = balsa_app.identities; list; list = list->next) {
-        LibBalsaIdentity *ident = list->data;
-        gchar *from = internet_address_to_string(ident->ia, FALSE);
-	gchar *name = g_strconcat("(", ident->identity_name, ")", NULL);
+        LibBalsaIdentity *ident;
+        gchar *from, *name;
         GtkTreeIter iter;
 
+        ident = list->data;
+        from = internet_address_to_string(ident->ia, FALSE);
+	name = g_strconcat("(", ident->identity_name, ")", NULL);
+
         gtk_list_store_append(store, &iter);
-        gtk_list_store_set(store, &iter, 0, from, 1, name, -1);
+        gtk_list_store_set(store, &iter,
+                           0, from,
+                           1, name,
+                           2, ident,
+                           -1);
+
         g_free(from);
         g_free(name);
     }



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