2005-10-16 [wwp] 1.9.15cvs52
[claws.git] / src / addressbook.c
index 4d802e847952c4b52f5e711cd1d2e25abcd42aca..53ddd30077620997aa2ac4d2940546b86ad5f5b0 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "expldifdlg.h"
 #include "browseldap.h"
 
+typedef enum
+{
+       COL_SOURCES     = 0,
+       N_INDEX_COLS    = 1
+} AddressIndexColumns;
+
 typedef enum
 {
        COL_NAME        = 0,
        COL_ADDRESS     = 1,
-       COL_REMARKS     = 2
-} AddressBookColumnPos;
+       COL_REMARKS     = 2,
+       N_LIST_COLS     = 3
+} AddressListColumns;
 
-#define N_COLS 3
 #define COL_NAME_WIDTH         164
 #define COL_ADDRESS_WIDTH      156
 
@@ -171,6 +177,8 @@ static void addressbook_to_clicked          (GtkButton      *button,
                                                 gpointer        data);
 static void addressbook_lup_clicked            (GtkButton      *button,
                                                 gpointer       data);
+static void addressbook_close_clicked          (GtkButton      *button,
+                                                gpointer       data);
 
 static gboolean addressbook_tree_selected      (GtkCTree       *ctree,
                                                 GtkCTreeNode   *node,
@@ -194,7 +202,6 @@ static void addressbook_person_expand_node  (GtkCTree       *ctree,
 static void addressbook_person_collapse_node   (GtkCTree       *ctree,
                                                 GList          *node,
                                                 gpointer       *data );
-static void addressbook_entry_gotfocus         (GtkWidget      *widget);
 
 #if 0
 static void addressbook_entry_changed          (GtkWidget      *widget);
@@ -212,8 +219,6 @@ static gboolean addressbook_tree_button_pressed     (GtkWidget      *ctree,
 static gboolean addressbook_tree_button_released(GtkWidget     *ctree,
                                                 GdkEventButton *event,
                                                 gpointer        data);
-static void addressbook_popup_close            (GtkMenuShell   *menu_shell,
-                                                gpointer        data);
 
 static void addressbook_new_folder_cb          (gpointer        data,
                                                 guint           action,
@@ -296,7 +301,7 @@ static void addressbook_move_nodes_up               (GtkCTree       *ctree,
                                                GtkCTreeNode    *node);
 static GtkCTreeNode *addressbook_find_group_node (GtkCTreeNode *parent,
                                                   ItemGroup    *group);
-static gboolean key_pressed                    (GtkWidget      *widget,
+static gboolean addressbook_entry_key_pressed  (GtkWidget      *widget,
                                                 GdkEventKey    *event,
                                                 gpointer        data);
 static gint addressbook_treenode_compare_func  (GtkCList       *clist,
@@ -316,10 +321,6 @@ static void addressbook_folder_remove_one_person(GtkCTree *clist,
 static void addressbook_folder_remove_node     (GtkCTree *clist, 
                                                 GtkCTreeNode *node);
 
-#ifdef USE_LDAP
-static void addressbook_ldap_show_message      ( LdapServer *server );
-#endif
-
 /* LUT's and IF stuff */
 static void addressbook_free_treenode          ( gpointer data );
 AddressTypeControlItem *addrbookctl_lookup     (gint            ot);
@@ -348,7 +349,6 @@ static void addressbook_export_ldif_cb              ( void );
 static void addressbook_clip_cut_cb            ( void );
 static void addressbook_clip_copy_cb           ( void );
 static void addressbook_clip_paste_cb          ( void );
-static void addressbook_clip_paste_address_cb  ( void );
 static void addressbook_treenode_cut_cb                ( void );
 static void addressbook_treenode_copy_cb       ( void );
 static void addressbook_treenode_paste_cb      ( void );
@@ -358,6 +358,7 @@ static void addressbook_mail_to_cb          ( void );
 #ifdef USE_LDAP
 static void addressbook_browse_entry_cb                ( void );
 #endif
+static void addressbook_edit_clicked(GtkButton *button, gpointer data);
 
 static void addressbook_start_drag(GtkWidget *widget, gint button, 
                                   GdkEvent *event,
@@ -386,6 +387,7 @@ static void addressbook_drag_received_cb(GtkWidget        *widget,
                                        guint             info,
                                        guint             time,
                                        void             *pdata);
+static void addressbook_list_menu_setup( void );
 
 static GtkTargetEntry addressbook_drag_types[] =
 {
@@ -397,44 +399,42 @@ static GtkTargetList *addressbook_target_list = NULL;
 
 static GtkItemFactoryEntry addressbook_entries[] =
 {
-       {N_("/_File"),                  NULL,           NULL, 0, "<Branch>"},
-       {N_("/_File/New _Book"),        "<alt>B",       addressbook_new_book_cb,        0, NULL},
-       {N_("/_File/New _vCard"),       "<alt>D",       addressbook_new_vcard_cb,       0, NULL},
+       {N_("/_Book"),                  NULL,           NULL, 0, "<Branch>"},
+       {N_("/_Book/New _Book"),        "<control>B",   addressbook_new_book_cb,        0, NULL},
+       {N_("/_Book/New _Folder"),      "<control>R",   addressbook_new_folder_cb,      0, NULL},
+       {N_("/_Book/New _vCard"),       "<control><shift>D",    addressbook_new_vcard_cb,       0, NULL},
 #ifdef USE_JPILOT
-       {N_("/_File/New _JPilot"),      "<alt>J",       addressbook_new_jpilot_cb,      0, NULL},
+       {N_("/_Book/New _JPilot"),      "<control>J",   addressbook_new_jpilot_cb,      0, NULL},
 #endif
 #ifdef USE_LDAP
-       {N_("/_File/New _Server"),      "<alt>S",       addressbook_new_ldap_cb,        0, NULL},
+       {N_("/_Book/New _Server"),      "<control><shift>S",    addressbook_new_ldap_cb,        0, NULL},
 #endif
-       {N_("/_File/---"),              NULL,           NULL, 0, "<Separator>"},
-       {N_("/_File/_Edit"),            NULL,           addressbook_treenode_edit_cb,   0, NULL},
-       {N_("/_File/_Delete"),          NULL,           addressbook_treenode_delete_cb, 0, NULL},
-       {N_("/_File/---"),              NULL,           NULL, 0, "<Separator>"},
-       {N_("/_File/_Save"),            "<alt>S",       addressbook_file_save_cb,       0, NULL},
-       {N_("/_File/_Close"),           "<alt>W",       close_cb,                       0, NULL},
-       {N_("/_Edit"),                  NULL,           NULL, 0, "<Branch>"},
-       {N_("/_Edit/C_ut"),             "<ctl>X",       addressbook_clip_cut_cb,        0, NULL},
-       {N_("/_Edit/_Copy"),            "<ctl>C",       addressbook_clip_copy_cb,       0, NULL},
-       {N_("/_Edit/_Paste"),           "<ctl>V",       addressbook_clip_paste_cb,      0, NULL},
-       {N_("/_Edit/---"),              NULL,           NULL, 0, "<Separator>"},
-       {N_("/_Edit/Pa_ste Address"),   NULL,           addressbook_clip_paste_address_cb, 0, NULL},
-       {N_("/_Address"),               NULL,           NULL, 0, "<Branch>"},
-       {N_("/_Address/New _Address"),  "<alt>N",       addressbook_new_address_cb,     0, NULL},
-       {N_("/_Address/New _Group"),    "<alt>G",       addressbook_new_group_cb,       0, NULL},
-       {N_("/_Address/New _Folder"),   "<alt>R",       addressbook_new_folder_cb,      0, NULL},
+       {N_("/_Book/---"),              NULL,           NULL, 0, "<Separator>"},
+       {N_("/_Book/_Edit book"),       NULL,           addressbook_treenode_edit_cb,   0, NULL},
+       {N_("/_Book/_Delete book"),     NULL,           addressbook_treenode_delete_cb, 0, NULL},
+       {N_("/_Book/---"),              NULL,           NULL, 0, "<Separator>"},
+       {N_("/_Book/_Save"),            "<control>S",   addressbook_file_save_cb,       0, NULL},
+       {N_("/_Book/_Close"),           "<control>W",   close_cb,                       0, NULL},
+       {N_("/_Address"),                       NULL,           NULL, 0, "<Branch>"},
+       {N_("/_Address/C_ut"),          "<control>X",   addressbook_clip_cut_cb,        0, NULL},
+       {N_("/_Address/_Copy"),         "<control>C",   addressbook_clip_copy_cb,       0, NULL},
+       {N_("/_Address/_Paste"),        "<control>V",   addressbook_clip_paste_cb,      0, NULL},
+       {N_("/_Address/---"),           NULL,           NULL, 0, "<Separator>"},
+       {N_("/_Address/_Edit"),         "<control>Return",addressbook_edit_address_cb,    0, NULL},
+       {N_("/_Address/_Delete"),       "<control>D",   addressbook_delete_address_cb,  0, NULL},
        {N_("/_Address/---"),           NULL,           NULL, 0, "<Separator>"},
-       {N_("/_Address/_Edit"),         "<alt>Return",  addressbook_edit_address_cb,    0, NULL},
-       {N_("/_Address/_Delete"),       NULL,           addressbook_delete_address_cb,  0, NULL},
+       {N_("/_Address/New _Address"),  "<control>N",   addressbook_new_address_cb,     0, NULL},
+       {N_("/_Address/New _Group"),    "<control>G",   addressbook_new_group_cb,       0, NULL},
        {N_("/_Address/---"),           NULL,           NULL, 0, "<Separator>"},
        {N_("/_Address/_Mail To"),      NULL,           addressbook_mail_to_cb,         0, NULL},
-       {N_("/_Tools/---"),             NULL,           NULL, 0, "<Separator>"},
+       {N_("/_Tools"),                 NULL,           NULL, 0, "<Branch>"},
        {N_("/_Tools/Import _LDIF file..."), NULL,      addressbook_import_ldif_cb,     0, NULL},
        {N_("/_Tools/Import M_utt file..."), NULL,      addressbook_import_mutt_cb,     0, NULL},
        {N_("/_Tools/Import _Pine file..."), NULL,      addressbook_import_pine_cb,     0, NULL},
        {N_("/_Tools/---"),             NULL,           NULL, 0, "<Separator>"},
        {N_("/_Tools/Export _HTML..."), NULL,           addressbook_export_html_cb,     0, NULL},
        {N_("/_Tools/Export LDI_F..."), NULL,           addressbook_export_ldif_cb,     0, NULL},
-       {N_("/_Help"),                  NULL,           NULL, 0, "<LastBranch>"},
+       {N_("/_Help"),                  NULL,           NULL, 0, "<Branch>"},
        {N_("/_Help/_About"),           NULL,           about_show, 0, NULL}
 };
 
@@ -443,8 +443,6 @@ static GtkItemFactoryEntry addressbook_tree_popup_entries[] =
        {N_("/_Edit"),          NULL, addressbook_treenode_edit_cb,   0, NULL},
        {N_("/_Delete"),        NULL, addressbook_treenode_delete_cb, 0, NULL},
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
-       {N_("/New _Address"),   NULL, addressbook_new_address_cb,     0, NULL},
-       {N_("/New _Group"),     NULL, addressbook_new_group_cb,       0, NULL},
        {N_("/New _Folder"),    NULL, addressbook_new_folder_cb,      0, NULL},
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
        {N_("/C_ut"),           NULL, addressbook_treenode_cut_cb,    0, NULL},
@@ -459,13 +457,12 @@ static GtkItemFactoryEntry addressbook_list_popup_entries[] =
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
        {N_("/New _Address"),   NULL, addressbook_new_address_cb,    0, NULL},
        {N_("/New _Group"),     NULL, addressbook_new_group_cb,      0, NULL},
-       {N_("/New _Folder"),    NULL, addressbook_new_folder_cb,     0, NULL},
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
        {N_("/C_ut"),           NULL, addressbook_clip_cut_cb,       0, NULL},
        {N_("/_Copy"),          NULL, addressbook_clip_copy_cb,      0, NULL},
        {N_("/_Paste"),         NULL, addressbook_clip_paste_cb,     0, NULL},
        {N_("/---"),            NULL, NULL, 0, "<Separator>"},
-       {N_("/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL},
+/*     {N_("/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL},*/
        {N_("/_Mail To"),       NULL, addressbook_mail_to_cb,            0, NULL},
 #ifdef USE_LDAP
        {N_("/_Browse Entry"),  NULL, addressbook_browse_entry_cb,       0, NULL},
@@ -546,6 +543,43 @@ static gchar *addressbook_err2string( ErrMsgTableEntry lut[], gint code ) {
         return desc;
 }
 
+static gboolean lastCanLookup = FALSE;
+
+void addressbook_show_buttons(gboolean add_and_delete, gboolean lookup, gboolean mail_ops)
+{
+       if (add_and_delete) {
+               gtk_widget_show(addrbook.edit_btn);
+               gtk_widget_show(addrbook.del_btn);
+               gtk_widget_show(addrbook.reg_btn);
+       } else {
+               gtk_widget_hide(addrbook.edit_btn);
+               gtk_widget_hide(addrbook.del_btn);
+               gtk_widget_hide(addrbook.reg_btn);
+       }
+       
+       if (lookup) {
+               gtk_widget_show(addrbook.lup_btn);
+               gtk_widget_show(addrbook.entry);
+               gtk_widget_show(addrbook.label);
+       } else {
+               gtk_widget_hide(addrbook.lup_btn);
+               gtk_widget_hide(addrbook.entry);
+               gtk_widget_hide(addrbook.label);
+       }
+
+       lastCanLookup = lookup;
+
+       if (mail_ops) {
+               gtk_widget_show(addrbook.to_btn);
+               gtk_widget_show(addrbook.cc_btn);
+               gtk_widget_show(addrbook.bcc_btn);
+       } else {
+               gtk_widget_hide(addrbook.to_btn);
+               gtk_widget_hide(addrbook.cc_btn);
+               gtk_widget_hide(addrbook.bcc_btn);
+       }
+}
+
 void addressbook_open(Compose *target)
 {
        /* Initialize all static members */
@@ -562,7 +596,7 @@ void addressbook_open(Compose *target)
                addressbook_read_file();
                addressbook_create();
                addressbook_load_tree();
-               gtk_ctree_select(GTK_CTREE(addrbook.ctree),
+               gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
                                 GTK_CTREE_NODE(GTK_CLIST(addrbook.ctree)->row_list));
        }
        else {
@@ -570,6 +604,7 @@ void addressbook_open(Compose *target)
        }
 
        gtk_widget_show_all(addrbook.window);
+       addressbook_show_buttons(target == NULL, lastCanLookup, target != NULL);
        addressbook_set_target_compose(target);
 }
 
@@ -611,13 +646,34 @@ void addressbook_refresh( void )
 {
        if (addrbook.window) {
                if (addrbook.treeSelected) {
-                       gtk_ctree_select(GTK_CTREE(addrbook.ctree),
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
                                         addrbook.treeSelected);
                }
        }
        addressbook_export_to_file();
 }
 
+static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
+{
+       if (event && event->keyval == GDK_Escape)
+               addressbook_close();
+       else if (event && event->keyval == GDK_Delete)
+               addressbook_del_clicked(NULL, NULL);
+       return FALSE;
+}
+
+/*!
+ *\brief       Save Gtk object size to prefs dataset
+ */
+static void addressbook_size_allocate_cb(GtkWidget *widget,
+                                        GtkAllocation *allocation)
+{
+       g_return_if_fail(allocation != NULL);
+
+       prefs_common.addressbookwin_width = allocation->width;
+       prefs_common.addressbookwin_height = allocation->height;
+}
+
 /*
 * Create the address book widgets. The address book contains two CTree widgets: the
 * address index tree on the left and the address list on the right.
@@ -652,11 +708,13 @@ static void addressbook_create(void)
        GtkWidget *hbbox;
        GtkWidget *hsbox;
        GtkWidget *del_btn;
+       GtkWidget *edit_btn;
        GtkWidget *reg_btn;
        GtkWidget *lup_btn;
        GtkWidget *to_btn;
        GtkWidget *cc_btn;
        GtkWidget *bcc_btn;
+       GtkWidget *close_btn;
        GtkWidget *tree_popup;
        GtkWidget *list_popup;
        GtkItemFactory *tree_factory;
@@ -665,26 +723,30 @@ static void addressbook_create(void)
        gint n_entries;
        GList *nodeIf;
 
-       gchar *titles[N_COLS];
-       gchar *dummy_titles[1];
+       gchar *index_titles[N_INDEX_COLS];
+       gchar *list_titles[N_LIST_COLS];
        gchar *text;
        gint i;
 
+       static GdkGeometry geometry;
+
        debug_print("Creating addressbook window...\n");
 
-       titles[COL_NAME]    = _("Name");
-       titles[COL_ADDRESS] = _("E-Mail address");
-       titles[COL_REMARKS] = _("Remarks");
-       dummy_titles[0]     = "";
+       index_titles[COL_SOURCES] = _("Sources");
+       list_titles[COL_NAME]    = _("Name");
+       list_titles[COL_ADDRESS] = _("E-Mail address");
+       list_titles[COL_REMARKS] = _("Remarks");
 
+       /* Address book window */
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), _("Address book"));
-       gtk_widget_set_size_request(window, ADDRESSBOOK_WIDTH, ADDRESSBOOK_HEIGHT);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
        gtk_widget_realize(window);
 
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(addressbook_close), NULL);
+       g_signal_connect(G_OBJECT(window), "size_allocate",
+                        G_CALLBACK(addressbook_size_allocate_cb), NULL);
        g_signal_connect(G_OBJECT(window), "key_press_event",
                         G_CALLBACK(key_pressed), NULL);
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
@@ -692,6 +754,7 @@ static void addressbook_create(void)
        vbox = gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(window), vbox);
 
+       /* Menu bar */
        n_entries = sizeof(addressbook_entries) /
                sizeof(addressbook_entries[0]);
        menubar = menubar_create(window, addressbook_entries, n_entries,
@@ -699,7 +762,7 @@ static void addressbook_create(void)
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
        menu_factory = gtk_item_factory_from_widget(menubar);
 
-       vbox2 = gtk_vbox_new(FALSE, 4);
+       vbox2 = gtk_vbox_new(FALSE, BORDER_WIDTH);
        gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
        gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
 
@@ -710,7 +773,7 @@ static void addressbook_create(void)
        gtk_widget_set_size_request(ctree_swin, COL_FOLDER_WIDTH + 40, -1);
 
        /* Address index */
-       ctree = gtk_sctree_new_with_titles(1, 0, dummy_titles);
+       ctree = gtk_sctree_new_with_titles(N_INDEX_COLS, 0, index_titles);
        gtk_container_add(GTK_CONTAINER(ctree_swin), ctree);
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
        gtk_clist_set_column_width(GTK_CLIST(ctree), 0, COL_FOLDER_WIDTH);
@@ -755,7 +818,7 @@ static void addressbook_create(void)
        gtk_box_pack_start(GTK_BOX(clist_vbox), clist_swin, TRUE, TRUE, 0);
 
        /* Address list */
-       clist = gtk_sctree_new_with_titles(N_COLS, 0, titles);
+       clist = gtk_sctree_new_with_titles(N_LIST_COLS, 0, list_titles);
        gtk_container_add(GTK_CONTAINER(clist_swin), clist);
        gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_EXTENDED);
        gtk_ctree_set_line_style(GTK_CTREE(clist), GTK_CTREE_LINES_NONE);
@@ -768,7 +831,7 @@ static void addressbook_create(void)
        gtk_clist_set_compare_func(GTK_CLIST(clist),
                                   addressbook_list_compare_func);
 
-       for (i = 0; i < N_COLS; i++)
+       for (i = 0; i < N_LIST_COLS; i++)
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
                                       GTK_CAN_FOCUS);
 
@@ -793,16 +856,17 @@ static void addressbook_create(void)
        hbox = gtk_hbox_new(FALSE, 4);
        gtk_box_pack_start(GTK_BOX(clist_vbox), hbox, FALSE, FALSE, 0);
 
-       label = gtk_label_new(_("Name:"));
+       label = gtk_label_new(_("Lookup name:"));
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 
        entry = gtk_entry_new();
        gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
 
        address_completion_register_entry(GTK_ENTRY(entry));
-       g_signal_connect(G_OBJECT(entry), "focus_in_event",
-                        G_CALLBACK(addressbook_entry_gotfocus), NULL);
 
+       g_signal_connect(G_OBJECT(entry), "key_press_event",
+                        G_CALLBACK(addressbook_entry_key_pressed),
+                        NULL);
 #if 0
        g_signal_connect(G_OBJECT(entry), "changed",
                         G_CALLBACK(addressbook_entry_changed), NULL);
@@ -822,19 +886,31 @@ static void addressbook_create(void)
        /* Button panel */
        hbbox = gtk_hbutton_box_new();
        gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
-       gtk_box_set_spacing(GTK_BOX(hbbox), 2);
+       gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 2);
+       gtk_container_set_border_width(GTK_CONTAINER(hbbox), 4);
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
 
-       del_btn = gtk_button_new_with_label(_("Delete"));
+#if GTK_CHECK_VERSION(2, 6, 0)
+       edit_btn = gtk_button_new_from_stock(GTK_STOCK_EDIT);
+#else
+       edit_btn = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES);
+#endif
+       GTK_WIDGET_SET_FLAGS(edit_btn, GTK_CAN_DEFAULT);
+       gtk_box_pack_start(GTK_BOX(hbbox), edit_btn, TRUE, TRUE, 0);
+       del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
        GTK_WIDGET_SET_FLAGS(del_btn, GTK_CAN_DEFAULT);
        gtk_box_pack_start(GTK_BOX(hbbox), del_btn, TRUE, TRUE, 0);
-       reg_btn = gtk_button_new_with_label(_("Add"));
+       reg_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
        GTK_WIDGET_SET_FLAGS(reg_btn, GTK_CAN_DEFAULT);
        gtk_box_pack_start(GTK_BOX(hbbox), reg_btn, TRUE, TRUE, 0);
-       lup_btn = gtk_button_new_with_label(_("Lookup"));
+
+
+       lup_btn = gtk_button_new_from_stock(GTK_STOCK_FIND);
        GTK_WIDGET_SET_FLAGS(lup_btn, GTK_CAN_DEFAULT);
-       gtk_box_pack_start(GTK_BOX(hbbox), lup_btn, TRUE, TRUE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), lup_btn, TRUE, TRUE, 0);
 
+       g_signal_connect(G_OBJECT(edit_btn), "clicked",
+                        G_CALLBACK(addressbook_edit_clicked), NULL);
        g_signal_connect(G_OBJECT(del_btn), "clicked",
                         G_CALLBACK(addressbook_del_clicked), NULL);
        g_signal_connect(G_OBJECT(reg_btn), "clicked",
@@ -855,6 +931,10 @@ static void addressbook_create(void)
        GTK_WIDGET_SET_FLAGS(bcc_btn, GTK_CAN_DEFAULT);
        gtk_box_pack_start(GTK_BOX(hbbox), bcc_btn, TRUE, TRUE, 0);
 
+       close_btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+       GTK_WIDGET_SET_FLAGS(close_btn, GTK_CAN_DEFAULT);
+       gtk_box_pack_start(GTK_BOX(hbbox), close_btn, TRUE, TRUE, 0);
+
        g_signal_connect(G_OBJECT(to_btn), "clicked",
                         G_CALLBACK(addressbook_to_clicked),
                         GINT_TO_POINTER(COMPOSE_TO));
@@ -864,6 +944,8 @@ static void addressbook_create(void)
        g_signal_connect(G_OBJECT(bcc_btn), "clicked",
                         G_CALLBACK(addressbook_to_clicked),
                         GINT_TO_POINTER(COMPOSE_BCC));
+       g_signal_connect(G_OBJECT(close_btn), "clicked",
+                        G_CALLBACK(addressbook_close_clicked), NULL);
 
        /* Build icons for interface */
        stock_pixmap_gdk( window, STOCK_PIXMAP_INTERFACE,
@@ -904,8 +986,6 @@ static void addressbook_create(void)
                                       n_entries,
                                       "<AddressBookTree>", &tree_factory,
                                       NULL);
-       g_signal_connect(G_OBJECT(tree_popup), "selection_done",
-                        G_CALLBACK(addressbook_popup_close), NULL);
        n_entries = sizeof(addressbook_list_popup_entries) /
                sizeof(addressbook_list_popup_entries[0]);
        list_popup = menu_create_items(addressbook_list_popup_entries,
@@ -919,11 +999,13 @@ static void addressbook_create(void)
        addrbook.ctree_swin
                         = ctree_swin;
        addrbook.clist   = clist;
+       addrbook.label   = label;
        addrbook.entry   = entry;
        addrbook.statusbar = statusbar;
        addrbook.status_cid = gtk_statusbar_get_context_id(
                        GTK_STATUSBAR(statusbar), "Addressbook Window" );
 
+       addrbook.edit_btn = edit_btn;
        addrbook.del_btn = del_btn;
        addrbook.reg_btn = reg_btn;
        addrbook.lup_btn = lup_btn;
@@ -939,9 +1021,18 @@ static void addressbook_create(void)
 
        addrbook.listSelected = NULL;
        address_completion_start(window);
-       gtk_widget_show_all(window);
-       gtk_widget_set_sensitive(addrbook.lup_btn, FALSE);
 
+       if (!geometry.min_height) {
+               geometry.min_width = ADDRESSBOOK_WIDTH;
+               geometry.min_height = ADDRESSBOOK_HEIGHT;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(window, prefs_common.addressbookwin_width,
+                                   prefs_common.addressbookwin_height);
+
+       gtk_widget_show_all(window);
 }
 
 /**
@@ -1029,6 +1120,11 @@ static void addressbook_button_set_sensitive(void)
        gtk_widget_set_sensitive(addrbook.bcc_btn, bcc_sens);
 }
 
+static void addressbook_edit_clicked(GtkButton *button, gpointer data)
+{
+       addressbook_edit_address_cb(NULL, 0, NULL);
+}
+
 /*
 * Delete one or more objects from address list.
 */
@@ -1054,6 +1150,7 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
 
        /* Test whether anything selected for deletion */
        nodeList = addrbook.listSelected;
+
        aio = gtk_ctree_node_get_row_data( clist, nodeList );
        if( aio == NULL) return;
        ds = addressbook_find_datasource( addrbook.treeSelected );
@@ -1094,6 +1191,7 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
        if( pobj->type == ADDR_DATASOURCE || pobj->type == ADDR_ITEM_FOLDER ) {
                /* Items inside folders */
                list = addrselect_get_list( _addressSelect_ );
+
                node = list;
                while( node ) {
                        item = node->data;
@@ -1115,6 +1213,8 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
                        else if( aio->type == ADDR_ITEM_PERSON ) {
                                ItemPerson *item = ( ItemPerson * ) aio;
                                addressbook_folder_remove_one_person( clist, item );
+                               if (pobj->type == ADDR_ITEM_FOLDER)
+                                       addritem_folder_remove_person(ADAPTER_FOLDER(pobj)->itemFolder, item);
                                item = addrbook_remove_person( abf, item );
                                if( item ) {
                                        addritem_free_item_person( item );
@@ -1132,7 +1232,11 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
                }
                g_list_free( list );
                addressbook_list_select_clear();
-               if( refreshList ) gtk_ctree_select( ctree, addrbook.opened);
+               if( refreshList ) 
+                       gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
+               addrbook_set_dirty(abf, TRUE);
+               addressbook_export_to_file();
+               addressbook_list_menu_setup();
                return;
        }
        else if( pobj->type == ADDR_ITEM_GROUP ) {
@@ -1154,7 +1258,10 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data)
                }
                g_list_free( list );
                addressbook_list_select_clear();
-               gtk_ctree_select( ctree, addrbook.opened);
+               gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened);
+               addrbook_set_dirty(abf, TRUE);
+               addressbook_export_to_file();
+               addressbook_list_menu_setup();
                return;
        }
 
@@ -1253,7 +1360,17 @@ static void addressbook_to_clicked(GtkButton *button, gpointer data)
                }
                else if( aio->type == ADDR_ITEM_GROUP ) {
                        ItemGroup *group = ( ItemGroup * ) aio;
+                       AddressDataSource *ds = NULL;
+                       AddressBookFile *abf = NULL;
                        GList *nodeMail = group->listEMail;
+                       if (nodeMail == NULL) {
+                               if(addrbook.treeSelected ) {
+                                       ds = addressbook_find_datasource( addrbook.treeSelected );
+                                       abf = ds->rawDataSource;
+                                       if( abf != NULL )
+                                               nodeMail = addrbook_get_available_email_list( abf, group );
+                               }
+                       }
                        while( nodeMail ) {
                                ItemEMail *email = nodeMail->data;
 
@@ -1270,24 +1387,25 @@ static void addressbook_to_clicked(GtkButton *button, gpointer data)
 }
 
 static void addressbook_menubar_set_sensitive( gboolean sensitive ) {
-       menu_set_sensitive( addrbook.menu_factory, "/File/Edit",   sensitive );
-       menu_set_sensitive( addrbook.menu_factory, "/File/Delete", sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book",   sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book", sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/New Folder",  sensitive );
 
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut",    sensitive );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy",   sensitive );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste",  sensitive );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address",  sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Cut",    sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Copy",   sensitive );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Paste",  sensitive );
 
        menu_set_sensitive( addrbook.menu_factory, "/Address/New Address", sensitive );
        menu_set_sensitive( addrbook.menu_factory, "/Address/New Group",   sensitive );
-       menu_set_sensitive( addrbook.menu_factory, "/Address/New Folder",  sensitive );
        menu_set_sensitive( addrbook.menu_factory, "/Address/Mail To",     sensitive );
        gtk_widget_set_sensitive( addrbook.reg_btn, sensitive );
+       gtk_widget_set_sensitive( addrbook.edit_btn, sensitive );
        gtk_widget_set_sensitive( addrbook.del_btn, sensitive );
 }
 
 static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode *node ) {
        gboolean canEdit = FALSE;
+       gboolean canDelete = TRUE;
        gboolean canAdd = FALSE;
        gboolean canEditTr = TRUE;
        gboolean editAddress = FALSE;
@@ -1314,10 +1432,10 @@ static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode
                ds = ads->dataSource;
                iface = ds->interface;
                if( ! iface->readOnly ) {
-                       canAdd = canEdit = editAddress = TRUE;
+                       canAdd = canEdit = editAddress = canDelete = TRUE;
                }
                if( ! iface->haveLibrary ) {
-                       canAdd = canEdit = editAddress = canExport = FALSE;
+                       canAdd = canEdit = editAddress = canExport = canDelete = FALSE;
                }
        }
        else if( obj->type == ADDR_ITEM_FOLDER ) {
@@ -1326,6 +1444,7 @@ static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode
                        iface = ds->interface;
                        if( iface->readOnly ) {
                                canEditTr = FALSE;
+                               canDelete = FALSE;
                        }
                        else {
                                canAdd = editAddress = TRUE;
@@ -1347,22 +1466,25 @@ static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCTreeNode
        /* Enable add */
        menu_set_sensitive( addrbook.menu_factory, "/Address/New Address", editAddress );
        menu_set_sensitive( addrbook.menu_factory, "/Address/New Group",   canAdd );
-       menu_set_sensitive( addrbook.menu_factory, "/Address/New Folder",  canAdd );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/New Folder",  canAdd );
        gtk_widget_set_sensitive( addrbook.reg_btn, editAddress );
 
        /* Enable edit */
        menu_set_sensitive( addrbook.menu_factory, "/Address/Edit",   canEdit );
-       menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canEdit );
-       gtk_widget_set_sensitive( addrbook.del_btn, canEdit );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Delete", canDelete );
+       gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
+       gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
 
-       menu_set_sensitive( addrbook.menu_factory, "/File/Edit",      canEditTr );
-       menu_set_sensitive( addrbook.menu_factory, "/File/Delete",    canEditTr );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book",      canEditTr );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book",    canEditTr );
 
        /* Export data */
        menu_set_sensitive( addrbook.menu_factory, "/Tools/Export HTML...", canExport );
        menu_set_sensitive( addrbook.menu_factory, "/Tools/Export LDIF...", canExport );
 }
 
