aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-05-19 01:09:31 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-05-19 01:09:31 +0800
commitd4a2e9f382f325a9f1277aa8b1a5de50f10e3b36 (patch)
tree664d0ce5f326c072948c9ffb5892445c4d12b00a /addressbook/gui
parent7cffbe65d1666776db06adc03178560bba9c5b42 (diff)
downloadgsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar.gz
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar.bz2
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar.lz
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar.xz
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.tar.zst
gsoc2013-evolution-d4a2e9f382f325a9f1277aa8b1a5de50f10e3b36.zip
Do a better job constructing match strings, so we never try to use a
2001-05-18 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names-completion.c (match_name): Do a better job constructing match strings, so we never try to use a segment of the name that isn't there (resulting in ugly (null)'s in the string). Boost our score if some part of the name also matches the front part of the e-mail address, so the name match will always trump the e-mail match. svn path=/trunk/; revision=9882
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/component/select-names/e-select-names-completion.c62
1 files changed, 56 insertions, 6 deletions
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 76b8fd0550..dbe54e8a6b 100644
--- a/addressbook/gui/component/select-names/e-select-names-completion.c
+++ b/addressbook/gui/component/select-names/e-select-names-completion.c
@@ -275,8 +275,10 @@ match_name (ESelectNamesCompletion *comp, EDestination *dest, double *score)
{
ECard *card;
gchar *cpy, **strv;
+ const gchar *email;
gint len, i, match_len = 0;
gint match = 0, first_match = 0;
+ gboolean have_given, have_additional, have_family;
card = e_destination_get_card (dest);
@@ -293,6 +295,7 @@ match_name (ESelectNamesCompletion *comp, EDestination *dest, double *score)
len = strlen (strv[i]);
if (card->name->given
+ && *card->name->given
&& !(match & MATCHED_GIVEN_NAME)
&& match_name_fragment (card->name->given, strv[i])) {
@@ -300,12 +303,14 @@ match_name (ESelectNamesCompletion *comp, EDestination *dest, double *score)
}
else if (card->name->additional
+ && *card->name->additional
&& !(match & MATCHED_ADDITIONAL_NAME)
&& match_name_fragment (card->name->additional, strv[i])) {
this_match = MATCHED_ADDITIONAL_NAME;
} else if (card->name->family
+ && *card->name->family
&& !(match & MATCHED_FAMILY_NAME)
&& match_name_fragment (card->name->family, strv[i])) {
@@ -337,12 +342,57 @@ match_name (ESelectNamesCompletion *comp, EDestination *dest, double *score)
*score *= 100;
}
- if (first_match == MATCHED_GIVEN_NAME)
- return g_strdup_printf ("%s %s", card->name->given, card->name->family);
- else if (first_match == MATCHED_ADDITIONAL_NAME)
- return g_strdup_printf ("%s, %s %s", card->name->family, card->name->given, card->name->additional);
- else if (first_match == MATCHED_FAMILY_NAME)
- return g_strdup_printf ("%s, %s", card->name->family, card->name->given);
+ email = e_destination_get_email (dest);
+ if (email) {
+ /* Do the same for the email address. */
+ gchar *at = strchr (email, '@');
+ len = at ? at-email : strlen (email);
+ if ((card->name->given && !e_utf8_strncasecmp (card->name->given, email, MIN (strlen (card->name->given), len)))
+ || (card->name->family && !e_utf8_strncasecmp (card->name->family, email, MIN (strlen (card->name->family), len)))
+ || (card->name->additional && !e_utf8_strncasecmp (card->name->additional, email, MIN (strlen (card->name->additional), len))))
+ *score *= 100;
+ }
+
+ have_given = card->name->given && *card->name->given;
+ have_additional = card->name->additional && *card->name->additional;
+ have_family = card->name->family && *card->name->family;
+
+ if (first_match == MATCHED_GIVEN_NAME) {
+
+ if (have_family)
+ return g_strdup_printf ("%s %s", card->name->given, card->name->family);
+ else
+ return g_strdup_printf (card->name->given);
+
+ } else if (first_match == MATCHED_ADDITIONAL_NAME) {
+
+ if (have_family) {
+
+ return g_strdup_printf ("%s, %s%s%s",
+ card->name->family,
+ have_given ? card->name->given : "",
+ have_given ? " " : "",
+ card->name->additional);
+
+ } else {
+
+ return g_strdup_printf ("%s%s%s",
+ have_given ? card->name->given : "",
+ have_given ? " " : "",
+ card->name->additional);
+
+ }
+
+ } else if (first_match == MATCHED_FAMILY_NAME) {
+
+ if (have_given)
+ return g_strdup_printf ("%s, %s %s",
+ card->name->family,
+ card->name->given,
+ have_additional ? card->name->additional : "");
+ else
+ return g_strdup_printf (card->name->family);
+ }
return NULL;
}