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 g_completion_set_compare(g_completion, addr_completion_func);
183 cm_return_if_fail(g_completion != NULL);
186 static void free_all_addresses(void)
191 walk = g_address_list;
192 for (; walk != NULL; walk = g_list_next(walk)) {
193 address_entry *ae = (address_entry *) walk->data;
196 g_list_free(ae->grp_emails);
199 g_list_free(g_address_list);
200 g_address_list = NULL;
201 if (_groupAddresses_)
202 g_hash_table_destroy(_groupAddresses_);
203 _groupAddresses_ = NULL;
206 static void clear_completion_cache(void);
207 static void free_completion_list(void)
210 if (!g_completion_list)
213 clear_completion_cache();
215 g_completion_clear_items(g_completion);
217 walk = g_list_first(g_completion_list);
218 for (; walk != NULL; walk = g_list_next(walk)) {
219 completion_entry *ce = (completion_entry *) walk->data;
223 g_list_free(g_completion_list);
224 g_completion_list = NULL;
227 * Free up all completion index data.
229 static void free_all(void)
231 free_completion_list();
232 free_all_addresses();
233 g_completion_free(g_completion);
238 * Append specified address entry to the index.
239 * \param str Index string value.
240 * \param ae Entry containing address data.
242 void addr_compl_add_address1(const char *str, address_entry *ae)
244 completion_entry *ce1;
245 ce1 = g_new0(completion_entry, 1),
246 /* GCompletion list is case sensitive */
247 ce1->string = g_utf8_strdown(str, -1);
250 g_completion_list = g_list_prepend(g_completion_list, ce1);
254 * Adds address to the completion list. This function looks complicated, but
255 * it's only allocation checks. Each value will be included in the index.
256 * \param name Recipient name.
257 * \param address EMail address.
258 * \param alias Alias to append.
259 * \param grp_emails the emails in case of a group. List should be freed later,
260 * but not its strings
261 * \return <code>0</code> if entry appended successfully, or <code>-1</code>
264 static gint add_address(const gchar *name, const gchar *address,
265 const gchar *nick, const gchar *alias, GList *grp_emails)
269 if (!address && !grp_emails)
275 ae = g_new0(address_entry, 1);
276 cm_return_val_if_fail(ae != NULL, -1);
278 ae->name = g_strdup(name);
279 ae->address = g_strdup(address);
280 ae->grp_emails = grp_emails;
281 g_address_list = g_list_prepend(g_address_list, ae);
283 addr_compl_add_address1(name, ae);
285 if (address != NULL && *address != '\0')
286 addr_compl_add_address1(address, ae);
288 if (nick != NULL && *nick != '\0')
289 addr_compl_add_address1(nick, ae);
291 if (alias != NULL && *alias != '\0')
292 addr_compl_add_address1(alias, ae);
298 * Read address book, creating all entries in the completion index.
300 static void read_address_book(gchar *folderpath) {
301 free_all_addresses();
302 free_completion_list();
304 #ifndef USE_NEW_ADDRBOOK
305 addrindex_load_completion( add_address, folderpath );
307 GError* error = NULL;
309 addrcompl_initialize();
310 if (! addrindex_dbus_load_completion(add_address, &error)) {
311 g_warning("Failed to populate address completion list");
316 /* plugins may hook in here to modify/extend the completion list */
317 hooks_invoke(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, &g_address_list);
319 g_address_list = g_list_reverse(g_address_list);
320 g_completion_list = g_list_reverse(g_completion_list);
321 /* merge the completion entry list into g_completion */
322 if (g_completion_list) {
323 g_completion_add_items(g_completion, g_completion_list);
324 if (debug_get_mode())
325 debug_print("read %d items in %s\n",
326 g_list_length(g_completion_list),
327 folderpath?folderpath:"(null)");
332 * Test whether there is a completion pending.
333 * \return <code>TRUE</code> if pending.
335 static gboolean is_completion_pending(void)
337 /* check if completion pending, i.e. we might satisfy a request for the next
338 * or previous address */
339 return g_completion_count;
343 * Clear the completion cache.
345 static void clear_completion_cache(void)
347 if (is_completion_pending()) {
348 g_free(g_completion_prefix);
350 if (g_completion_addresses) {
351 g_slist_free(g_completion_addresses);
352 g_completion_addresses = NULL;
355 g_completion_count = g_completion_next = 0;
360 * Prepare completion index. This function should be called prior to attempting
361 * address completion.
362 * \return The number of addresses in the completion list.
364 gint start_address_completion(gchar *folderpath)
366 gboolean different_book = FALSE;
367 clear_completion_cache();
369 if (strcmp2(completion_folder_path,folderpath))
370 different_book = TRUE;
372 g_free(completion_folder_path);
373 if (folderpath != NULL)
374 completion_folder_path = g_strdup(folderpath);
376 completion_folder_path = NULL;
380 /* open the address book */
381 read_address_book(folderpath);
382 } else if (different_book)
383 read_address_book(folderpath);
386 debug_print("start_address_completion(%s) ref count %d\n",
387 folderpath?folderpath:"(null)", g_ref_count);
389 return g_list_length(g_completion_list);
393 * Retrieve a possible address (or a part) from an entry box. To make life
394 * easier, we only look at the last valid address component; address
395 * completion only works at the last string component in the entry box.
397 * \param entry Address entry field.
398 * \param start_pos Address of start position of address.
399 * \return Possible address.
401 static gchar *get_address_from_edit(GtkEntry *entry, gint *start_pos)
403 const gchar *edit_text, *p;
405 gboolean in_quote = FALSE;
406 gboolean in_bracket = FALSE;
409 edit_text = gtk_entry_get_text(entry);
410 if (edit_text == NULL) return NULL;
412 cur_pos = gtk_editable_get_position(GTK_EDITABLE(entry));
414 /* scan for a separator. doesn't matter if walk points at null byte. */
415 for (p = g_utf8_offset_to_pointer(edit_text, cur_pos);
417 p = g_utf8_prev_char(p)) {
420 } else if (!in_quote) {
421 if (!in_bracket && *p == ',') {
423 } else if (*p == '<')
430 /* have something valid */
431 if (g_utf8_strlen(p, -1) == 0)
434 #define IS_VALID_CHAR(x) \
435 (g_ascii_isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f))
437 /* now scan back until we hit a valid character */
438 for (; *p && !IS_VALID_CHAR(*p); p = g_utf8_next_char(p))
443 if (g_utf8_strlen(p, -1) == 0)
446 if (start_pos) *start_pos = g_utf8_pointer_to_offset(edit_text, p);
453 static gchar *get_complete_address_from_name_email(const gchar *name, const gchar *email)
455 gchar *address = NULL;
456 if (!name || name[0] == '\0')
457 address = g_strdup_printf("<%s>", email);
458 else if (strchr_with_skip_quote(name, '"', ','))
459 address = g_strdup_printf
460 ("\"%s\" <%s>", name, email);
462 address = g_strdup_printf
463 ("%s <%s>", name, email);
468 * Replace an incompleted address with a completed one.
469 * \param entry Address entry field.
470 * \param newtext New text.
471 * \param start_pos Insertion point in entry field.
473 static void replace_address_in_edit(GtkEntry *entry, const gchar *newtext,
474 gint start_pos, gboolean is_group, GList *grp_emails)
476 if (!newtext) return;
477 gtk_editable_delete_text(GTK_EDITABLE(entry), start_pos, -1);
479 gtk_editable_insert_text(GTK_EDITABLE(entry), newtext, strlen(newtext),
482 gchar *addresses = NULL;
483 GList *cur = grp_emails;
484 for (; cur; cur = cur->next) {
486 ItemEMail *email = (ItemEMail *)cur->data;
487 ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(email);
489 gchar *addr = get_complete_address_from_name_email(
490 ADDRITEM_NAME(person), email->address);
492 tmp = g_strdup_printf("%s, %s", addresses, addr);
494 tmp = g_strdup_printf("%s", addr);
499 gtk_editable_insert_text(GTK_EDITABLE(entry), addresses, strlen(addresses),
503 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
507 * Attempt to complete an address, and returns the number of addresses found.
508 * Use <code>get_complete_address()</code> to get an entry from the index.
510 * \param str Search string to find.
511 * \return Zero if no match was found, otherwise the number of addresses; the
512 * original prefix (search string) will appear at index 0.
514 guint complete_address(const gchar *str)
516 GList *result = NULL;
520 completion_entry *ce = NULL;
522 cm_return_val_if_fail(str != NULL, 0);
524 /* g_completion is case sensitive */
525 d = g_utf8_strdown(str, -1);
527 clear_completion_cache();
528 g_completion_prefix = g_strdup(str);
530 result = g_completion_complete(g_completion, d, NULL);
532 count = g_list_length(result);
534 /* create list with unique addresses */
535 for (cpl = 0, result = g_list_first(result);
537 result = g_list_next(result)) {
538 ce = (completion_entry *)(result->data);
539 if (NULL == g_slist_find(g_completion_addresses,
542 g_completion_addresses =
543 g_slist_append(g_completion_addresses,
547 count = cpl + 1; /* index 0 is the original prefix */
548 g_completion_next = 1; /* we start at the first completed one */
550 g_free(g_completion_prefix);
551 g_completion_prefix = NULL;
554 g_completion_count = count;
562 * complete_matches_found() returns the number of matched addresses according
563 * to the completion mechanism. Unlike complete_address(), the returned value
564 * doesn't count str itself. If there's no match, it returns 0.
565 * To get a list of completion matches, see complete_address() instead.
567 guint complete_matches_found(const gchar *str)
569 GList *result = NULL;
572 cm_return_val_if_fail(str != NULL, 0);
574 /* g_completion is case sensitive */
575 d = g_utf8_strdown(str, -1);
577 clear_completion_cache();
578 g_completion_prefix = g_strdup(str);
580 result = g_completion_complete(g_completion, d, NULL);
582 g_free(g_completion_prefix);
585 return g_list_length(result);
589 * Return a complete address from the index.
590 * \param index Index of entry that was found (by the previous call to
591 * <code>complete_address()</code>
592 * \return Completed address string; this should be freed when done.
594 gchar *get_complete_address(gint index)
596 const address_entry *p;
597 gchar *address = NULL;
599 if (index < g_completion_count) {
601 address = g_strdup(g_completion_prefix);
603 /* get something from the unique addresses */
604 p = (address_entry *)g_slist_nth_data
605 (g_completion_addresses, index - 1);
606 if (p != NULL && p->address != NULL) {
607 address = get_complete_address_from_name_email(p->name, p->address);
608 } else if (p != NULL && p->address == NULL && p->name != NULL) {
610 address = g_strdup_printf("%s (%s) <!--___group___-->", p->name, _("Group"));
611 if (!_groupAddresses_) {
612 _groupAddresses_ = g_hash_table_new(NULL, g_direct_equal);
614 if (!g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)))) {
615 g_hash_table_insert(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)), p->grp_emails);
626 * Return the next complete address match from the completion index.
627 * \return Completed address string; this should be freed when done.
629 static gchar *get_next_complete_address(void)
631 if (is_completion_pending()) {
634 res = get_complete_address(g_completion_next);
635 g_completion_next += 1;
636 if (g_completion_next >= g_completion_count)
637 g_completion_next = 0;
645 * Return a count of the completed matches in the completion index.
646 * \return Number of matched entries.
648 static guint get_completion_count(void)
650 if (is_completion_pending())
651 return g_completion_count;
657 * Invalidate address completion index. This function should be called whenever
658 * the address book changes. This forces data to be read into the completion
660 * \return Number of entries in index.
662 gint invalidate_address_completion(void)
665 /* simply the same as start_address_completion() */
666 debug_print("Invalidation request for address completion\n");
667 read_address_book(completion_folder_path);
668 clear_completion_cache();
671 return g_list_length(g_completion_list);
675 * Finished with completion index. This function should be called after
676 * matching addresses.
677 * \return Reference count.
679 gint end_address_completion(void)
681 gboolean different_folder = FALSE;
682 clear_completion_cache();
684 /* reset the folderpath to NULL */
685 if (completion_folder_path) {
686 g_free(completion_folder_path);
687 completion_folder_path = NULL;
688 different_folder = TRUE;
690 if (0 == --g_ref_count)
693 debug_print("end_address_completion ref count %d\n", g_ref_count);
694 if (g_ref_count && different_folder) {
695 debug_print("still ref'd, different folder\n");
696 invalidate_address_completion();
705 static CompletionWindow *_compWindow_ = NULL;
708 * Mutex to protect callback from multiple threads.
710 static pthread_mutex_t _completionMutex_ = PTHREAD_MUTEX_INITIALIZER;
713 * Completion queue list.
715 static GList *_displayQueue_ = NULL;
719 static gint _queryID_ = 0;
722 * Completion idle ID.
724 static guint _completionIdleID_ = 0;
727 * address completion entry ui. the ui (completion list was inspired by galeon's
728 * auto completion list). remaining things powered by claws's completion engine.
731 #define ENTRY_DATA_TAB_HOOK "tab_hook" /* used to lookup entry */
732 #define ENTRY_DATA_ALLOW_COMMAS "allowcommas" /* used to know whether to present groups */
734 static void address_completion_mainwindow_set_focus (GtkWindow *window,
737 static gboolean address_completion_entry_key_pressed (GtkEntry *entry,
740 static gboolean address_completion_complete_address_in_entry
743 static void address_completion_create_completion_window (GtkEntry *entry);
745 static gboolean completion_window_button_press
747 GdkEventButton *event,
748 CompletionWindow *compWin );
750 static gboolean completion_window_key_press
753 CompletionWindow *compWin );
754 static void address_completion_create_completion_window( GtkEntry *entry_ );
757 * Create a completion window object.
758 * \return Initialized completion window.
760 static CompletionWindow *addrcompl_create_window( void ) {
761 CompletionWindow *cw;
763 cw = g_new0( CompletionWindow, 1 );
765 cw->searchTerm = NULL;
768 cw->list_view = NULL;
769 cw->in_mouse = FALSE;
770 cw->destroying = FALSE;
776 * Destroy completion window.
777 * \param cw Window to destroy.
779 static void addrcompl_destroy_window( CompletionWindow *cw ) {
780 /* Stop all searches currently in progress */
781 #ifndef USE_NEW_ADDRBOOK
782 addrindex_stop_search( _queryID_ );
784 /* Remove idler function... or application may not terminate */
785 if( _completionIdleID_ != 0 ) {
786 g_source_remove( _completionIdleID_ );
787 _completionIdleID_ = 0;
790 /* Now destroy window */
792 /* Clear references to widgets */
794 cw->list_view = NULL;
798 gtk_widget_hide( cw->window );
799 gtk_widget_destroy( cw->window );
802 cw->destroying = FALSE;
803 cw->in_mouse = FALSE;
809 * Free up completion window.
810 * \param cw Window to free.
812 static void addrcompl_free_window( CompletionWindow *cw ) {
814 addrcompl_destroy_window( cw );
816 g_free( cw->searchTerm );
817 cw->searchTerm = NULL;
819 /* Clear references */
828 * Advance selection to previous/next item in list.
829 * \param list_view List to process.
830 * \param forward Set to <i>TRUE</i> to select next or <i>FALSE</i> for
833 static void completion_window_advance_selection(GtkTreeView *list_view, gboolean forward)
835 GtkTreeSelection *selection;
839 cm_return_if_fail(list_view != NULL);
841 selection = gtk_tree_view_get_selection(list_view);
842 if (!gtk_tree_selection_get_selected(selection, &model, &iter))
846 forward = gtk_tree_model_iter_next(model, &iter);
848 gtk_tree_selection_select_iter(selection, &iter);
852 prev = gtk_tree_model_get_path(model, &iter);
856 if (gtk_tree_path_prev(prev))
857 gtk_tree_selection_select_path(selection, prev);
859 gtk_tree_path_free(prev);
864 * Resize window to accommodate maximum number of address entries.
865 * \param cw Completion window.
867 static void addrcompl_resize_window( CompletionWindow *cw ) {
869 gint x, y, width, height, depth;
871 /* Get current geometry of window */
872 #if !GTK_CHECK_VERSION(3, 0, 0)
873 gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height, &depth );
875 gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height );
878 /* simple _hide breaks size requisition !? */
879 #if !GTK_CHECK_VERSION(3, 0, 0)
880 gtk_widget_hide_all( cw->window );
881 gtk_widget_show_all( cw->window );
883 gtk_widget_hide( cw->window );
884 gtk_widget_show( cw->window );
886 gtk_widget_size_request( cw->list_view, &r );
888 /* Adjust window height to available screen space */
889 if( y + r.height > gdk_screen_height())
890 r.height = gdk_screen_height() - y;
892 gtk_widget_set_size_request(cw->window, width, r.height);
894 gdk_pointer_grab(gtk_widget_get_window(cw->window), TRUE,
895 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
896 GDK_BUTTON_RELEASE_MASK,
897 NULL, NULL, GDK_CURRENT_TIME);
898 gdk_keyboard_grab(gtk_widget_get_window(cw->window), FALSE, GDK_CURRENT_TIME);
899 gtk_grab_add(cw->window);
903 static GdkPixbuf *group_pixbuf = NULL;
904 static GdkPixbuf *email_pixbuf = NULL;
907 * Add an address the completion window address list.
908 * \param cw Completion window.
909 * \param address Address to add.
911 static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
914 GtkTreeSelection *selection;
915 gboolean is_group = FALSE;
916 GList *grp_emails = NULL;
917 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cw->list_view)));
921 stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_TWO, &group_pixbuf);
922 g_object_ref(G_OBJECT(group_pixbuf));
925 stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_ONE, &email_pixbuf);
926 g_object_ref(G_OBJECT(email_pixbuf));
928 /* g_print( "\t\tAdding :%s\n", address ); */
929 if (strstr(address, " <!--___group___-->")) {
931 if (_groupAddresses_)
932 grp_emails = g_hash_table_lookup(_groupAddresses_, GINT_TO_POINTER(g_str_hash(address)));
933 *(strstr(address, " <!--___group___-->")) = '\0';
934 pixbuf = group_pixbuf;
935 } else if (strchr(address, '@') && strchr(address, '<') &&
936 strchr(address, '>')) {
937 pixbuf = email_pixbuf;
941 if (is_group && !_allowCommas_)
943 gtk_list_store_append(store, &iter);
944 gtk_list_store_set(store, &iter,
945 ADDR_COMPL_ICON, pixbuf,
946 ADDR_COMPL_ADDRESS, address,
947 ADDR_COMPL_ISGROUP, is_group,
948 ADDR_COMPL_GROUPLIST, grp_emails,
953 addrcompl_resize_window( cw );
954 gtk_grab_add( cw->window );
956 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cw->list_view));
957 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
959 if( cw->listCount == 1 ) {
960 /* Select first row for now */
961 gtk_tree_selection_select_iter(selection, &iter);
964 else if( cw->listCount == 2 ) {
965 gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
966 /* Move off first row */
967 gtk_tree_selection_select_iter(selection, &iter);
972 void addrcompl_reflect_prefs_pixmap_theme(void) {
974 g_object_unref(G_OBJECT(group_pixbuf));
978 g_object_unref(G_OBJECT(email_pixbuf));
984 * Completion idle function. This function is called by the main (UI) thread
985 * during UI idle time while an address search is in progress. Items from the
986 * display queue are processed and appended to the address list.
988 * \param data Target completion window to receive email addresses.
989 * \return <i>TRUE</i> to ensure that idle event do not get ignored.
991 static gboolean addrcompl_idle( gpointer data ) {
995 /* Process all entries in display queue */
996 pthread_mutex_lock( & _completionMutex_ );
997 if( _displayQueue_ ) {
998 node = _displayQueue_;
1000 address = node->data;
1001 /* g_print( "address ::: %s :::\n", address ); */
1002 addrcompl_add_entry( _compWindow_, address );
1004 node = g_list_next( node );
1006 g_list_free( _displayQueue_ );
1007 _displayQueue_ = NULL;
1009 pthread_mutex_unlock( & _completionMutex_ );
1016 * Callback entry point. The background thread (if any) appends the address
1017 * list to the display queue.
1018 * \param sender Sender of query.
1019 * \param queryID Query ID of search request.
1020 * \param listEMail List of zero of more email objects that met search
1022 * \param data Query data.
1024 #ifndef USE_NEW_ADDRBOOK
1025 static gint addrcompl_callback_entry(
1026 gpointer sender, gint queryID, GList *listEMail, gpointer data )
1031 /* g_print( "addrcompl_callback_entry::queryID=%d\n", queryID ); */
1032 pthread_mutex_lock( & _completionMutex_ );
1033 if( queryID == _queryID_ ) {
1034 /* Append contents to end of display queue */
1037 ItemEMail *email = node->data;
1039 address = addritem_format_email( email );
1040 /* g_print( "\temail/address ::%s::\n", address ); */
1041 _displayQueue_ = g_list_append( _displayQueue_, address );
1042 node = g_list_next( node );
1045 g_list_free( listEMail );
1046 pthread_mutex_unlock( & _completionMutex_ );
1053 * Clear the display queue.
1055 static void addrcompl_clear_queue( void ) {
1056 /* Clear out display queue */
1057 pthread_mutex_lock( & _completionMutex_ );
1059 g_list_free( _displayQueue_ );
1060 _displayQueue_ = NULL;
1062 pthread_mutex_unlock( & _completionMutex_ );
1066 * Add a single address entry into the display queue.
1067 * \param address Address to append.
1069 static void addrcompl_add_queue( gchar *address ) {
1070 pthread_mutex_lock( & _completionMutex_ );
1071 _displayQueue_ = g_list_append( _displayQueue_, address );
1072 pthread_mutex_unlock( & _completionMutex_ );
1076 * Load list with entries from local completion index.
1078 static void addrcompl_load_local( void ) {
1081 for (count = 0; count < get_completion_count(); count++) {
1084 address = get_complete_address( count );
1085 /* g_print( "\taddress ::%s::\n", address ); */
1087 /* Append contents to end of display queue */
1088 addrcompl_add_queue( address );
1095 static void addrcompl_start_search( void ) {
1096 #ifndef USE_NEW_ADDRBOOK
1099 searchTerm = g_strdup( _compWindow_->searchTerm );
1101 /* Setup the search */
1102 _queryID_ = addrindex_setup_search(
1103 searchTerm, NULL, addrcompl_callback_entry );
1104 g_free( searchTerm );
1106 /* g_print( "addrcompl_start_search::queryID=%d\n", _queryID_ ); */
1108 /* Load local stuff */
1109 addrcompl_load_local();
1111 /* Sit back and wait until something happens */
1112 _completionIdleID_ =
1113 g_idle_add( (GSourceFunc) addrcompl_idle, NULL );
1114 /* g_print( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
1116 #ifndef USE_NEW_ADDRBOOK
1117 addrindex_start_search( _queryID_ );
1124 * Apply the current selection in the list to the entry field. Focus is also
1125 * moved to the next widget so that Tab key works correctly.
1126 * \param list_view List to process.
1127 * \param entry Address entry field.
1128 * \param move_focus Move focus to the next widget ?
1130 static void completion_window_apply_selection(GtkTreeView *list_view,
1132 gboolean move_focus)
1134 gchar *address = NULL, *text = NULL;
1137 GtkTreeSelection *selection;
1138 GtkTreeModel *model;
1140 gboolean is_group = FALSE;
1141 cm_return_if_fail(list_view != NULL);
1142 cm_return_if_fail(entry != NULL);
1143 GList *grp_emails = NULL;
1145 selection = gtk_tree_view_get_selection(list_view);
1146 if (! gtk_tree_selection_get_selected(selection, &model, &iter))
1149 /* First remove the idler */
1150 if( _completionIdleID_ != 0 ) {
1151 g_source_remove( _completionIdleID_ );
1152 _completionIdleID_ = 0;
1155 /* Process selected item */
1156 gtk_tree_model_get(model, &iter, ADDR_COMPL_ADDRESS, &text,
1157 ADDR_COMPL_ISGROUP, &is_group,
1158 ADDR_COMPL_GROUPLIST, &grp_emails,
1161 address = get_address_from_edit(entry, &cursor_pos);
1163 replace_address_in_edit(entry, text, cursor_pos, is_group, grp_emails);
1166 /* Move focus to next widget */
1167 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1168 if( parent && move_focus) {
1169 gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
1174 * Start address completion. Should be called when creating the main window
1175 * containing address completion entries.
1176 * \param mainwindow Main window.
1178 void address_completion_start(GtkWidget *mainwindow)
1180 start_address_completion(NULL);
1182 /* register focus change hook */
1183 g_signal_connect(G_OBJECT(mainwindow), "set_focus",
1184 G_CALLBACK(address_completion_mainwindow_set_focus),
1189 * Need unique data to make unregistering signal handler possible for the auto
1192 #define COMPLETION_UNIQUE_DATA (GINT_TO_POINTER(0xfeefaa))
1195 * Register specified entry widget for address completion.
1196 * \param entry Address entry field.
1198 void address_completion_register_entry(GtkEntry *entry, gboolean allow_commas)
1200 cm_return_if_fail(entry != NULL);
1201 cm_return_if_fail(GTK_IS_ENTRY(entry));
1203 /* add hooked property */
1204 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, entry);
1205 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS, GINT_TO_POINTER(allow_commas));
1207 /* add keypress event */
1208 g_signal_connect_closure
1209 (G_OBJECT(entry), "key_press_event",
1210 g_cclosure_new(G_CALLBACK(address_completion_entry_key_pressed),
1211 COMPLETION_UNIQUE_DATA,
1217 * Unregister specified entry widget from address completion operations.
1218 * \param entry Address entry field.
1220 void address_completion_unregister_entry(GtkEntry *entry)
1224 cm_return_if_fail(entry != NULL);
1225 cm_return_if_fail(GTK_IS_ENTRY(entry));
1227 entry_obj = g_object_get_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
1228 cm_return_if_fail(entry_obj);
1229 cm_return_if_fail(G_OBJECT(entry_obj) == G_OBJECT(entry));
1231 /* has the hooked property? */
1232 g_object_set_data(G_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
1234 /* remove the hook */
1235 g_signal_handlers_disconnect_by_func(G_OBJECT(entry),
1236 G_CALLBACK(address_completion_entry_key_pressed),
1237 COMPLETION_UNIQUE_DATA);
1241 * End address completion. Should be called when main window with address
1242 * completion entries terminates. NOTE: this function assumes that it is
1243 * called upon destruction of the window.
1244 * \param mainwindow Main window.
1246 void address_completion_end(GtkWidget *mainwindow)
1248 /* if address_completion_end() is really called on closing the window,
1249 * we don't need to unregister the set_focus_cb */
1250 end_address_completion();
1253 /* if focus changes to another entry, then clear completion cache */
1254 static void address_completion_mainwindow_set_focus(GtkWindow *window,
1259 if (widget && GTK_IS_ENTRY(widget) &&
1260 g_object_get_data(G_OBJECT(widget), ENTRY_DATA_TAB_HOOK)) {
1261 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), ENTRY_DATA_ALLOW_COMMAS));
1262 clear_completion_cache();
1267 * Listener that watches for tab or other keystroke in address entry field.
1268 * \param entry Address entry field.
1269 * \param ev Event object.
1270 * \param data User data.
1271 * \return <i>TRUE</i>.
1273 static gboolean address_completion_entry_key_pressed(GtkEntry *entry,
1277 if (ev->keyval == GDK_KEY_Tab) {
1278 addrcompl_clear_queue();
1279 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
1280 if( address_completion_complete_address_in_entry( entry, TRUE ) ) {
1281 /* route a void character to the default handler */
1282 /* this is a dirty hack; we're actually changing a key
1283 * reported by the system. */
1284 ev->keyval = GDK_KEY_AudibleBell_Enable;
1285 ev->state &= ~GDK_SHIFT_MASK;
1288 address_completion_create_completion_window(entry);
1290 /* Start remote queries */
1291 addrcompl_start_search();
1298 } else if (ev->keyval == GDK_KEY_Shift_L
1299 || ev->keyval == GDK_KEY_Shift_R
1300 || ev->keyval == GDK_KEY_Control_L
1301 || ev->keyval == GDK_KEY_Control_R
1302 || ev->keyval == GDK_KEY_Caps_Lock
1303 || ev->keyval == GDK_KEY_Shift_Lock
1304 || ev->keyval == GDK_KEY_Meta_L
1305 || ev->keyval == GDK_KEY_Meta_R
1306 || ev->keyval == GDK_KEY_Alt_L
1307 || ev->keyval == GDK_KEY_Alt_R) {
1308 /* these buttons should not clear the cache... */
1310 clear_completion_cache();
1315 * Initialize search term for address completion.
1316 * \param entry Address entry field.
1318 static gboolean address_completion_complete_address_in_entry(GtkEntry *entry,
1321 gint ncount, cursor_pos;
1322 gchar *searchTerm, *new = NULL;
1324 cm_return_val_if_fail(entry != NULL, FALSE);
1326 if (!gtk_widget_has_focus(GTK_WIDGET(entry))) return FALSE;
1328 /* get an address component from the cursor */
1329 searchTerm = get_address_from_edit( entry, &cursor_pos );
1330 if( ! searchTerm ) return FALSE;
1331 /* g_print( "search for :::%s:::\n", searchTerm ); */
1333 /* Clear any existing search */
1334 g_free( _compWindow_->searchTerm );
1335 _compWindow_->searchTerm = g_strdup( searchTerm );
1337 /* Perform search on local completion index */
1338 ncount = complete_address( searchTerm );
1340 new = get_next_complete_address();
1343 #if (!defined(USE_LDAP) && !defined(GENERIC_UMPC))
1344 /* Select the address if there is only one match */
1346 /* Display selected address in entry field */
1347 gchar *addr = get_complete_address(1);
1348 if (addr && !strstr(addr, " <!--___group___-->")) {
1349 replace_address_in_edit(entry, addr, cursor_pos, FALSE, NULL);
1350 /* Discard the window */
1351 clear_completion_cache();
1355 /* Make sure that drop-down appears uniform! */
1359 addrcompl_add_queue( g_strdup( searchTerm ) );
1361 g_free( searchTerm );
1367 * Create new address completion window for specified entry.
1368 * \param entry_ Entry widget to associate with window.
1370 static void address_completion_create_completion_window( GtkEntry *entry_ )
1372 gint x, y, height, width, depth;
1373 GtkWidget *scroll, *list_view;
1376 GtkWidget *entry = GTK_WIDGET(entry_);
1379 /* Create new window and list */
1380 window = gtk_window_new(GTK_WINDOW_POPUP);
1381 list_view = addr_compl_list_view_create(_compWindow_);
1383 /* Destroy any existing window */
1384 addrcompl_destroy_window( _compWindow_ );
1386 /* Create new object */
1387 _compWindow_->window = window;
1388 _compWindow_->entry = entry;
1389 _compWindow_->list_view = list_view;
1390 _compWindow_->listCount = 0;
1391 _compWindow_->in_mouse = FALSE;
1393 scroll = gtk_scrolled_window_new(NULL, NULL);
1394 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
1395 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1396 gtk_container_add(GTK_CONTAINER(window), scroll);
1397 gtk_container_add(GTK_CONTAINER(scroll), list_view);
1398 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
1400 /* Use entry widget to create initial window */
1401 gdkwin = gtk_widget_get_window(entry),
1402 #if !GTK_CHECK_VERSION(3, 0, 0)
1403 gdk_window_get_geometry(gdkwin, &x, &y, &width, &height, &depth);
1405 gdk_window_get_geometry(gdkwin, &x, &y, &width, &height);
1407 gdk_window_get_origin (gdkwin, &x, &y);
1409 gtk_window_move(GTK_WINDOW(window), x, y);
1411 /* Resize window to fit initial (empty) address list */
1412 gtk_widget_size_request( list_view, &r );
1413 gtk_widget_set_size_request( window, width, r.height );
1414 gtk_widget_show_all( window );
1415 gtk_widget_size_request( list_view, &r );
1417 /* Setup handlers */
1418 g_signal_connect(G_OBJECT(list_view), "button_press_event",
1419 G_CALLBACK(list_view_button_press),
1422 g_signal_connect(G_OBJECT(list_view), "button_release_event",
1423 G_CALLBACK(list_view_button_release),
1426 g_signal_connect(G_OBJECT(window),
1427 "button-press-event",
1428 G_CALLBACK(completion_window_button_press),
1430 g_signal_connect(G_OBJECT(window),
1432 G_CALLBACK(completion_window_key_press),
1434 gdk_pointer_grab(gtk_widget_get_window(window), TRUE,
1435 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
1436 GDK_BUTTON_RELEASE_MASK,
1437 NULL, NULL, GDK_CURRENT_TIME);
1438 gdk_keyboard_grab(gtk_widget_get_window(window), FALSE, GDK_CURRENT_TIME);
1439 gtk_grab_add( window );
1443 * Respond to button press in completion window. Check if mouse click is
1444 * anywhere outside the completion window. In that case the completion
1445 * window is destroyed, and the original searchTerm is restored.
1447 * \param widget Window object.
1448 * \param event Event.
1449 * \param compWin Reference to completion window.
1451 static gboolean completion_window_button_press(GtkWidget *widget,
1452 GdkEventButton *event,
1453 CompletionWindow *compWin )
1455 GtkWidget *event_widget, *entry;
1458 gboolean restore = TRUE;
1460 cm_return_val_if_fail(compWin != NULL, FALSE);
1462 entry = compWin->entry;
1463 cm_return_val_if_fail(entry != NULL, FALSE);
1465 /* Test where mouse was clicked */
1466 event_widget = gtk_get_event_widget((GdkEvent *)event);
1467 if (event_widget != widget) {
1468 while (event_widget) {
1469 if (event_widget == widget)
1471 else if (event_widget == entry) {
1475 event_widget = gtk_widget_get_parent(event_widget);
1480 /* Clicked outside of completion window - restore */
1481 searchTerm = _compWindow_->searchTerm;
1482 g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
1483 replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
1486 clear_completion_cache();
1487 addrcompl_destroy_window( _compWindow_ );
1493 * Respond to key press in completion window.
1494 * \param widget Window object.
1495 * \param event Event.
1496 * \param compWind Reference to completion window.
1498 static gboolean completion_window_key_press(GtkWidget *widget,
1500 CompletionWindow *compWin )
1502 GdkEventKey tmp_event;
1506 GtkWidget *list_view;
1508 cm_return_val_if_fail(compWin != NULL, FALSE);
1510 entry = compWin->entry;
1511 list_view = compWin->list_view;
1512 cm_return_val_if_fail(entry != NULL, FALSE);
1514 /* allow keyboard navigation in the alternatives tree view */
1515 if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down ||
1516 event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down) {
1517 completion_window_advance_selection
1518 (GTK_TREE_VIEW(list_view),
1519 event->keyval == GDK_KEY_Down ||
1520 event->keyval == GDK_KEY_Page_Down ? TRUE : FALSE);
1524 /* make tab move to next field */
1525 if( event->keyval == GDK_KEY_Tab ) {
1526 /* Reference to parent */
1527 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1529 /* Discard the window */
1530 clear_completion_cache();
1531 addrcompl_destroy_window( _compWindow_ );
1533 /* Move focus to next widget */
1535 gtk_widget_child_focus( parent, GTK_DIR_TAB_FORWARD );
1540 /* make backtab move to previous field */
1541 if( event->keyval == GDK_KEY_ISO_Left_Tab ) {
1542 /* Reference to parent */
1543 parent = gtk_widget_get_parent(GTK_WIDGET(entry));
1545 /* Discard the window */
1546 clear_completion_cache();
1547 addrcompl_destroy_window( _compWindow_ );
1549 /* Move focus to previous widget */
1551 gtk_widget_child_focus( parent, GTK_DIR_TAB_BACKWARD );
1555 _allowCommas_ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(entry), ENTRY_DATA_ALLOW_COMMAS));
1557 /* look for presses that accept the selection */
1558 if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_space ||
1559 event->keyval == GDK_KEY_KP_Enter ||
1560 (_allowCommas_ && event->keyval == GDK_KEY_comma)) {
1561 /* User selected address with a key press */
1563 /* Display selected address in entry field */
1564 completion_window_apply_selection(
1565 GTK_TREE_VIEW(list_view), GTK_ENTRY(entry),
1566 event->keyval != GDK_KEY_comma);
1568 if (event->keyval == GDK_KEY_comma) {
1569 gint pos = gtk_editable_get_position(GTK_EDITABLE(entry));
1570 gtk_editable_insert_text(GTK_EDITABLE(entry), ", ", 2, &pos);
1571 gtk_editable_set_position(GTK_EDITABLE(entry), pos + 1);
1574 /* Discard the window */
1575 clear_completion_cache();
1576 addrcompl_destroy_window( _compWindow_ );
1580 /* key state keys should never be handled */
1581 if (event->keyval == GDK_KEY_Shift_L
1582 || event->keyval == GDK_KEY_Shift_R
1583 || event->keyval == GDK_KEY_Control_L
1584 || event->keyval == GDK_KEY_Control_R
1585 || event->keyval == GDK_KEY_Caps_Lock
1586 || event->keyval == GDK_KEY_Shift_Lock
1587 || event->keyval == GDK_KEY_Meta_L
1588 || event->keyval == GDK_KEY_Meta_R
1589 || event->keyval == GDK_KEY_Alt_L
1590 || event->keyval == GDK_KEY_Alt_R) {
1594 /* some other key, let's restore the searchTerm (orignal text) */
1595 searchTerm = _compWindow_->searchTerm;
1596 g_free(get_address_from_edit(GTK_ENTRY(entry), &cursor_pos));
1597 replace_address_in_edit(GTK_ENTRY(entry), searchTerm, cursor_pos, FALSE, NULL);
1599 /* make sure anything we typed comes in the edit box */
1600 tmp_event.type = event->type;
1601 tmp_event.window = gtk_widget_get_window(GTK_WIDGET(entry));
1602 tmp_event.send_event = TRUE;
1603 tmp_event.time = event->time;
1604 tmp_event.state = event->state;
1605 tmp_event.keyval = event->keyval;
1606 tmp_event.length = event->length;
1607 tmp_event.string = event->string;
1608 gtk_widget_event(entry, (GdkEvent *)&tmp_event);
1610 /* and close the completion window */
1611 clear_completion_cache();
1612 addrcompl_destroy_window( _compWindow_ );
1618 * ============================================================================
1619 * Publically accessible functions.
1620 * ============================================================================
1624 * Setup completion object.
1626 void addrcompl_initialize( void ) {
1627 /* g_print( "addrcompl_initialize...\n" ); */
1628 if( ! _compWindow_ ) {
1629 _compWindow_ = addrcompl_create_window();
1632 _completionIdleID_ = 0;
1633 /* g_print( "addrcompl_initialize...done\n" ); */
1637 * Teardown completion object.
1639 void addrcompl_teardown( void ) {
1640 /* g_print( "addrcompl_teardown...\n" ); */
1641 addrcompl_free_window( _compWindow_ );
1642 _compWindow_ = NULL;
1643 if( _displayQueue_ ) {
1644 g_list_free( _displayQueue_ );
1646 _displayQueue_ = NULL;
1647 _completionIdleID_ = 0;
1648 /* g_print( "addrcompl_teardown...done\n" ); */
1652 * tree view functions
1655 static GtkListStore *addr_compl_create_store(void)
1657 return gtk_list_store_new(N_ADDR_COMPL_COLUMNS,
1665 static GtkWidget *addr_compl_list_view_create(CompletionWindow *window)
1667 GtkTreeView *list_view;
1668 GtkTreeSelection *selector;
1669 GtkTreeModel *model;
1671 model = GTK_TREE_MODEL(addr_compl_create_store());
1672 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
1673 g_object_unref(model);
1675 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1676 gtk_tree_view_set_headers_visible(list_view, FALSE);
1678 selector = gtk_tree_view_get_selection(list_view);
1679 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1680 gtk_tree_selection_set_select_function(selector, addr_compl_selected,
1683 /* create the columns */
1684 addr_compl_create_list_view_columns(GTK_WIDGET(list_view));
1686 return GTK_WIDGET(list_view);
1689 static void addr_compl_create_list_view_columns(GtkWidget *list_view)
1691 GtkTreeViewColumn *column;
1692 GtkCellRenderer *renderer;
1694 renderer = gtk_cell_renderer_pixbuf_new();
1695 column = gtk_tree_view_column_new_with_attributes
1697 "pixbuf", ADDR_COMPL_ICON, NULL);
1698 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1699 renderer = gtk_cell_renderer_text_new();
1700 column = gtk_tree_view_column_new_with_attributes
1701 ("", renderer, "text", ADDR_COMPL_ADDRESS, NULL);
1702 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1705 static gboolean list_view_button_press(GtkWidget *widget, GdkEventButton *event,
1706 CompletionWindow *window)
1708 if (window && event && event->type == GDK_BUTTON_PRESS) {
1709 window->in_mouse = TRUE;
1714 static gboolean list_view_button_release(GtkWidget *widget, GdkEventButton *event,
1715 CompletionWindow *window)
1717 if (window && event && event->type == GDK_BUTTON_RELEASE) {
1718 window->in_mouse = FALSE;
1723 static gboolean addr_compl_selected(GtkTreeSelection *selector,
1724 GtkTreeModel *model,
1726 gboolean currently_selected,
1729 CompletionWindow *window = data;
1731 if (currently_selected)
1734 if (!window->in_mouse)
1737 /* XXX: select the entry and kill window later... select is called before
1738 * any other mouse events handlers including the tree view internal one;
1739 * not using a time out would result in a crash. if this doesn't work
1740 * safely, maybe we should set variables when receiving button presses
1741 * in the tree view. */
1742 if (!window->destroying) {
1743 window->destroying = TRUE;
1744 g_idle_add((GSourceFunc) addr_compl_defer_select_destruct, data);
1750 static gboolean addr_compl_defer_select_destruct(CompletionWindow *window)
1752 GtkEntry *entry = GTK_ENTRY(window->entry);
1754 completion_window_apply_selection(GTK_TREE_VIEW(window->list_view),
1757 clear_completion_cache();
1759 addrcompl_destroy_window(window);