2008-06-13 [wwp] 3.4.0cvs92
[claws.git] / src / editgroup.c
index 9a21375640e94e9f684a62dadfa7377e5125b4d0..aa4464e65b537e58a6624b67900294e6a3c2ef97 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * 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.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -24,9 +24,9 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 
-#include "intl.h"
 #include "addressbook.h"
 #include "addressitem.h"
 #include "addrbook.h"
@@ -44,9 +44,6 @@
 #define ADDRESSBOOK_GUESS_FOLDER_NAME  "NewFolder"
 #define ADDRESSBOOK_GUESS_GROUP_NAME   "NewGroup"
 
-#define EDITGROUP_WIDTH      580
-#define EDITGROUP_HEIGHT     340
-
 typedef enum {
        GROUP_COL_NAME    = 0,
        GROUP_COL_EMAIL   = 1,
@@ -104,7 +101,7 @@ static void edit_group_ok(GtkWidget *widget, gboolean *cancelled) {
        }
        g_free( sName );
 }
-       
+
 static void edit_group_cancel(GtkWidget *widget, gboolean *cancelled) {
        *cancelled = TRUE;
        gtk_main_quit();
@@ -116,11 +113,12 @@ static gint edit_group_delete_event(GtkWidget *widget, GdkEventAny *event, gbool
        return TRUE;
 }
 
-static void edit_group_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
+static gboolean edit_group_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
        if (event && event->keyval == GDK_Escape) {
                *cancelled = TRUE;
                gtk_main_quit();
        }
+       return FALSE;
 }
 
 static gchar *edit_group_format_item_clist( ItemPerson *person, ItemEMail *email ) {
@@ -142,13 +140,14 @@ static gint edit_group_clist_add_email( GtkCList *clist, ItemEMail *email ) {
        gchar *text[ GROUP_N_COLS ];
        gint row;
        if( str ) {
-               text[ GROUP_COL_NAME ] = str;
+               text[ GROUP_COL_NAME ] = addressbook_set_col_name_guard(str);
        }
        else {
-               text[ GROUP_COL_NAME ] = ADDRITEM_NAME(person);
+               text[ GROUP_COL_NAME ] = addressbook_set_col_name_guard(ADDRITEM_NAME(person));
        }
        text[ GROUP_COL_EMAIL   ] = email->address;
        text[ GROUP_COL_REMARKS ] = email->remarks;
+
        row = gtk_clist_append( clist, text );
        gtk_clist_set_row_data( clist, row, email );
        return row;
@@ -156,63 +155,83 @@ static gint edit_group_clist_add_email( GtkCList *clist, ItemEMail *email ) {
 
 static void edit_group_load_clist( GtkCList *clist, GList *listEMail ) {
        GList *node = listEMail;
+       gtk_clist_freeze(clist);
        while( node ) {
                ItemEMail *email = node->data;
                edit_group_clist_add_email( clist, email );
                node = g_list_next( node );
        }
+       gtk_clist_thaw(clist);
 }
 
 
-static gint edit_group_move_email( GtkCList *clist_from, GtkCList *clist_to, gint row ) {
-       ItemEMail *email = gtk_clist_get_row_data( clist_from, row );
-       gint rrow = -1;
+static void edit_group_move_email( GtkCList *clist_from, GtkCList *clist_to, GtkCTreeNode *node ) {
+       ItemEMail *email = gtk_ctree_node_get_row_data( GTK_CTREE(clist_from), node );
+       GtkCTreeNode *next = gtkut_ctree_node_next(GTK_CTREE(clist_from), node);
+       GtkCTreeNode *prev = gtkut_ctree_node_prev(GTK_CTREE(clist_from), node);
+       int rrow = 0;
        if( email ) {
-               gtk_clist_remove( clist_from, row );
+               gtk_ctree_remove_node(GTK_CTREE(clist_from), node);
                rrow = edit_group_clist_add_email( clist_to, email );
                gtk_clist_select_row( clist_to, rrow, 0 );
+               if (next)
+                       gtk_ctree_select(GTK_CTREE(clist_from), next);
+               else if (prev)
+                       gtk_ctree_select(GTK_CTREE(clist_from), prev);
        }
-       return rrow;
 }
 
 static void edit_group_to_group( GtkWidget *widget, gpointer data ) {
-       GList *selected = GTK_CLIST(groupeditdlg.clist_avail)->selection;
+       GList *selected = g_list_copy(GTK_CLIST(groupeditdlg.clist_avail)->selection);
        /* Clear the selected rows on destination clist */
+       gtk_clist_freeze(groupeditdlg.clist_avail);
+       gtk_clist_freeze(groupeditdlg.clist_group);
        gtk_clist_unselect_all(groupeditdlg.clist_group);
        while (selected) {
                edit_group_move_email( groupeditdlg.clist_avail,
-                                       groupeditdlg.clist_group, GPOINTER_TO_UINT(selected->data) );
-               /* cannot use g_list_next as the selection list will have changed */
-               selected = GTK_CLIST(groupeditdlg.clist_avail)->selection;
+                                       groupeditdlg.clist_group, GTK_CTREE_NODE(selected->data) );
+               selected = selected->next;
        }
+       g_list_free(selected);
+       gtk_clist_thaw(groupeditdlg.clist_avail);
+       gtk_clist_thaw(groupeditdlg.clist_group);
 }
 
 static void edit_group_to_avail( GtkWidget *widget, gpointer data ) {
-       GList *selected = GTK_CLIST(groupeditdlg.clist_group)->selection;
+       GList *selected = g_list_copy(GTK_CLIST(groupeditdlg.clist_group)->selection);
+       gtk_clist_freeze(groupeditdlg.clist_avail);
+       gtk_clist_freeze(groupeditdlg.clist_group);
        gtk_clist_unselect_all(groupeditdlg.clist_avail);
        while (selected) {
                edit_group_move_email( groupeditdlg.clist_group,
-                                       groupeditdlg.clist_avail, GPOINTER_TO_UINT(selected->data) );
-               selected = GTK_CLIST(groupeditdlg.clist_group)->selection;
+                                       groupeditdlg.clist_avail, GTK_CTREE_NODE(selected->data) );
+               selected = selected->next;
        }
+       g_list_free(selected);
+       gtk_clist_thaw(groupeditdlg.clist_avail);
+       gtk_clist_thaw(groupeditdlg.clist_group);
 }
 
-static void edit_group_list_group_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
-       if( ! event ) return;
+static gboolean edit_group_list_group_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
+       if( ! event ) return FALSE;
+
        if( event->button == 1 ) {
                if( event->type == GDK_2BUTTON_PRESS ) {
                        edit_group_to_avail( NULL, NULL );
                }
        }
+       return FALSE;
 }
 
-static void edit_group_list_avail_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
-       if( ! event ) return;
+static gboolean edit_group_list_avail_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
+       if( ! event ) return FALSE;
+
        if( event->button == 1 ) {
                if( event->type == GDK_2BUTTON_PRESS ) {
                        edit_group_to_group( NULL, NULL );
                }
        }
+       return FALSE;
 }
 
 static gint edit_group_list_compare_func( GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 ) {
@@ -223,7 +242,16 @@ static gint edit_group_list_compare_func( GtkCList *clist, gconstpointer ptr1, g
        if( cell2 ) name2 = cell2->u.text;
        if( ! name1 ) return ( name2 != NULL );
        if( ! name2 ) return -1;
-       return strcasecmp( name1, name2 );
+       return g_utf8_collate( name1, name2 );
+}
+
+static void addressbook_edit_group_size_allocate_cb(GtkWidget *widget,
+                                        GtkAllocation *allocation)
+{
+       g_return_if_fail(allocation != NULL);
+
+       prefs_common.addressbookeditgroupwin_width = allocation->width;
+       prefs_common.addressbookeditgroupwin_height = allocation->height;
 }
 
 static void addressbook_edit_group_create( gboolean *cancelled ) {
@@ -254,22 +282,25 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        gchar *titles[ GROUP_N_COLS ];
        gint i;
 
+       static GdkGeometry geometry;
+
        titles[ GROUP_COL_NAME    ] = _( "Name" );
-       titles[ GROUP_COL_EMAIL   ] = _("E-Mail Address");
+       titles[ GROUP_COL_EMAIL   ] = _("Email Address");
        titles[ GROUP_COL_REMARKS ] = _("Remarks");
 
-       window = gtk_window_new(GTK_WINDOW_DIALOG);
-       gtk_widget_set_usize(window, EDITGROUP_WIDTH, EDITGROUP_HEIGHT );
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editgroup");
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
        gtk_window_set_title(GTK_WINDOW(window), _("Edit Group Data"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
-       gtk_signal_connect(GTK_OBJECT(window), "delete_event",
-                          GTK_SIGNAL_FUNC(edit_group_delete_event),
-                          cancelled);
-       gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
-                          GTK_SIGNAL_FUNC(edit_group_key_pressed),
-                          cancelled);
+       gtk_window_set_modal(GTK_WINDOW(window), TRUE);
+       g_signal_connect(G_OBJECT(window), "delete_event",
+                        G_CALLBACK(edit_group_delete_event),
+                        cancelled);
+       g_signal_connect(G_OBJECT(window), "key_press_event",
+                        G_CALLBACK(edit_group_key_pressed),
+                        cancelled);
+       g_signal_connect(G_OBJECT(window), "size_allocate",
+                        G_CALLBACK(addressbook_edit_group_size_allocate_cb), NULL);
 
        vbox = gtk_vbox_new( FALSE, 6 );
        gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH);
@@ -310,17 +341,27 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
        label = gtk_label_new(_("Addresses in Group"));
        gtk_box_pack_start(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
-       buttonAvail = gtk_button_new_with_label( _( " -> " ) );
+       buttonAvail = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
        gtk_box_pack_end(GTK_BOX(hboxh), buttonAvail, FALSE, FALSE, 0);
 
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
        gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
                                       GTK_POLICY_AUTOMATIC,
-                                      GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_AUTOMATIC);
 
-       clist_group = gtk_clist_new_with_titles( GROUP_N_COLS, titles );
+       clist_group = gtk_sctree_new_with_titles( GROUP_N_COLS, GROUP_N_COLS, titles );
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_group );
+       if (prefs_common.enable_dotted_lines) {
+               gtk_ctree_set_line_style(GTK_CTREE(clist_group), GTK_CTREE_LINES_DOTTED);
+               gtk_ctree_set_expander_style(GTK_CTREE(clist_group),
+                                    GTK_CTREE_EXPANDER_SQUARE);
+       } else {
+               gtk_ctree_set_line_style(GTK_CTREE(clist_group), GTK_CTREE_LINES_NONE);
+               gtk_ctree_set_expander_style(GTK_CTREE(clist_group),
+                                    GTK_CTREE_EXPANDER_TRIANGLE);
+       }
+       gtk_sctree_set_stripes(GTK_SCTREE(clist_group), prefs_common.use_stripes_in_summaries);
        gtk_clist_set_selection_mode( GTK_CLIST(clist_group), GTK_SELECTION_EXTENDED );
        gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
        gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_EMAIL, GROUP_COL_WIDTH_EMAIL );
