? default_key_control.diff
Index: libseahorse/seahorse-default-key-control.c
===================================================================
RCS file: /cvs/gnome/seahorse/libseahorse/seahorse-default-key-control.c,v
retrieving revision 1.18
diff -u -d -b -w -r1.18 seahorse-default-key-control.c
--- libseahorse/seahorse-default-key-control.c	16 May 2006 16:40:40 -0000	1.18
+++ libseahorse/seahorse-default-key-control.c	17 May 2006 01:52:07 -0000
@@ -30,11 +30,95 @@
  */
 
 static void
+change_prev_label_cb (GtkMenuItem *item, gchar *userid)
+{
+    GtkLabel        *label;
+    GList           *children = NULL, *iter;
+    const gchar    *label_text;
+    gchar           *new_text;
+    SeahorseKey     *skey; 
+    
+    children = gtk_container_get_children (GTK_CONTAINER(item));
+    iter = children;
+    
+    while (iter && GTK_IS_LABEL(iter->data) == 0)
+        iter = iter->next;
+    
+    if (iter == NULL)
+        return;
+            
+    label = GTK_LABEL (iter->data);
+    
+    label_text = gtk_label_get_text (label);
+    
+    if (g_ascii_strcasecmp (userid, label_text) == 0) {
+        skey = g_object_get_data (G_OBJECT (item), "key");
+        
+        new_text = g_strdup_printf ("%s %s", userid, seahorse_key_get_short_keyid(skey));
+        gtk_label_set_text (label, new_text);
+        
+        g_free (new_text);
+    }
+    
+    g_list_free (children);
+}
+
+static void
+change_last_label_cb (GtkMenuItem *item, GtkMenuItem *last_item)
+{
+    GList *children, *iter;
+    GtkLabel *label, *last_label;
+    const gchar *last_text, *label_text;
+    gchar *new_text;
+    SeahorseKey *skey;
+    
+    /* Get the label in the current item */
+    children = gtk_container_get_children (GTK_CONTAINER(item));
+    iter = children;
+    
+    while (iter && GTK_IS_LABEL(iter->data) == 0)
+        iter = iter->next;
+    
+    if (iter == NULL)
+        return;
+            
+    label = GTK_LABEL (iter->data);
+    label_text = gtk_label_get_text(label);
+    
+    g_list_free(children);
+    
+    children = gtk_container_get_children (GTK_CONTAINER(last_item));
+    iter = children;
+    
+    /* Get the label from the last item */
+    while (iter && GTK_IS_LABEL(iter->data) == 0)
+        iter = iter->next;
+    
+    if (iter == NULL)
+        return;
+            
+    last_label = GTK_LABEL (iter->data);
+    last_text = gtk_label_get_text(last_label);
+    
+    if (g_ascii_strncasecmp (last_text, label_text, strlen(last_text)) == 0) {
+        skey = g_object_get_data (G_OBJECT (last_item), "key");
+        
+        new_text = g_strdup_printf ("%s %s", last_text, seahorse_key_get_short_keyid(skey));
+        gtk_label_set_text (last_label, new_text);
+        
+        g_free (new_text);
+    }
+    
+    g_list_free (children);
+}
+
+static void
 key_added (SeahorseKeyset *skset, SeahorseKey *skey, GtkOptionMenu *combo)
 {
     GtkWidget *menu;
     GtkWidget *item;
     gchar *userid;
+    GList *menu_items = NULL, *last;
     
     g_return_if_fail (skey != NULL);
     g_return_if_fail (combo != NULL);
@@ -42,13 +126,28 @@
     menu = gtk_option_menu_get_menu (combo);
     
     userid = seahorse_key_get_display_name (skey);
+        
     item = gtk_menu_item_new_with_label (userid);
-    g_free (userid);
+    
 
     g_object_set_data (G_OBJECT (item), "key", skey);
 
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
     gtk_widget_show (item);
+    
+    /* Change Display name if necessary */
+    menu_items = gtk_container_get_children(GTK_CONTAINER(menu));
+    
+    if (g_list_length (menu_items) > 1) {
+        last = g_list_last (menu_items);
+        menu_items = g_list_delete_link (menu_items, last);
+        g_list_foreach (menu_items, (GFunc) change_prev_label_cb, userid);
+
+        g_list_foreach (menu_items, (GFunc) change_last_label_cb, item);        
+    }
+    
+    g_free (userid);
+    g_list_free(menu_items);
     
     seahorse_keyset_set_closure (skset, skey, item);
 }