+static void addressbook_list_menu_setup( void );
+
 /**
  * Address book tree callback function that responds to selection of tree
  * items.
@@ -1438,10 +1560,11 @@ static gboolean addressbook_tree_selected(GtkCTree *ctree, GtkCTreeNode *node,
 
        /* Setup main menu selections */
        addressbook_menubar_set_sensitive( FALSE );
+       addressbook_list_menu_setup();
        addressbook_menuitem_set_sensitive( obj, node );
 
        addressbook_list_select_clear();
-       
+       addressbook_list_menu_setup();
        return FALSE;
 }
 
@@ -1479,13 +1602,13 @@ static void addressbook_list_menu_setup( void ) {
                iface = ds->interface;
                if( ! iface->readOnly ) {
                        menu_set_sensitive( addrbook.list_factory, "/New Address", TRUE );
-                       menu_set_sensitive( addrbook.list_factory, "/New Folder", TRUE );
                        menu_set_sensitive( addrbook.list_factory, "/New Group", TRUE );
                        gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
                        if( ! addrclip_is_empty( _clipBoard_ ) ) canPaste = TRUE;
                        if( ! addrselect_test_empty( _addressSelect_ ) ) canCut = TRUE;
                        if( obj ) canEdit = TRUE;
                }
+               canDelete = canEdit;
        }
        else if( pobj->type != ADDR_INTERFACE ) {
                /* Parent object is not an interface */
@@ -1500,21 +1623,21 @@ static void addressbook_list_menu_setup( void ) {
                        }
                        /* Folder */
                        if( pobj->type == ADDR_ITEM_FOLDER ) {
-                               menu_set_sensitive( addrbook.list_factory, "/New Folder", TRUE );
                                menu_set_sensitive( addrbook.list_factory, "/New Group", TRUE );
                                if( obj ) canEdit = TRUE;
                        }
                        if( ! addrclip_is_empty( _clipBoard_ ) ) canPaste = TRUE;
                        if( ! addrselect_test_empty( _addressSelect_ ) ) canCut = TRUE;
+                       canDelete = canEdit;
                }
                if( iface->type == ADDR_IF_LDAP ) {
                        if( obj ) canBrowse = TRUE;
+                       canEdit = TRUE;
+                       canDelete = FALSE;
                }
        }
        if( ! addrselect_test_empty( _addressSelect_ ) ) canCopy = TRUE;
 
