2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (C) 2000-2012 by Alfons Hoogervorst & The Claws Mail Team.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "claws-features.h"
28 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
34 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
39 #include "addr_compl.h"
42 #include "prefs_common.h"
46 #include "stock_pixmap.h"
49 #ifndef USE_NEW_ADDRBOOK
50 #include "addrindex.h"
52 #include "addressbook-dbus.h"
56 *\brief For the GtkListStore
69 * The address book is read into memory. We set up an address list
70 * containing all address book entries. Next we make the completion
71 * list, which contains all the completable strings, and store a
72 * reference to the address entry it belongs to.
73 * After calling the g_completion_complete(), we get a reference
74 * to a valid email address.
76 * Completion is very simplified. We never complete on another prefix,
77 * i.e. we neglect the next smallest possible prefix for the current
78 * completion cache. This is simply done so we might break up the
79 * addresses a little more (e.g. break up alfons@proteus.demon.nl into
80 * something like alfons, proteus, demon, nl; and then completing on
81 * any of those words).
85 * completion_entry - structure used to complete addresses, with a reference
86 * the the real address information.
90 gchar *string; /* string to complete */
91 address_entry *ref; /* address the string belongs to */
94 /*******************************************************************************/
96 static gint g_ref_count; /* list ref count */
97 static GList *g_completion_list = NULL; /* list of strings to be checked */
98 static GList *g_address_list = NULL; /* address storage */
99 static GCompletion *g_completion; /* completion object */
101 static GHashTable *_groupAddresses_ = NULL;
102 static gboolean _allowCommas_ = TRUE;
104 /* To allow for continuing completion we have to keep track of the state
105 * using the following variables. No need to create a context object. */
107 static gint g_completion_count; /* nr of addresses incl. the prefix */
108 static gint g_completion_next; /* next prev address */
109 static GSList *g_completion_addresses; /* unique addresses found in the
111 static gchar *g_completion_prefix; /* last prefix. (this is cached here
112 * because the prefix passed to g_completion
113 * is g_utf8_strdown()'ed */
115 static gchar *completion_folder_path = NULL;
117 /*******************************************************************************/
120 * Define the structure of the completion window.
122 typedef struct _CompletionWindow CompletionWindow;
123 struct _CompletionWindow {
128 GtkWidget *list_view;
130 gboolean in_mouse; /*!< mouse press pending... */
131 gboolean destroying; /*!< destruction in progress */
134 static GtkListStore *addr_compl_create_store (void);
136 static GtkWidget *addr_compl_list_view_create (CompletionWindow *window);
138 static void addr_compl_create_list_view_columns (GtkWidget *list_view);
140 static gboolean list_view_button_press (GtkWidget *widget,
141 GdkEventButton *event,
142 CompletionWindow *window);
144 static gboolean list_view_button_release (GtkWidget *widget,
145 GdkEventButton *event,
146 CompletionWindow *window);
148 static gboolean addr_compl_selected (GtkTreeSelection *selector,
151 gboolean currently_selected,
154 static gboolean addr_compl_defer_select_destruct(CompletionWindow *window);
157 * Function used by GTK to find the string data to be used for completion.
158 * \param data Pointer to data being processed.
160 static gchar *completion_func(gpointer data)
162 cm_return_val_if_fail(data != NULL, NULL);
164 return ((completion_entry *)data)->string;
167 static gint addr_completion_func(const gchar *needle, const gchar *haystack,
170 if (needle == NULL || haystack == NULL)
173 return (strcasestr(haystack, needle) != NULL ? 0 : 1);
177 * Initialize all completion index data.
179 static void init_all(void)
181 g_completion = g_completion_new(completion_func);
182 cm_return_if_fail(g_completion != NULL);
186 * set the compare function (default is strncmp)
188 static void set_match_any_part(const gboolean any_part)
190 if (any_part && prefs_common.address_search_wildcard)
191 g_completion_set_compare(g_completion, addr_completion_func);
193 g_completion_set_compare(g_completion, strncmp);
196 static void free_all_addresses(void)
201 walk = g_address_list;
202 for (; walk != NULL; walk = g_list_next(walk)) {
203 address_entry *ae = (address_entry *) walk->data;
206 g_list_free(ae->grp_emails);
209 g_list_free(g_address_list);
210 g_address_list = NULL;
211 if (_groupAddresses_)
212 g_hash_table_destroy(_groupAddresses_);
213 _groupAddresses_ = NULL;
216 static void clear_completion_cache(void);
217 static void free_completion_list(void)
220 if (!g_completion_list)
223 clear_completion_cache();
225 g_completion_clear_items(g_completion);
227 walk = g_list_first(g_completion_list);
228 for (; walk != NULL; walk = g_list_next(walk)) {
229 completion_entry *ce = (completion_entry *) walk->data;
233 g_list_free(g_completion_list);
234 g_completion_list = NULL;
237 * Free up all completion index data.
239 static void free_all(void)
241 free_completion_list();
242 free_all_addresses();
243 g_completion_free(g_completion);
248 * Append specified address entry to the index.
249 * \param str Index string value.
250 * \param ae Entry containing address data.
252 void addr_compl_add_address1(const char *str, address_entry *ae)
254 completion_entry *ce1;
255 ce1 = g_new0(completion_entry, 1),
256 /* GCompletion list is case sensitive */
257 ce1->string = g_utf8_strdown(str, -1);
260 g_completion_list = g_list_prepend(g_completion_list, ce1);
264 * Adds address to the completion list. This function looks complicated, but
265 * it's only allocation checks. Each value will be included in the index.
266 * \param name Recipient name.
267 * \param address EMail address.
268 * \param alias Alias to append.
269 * \param grp_emails the emails in case of a group. List should be freed later,
270 * but not its strings
271 * \return <code>0</code> if entry appended successfully, or <code>-1</code>
274 static gint add_address(const gchar *name, const gchar *address,
275 const gchar *nick, const gchar *alias, GList *grp_emails)
279 if (!address && !grp_emails)
285 ae = g_new0(address_entry, 1);
286 cm_return_val_if_fail(ae != NULL, -1);
288 ae->name = g_strdup(name);
289 ae->address = g_strdup(address);
290 ae->grp_emails = grp_emails;
291 g_address_list = g_list_prepend(g_address_list, ae);
293 addr_compl_add_address1(name, ae);
295 if (address != NULL && *address != '\0')
296 addr_compl_add_address1(address, ae);
298 if (nick != NULL && *nick != '\0')
299 addr_compl_add_address1(nick, ae);
301 if (alias != NULL && *alias != '\0')
302 addr_compl_add_address1(alias, ae);
308 * Read address book, creating all entries in the completion index.
310 static void read_address_book(gchar *folderpath) {
311 free_all_addresses();
312 free_completion_list();
314 #ifndef USE_NEW_ADDRBOOK
315 addrindex_load_completion( add_address, folderpath );
317 GError* error = NULL;
319 addrcompl_initialize();
320 if (! addrindex_dbus_load_completion(add_address, &error)) {
321 g_warning("Failed to populate address completion list");
326 /* plugins may hook in here to modify/extend the completion list */
327 hooks_invoke(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, &g_address_list);
329 g_address_list = g_list_reverse(g_address_list);
330 g_completion_list = g_list_reverse(g_completion_list);
331 /* merge the completion entry list into g_completion */
332 if (g_completion_list) {
333 g_completion_add_items(g_completion, g_completion_list);
334 if (debug_get_mode())
335 debug_print("read %d items in %s\n",
336 g_list_length(g_completion_list),
337 folderpath?folderpath:"(null)");
342 * Test whether there is a completion pending.
343 * \return <code>TRUE</code> if pending.
345 static gboolean is_completion_pending(void)
347 /* check if completion pending, i.e. we might satisfy a request for the next
348 * or previous address */
349 return g_completion_count;
353 * Clear the completion cache.
355 static void clear_completion_cache(void)
357 if (is_completion_pending()) {
358 g_free(g_completion_prefix);
360 if (g_completion_addresses) {
361 g_slist_free(g_completion_addresses);
362 g_completion_addresses = NULL;
365 g_completion_count = g_completion_next = 0;
370 * Prepare completion index. This function should be called prior to attempting
371 * address completion.
372 * \return The number of addresses in the completion list.
374 gint start_address_completion(gchar *folderpath)
376 gboolean different_book = FALSE;
377 clear_completion_cache();
379 if (strcmp2(completion_folder_path,folderpath))
380 different_book = TRUE;
382 g_free(completion_folder_path);
383 if (folderpath != NULL)
384 completion_folder_path = g_strdup(folderpath);
386 completion_folder_path = NULL;
390 /* open the address book */
391 read_address_book(folderpath);
392 } else if (different_book)
393 read_address_book(folderpath);
396 debug_print("start_address_completion(%s) ref count %d\n",
397 folderpath?folderpath:"(null)", g_ref_count);
399 return g_list_length(g_completion_list);
403 * Retrieve a possible address (or a part) from an entry box. To make life
404 * easier, we only look at the last valid address component; address
405 * completion only works at the last string component in the entry box.
407 * \param entry Address entry field.
408 * \param start_pos Address of start position of address.
409 * \return Possible address.
411 static gchar *get_address_from_edit(GtkEntry *entry, gint *start_pos)
413 const gchar *edit_text, *p;
415 gboolean in_quote = FALSE;
416 gboolean in_bracket = FALSE;
419 edit_text = gtk_entry_get_text(entry);
420 if (edit_text == NULL) return NULL;
422 cur_pos = gtk_editable_get_position(GTK_EDITABLE(entry));
424 /* scan for a separator. doesn't matter if walk points at null byte. */
425 for (p = g_utf8_offset_to_pointer(edit_text, cur_pos);
427 p = g_utf8_prev_char(p)) {
430 } else if (!in_quote) {
431 if (!in_bracket && *p == ',') {
433 } else if (*p == '<')
440 /* have something valid */
441 if (g_utf8_strlen(p, -1) == 0)
444 #define IS_VALID_CHAR(x) \
445 (g_ascii_isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f))
447 /* now scan back until we hit a valid character */
448 for (; *p && !IS_VALID_CHAR(*p); p = g_utf8_next_char(p))
453 if (g_utf8_strlen(p, -1) == 0)
456 if (start_pos) *start_pos = g_utf8_pointer_to_offset(edit_text, p);
463 static gchar *get_complete_address_from_name_email(const gchar *name, const gchar *email)
465 gchar *address = NULL;
466 if (!name || name[0] == '\0')
467 address = g_strdup_printf("<%s>", email);
468 else if (strchr_with_skip_quote(name, '"', ','))
469 address = g_strdup_printf
470 ("\"%s\" <%s>", name, email);
472 address = g_strdup_printf
473 ("%s <%s>", name, email);
478 * Replace an incompleted address with a completed one.
479 * \param entry Address entry field.
480 * \param newtext New text.
481 * \param start_pos Insertion point in entry field.
483 static void replace_address_in_edit(GtkEntry *entry, const gchar *newtext,
484 gint start_pos, gboolean is_group, GList *grp_emails)
486 if (!newtext) return;
487 gtk_editable_delete_text(GTK_EDITABLE(entry), start_pos, -1);
489 gtk_editable_insert_text(GTK_EDITABLE(entry), newtext, strlen(newtext),
492 gchar *addresses = NULL;
493 GList *cur = grp_emails;
494 for (; cur; cur = cur->next) {
496 ItemEMail *email = (ItemEMail *)cur->data;
497 ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(email);
499 gchar *addr = get_complete_address_from_name_email(
500 ADDRITEM_NAME(person), email->address);
502 tmp = g_strdup_printf("%s, %s", addresses, addr);
504 tmp = g_strdup_printf("%s", addr);
509 gtk_editable_insert_text(GTK_EDITABLE(entry), addresses, strlen(addresses),
513 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
517 * Attempt to complete an address, and returns the number of addresses found.
518 * Use <code>get_complete_address()</code> to get an entry from the index.
520 * \param str Search string to find.
521 * \return Zero if no match was found, otherwise the number of addresses; the
522 * original prefix (search string) will appear at index 0.
524 guint complete_address(const gchar *str)
526 GList *result = NULL;
530 completion_entry *ce = NULL;
532 cm_return_val_if_fail(str != NULL, 0);
534 /* g_completion is case sensitive */
535 d = g_utf8_strdown(str, -1);
537 clear_completion_cache();
538 g_completion_prefix = g_strdup(str);
540 result = g_completion_complete(g_completion, d, NULL);
542 count = g_list_length(result);
544 /* create list with unique addresses */
545 for (cpl = 0, result = g_list_first(result);
547 result = g_list_next(result)) {
548 ce = (completion_entry *)(result->data);
549 if (NULL == g_slist_find(g_completion_addresses,
552 g_completion_addresses =
553 g_slist_append(g_completion_addresses,
557 count = cpl + 1; /* index 0 is the original prefix */
558 g_completion_next = 1; /* we start at the first completed one */
560 g_free(g_completion_prefix);
561 g_completion_prefix = NULL;
564 g_completion_count = count;
572 * complete_matches_found() returns the number of matched addresses according
573 * to the completion mechanism. Unlike complete_address(), the returned value
574 * doesn't count str itself. If there's no match, it returns 0.
575 * To get a list of completion matches, see complete_address() instead.
577 guint complete_matches_found(const gchar *str)
579 GList *result = NULL;
582 cm_return_val_if_fail(str != NULL, 0);
584 /* g_completion is case sensitive */
585 d = g_utf8_strdown(str, -1);
587 clear_completion_cache();
588 g_completion_prefix = g_strdup(str);
590 result = g_completion_complete(g_completion, d, NULL);
592 g_free(g_completion_prefix);
595 return g_list_length(result);
599 * Return a complete address from the index.
600 * \param index Index of entry that was found (by the previous call to
601 * <code>complete_address()</code>
602 * \return Completed address string; this should be freed when done.
604 gchar *get_complete_address(gint index)
606 const address_entry *p;
607 gchar *address = NULL;
609 if (index < g_completion_count) {
611 address = g_strdup(g_completion_prefix);
613 /* get something from the unique addresses */
614 p = (address_entry *)g_slist_nth_data
615 (g_completion_addresses, index - 1);
616 if (p != NULL && p->address != NULL) {
617 address = get_complete_address_from_name_email(p->name, p->address);
618 } else if (p != NULL && p->address == NULL && p->name != NULL) {
620 address = g_strdup_printf("%s (%s) <!--___group___-->", p->name, _("Group"));
621 if (!_groupAddresses_) {
622 _groupAddresses_ = g_hash_table_new(NULL, g_direct_equal);
624 if (!g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)))) {
625 g_hash_table_insert(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)), p->grp_emails);
636 * Return the next complete address match from the completion index.
637 * \return Completed address string; this should be freed when done.
639 static gchar *get_next_complete_address(void)
641 if (is_completion_pending()) {
644 res = get_complete_address(g_completion_next);
645 g_completion_next += 1;
646 if (g_completion_next >= g_completion_count)
647 g_completion_next = 0;
655 * Return a count of the completed matches in the completion index.
656 * \return Number of matched entries.
658 static guint get_completion_count(void)
660 if (is_completion_pending())
661 return g_completion_count;
667 * Invalidate address completion index. This function should be called whenever
668 * the address book changes. This forces data to be read into the completion
670 * \return Number of entries in index.
672 gint invalidate_address_completion(void)
675 /* simply the same as start_address_completion() */
676 debug_print("Invalidation request for address completion\n");
677 read_address_book(completion_folder_path);
678 clear_completion_cache();
681 return g_list_length(g_completion_list);
685 * Finished with completion index. This function should be called after
686 * matching addresses.
687 * \return Reference count.
689 gint end_address_completion(void)
691 gboolean different_folder = FALSE;
692 clear_completion_cache();
694 /* reset the folderpath to NULL */
695 if (completion_folder_path) {
696 g_free(completion_folder_path);
697 completion_folder_path = NULL;
698 different_folder = TRUE;
700 if (0 == --g_ref_count)
703 debug_print("end_address_completion ref count %d\n", g_ref_count);
704 if (g_ref_count && different_folder) {
705 debug_print("still ref'd, different folder\n");
706 invalidate_address_completion();
715 static CompletionWindow *_compWindow_ = NULL;
718 * Mutex to protect callback from multiple threads.
720 static pthread_mutex_t _completionMutex_ = PTHREAD_MUTEX_INITIALIZER;
723 * Completion queue list.
725 static GList *_displayQueue_ = NULL;
729 static gint _queryID_ = 0;
732 * Completion idle ID.
734 static guint _completionIdleID_ = 0;
737 * address completion entry ui. the ui (completion list was inspired by galeon's
738 * auto completion list). remaining things powered by claws's completion engine.
741 #define ENTRY_DATA_TAB_HOOK "tab_hook" /* used to lookup entry */
742 #define ENTRY_DATA_ALLOW_COMMAS "allowcommas" /* used to know whether to present groups */
744 static void address_completion_mainwindow_set_focus (GtkWindow *window,
747 static gboolean address_completion_entry_key_pressed (GtkEntry *entry,
750 static gboolean address_completion_complete_address_in_entry
753 static void address_completion_create_completion_window (GtkEntry *entry);
755 static gboolean completion_window_button_press
757 GdkEventButton *event,
758 CompletionWindow *compWin );
760 static gboolean completion_window_key_press
763 CompletionWindow *compWin );
764 static void address_completion_create_completion_window( GtkEntry *entry_ );
767 * Create a completion window object.
768 * \return Initialized completion window.
770 static CompletionWindow *addrcompl_create_window( void ) {
771 CompletionWindow *cw;
773 cw = g_new0( CompletionWindow, 1 );
775 cw->searchTerm = NULL;
778 cw->list_view = NULL;
779 cw->in_mouse = FALSE;
780 cw->destroying = FALSE;
786 * Destroy completion window.
787 * \param cw Window to destroy.
789 static void addrcompl_destroy_window( CompletionWindow *cw ) {
790 /* Stop all searches currently in progress */
791 #ifndef USE_NEW_ADDRBOOK
792 addrindex_stop_search( _queryID_ );
794 /* Remove idler function... or application may not terminate */
795 if( _completionIdleID_ != 0 ) {
796 g_source_remove( _completionIdleID_ );
797 _completionIdleID_ = 0;
800 /* Now destroy window */
802 /* Clear references to widgets */
804 cw->list_view = NULL;
808 gtk_widget_hide( cw->window );
809 gtk_widget_destroy( cw->window );
812 cw->destroying = FALSE;
813 cw->in_mouse = FALSE;
819 * Free up completion window.
820 * \param cw Window to free.
822 static void addrcompl_free_window( CompletionWindow *cw ) {
824 addrcompl_destroy_window( cw );
826 g_free( cw->searchTerm );
827 cw->searchTerm = NULL;
829 /* Clear references */
838 * Advance selection to previous/next item in list.
839 * \param list_view List to process.
840 * \param forward Set to <i>TRUE</i> to select next or <i>FALSE</i> for
843 static void completion_window_advance_selection(GtkTreeView *list_view, gboolean forward)
845 GtkTreeSelection *selection;
849 cm_return_if_fail(list_view != NULL);
851 selection = gtk_tree_view_get_selection(list_view);
852 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
856 forward = gtk_tree_model_iter_next(model, &iter);
858 gtk_tree_selection_select_iter(selection, &iter);
862 prev = gtk_tree_model_get_path(model, &iter);
866 if (gtk_tree_path_prev(prev))
867 gtk_tree_selection_select_path(selection, prev);
869 gtk_tree_path_free(prev);
874 * Resize window to accommodate maximum number of address entries.
875 * \param cw Completion window.
877 static void addrcompl_resize_window( CompletionWindow *cw ) {
879 gint x, y, width, height, depth;
881 /* Get current geometry of window */
882 #if !GTK_CHECK_VERSION(3, 0, 0)
883 gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height, &depth );
885 gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height );
888 /* simple _hide breaks size requisition !? */
889 #if !GTK_CHECK_VERSION(3, 0, 0)
890 gtk_widget_hide_all( cw->window );
891 gtk_widget_show_all( cw->window );
893 gtk_widget_hide( cw->window );
894 gtk_widget_show( cw->window );
896 gtk_widget_size_request( cw->list_view, &r );
898 /* Adjust window height to available screen space */
899 if( y + r.height > gdk_screen_height())
900 r.height = gdk_screen_height() - y;
902 gtk_widget_set_size_request(cw->window, width, r.height);
904 gdk_pointer_grab(gtk_widget_get_window(cw->window), TRUE,
905 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
906 GDK_BUTTON_RELEASE_MASK,
907 NULL, NULL, GDK_CURRENT_TIME);
908 gdk_keyboard_grab(gtk_widget_get_window(cw->window), FALSE, GDK_CURRENT_TIME);
909 gtk_grab_add(cw->window);
913 static GdkPixbuf *group_pixbuf = NULL;
914 static GdkPixbuf *email_pixbuf = NULL;
917 * Add an address the completion window address list.
918 * \param cw Completion window.
919 * \param address Address to add.
921 static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
924 GtkTreeSelection *selection;
925 gboolean is_group = FALSE;
926 GList *grp_emails = NULL;
927 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cw->list_view)));
931 stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_TWO, &group_pixbuf);
932 g_object_ref(G_OBJECT(group_pixbuf));
935 stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_ONE, &email_pixbuf);
936 g_object_ref(G_OBJECT(email_pixbuf));
938 /* g_print( "\t\tAdding :%s\n", address ); */
939 if (strstr(address, " <!--___group___-->")) {
941 if (_groupAddresses_)
942 grp_emails = g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)));
943 *(strstr(address, " <!--___group___-->")) = '\0';
944 pixbuf = group_pixbuf;
945 } else if (strchr(address, '@') && strchr(address, '<') &&
946 strchr(address, '>')) {
947 pixbuf = email_pixbuf;
951 if (is_group && !_allowCommas_)
953 gtk_list_store_append(store, &iter);
954 gtk_list_store_set(store, &iter,
955 ADDR_COMPL_ICON, pixbuf,
956 ADDR_COMPL_ADDRESS, address,
957 ADDR_COMPL_ISGROUP, is_group,
958 ADDR_COMPL_GROUPLIST, grp_emails,
963 addrcompl_resize_window( cw );
964 gtk_grab_add( cw->window );
966 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cw->list_view));
967 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
969 if( cw->listCount == 1 ) {
970 /* Select first row for now */
971 gtk_tree_selection_select_iter(selection, &iter);
974 else if( cw->listCount == 2 ) {
975 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)) {
976 /* Move off first row */
977 gtk_tree_selection_select_iter(selection, &iter);
983 void addrcompl_reflect_prefs_pixmap_theme(void) {
985 g_object_unref(G_OBJECT(group_pixbuf));
989 g_object_unref(G_OBJECT(email_pixbuf));
995 * Completion idle function. This function is called by the main (UI) thread
996 * during UI idle time while an address search is in progress. Items from the
997 * display queue are processed and appended to the address list.
999 * \param data Target completion window to receive email addresses.
1000 * \return <i>TRUE</i> to ensure that idle event do not get ignored.
1002 static gboolean addrcompl_idle( gpointer data ) {
1006 /* Process all entries in display queue */
1007 pthread_mutex_lock( & _completionMutex_ );
1008 if( _displayQueue_ ) {
1009 node = _displayQueue_;
1011 address = node->data;
1012 /* g_print( "address ::: %s :::\n", address ); */
1013 addrcompl_add_entry( _compWindow_, address );
1015 node = g_list_next( node );
1017 g_list_free( _displayQueue_ );
1018 _displayQueue_ = NULL;
1020 pthread_mutex_unlock( & _completionMutex_ );
1027 * Callback entry point. The background thread (if any) appends the address
1028 * list to the display queue.
1029 * \param sender Sender of query.
1030 * \param queryID Query ID of search request.
1031 * \param listEMail List of zero of more email objects that met search
1033 * \param data Query data.
1035 #ifndef USE_NEW_ADDRBOOK
1036 static gint addrcompl_callback_entry(
1037 gpointer sender, gint queryID, GList *listEMail, gpointer data )
1042 /* g_print( "addrcompl_callback_entry::queryID=%d\n", queryID ); */
1043 pthread_mutex_lock( & _completionMutex_ );
1044 if( queryID == _queryID_ ) {
1045 /* Append contents to end of display queue */
1048 ItemEMail *email = node->data;
1050 address = addritem_format_email( email );
1051 /* g_print( "\temail/address ::%s::\n", address ); */
1052 _displayQueue_ = g_list_append( _displayQueue_, address );
1053 node = g_list_next( node );
1056 g_list_free( listEMail );
1057 pthread_mutex_unlock( & _completionMutex_ );
1064 * Clear the display queue.
1066 static void addrcompl_clear_queue( void ) {
1067 /* Clear out display queue */
1068 pthread_mutex_lock( & _completionMutex_ );
1070 g_list_free( _displayQueue_ );
1071 _displayQueue_ = NULL;
1073 pthread_mutex_unlock( & _completionMutex_ );
1077 * Add a single address entry into the display queue.
1078 * \param address Address to append.
1080 static void addrcompl_add_queue( gchar *address ) {
1081 pthread_mutex_lock( & _completionMutex_ );
1082 _displayQueue_ = g_list_append( _displayQueue_, address );
1083 pthread_mutex_unlock( & _completionMutex_ );
1087 * Load list with entries from local completion index.
1089 static void addrcompl_load_local( void ) {
1092 for (count = 0; count < get_completion_count(); count++) {
1095 address = get_complete_address( count );
1096 /* g_print( "\taddress ::%s::\n", address ); */
1098 /* Append contents to end of display queue */
1099 addrcompl_add_queue( address );
1106 static void addrcompl_start_search( void ) {
1107 #ifndef USE_NEW_ADDRBOOK
1110 searchTerm = g_strdup( _compWindow_->searchTerm );
1112 /* Setup the search */
1113 _queryID_ = addrindex_setup_search(
1114 searchTerm, NULL, addrcompl_callback_entry );
1115 g_free( searchTerm );
1117 /* g_print( "addrcompl_start_search::queryID=%d\n", _queryID_ ); */
1119 /* Load local stuff */
1120 addrcompl_load_local();
1122 /* Sit back and wait until something happens */
1123 _completionIdleID_ =
1124 g_idle_add( (GSourceFunc) addrcompl_idle, NULL );
1125 /* g_print( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
1127 #ifndef USE_NEW_ADDRBOOK
1128 addrindex_start_search( _queryID_ );
1135 * Apply the current selection in the list to the entry field. Focus is also
1136 * moved to the next widget so that Tab key works correctly.
1137 * \param list_view List to process.
1138 * \param entry Address entry field.
1139 * \param move_focus Move focus to the next widget ?
1141 static void completion_window_apply_selection(GtkTreeView *list_view,
1143 gboolean move_focus)
1145 gchar *address = NULL, *text = NULL;
1148 GtkTreeSelection *selection;
1149 GtkTreeModel *model;
1151 gboolean is_group = FALSE;
1152 cm_return_if_fail(list_view != NULL);
1153 cm_return_if_fail(entry != NULL);
1154 GList *grp_emails = NULL;
1156 selection = gtk_tree_view_get_selection(list_view);
1157 if (! gtk_tree_selection_get_selected(selection, &model, &iter))
1160 /* First remove the idler */
1161 if( _completionIdleID_ != 0 ) {
1162 g_source_remove( _completionIdleID_ );
1163 _completionIdleID_ = 0;
1166 /* Process selected item */
1167 gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text,
1168 ADDR_COMPL_ISGROUP, &is_group,
1169 ADDR_COMPL_GROUPLIST, &grp_emails,
1172 address = get_address_from_edit(entry, &cursor_pos);
1174 replace_address_in_edit(entry, text, cursor_pos, is_group, grp_emails);
1177 /* Move focus to next widget */
1178 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1179 if( parent && move_focus) {
1180 gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
1185 * Start address completion. Should be called when creating the main window
1186 * containing address completion entries.
1187 * \param mainwindow Main window.
1189 void address_completion_start(GtkWidget *mainwindow)
1191 start_address_completion(NULL);
1192 set_match_any_part(TRUE);
1194 /* register focus change hook */
1195 g_signal_connect(G_OBJECT(mainwindow), "set_focus",
1196 G_CALLBACK(address_completion_mainwindow_set_focus),
1201 * Need unique data to make unregistering signal handler possible for the auto
1204 #define COMPLETION_UNIQUE_DATA (GINT_TO_POINTER(0xfeefaa))
1207 * Register specified entry widget for address completion.
1208 * \param entry Address entry field.
1210 void address_completion_register_entry(GtkEntry *entry, gboolean allow_commas)
1212 cm_return_if_fail(entry != NULL);
1213 cm_return_if_fail(GTK_IS_ENTRY(entry));
1215 /* add hooked property */
1216 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, entry);
1217 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS, GINT_TO_POINTER(allow_commas));
1219 /* add keypress event */
1220 g_signal_connect_closure
1221 (G_OBJECT(entry), "key_press_event",
1222 g_cclosure_new(G_CALLBACK(address_completion_entry_key_pressed),
1223 COMPLETION_UNIQUE_DATA,
1229 * Unregister specified entry widget from address completion operations.
1230 * \param entry Address entry field.
1232 void address_completion_unregister_entry(GtkEntry *entry)
1236 cm_return_if_fail(entry != NULL);
1237 cm_return_if_fail(GTK_IS_ENTRY(entry));
1239 entry_obj = g_object_get_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
1240 cm_return_if_fail(entry_obj);
1241 cm_return_if_fail(G_OBJECT(entry_obj) == G_OBJECT(entry));
1243 /* has the hooked property? */
1244 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
1246 /* remove the hook */
1247 g_signal_handlers_disconnect_by_func(G_OBJECT(entry),
1248 G_CALLBACK(address_completion_entry_key_pressed),
1249 COMPLETION_UNIQUE_DATA);
1253 * End address completion. Should be called when main window with address
1254 * completion entries terminates. NOTE: this function assumes that it is
1255 * called upon destruction of the window.
1256 * \param mainwindow Main window.
1258 void address_completion_end(GtkWidget *mainwindow)
1260 /* if address_completion_end() is really called on closing the window,
1261 * we don't need to unregister the set_focus_cb */
1262 end_address_completion();
1265 /* if focus changes to another entry, then clear completion cache */
1266 static void address_completion_mainwindow_set_focus(GtkWindow *window,
1271 if (widget && GTK_IS_ENTRY(widget) &&
1272 g_object_get_data(G_OBJECT(widget), ENTRY_DATA_TAB_HOOK)) {
1273 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), ENTRY_DATA_ALLOW_COMMAS));
1274 clear_completion_cache();
1279 * Listener that watches for tab or other keystroke in address entry field.
1280 * \param entry Address entry field.
1281 * \param ev Event object.
1282 * \param data User data.
1283 * \return <i>TRUE</i>.
1285 static gboolean address_completion_entry_key_pressed(GtkEntry *entry,
1289 if (ev->keyval == GDK_KEY_Tab) {
1290 addrcompl_clear_queue();
1291 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
1292 if( address_completion_complete_address_in_entry( entry, TRUE ) ) {
1293 /* route a void character to the default handler */
1294 /* this is a dirty hack; we're actually changing a key
1295 * reported by the system. */
1296 ev->keyval = GDK_KEY_AudibleBell_Enable;
1297 ev->state &= ~GDK_SHIFT_MASK;
1300 address_completion_create_completion_window(entry);
1302 /* Start remote queries */
1303 addrcompl_start_search();
1310 } else if (ev->keyval == GDK_KEY_Shift_L
1311 || ev->keyval == GDK_KEY_Shift_R
1312 || ev->keyval == GDK_KEY_Control_L
1313 || ev->keyval == GDK_KEY_Control_R
1314 || ev->keyval == GDK_KEY_Caps_Lock
1315 || ev->keyval == GDK_KEY_Shift_Lock
1316 || ev->keyval == GDK_KEY_Meta_L
1317 || ev->keyval == GDK_KEY_Meta_R
1318 || ev->keyval == GDK_KEY_Alt_L
1319 || ev->keyval == GDK_KEY_Alt_R) {
1320 /* these buttons should not clear the cache... */
1322 clear_completion_cache();
1327 * Initialize search term for address completion.
1328 * \param entry Address entry field.
1330 static gboolean address_completion_complete_address_in_entry(GtkEntry *entry,
1333 gint ncount, cursor_pos;
1334 gchar *searchTerm, *new = NULL;
1336 cm_return_val_if_fail(entry != NULL, FALSE);
1338 if (!gtk_widget_has_focus(GTK_WIDGET(entry))) return FALSE;
1340 /* get an address component from the cursor */
1341 searchTerm = get_address_from_edit( entry, &cursor_pos );
1342 if( ! searchTerm ) return FALSE;
1343 /* g_print( "search for :::%s:::\n", searchTerm ); */
1345 /* Clear any existing search */
1346 g_free( _compWindow_->searchTerm );
1347 _compWindow_->searchTerm = g_strdup( searchTerm );
1349 /* Perform search on local completion index */
1350 ncount = complete_address( searchTerm );
1352 new = get_next_complete_address();
1355 #if (!defined(USE_LDAP) && !defined(GENERIC_UMPC))
1356 /* Select the address if there is only one match */
1358 /* Display selected address in entry field */
1359 gchar *addr = get_complete_address(1);
1360 if (addr && !strstr(addr, " <!--___group___-->")) {
1361 replace_address_in_edit(entry, addr, cursor_pos, FALSE, NULL);
1362 /* Discard the window */
1363 clear_completion_cache();
1367 /* Make sure that drop-down appears uniform! */
1371 addrcompl_add_queue( g_strdup( searchTerm ) );
1373 g_free( searchTerm );
1379 * Create new address completion window for specified entry.
1380 * \param entry_ Entry widget to associate with window.
1382 static void address_completion_create_completion_window( GtkEntry *entry_ )
1384 gint x, y, height, width, depth;
1385 GtkWidget *scroll, *list_view;
1388 GtkWidget *entry = GTK_WIDGET(entry_);
1391 /* Create new window and list */
1392 window = gtk_window_new(GTK_WINDOW_POPUP);
1393 list_view = addr_compl_list_view_create(_compWindow_);
1395 /* Destroy any existing window */
1396 addrcompl_destroy_window( _compWindow_ );
1398 /* Create new object */
1399 _compWindow_->window = window;
1400 _compWindow_->entry = entry;
1401 _compWindow_->list_view = list_view;
1402 _compWindow_->listCount = 0;
1403 _compWindow_->in_mouse = FALSE;
1405 scroll = gtk_scrolled_window_new(NULL, NULL);
1406 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
1407 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1408 gtk_container_add(GTK_CONTAINER(window), scroll);
1409 gtk_container_add(GTK_CONTAINER(scroll), list_view);
1410 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
1412 /* Use entry widget to create initial window */
1413 gdkwin = gtk_widget_get_window(entry),
1414 #if !GTK_CHECK_VERSION(3, 0, 0)
1415 gdk_window_get_geometry(gdkwin, &x, &y, &width, &height, &depth);
1417 gdk_window_get_geometry(gdkwin, &x, &y, &width, &height);
1419 gdk_window_get_origin (gdkwin, &x, &y);
1421 gtk_window_move(GTK_WINDOW(window), x, y);
1423 /* Resize window to fit initial (empty) address list */
1424 gtk_widget_size_request( list_view, &r );
1425 gtk_widget_set_size_request( window, width, r.height );
1426 gtk_widget_show_all( window );
1427 gtk_widget_size_request( list_view, &r );
1429 /* Setup handlers */
1430 g_signal_connect(G_OBJECT(list_view), "button_press_event",
1431 G_CALLBACK(list_view_button_press),
1434 g_signal_connect(G_OBJECT(list_view), "button_release_event",
1435 G_CALLBACK(list_view_button_release),
1438 g_signal_connect(G_OBJECT(window),
1439 "button-press-event",
1440 G_CALLBACK(completion_window_button_press),
1442 g_signal_connect(G_OBJECT(window),
1444 G_CALLBACK(completion_window_key_press),
1446 gdk_pointer_grab(gtk_widget_get_window(window), TRUE,
1447 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
1448 GDK_BUTTON_RELEASE_MASK,
1449 NULL, NULL, GDK_CURRENT_TIME);
1450 gdk_keyboard_grab(gtk_widget_get_window(window), FALSE, GDK_CURRENT_TIME);
1451 gtk_grab_add( window );
1455 * Respond to button press in completion window. Check if mouse click is
1456 * anywhere outside the completion window. In that case the completion
1457 * window is destroyed, and the original searchTerm is restored.
1459 * \param widget Window object.
1460 * \param event Event.
1461 * \param compWin Reference to completion window.
1463 static gboolean completion_window_button_press(GtkWidget *widget,
1464 GdkEventButton *event,
1465 CompletionWindow *compWin )
1467 GtkWidget *event_widget, *entry;
1470 gboolean restore = TRUE;
1472 cm_return_val_if_fail(compWin != NULL, FALSE);
1474 entry = compWin->entry;
1475 cm_return_val_if_fail(entry != NULL, FALSE);
1477 /* Test where mouse was clicked */
1478 event_widget = gtk_get_event_widget((GdkEvent *)event);
1479 if (event_widget != widget) {
1480 while (event_widget) {
1481 if (event_widget == widget)
1483 else if (event_widget == entry) {
1487 event_widget = gtk_widget_get_parent(event_widget);
1492 /* Clicked outside of completion window - restore */
1493 searchTerm = _compWindow_->searchTerm;
1494 g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
1495 replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
1498 clear_completion_cache();
1499 addrcompl_destroy_window( _compWindow_ );
1505 * Respond to key press in completion window.
1506 * \param widget Window object.
1507 * \param event Event.
1508 * \param compWind Reference to completion window.
1510 static gboolean completion_window_key_press(GtkWidget *widget,
1512 CompletionWindow *compWin )
1514 GdkEventKey tmp_event;
1518 GtkWidget *list_view;
1520 cm_return_val_if_fail(compWin != NULL, FALSE);
1522 entry = compWin->entry;
1523 list_view = compWin->list_view;
1524 cm_return_val_if_fail(entry != NULL, FALSE);
1526 /* allow keyboard navigation in the alternatives tree view */
1527 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down ||
1528 event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down) {
1529 completion_window_advance_selection
1530 (GTK_TREE_VIEW(list_view),
1531 event->keyval == GDK_KEY_Down ||
1532 event->keyval == GDK_KEY_Page_Down ? TRUE : FALSE);
1536 /* make tab move to next field */
1537 if( event->keyval == GDK_KEY_Tab ) {
1538 /* Reference to parent */
1539 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1541 /* Discard the window */
1542 clear_completion_cache();
1543 addrcompl_destroy_window( _compWindow_ );
1545 /* Move focus to next widget */
1547 gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
1552 /* make backtab move to previous field */
1553 if( event->keyval == GDK_KEY_ISO_Left_Tab ) {
1554 /* Reference to parent */
1555 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1557 /* Discard the window */
1558 clear_completion_cache();
1559 addrcompl_destroy_window( _compWindow_ );
1561 /* Move focus to previous widget */
1563 gtk_widget_child_focus( parent, GTK_DIR_TAB_BACKWARD );
1567 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
1569 /* look for presses that accept the selection */
1570 if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_space ||
1571 event->keyval == GDK_KEY_KP_Enter ||
1572 (_allowCommas_ && event->keyval == GDK_KEY_comma)) {
1573 /* User selected address with a key press */
1575 /* Display selected address in entry field */
1576 completion_window_apply_selection(
1577 GTK_TREE_VIEW(list_view), GTK_ENTRY(entry),
1578 event->keyval != GDK_KEY_comma);
1580 if (event->keyval == GDK_KEY_comma) {
1581 gint pos = gtk_editable_get_position(GTK_EDITABLE(entry));
1582 gtk_editable_insert_text(GTK_EDITABLE(entry), ", ", 2, &pos);
1583 gtk_editable_set_position(GTK_EDITABLE(entry), pos + 1);
1586 /* Discard the window */
1587 clear_completion_cache();
1588 addrcompl_destroy_window( _compWindow_ );
1592 /* key state keys should never be handled */
1593 if (event->keyval == GDK_KEY_Shift_L
1594 || event->keyval == GDK_KEY_Shift_R
1595 || event->keyval == GDK_KEY_Control_L
1596 || event->keyval == GDK_KEY_Control_R
1597 || event->keyval == GDK_KEY_Caps_Lock
1598 || event->keyval == GDK_KEY_Shift_Lock
1599 || event->keyval == GDK_KEY_Meta_L
1600 || event->keyval == GDK_KEY_Meta_R
1601 || event->keyval == GDK_KEY_Alt_L
1602 || event->keyval == GDK_KEY_Alt_R) {
1606 /* some other key, let's restore the searchTerm (orignal text) */
1607 searchTerm = _compWindow_->searchTerm;
1608 g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
1609 replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
1611 /* make sure anything we typed comes in the edit box */
1612 tmp_event.type = event->type;
1613 tmp_event.window = gtk_widget_get_window(GTK_WIDGET(entry));
1614 tmp_event.send_event = TRUE;
1615 tmp_event.time = event->time;
1616 tmp_event.state = event->state;
1617 tmp_event.keyval = event->keyval;
1618 tmp_event.length = event->length;
1619 tmp_event.string = event->string;
1620 gtk_widget_event(entry, (GdkEvent *)&tmp_event);
1622 /* and close the completion window */
1623 clear_completion_cache();
1624 addrcompl_destroy_window( _compWindow_ );
1630 * ============================================================================
1631 * Publically accessible functions.
1632 * ============================================================================
1636 * Setup completion object.
1638 void addrcompl_initialize( void ) {
1639 /* g_print( "addrcompl_initialize...\n" ); */
1640 if( ! _compWindow_ ) {
1641 _compWindow_ = addrcompl_create_window();
1644 _completionIdleID_ = 0;
1645 /* g_print( "addrcompl_initialize...done\n" ); */
1649 * Teardown completion object.
1651 void addrcompl_teardown( void ) {
1652 /* g_print( "addrcompl_teardown...\n" ); */
1653 addrcompl_free_window( _compWindow_ );
1654 _compWindow_ = NULL;
1656 addrcompl_clear_queue();
1658 _completionIdleID_ = 0;
1659 /* g_print( "addrcompl_teardown...done\n" ); */
1663 * tree view functions
1666 static GtkListStore *addr_compl_create_store(void)
1668 return gtk_list_store_new(N_ADDR_COMPL_COLUMNS,
1676 static GtkWidget *addr_compl_list_view_create(CompletionWindow *window)
1678 GtkTreeView *list_view;
1679 GtkTreeSelection *selector;
1680 GtkTreeModel *model;
1682 model = GTK_TREE_MODEL(addr_compl_create_store());
1683 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1684 g_object_unref(model);
1686 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1687 gtk_tree_view_set_headers_visible(list_view, FALSE);
1689 selector = gtk_tree_view_get_selection(list_view);
1690 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1691 gtk_tree_selection_set_select_function(selector, addr_compl_selected,
1694 /* create the columns */
1695 addr_compl_create_list_view_columns(GTK_WIDGET(list_view));
1697 return GTK_WIDGET(list_view);
1700 static void addr_compl_create_list_view_columns(GtkWidget *list_view)
1702 GtkTreeViewColumn *column;
1703 GtkCellRenderer *renderer;
1705 renderer = gtk_cell_renderer_pixbuf_new();
1706 column = gtk_tree_view_column_new_with_attributes
1708 "pixbuf", ADDR_COMPL_ICON, NULL);
1709 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1710 renderer = gtk_cell_renderer_text_new();
1711 column = gtk_tree_view_column_new_with_attributes
1712 ("", renderer, "text", ADDR_COMPL_ADDRESS, NULL);
1713 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1716 static gboolean list_view_button_press(GtkWidget *widget, GdkEventButton *event,
1717 CompletionWindow *window)
1719 if (window && event && event->type == GDK_BUTTON_PRESS) {
1720 window->in_mouse = TRUE;
1725 static gboolean list_view_button_release(GtkWidget *widget, GdkEventButton *event,
1726 CompletionWindow *window)
1728 if (window && event && event->type == GDK_BUTTON_RELEASE) {
1729 window->in_mouse = FALSE;
1734 static gboolean addr_compl_selected(GtkTreeSelection *selector,
1735 GtkTreeModel *model,
1737 gboolean currently_selected,
1740 CompletionWindow *window = data;
1742 if (currently_selected)
1745 if (!window->in_mouse)
1748 /* XXX: select the entry and kill window later... select is called before
1749 * any other mouse events handlers including the tree view internal one;
1750 * not using a time out would result in a crash. if this doesn't work
1751 * safely, maybe we should set variables when receiving button presses
1752 * in the tree view. */
1753 if (!window->destroying) {
1754 window->destroying = TRUE;
1755 g_idle_add((GSourceFunc) addr_compl_defer_select_destruct, data);
1761 static gboolean addr_compl_defer_select_destruct(CompletionWindow *window)
1763 GtkEntry *entry = GTK_ENTRY(window->entry);
1765 completion_window_apply_selection(GTK_TREE_VIEW(window->list_view),
1768 clear_completion_cache();
1770 addrcompl_destroy_window(window);