/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
*
- * Copyright (c) 2000-2003 by Alfons Hoogervorst <alfons@proteus.demon.nl>
+ * Copyright (C) 2000-2004 by Alfons Hoogervorst & 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
# include <wctype.h>
#endif
-#include "addressbook.h"
+#include "addrindex.h"
#include "addr_compl.h"
#include "utils.h"
#include <pthread.h>
* any of those words).
*/
-/**
- * Reference to address index.
- */
-static AddressIndex *_addressIndex_ = NULL;
-
/**
* address_entry - structure which refers to the original address entry in the
* address book .
* \return <code>0</code> if entry appended successfully, or <code>-1</code>
* if failure.
*/
-static gint add_address(const gchar *name, const gchar *address, const gchar *alias)
+static gint add_address(const gchar *name, const gchar *address,
+ const gchar *nick, const gchar *alias)
{
address_entry *ae;
add_address1(name, ae);
add_address1(address, ae);
- add_address1(alias, ae);
+
+ if (nick != NULL)
+ add_address1(nick, ae);
+
+ if ( alias != NULL ) {
+ add_address1(alias, ae);
+ }
return 0;
}
* Read address book, creating all entries in the completion index.
*/
static void read_address_book(void) {
- addrindex_load_completion( _addressIndex_, add_address );
+ addrindex_load_completion( add_address );
g_address_list = g_list_reverse(g_address_list);
g_completion_list = g_list_reverse(g_completion_list);
}
* \param cw Window to destroy.
*/
static void addrcompl_destroy_window( CompletionWindow *cw ) {
+ /* Stop all searches currently in progress */
+ addrindex_stop_search( _queryID_ );
+
/* Remove idler function... or application may not terminate */
if( _completionIdleID_ != 0 ) {
gtk_idle_remove( _completionIdleID_ );
/* Get current geometry of window */
gdk_window_get_geometry( cw->window->window, &x, &y, &width, &height, &depth );
- gtk_widget_size_request( cw->clist, &r );
- gtk_widget_set_size_request( cw->window, width, r.height );
+ gtk_widget_hide_all( cw->window );
gtk_widget_show_all( cw->window );
gtk_widget_size_request( cw->clist, &r );
/* Adjust window height to available screen space */
if( ( y + r.height ) > gdk_screen_height() ) {
- gtk_window_set_policy( GTK_WINDOW( cw->window ), TRUE, FALSE, FALSE );
+ gtk_window_set_resizable(GTK_WINDOW(cw->window), FALSE);
gtk_widget_set_size_request( cw->window, width, gdk_screen_height() - y );
- }
+ } else
+ gtk_widget_set_size_request(cw->window, width, r.height);
}
/**
static gboolean addrcompl_idle( gpointer data ) {
GList *node;
gchar *address;
- CompletionWindow *cw;
/* Process all entries in display queue */
pthread_mutex_lock( & _completionMutex_ );
if( _displayQueue_ ) {
- cw = data;
node = _displayQueue_;
while( node ) {
address = node->data;
/* printf( "address ::: %s :::\n", address ); */
- addrcompl_add_entry( cw, address );
+ addrcompl_add_entry( _compWindow_, address );
g_free( address );
node = g_list_next( node );
}
/**
* Callback entry point. The background thread (if any) appends the address
* list to the display queue.
+ * \param sender Sender of query.
* \param queryID Query ID of search request.
* \param listEMail List of zero of more email objects that met search
* criteria.
- * \param target Target object to received data.
+ * \param data Query data.
*/
-static gint addrcompl_callback(
- gint queryID, GList *listEMail, gpointer target )
+static gint addrcompl_callback_entry(
+ gpointer sender, gint queryID, GList *listEMail, gpointer data )
{
GList *node;
gchar *address;
- /* printf( "addrcompl_callback::queryID=%d\n", queryID ); */
+ /* printf( "addrcompl_callback_entry::queryID=%d\n", queryID ); */
pthread_mutex_lock( & _completionMutex_ );
- if( target ) {
- if( queryID == _queryID_ ) {
- /* Append contents to end of display queue */
- node = listEMail;
- while( node ) {
- ItemEMail *email = node->data;
-
- address = addritem_format_email( email );
- /* printf( "\temail/address ::%s::\n", address ); */
- _displayQueue_ = g_list_append( _displayQueue_, address );
- node = g_list_next( node );
- }
+ if( queryID == _queryID_ ) {
+ /* Append contents to end of display queue */
+ node = listEMail;
+ while( node ) {
+ ItemEMail *email = node->data;
+
+ address = addritem_format_email( email );
+ /* printf( "\temail/address ::%s::\n", address ); */
+ _displayQueue_ = g_list_append( _displayQueue_, address );
+ node = g_list_next( node );
}
}
+ g_list_free( listEMail );
pthread_mutex_unlock( & _completionMutex_ );
- /* printf( "addrcompl_callback...done\n" ); */
return 0;
}
/**
* Load list with entries from local completion index.
- * \param cw Completion window.
*/
-static void addrcompl_load_local( CompletionWindow *cw ) {
+static void addrcompl_load_local( void ) {
guint count = 0;
for (count = 0; count < get_completion_count(); count++) {
/* Setup the search */
_queryID_ = addrindex_setup_search(
- _addressIndex_, searchTerm, _compWindow_, addrcompl_callback );
+ searchTerm, NULL, addrcompl_callback_entry );
g_free( searchTerm );
/* printf( "addrcompl_start_search::queryID=%d\n", _queryID_ ); */
/* Load local stuff */
- addrcompl_load_local( _compWindow_ );
+ addrcompl_load_local();
/* Sit back and wait until something happens */
_completionIdleID_ =
- gtk_idle_add( ( GtkFunction ) addrcompl_idle, _compWindow_ );
+ gtk_idle_add( ( GtkFunction ) addrcompl_idle, NULL );
/* printf( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
- addrindex_start_search( _addressIndex_, _queryID_ );
+ addrindex_start_search( _queryID_ );
}
/**
/* add keypress event */
g_signal_connect_closure
- (GTK_OBJECT(entry), "key_press_event",
+ (G_OBJECT(entry), "key_press_event",
g_cclosure_new(G_CALLBACK(address_completion_entry_key_pressed),
COMPLETION_UNIQUE_DATA,
NULL),
entry_obj = g_object_get_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
g_return_if_fail(entry_obj);
- g_return_if_fail(entry_obj == GTK_OBJECT(entry));
+ g_return_if_fail(entry_obj == G_OBJECT(entry));
/* has the hooked property? */
g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
g_free( new );
}
+ /* Select the address if there is only one match */
+ if (ncount == 2) {
+ /* Display selected address in entry field */
+ gchar *addr = get_complete_address(1);
+
+ if (addr) {
+ replace_address_in_edit(entry, addr, cursor_pos);
+ g_free(addr);
+ }
+
+ /* Discard the window */
+ clear_completion_cache();
+ }
/* Make sure that drop-down appears uniform! */
- if( ncount == 0 ) {
+ else if( ncount == 0 ) {
addrcompl_add_queue( g_strdup( searchTerm ) );
}
g_free( searchTerm );
/**
* Setup completion object.
- * \param addrIndex Address index object.
*/
-void addrcompl_initialize( AddressIndex *addrIndex ) {
- g_return_if_fail( addrIndex != NULL );
- _addressIndex_ = addrIndex;
-
+void addrcompl_initialize( void ) {
/* printf( "addrcompl_initialize...\n" ); */
if( ! _compWindow_ ) {
_compWindow_ = addrcompl_create_window();
}
_displayQueue_ = NULL;
_completionIdleID_ = 0;
- _addressIndex_ = NULL;
/* printf( "addrcompl_teardown...done\n" ); */
}