-       canDelete = canEdit;
-
        /* Disable edit or browse if more than one row selected */
        if( GTK_CLIST(clist)->selection && GTK_CLIST(clist)->selection->next ) {
                canEdit = FALSE;
@@ -1528,14 +1651,14 @@ static void addressbook_list_menu_setup( void ) {
        menu_set_sensitive( addrbook.list_factory, "/Cut",           canCut );
        menu_set_sensitive( addrbook.list_factory, "/Copy",          canCopy );
        menu_set_sensitive( addrbook.list_factory, "/Paste",         canPaste );
-       menu_set_sensitive( addrbook.list_factory, "/Paste Address", canPaste );
+/*     menu_set_sensitive( addrbook.list_factory, "/Paste Address", canPaste );*/
 
        menu_set_sensitive( addrbook.list_factory, "/Mail To",       canCopy );
 
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut",           canCut );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy",          canCopy );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste",         canPaste );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Cut",           canCut );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Copy",          canCopy );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Paste",         canPaste );
+/*     menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );*/
 
        menu_set_sensitive( addrbook.tree_factory, "/Cut",             canCut );
        menu_set_sensitive( addrbook.tree_factory, "/Copy",            canCopy );
@@ -1545,6 +1668,7 @@ static void addressbook_list_menu_setup( void ) {
        menu_set_sensitive( addrbook.menu_factory, "/Address/Delete",  canDelete );
        menu_set_sensitive( addrbook.menu_factory, "/Address/Mail To", canCopy );
 
+       gtk_widget_set_sensitive( addrbook.edit_btn, canEdit );
        gtk_widget_set_sensitive( addrbook.del_btn, canDelete );
 
 #ifdef USE_LDAP
@@ -1677,10 +1801,11 @@ static void addressbook_clip_paste_cb( void ) {
        }
 
        /* Display items pasted */
-       gtk_ctree_select( ctree, addrbook.opened );
+       gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
 
 }
 
