From f096c882c0d012b85bc8d3cb9104a2334488a667 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 4 Mar 2004 04:15:33 +0000 Subject: ** See #54991. 2004-03-04 Not Zed ** See #54991. * gui/component/select-names/e-select-names-completion.c (e_select_names_completion_start_query): dont try to unref a null query. (name_style_query): use a GString to build the query, so we can use e_sexp_encode_string to properly encode the sub terms. svn path=/trunk/; revision=24957 --- .../select-names/e-select-names-completion.c | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'addressbook/gui/component/select-names') diff --git a/addressbook/gui/component/select-names/e-select-names-completion.c b/addressbook/gui/component/select-names/e-select-names-completion.c index b80611b9ff..e3fa256dc8 100644 --- a/addressbook/gui/component/select-names/e-select-names-completion.c +++ b/addressbook/gui/component/select-names/e-select-names-completion.c @@ -39,6 +39,8 @@ #include #include +#include + typedef struct { EBook *book; guint book_view_tag; @@ -261,7 +263,8 @@ name_style_query (ESelectNamesCompletion *comp, const gchar *field) gchar *cpy = g_strdup (comp->priv->query_text), *c; gchar **strv; gchar *query; - gint i, count=0; + gint i; + GString *out = g_string_new(""); for (c = cpy; *c; ++c) { if (*c == ',') @@ -269,23 +272,23 @@ name_style_query (ESelectNamesCompletion *comp, const gchar *field) } strv = g_strsplit (cpy, " ", 0); + if (strv[0] && strv[1]) + g_string_append(out, "(and "); for (i=0; strv[i]; ++i) { - gchar *old; - ++count; - g_strstrip (strv[i]); - old = strv[i]; - strv[i] = g_strdup_printf ("(beginswith \"%s\" \"%s\")", field, old); - g_free (old); + if (i==0) + g_string_append(out, "(beginswith "); + else + g_string_append(out, " (beginswith "); + e_sexp_encode_string(out, field); + g_strstrip(strv[i]); + e_sexp_encode_string(out, strv[i]); + g_string_append(out, ")"); } + if (strv[0] && strv[1]) + g_string_append(out, ")"); - if (count == 1) { - query = strv[0]; - strv[0] = NULL; - } else { - gchar *joined = g_strjoinv (" ", strv); - query = g_strdup_printf ("(and %s)", joined); - g_free (joined); - } + query = out->str; + g_string_free(out, FALSE); g_free (cpy); g_strfreev (strv); @@ -1025,12 +1028,12 @@ e_select_names_completion_start_query (ESelectNamesCompletion *comp, const gchar that the search is over. */ if (!comp->priv->pending_completion_seq) e_select_names_completion_done (E_SELECT_NAMES_COMPLETION (comp)); + + e_book_query_unref (query); } else { g_free (comp->priv->query_text); comp->priv->query_text = NULL; } - e_book_query_unref (query); - } else { comp->priv->waiting_query = g_strdup (query_text); -- cgit v1.2.3