Fix wrong address book contact in message list's From column and potentially
[claws.git] / src / addr_compl.c
index 89f1b56315bdf3331552387756b39551752a665e..104ce6661f8e73d5eb96230aa713ae6d7d1cae3f 100644 (file)
@@ -164,6 +164,15 @@ static gchar *completion_func(gpointer data)
        return ((completion_entry *)data)->string;
 } 
 
+static gint addr_completion_func(const gchar *needle, const gchar *haystack,
+               gsize n)
+{
+       if (needle == NULL || haystack == NULL)
+               return 1;
+
+       return (strcasestr(haystack, needle) != NULL ? 0 : 1);
+}
+
 /**
  * Initialize all completion index data.
  */
@@ -173,6 +182,17 @@ static void init_all(void)
        cm_return_if_fail(g_completion != NULL);
 }
 
+/**
+ * set the compare function (default is strncmp)
+ */
+static void set_match_any_part(const gboolean any_part)
+{
+       if (any_part && prefs_common.address_search_wildcard)
+               g_completion_set_compare(g_completion, addr_completion_func);
+       else
+               g_completion_set_compare(g_completion, strncmp);
+}
+
 static void free_all_addresses(void)
 {
        GList *walk;
@@ -256,30 +276,30 @@ static gint add_address(const gchar *name, const gchar *address,
 {
        address_entry *ae;
 
-       if (!name || !address) {
-               if (address || nick || alias || !grp_emails) 
-                       return -1;
-       }
+       if (!address && !grp_emails)
+               return -1;
 
-       ae = g_new0(address_entry, 1);
+       if (!name)
+               name = "";
 
+       ae = g_new0(address_entry, 1);
        cm_return_val_if_fail(ae != NULL, -1);
 
-       ae->name    = g_strdup(name);
+       ae->name = g_strdup(name);
        ae->address = g_strdup(address);
        ae->grp_emails = grp_emails;
        g_address_list = g_list_prepend(g_address_list, ae);
 
        addr_compl_add_address1(name, ae);
+
        if (address != NULL && *address != '\0')
                addr_compl_add_address1(address, ae);
 
        if (nick != NULL && *nick != '\0')
                addr_compl_add_address1(nick, ae);
 
-       if ( alias != NULL && *alias != '\0') {
+       if (alias != NULL && *alias != '\0')
                addr_compl_add_address1(alias, ae);
-       }
 
        return 0;
 }
@@ -859,11 +879,20 @@ static void addrcompl_resize_window( CompletionWindow *cw ) {
        gint x, y, width, height, depth;
 
        /* Get current geometry of window */
+#if !GTK_CHECK_VERSION(3, 0, 0)
        gdk_window_get_geometry( gtk_widget_get_window( cw->window ), &x, &y, &width, &height, &depth );
+#else
+       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_size_request( cw->list_view, &r );
 
        /* Adjust window height to available screen space */
@@ -950,6 +979,17 @@ static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
 #endif
 }
 
+void addrcompl_reflect_prefs_pixmap_theme(void) {
+       if (group_pixbuf) {
+               g_object_unref(G_OBJECT(group_pixbuf));
+               group_pixbuf = NULL;
+       }
+       if (email_pixbuf) {
+               g_object_unref(G_OBJECT(email_pixbuf));
+               email_pixbuf = NULL;
+       }
+}
+
 /**
  * Completion idle function. This function is called by the main (UI) thread
  * during UI idle time while an address search is in progress. Items from the
@@ -1148,6 +1188,7 @@ static void completion_window_apply_selection(GtkTreeView *list_view,
 void address_completion_start(GtkWidget *mainwindow)
 {
        start_address_completion(NULL);
+       set_match_any_part(TRUE);
 
        /* register focus change hook */
        g_signal_connect(G_OBJECT(mainwindow), "set_focus",
@@ -1369,7 +1410,11 @@ static void address_completion_create_completion_window( GtkEntry *entry_ )
                GTK_SHADOW_OUT);
        /* Use entry widget to create initial window */
        gdkwin = gtk_widget_get_window(entry),
+#if !GTK_CHECK_VERSION(3, 0, 0)
        gdk_window_get_geometry(gdkwin, &x, &y, &width, &height, &depth);
+#else
+       gdk_window_get_geometry(gdkwin, &x, &y, &width, &height);
+#endif
        gdk_window_get_origin (gdkwin, &x, &y);
        y += height;
        gtk_window_move(GTK_WINDOW(window), x, y);