+#if 0
 /**
  * Paste clipboard email addresses only into address list widget.
  */
@@ -1742,9 +1867,10 @@ static void addressbook_clip_paste_address_cb( void ) {
 
        /* Display items pasted */
        if( cnt > 0 ) {
-               gtk_ctree_select( ctree, addrbook.opened );
+               gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
        }
 }
+#endif
 
 /**
  * Add current treenode object to clipboard. Note that widget only allows
@@ -1917,10 +2043,6 @@ static void addressbook_list_row_unselected( GtkCTree *ctree,
        }
 }
 
-static void addressbook_entry_gotfocus( GtkWidget *widget ) {
-       gtk_editable_select_region( GTK_EDITABLE(addrbook.entry), 0, -1 );
-}
-
 /* from gdkevents.c */
 #define DOUBLE_CLICK_TIME 250
 
@@ -1984,12 +2106,12 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
 
        if( gtk_clist_get_selection_info( clist, event->x, event->y, &row, &column ) ) {
                gtk_clist_select_row( clist, row, column );
+               
                gtkut_clist_set_focus_row(clist, row);
                obj = gtk_clist_get_row_data( clist, row );
        }
 
        menu_set_insensitive_all(GTK_MENU_SHELL(addrbook.tree_popup));
-       gtk_widget_set_sensitive( addrbook.lup_btn, FALSE );
 
        if( obj == NULL ) return FALSE;
 
