~ubuntu-branches/ubuntu/precise/evolution/precise

« back to all changes in this revision

Viewing changes to addressbook/gui/merging/eab-contact-compare.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-09-08 09:38:57 UTC
  • mfrom: (1.1.84 upstream)
  • Revision ID: package-import@ubuntu.com-20110908093857-6lfl04ke2ns3kx2o
Tags: 3.1.91-0ubuntu1
* New upstream release. (LP: #843769)
* debian/control: bump e-d-s Build-Depends to 3.1.91. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "eab-contact-compare.h"
34
34
 
35
35
/* This is an "optimistic" combiner: the best of the two outcomes is
36
 
   selected. */
 
36
 * selected. */
37
37
static EABContactMatchType
38
38
combine_comparisons (EABContactMatchType prev,
39
 
                     EABContactMatchType new_info)
 
39
                     EABContactMatchType new_info)
40
40
{
41
41
        if (new_info == EAB_CONTACT_MATCH_NOT_APPLICABLE)
42
42
                return prev;
46
46
/*** Name comparisons ***/
47
47
 
48
48
/* This *so* doesn't belong here... at least not implemented in a
49
 
   sucky way like this.  But it can be fixed later. */
 
49
 * sucky way like this.  But it can be fixed later. */
50
50
 
51
51
/* This is very Anglocentric. */
52
52
static const gchar *name_synonyms[][2] = {
83
83
};
84
84
 
85
85
static gboolean
86
 
name_fragment_match_with_synonyms (const gchar *a, const gchar *b, gboolean strict)
 
86
name_fragment_match_with_synonyms (const gchar *a,
 
87
                                   const gchar *b,
 
88
                                   gboolean strict)
87
89
{
88
90
        gint i;
89
91
 
94
96
                return TRUE;
95
97
 
96
98
        /* Check for nicknames.  Yes, the linear search blows. */
97
 
        for (i=0; name_synonyms[i][0]; ++i) {
 
99
        for (i = 0; name_synonyms[i][0]; ++i) {
98
100
 
99
101
                if (!e_utf8_casefold_collate (name_synonyms[i][0], a)
100
102
                    && !e_utf8_casefold_collate (name_synonyms[i][1], b))
109
111
}
110
112
 
111
113
EABContactMatchType
112
 
eab_contact_compare_name_to_string (EContact *contact, const gchar *str)
 
114
eab_contact_compare_name_to_string (EContact *contact,
 
115
                                    const gchar *str)
113
116
{
114
117
        return eab_contact_compare_name_to_string_full (contact, str, FALSE, NULL, NULL, NULL);
115
118
}
116
119
 
117
120
EABContactMatchType
118
 
eab_contact_compare_name_to_string_full (EContact *contact, const gchar *str, gboolean allow_partial_matches,
119
 
                                         gint *matched_parts_out, EABContactMatchPart *first_matched_part_out, gint *matched_character_count_out)
 
121
eab_contact_compare_name_to_string_full (EContact *contact,
 
122
                                         const gchar *str,
 
123
                                         gboolean allow_partial_matches,
 
124
                                         gint *matched_parts_out,
 
125
                                         EABContactMatchPart *first_matched_part_out,
 
126
                                         gint *matched_character_count_out)
120
127
{
121
128
        gchar **namev, **givenv = NULL, **addv = NULL, **familyv = NULL;
122
129
 
172
179
                        this_part_match = EAB_CONTACT_MATCH_PART_NONE;
173
180
 
174
181
                        /* When we are allowing partials, we are strict about the matches we allow.
175
 
                           Does this make sense?  Not really, but it does the right thing for the purposes
176
 
                           of completion. */
 
182
                         * Does this make sense?  Not really, but it does the right thing for the purposes
 
183
                         * of completion. */
177
184
 
178
185
                        if (givenv && this_part_match == EAB_CONTACT_MATCH_PART_NONE) {
179
186
                                for (j = 0; givenv[j]; ++j) {
182
189
                                                this_part_match = EAB_CONTACT_MATCH_PART_GIVEN_NAME;
183
190
 
184
191
                                                /* We remove a piece of a name once it has been matched against, so
185
 
                                                   that "john john" won't match "john doe". */
 
192
                                                 * that "john john" won't match "john doe". */
186
193
                                                g_free (givenv[j]);
187
194
                                                givenv[j] = g_strdup ("");
188
195
                                                break;
261
268
}
262
269
 
263
270
EABContactMatchType
264
 
eab_contact_compare_file_as (EContact *contact1, EContact *contact2)
 
271
eab_contact_compare_file_as (EContact *contact1,
 
272
                             EContact *contact2)
265
273
{
266
274
        EABContactMatchType match_type;
267
275
        gchar *a, *b;
292
300
}
293
301
 
294
302
EABContactMatchType
295
 
eab_contact_compare_name (EContact *contact1, EContact *contact2)
 
303
eab_contact_compare_name (EContact *contact1,
 
304
                          EContact *contact2)
296
305
{
297
306
        EContactName *a, *b;
298
 
        gint matches=0, possible=0;
 
307
        gint matches = 0, possible = 0;
299
308
        gboolean family_match = FALSE;
300
309
 
301
310
        g_return_val_if_fail (E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
337
346
        e_contact_name_free (b);
338
347
 
339
348
        /* Now look at the # of matches and try to intelligently map
340
 
           an EAB_CONTACT_MATCH_* type to it.  Special consideration is given
341
 
           to family-name matches. */
 
349
         * an EAB_CONTACT_MATCH_* type to it.  Special consideration is given
 
350
         * to family-name matches. */
342
351
 
343
352
        if (possible == 0)
344
353
                return EAB_CONTACT_MATCH_NOT_APPLICABLE;
349
358
        if (possible == matches)
350
359
                return family_match ? EAB_CONTACT_MATCH_EXACT : EAB_CONTACT_MATCH_PARTIAL;
351
360
 
352
 
        if (possible == matches+1)
 
361
        if (possible == matches + 1)
353
362
                return family_match ? EAB_CONTACT_MATCH_VAGUE : EAB_CONTACT_MATCH_NONE;
354
363
 
355
364
        return EAB_CONTACT_MATCH_NONE;
358
367
/*** Nickname Comparisons ***/
359
368
 
360
369
EABContactMatchType
361
 
eab_contact_compare_nickname (EContact *contact1, EContact *contact2)
 
370
eab_contact_compare_nickname (EContact *contact1,
 
371
                              EContact *contact2)
362
372
{
363
373
        g_return_val_if_fail (contact1 && E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
364
374
        g_return_val_if_fail (contact2 && E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE);
369
379
/*** E-mail Comparisons ***/
370
380
 
371
381
static gboolean
372
 
match_email_username (const gchar *addr1, const gchar *addr2)
 
382
match_email_username (const gchar *addr1,
 
383
                      const gchar *addr2)
373
384
{
374
385
        gint c1, c2;
375
386
        if (addr1 == NULL || addr2 == NULL)
388
399
}
389
400
 
390
401
static gboolean
391
 
match_email_hostname (const gchar *addr1, const gchar *addr2)
 
402
match_email_hostname (const gchar *addr1,
 
403
                      const gchar *addr2)
392
404
{
393
405
        gint c1, c2;
394
406
        gboolean seen_at1, seen_at2;
436
448
}
437
449
 
438
450
static EABContactMatchType
439
 
compare_email_addresses (const gchar *addr1, const gchar *addr2)
 
451
compare_email_addresses (const gchar *addr1,
 
452
                         const gchar *addr2)
440
453
{
441
454
        if (addr1 == NULL || *addr1 == 0 ||
442
455
            addr2 == NULL || *addr2 == 0)
449
462
}
450
463
 
451
464
EABContactMatchType
452
 
eab_contact_compare_email (EContact *contact1, EContact *contact2)
 
465
eab_contact_compare_email (EContact *contact1,
 
466
                           EContact *contact2)
453
467
{
454
468
        EABContactMatchType match = EAB_CONTACT_MATCH_NOT_APPLICABLE;
455
469
        GList *contact1_email, *contact2_email;
473
487
        i1 = contact1_email;
474
488
 
475
489
        /* Do pairwise-comparisons on all of the e-mail addresses.  If
476
 
           we find an exact match, there is no reason to keep
477
 
           checking. */
 
490
         * we find an exact match, there is no reason to keep
 
491
         * checking. */
478
492
        while (i1 && match != EAB_CONTACT_MATCH_EXACT) {
479
493
                gchar *addr1 = (gchar *) i1->data;
480
494
 
500
514
}
501
515
 
502
516
EABContactMatchType
503
 
eab_contact_compare_address (EContact *contact1, EContact *contact2)
504
 
{
505
 
        g_return_val_if_fail (contact1 && E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
506
 
        g_return_val_if_fail (contact2 && E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE);
507
 
 
508
 
        /* Unimplemented */
509
 
 
510
 
        return EAB_CONTACT_MATCH_NOT_APPLICABLE;
511
 
}
512
 
 
513
 
EABContactMatchType
514
 
eab_contact_compare_telephone (EContact *contact1, EContact *contact2)
515
 
{
516
 
        g_return_val_if_fail (contact1 && E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
517
 
        g_return_val_if_fail (contact2 && E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE);
518
 
 
519
 
        /* Unimplemented */
520
 
 
521
 
        return EAB_CONTACT_MATCH_NOT_APPLICABLE;
522
 
}
523
 
 
524
 
EABContactMatchType
525
 
eab_contact_compare (EContact *contact1, EContact *contact2)
 
517
eab_contact_compare_address (EContact *contact1,
 
518
                             EContact *contact2)
 
519
{
 
520
        g_return_val_if_fail (contact1 && E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
 
521
        g_return_val_if_fail (contact2 && E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE);
 
522
 
 
523
        /* Unimplemented */
 
524
 
 
525
        return EAB_CONTACT_MATCH_NOT_APPLICABLE;
 
526
}
 
527
 
 
528
EABContactMatchType
 
529
eab_contact_compare_telephone (EContact *contact1,
 
530
                               EContact *contact2)
 
531
{
 
532
        g_return_val_if_fail (contact1 && E_IS_CONTACT (contact1), EAB_CONTACT_MATCH_NOT_APPLICABLE);
 
533
        g_return_val_if_fail (contact2 && E_IS_CONTACT (contact2), EAB_CONTACT_MATCH_NOT_APPLICABLE);
 
534
 
 
535
        /* Unimplemented */
 
536
 
 
537
        return EAB_CONTACT_MATCH_NOT_APPLICABLE;
 
538
}
 
539
 
 
540
EABContactMatchType
 
541
eab_contact_compare (EContact *contact1,
 
542
                     EContact *contact2)
526
543
{
527
544
        EABContactMatchType result;
528
545
 
660
677
#define MAX_QUERY_PARTS 10
661
678
static void
662
679
use_common_book_client (EBookClient *book_client,
663
 
                        MatchSearchInfo *info)
 
680
                        MatchSearchInfo *info)
664
681
{
665
682
        EContact *contact = info->contact;
666
683
        EContactName *contact_name;
667
684
        GList *contact_email;
668
685
        gchar *query_parts[MAX_QUERY_PARTS];
669
 
        gint p=0;
 
686
        gint p = 0;
670
687
        gchar *contact_file_as, *qj;
671
688
        EBookQuery *query = NULL;
672
689
        gint i;