#include "stock_pixmap.h"
#include <pthread.h>
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
#include "addrindex.h"
#else
#include "addressbook-dbus.h"
return (strcasestr(haystack, needle) != NULL ? 0 : 1);
}
+/**
+ * Function used by GTK to compare elements for sorting
+ * name match beginning > name match after space > email address
+ * match beginning and full match before @ > email adress
+ * match beginning. Otherwise match position in string.
+ * \param a first element in comparsion
+ * \param b second element in comparison
+ */
+static gint weight_addr_match(const address_entry* addr)
+{
+ gint n_weight = addr->name ? strlen(addr->name): 0;
+ gint a_weight = addr->address ? strlen(addr->address) : n_weight;
+ gchar* match = NULL;
+
+ if (addr->name)
+ match = strcasestr(addr->name, g_completion_prefix);
+
+ if (match != NULL) {
+ if (match == addr->name)
+ n_weight = -4;
+ else if (match > addr->name && *(match - 1) == ' ')
+ n_weight = -3;
+ else
+ n_weight = match - addr->name;
+ }
+
+ if (addr->address) {
+ match = strcasestr(addr->address, g_completion_prefix);
+ if (match != NULL) {
+ if (match == addr->address)
+ a_weight = -1;
+ else
+ a_weight = match - addr->address;
+
+ if (strlen(match) > strlen(g_completion_prefix)
+ && *(match + strlen(g_completion_prefix)) == '@')
+ a_weight--;
+ }
+ }
+
+ if (n_weight == -4 && a_weight < 0)
+ n_weight = -5;
+
+ return MIN(a_weight, n_weight);
+}
+
+static gint addr_comparison_func(gconstpointer a, gconstpointer b)
+{
+ const address_entry* a_ref = (const address_entry*)a;
+ const address_entry* b_ref = (const address_entry*)b;
+ gint a_weight = weight_addr_match(a_ref);
+ gint b_weight = weight_addr_match(b_ref);
+ gint cmp;
+
+ if (a_weight < b_weight)
+ return -1;
+ else if (a_weight > b_weight)
+ return 1;
+ else {
+ cmp = strcmp(a_ref->name, b_ref->name);
+ return cmp ? cmp : g_strcmp0(a_ref->address, b_ref->address);
+ }
+}
+
/**
* Initialize all completion index data.
*/
free_all_addresses();
free_completion_list();
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
addrindex_load_completion( add_address, folderpath );
#else
GError* error = NULL;
}
#endif
/* plugins may hook in here to modify/extend the completion list */
- hooks_invoke(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, &g_address_list);
+ if(!folderpath) {
+ hooks_invoke(ADDDRESS_COMPLETION_BUILD_ADDRESS_LIST_HOOKLIST, &g_address_list);
+ }
g_address_list = g_list_reverse(g_address_list);
g_completion_list = g_list_reverse(g_completion_list);
}
count = cpl + 1; /* index 0 is the original prefix */
g_completion_next = 1; /* we start at the first completed one */
+ if (prefs_common.address_search_wildcard)
+ g_completion_addresses = g_slist_sort(g_completion_addresses,
+ addr_comparison_func);
} else {
g_free(g_completion_prefix);
g_completion_prefix = NULL;
*/
static void addrcompl_destroy_window( CompletionWindow *cw ) {
/* Stop all searches currently in progress */
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
addrindex_stop_search( _queryID_ );
#endif
/* Remove idler function... or application may not terminate */
gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height );
#endif
- /* simple _hide breaks size requisition !? */
-#if !GTK_CHECK_VERSION(3, 0, 0)
- gtk_widget_hide_all( cw->window );
- gtk_widget_show_all( cw->window );
-#else
- gtk_widget_hide( cw->window );
- gtk_widget_show( cw->window );
-#endif
+ gtk_widget_queue_resize_no_redraw(cw->list_view);
gtk_widget_size_request( cw->list_view, &r );
/* Adjust window height to available screen space */
GdkPixbuf *pixbuf;
if (!group_pixbuf) {
- stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_TWO, &group_pixbuf);
+ stock_pixbuf_gdk(STOCK_PIXMAP_ADDR_TWO, &group_pixbuf);
g_object_ref(G_OBJECT(group_pixbuf));
}
if (!email_pixbuf) {
- stock_pixbuf_gdk(cw->list_view, STOCK_PIXMAP_ADDR_ONE, &email_pixbuf);
+ stock_pixbuf_gdk(STOCK_PIXMAP_ADDR_ONE, &email_pixbuf);
g_object_ref(G_OBJECT(email_pixbuf));
}
/* g_print( "\t\tAdding :%s\n", address ); */
* criteria.
* \param data Query data.
*/
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
static gint addrcompl_callback_entry(
gpointer sender, gint queryID, GList *listEMail, gpointer data )
{
/* Clear out display queue */
pthread_mutex_lock( & _completionMutex_ );
- g_list_free( _displayQueue_ );
+ g_list_free_full( _displayQueue_, g_free );
_displayQueue_ = NULL;
pthread_mutex_unlock( & _completionMutex_ );
* Start the search.
*/
static void addrcompl_start_search( void ) {
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
gchar *searchTerm;
searchTerm = g_strdup( _compWindow_->searchTerm );
g_idle_add( (GSourceFunc) addrcompl_idle, NULL );
/* g_print( "addrindex_start_search::queryID=%d\n", _queryID_ ); */
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
addrindex_start_search( _queryID_ );
#else
(GTK_TREE_VIEW(list_view),
event->keyval == GDK_KEY_Down ||
event->keyval == GDK_KEY_Page_Down ? TRUE : FALSE);
- return FALSE;
+ return TRUE;
}
/* make tab move to next field */
return FALSE;
}
+gboolean found_in_addressbook(const gchar *address)
+{
+ gchar *addr = NULL;
+ gboolean found = FALSE;
+ gint num_addr = 0;
+
+ if (!address)
+ return FALSE;
+
+ addr = g_strdup(address);
+ extract_address(addr);
+ num_addr = complete_address(addr);
+ if (num_addr > 1) {
+ /* skip first item (this is the search string itself) */
+ int i = 1;
+ for (; i < num_addr && !found; i++) {
+ gchar *caddr = get_complete_address(i);
+ extract_address(caddr);
+ if (strcasecmp(caddr, addr) == 0)
+ found = TRUE;
+ g_free(caddr);
+ }
+ }
+ g_free(addr);
+ return found;
+}
/*
* End of Source.
*/
-