@@ -2007,9 +2129,7 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
                        canTreePaste = FALSE;
                }
                else {
-                       menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
                        menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
-                       menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
                        gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
                }
                canTreeCopy = TRUE;
@@ -2025,9 +2145,7 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
                        canEdit = TRUE;
                        canDelete = TRUE;
                        canTreeCut = TRUE;
-                       menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
                        menu_set_sensitive( addrbook.tree_factory, "/New Folder", TRUE );
-                       menu_set_sensitive( addrbook.tree_factory, "/New Group", TRUE );
                        gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
                }
                canTreeCopy = TRUE;
@@ -2044,7 +2162,7 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
                if( ! iface->readOnly ) {
                        canEdit = TRUE;
                        canDelete = TRUE;
-                       menu_set_sensitive( addrbook.tree_factory, "/New Address", TRUE );
+                       menu_set_sensitive( addrbook.list_factory, "/New Address", TRUE );
                        gtk_widget_set_sensitive( addrbook.reg_btn, TRUE );
                }
        }
@@ -2065,15 +2183,14 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
        menu_set_sensitive( addrbook.tree_factory, "/Copy",   canTreeCopy );
        menu_set_sensitive( addrbook.tree_factory, "/Paste",  canTreePaste );
 
-       menu_set_sensitive( addrbook.menu_factory, "/File/Edit",          canEdit );
-       menu_set_sensitive( addrbook.menu_factory, "/File/Delete",        canEdit );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Cut",           canCut );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Copy",          canCopy );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste",         canPaste );
-       menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );
-
-       gtk_widget_set_sensitive( addrbook.lup_btn, canLookup );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Edit book",          canEdit );
+       menu_set_sensitive( addrbook.menu_factory, "/Book/Delete book",        canEdit );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Cut",           canCut );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Copy",          canCopy );
+       menu_set_sensitive( addrbook.menu_factory, "/Address/Paste",         canPaste );
+/*     menu_set_sensitive( addrbook.menu_factory, "/Edit/Paste Address", canPaste );*/
 
