2006-04-06 [colin] 2.1.0cvs5
[claws.git] / src / addressbook.c
index 159072f8ff318f53c4193159811d0124b5f9f8d9..42a58f35ca620bf897c60bb697c4d8ac6c1fa61a 100644 (file)
@@ -682,18 +682,35 @@ static void addressbook_size_allocate_cb(GtkWidget *widget,
        prefs_common.addressbookwin_height = allocation->height;
 }
 
+static gint sort_column_number = 0;
+static GtkSortType sort_column_type = GTK_SORT_ASCENDING;
+
 static gint list_case_sort(
        GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
 {
-       GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
-       GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
+       GtkCListRow *row1 = (GtkCListRow *) ptr1;
+       GtkCListRow *row2 = (GtkCListRow *) ptr2;
        gchar *name1 = NULL, *name2 = NULL;
-
-       if( cell1 ) name1 = cell1->u.text;
-       if( cell2 ) name2 = cell2->u.text;
-       if( ! name1 ) return ( name2 != NULL );
-       if( ! name2 ) return -1;
-       return strcasecmp( name1, name2 );
+       AddrItemObject *aio1 = ((GtkCListRow *)ptr1)->data;
+       AddrItemObject *aio2 = ((GtkCListRow *)ptr2)->data;
+
+       if( aio1->type == aio2->type ) {
+               if( row1 ) 
+                       name1 = GTK_CELL_TEXT (row1->cell[sort_column_number])->text;
+               if( row2 ) 
+                       name2 = GTK_CELL_TEXT (row2->cell[sort_column_number])->text;
+               if( ! name1 ) return ( name2 != NULL );
+               if( ! name2 ) return -1;
+               return strcasecmp( name1, name2 );
+       } else {
+               /* Order groups before person */
+               if( aio1->type == ITEMTYPE_GROUP ) {
+                       return (sort_column_type==GTK_SORT_ASCENDING) ? -1:+1;
+               } else if( aio2->type == ITEMTYPE_GROUP ) {
+                       return (sort_column_type==GTK_SORT_ASCENDING) ? +1:-1;
+               }
+               return 0;
+       }
 }
 
 static void addressbook_sort_list(GtkCList *clist, const gint col,
@@ -702,6 +719,8 @@ static void addressbook_sort_list(GtkCList *clist, const gint col,
        gint pos;
        GtkWidget *hbox, *label, *arrow;
 
+       sort_column_number = col;
+       sort_column_type = sort_type;
        gtk_clist_set_compare_func(clist, list_case_sort);
        gtk_clist_set_sort_type(clist, sort_type);
        gtk_clist_set_sort_column(clist, col);  
@@ -711,7 +730,7 @@ static void addressbook_sort_list(GtkCList *clist, const gint col,
        
        for(pos = 0 ; pos < N_LIST_COLS ; pos++) {
                hbox = gtk_hbox_new(FALSE, 4);
-               label = gtk_label_new(list_titles[pos]);
+               label = gtk_label_new(gettext(list_titles[pos]));
                gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
                
                if(pos == col) {
@@ -905,7 +924,7 @@ static void addressbook_create(void)
        gtk_clist_set_column_width(GTK_CLIST(clist), COL_ADDRESS,
                                   COL_ADDRESS_WIDTH);
 
-       addressbook_sort_list(clist, COL_NAME, GTK_SORT_ASCENDING);
+       addressbook_sort_list(GTK_CLIST(clist), COL_NAME, GTK_SORT_ASCENDING);
        g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_NAME].button),
                "clicked", G_CALLBACK(addressbook_name_clicked), clist);
        g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_ADDRESS].button),
@@ -2917,7 +2936,7 @@ static void addressbook_folder_load_one_person(
 
        if( person == NULL ) return;
 
-       text[COL_NAME] = NULL;
+       text[COL_NAME] = "";
        node = person->listEMail;
        while( node ) {
                ItemEMail *email = node->data;
@@ -2964,8 +2983,8 @@ static void addressbook_folder_load_one_person(
        if( ! haveAddr ) {
                /* Have name without EMail */
                text[COL_NAME] = ADDRITEM_NAME(person);
-               text[COL_ADDRESS] = NULL;
-               text[COL_REMARKS] = NULL;
+               text[COL_ADDRESS] = "";
+               text[COL_REMARKS] = "";
                nodePerson = gtk_sctree_insert_node(
                                clist, NULL, NULL,
                                text, FOLDER_SPACING,
@@ -3052,8 +3071,8 @@ static void addressbook_folder_load_group( GtkCTree *clist, ItemFolder *itemFold
                ItemGroup *group = items->data;
                if( group == NULL ) continue;
                text[COL_NAME] = ADDRITEM_NAME(group);
-               text[COL_ADDRESS] = NULL;
-               text[COL_REMARKS] = NULL;
+               text[COL_ADDRESS] = "";
+               text[COL_REMARKS] = "";
                nodeGroup = gtk_sctree_insert_node(clist, NULL, NULL,
                                      text, FOLDER_SPACING,
                                      atci->iconXpm, atci->maskXpm,
@@ -4222,7 +4241,7 @@ void addrbookctl_build_map( GtkWidget *window ) {
        atci->showInTree = TRUE;
        atci->treeExpand = TRUE;
        atci->treeLeaf = FALSE;
-       atci->displayName = _( "LDAP Server" );
+       atci->displayName = _( "LDAP servers" );
        atci->iconXpm = ldapxpm;
        atci->maskXpm = ldapxpmmask;
        atci->iconXpmOpen = ldapxpm;