@@ -337,7 +378,7 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        hboxh = gtk_hbox_new( FALSE, 0 );
        gtk_container_set_border_width( GTK_CONTAINER(hboxh), 4 );
        gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
-       buttonGroup = gtk_button_new_with_label( _( " <- " ) );
+       buttonGroup = gtk_button_new_from_stock(GTK_STOCK_ADD);
        gtk_box_pack_start(GTK_BOX(hboxh), buttonGroup, FALSE, FALSE, 0);
        label = gtk_label_new(_("Available Addresses"));
        gtk_box_pack_end(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
@@ -346,9 +387,9 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
                                       GTK_POLICY_AUTOMATIC,
-                                      GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_AUTOMATIC);
 
-       clist_avail = gtk_clist_new_with_titles( GROUP_N_COLS, titles );
+       clist_avail = gtk_sctree_new_with_titles( GROUP_N_COLS, GROUP_N_COLS, titles );
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_avail );
        gtk_clist_set_selection_mode( GTK_CLIST(clist_avail), GTK_SELECTION_EXTENDED );
        gtk_clist_set_column_width( GTK_CLIST(clist_avail), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
@@ -366,27 +407,39 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
 
        /* Button panel */
-       gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
-                               &cancel_btn, _("Cancel"), NULL, NULL);
+       gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
+                                     &ok_btn, GTK_STOCK_OK,
+                                     NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_btn);
 