+       addressbook_show_buttons(addrbook.target_compose == NULL, canLookup, addrbook.target_compose != NULL);
        if( event->button == 3 ) {
                gtk_menu_popup(GTK_MENU(addrbook.tree_popup), NULL, NULL, NULL, NULL,
                               event->button, event->time);
@@ -2086,20 +2203,12 @@ static gboolean addressbook_tree_button_released(GtkWidget *ctree,
                                                 GdkEventButton *event,
                                                 gpointer data)
 {
-       gtk_ctree_select(GTK_CTREE(addrbook.ctree), addrbook.opened);
+       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened);
+       
        gtkut_ctree_set_focus_row(GTK_CTREE(addrbook.ctree), addrbook.opened);
        return FALSE;
 }
 
-static void addressbook_popup_close(GtkMenuShell *menu_shell, gpointer data)
-{
-       if (!addrbook.opened) return;
-
-       gtk_ctree_select(GTK_CTREE(addrbook.ctree), addrbook.opened);
-       gtkut_ctree_set_focus_row(GTK_CTREE(addrbook.ctree),
-                                 addrbook.opened);
-}
-
 static void addressbook_new_folder_cb(gpointer data, guint action,
                                      GtkWidget *widget)
 {
@@ -2299,7 +2408,7 @@ static void addressbook_treenode_edit_cb(gpointer data, guint action,
                addressbook_change_node_name( node, name );
                gtk_sctree_sort_node(ctree, parentNode);
                gtk_ctree_expand( ctree, node );
-               gtk_ctree_select( ctree, node );
+               gtk_sctree_select( GTK_SCTREE( ctree), node );
        }
 }
 
@@ -2364,7 +2473,7 @@ static void addressbook_treenode_delete_cb(
                if( iface->externalQuery ) {
                        message = g_strdup_printf( _(
                                "Do you want to delete the query " \
-                               "results and addresses in `%s' ?" ),
+                               "results and addresses in '%s' ?" ),
                                obj->name );
                        aval = alertpanel( _("Delete"), message,
                                GTK_STOCK_YES, GTK_STOCK_NO, NULL );
@@ -2374,15 +2483,12 @@ static void addressbook_treenode_delete_cb(
                        }
                }
                else {
-                       message = g_strdup_printf( _(
-                               "Do you want to delete the folder " \
-                               "AND all addresses in `%s' ? \n" \
-                               "If deleting the folder only, addresses " \
-                               "will be moved into parent folder." ),
-                               obj->name );
-                       aval = alertpanel( _("Delete"), message,
-                               _("Folder only"),
-                               _("Folder and Addresses"),
+                       message = g_strdup_printf
+                               ( _( "Do you want to delete the folder AND all addresses in '%s' ?\n"
+                                    "If deleting the folder only, addresses will be moved into parent folder." ),
+                                obj->name );
+                       aval = alertpanel( _("Delete folder"), message,
+                               _("_Folder only"), _("Folder and _addresses"),
                                GTK_STOCK_CANCEL );
                        g_free(message);
                        if( aval == G_ALERTDEFAULT ) {
@@ -2394,7 +2500,7 @@ static void addressbook_treenode_delete_cb(
                }
        }
        else {
-               message = g_strdup_printf(_("Really delete `%s' ?"), obj->name);
+               message = g_strdup_printf(_("Really delete '%s' ?"), obj->name);
                aval = alertpanel(_("Delete"), message, GTK_STOCK_YES, GTK_STOCK_NO, NULL);
                g_free(message);
                if( aval == G_ALERTDEFAULT ) delType = ADDRTREE_DEL_DATA;
@@ -2505,7 +2611,7 @@ static void addressbook_new_address_cb( gpointer data, guint action, GtkWidget *
                ItemPerson *person = addressbook_edit_person( abf, folder, NULL, FALSE );
                if( person ) {
                        if (addrbook.treeSelected == addrbook.opened) {
-                               gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened );
+                               gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
                        }
                }
        }
@@ -2516,7 +2622,7 @@ static void addressbook_new_address_cb( gpointer data, guint action, GtkWidget *
                if (addrbook.treeSelected == addrbook.opened) {
                        /* Change node name in tree. */
                        addressbook_change_node_name( addrbook.treeSelected, ADDRITEM_NAME(group) );
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened );
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened );
                }
        }
 }
