/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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
N_LIST_COLS = 3
} AddressListColumns;
+static gchar *list_titles[] = { N_("Name"),
+ N_("Email Address"),
+ N_("Remarks") };
+
#define COL_NAME_WIDTH 164
#define COL_ADDRESS_WIDTH 156
GList *node,
gpointer *data );
-#if 0
-static void addressbook_entry_changed (GtkWidget *widget);
-#endif
-
static gboolean addressbook_list_button_pressed (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
static gint addressbook_treenode_compare_func (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2);
-static gint addressbook_list_compare_func (GtkCList *clist,
- gconstpointer ptr1,
- gconstpointer ptr2);
static void addressbook_folder_load_one_person (GtkCTree *clist,
ItemPerson *person,
AddressTypeControlItem *atci,
static GtkTargetEntry addressbook_drag_types[] =
{
- {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
+ {"sylpheed-claws/internal", GTK_TARGET_SAME_APP, TARGET_DUMMY}
};
static GtkTargetList *addressbook_target_list = NULL;
prefs_common.addressbookwin_height = allocation->height;
}
+static gint list_case_sort(
+ GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
+{
+ GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
+ GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
+ 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 );
+}
+
+static void addressbook_sort_list(GtkCList *clist, const gint col,
+ const GtkSortType sort_type)
+{
+ gint pos;
+ GtkWidget *hbox, *label, *arrow;
+
+ gtk_clist_set_compare_func(clist, list_case_sort);
+ gtk_clist_set_sort_type(clist, sort_type);
+ gtk_clist_set_sort_column(clist, col);
+
+ gtk_clist_freeze(clist);
+ gtk_clist_sort(clist);
+
+ for(pos = 0 ; pos < N_LIST_COLS ; pos++) {
+ hbox = gtk_hbox_new(FALSE, 4);
+ label = gtk_label_new(list_titles[pos]);
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+ if(pos == col) {
+ arrow = gtk_arrow_new(sort_type == GTK_SORT_ASCENDING ?
+ GTK_ARROW_DOWN : GTK_ARROW_UP, GTK_SHADOW_IN);
+ gtk_box_pack_end(GTK_BOX(hbox), arrow, FALSE, FALSE, 0);
+ }
+
+ gtk_widget_show_all(hbox);
+ gtk_clist_set_column_widget(clist, pos, hbox);
+ }
+
+ gtk_clist_thaw(clist);
+}
+
+static void addressbook_name_clicked(GtkWidget *button, GtkCList *clist)
+{
+ static GtkSortType sort_type = GTK_SORT_ASCENDING;
+
+ sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
+ GTK_SORT_ASCENDING;
+ addressbook_sort_list(clist, COL_NAME, sort_type);
+}
+
+static void addressbook_address_clicked(GtkWidget *button, GtkCList *clist)
+{
+ static GtkSortType sort_type = GTK_SORT_ASCENDING;
+
+ sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
+ GTK_SORT_ASCENDING;
+ addressbook_sort_list(clist, COL_ADDRESS, sort_type);
+}
+
+static void addressbook_remarks_clicked(GtkWidget *button, GtkCList *clist)
+{
+ static GtkSortType sort_type = GTK_SORT_ASCENDING;
+
+ sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING :
+ GTK_SORT_ASCENDING;
+ addressbook_sort_list(clist, COL_REMARKS, sort_type);
+}
+
/*
* 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.
GList *nodeIf;
gchar *index_titles[N_INDEX_COLS];
- gchar *list_titles[N_LIST_COLS];
gchar *text;
gint i;
debug_print("Creating addressbook window...\n");
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);
COL_NAME_WIDTH);
gtk_clist_set_column_width(GTK_CLIST(clist), COL_ADDRESS,
COL_ADDRESS_WIDTH);
- gtk_clist_set_compare_func(GTK_CLIST(clist),
- addressbook_list_compare_func);
+ addressbook_sort_list(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),
+ "clicked", G_CALLBACK(addressbook_address_clicked), clist);
+ g_signal_connect(G_OBJECT(GTK_CLIST(clist)->column[COL_REMARKS].button),
+ "clicked", G_CALLBACK(addressbook_remarks_clicked), clist);
+
for (i = 0; i < N_LIST_COLS; i++)
GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
GTK_CAN_FOCUS);
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);
-#endif
-
paned = gtk_hpaned_new();
gtk_box_pack_start(GTK_BOX(vbox2), paned, TRUE, TRUE, 0);
gtk_paned_add1(GTK_PANED(paned), ctree_swin);
addrbookctl_build_iflist();
addrbookctl_build_ifselect();
+ addrbook.clist = NULL;
+
/* Add each interface into the tree as a root level folder */
nodeIf = _addressInterfaceList_;
while( nodeIf ) {
/* Confirm deletion */
aval = alertpanel( _("Delete address(es)"),
_("Really delete the address(es)?"),
- GTK_STOCK_YES, GTK_STOCK_NO, NULL );
- if( aval != G_ALERTDEFAULT ) return;
+ GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
+ if( aval != G_ALERTALTERNATE ) return;
/* Process deletions */
if( pobj->type == ADDR_DATASOURCE || pobj->type == ADDR_ITEM_FOLDER ) {
addrindex_ds_set_access_flag( ds, &tVal );
gtk_ctree_expand( ctree, node );
}
+ } else {
+ addressbook_set_clist(NULL, TRUE);
}
/* Update address list */
}
-#if 0
-/**
- * Paste clipboard email addresses only into address list widget.
- */
-static void addressbook_clip_paste_address_cb( void ) {
- GtkCTree *clist = GTK_CTREE(addrbook.clist);
- GtkCTree *ctree;
- AddressObject *pobj = NULL;
- AddressDataSource *ds = NULL;
- AddressBookFile *abf = NULL;
- ItemFolder *folder = NULL;
- AddrItemObject *aio;
- gint cnt;
-
- if( addrbook.listSelected == NULL ) return;
-
- ctree = GTK_CTREE( addrbook.ctree );
- ds = addressbook_find_datasource( GTK_CTREE_NODE(addrbook.treeSelected) );
- if( ds == NULL ) return;
- if( addrindex_ds_get_readonly( ds ) ) {
- addressbook_ds_status_message(
- ds, _( "Cannot paste. Target address book is readonly." ) );
- return;
- }
-
- pobj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
- if( pobj ) {
- if( pobj->type == ADDR_ITEM_FOLDER ) {
- folder = ADAPTER_FOLDER(pobj)->itemFolder;
- }
- }
-
- abf = addressbook_get_book_file();
- if( abf == NULL ) return;
-
- cnt = 0;
- aio = gtk_ctree_node_get_row_data( clist, addrbook.listSelected );
- if( aio->type == ADDR_ITEM_PERSON ) {
- ItemPerson *person;
-
- person = ( ItemPerson * ) aio;
- if( _clipBoard_->cutFlag ) {
- /* Paste/Cut */
- cnt = addrclip_paste_person_cut( _clipBoard_, abf, person );
-
- /* Remove all "cut" items */
- addrclip_delete_address( _clipBoard_ );
-
- /* Clear clipboard */
- addrclip_clear( _clipBoard_ );
- }
- else {
- /* Paste/Copy */
- cnt = addrclip_paste_person_copy( _clipBoard_, abf, person );
- }
- if( cnt > 0 ) {
- addritem_person_set_opened( person, TRUE );
- }
- }
-
- /* Display items pasted */
- if( cnt > 0 ) {
- gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened );
- addressbook_set_clist(
- gtk_ctree_node_get_row_data(GTK_CTREE(addrbook.ctree),
- addrbook.opened),
- TRUE);
- }
-}
-#endif
-
/**
* Add current treenode object to clipboard. Note that widget only allows
* one entry from the tree list to be selected.
"results and addresses in '%s' ?" ),
obj->name );
aval = alertpanel( _("Delete"), message,
- GTK_STOCK_YES, GTK_STOCK_NO, NULL );
+ GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL );
g_free(message);
- if( aval == G_ALERTDEFAULT ) {
+ if( aval == G_ALERTALTERNATE ) {
delType = ADDRTREE_DEL_FOLDER_ADDR;
}
}
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." ),
+ ( _( "Do you want to delete '%s' ?"
+ "If you delete the folder only, the addresses it contains will be moved into the parent folder." ),
obj->name );
aval = alertpanel( _("Delete folder"), message,
- _("_Folder only"), _("Folder and _addresses"),
- GTK_STOCK_CANCEL );
+ GTK_STOCK_CANCEL, _("+Delete _folder only"), _("Delete folder and _addresses"));
g_free(message);
- if( aval == G_ALERTDEFAULT ) {
+ if( aval == G_ALERTALTERNATE ) {
delType = ADDRTREE_DEL_FOLDER_ONLY;
}
- else if( aval == G_ALERTALTERNATE ) {
+ else if( aval == G_ALERTOTHER ) {
delType = ADDRTREE_DEL_FOLDER_ADDR;
}
}
}
else {
- message = g_strdup_printf(_("Really delete '%s' ?"), obj->name);
- aval = alertpanel(_("Delete"), message, GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+ message = g_strdup_printf(_("Do you want to delete '%s'?\n"
+ "The addresses it contains will be lost."), obj->name);
+ aval = alertpanel(_("Delete"), message, GTK_STOCK_CANCEL,
+ "+" GTK_STOCK_DELETE, NULL);
g_free(message);
- if( aval == G_ALERTDEFAULT ) delType = ADDRTREE_DEL_DATA;
+ if( aval == G_ALERTALTERNATE ) delType = ADDRTREE_DEL_DATA;
}
if( delType == ADDRTREE_DEL_NONE ) return;
AdapterDSource *ads = NULL;
static AddressObject *last_obj = NULL;
+ if (addrbook.clist == NULL) {
+ return;
+ }
if (obj == last_obj && !refresh)
return;
}
else {
msg = _("Old address book converted,\n"
- "could not save new address index file" );
+ "could not save new address index file." );
}
}
else {
}
else {
msg = _("Could not convert address book,\n"
- "could not create new address book files." );
+ "could not save new address index file." );
}
}
else {
return g_utf8_collate( name1, name2 );
}
-/*
-* Comparison using object names and types.
-*/
-static gint addressbook_list_compare_func(
- GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
-{
- AddrItemObject *aio1 = ((GtkCListRow *)ptr1)->data;
- AddrItemObject *aio2 = ((GtkCListRow *)ptr2)->data;
- gchar *name1 = NULL, *name2 = NULL;
-
- /* Order by cell contents */
- name1 = ADDRITEM_NAME( aio1 );
- name2 = ADDRITEM_NAME( aio2 );
-
- if( aio1->type == aio2->type ) {
- /* Order by name */
- if( ! name1 ) return ( name2 != NULL );
- if( ! name2 ) return -1;
- return g_utf8_collate( name1, name2 );
- }
- else {
- /* Order groups before person */
- if( aio1->type == ITEMTYPE_GROUP ) {
- return -1;
- }
- else if( aio2->type == ITEMTYPE_GROUP ) {
- return 1;
- }
- return 0;
- }
-}
-
static void addressbook_new_book_cb( gpointer data, guint action, GtkWidget *widget ) {
AdapterDSource *ads;
AdapterInterface *adapter;
}
}
-#if 0
-void addrbookctl_free_selection( GList *list ) {
- GList *node = list;
- while( node ) {
- AdapterInterface *adapter = node->data;
- adapter = NULL;
- node = g_list_next( node );
- }
- g_list_free( list );
-}
-#endif
-
/**
* Find GUI interface type specified interface type.
* \param ifType Interface type.