-       gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
-                          GTK_SIGNAL_FUNC(edit_group_ok), cancelled);
-       gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
-                          GTK_SIGNAL_FUNC(edit_group_cancel), cancelled);
+       g_signal_connect(G_OBJECT(ok_btn), "clicked",
+                        G_CALLBACK(edit_group_ok), cancelled);
+       g_signal_connect(G_OBJECT(cancel_btn), "clicked",
+                        G_CALLBACK(edit_group_cancel), cancelled);
 
        gtk_widget_show_all(vbox);
 
        /* Event handlers */
-       gtk_signal_connect( GTK_OBJECT(buttonGroup), "clicked",
-                       GTK_SIGNAL_FUNC( edit_group_to_group ), NULL );
-       gtk_signal_connect( GTK_OBJECT(buttonAvail), "clicked",
-                       GTK_SIGNAL_FUNC( edit_group_to_avail ), NULL );
-       gtk_signal_connect(GTK_OBJECT(clist_avail), "button_press_event",
-                          GTK_SIGNAL_FUNC(edit_group_list_avail_button), NULL);
-       gtk_signal_connect(GTK_OBJECT(clist_group), "button_press_event",
-                          GTK_SIGNAL_FUNC(edit_group_list_group_button), NULL);
+       g_signal_connect( G_OBJECT(buttonGroup), "clicked",
+                         G_CALLBACK( edit_group_to_group ), NULL );
+       g_signal_connect( G_OBJECT(buttonAvail), "clicked",
+                         G_CALLBACK( edit_group_to_avail ), NULL );
+       g_signal_connect(G_OBJECT(clist_avail), "button_press_event",
+                        G_CALLBACK(edit_group_list_avail_button), NULL);
+       g_signal_connect(G_OBJECT(clist_group), "button_press_event",
+                        G_CALLBACK(edit_group_list_group_button), NULL);
+
+       if (!geometry.min_height) {
+               geometry.min_width = 580;
+               geometry.min_height = 340;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(window,
+                                       prefs_common.addressbookeditgroupwin_width,
+                                   prefs_common.addressbookeditgroupwin_height);
 
        groupeditdlg.window     = window;
        groupeditdlg.ok_btn     = ok_btn;
@@ -399,7 +452,7 @@ static void addressbook_edit_group_create( gboolean *cancelled ) {
        groupeditdlg.clist_avail = GTK_CLIST( clist_avail );
 
        if( ! _edit_group_dfl_message_ ) {
-               _edit_group_dfl_message_ = _( "Move E-Mail Addresses to or from Group with arrow buttons" );
+               _edit_group_dfl_message_ = _( "Move Email Addresses to or from Group with arrow buttons" );
        }
 }