@@ -2615,7 +2721,7 @@ static void addressbook_edit_address_cb( gpointer data, guint action, GtkWidget
        if( ds == NULL ) return;
 
        abf = addressbook_get_book_file();
-       if( abf == NULL ) return;
+       
        if( obj->type == ADDR_ITEM_EMAIL ) {
                ItemEMail *email = ( ItemEMail * ) obj;
                if( email == NULL ) return;
@@ -2623,6 +2729,7 @@ static void addressbook_edit_address_cb( gpointer data, guint action, GtkWidget
                        /* Edit parent group */
                        AdapterGroup *adapter = ADAPTER_GROUP(pobj);
                        ItemGroup *itemGrp = adapter->itemGroup;
+                       if( abf == NULL ) return;
                        if( addressbook_edit_group( abf, NULL, itemGrp ) == NULL ) return;
                        name = ADDRITEM_NAME(itemGrp);
                        node = addrbook.treeSelected;
@@ -2661,7 +2768,7 @@ static void addressbook_edit_address_cb( gpointer data, guint action, GtkWidget
        if( node == NULL ) return;
        addressbook_change_node_name( node, name );
        gtk_sctree_sort_node( ctree, parentNode );
-       gtk_ctree_select( ctree, addrbook.opened ); 
+       gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened ); 
 }
 
 static void addressbook_delete_address_cb(gpointer data, guint action,
@@ -2712,7 +2819,7 @@ static void addressbook_load_group( GtkCTree *clist, ItemGroup *itemGroup ) {
        AddressTypeControlItem *atci = addrbookctl_lookup( ADDR_ITEM_EMAIL );
        for( ; items != NULL; items = g_list_next( items ) ) {
                GtkCTreeNode *nodeEMail = NULL;
-               gchar *text[N_COLS];
+               gchar *text[N_LIST_COLS];
                ItemEMail *email = items->data;
                ItemPerson *person;
                gchar *str = NULL;
@@ -2748,7 +2855,7 @@ static void addressbook_folder_load_one_person(
 {
        GtkCTreeNode *nodePerson = NULL;
        GtkCTreeNode *nodeEMail = NULL;
-       gchar *text[N_COLS];
+       gchar *text[N_LIST_COLS];
        gboolean flgFirst = TRUE, haveAddr = FALSE;
        GList *node;
 
@@ -2855,9 +2962,10 @@ static void addressbook_folder_refresh_one_person( GtkCTree *clist, ItemPerson *
        if( node )
                addressbook_folder_remove_node( clist, node );
        addressbook_folder_load_one_person( clist, person, atci, atciMail );
+       gtk_sctree_sort_node( clist, NULL );
        node = gtk_ctree_find_by_row_data( clist, NULL, person );
        if( node ) {
-               gtk_ctree_select( clist, node );
+               gtk_sctree_select( GTK_SCTREE(clist), node );
                if (!gtk_ctree_node_is_visible( clist, node ) ) 
                        gtk_ctree_node_moveto( clist, node, 0, 0, 0 );
        }
@@ -2884,7 +2992,7 @@ static void addressbook_folder_load_group( GtkCTree *clist, ItemFolder *itemFold
        items = addritem_folder_get_group_list( itemFolder );
        for( ; items != NULL; items = g_list_next( items ) ) {
                GtkCTreeNode *nodeGroup = NULL;
-               gchar *text[N_COLS];
+               gchar *text[N_LIST_COLS];
                ItemGroup *group = items->data;
                if( group == NULL ) continue;
                text[COL_NAME] = ADDRITEM_NAME(group);
@@ -3238,13 +3346,15 @@ static gboolean addressbook_convert( AddressIndex *addrIndex ) {
        }
        if( errFlag ) {
                debug_print( "Error\n%s\n", msg );
-               alertpanel_with_type( _( "Addressbook conversion error" ), msg, GTK_STOCK_CLOSE, 
-                                     NULL, NULL, NULL, ALERT_ERROR );
+               alertpanel_full(_("Addressbook conversion error"), msg,
+                               GTK_STOCK_CLOSE, NULL, NULL, FALSE,
+                               NULL, ALERT_ERROR, G_ALERTDEFAULT);
        }
        else if( msg ) {
                debug_print( "Warning\n%s\n", msg );
-               alertpanel_with_type( _( "Addressbook conversion" ), msg, GTK_STOCK_CLOSE, 
-                                     NULL, NULL, NULL, ALERT_WARNING );
+               alertpanel_full(_("Addressbook conversion error"), msg,
+                               GTK_STOCK_CLOSE, NULL, NULL, FALSE,
+                               NULL, ALERT_WARNING, G_ALERTDEFAULT);
        }
 
        return retVal;
@@ -3280,10 +3390,10 @@ void addressbook_read_file( void ) {
                /* Error reading address book */
                debug_print( "Could not read address index.\n" );
                addrindex_print_index( addrIndex, stdout );
-               alertpanel_with_type( _( "Addressbook Error" ),
-                           _( "Could not read address index" ),
-                           GTK_STOCK_CLOSE, NULL, NULL, NULL,
-                           ALERT_ERROR);
+               alertpanel_full(_("Addressbook Error"),
+                               _("Could not read address index"),
+                               GTK_STOCK_CLOSE, NULL, NULL, FALSE,
+                               NULL, ALERT_ERROR, G_ALERTDEFAULT);
        }
        debug_print( "done.\n" );
 }
@@ -3462,10 +3572,10 @@ void addressbook_export_to_file( void ) {
        }
 }
 
-static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean addressbook_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-       if (event && event->keyval == GDK_Escape)
-               addressbook_close();
+       if (event && event->keyval == GDK_Return)
+               addressbook_lup_clicked(NULL, NULL);
        return FALSE;
 }
 
@@ -3529,7 +3639,7 @@ static void addressbook_new_book_cb( gpointer data, guint action, GtkWidget *wid
        if( ads ) {
                newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
                if( newNode ) {
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
                        addrbook.treeSelected = newNode;
                }
        }
@@ -3546,7 +3656,7 @@ static void addressbook_new_vcard_cb( gpointer data, guint action, GtkWidget *wi
        if( ads ) {
                newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
                if( newNode ) {
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
                        addrbook.treeSelected = newNode;
                }
        }
@@ -3567,7 +3677,7 @@ static void addressbook_new_jpilot_cb( gpointer data, guint action, GtkWidget *w
        if( ads ) {
                newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
                if( newNode ) {
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
                        addrbook.treeSelected = newNode;
                }
        }
@@ -3589,7 +3699,7 @@ static void addressbook_new_ldap_cb( gpointer data, guint action, GtkWidget *wid
        if( ads ) {
                newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) );
                if( newNode ) {
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), newNode );
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode );
                        addrbook.treeSelected = newNode;
                }
        }
@@ -3762,7 +3872,7 @@ static void addressbook_perform_search(
        nNode = addressbook_node_add_folder( pNode, ds, folder, aoType );
        gtk_ctree_expand( ctree, pNode );
        if( nNode ) {
-               gtk_ctree_select( ctree, nNode );
+               gtk_sctree_select( GTK_SCTREE(ctree), nNode );
                addrbook.treeSelected = nNode;
        }
 
@@ -3824,11 +3934,16 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
                parentNode = node;
        }
        addressbook_perform_search( ds, searchTerm, parentNode );
+       
        gtk_widget_grab_focus( addrbook.entry );
 
        g_free( searchTerm );
 }
 
+static void addressbook_close_clicked( GtkButton *button, gpointer data ) {
+       addressbook_close();
+}
+
 #ifdef USE_LDAP
 /**
  * Browse address entry for highlighted entry.
@@ -3952,7 +4067,7 @@ void addrbookctl_build_map( GtkWidget *window ) {
        atci->maskXpm = bookxpmmask;
        atci->iconXpmOpen = bookxpm;
        atci->maskXpmOpen = bookxpmmask;
-       atci->menuCommand = "/File/New Book";
+       atci->menuCommand = "/Book/New Book";
        g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
        _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
 
@@ -4032,7 +4147,7 @@ void addrbookctl_build_map( GtkWidget *window ) {
        atci->maskXpm = vcardxpmmask;
        atci->iconXpmOpen = vcardxpm;
        atci->maskXpmOpen = vcardxpmmask;
-       atci->menuCommand = "/File/New vCard";
+       atci->menuCommand = "/Book/New vCard";
        g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
        _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
 
@@ -4048,7 +4163,7 @@ void addrbookctl_build_map( GtkWidget *window ) {
        atci->maskXpm = jpilotxpmmask;
        atci->iconXpmOpen = jpilotxpm;
        atci->maskXpmOpen = jpilotxpmmask;
-       atci->menuCommand = "/File/New JPilot";
+       atci->menuCommand = "/Book/New JPilot";
        g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
        _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
 
@@ -4080,7 +4195,7 @@ void addrbookctl_build_map( GtkWidget *window ) {
        atci->maskXpm = ldapxpmmask;
        atci->iconXpmOpen = ldapxpm;
        atci->maskXpmOpen = ldapxpmmask;
-       atci->menuCommand = "/File/New Server";
+       atci->menuCommand = "/Book/New Server";
        g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci );
        _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci );
 
@@ -4320,8 +4435,7 @@ static void addressbook_import_ldif_cb( void ) {
                                        adapter->treeNode,
                                        ADDRESS_OBJECT(ads) );
                                if( newNode ) {
-                                       gtk_ctree_select(
-                                               GTK_CTREE(addrbook.ctree),
+                                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
                                                newNode );
                                        addrbook.treeSelected = newNode;
                                }
@@ -4358,8 +4472,7 @@ static void addressbook_import_mutt_cb( void ) {
                                        adapter->treeNode,
                                        ADDRESS_OBJECT(ads) );
                                if( newNode ) {
-                                       gtk_ctree_select(
-                                               GTK_CTREE(addrbook.ctree),
+                                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
                                                newNode );
                                        addrbook.treeSelected = newNode;
                                }
@@ -4396,8 +4509,7 @@ static void addressbook_import_pine_cb( void ) {
                                        adapter->treeNode,
                                        ADDRESS_OBJECT(ads) );
                                if( newNode ) {
-                                       gtk_ctree_select(
-                                               GTK_CTREE(addrbook.ctree),
+                                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree),
                                                newNode );
                                        addrbook.treeSelected = newNode;
                                }
@@ -4507,7 +4619,7 @@ static void addressbook_start_drag(GtkWidget *widget, gint button,
        gtk_drag_set_icon_default(context);
 }
 
-static ItemPerson *dragged_person = NULL;
+static GSList *dragged_persons = NULL;
 static ItemFolder *dragged_folder = NULL;
 static AddressBookFile *dragged_ab = NULL;
 
@@ -4522,6 +4634,7 @@ static void addressbook_drag_data_get(GtkWidget        *widget,
        AddressObject *pobj = NULL;
        AdapterDSource *ads = NULL;
        AddressDataSource *ds = NULL;
+       GList *cur;
 
        pobj = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.ctree), addrbook.treeSelected );
        if( pobj == NULL ) return;
@@ -4538,16 +4651,20 @@ static void addressbook_drag_data_get(GtkWidget        *widget,
                if (!ds)
                        return;
        }
-       if (addrbook.listSelected)
-               aio = gtk_ctree_node_get_row_data( GTK_CTREE(addrbook.clist), 
-                               addrbook.listSelected );
        
-       while (aio && aio->type != ADDR_ITEM_PERSON) {
-               aio = aio->parent;
+
+       for(cur = GTK_CLIST(addrbook.clist)->selection; cur; cur = cur->next) {
+               aio = (AddrItemObject *)gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.clist), 
+                       GTK_CTREE_NODE(cur->data));
+               while (aio && aio->type != ADDR_ITEM_PERSON) {
+                       aio = aio->parent;
+               }
+               if (aio) {
+                       dragged_persons = g_slist_append(dragged_persons, aio);
+               }
        }
 
        if (aio && aio->type == ADDR_ITEM_PERSON) {
-               dragged_person = (ItemPerson *)aio;
                dragged_folder = (ItemFolder *)ADAPTER_FOLDER(pobj)->itemFolder;
                dragged_ab = addressbook_get_book_file();
 
@@ -4564,13 +4681,15 @@ static void addressbook_drag_data_get(GtkWidget        *widget,
                                    drag_context->action = GDK_ACTION_COPY;
                        } else {
                                dragged_folder = NULL;
-                               dragged_person = NULL;
+                               g_slist_free(dragged_persons);
+                               dragged_persons = NULL;
                                dragged_ab = NULL;
                        }
                }
        } else {
                dragged_folder = NULL;
-               dragged_person = NULL;
+               g_slist_free(dragged_persons);
+               dragged_persons = NULL;
                dragged_ab = NULL;
        }
 }
@@ -4627,7 +4746,7 @@ static gboolean addressbook_drag_motion_cb(GtkWidget      *widget,
                g_signal_handlers_block_by_func
                        (G_OBJECT(widget),
                         G_CALLBACK(addressbook_tree_selected), NULL);
-               gtk_ctree_select(GTK_CTREE(widget), node);
+               gtk_sctree_select( GTK_SCTREE(widget), node);
                g_signal_handlers_unblock_by_func
                        (G_OBJECT(widget),
                         G_CALLBACK(addressbook_tree_selected), NULL);
@@ -4650,7 +4769,7 @@ static void addressbook_drag_leave_cb(GtkWidget      *widget,
                g_signal_handlers_block_by_func
                        (G_OBJECT(widget),
                         G_CALLBACK(addressbook_tree_selected), NULL);
-               gtk_ctree_select(GTK_CTREE(widget), addrbook.treeSelected);
+               gtk_sctree_select( GTK_SCTREE(widget), addrbook.treeSelected);
                g_signal_handlers_unblock_by_func
                        (G_OBJECT(widget),
                         G_CALLBACK(addressbook_tree_selected), NULL);
@@ -4677,38 +4796,34 @@ static void addressbook_drag_received_cb(GtkWidget        *widget,
                AddressObject *obj = NULL;
                AdapterDSource *ads = NULL;
                AddressDataSource *ds = NULL;
-               
+               GSList *cur = dragged_persons;
+
                if (gtk_clist_get_selection_info
                        (GTK_CLIST(widget), x - 24, y - 24, &row, &column) == 0) {
-                       return;
+                       goto free_list;
                }
        
                node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
                if( node ) 
                        obj = gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree), node );
                if( obj == NULL ) 
-                       return;
-                       
-               
-               
-               person = ( ItemPerson * )dragged_person;
-               
+                       goto free_list;
+                               
                if (obj->type == ADDR_ITEM_FOLDER) {
                        afolder = ADAPTER_FOLDER(obj)->itemFolder;
 
                } else if (obj->type == ADDR_DATASOURCE) {
                        ads = ADAPTER_DSOURCE(obj);
                        if( ads == NULL ) 
-                               return;
+                               goto free_list;
                        ds = ads->dataSource;
                        if( ds == NULL ||
                            ds->type == ADDR_IF_JPILOT || 
                            ds->type == ADDR_IF_LDAP) 
-                               return;         
+                               goto free_list;         
                        afolder = addrindex_ds_get_root_folder( ds );
-                       
                } else {
-                       return;
+                       goto free_list;
                }
 
                ofolder = dragged_folder;
@@ -4716,10 +4831,20 @@ static void addressbook_drag_received_cb(GtkWidget        *widget,
                if (afolder && ofolder) {
                        AddressBookFile *obook = dragged_ab;
                        AddressBookFile *abook = addressbook_get_book_file_for_node(node);
-                       addritem_folder_remove_person(ofolder, person);
-                       addritem_folder_add_person(afolder, person);
+                       for (cur = dragged_persons; cur; cur = cur->next) {
+                               AddrBookBase *adbase = ( AddrBookBase * ) ds ? ds->rawDataSource : NULL;
+                               AddressCache *cache = (adbase) ? adbase->addressCache : NULL;
+
+                               person = (ItemPerson *)cur->data;
+                               addritem_folder_remove_person(ofolder, person);
+                               if (cache) {
+                                       addrcache_folder_add_person(cache, afolder, person);
+                               } else {
+                                       addritem_folder_add_person(afolder, person);
+                               }
+                       }
                        addressbook_list_select_clear();
-                       gtk_ctree_select( GTK_CTREE(addrbook.ctree), addrbook.opened);
+                       gtk_sctree_select( GTK_SCTREE(addrbook.ctree), addrbook.opened);
                                                        
                        if (abook) {
                                addrbook_set_dirty(abook, TRUE);
@@ -4733,6 +4858,9 @@ static void addressbook_drag_received_cb(GtkWidget        *widget,
 
                gtk_drag_finish(drag_context, TRUE, TRUE, time);
        }
+free_list:
+       g_slist_free(dragged_persons);
+       dragged_persons = NULL;
 }
 
 /*